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"
30 #include "ownershiptransfermanager.h"
31 #include "ocstackinternal.h"
32 #include "mbedtls/ssl_ciphersuites.h"
34 #define TAG "OIC_OXM_JustWorks"
36 OCStackResult CreateJustWorksSelectOxmPayload(OTMContext_t *otmCtx,
37 uint8_t **payload, size_t *size)
39 if (!otmCtx || !otmCtx->selectedDeviceInfo || !payload || *payload || !size)
41 return OC_STACK_INVALID_PARAM;
44 otmCtx->selectedDeviceInfo->doxm->oxmSel = OIC_JUST_WORKS;
48 bool propertiesToInclude[DOXM_PROPERTY_COUNT];
49 memset(propertiesToInclude, 0, sizeof(propertiesToInclude));
50 propertiesToInclude[DOXM_OXMSEL] = true;
52 return DoxmToCBORPayloadPartial(otmCtx->selectedDeviceInfo->doxm, payload,
53 size, propertiesToInclude);
56 OCStackResult CreateJustWorksOwnerTransferPayload(OTMContext_t* otmCtx,
57 uint8_t **payload, size_t *size)
59 if (!otmCtx || !otmCtx->selectedDeviceInfo || !payload || *payload || !size)
61 return OC_STACK_INVALID_PARAM;
64 OicUuid_t uuidPT = {.id={0}};
66 if (OC_STACK_OK != GetDoxmDeviceID(&uuidPT))
68 OIC_LOG(ERROR, TAG, "Error while retrieving provisioning tool's device ID");
69 return OC_STACK_ERROR;
71 memcpy(otmCtx->selectedDeviceInfo->doxm->owner.id, uuidPT.id , UUID_LENGTH);
76 bool propertiesToInclude[DOXM_PROPERTY_COUNT];
77 memset(propertiesToInclude, 0, sizeof(propertiesToInclude));
78 propertiesToInclude[DOXM_DEVOWNERUUID] = true;
80 return DoxmToCBORPayloadPartial(otmCtx->selectedDeviceInfo->doxm, payload,
81 size, propertiesToInclude);
84 OCStackResult LoadSecretJustWorksCallback(OTMContext_t* UNUSED_PARAM)
86 //In case of 'just works', secret data not required
91 OCStackResult CreateSecureSessionJustWorksCallback(OTMContext_t* otmCtx)
93 OIC_LOG(INFO, TAG, "IN CreateSecureSessionJustWorksCallback");
94 if (!otmCtx || !otmCtx->selectedDeviceInfo)
96 return OC_STACK_INVALID_PARAM;
99 CAResult_t caresult = CAEnableAnonECDHCipherSuite(true);
100 if (CA_STATUS_OK != caresult)
102 OIC_LOG_V(ERROR, TAG, "Unable to enable anon cipher suite");
103 return OC_STACK_ERROR;
105 OIC_LOG(INFO, TAG, "Anonymous cipher suite Enabled.");
107 caresult = CASelectCipherSuite(MBEDTLS_TLS_ECDH_ANON_WITH_AES_128_CBC_SHA256, otmCtx->selectedDeviceInfo->endpoint.adapter);
108 if (CA_STATUS_OK != caresult)
110 OIC_LOG_V(ERROR, TAG, "Failed to select TLS_ECDH_anon_WITH_AES_128_CBC_SHA256");
111 caresult = CAEnableAnonECDHCipherSuite(false);
112 if (CA_STATUS_OK != caresult)
114 OIC_LOG_V(ERROR, TAG, "Unable to enable anon cipher suite");
118 OIC_LOG(INFO, TAG, "Anonymous cipher suite Disabled.");
120 return OC_STACK_ERROR;
122 OIC_LOG(INFO, TAG, "TLS_ECDH_anon_WITH_AES_128_CBC_SHA256 cipher suite selected.");
124 CAEndpoint_t endpoint;
125 OCProvisionDev_t *selDevInfo = otmCtx->selectedDeviceInfo;
126 CopyDevAddrToEndpoint(&selDevInfo->endpoint, &endpoint);
128 if (CA_ADAPTER_IP == endpoint.adapter)
130 endpoint.port = selDevInfo->securePort;
133 else if (CA_ADAPTER_TCP == endpoint.adapter)
135 endpoint.port = selDevInfo->tcpSecurePort;
139 caresult = CAInitiateHandshake(&endpoint);
140 if (CA_STATUS_OK != caresult)
142 OIC_LOG_V(ERROR, TAG, "DTLS/TLS handshake failure.");
143 return OC_STACK_ERROR;
146 OIC_LOG(INFO, TAG, "OUT CreateSecureSessionJustWorksCallback");
150 OCStackResult CreateMVJustWorksSelectOxmPayload(OTMContext_t *otmCtx, uint8_t **cborPayload,
153 if (!otmCtx || !otmCtx->selectedDeviceInfo || !cborPayload || *cborPayload || !cborSize)
155 return OC_STACK_INVALID_PARAM;
158 otmCtx->selectedDeviceInfo->doxm->oxmSel = OIC_MV_JUST_WORKS;
162 bool propertiesToInclude[DOXM_PROPERTY_COUNT];
163 memset(propertiesToInclude, 0, sizeof(propertiesToInclude));
164 propertiesToInclude[DOXM_OXMSEL] = true;
166 return DoxmToCBORPayloadPartial(otmCtx->selectedDeviceInfo->doxm, cborPayload,
167 cborSize, propertiesToInclude);