[IOT-3293] Proper PSK hint for random pin 12/29612/4 2.0.1.1 2.0.1.1-RC0
authorAleksey Volkov <a.volkov@samsung.com>
Wed, 17 Jul 2019 10:47:21 +0000 (13:47 +0300)
committerNathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
Thu, 18 Jul 2019 17:03:36 +0000 (17:03 +0000)
Use device uuid as psk hint for the random pin
otm TLS session

Change-Id: I02daa8b7cacdac46c6ce5b9d59f6d0932a2b5e15
Signed-off-by: Aleksey Volkov <a.volkov@samsung.com>
resource/csdk/security/src/oxmpincommon.c
resource/csdk/security/unittest/oxmpincommon.cpp

index 2d12d75..c8f938c 100644 (file)
@@ -451,21 +451,25 @@ int32_t GetDtlsPskForRandomPinOxm( CADtlsPskCredType_t type,
         case CA_DTLS_PSK_HINT:
         case CA_DTLS_PSK_IDENTITY:
             {
-                /**
-                 * The server will provide PSK hint to identify PSK according to RFC 4589 and RFC 4279.
-                 *
-                 * At this point, The server generate random hint and
-                 * provide it to client through server key exchange message.
-                 */
-                if (!OCGetRandomBytes(result, result_length))
+                const OicSecDoxm_t* doxm = GetDoxmResourceData();
+
+                if (NULL == doxm)
                 {
-                    OIC_LOG(ERROR, TAG, "Failed to generate random PSK hint");
-                    break;
+                    OIC_LOG(ERROR, TAG, "Cant get own uuid");
+                    return ret;
                 }
-                ret = (int32_t)result_length;
+
+                if (sizeof(doxm->deviceID.id) > result_length)
+                {
+                    OIC_LOG(ERROR, TAG, "Identity buffer is too small");
+                    return ret;
+                }
+
+                memcpy(result, doxm->deviceID.id, sizeof(doxm->deviceID.id));
+                ret = sizeof(doxm->deviceID.id);
 
                 OIC_LOG(DEBUG, TAG, "PSK HINT : ");
-                OIC_LOG_BUFFER(DEBUG, TAG, result, result_length);
+                OIC_LOG_BUFFER(DEBUG, TAG, result, ret);
             }
             break;
 
index 324dc5a..e711ca1 100644 (file)
@@ -232,7 +232,7 @@ TEST_F(OXMPIN, GetDtlsPskForRandomPinOxm)
     ASSERT_NE(nullptr, result);
 
     EXPECT_EQ(GetDtlsPskForRandomPinOxm(CA_DTLS_PSK_KEY, NULL, 0, result, len), OWNER_PSK_LENGTH_128);
-    EXPECT_GT(GetDtlsPskForRandomPinOxm(CA_DTLS_PSK_HINT, NULL, 0, result, len), 0);
+    EXPECT_GT(GetDtlsPskForRandomPinOxm(CA_DTLS_PSK_HINT, NULL, 0, result, len), sizeof(OicUuid_t));
     EXPECT_EQ(GetDtlsPskForRandomPinOxm((CADtlsPskCredType_t)3, NULL, 0, result, len), -1);
 
     OICFree(result);