From 6b15edb6deb7968ca3b307da62cec50158ba7551 Mon Sep 17 00:00:00 2001 From: Chul Lee Date: Thu, 23 Jun 2016 09:56:49 +0900 Subject: [PATCH] Prevent the duplicate PIN output in case of retransmission message. [Patch #1] Initial upload. Change-Id: I3f69865a5fccaef9775d0200c0afaa7ce7247c20 Signed-off-by: Chul Lee Reviewed-on: https://gerrit.iotivity.org/gerrit/8897 Tested-by: jenkins-iotivity Reviewed-by: dongik Lee Reviewed-by: Randeep Singh --- resource/csdk/security/src/doxmresource.c | 41 +++++++++++++++++-------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/resource/csdk/security/src/doxmresource.c b/resource/csdk/security/src/doxmresource.c index 33935a1..fbe30ae 100644 --- a/resource/csdk/security/src/doxmresource.c +++ b/resource/csdk/security/src/doxmresource.c @@ -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__ } -- 2.7.4