1 /* *****************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * *****************************************************************/
23 #include "securevirtualresourcetypes.h"
24 #include "doxmresource.h"
26 #include "cainterface.h"
27 #include "oic_malloc.h"
31 #include "ownershiptransfermanager.h"
33 #define TAG "OXM_JustWorks"
35 OCStackResult CreateJustWorksSelectOxmPayload(OTMContext_t *otmCtx, uint8_t **payload, size_t *size)
37 if (!otmCtx || !otmCtx->selectedDeviceInfo || !payload || *payload || !size)
39 return OC_STACK_INVALID_PARAM;
42 otmCtx->selectedDeviceInfo->doxm->oxmSel = OIC_JUST_WORKS;
46 return DoxmToCBORPayload(otmCtx->selectedDeviceInfo->doxm, payload, size);
49 OCStackResult CreateJustWorksOwnerTransferPayload(OTMContext_t* otmCtx, uint8_t **payload, size_t *size)
51 if (!otmCtx || !otmCtx->selectedDeviceInfo || !payload || *payload || !size)
53 return OC_STACK_INVALID_PARAM;
56 OicUuid_t uuidPT = {.id={0}};
58 if (OC_STACK_OK != GetDoxmDeviceID(&uuidPT))
60 OIC_LOG(ERROR, TAG, "Error while retrieving provisioning tool's device ID");
61 return OC_STACK_ERROR;
63 memcpy(otmCtx->selectedDeviceInfo->doxm->owner.id, uuidPT.id , UUID_LENGTH);
68 return DoxmToCBORPayload(otmCtx->selectedDeviceInfo->doxm, payload, size);
71 OCStackResult LoadSecretJustWorksCallback(OTMContext_t* UNUSED_PARAM)
73 //In case of 'just works', secret data not required
78 OCStackResult CreateSecureSessionJustWorksCallback(OTMContext_t* otmCtx)
80 OIC_LOG(INFO, TAG, "IN CreateSecureSessionJustWorksCallback");
81 if (!otmCtx || !otmCtx->selectedDeviceInfo)
83 return OC_STACK_INVALID_PARAM;
86 CAResult_t caresult = CAEnableAnonECDHCipherSuite(true);
87 if (CA_STATUS_OK != caresult)
89 OIC_LOG_V(ERROR, TAG, "Unable to enable anon cipher suite");
90 return OC_STACK_ERROR;
92 OIC_LOG(INFO, TAG, "Anonymous cipher suite Enabled.");
94 caresult = CASelectCipherSuite(TLS_ECDH_anon_WITH_AES_128_CBC_SHA_256);
95 if (CA_STATUS_OK != caresult)
97 OIC_LOG_V(ERROR, TAG, "Failed to select TLS_ECDH_anon_WITH_AES_128_CBC_SHA_256");
98 caresult = CAEnableAnonECDHCipherSuite(false);
99 if (CA_STATUS_OK != caresult)
101 OIC_LOG_V(ERROR, TAG, "Unable to enable anon cipher suite");
105 OIC_LOG(INFO, TAG, "Anonymous cipher suite Disabled.");
107 return OC_STACK_ERROR;
109 OIC_LOG(INFO, TAG, "TLS_ECDH_anon_WITH_AES_128_CBC_SHA_256 cipher suite selected.");
111 OCProvisionDev_t *selDevInfo = otmCtx->selectedDeviceInfo;
112 CAEndpoint_t *endpoint = (CAEndpoint_t *)OICCalloc(1, sizeof (CAEndpoint_t));
115 return OC_STACK_NO_MEMORY;
117 memcpy(endpoint, &selDevInfo->endpoint, sizeof(CAEndpoint_t));
118 endpoint->port = selDevInfo->securePort;
120 caresult = CAInitiateHandshake(endpoint);
122 if (CA_STATUS_OK != caresult)
124 OIC_LOG_V(ERROR, TAG, "DTLS handshake failure.");
125 return OC_STACK_ERROR;
128 OIC_LOG(INFO, TAG, "OUT CreateSecureSessionJustWorksCallback");