X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fcsdk%2Fsecurity%2Fsrc%2Fdpairingresource.c;h=8f03b9a00691b6a454d707fc703222e8ecf31443;hb=3c093548382bb2542c87a67e6e5fa32552c29cb3;hp=5f244c87a17eb6cfba0b7b29fba8712f66075aad;hpb=7971eea6746afbea2c37e924e7f3c96780a85fb1;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/csdk/security/src/dpairingresource.c b/resource/csdk/security/src/dpairingresource.c index 5f244c8..8f03b9a 100644 --- a/resource/csdk/security/src/dpairingresource.c +++ b/resource/csdk/security/src/dpairingresource.c @@ -18,13 +18,18 @@ * * *****************************************************************/ +#include "iotivity_config.h" #include #include #include "ocstack.h" #include "logger.h" #include "oic_malloc.h" #include "oic_string.h" +#if defined (__TIZENRT__) +#include +#else #include "cJSON.h" +#endif #include "base64.h" #include "resourcemanager.h" #include "dpairingresource.h" @@ -38,19 +43,15 @@ #include "aclresource.h" #include "srmutility.h" #include "ocserverrequest.h" -#include "ocpayloadcbor.h" #include "ocpayload.h" +#include "ocpayloadcbor.h" #include "payload_logging.h" -#include + #ifdef HAVE_STRINGS_H #include #endif -#ifdef __WITH_DTLS__ -#include "global.h" -#endif - -#define TAG "SRM-DPAIRING" +#define TAG "OIC_SRM_DPAIRING" /** Default cbor payload size. This value is increased in case of CborErrorOutOfMemory. * The value of payload size is increased until reaching belox max cbor size. */ @@ -103,7 +104,7 @@ void SetDpairingResourceOwner(OicUuid_t *rowner) } } -#ifdef __WITH_DTLS__ +#if defined(__WITH_DTLS__) || defined(__WITH_TLS__) /** * Function to save PairingPSK. * @@ -146,13 +147,14 @@ OCStackResult SavePairingPSK(OCDevAddr *endpoint, if (CA_STATUS_OK == pskRet) { - OIC_LOG(INFO, TAG, "pairingPSK dump:\n"); - OIC_LOG_BUFFER(INFO, TAG, pairingPSK, OWNER_PSK_LENGTH_128); + OIC_LOG(DEBUG, TAG, "pairingPSK dump:\n"); + OIC_LOG_BUFFER(DEBUG, TAG, pairingPSK, OWNER_PSK_LENGTH_128); //Generating new credential for direct-pairing client OicSecCred_t *cred = GenerateCredential(peerDevID, SYMMETRIC_PAIR_WISE_KEY, NULL, - &pairingKey, owner); + &pairingKey, owner, NULL); + OICClearMemory(pairingPSK, sizeof(pairingPSK)); VERIFY_NON_NULL(TAG, cred, ERROR); res = AddCredential(cred); @@ -171,7 +173,7 @@ OCStackResult SavePairingPSK(OCDevAddr *endpoint, exit: return res; } -#endif // __WITH_DTLS__ +#endif // __WITH_DTLS__ or __WITH_TLS__ OCStackResult DpairingToCBORPayload(const OicSecDpairing_t *dpair, uint8_t **payload, size_t *size) { @@ -242,7 +244,7 @@ OCStackResult DpairingToCBORPayload(const OicSecDpairing_t *dpair, uint8_t **pay if (CborNoError == cborEncoderResult) { - *size = encoder.ptr - outPayload; + *size = cbor_encoder_get_buffer_size(&encoder, outPayload); *payload = outPayload; ret = OC_STACK_OK; } @@ -252,8 +254,9 @@ exit: { // reallocate and try again! OICFree(outPayload); + outPayload = NULL; // Since the allocated initial memory failed, double the memory. - cborLen += encoder.ptr - encoder.end; + cborLen += cbor_encoder_get_buffer_size(&encoder, encoder.end); cborEncoderResult = CborNoError; ret = DpairingToCBORPayload(dpair, payload, &cborLen); *size = cborLen; @@ -383,9 +386,9 @@ void DPairingDTLSHandshakeCB(const CAEndpoint_t *endpoint, const CAErrorInfo_t * } -#ifdef __WITH_DTLS__ - CARegisterDTLSHandshakeCallback(NULL); -#endif // __WITH_DTLS__ +#if defined(__WITH_DTLS__) || defined(__WITH_TLS__) + CAregisterSslHandshakeCallback(NULL); +#endif // __WITH_DTLS__ or __WITH_TLS__ // delete temporary key RemoveCredential(&gDpair->pdeviceID); @@ -443,7 +446,7 @@ static OCEntityHandlerResult HandleDpairingPostRequest (const OCEntityHandlerReq memcpy(&gDpair->pdeviceID, &newDpair->pdeviceID, sizeof(OicUuid_t)); memcpy(&gDpair->rownerID, &pconf->rownerID, sizeof(OicUuid_t)); -#ifdef __WITH_DTLS__ +#if defined(__WITH_DTLS__) || defined(__WITH_TLS__) // Add temporary psk OCStackResult res; OicUuid_t subjectId = {.id={0}}; @@ -460,19 +463,19 @@ static OCEntityHandlerResult HandleDpairingPostRequest (const OCEntityHandlerReq // Prepare to establish a secure channel with Pin-based PSK cipher suite if (CA_STATUS_OK != CAEnableAnonECDHCipherSuite(false) || - CA_STATUS_OK != CASelectCipherSuite(TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA_256)) + CA_STATUS_OK != CASelectCipherSuite(MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256, CA_ADAPTER_IP)) { OIC_LOG_V(ERROR, TAG, "Failed to select TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA_256"); goto exit; } - if(CA_STATUS_OK != CARegisterDTLSHandshakeCallback(DPairingDTLSHandshakeCB)) + if(CA_STATUS_OK != CAregisterSslHandshakeCallback(DPairingDTLSHandshakeCB)) { OIC_LOG(WARNING, TAG, "DirectPairingHandler : Failed to register" " DTLS handshake callback."); goto exit; } -#endif // __WITH_DTLS__ +#endif // __WITH_DTLS__ or __WITH_TLS__ // should be lock /oic/sec/dpairing resource if Direct-Pairing starts normally ? OIC_LOG (DEBUG, TAG, "/oic/sec/dpairing resource created"); @@ -486,9 +489,9 @@ static OCEntityHandlerResult HandleDpairingPostRequest (const OCEntityHandlerReq } -#ifdef __WITH_DTLS__ +#if defined(__WITH_DTLS__) || defined(__WITH_TLS__) exit: -#endif // __WITH_DTLS__ +#endif // __WITH_DTLS__ or __WITH_TLS__ // Send payload to request originator if(OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, NULL, 0)) @@ -544,8 +547,9 @@ static OCEntityHandlerResult HandleDpairingPutRequest (const OCEntityHandlerRequ const OicSecPconf_t *pconf = GetPconfResourceData(); VERIFY_NON_NULL(TAG, pconf, ERROR); -#ifdef __WITH_DTLS__ - OCServerRequest * request = (OCServerRequest *)ehRequest->requestHandle; +#if defined(__WITH_DTLS__) || defined(__WITH_TLS__) + OCServerRequest *request = GetServerRequestUsingHandle(ehRequest->requestHandle); + VERIFY_NON_NULL(TAG, request, ERROR); VERIFY_SUCCESS(TAG, (request->devAddr.flags | OC_FLAG_SECURE), ERROR); //Generate new credential @@ -554,7 +558,7 @@ static OCEntityHandlerResult HandleDpairingPutRequest (const OCEntityHandlerRequ OCStackResult res = SavePairingPSK(&request->devAddr, &newDpair->pdeviceID, (OicUuid_t *)&pconf->rownerID, true); VERIFY_SUCCESS(TAG, OC_STACK_OK == res, ERROR); -#endif //__WITH_DTLS__ +#endif // __WITH_DTLS__ or __WITH_TLS__ //Generate new acl OicSecPdAcl_t *pdAcl; @@ -634,7 +638,7 @@ static OCEntityHandlerResult HandleDpairingPutRequest (const OCEntityHandlerRequ uint8_t *payload = NULL; if (OC_STACK_OK == AclToCBORPayload(acl, &payload, &size)) { - InstallNewACL(payload, size); + AppendACL(payload, size); OICFree(payload); } DeleteACLList(acl);