Prevent the duplicate PIN output in case of retransmission message.
authorChul Lee <chuls.lee@samsung.com>
Thu, 23 Jun 2016 00:56:49 +0000 (09:56 +0900)
committerRandeep Singh <randeep.s@samsung.com>
Tue, 5 Jul 2016 06:46:45 +0000 (06:46 +0000)
[Patch #1] Initial upload.

Change-Id: I3f69865a5fccaef9775d0200c0afaa7ce7247c20
Signed-off-by: Chul Lee <chuls.lee@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8897
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: dongik Lee <dongik.lee@samsung.com>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
resource/csdk/security/src/doxmresource.c

index 33935a1..fbe30ae 100644 (file)
@@ -584,6 +584,7 @@ static OCEntityHandlerResult HandleDoxmPostRequest(const OCEntityHandlerRequest
     OIC_LOG (DEBUG, TAG, "Doxm EntityHandle  processing POST request");
     OCEntityHandlerResult ehRet = OC_EH_ERROR;
     OicUuid_t emptyOwner = {.id = {0} };
+    static uint16_t previousMsgId = 0;
 
     /*
      * Convert CBOR Doxm data into binary. This will also validate
@@ -683,25 +684,29 @@ static OCEntityHandlerResult HandleDoxmPostRequest(const OCEntityHandlerRequest
                         caRes = CASelectCipherSuite(TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA_256);
                         VERIFY_SUCCESS(TAG, caRes == CA_STATUS_OK, ERROR);
 
-                        char ranPin[OXM_RANDOM_PIN_SIZE + 1] = {0,};
-                        if(OC_STACK_OK == GeneratePin(ranPin, OXM_RANDOM_PIN_SIZE + 1))
+                        if(previousMsgId != ehRequest->messageID)
                         {
-                            //Set the device id to derive temporal PSK
-                            SetUuidForRandomPinOxm(&gDoxm->deviceID);
-
-                            /**
-                             * Since PSK will be used directly by DTLS layer while PIN based ownership transfer,
-                             * Credential should not be saved into SVR.
-                             * For this reason, use a temporary get_psk_info callback to random PIN OxM.
-                             */
-                            caRes = CARegisterDTLSCredentialsHandler(GetDtlsPskForRandomPinOxm);
-                            VERIFY_SUCCESS(TAG, caRes == CA_STATUS_OK, ERROR);
-                            ehRet = OC_EH_OK;
-                        }
-                        else
-                        {
-                            OIC_LOG(ERROR, TAG, "Failed to generate random PIN");
-                            ehRet = OC_EH_ERROR;
+                            char ranPin[OXM_RANDOM_PIN_SIZE + 1] = {0,};
+                            if(OC_STACK_OK == GeneratePin(ranPin, OXM_RANDOM_PIN_SIZE + 1))
+                            {
+                                //Set the device id to derive temporal PSK
+                                SetUuidForRandomPinOxm(&gDoxm->deviceID);
+
+                                /**
+                                 * Since PSK will be used directly by DTLS layer while PIN based ownership transfer,
+                                 * Credential should not be saved into SVR.
+                                 * For this reason, use a temporary get_psk_info callback to random PIN OxM.
+                                 */
+                                caRes = CARegisterDTLSCredentialsHandler(GetDtlsPskForRandomPinOxm);
+                                VERIFY_SUCCESS(TAG, caRes == CA_STATUS_OK, ERROR);
+                                ehRet = OC_EH_OK;
+                            }
+                            else
+                            {
+                                OIC_LOG(ERROR, TAG, "Failed to generate random PIN");
+                                ehRet = OC_EH_ERROR;
+                            }
+                            previousMsgId = ehRequest->messageID;
                         }
 #endif //__WITH_DTLS__
                     }