OCSRM_SRC + 'secureresourcemanager.c',
OCSRM_SRC + 'resourcemanager.c',
OCSRM_SRC + 'aclresource.c',
- OCSRM_SRC + 'verresource.c',
OCSRM_SRC + 'amaclresource.c',
OCSRM_SRC + 'pstatresource.c',
OCSRM_SRC + 'doxmresource.c',
extern char OIC_SEC_REST_QUERY_DELIMETER;
//Security Version
-extern const char * DEFAULT_SEC_VERSION;
+extern const char * DEFAULT_SPEC_VERSION;
// Preconfigured Pin credential usage
#ifdef MULTIPLE_OWNER
+++ /dev/null
-/* *****************************************************************
- *
- * Copyright 2016 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * *****************************************************************/
-
-#ifndef IOTVT_SRM_VER_H
-#define IOTVT_SRM_VER_H
-
-#include "octypes.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * Initialize VER resource by loading data from persistent storage.
- *
- * @return ::OC_STACK_OK for Success, otherwise some error value.
- */
-OCStackResult InitVerResource();
-
-/**
- * Perform cleanup for VER resources.
- *
- * @return ::OC_STACK_OK for Success, otherwise some error value.
- */
-OCStackResult DeInitVerResource();
-
-/**
- * This method is used by SRM to retrieve VER resource data.
- *
- * @return reference to @ref OicSecDoxm_t, binary format of Doxm resource data.
- */
-const OicSecVer_t* GetVerResourceData();
-
-/**
- * This method converts CBOR VER into binary VER.
- * The CBOR VER can be from persistent database or
- * or received as PUT/POST request.
- *
- * @param cborPayload is a ver data in cbor.
- * @note Caller needs to invoke OCFree after done using the return pointer.
- * @param size of the cborPayload. In case value is 0, CBOR_SIZE value is assigned.
- * @param ver is the pointer to @ref OicSecVer_t.
- *
- * @return ::OC_STACK_OK for Success, otherwise some error value.
- */
-OCStackResult CBORPayloadToVer(const uint8_t *cborPayload, size_t size,
- OicSecVer_t **ver);
-
-/**
- * This method converts VER data into CBOR format.
- * Caller needs to invoke 'free' when finished done using
- * return string.
- *
- * @param ver Pointer to @ref OicSecVer_t.
- * @note Caller needs to invoke OCFree after done using the return pointer.
- * @param cborPayload is the payload of the cbor.
- * @param cborSize is the size of the cbor payload. Passed parameter should not be NULL.
- *
- * @return ::OC_STACK_OK for Success, otherwise some error value.
- */
-OCStackResult VerToCBORPayload(const OicSecVer_t * ver, uint8_t **cborPayload,
- size_t *cborSize);
-
-/**
- * Get the security version.
- *
- * @return the version string of security.
- */
-const char* GetSecVersion();
-
-/** This function deallocates the memory for OicSecVer_t .
- *
- * @param ver is the pointer to @ref OicSecVer_t.
- */
-void DeleteVerBinData(OicSecVer_t* ver);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //IOTVT_SRM_VER_H
OicUuid_t rownerID; // 2:R:S:Y:oic.uuid
};
-#define OIC_SEC_MAX_VER_LEN 16 // Security Version length. i.e., 00.00.000 + reserved space
-
+#define SPEC_MAX_VER_LEN (sizeof("core.x.x.x") + 1) // Spec Version length.
/**
- * @brief security version data type
+ * @def GET_ACL_VER(specVer)
+ * Gets ACL version depending on spec. version.
+ * Version value has "ocf.x.x.x" for ocf device and "core.x.x.x" for oic device.
+ *
+ * @param specVer spec. version string
+ * @return ACL version
*/
-typedef struct OicSecVer OicSecVer_t;
-/**
- * @brief /oic/sec/ver (Security Version) data type
- */
-struct OicSecVer
-{
- // <Attribute ID>:<Read/Write>:<Multiple/Single>:<Mandatory?>:<Type>
- char secv[OIC_SEC_MAX_VER_LEN]; // 0:R:S:Y:String
- OicUuid_t deviceID; // 1:R:S:Y:oic.uuid
-};
+#define GET_ACL_VER(specVer) ((specVer)[0] == 'o' && (specVer)[1] == 'c' && (specVer)[2] == 'f' ? \
+ OIC_SEC_ACL_V2 : OIC_SEC_ACL_V1)
+#define IS_OIC(specVer) ((specVer)[0] == 'c' && (specVer)[1] == 'o' && (specVer)[2] == 'r' && (specVer)[3] == 'e')
#ifdef __cplusplus
}
uint16_t tcpPort; /**< tcp port **/
uint16_t tcpSecurePort; /**< secure tcp port **/
#endif
- char secVer[OIC_SEC_MAX_VER_LEN]; /**< security version **/
+ char specVer[SPEC_MAX_VER_LEN]; /**< spec version **/
DeviceStatus devStatus; /**< status of device **/
OCDoHandle handle;
bool ownerAclUnauthorizedRequest; /**< true if the provisioning client has already re-tried posting the Owner ACE **/
{
printf(" [%d] ", ++lst_cnt);
printUuid((const OicUuid_t*) &lst->doxm->deviceID);
+ printf(" %s", lst->specVer);
printf("\n");
lst = lst->next;
}
#define TAG "SAMPLE_JUSTWORKS"
+const char * specVersion = "ocf.1.1.0";
int gQuitFlag = 0;
/* Structure to represent a LED resource */
OIC_LOG(ERROR, TAG, "OCStack init error");
return 0;
}
+ OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, (void*) specVersion);
/*
* Declare and create the example resource: LED
#define TAG "SAMPLE_MANUFACTURER_CERT"
int gQuitFlag = 0;
+const char * specVersion = "ocf.1.1.0";
/* Structure to represent a LED resource */
typedef struct LEDRESOURCE{
OIC_LOG(ERROR, TAG, "OCStack init error");
return 0;
}
+ OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, (void*) specVersion);
/*
* Declare and create the example resource: LED
#define TAG "SAMPLE_MV_JUSTWORKS"
int gQuitFlag = 0;
+const char * specVersion = "ocf.1.1.0";
/* Structure to represent a LED resource */
typedef struct LEDRESOURCE{
OIC_LOG(ERROR, TAG, "OCStack init error");
return 0;
}
+ OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, (void*) specVersion);
/*
* Declare and create the example resource: LED
#define TAG "SAMPLE_PRECONF_PIN"
int gQuitFlag = 0;
+const char * specVersion = "ocf.1.1.0";
/* Structure to represent a LED resource */
typedef struct LEDRESOURCE{
OIC_LOG(ERROR, TAG, "OCStack init error");
return 0;
}
+ OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, (void*) specVersion);
/*
* Declare and create the example resource: LED
#define TAG "SAMPLE_RANDOMPIN"
int gQuitFlag = 0;
+const char * specVersion = "ocf.1.1.0";
/* Structure to represent a LED resource */
typedef struct LEDRESOURCE{
OIC_LOG(ERROR, TAG, "Failed to setting PIN policy");
return 0;
}
+ OCSetPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, (void*) specVersion);
/*
* Declare and create the example resource: LED
* since we may be provisioning an IoTivity 1.2 or earlier device.
* TODO IOT-2219 - reintroduce OIC 1.1 /acl (v1) support
*/
- OicSecAclVersion_t aclVersion = OIC_SEC_ACL_V2;
+ OicSecAclVersion_t aclVersion = GET_ACL_VER(selectedDeviceInfo->specVer);
if (acl->aces != NULL)
{
/* If any of the aces have the role subject, the ACL is v2 */
UpdateLinkResults(link, 1, arr[0].res);
if (NULL != link->pDev2Acl)
{
- OCStackResult res = SRPProvisionACL(ctx, link->pDev2, link->pDev2Acl, OIC_SEC_ACL_V2, &AclProv2CB);
+ OCStackResult res = SRPProvisionACL(ctx, link->pDev2, link->pDev2Acl, GET_ACL_VER(link->pDev2->specVer), &AclProv2CB);
if (OC_STACK_OK!=res)
{
UpdateLinkResults(link, 2, res);
}
if (NULL != link->pDev1Acl)
{
- OCStackResult res = SRPProvisionACL(ctx, link->pDev1, link->pDev1Acl, OIC_SEC_ACL_V2, &AclProv1CB);
+ OCStackResult res = SRPProvisionACL(ctx, link->pDev1, link->pDev1Acl, GET_ACL_VER(link->pDev1->specVer), &AclProv1CB);
if (OC_STACK_OK!=res)
{
OIC_LOG(ERROR, TAG, "Error while provisioning ACL for device 1");
{
OIC_LOG(ERROR, TAG, "ACL for device 1 is NULL");
- OCStackResult res = SRPProvisionACL(ctx, link->pDev2, link->pDev2Acl, OIC_SEC_ACL_V2, &AclProv2CB);
+ OCStackResult res = SRPProvisionACL(ctx, link->pDev2, link->pDev2Acl, GET_ACL_VER(link->pDev2->specVer), &AclProv2CB);
if (OC_STACK_OK!=res)
{
OIC_LOG(ERROR, TAG, "Error while provisioning ACL for device 2");
* @param[in] otmCtx Context value of ownership transfer.
* @return OC_STACK_OK on success
*/
-static OCStackResult PostOwnerAcl(OTMContext_t* otmCtx);
+static OCStackResult PostOwnerAcl(OTMContext_t* otmCtx, OicSecAclVersion_t aclVer);
/**
* Function to send ownerShip info.
#ifdef __WITH_TLS__
otmCtx->selectedDeviceInfo->connType |= CT_FLAG_SECURE;
#endif
- res = PostOwnerAcl(otmCtx);
+ res = PostOwnerAcl(otmCtx, GET_ACL_VER(otmCtx->selectedDeviceInfo->specVer));
if(OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "Failed to update owner ACL to new device");
}
}
}
- else if((OC_STACK_UNAUTHORIZED_REQ == res) &&
- (NULL != selectedDeviceInfo) &&
- !selectedDeviceInfo->ownerAclUnauthorizedRequest)
- {
- OIC_LOG_V(WARNING, TAG, "%s: UNAUTHORIZED_REQ. Assuming server is based on OIC 1.1",
- __func__);
- selectedDeviceInfo->ownerAclUnauthorizedRequest = true;
-
- //Close the temporal secure session and re-connect using the owner credential
- if(!CloseSslConnection(selectedDeviceInfo))
- {
- //Cannot make progress reliably, so return the error code from the previous request.
- SetResult(otmCtx, OC_STACK_UNAUTHORIZED_REQ);
- }
- else
- {
- res = PostOwnerAcl(otmCtx);
- if(OC_STACK_OK != res)
- {
- OIC_LOG_V(ERROR, TAG, "%s: Failed to update owner ACL to new device, res = %d",
- __func__, res);
- SetResult(otmCtx, res);
- }
- }
- }
else
{
OIC_LOG_V(ERROR, TAG, "OwnerAclHandler : Unexpected result %d", res);
return OC_STACK_DELETE_TRANSACTION;
}
-
/**
* Response handler for update owner information request.
*
* Function to update the owner ACL to new device.
*
* @param[in] otmCtx Context value of ownership transfer.
+ * @param[in] aclVer ACL version.
* @return OC_STACK_OK on success
*/
-static OCStackResult PostOwnerAcl(OTMContext_t* otmCtx)
+static OCStackResult PostOwnerAcl(OTMContext_t* otmCtx, OicSecAclVersion_t aclVer)
{
OCStackResult res = OC_STACK_ERROR;
OIC_LOG(ERROR, TAG, "Invalid parameters");
return OC_STACK_INVALID_PARAM;
}
-
+ const char * aclUri = (OIC_SEC_ACL_V2 == aclVer ? OIC_RSRC_ACL2_URI : OIC_RSRC_ACL_URI);
OCProvisionDev_t* deviceInfo = otmCtx->selectedDeviceInfo;
char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
OicSecAcl_t* ownerAcl = NULL;
if(!PMGenerateQuery(true,
deviceInfo->endpoint.addr, deviceInfo->securePort,
deviceInfo->connType,
- query, sizeof(query), OIC_RSRC_ACL2_URI))
+ query, sizeof(query), aclUri))
{
OIC_LOG(ERROR, TAG, "Failed to generate query");
return OC_STACK_ERROR;
goto error;
}
- // TODO IOT-2052 change to V2
- res = AclToCBORPayload(ownerAcl, OIC_SEC_ACL_V2, &secPayload->securityData, &secPayload->payloadSize);
+ res = AclToCBORPayload(ownerAcl, aclVer, &secPayload->securityData, &secPayload->payloadSize);
if (OC_STACK_OK != res)
{
OICFree(secPayload);
//Send owner ACL to new device : POST /oic/sec/cred [ owner credential ]
OCCallbackData cbData;
- cbData.cb = &OwnerAclHandler;
+ cbData.cb = OwnerAclHandler;
cbData.context = (void *)otmCtx;
cbData.cd = NULL;
res = OCDoResource(&otmCtx->ocDoHandle, OC_REST_POST, query,
#include "srmresourcestrings.h" //@note: SRM's internal header
#include "doxmresource.h" //@note: SRM's internal header
#include "pstatresource.h" //@note: SRM's internal header
-#include "verresource.h" //@note: SRM's internal header
#include "pmtypes.h"
#include "pmutility.h"
* Since security version discovery does not used anymore, disable security version discovery.
* Need to discussion to removing all version discovery related codes.
*/
-#if 0
+
/*
* Function to discover security version information through unicast
*
*
* @return OC_STACK_OK on success otherwise error.
*/
-static OCStackResult SecurityVersionDiscovery(DiscoveryInfo* discoveryInfo,
+static OCStackResult SpecVersionDiscovery(DiscoveryInfo* discoveryInfo,
const OCClientResponse *clientResponse);
-
+#if 0
/**
* Callback handler for getting secure port information using /oic/res discovery.
*
ptr->next = NULL;
ptr->connType = connType;
ptr->devStatus = DEV_STATUS_ON; //AddDevice is called when discovery(=alive)
- OICStrcpy(ptr->secVer, OIC_SEC_MAX_VER_LEN, DEFAULT_SEC_VERSION); // version initialization
+ OICStrcpy(ptr->specVer, SPEC_MAX_VER_LEN, DEFAULT_SPEC_VERSION); // version initialization
ptr->handle = NULL;
LL_PREPEND(*ppDevicesList, ptr);
* @param[in] pList List of OCProvisionDev_t.
* @param[in] addr address of target device.
* @param[in] port port of remote server.
- * @param[in] secVer security version information.
+ * @param[in] specVer security version information.
*
* @return OC_STACK_OK for success and errorcode otherwise.
*/
-OCStackResult UpdateSecVersionOfDevice(OCProvisionDev_t **ppDevicesList, const char *addr,
- uint16_t port, const char* secVer)
+static OCStackResult UpdateSpecVersionOfDevice(OCProvisionDev_t **ppDevicesList, const char *addr,
+ uint16_t port, const char* specVer)
{
- if (NULL == secVer)
+ if (NULL == specVer)
{
return OC_STACK_INVALID_PARAM;
}
return OC_STACK_ERROR;
}
- OICStrcpy(ptr->secVer, OIC_SEC_MAX_VER_LEN, secVer);
+ OICStrcpy(ptr->specVer, SPEC_MAX_VER_LEN, specVer);
return OC_STACK_OK;
}
VERIFY_NOT_NULL(TAG, newDev->doxm, ERROR);
}
- if (0 == strlen(src->secVer))
+ if (0 == strlen(src->specVer))
{
- OICStrcpy(newDev->secVer, OIC_SEC_MAX_VER_LEN, DEFAULT_SEC_VERSION);
+ OICStrcpy(newDev->specVer, SPEC_MAX_VER_LEN, DEFAULT_SPEC_VERSION);
}
else
{
- OICStrcpy(newDev->secVer, OIC_SEC_MAX_VER_LEN, src->secVer);
+ OICStrcpy(newDev->specVer, SPEC_MAX_VER_LEN, src->specVer);
}
newDev->securePort = src->securePort;
* Since security version discovery does not used anymore, disable security version discovery.
* Need to discussion to removing all version discovery related codes.
*/
-#if 0
-static OCStackApplicationResult SecurityVersionDiscoveryHandler(void *ctx, OCDoHandle UNUSED,
+static OCStackApplicationResult SpecVersionDiscoveryHandler(void *ctx, OCDoHandle UNUSED,
OCClientResponse *clientResponse)
{
if (ctx == NULL)
}
else
{
- if (PAYLOAD_TYPE_SECURITY != clientResponse->payload->type)
+ if (PAYLOAD_TYPE_REPRESENTATION != clientResponse->payload->type)
{
OIC_LOG(INFO, TAG, "Unknown payload type");
return OC_STACK_KEEP_TRANSACTION;
}
+ OCRepPayloadValue* val = ((OCRepPayload*) clientResponse->payload)->values;
- OicSecVer_t *ptrVer = NULL;
- uint8_t *payload = ((OCSecurityPayload*)clientResponse->payload)->securityData;
- size_t size = ((OCSecurityPayload*)clientResponse->payload)->payloadSize;
-
- OCStackResult res = CBORPayloadToVer(payload, size, &ptrVer);
- if ((NULL == ptrVer) && (OC_STACK_OK != res))
- {
- OIC_LOG(INFO, TAG, "Ignoring malformed CBOR");
- return OC_STACK_KEEP_TRANSACTION;
- }
- else
+ char specVer[SPEC_MAX_VER_LEN + 1] = {0};
+ OICStrcpy(specVer, SPEC_MAX_VER_LEN, DEFAULT_SPEC_VERSION);
+ while (val)
{
- OIC_LOG(DEBUG, TAG, "Successfully converted ver cbor to bin.");
-
- //If this is owend device discovery we have to filter out the responses.
- DiscoveryInfo* pDInfo = (DiscoveryInfo*)ctx;
- res = UpdateSecVersionOfDevice(pDInfo->ppDevicesList, clientResponse->devAddr.addr,
- clientResponse->devAddr.port, ptrVer->secv);
- if (OC_STACK_OK != res)
+ if (val->type == OCREP_PROP_STRING)
{
- OIC_LOG(ERROR, TAG, "Error while getting security version.");
- DeleteVerBinData(ptrVer);
- return OC_STACK_KEEP_TRANSACTION;
+ OIC_LOG_V(DEBUG, TAG, "\t\t%s:%s", val->name, val->str);
+ if (0 == strcmp(val->name, OC_RSRVD_SPEC_VERSION))
+ {
+ OICStrcpy(specVer, SPEC_MAX_VER_LEN, val->str);
+ break;
+ }
}
-
- OIC_LOG(INFO, TAG, "= Discovered security version =");
- OIC_LOG_V(DEBUG, TAG, "IP %s", clientResponse->devAddr.addr);
- OIC_LOG_V(DEBUG, TAG, "PORT %d", clientResponse->devAddr.port);
- OIC_LOG_V(DEBUG, TAG, "VERSION %s", ptrVer->secv);
-
- OIC_LOG(INFO, TAG, "Exiting SecVersionDiscoveryHandler.");
- DeleteVerBinData(ptrVer);
+ val = val -> next;
+ }
+ //If this is owend device discovery we have to filter out the responses.
+ DiscoveryInfo* pDInfo = (DiscoveryInfo*)ctx;
+ OCStackResult res = UpdateSpecVersionOfDevice(pDInfo->ppDevicesList, clientResponse->devAddr.addr,
+ clientResponse->devAddr.port, specVer);
+ if (OC_STACK_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "Error while getting security version.");
+ return OC_STACK_KEEP_TRANSACTION;
}
+
+ OIC_LOG(INFO, TAG, "= Discovered security version =");
+ OIC_LOG_V(DEBUG, TAG, "IP %s", clientResponse->devAddr.addr);
+ OIC_LOG_V(DEBUG, TAG, "PORT %d", clientResponse->devAddr.port);
+ OIC_LOG_V(DEBUG, TAG, "VERSION %s", specVer);
}
}
else
return OC_STACK_DELETE_TRANSACTION;
}
-#endif
static OCStackApplicationResult SecurePortDiscoveryHandler(void *ctx, OCDoHandle UNUSED,
OCClientResponse *clientResponse)
pDInfo->isFound = true;
}
-/*
- * Since security version discovery does not used anymore, disable security version discovery.
- * Need to discussion to removing all version discovery related codes.
- */
-#if 0
- res = SecurityVersionDiscovery(pDInfo, clientResponse);
+ res = SpecVersionDiscovery(pDInfo, clientResponse);
if(OC_STACK_OK != res)
{
- OIC_LOG(ERROR, TAG, "Failed to SecurityVersionDiscovery");
+ OIC_LOG(ERROR, TAG, "Failed to SpecVersionDiscovery");
return OC_STACK_DELETE_TRANSACTION;
}
-#endif
+
OIC_LOG(INFO, TAG, "Exiting SecurePortDiscoveryHandler.");
}
return ret;
}
-/*
- * Since security version discovery does not used anymore, disable security version discovery.
- * Need to discussion to removing all version discovery related codes.
- */
-#if 0
-static OCStackResult SecurityVersionDiscovery(DiscoveryInfo* discoveryInfo,
+
+static OCStackResult SpecVersionDiscovery(DiscoveryInfo* discoveryInfo,
const OCClientResponse *clientResponse)
{
- OIC_LOG(DEBUG, TAG, "IN SecurityVersionDiscovery");
+ OIC_LOG(DEBUG, TAG, "IN SpecVersionDiscovery");
if(NULL == discoveryInfo || NULL == clientResponse)
{
if(!PMGenerateQuery(false,
clientResponse->devAddr.addr, clientResponse->devAddr.port,
clientResponse->connType,
- query, sizeof(query), OIC_RSRC_VER_URI))
+ query, sizeof(query), OC_RSRVD_DEVICE_URI))
{
- OIC_LOG(ERROR, TAG, "SecurityVersionDiscovery : Failed to generate query");
+ OIC_LOG(ERROR, TAG, "SpecVersionDiscovery : Failed to generate query");
return OC_STACK_ERROR;
}
OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
OCCallbackData cbData;
- cbData.cb = &SecurityVersionDiscoveryHandler;
+ cbData.cb = &SpecVersionDiscoveryHandler;
cbData.context = (void*)discoveryInfo;
cbData.cd = NULL;
OCStackResult ret = OCDoResource(NULL, OC_REST_DISCOVER, query, 0, 0,
OIC_LOG_V(INFO, TAG, "OCDoResource with [%s] Success", query);
}
- OIC_LOG(DEBUG, TAG, "OUT SecurityVersionDiscovery");
+ OIC_LOG(DEBUG, TAG, "OUT SpecVersionDiscovery");
return ret;
}
-#endif
/**
* Function to print OCProvisionDev_t for debug purpose.
return OC_STACK_INVALID_PARAM;
}
}
+ // Skip posting new DOS state in case of OIC server
+ if (IS_OIC(pTargetDev->specVer))
+ {
+ OCClientResponse clientResponse = {.result = OC_STACK_RESOURCE_CHANGED};
+ resultCallback((void*) data, NULL, &clientResponse);
+ return OC_STACK_OK;
+ }
OCStackResult res = OC_STACK_ERROR;
OicSecPstat_t *pstat = (OicSecPstat_t *) OICCalloc(1, sizeof(OicSecPstat_t));
#include "pconfresource.h"
#include "dpairingresource.h"
//#endif // DIRECT_PAIRING
-#include "verresource.h"
#define TAG "OIC_SRM_RM"
ret = InitDpairingResource();
}
//#endif // DIRECT_PAIRING
- if(OC_STACK_OK == ret)
- {
- ret = InitVerResource();
- }
if(OC_STACK_OK != ret)
{
//TODO: Update the default behavior if one of the SVR fails
DeInitPconfResource();
DeInitDpairingResource();
//#endif // DIRECT_PAIRING
- DeInitVerResource();
return OC_STACK_OK;
}
const char * OIC_SEC_REST_QUERY_SEPARATOR = ";";
char OIC_SEC_REST_QUERY_DELIMETER = '=';
-//Security Version
-const char * DEFAULT_SEC_VERSION = "0.0.0";
+//Spec Version
+const char * DEFAULT_SPEC_VERSION = "core.0.0.0";
//Preconfigured Pin credential identifier
#ifdef MULTIPLE_OWNER
+++ /dev/null
-/* *****************************************************************
- *
- * Copyright 2016 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * *****************************************************************/
-
-#include "iotivity_config.h"
-#include <stdlib.h>
-#include <string.h>
-
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-
-#include "ocstack.h"
-#include "oic_malloc.h"
-#include "oic_string.h"
-#include "logger.h"
-#include "payload_logging.h"
-#include "ocpayload.h"
-#include "ocpayloadcbor.h"
-#include "cainterface.h"
-#include "ocserverrequest.h"
-#include "resourcemanager.h"
-#include "verresource.h"
-#include "doxmresource.h"
-#include "psinterface.h"
-#include "srmresourcestrings.h"
-#include "securevirtualresourcetypes.h"
-#include "srmutility.h"
-
-#define TAG "OIC_SEC_VER"
-
-/** 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. */
-static const uint8_t CBOR_SIZE = 255;
-
-/** Max cbor size payload. */
-static const uint16_t CBOR_MAX_SIZE = 4400;
-
-/** VER Map size - Number of mandatory items. */
-static const uint8_t VER_MAP_SIZE = 2;
-
-static OCResourceHandle gVerHandle = NULL;
-
-/** Security version is mapped with iotivity release version */
-const char* SECURITY_VERSION = IOTIVITY_VERSION;
-
-static OicSecVer_t gVer =
-{
- {0}, /* char *secv */
- {.id = {0}}, /* OicUuid_t deviceID */
-};
-
-void DeleteVerBinData(OicSecVer_t* ver)
-{
- if (ver)
- {
- //Clean ver itself
- OICFree(ver);
- }
-}
-
-OCStackResult VerToCBORPayload(const OicSecVer_t *ver, uint8_t **payload, size_t *size)
-{
- if (NULL == ver || NULL == payload || NULL != *payload || NULL == size)
- {
- return OC_STACK_INVALID_PARAM;
- }
- size_t cborLen = *size;
- if (0 == cborLen)
- {
- cborLen = CBOR_SIZE;
- }
- *payload = NULL;
- *size = 0;
-
- OCStackResult ret = OC_STACK_ERROR;
-
- CborEncoder encoder;
- CborEncoder verMap;
-
- int64_t cborEncoderResult = CborNoError;
- uint8_t mapSize = VER_MAP_SIZE;
- char* strUuid = NULL;
-
- uint8_t *outPayload = (uint8_t *)OICCalloc(1, cborLen);
- VERIFY_NOT_NULL_RETURN(TAG, outPayload, ERROR, OC_STACK_ERROR);
-
- cbor_encoder_init(&encoder, outPayload, cborLen, 0);
-
- cborEncoderResult |= cbor_encoder_create_map(&encoder, &verMap, mapSize);
- VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding Ver Map.");
-
- //SecV -- Mandatory
- cborEncoderResult |= cbor_encode_text_string(&verMap, OIC_JSON_SEC_V_NAME,
- strlen(OIC_JSON_SEC_V_NAME));
- VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding SecV Tag.");
- cborEncoderResult |= cbor_encode_text_string(&verMap, ver->secv, strlen(ver->secv));
- VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding SecV Value.");
-
- //DeviceId -- Mandatory
- cborEncoderResult = cbor_encode_text_string(&verMap, OIC_JSON_DEVICE_ID_NAME,
- strlen(OIC_JSON_DEVICE_ID_NAME));
- VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding Device Id Tag.");
- ret = ConvertUuidToStr(&ver->deviceID, &strUuid);
- VERIFY_SUCCESS(TAG, OC_STACK_OK == ret , ERROR);
- cborEncoderResult = cbor_encode_text_string(&verMap, strUuid, strlen(strUuid));
- VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding Device Id Value.");
- OICFree(strUuid);
- strUuid = NULL;
-
-
- // Close ver(first) container
- cborEncoderResult |= cbor_encoder_close_container(&encoder, &verMap);
- VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Closing VerMap.");
-
- if (CborNoError == cborEncoderResult)
- {
- *size = cbor_encoder_get_buffer_size(&encoder, outPayload);
- *payload = outPayload;
- ret = OC_STACK_OK;
- }
-exit:
- if ((CborErrorOutOfMemory == cborEncoderResult) && (cborLen < CBOR_MAX_SIZE))
- {
- OIC_LOG(DEBUG, TAG, "Memory getting reallocated.");
- // reallocate and try again!
- OICFree(outPayload);
- outPayload = NULL;
- // Since the allocated initial memory failed, double the memory.
- cborLen += cbor_encoder_get_buffer_size(&encoder, encoder.end);
- OIC_LOG_V(DEBUG, TAG, "Ver reallocation size : %zd.", cborLen);
- cborEncoderResult = CborNoError;
- ret = VerToCBORPayload(ver, payload, &cborLen);
- *size = cborLen;
- }
-
- if ((CborNoError != cborEncoderResult) || (OC_STACK_OK != ret))
- {
- OICFree(outPayload);
- outPayload = NULL;
- *payload = NULL;
- *size = 0;
- ret = OC_STACK_ERROR;
- }
-
- return ret;
-}
-
-OCStackResult CBORPayloadToVer(const uint8_t *cborPayload, size_t size,
- OicSecVer_t **secVer)
-{
- if (NULL == cborPayload || NULL == secVer || NULL != *secVer || 0 == size)
- {
- return OC_STACK_INVALID_PARAM;
- }
-
- OCStackResult ret = OC_STACK_ERROR;
- *secVer = NULL;
- char *strUuid = NULL;
-
- CborParser parser = { .end = NULL};
- CborError cborFindResult = CborNoError;
- size_t len = 0;
- CborValue verCbor = { .parser = NULL };
- cbor_parser_init(cborPayload, size, 0, &parser, &verCbor);
- CborValue verMap = { .parser = NULL };
- OicSecVer_t *ver = (OicSecVer_t *)OICCalloc(1, sizeof(OicSecVer_t));
- VERIFY_NOT_NULL(TAG, ver, ERROR);
-
-
- cborFindResult = cbor_value_map_find_value(&verCbor, OIC_JSON_SEC_V_NAME, &verMap);
- if (CborNoError == cborFindResult && cbor_value_is_text_string(&verMap))
- {
- char *version = NULL;
- cborFindResult = cbor_value_dup_text_string(&verMap, &version, &len, NULL);
- VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Security Version Value.");
- if (sizeof(ver->secv) < len)
- {
- OIC_LOG (ERROR, TAG, "Version length is too long");
- OICFree(version);
- OICFree(ver);
- goto exit;
- }
- memcpy(ver->secv, version, len);
- OICFree(version);
- }
-
- cborFindResult = cbor_value_map_find_value(&verCbor, OIC_JSON_DEVICE_ID_NAME, &verMap);
- if (CborNoError == cborFindResult && cbor_value_is_text_string(&verMap))
- {
- cborFindResult = cbor_value_dup_text_string(&verMap, &strUuid , &len, NULL);
- VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Device Id Value.");
- ret = ConvertStrToUuid(strUuid , &ver->deviceID);
- VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
- OICFree(strUuid );
- strUuid = NULL;
- }
-
- *secVer = ver;
- ret = OC_STACK_OK;
-
-exit:
- if (CborNoError != cborFindResult)
- {
- OIC_LOG (ERROR, TAG, "CBORPayloadToVer failed!!!");
- DeleteVerBinData(ver);
- ret = OC_STACK_ERROR;
- }
- return ret;
-}
-
-static OCEntityHandlerResult HandleVerGetRequest (const OCEntityHandlerRequest * ehRequest)
-{
- OCEntityHandlerResult ehRet = OC_EH_OK;
-
- OIC_LOG(DEBUG, TAG, "Ver EntityHandle processing GET request");
-
- /*
- * For GET request return ver resource CBOR payload.
- * For non-valid query return NULL json payload.
- * The version is static built-in information, so VerToCBORPayload will
- * return valid ver resource json.
- */
- uint8_t *payload = NULL;
- size_t size = 0;
- if (OC_STACK_OK != VerToCBORPayload(&gVer, &payload, &size))
- {
- payload = NULL;
- }
-
- // Send response payload to request originator
- if (OC_STACK_OK != SendSRMResponse(ehRequest, ehRet, payload, size))
- {
- ehRet = OC_EH_ERROR;
- OIC_LOG(ERROR, TAG, "SendSRMResponse failed in HandleVerGetRequest");
- }
-
- OICFree(payload);
-
- return ehRet;
-}
-
-OCEntityHandlerResult VerEntityHandler(OCEntityHandlerFlag flag,
- OCEntityHandlerRequest * ehRequest,
- void* callbackParam)
-{
- (void)callbackParam;
- OCEntityHandlerResult ehRet = OC_EH_ERROR;
-
- if(NULL == ehRequest)
- {
- return ehRet;
- }
-
- if (flag & OC_REQUEST_FLAG)
- {
- OIC_LOG(DEBUG, TAG, "Flag includes OC_REQUEST_FLAG");
-
- switch (ehRequest->method)
- {
- case OC_REST_GET:
- ehRet = HandleVerGetRequest(ehRequest);
- break;
-
- default:
- ehRet = OC_EH_ERROR;
- SendSRMResponse(ehRequest, ehRet, NULL, 0);
- break;
- }
- }
-
- return ehRet;
-}
-
-OCStackResult CreateVerResource()
-{
- OCStackResult ret = OCCreateResource(&gVerHandle,
- OIC_RSRC_TYPE_SEC_VER,
- OC_RSRVD_INTERFACE_DEFAULT,
- OIC_RSRC_VER_URI,
- VerEntityHandler,
- NULL,
- OC_SECURE);
-
- if (OC_STACK_OK != ret)
- {
- OIC_LOG (FATAL, TAG, "Unable to instantiate Ver resource");
- DeInitVerResource();
- }
- return ret;
-}
-
-/**
- * Get the security version.
- *
- * @return the version string of security.
- */
-const char* GetSecVersion()
-{
- OIC_LOG(DEBUG, TAG, "GetSecVersion");
- return gVer.secv;
-}
-
-const OicSecVer_t* GetVerResourceData()
-{
- return &gVer;
-}
-
-OCStackResult InitVerResource()
-{
- OCStackResult ret = OC_STACK_ERROR;
-
- OICStrcpy(gVer.secv, OIC_SEC_MAX_VER_LEN, SECURITY_VERSION);
-
- //Read device id from doxm
- OicUuid_t deviceID = {.id={0}};
- ret = GetDoxmDeviceID(&deviceID);
- if (OC_STACK_OK != ret)
- {
- OIC_LOG(ERROR, TAG, "Error while retrieving doxm device ID");
- return ret;
- }
- memcpy(&gVer.deviceID, &deviceID, sizeof(OicUuid_t));
-
- //Instantiate 'oic.sec.ver'
- ret = CreateVerResource();
- if (OC_STACK_OK != ret)
- {
- OIC_LOG(ERROR, TAG, "Error while creating VER resource");
- }
-
- return ret;
-}
-
-OCStackResult DeInitVerResource()
-{
- OCStackResult ret = OCDeleteResource(gVerHandle);
-
- memset(&gVer, 0, sizeof(gVer));
-
- if (OC_STACK_OK == ret)
- {
- return OC_STACK_OK;
- }
- else
- {
- return OC_STACK_ERROR;
- }
-}