Commit 37ed9e2f authored by Oleksandr Dmytrenko's avatar Oleksandr Dmytrenko Committed by Uze Choi

[IOT-2083] TLSAdapter.Test_11

Change-Id: I4d6379193291d01d50ecbca2df25a51dc20b75c8
Signed-off-by: default avatarOleksandr Dmytrenko <o.dmytrenko@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/19255Tested-by: default avatarjenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: default avatarUze Choi <uzchoi@samsung.com>
Tested-by: default avatarUze Choi <uzchoi@samsung.com>
parent f15f58c2
......@@ -90,6 +90,8 @@
#define SEED "PREDICTED_SEED"
#define dummyHandler 0xF123
#define DEFAULT_HEX_WIDTH 16
#define SERVER_PORT 4433
#define SERVER_PORT_STRING "4433"
#define SERVER_NAME "localhost"
......@@ -802,6 +804,23 @@ unsigned char control_server_message_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384[] = {
};
size_t control_server_message_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384_len = sizeof(control_server_message_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384);
void printHexArray(unsigned char *m, size_t len, size_t cols)
{
for(size_t i = 0; i < len; i++)
{
mbedtls_printf("0x%02x", m[i]);
if (i != len - 1)
{
mbedtls_printf(", ");
}
if (i > 0 && (i + 1) % cols == 0)
{
mbedtls_printf("\n");
}
}
mbedtls_printf("\n");
}
static volatile bool socket_error = false;
static void error(const char *msg)
......@@ -3086,9 +3105,35 @@ TEST(TLSAdapter, Test_10)
EXPECT_EQ(0, ret);
}
static void * testCAsslGenerateOwnerPsk(void * arg)
// This test has a bug in it (IOT-1848):
// server() listens only on IPv6 on Windows (because IPV6_V6ONLY defaults
// to true) and socketConnect() is hard coded to try only IPv4.
#ifdef HAVE_WINSOCK2_H
TEST(TLSAdapter, DISABLED_Test_11)
#else
TEST(TLSAdapter, Test_11)
#endif
{
int ret = 0;
uint8_t predictedPSK[] = {
0xba, 0x72, 0x16, 0xbc, 0x7f, 0x8c, 0xfe, 0xfc, 0xd0, 0xac, 0x1a, 0x37, 0xad, 0x60, 0xe8, 0x9e,
0xb3, 0x31, 0xa2, 0x30, 0xaf, 0x68, 0xc9, 0xa6, 0x89, 0x8a, 0x04, 0x21, 0x6c, 0xbd, 0x04, 0x08,
0x68, 0x11, 0x54, 0x9e, 0x2a, 0x10, 0x91, 0x94, 0x3c, 0x44, 0x52, 0xc7, 0xfa, 0x78, 0x44, 0x87,
0xea, 0x30, 0x08, 0x5f, 0xc1, 0x64, 0xaa, 0x0d, 0xfd, 0x84, 0x16, 0x83, 0x20, 0xc9, 0x08, 0x65,
0xd2, 0x4a, 0x55, 0x9e, 0x8f, 0x88, 0x3c, 0x57, 0x10, 0xbd, 0x5a, 0x30, 0x01, 0xb4, 0x59, 0x63,
0x64, 0x19, 0x8d, 0xfa, 0x5c, 0x86, 0x92, 0xf7, 0x60, 0x99, 0xdb, 0xae, 0x0e, 0xad, 0x80, 0xf1,
0x82, 0xaf, 0x1b, 0x14
};
size_t predictedPSK_len = sizeof(predictedPSK);
uint8_t label[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A};
uint8_t rsrcServerDeviceId[] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A};
uint8_t provServerDeviceId[] = {0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A};
uint8_t *ownerPsk = (uint8_t*)OICMalloc(predictedPSK_len);
EXPECT_TRUE(NULL != ownerPsk) << "Cannot allocate memory";
memset(ownerPsk, 0, predictedPSK_len);
socket_error = false;
CAEndpoint_t serverAddr;
memset(&serverAddr, 0, sizeof(serverAddr));
serverAddr.adapter = CA_ADAPTER_TCP;
......@@ -3098,28 +3143,11 @@ static void * testCAsslGenerateOwnerPsk(void * arg)
memcpy(serverAddr.addr, addr, sizeof(addr));
serverAddr.ifindex = 0;
uint8_t label[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A};
uint8_t rsrcServerDeviceId[] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A};
uint8_t provServerDeviceId[] = {0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A};
uint8_t ownerPsk[0x100] = {0x00};
uint8_t predictedPSK[] = {
0xba, 0x72, 0x16, 0xbc, 0x7f, 0x8c, 0xfe, 0xfc, 0xd0, 0xac, 0x1a, 0x37, 0xad, 0x60, 0xe8, 0x9e,
0xb3, 0x31, 0xa2, 0x30, 0xaf, 0x68, 0xc9, 0xa6, 0x89, 0x8a, 0x04, 0x21, 0x6c, 0xbd, 0x04, 0x08,
0x68, 0x11, 0x54, 0x9e, 0x2a, 0x10, 0x91, 0x94, 0x3c, 0x44, 0x52, 0xc7, 0xfa, 0x78, 0x44, 0x87,
0xea, 0x30, 0x08, 0x5f, 0xc1, 0x64, 0xaa, 0x0d, 0xfd, 0x84, 0x16, 0x83, 0x20, 0xc9, 0x08, 0x65,
0xd2, 0x4a, 0x55, 0x9e, 0x8f, 0x88, 0x3c, 0x57, 0x10, 0xbd, 0x5a, 0x30, 0x01, 0xb4, 0x59, 0x63,
0x64, 0x19, 0x8d, 0xfa, 0x5c, 0x86, 0x92, 0xf7, 0x60, 0x99, 0xdb, 0xae, 0x0e, 0xad, 0x80, 0xf1,
0x82, 0xaf, 0x1b, 0x14, 0x0c, 0x99, 0x13, 0x53, 0x54, 0x33, 0x6a, 0x17, 0x24, 0x5c, 0x9d, 0xdb,
0x5a, 0xfb, 0x73, 0x2f, 0x41, 0xe8, 0xeb, 0x2e, 0x68, 0xfe, 0xee, 0x0b, 0xdc, 0x54, 0x50, 0xf1,
0x1e, 0x16, 0x19, 0x2c, 0x4e, 0xb6, 0x97, 0x9f, 0x9c, 0x32, 0x9c, 0x0e, 0xe0, 0xe1, 0x32, 0x64,
0x16, 0x34, 0x53, 0x8e, 0xc5, 0xe3, 0xe5, 0xbc, 0x2c, 0x10, 0xae, 0x81, 0x2c, 0x1a, 0xb2, 0xb7,
0xa3, 0xbe, 0x0f, 0xab, 0xfd, 0xf7, 0x87, 0x53, 0xcd, 0x3e, 0x31, 0xfb, 0x2d, 0x69, 0x6a, 0xd5,
0xc3, 0x27, 0x04, 0x2b, 0x37, 0x02, 0x91, 0x05, 0x0c, 0x4e, 0x2a, 0xfc, 0x6c, 0x42, 0xe8, 0x37,
0x23, 0x2f, 0x60, 0x6e, 0x0c, 0xed, 0x7c, 0xe0, 0x5f, 0x47, 0xb3, 0x51, 0x86, 0x5b, 0x26, 0x08,
0x2a, 0x05, 0x89, 0xb0, 0xdd, 0x6f, 0xc6, 0x76, 0xc5, 0x2a, 0x60, 0x07, 0x0e, 0xb1, 0x71, 0x67,
0x21, 0x11, 0xf8, 0xb5, 0x52, 0xa3, 0xf3, 0xf0, 0xd4, 0x5f, 0xdf, 0x44, 0x66, 0x23, 0xd8, 0x4e,
0xbd, 0x64, 0x39, 0x43, 0x03, 0x37, 0xaa, 0xd7, 0xea, 0xb3, 0x6d, 0x2f, 0x84, 0x9c, 0x02, 0x49
};
//start server
pthread_t thread;
EXPECT_EQ(0, pthread_create( &thread, NULL, server, (void*) NULL)) << "Thread create";
sleep(5);
ASSERT_FALSE(socket_error) << "Server: socket error";
// CAinitTlsAdapter
g_sslContextMutex = oc_mutex_new();
......@@ -3163,22 +3191,19 @@ static void * testCAsslGenerateOwnerPsk(void * arg)
CAsetPskCredentialsCallback(GetDtlsPskCredentials);
if (!socketConnect())
{
*((int*)arg) = 0xFF;
return (void *) 0xFF;
}
EXPECT_NE(0, socketConnect());
ASSERT_FALSE(socket_error) << "Client: cannot connect to server";
// CAinitiateSslHandshake
oc_mutex_lock(g_sslContextMutex);
InitiateTlsHandshake(&serverAddr);
oc_mutex_unlock(g_sslContextMutex);
ret = CAsslGenerateOwnerPsk(&serverAddr,
EXPECT_EQ(0, CAsslGenerateOwnerPsk(&serverAddr,
label, sizeof(label),
rsrcServerDeviceId, sizeof(rsrcServerDeviceId),
provServerDeviceId, sizeof(provServerDeviceId),
ownerPsk, 0x100);
ownerPsk, predictedPSK_len));
// CAcloseTlsConnection
oc_mutex_lock(g_sslContextMutex);
......@@ -3204,52 +3229,12 @@ static void * testCAsslGenerateOwnerPsk(void * arg)
socketClose();
if (ret == 0 && memcmp(predictedPSK, ownerPsk, sizeof(predictedPSK)) == 0)
{
*((int*)arg) = 0;
return NULL;
}
else
{
*((int*)arg) = 0xFF;
return (void *) 0xFF;
}
}
// This test has a bug in it (IOT-1848):
// server() listens only on IPv6 on Windows (because IPV6_V6ONLY defaults
// to true) and socketConnect() is hard coded to try only IPv4.
#ifdef HAVE_WINSOCK2_H
TEST(TLSAdapter, DISABLED_Test_11)
#else
TEST(TLSAdapter, Test_11)
#endif
{
socket_error = false;
pthread_t thread1, thread2;
int ret = 0;
int arg = 1;
ret = pthread_create( &thread1, NULL, server, (void*) NULL);
if(ret)
{
fprintf(stderr, "Error - pthread_create() return code: %d\n", ret);
ASSERT_TRUE(false);
}
sleep(5);
ret = pthread_create( &thread2, NULL, testCAsslGenerateOwnerPsk, &arg);
if(ret)
{
fprintf(stderr, "Error - pthread_create() return code: %d\n", ret);
ASSERT_TRUE(false);
}
sleep(5);
ASSERT_FALSE(socket_error) << "Client: socket error";
ASSERT_FALSE(socket_error);
EXPECT_EQ(0, arg);
mbedtls_printf("Got PSK:\n");
printHexArray(ownerPsk, predictedPSK_len, DEFAULT_HEX_WIDTH);
EXPECT_EQ(0, memcmp(predictedPSK, ownerPsk, predictedPSK_len)) << "PSK error";
OICFree(ownerPsk);
}
TEST(TLSAdapter, Test_ParseChain)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment