From fe8c63d374c0af44ebcc8dc08c2465851f9e6762 Mon Sep 17 00:00:00 2001 From: "saurabh.s9" Date: Mon, 5 Dec 2016 12:22:24 +0530 Subject: [PATCH] Adding C++ API for MOT Patch #11 Fix Review comments Changed MACRO _ENABLE_MULTIPLE_OWNER_ to MULTIPLE_OWNER and this change propagated upto C-API's. Change-Id: I55305d5cf9210b25c68f0eaf04c1362111735979 Signed-off-by: saurabh.s9 Signed-off-by: Sandeep Sharma Signed-off-by: Randeep Singh Reviewed-on: https://gerrit.iotivity.org/gerrit/14221 Tested-by: jenkins-iotivity Reviewed-by: Chul Lee Signed-off-by: saurabh.s9 Reviewed-on: https://gerrit.iotivity.org/gerrit/15145 --- android/android_api/base/jni/JniOcProvisioning.cpp | 16 +- .../csdk/connectivity/api/casecurityinterface.h | 4 +- .../csdk/connectivity/inc/ca_adapter_net_ssl.h | 2 +- resource/csdk/connectivity/src/SConscript | 2 +- .../src/adapter_util/ca_adapter_net_ssl.c | 2 +- .../csdk/connectivity/src/caconnectivitymanager.c | 4 +- resource/csdk/security/SConscript | 2 +- .../csdk/security/include/internal/aclresource.h | 4 +- .../csdk/security/include/internal/credresource.h | 4 +- .../csdk/security/include/internal/doxmresource.h | 12 +- .../csdk/security/include/internal/policyengine.h | 4 +- .../security/include/internal/srmresourcestrings.h | 16 +- resource/csdk/security/include/pinoxmcommon.h | 6 +- .../security/include/securevirtualresourcetypes.h | 28 +- resource/csdk/security/provisioning/SConscript | 2 +- .../provisioning/include/ocprovisioningmanager.h | 16 +- .../csdk/security/provisioning/include/pmutility.h | 4 +- .../csdk/security/provisioning/sample/SConscript | 2 +- .../provisioning/sample/provisioningclient.c | 48 +-- .../provisioning/sample/sampleserver_randompin.cpp | 8 +- .../security/provisioning/sample/subownerclient.c | 4 +- .../provisioning/src/ocprovisioningmanager.c | 21 +- .../provisioning/src/ownershiptransfermanager.c | 12 +- .../csdk/security/provisioning/src/oxmpreconfpin.c | 4 +- .../csdk/security/provisioning/src/oxmrandompin.c | 4 +- .../csdk/security/provisioning/src/pmutility.c | 4 +- .../csdk/security/provisioning/unittest/SConscript | 2 +- .../security/provisioning/unittest/otmunittest.cpp | 16 +- resource/csdk/security/src/aclresource.c | 24 +- resource/csdk/security/src/credresource.c | 34 +- resource/csdk/security/src/doxmresource.c | 52 +-- resource/csdk/security/src/oxmpincommon.c | 8 +- resource/csdk/security/src/policyengine.c | 8 +- resource/csdk/security/src/secureresourcemanager.c | 4 +- resource/csdk/security/src/srmresourcestrings.c | 18 +- resource/csdk/security/src/srmutility.c | 4 +- resource/csdk/security/tool/json2cbor.c | 4 +- resource/csdk/security/unittest/SConscript | 2 +- resource/include/OCProvisioningManager.h | 92 ++++- resource/provisioning/examples/SConscript | 11 +- .../examples/oic_svr_db_subowner_client.dat | Bin 0 -> 1027 bytes .../examples/oic_svr_db_subowner_client.json | 85 +++++ .../provisioning/examples/provisioningclient.cpp | 298 ++++++++++++++-- resource/provisioning/examples/subownerclient.cpp | 394 +++++++++++++++++++++ .../provisioning/src/OCProvisioningManager.cpp | 246 ++++++++++++- .../provisioning/unittests/OCProvisioningTest.cpp | 81 +++-- .../mediator/richsdk/src/EnrolleeSecurity.cpp | 12 +- 47 files changed, 1335 insertions(+), 295 deletions(-) create mode 100644 resource/provisioning/examples/oic_svr_db_subowner_client.dat create mode 100644 resource/provisioning/examples/oic_svr_db_subowner_client.json create mode 100644 resource/provisioning/examples/subownerclient.cpp mode change 100755 => 100644 resource/provisioning/unittests/OCProvisioningTest.cpp mode change 100755 => 100644 service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp diff --git a/android/android_api/base/jni/JniOcProvisioning.cpp b/android/android_api/base/jni/JniOcProvisioning.cpp index 5fe0b90..0bacfbd 100644 --- a/android/android_api/base/jni/JniOcProvisioning.cpp +++ b/android/android_api/base/jni/JniOcProvisioning.cpp @@ -70,13 +70,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_ownershipTransferCB OTMCallbackData_t CBData = {0}; if (OIC_JUST_WORKS == (OicSecOxm_t)OxmType) { - CBData.loadSecretCB = LoadSecretJustWorksCallback; - CBData.createSecureSessionCB = CreateSecureSessionJustWorksCallback; - CBData.createSelectOxmPayloadCB = CreateJustWorksSelectOxmPayload; - CBData.createOwnerTransferPayloadCB = CreateJustWorksOwnerTransferPayload; - - result = OCSecure::setOwnerTransferCallbackData((OicSecOxm_t)OxmType, - &CBData, NULL); + /*NO callback required for JUST_WORKS*/ + result = OCSecure::setInputPinCallback(NULL); } if (OIC_RANDOM_DEVICE_PIN == (OicSecOxm_t)OxmType) { @@ -84,12 +79,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_ownershipTransferCB { delete jniPinListener; jniPinListener = new JniPinCheckListener(env, jListener); - CBData.loadSecretCB = InputPinCodeCallback; - CBData.createSecureSessionCB = CreateSecureSessionRandomPinCallback; - CBData.createSelectOxmPayloadCB = CreatePinBasedSelectOxmPayload; - CBData.createOwnerTransferPayloadCB = CreatePinBasedOwnerTransferPayload; - result = OCSecure::setOwnerTransferCallbackData((OicSecOxm_t)OxmType, - &CBData, Callback); + result = OCSecure::setInputPinCallback(Callback); } else { diff --git a/resource/csdk/connectivity/api/casecurityinterface.h b/resource/csdk/connectivity/api/casecurityinterface.h index 88b8e92..1b62dba 100644 --- a/resource/csdk/connectivity/api/casecurityinterface.h +++ b/resource/csdk/connectivity/api/casecurityinterface.h @@ -67,7 +67,7 @@ typedef int (*CAgetPskCredentialsHandler)(CADtlsPskCredType_t type, uint8_t *result, size_t result_length); #if defined(__WITH_DTLS__) || defined(__WITH_TLS__) -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER /** * API to get a secure connected peer information * @@ -76,7 +76,7 @@ typedef int (*CAgetPskCredentialsHandler)(CADtlsPskCredType_t type, * @return secure connected peer information on success, otherwise NULL */ const CASecureEndpoint_t *CAGetSecureEndpointData(const CAEndpoint_t *peer); -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER #endif /** diff --git a/resource/csdk/connectivity/inc/ca_adapter_net_ssl.h b/resource/csdk/connectivity/inc/ca_adapter_net_ssl.h index d189fb3..d402284 100644 --- a/resource/csdk/connectivity/inc/ca_adapter_net_ssl.h +++ b/resource/csdk/connectivity/inc/ca_adapter_net_ssl.h @@ -172,7 +172,7 @@ CAResult_t CAsslGenerateOwnerPsk(const CAEndpoint_t *endpoint, const uint8_t* provServerDeviceId, const size_t provServerDeviceIdLen, uint8_t* ownerPsk, const size_t ownerPskSize); -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER /** * Gets CA secure endpoint info corresponding for endpoint. * diff --git a/resource/csdk/connectivity/src/SConscript b/resource/csdk/connectivity/src/SConscript index 0d519b1..006672f 100644 --- a/resource/csdk/connectivity/src/SConscript +++ b/resource/csdk/connectivity/src/SConscript @@ -88,7 +88,7 @@ if ((secured == '1') and (with_tcp == True)): env.AppendUnique(CPPDEFINES = ['__WITH_TLS__']) if (multiple_owner == '1'): - env.AppendUnique(CPPDEFINES=['_ENABLE_MULTIPLE_OWNER_']) + env.AppendUnique(CPPDEFINES=['MULTIPLE_OWNER']) ca_common_src = None diff --git a/resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c b/resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c index a755ce0..5f9bd76 100644 --- a/resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c +++ b/resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c @@ -792,7 +792,7 @@ static SslEndPoint_t *GetSslPeer(const CAEndpoint_t *peer) return NULL; } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER /** * Gets CA secure endpoint info corresponding for endpoint. * diff --git a/resource/csdk/connectivity/src/caconnectivitymanager.c b/resource/csdk/connectivity/src/caconnectivitymanager.c index c9bfab1..a5dbf2b 100644 --- a/resource/csdk/connectivity/src/caconnectivitymanager.c +++ b/resource/csdk/connectivity/src/caconnectivitymanager.c @@ -143,7 +143,7 @@ void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHand } #if defined(__WITH_DTLS__) || defined(__WITH_TLS__) -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER const CASecureEndpoint_t *CAGetSecureEndpointData(const CAEndpoint_t *peer) { OIC_LOG(DEBUG, TAG, "IN CAGetSecurePeerInfo"); @@ -157,7 +157,7 @@ const CASecureEndpoint_t *CAGetSecureEndpointData(const CAEndpoint_t *peer) OIC_LOG(DEBUG, TAG, "OUT CAGetSecurePeerInfo"); return GetCASecureEndpointData(peer); } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER CAResult_t CAregisterSslHandshakeCallback(CAErrorCallback tlsHandshakeCallback) { diff --git a/resource/csdk/security/SConscript b/resource/csdk/security/SConscript index c399dda..f0b347b 100644 --- a/resource/csdk/security/SConscript +++ b/resource/csdk/security/SConscript @@ -88,7 +88,7 @@ if env.get('LOGGING'): libocsrm_env.AppendUnique(CPPDEFINES = ['TB_LOG']) if env.get('MULTIPLE_OWNER') == '1': - libocsrm_env.AppendUnique(CPPDEFINES=['_ENABLE_MULTIPLE_OWNER_']) + libocsrm_env.AppendUnique(CPPDEFINES=['MULTIPLE_OWNER']) ###################################################################### # Source files and Targets diff --git a/resource/csdk/security/include/internal/aclresource.h b/resource/csdk/security/include/internal/aclresource.h index db09e46..0172ae4 100644 --- a/resource/csdk/security/include/internal/aclresource.h +++ b/resource/csdk/security/include/internal/aclresource.h @@ -62,7 +62,7 @@ const OicSecAce_t* GetACLResourceData(const OicUuid_t* subjectId, OicSecAce_t ** */ OCStackResult AclToCBORPayload(const OicSecAcl_t * acl, uint8_t **outPayload, size_t *size); -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER /** * Function to check the ACL access of SubOwner * @@ -73,7 +73,7 @@ OCStackResult AclToCBORPayload(const OicSecAcl_t * acl, uint8_t **outPayload, si * @return ::true for valid access, otherwise invalid access */ bool IsValidAclAccessForSubOwner(const OicUuid_t* uuid, const uint8_t *cborPayload, const size_t size); -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER /** diff --git a/resource/csdk/security/include/internal/credresource.h b/resource/csdk/security/include/internal/credresource.h index 32ccefe..9a9a0ff 100644 --- a/resource/csdk/security/include/internal/credresource.h +++ b/resource/csdk/security/include/internal/credresource.h @@ -82,7 +82,7 @@ OicSecCred_t* GetCredEntryByCredId(const uint16_t credId); OCStackResult CredToCBORPayload(const OicSecCred_t* cred, uint8_t **cborPayload, size_t *cborSize, int secureFlag); -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER /** * Function to check the credential access of SubOwner * @@ -93,7 +93,7 @@ OCStackResult CredToCBORPayload(const OicSecCred_t* cred, uint8_t **cborPayload, * @return ::true for valid access, otherwise invalid access */ bool IsValidCredentialAccessForSubOwner(const OicUuid_t* uuid, const uint8_t *cborPayload, size_t size); -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER /** * This function generates the bin credential data. diff --git a/resource/csdk/security/include/internal/doxmresource.h b/resource/csdk/security/include/internal/doxmresource.h index 826c187..fa37070 100644 --- a/resource/csdk/security/include/internal/doxmresource.h +++ b/resource/csdk/security/include/internal/doxmresource.h @@ -22,9 +22,9 @@ #define IOTVT_SRM_DOXM_H #include "octypes.h" -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER #include "cacommon.h" -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER #ifdef __cplusplus extern "C" { @@ -121,7 +121,7 @@ OCStackResult GetDoxmIsOwned(bool *isOwned); */ OCStackResult GetDoxmRownerId(OicUuid_t *rowneruuid); -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER /** * Compare the UUID to SubOwner. * @@ -130,7 +130,7 @@ OCStackResult GetDoxmRownerId(OicUuid_t *rowneruuid); * @return true if uuid exists in the SubOwner list of doxm, else false. */ bool IsSubOwner(const OicUuid_t* uuid); -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER /** This function deallocates the memory for OicSecDoxm_t . * @@ -144,7 +144,7 @@ void DeleteDoxmBinData(OicSecDoxm_t* doxm); */ void RestoreDoxmToInitState(); -#if defined(__WITH_DTLS__) && defined(_ENABLE_MULTIPLE_OWNER_) +#if defined(__WITH_DTLS__) && defined(MULTIPLE_OWNER) /** * Callback function to handle MOT DTLS handshake result. * @param[out] object remote device information. @@ -152,7 +152,7 @@ void RestoreDoxmToInitState(); */ void MultipleOwnerDTLSHandshakeCB(const CAEndpoint_t *object, const CAErrorInfo_t *errorInfo); -#endif //__WITH_DTLS__ && _ENABLE_MULTIPLE_OWNER_ +#endif //__WITH_DTLS__ && MULTIPLE_OWNER #ifdef __cplusplus } diff --git a/resource/csdk/security/include/internal/policyengine.h b/resource/csdk/security/include/internal/policyengine.h index 66b399c..83841c1 100644 --- a/resource/csdk/security/include/internal/policyengine.h +++ b/resource/csdk/security/include/internal/policyengine.h @@ -50,10 +50,10 @@ typedef struct PEContext SRMAccessResponse_t retVal; AmsMgrContext_t *amsMgrContext; -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER uint8_t* payload; size_t payloadSize; -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER } PEContext_t; /** diff --git a/resource/csdk/security/include/internal/srmresourcestrings.h b/resource/csdk/security/include/internal/srmresourcestrings.h index 3a35e28..5dbf7e0 100644 --- a/resource/csdk/security/include/internal/srmresourcestrings.h +++ b/resource/csdk/security/include/internal/srmresourcestrings.h @@ -101,15 +101,15 @@ extern const char * OIC_JSON_PERMISSION_NAME; extern const char * OIC_JSON_OWNERS_NAME; extern const char * OIC_JSON_OWNER_NAME; extern const char * OIC_JSON_DEVOWNERID_NAME; -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER extern const char * OIC_JSON_SUBOWNERID_NAME; -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER extern const char * OIC_JSON_OWNED_NAME; extern const char * OIC_JSON_OXM_NAME; extern const char * OIC_JSON_OXMS_NAME; -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER extern const char * OIC_JSON_MOM_NAME; -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER extern const char * OIC_JSON_OXM_TYPE_NAME; extern const char * OIC_JSON_OXM_SEL_NAME; extern const char * OIC_JSON_DEVICE_ID_FORMAT_NAME; @@ -152,9 +152,9 @@ extern const char * OIC_JSON_REL_NAME; extern const char * OIC_JSON_RT_NAME; extern const char * OIC_JSON_IF_NAME; extern const char * OIC_JSON_ROWNERID_NAME; -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER extern const char * OIC_JSON_EOWNERID_NAME; -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER extern const char * OIC_JSON_ENCODING_NAME; extern const char * OIC_JSON_DATA_NAME; extern const char * OIC_JSON_SEC_V_NAME; @@ -178,9 +178,9 @@ extern const char * WILDCARD_RESOURCE_URI; extern const char * OXM_JUST_WORKS; extern const char * OXM_RANDOM_DEVICE_PIN; extern const char * OXM_MANUFACTURER_CERTIFICATE; -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER extern const char * OXM_PRECONF_PIN; -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER extern const char * OIC_SEC_ENCODING_BASE64; extern const char * OIC_SEC_ENCODING_RAW; diff --git a/resource/csdk/security/include/pinoxmcommon.h b/resource/csdk/security/include/pinoxmcommon.h index 52e411f..c624117 100644 --- a/resource/csdk/security/include/pinoxmcommon.h +++ b/resource/csdk/security/include/pinoxmcommon.h @@ -105,7 +105,7 @@ OCStackResult GeneratePin(char* pinBuffer, size_t bufferSize); */ OCStackResult InputPin(char* pinBuffer, size_t bufferSize); -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER /** * Function to save the Pre-configured PIN. * @@ -153,7 +153,7 @@ int32_t GetDtlsPskForRandomPinOxm( CADtlsPskCredType_t type, const unsigned char *UNUSED1, size_t UNUSED2, unsigned char *result, size_t result_length); -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER /** * This internal callback is used while Random PIN based MOT. * This callback will be used to establish a temporary secure session according to @@ -210,7 +210,7 @@ int32_t GetDtlsPskForMotPreconfPinOxm( CADtlsPskCredType_t type, const unsigned char *UNUSED1, size_t UNUSED2, unsigned char *result, size_t result_length); -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER /** diff --git a/resource/csdk/security/include/securevirtualresourcetypes.h b/resource/csdk/security/include/securevirtualresourcetypes.h index 0f2ac78..3a48a18 100644 --- a/resource/csdk/security/include/securevirtualresourcetypes.h +++ b/resource/csdk/security/include/securevirtualresourcetypes.h @@ -219,7 +219,7 @@ typedef enum OicSecDpm SECURITY_MANAGEMENT_SERVICES = (0x1 << 3), PROVISION_CREDENTIALS = (0x1 << 4), PROVISION_ACLS = (0x1 << 5), -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER TAKE_SUB_OWNER = (0x1 << 6), #endif // << 7 THROUGH 15 RESERVED @@ -273,9 +273,9 @@ typedef enum OIC_MANUFACTURER_CERTIFICATE = 0x2, OIC_DECENTRALIZED_PUBLIC_KEY = 0x3, OIC_OXM_COUNT, -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER OIC_PRECONFIG_PIN = 0xFF00, -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER }OicSecOxm_t; typedef enum @@ -287,14 +287,14 @@ typedef enum OIC_ENCODING_DER = 4 }OicEncodingType_t; -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER typedef enum { MOT_STATUS_READY = 0, MOT_STATUS_IN_PROGRESS = 1, MOT_STATUS_DONE = 2, }MotStatus_t; -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER /* * oic.sec.mom type definition @@ -325,10 +325,10 @@ typedef char *OicUrn_t; //TODO is URN type defined elsewhere? typedef struct OicUuid OicUuid_t; //TODO is UUID type defined elsewhere? -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER typedef struct OicSecSubOwner OicSecSubOwner_t; typedef struct OicSecMom OicSecMom_t; -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER #if defined(__WITH_DTLS__) || defined(__WITH_TLS__) @@ -395,7 +395,7 @@ struct OicSecAce OicSecRsrc_t *resources; // 1:R:M:Y:Resource uint16_t permission; // 2:R:S:Y:UINT16 OicSecValidity_t *validities; // 3:R:M:N:Time-interval -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER OicUuid_t* eownerID; //4:R:S:N:oic.uuid #endif OicSecAce_t *next; @@ -449,13 +449,13 @@ struct OicSecCred OicSecKey_t privateData; // 6:R:S:N:oic.sec.key char *period; // 7:R:S:N:String OicUuid_t rownerID; // 8:R:S:Y:oic.uuid -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER OicUuid_t *eownerID; //9:R:S:N:oic.uuid -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER OicSecCred_t *next; }; -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER struct OicSecSubOwner { OicUuid_t uuid; MotStatus_t status; @@ -465,7 +465,7 @@ struct OicSecSubOwner { struct OicSecMom{ OicSecMomType_t mode; }; -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER /** * /oic/sec/doxm (Device Owner Transfer Methods) data type @@ -486,10 +486,10 @@ struct OicSecDoxm OicUuid_t deviceID; // 6:R:S:Y:oic.uuid bool dpc; // 7:R:S:Y:Boolean OicUuid_t owner; // 8:R:S:Y:oic.uuid -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER OicSecSubOwner_t* subOwners; //9:R/W:M:N:oic.uuid OicSecMom_t *mom; //10:R/W:S:N:oic.sec.mom -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER OicUuid_t rownerID; // 11:R:S:Y:oic.uuid }; diff --git a/resource/csdk/security/provisioning/SConscript b/resource/csdk/security/provisioning/SConscript index 8aab750..560f656 100644 --- a/resource/csdk/security/provisioning/SConscript +++ b/resource/csdk/security/provisioning/SConscript @@ -89,7 +89,7 @@ if provisioning_env.get('LOGGING'): provisioning_env.AppendUnique(CPPDEFINES = ['TB_LOG']) if provisioning_env.get('MULTIPLE_OWNER') == '1': - provisioning_env.AppendUnique(CPPDEFINES=['_ENABLE_MULTIPLE_OWNER_']) + provisioning_env.AppendUnique(CPPDEFINES=['MULTIPLE_OWNER']) ###################################################################### # Source files and Targets diff --git a/resource/csdk/security/provisioning/include/ocprovisioningmanager.h b/resource/csdk/security/provisioning/include/ocprovisioningmanager.h index 7a4f289..973dfb9 100644 --- a/resource/csdk/security/provisioning/include/ocprovisioningmanager.h +++ b/resource/csdk/security/provisioning/include/ocprovisioningmanager.h @@ -24,9 +24,9 @@ #include "octypes.h" #include "pmtypes.h" #include "ownershiptransfermanager.h" -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER #include "securevirtualresourcetypes.h" -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER #ifdef __cplusplus extern "C" { @@ -91,7 +91,7 @@ OCStackResult OCDoOwnershipTransfer(void* ctx, */ OCStackResult OCSetOxmAllowStatus(const OicSecOxm_t oxm, const bool allowStatus); -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER /** * API to perfrom multiple ownership transfer for MOT enabled device. * @@ -103,7 +103,7 @@ OCStackResult OCSetOxmAllowStatus(const OicSecOxm_t oxm, const bool allowStatus) OCStackResult OCDoMultipleOwnershipTransfer(void* ctx, OCProvisionDev_t *targetDevices, OCProvisionResultCB resultCallback); -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER /** * API to register for particular OxM. @@ -125,7 +125,7 @@ OCStackResult OCSetOwnerTransferCallbackData(OicSecOxm_t oxm, OTMCallbackData_t* */ OCStackResult OCDiscoverOwnedDevices(unsigned short timeout, OCProvisionDev_t **ppList); -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER /** * The function is responsible for discovery of MOT enabled device is current subnet. * @@ -145,7 +145,7 @@ OCStackResult OCDiscoverMultipleOwnerEnabledDevices(unsigned short timeout, OCPr * @return OC_STACK_OK in case of success and other value otherwise. */ OCStackResult OCDiscoverMultipleOwnedDevices(unsigned short timeout, OCProvisionDev_t **ppList); -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER /** * API to provision credentials between two devices and ACLs for the devices who act as a server. @@ -239,7 +239,7 @@ OCStackResult OCProvisionCredentials(void *ctx, OicSecCredType_t type, size_t ke const OCProvisionDev_t *pDev2, OCProvisionResultCB resultCallback); -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER /** * API to provision preconfigured PIN to device(NOT LIST). * If device does not support the Preconfigured PIN OxM, @@ -295,7 +295,7 @@ OCStackResult OCChangeMOTMode(void *ctx, const OCProvisionDev_t *targetDeviceInf */ OCStackResult OCSelectMOTMethod(void *ctx, const OCProvisionDev_t *targetDeviceInfo, const OicSecOxm_t oxmSelValue, OCProvisionResultCB resultCallback); -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER /** * Function to unlink devices. diff --git a/resource/csdk/security/provisioning/include/pmutility.h b/resource/csdk/security/provisioning/include/pmutility.h index 897ee94..2fd8e9c 100644 --- a/resource/csdk/security/provisioning/include/pmutility.h +++ b/resource/csdk/security/provisioning/include/pmutility.h @@ -67,7 +67,7 @@ OCStackResult PMSingleDeviceDiscovery(unsigned short waittime, const OicUuid_t* */ OCStackResult PMDeviceDiscovery(unsigned short waittime, bool isOwned, OCProvisionDev_t **ppList); -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER /** * Discover multiple OTM enabled devices in the same IP subnet. * @@ -78,7 +78,7 @@ OCStackResult PMDeviceDiscovery(unsigned short waittime, bool isOwned, OCProvisi * @return OC_STACK_OK on success otherwise error. */ OCStackResult PMMultipleOwnerDeviceDiscovery(unsigned short waittime, bool isMultipleOwned, OCProvisionDev_t **ppDevicesList); -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER /** * This function deletes list of provision target devices diff --git a/resource/csdk/security/provisioning/sample/SConscript b/resource/csdk/security/provisioning/sample/SConscript index 5f2fe11..947182d 100644 --- a/resource/csdk/security/provisioning/sample/SConscript +++ b/resource/csdk/security/provisioning/sample/SConscript @@ -86,7 +86,7 @@ if env.get('SECURED') == '1': if env.get('MULTIPLE_OWNER') == '1': - provisioning_env.AppendUnique(CPPDEFINES = ['_ENABLE_MULTIPLE_OWNER_']) + provisioning_env.AppendUnique(CPPDEFINES = ['MULTIPLE_OWNER']) provisioning_env.AppendUnique(CPPDEFINES = ['TB_LOG']) diff --git a/resource/csdk/security/provisioning/sample/provisioningclient.c b/resource/csdk/security/provisioning/sample/provisioningclient.c index 6b90720..db31e88 100644 --- a/resource/csdk/security/provisioning/sample/provisioningclient.c +++ b/resource/csdk/security/provisioning/sample/provisioningclient.c @@ -47,9 +47,9 @@ extern "C" #define _10_DISCOV_ALL_DEVS_ 10 #define _11_DISCOV_UNOWN_DEVS_ 11 #define _12_DISCOV_OWN_DEVS_ 12 -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER #define _13_MOT_DISCOV_DEV_ 13 -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER #define _20_REGIST_DEVS_ 20 #define _30_PROVIS_PAIR_DEVS_ 30 #define _31_PROVIS_CRED_ 31 @@ -63,11 +63,11 @@ extern "C" #define _52_RESET_SELEC_DEV_ 52 #define _60_GET_CRED_ 60 #define _61_GET_ACL_ 61 -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER #define _70_MOT_CHANGE_MOM_ 70 #define _71_MOT_PROV_PRECONF_PIN_ 71 #define _72_MOT_OXM_SEL_ 72 -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER #define _80_SELECT_PROTOCOL_ 80 #define _99_EXIT_PRVN_CLT_ 99 @@ -98,10 +98,10 @@ static OCProvisionDev_t* g_own_list; static OCProvisionDev_t* g_unown_list; static int g_own_cnt; static int g_unown_cnt; -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER static OCProvisionDev_t* g_mot_enable_list; static int g_mot_enable_cnt; -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER static bool g_doneCB; #ifdef __WITH_TLS__ @@ -262,7 +262,7 @@ static void syncDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool h g_doneCB = true; } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER static void updateDoxmForMOTCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) { if(!hasError) @@ -276,7 +276,7 @@ static void updateDoxmForMOTCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, } g_doneCB = true; } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER static void inputPinCB(char* pin, size_t len) { @@ -431,7 +431,7 @@ static int discoverOwnedDevices(void) return 0; } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER static int discoverMOTEnabledDevices(void) { // delete owned device list before updating it @@ -455,7 +455,7 @@ static int discoverMOTEnabledDevices(void) return 0; } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER static int registerDevices(void) { @@ -1206,7 +1206,7 @@ static int removeDeviceWithUuid(void) return 0; } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER static int changeMultipleOwnershipTrnasferMode(void) { // check |own_list| for removing device @@ -1402,7 +1402,7 @@ static int provisionPreconfigPIN() return 0; } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER static int resetDevice(void) { @@ -2018,12 +2018,12 @@ static void printMenu(void) printf("** [A] DISCOVER DEVICES ON NETWORK\n"); printf("** 10. Discover All Un/Owned Devices on Network\n"); printf("** 11. Discover Only Unowned Devices on Network\n"); -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER printf("** 12. Discover Only Owned Devices on Network\n"); printf("** 13. Discover Multiple Ownership Transfer Enabled Devices on Network\n\n"); #else printf("** 12. Discover Only Owned Devices on Network\n\n"); -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER printf("** [B] REGISTER/OWN ALL DISCOVERED UNOWNED DEVICES\n"); printf("** 20. Register/Own All Discovered Unowned Devices\n\n"); @@ -2048,12 +2048,12 @@ static void printMenu(void) printf("** 60. Get the Credential resources of the Selected Device\n"); printf("** 61. Get the ACL resources of the Selected Device\n\n"); -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER printf("** [G] UPDATE THE MULTIPLE OWNERSHIP TRANSFER RELATED VALUE\n"); printf("** 70. Change the Multiple Ownership transfer MODE(update mom)\n"); printf("** 71. Provision Preconfigured PIN\n"); printf("** 72. Change the Multiple Ownership transfer METHOD(update oxmsel)\n\n"); -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER #ifdef __WITH_TLS__ printf("** [H] SELECT SECURE PROTOCOL DTLS/TLS\n"); @@ -2105,9 +2105,9 @@ int main() OIC_LOG(WARNING, TAG, "Failed to disable OIC_DECENTRALIZED_PUBLIC_KEY OxM"); } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER SetPreconfigPin("12341234", 8); -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER // main loop for provisioning manager int mn_num = 0; @@ -2143,14 +2143,14 @@ int main() OIC_LOG(ERROR, TAG, "_12_DISCOV_OWN_DEVS_: error"); } break; -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER case _13_MOT_DISCOV_DEV_: if(discoverMOTEnabledDevices()) { OIC_LOG(ERROR, TAG, "_13_MOT_DISCOV_DEV_: error"); } break; -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER case _20_REGIST_DEVS_: if(registerDevices()) { @@ -2229,7 +2229,7 @@ int main() OIC_LOG(ERROR, TAG, "_61_GET_ACL_: error"); } break; -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER case _70_MOT_CHANGE_MOM_: if(changeMultipleOwnershipTrnasferMode()) { @@ -2248,7 +2248,7 @@ int main() OIC_LOG(ERROR, TAG, "_72_MOT_OXM_SEL_: error"); } break; -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER #ifdef __WITH_TLS__ case _80_SELECT_PROTOCOL_: selectSecureProtocol(); @@ -2269,9 +2269,9 @@ PMCLT_ERROR: } OCDeleteDiscoveredDevices(g_own_list); // after here |g_own_list| points nothing OCDeleteDiscoveredDevices(g_unown_list); // after here |g_unown_list| points nothing -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER OCDeleteDiscoveredDevices(g_mot_enable_list); // after here |g_motdev_list| points nothing -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER if(g_svr_fname) { diff --git a/resource/csdk/security/provisioning/sample/sampleserver_randompin.cpp b/resource/csdk/security/provisioning/sample/sampleserver_randompin.cpp index 81b07c4..a7caaa2 100644 --- a/resource/csdk/security/provisioning/sample/sampleserver_randompin.cpp +++ b/resource/csdk/security/provisioning/sample/sampleserver_randompin.cpp @@ -142,7 +142,7 @@ const char *getResult(OCStackResult result) { } } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER #include #include @@ -177,7 +177,7 @@ static void StopOCProcessThread() g_LoopFlag = false; oc_process_thread->join(); } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER OCRepPayload* getPayload(const char* uri, int64_t power, bool state) { @@ -500,7 +500,7 @@ int main() OIC_LOG(INFO, TAG, "Entering ocserver main loop..."); signal(SIGINT, handleSigInt); -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER StartOCProcessThread(); while(!gQuitFlag) @@ -534,7 +534,7 @@ int main() } nanosleep(&timeout, NULL); } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER OIC_LOG(INFO, TAG, "Exiting ocserver main loop..."); diff --git a/resource/csdk/security/provisioning/sample/subownerclient.c b/resource/csdk/security/provisioning/sample/subownerclient.c index 1cdb604..d3456ef 100644 --- a/resource/csdk/security/provisioning/sample/subownerclient.c +++ b/resource/csdk/security/provisioning/sample/subownerclient.c @@ -321,7 +321,7 @@ static int multipleOwnershipTransfer(void) // for error checking, the return value saved and printed g_doneCB = false; -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER OCProvisionDev_t* dev = NULL; LL_FOREACH(g_motdev_list, dev) { @@ -337,7 +337,7 @@ static int multipleOwnershipTransfer(void) } } } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER if(OC_STACK_OK != OCDoMultipleOwnershipTransfer(g_ctx, g_motdev_list, multipleOwnershipTransferCB)) { diff --git a/resource/csdk/security/provisioning/src/ocprovisioningmanager.c b/resource/csdk/security/provisioning/src/ocprovisioningmanager.c index b538ace..1dfc8c2 100644 --- a/resource/csdk/security/provisioning/src/ocprovisioningmanager.c +++ b/resource/csdk/security/provisioning/src/ocprovisioningmanager.c @@ -24,9 +24,9 @@ #include "pmutility.h" #include "srmutility.h" #include "ownershiptransfermanager.h" -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER #include "multipleownershiptransfermanager.h" -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER #include "oic_malloc.h" #include "logger.h" #include "secureresourceprovider.h" @@ -53,7 +53,7 @@ struct Linkdata }; -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER typedef struct ProvPreconfPINCtx ProvPreconfPINCtx_t; struct ProvPreconfPINCtx { @@ -63,7 +63,7 @@ struct ProvPreconfPINCtx size_t pinLen; OCProvisionResultCB resultCallback; }; -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER /** * The function is responsible for initializaton of the provisioning manager. It will load @@ -140,7 +140,7 @@ OCStackResult OCDiscoverOwnedDevices(unsigned short timeout, OCProvisionDev_t ** return PMDeviceDiscovery(timeout, true, ppList); } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER /** * The function is responsible for discovery of MOT enabled device is current subnet. * @@ -208,7 +208,8 @@ OCStackResult OCDoMultipleOwnershipTransfer(void* ctx, } return MOTDoOwnershipTransfer(ctx, targetDevices, resultCallback); } -#endif //_ENABLE_MULTIPLE_OWNER_ + +#endif //MULTIPLE_OWNER /** * API to register for particular OxM. @@ -366,7 +367,7 @@ OCStackResult OCProvisionDirectPairing(void* ctx, const OCProvisionDev_t *select return SRPProvisionDirectPairing(ctx, selectedDeviceInfo, pconf, resultCallback); } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER static void AddPreconfPinOxMCB(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool hasError) { ProvPreconfPINCtx_t* provCtx = (ProvPreconfPINCtx_t*)ctx; @@ -416,7 +417,7 @@ OCStackResult OCProvisionPreconfigPin(void *ctx, */ return MOTAddMOTMethod((void*)provCtx, targetDeviceInfo, OIC_PRECONFIG_PIN, AddPreconfPinOxMCB); } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER /* * Function to unlink devices. @@ -1237,7 +1238,7 @@ void OCDeletePdAclList(OicSecPdAcl_t* pPdAcl) FreePdAclList(pPdAcl); } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER /** * API to update 'doxm.mom' to resource server. * @@ -1267,7 +1268,7 @@ OCStackResult OCSelectMOTMethod(void *ctx, const OCProvisionDev_t *targetDeviceI { return MOTSelectMOTMethod(ctx, targetDeviceInfo, oxmSelValue, resultCallback); } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER #if defined(__WITH_DTLS__) || defined(__WITH_TLS__) /** diff --git a/resource/csdk/security/provisioning/src/ownershiptransfermanager.c b/resource/csdk/security/provisioning/src/ownershiptransfermanager.c index 36f88f5..5e3b2f3 100644 --- a/resource/csdk/security/provisioning/src/ownershiptransfermanager.c +++ b/resource/csdk/security/provisioning/src/ownershiptransfermanager.c @@ -61,9 +61,9 @@ #include "oxmjustworks.h" #include "oxmrandompin.h" #include "oxmmanufacturercert.h" -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER #include "oxmpreconfpin.h" -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER #include "otmcontextlist.h" #include "pmtypes.h" #include "pmutility.h" @@ -97,11 +97,11 @@ OCStackResult OTMSetOTCallback(OicSecOxm_t oxm, OTMCallbackData_t* callbacks) OIC_LOG(INFO, TAG, "IN OTMSetOTCallback"); VERIFY_NON_NULL(TAG, callbacks, ERROR); -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER VERIFY_SUCCESS(TAG, (OIC_OXM_COUNT > oxm || OIC_PRECONFIG_PIN == oxm), ERROR); #else VERIFY_SUCCESS(TAG, (OIC_OXM_COUNT > oxm), ERROR); -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER switch(oxm) { @@ -126,14 +126,14 @@ OCStackResult OTMSetOTCallback(OicSecOxm_t oxm, OTMCallbackData_t* callbacks) case OIC_DECENTRALIZED_PUBLIC_KEY: OIC_LOG(ERROR, TAG, "OIC_DECENTRALIZED_PUBLIC_KEY not supported yet."); return OC_STACK_INVALID_METHOD; -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER case OIC_PRECONFIG_PIN: callbacks->loadSecretCB = LoadPreconfigPinCodeCallback; callbacks->createSecureSessionCB = CreateSecureSessionPreconfigPinCallback; callbacks->createSelectOxmPayloadCB = CreatePreconfigPinBasedSelectOxmPayload; callbacks->createOwnerTransferPayloadCB = CreatePreconfigPinBasedOwnerTransferPayload; break; -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER default: OIC_LOG_V(ERROR, TAG, "Unknown OxM : %d", (int)oxm); return OC_STACK_INVALID_PARAM; diff --git a/resource/csdk/security/provisioning/src/oxmpreconfpin.c b/resource/csdk/security/provisioning/src/oxmpreconfpin.c index ecdeb35..723c5e9 100644 --- a/resource/csdk/security/provisioning/src/oxmpreconfpin.c +++ b/resource/csdk/security/provisioning/src/oxmpreconfpin.c @@ -146,7 +146,7 @@ OCStackResult LoadPreconfigPinCodeCallback(OTMContext_t *otmCtx) res = OC_STACK_ERROR; } } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER //in case of MOT else if(true == otmCtx->selectedDeviceInfo->doxm->owned && otmCtx->selectedDeviceInfo->doxm->mom && @@ -158,7 +158,7 @@ OCStackResult LoadPreconfigPinCodeCallback(OTMContext_t *otmCtx) res = OC_STACK_ERROR; } } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER //Set the device id to derive temporal PSK SetUuidForPinBasedOxm(&(otmCtx->selectedDeviceInfo->doxm->deviceID)); diff --git a/resource/csdk/security/provisioning/src/oxmrandompin.c b/resource/csdk/security/provisioning/src/oxmrandompin.c index dcf7214..19e8019 100644 --- a/resource/csdk/security/provisioning/src/oxmrandompin.c +++ b/resource/csdk/security/provisioning/src/oxmrandompin.c @@ -101,7 +101,7 @@ OCStackResult InputPinCodeCallback(OTMContext_t *otmCtx) res = OC_STACK_ERROR; } } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER //in case of MOT else if(otmCtx->selectedDeviceInfo->doxm->owned && otmCtx->selectedDeviceInfo->doxm->mom && @@ -113,7 +113,7 @@ OCStackResult InputPinCodeCallback(OTMContext_t *otmCtx) res = OC_STACK_ERROR; } } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER //Set the device id to derive temporal PSK SetUuidForPinBasedOxm(&(otmCtx->selectedDeviceInfo->doxm->deviceID)); diff --git a/resource/csdk/security/provisioning/src/pmutility.c b/resource/csdk/security/provisioning/src/pmutility.c index 8cd3d0f..d5e2e01 100644 --- a/resource/csdk/security/provisioning/src/pmutility.c +++ b/resource/csdk/security/provisioning/src/pmutility.c @@ -999,7 +999,7 @@ OCStackResult PMDeviceDiscovery(unsigned short waittime, bool isOwned, OCProvisi return res; } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER static OCStackApplicationResult MOTDeviceDiscoveryHandler(void *ctx, OCDoHandle UNUSED, OCClientResponse *clientResponse) { @@ -1232,7 +1232,7 @@ OCStackResult PMMultipleOwnerDeviceDiscovery(unsigned short waittime, bool isMul return res; } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER static OCStackResult SecurePortDiscovery(DiscoveryInfo* discoveryInfo, const OCClientResponse *clientResponse) diff --git a/resource/csdk/security/provisioning/unittest/SConscript b/resource/csdk/security/provisioning/unittest/SConscript index cdfdecc..2e02697 100644 --- a/resource/csdk/security/provisioning/unittest/SConscript +++ b/resource/csdk/security/provisioning/unittest/SConscript @@ -77,7 +77,7 @@ if not sptest_env.get('RELEASE'): sptest_env.AppendUnique(CPPDEFINES = ['TB_LOG']) if sptest_env.get('MULTIPLE_OWNER') == '1': - sptest_env.AppendUnique(CPPDEFINES=['_ENABLE_MULTIPLE_OWNER_']) + sptest_env.AppendUnique(CPPDEFINES=['MULTIPLE_OWNER']) if target_os in ['msys_nt', 'windows']: sptest_env.AppendUnique(LIBS = ['ws2_32', diff --git a/resource/csdk/security/provisioning/unittest/otmunittest.cpp b/resource/csdk/security/provisioning/unittest/otmunittest.cpp index 69c4c67..1bbcfa7 100644 --- a/resource/csdk/security/provisioning/unittest/otmunittest.cpp +++ b/resource/csdk/security/provisioning/unittest/otmunittest.cpp @@ -32,9 +32,9 @@ #include "oxmmanufacturercert.h" #include "securevirtualresourcetypes.h" #include "provisioningdatabasemanager.h" -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER #include "multipleownershiptransfermanager.h" -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER #include "srmutility.h" #include "doxmresource.h" #include "pmtypes.h" @@ -240,10 +240,10 @@ static pid_t g_myPID2; static const char* g_otmCtx = "Test User Context"; static OCProvisionDev_t* g_unownedDevices = NULL; static OCProvisionDev_t* g_ownedDevices = NULL; -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER static OCProvisionDev_t* g_motEnabledDevices = NULL; static OCProvisionDev_t* g_multiplOwnedDevices = NULL; -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER static void GetCurrentWorkingDirectory(char* buf, size_t bufsize) { @@ -303,7 +303,7 @@ static void ownershipTransferCB(void* ctx, int UNUSED1, OCProvisionResult_t* UNU g_doneCB = true; } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER static void updateDoxmForMOTCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) { if(!hasError) @@ -331,7 +331,7 @@ static void provisionPreconfiguredPinCB(void* ctx, int nOfRes, OCProvisionResult g_callbackResult = !hasError; g_doneCB = true; } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER // callback function(s) for provisioning client using C-level provisioning API static void removeDeviceCB(void* ctx, int UNUSED1, OCProvisionResult_t* UNUSED2, bool hasError) @@ -646,7 +646,7 @@ TEST(PerformUnlinkDevices, NullParam) EXPECT_EQ(OC_STACK_OK, result); } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER TEST(RegisterPreconfiguredPIN, NullParam) { OCStackResult result = SetPreconfigPin("12341234", strlen("12341234")); @@ -759,7 +759,7 @@ TEST(DiscoverMultipleOwnedDevices, NullParam) EXPECT_TRUE(NULL != g_multiplOwnedDevices); }*/ -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER TEST(PerformRemoveDevice, NullParam) { diff --git a/resource/csdk/security/src/aclresource.c b/resource/csdk/security/src/aclresource.c index 94118bc..83e4e58 100644 --- a/resource/csdk/security/src/aclresource.c +++ b/resource/csdk/security/src/aclresource.c @@ -132,7 +132,7 @@ static void FreeACE(OicSecAce_t *ace) validity = NULL; } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER OICFree(ace->eownerID); #endif @@ -256,7 +256,7 @@ OicSecAce_t* DuplicateACE(const OicSecAce_t* ace) } } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER if (ace->eownerID) { if (NULL == newAce->eownerID) @@ -364,12 +364,12 @@ OCStackResult AclToCBORPayload(const OicSecAcl_t *secAcl, uint8_t **payload, siz } } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER if(ace->eownerID) { aclMapSize++; } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER cborEncoderResult = cbor_encoder_create_map(&acesArray, &oicSecAclMap, aclMapSize); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Creating ACES Map"); @@ -561,7 +561,7 @@ OCStackResult AclToCBORPayload(const OicSecAcl_t *secAcl, uint8_t **payload, siz VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Closing Validities Array."); } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER // Eownerid -- Not Mandatory if(ace->eownerID) { @@ -575,7 +575,7 @@ OCStackResult AclToCBORPayload(const OicSecAcl_t *secAcl, uint8_t **payload, siz OICFree(eowner); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding eownerId Value."); } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER cborEncoderResult = cbor_encoder_close_container(&acesArray, &oicSecAclMap); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Closing ACES Map."); @@ -1254,7 +1254,7 @@ OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size) } } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER // eowner uuid -- Not Mandatory if (strcmp(name, OIC_JSON_EOWNERID_NAME) == 0) { @@ -1270,7 +1270,7 @@ OicSecAcl_t* CBORPayloadToAcl(const uint8_t *cborPayload, const size_t size) OICFree(eowner); VERIFY_SUCCESS(TAG, OC_STACK_OK == ret , ERROR); } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER OICFree(name); } @@ -1333,7 +1333,7 @@ exit: return acl; } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER bool IsValidAclAccessForSubOwner(const OicUuid_t* uuid, const uint8_t *cborPayload, const size_t size) { bool retValue = false; @@ -1373,7 +1373,7 @@ exit: return retValue; } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER /** * This method removes ACE for the subject and resource from the ACL @@ -1702,7 +1702,7 @@ static bool IsSameValidities(OicSecValidity_t* validities1, OicSecValidity_t* va return false; } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER static bool IsSameEowner(OicUuid_t* eowner1, OicUuid_t* eowner2) { if (NULL != eowner1 && NULL != eowner2) @@ -1746,7 +1746,7 @@ static bool IsSameACE(OicSecAce_t* ace1, OicSecAce_t* ace2) return false; } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER if(false == IsSameEowner(ace1->eownerID, ace2->eownerID)) { return false; diff --git a/resource/csdk/security/src/credresource.c b/resource/csdk/security/src/credresource.c index 340db08..54180ea 100644 --- a/resource/csdk/security/src/credresource.c +++ b/resource/csdk/security/src/credresource.c @@ -221,7 +221,7 @@ static void FreeCred(OicSecCred_t *cred) //Clean Period OICFree(cred->period); -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER //Clean eowner OICFree(cred->eownerID); #endif @@ -334,12 +334,12 @@ OCStackResult CredToCBORPayload(const OicSecCred_t *credS, uint8_t **cborPayload } #if defined(__WITH_DTLS__) || defined(__WITH_TLS__) -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER if(cred->eownerID) { mapSize++; } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER if (SIGNED_ASYMMETRIC_KEY == cred->credType && cred->publicData.data) { @@ -611,7 +611,7 @@ OCStackResult CredToCBORPayload(const OicSecCred_t *credS, uint8_t **cborPayload VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding Period Name Value."); } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER // Eownerid -- Not Mandatory if(cred->eownerID) { @@ -625,7 +625,7 @@ OCStackResult CredToCBORPayload(const OicSecCred_t *credS, uint8_t **cborPayload VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Addding eownerId Value."); OICFree(eowner); } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER cborEncoderResult = cbor_encoder_close_container(&credArray, &credMap); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Closing Cred Map."); @@ -1051,7 +1051,7 @@ OCStackResult CBORPayloadToCred(const uint8_t *cborPayload, size_t size, VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Period."); } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER // Eowner uuid -- Not Mandatory if (strcmp(OIC_JSON_EOWNERID_NAME, name) == 0 && cbor_value_is_text_string(&credMap)) { @@ -1067,7 +1067,7 @@ OCStackResult CBORPayloadToCred(const uint8_t *cborPayload, size_t size, OICFree(eowner); VERIFY_SUCCESS(TAG, OC_STACK_OK == ret , ERROR); } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER if (cbor_value_is_valid(&credMap)) { @@ -1125,7 +1125,7 @@ exit: return ret; } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER bool IsValidCredentialAccessForSubOwner(const OicUuid_t* uuid, const uint8_t *cborPayload, size_t size) { OicSecCred_t* cred = NULL; @@ -1149,7 +1149,7 @@ exit: return isValidCred; } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER OicSecCred_t * GenerateCredential(const OicUuid_t * subject, OicSecCredType_t credType, const OicSecCert_t * publicData, const OicSecKey_t* privateData, @@ -1217,14 +1217,14 @@ OicSecCred_t * GenerateCredential(const OicUuid_t * subject, OicSecCredType_t cr VERIFY_NON_NULL(TAG, rownerID, ERROR); memcpy(&cred->rownerID, rownerID, sizeof(OicUuid_t)); -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER if(eownerID) { cred->eownerID = (OicUuid_t*)OICCalloc(1, sizeof(OicUuid_t)); VERIFY_NON_NULL(TAG, cred->eownerID, ERROR); memcpy(cred->eownerID->id, eownerID->id, sizeof(eownerID->id)); } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER ret = OC_STACK_OK; @@ -1741,7 +1741,7 @@ exit: } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER /** * Internal function to fill private data of SubOwner PSK. * @@ -1812,7 +1812,7 @@ exit: OICFree(b64Buf); return false; } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER #endif // __WITH_DTLS__ or __WITH_TLS__ static OCEntityHandlerResult HandlePostRequest(OCEntityHandlerRequest * ehRequest) @@ -1951,7 +1951,7 @@ static OCEntityHandlerResult HandlePostRequest(OCEntityHandlerRequest * ehReques } } } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER // In case SubOwner Credential else if(doxm && doxm->owned && doxm->mom && OIC_MULTIPLE_OWNER_DISABLE != doxm->mom->mode && @@ -2006,7 +2006,7 @@ static OCEntityHandlerResult HandlePostRequest(OCEntityHandlerRequest * ehReques } } } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER else { if(IsEmptyCred(cred)) @@ -2446,7 +2446,7 @@ int32_t GetDtlsPskCredentials(CADtlsPskCredType_t type, } OIC_LOG(DEBUG, TAG, "Can not find subject matched credential."); -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER const OicSecDoxm_t* doxm = GetDoxmResourceData(); if(doxm && doxm->mom && OIC_MULTIPLE_OWNER_DISABLE != doxm->mom->mode) { @@ -2542,7 +2542,7 @@ int32_t GetDtlsPskCredentials(CADtlsPskCredType_t type, } } } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER } break; } diff --git a/resource/csdk/security/src/doxmresource.c b/resource/csdk/security/src/doxmresource.c index 122de33..0dda37c 100644 --- a/resource/csdk/security/src/doxmresource.c +++ b/resource/csdk/security/src/doxmresource.c @@ -82,10 +82,10 @@ static OicSecDoxm_t gDefaultDoxm = {.id = {0}}, /* OicUuid_t deviceID */ false, /* bool dpc */ {.id = {0}}, /* OicUuid_t owner */ -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER NULL, /* OicSecSubOwner_t sub-owner list */ NULL, /* OicSecMomType_t multiple owner mode */ -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER {.id = {0}}, /* OicUuid_t rownerID */ }; @@ -111,7 +111,7 @@ void DeleteDoxmBinData(OicSecDoxm_t* doxm) //clean oxm OICFree(doxm->oxm); -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER //clean mom OICFree(doxm->mom); @@ -126,7 +126,7 @@ void DeleteDoxmBinData(OicSecDoxm_t* doxm) OICFree(subowner); } } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER //Clean doxm itself OICFree(doxm); @@ -240,7 +240,7 @@ OCStackResult DoxmToCBORPayload(const OicSecDoxm_t *doxm, uint8_t **payload, siz strUuid = NULL; } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER //Device SubOwnerID -- Not Mandatory if(doxm->subOwners) { @@ -281,7 +281,7 @@ OCStackResult DoxmToCBORPayload(const OicSecDoxm_t *doxm, uint8_t **payload, siz cborEncoderResult = cbor_encode_int(&doxmMap, (int64_t)doxm->mom->mode); VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding mom Value."); } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER //devownerid -- Mandatory cborEncoderResult = cbor_encode_text_string(&doxmMap, OIC_JSON_DEVOWNERID_NAME, @@ -551,7 +551,7 @@ static OCStackResult CBORPayloadToDoxmBin(const uint8_t *cborPayload, size_t siz memcpy(doxm->owner.id, gDoxm->owner.id, sizeof(doxm->owner.id)); } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER cborFindResult = cbor_value_map_find_value(&doxmCbor, OIC_JSON_MOM_NAME, &doxmMap); if(CborNoError == cborFindResult && cbor_value_is_integer(&doxmMap)) { @@ -625,7 +625,7 @@ static OCStackResult CBORPayloadToDoxmBin(const uint8_t *cborPayload, size_t siz LL_APPEND(doxm->subOwners, subOwnerId); } } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER cborFindResult = cbor_value_map_find_value(&doxmCbor, OIC_JSON_ROWNERID_NAME, &doxmMap); if (CborNoError == cborFindResult && cbor_value_is_text_string(&doxmMap)) @@ -712,10 +712,10 @@ static bool ValidateQuery(const char * query) bool bDeviceIDMatch = false; // does 'deviceid' query matches with doxm.deviceid ? bool bInterfaceQry = false; // does querystring contains 'if' query ? bool bInterfaceMatch = false; // does 'if' query matches with oic.if.baseline ? -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER bool bMotQry = false; // does querystring contains 'mom' and 'owned' query ? bool bMotMatch = false; // does 'mom' query value is not '0' && does query value matches with doxm.owned status? -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER OicParseQueryIter_t parseIter = {.attrPos = NULL}; @@ -738,7 +738,7 @@ static bool ValidateQuery(const char * query) } } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER if (strncasecmp((char *)parseIter.attrPos, OIC_JSON_MOM_NAME, strlen(OIC_JSON_MOM_NAME)) == 0) { bMotQry = true; @@ -759,7 +759,7 @@ static bool ValidateQuery(const char * query) } return bMotMatch; } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER if (strncasecmp((char *)parseIter.attrPos, OIC_JSON_DEVICE_ID_NAME, parseIter.attrLen) == 0) { @@ -784,14 +784,14 @@ static bool ValidateQuery(const char * query) } } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER return ((bOwnedQry ? bOwnedMatch : true) && (bDeviceIDQry ? bDeviceIDMatch : true) && (bMotQry ? bMotMatch : true)); #else return ((bOwnedQry ? bOwnedMatch : true) && (bDeviceIDQry ? bDeviceIDMatch : true)); -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER } static OCEntityHandlerResult HandleDoxmGetRequest (const OCEntityHandlerRequest * ehRequest) @@ -862,7 +862,7 @@ static void updateWriteableProperty(const OicSecDoxm_t* src, OicSecDoxm_t* dst) dst->owned = src->owned; } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER if(src->mom) { OIC_LOG(DEBUG, TAG, "dectected 'mom' property"); @@ -875,12 +875,12 @@ static void updateWriteableProperty(const OicSecDoxm_t* src, OicSecDoxm_t* dst) } } } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER } } #if defined(__WITH_DTLS__) || defined (__WITH_TLS__) -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER /** * Callback function to handle MOT DTLS handshake result. * @param[out] object remote device information. @@ -932,7 +932,7 @@ void MultipleOwnerDTLSHandshakeCB(const CAEndpoint_t *object, OIC_LOG(DEBUG, TAG, "OUT MultipleOwnerDTLSHandshakeCB"); } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER #endif // defined(__WITH_DTLS__) || defined (__WITH_TLS__) /** @@ -1010,7 +1010,7 @@ static OCEntityHandlerResult HandleDoxmPostRequest(OCEntityHandlerRequest * ehRe updateWriteableProperty(newDoxm, gDoxm); #if defined(__WITH_DTLS__) || defined (__WITH_TLS__) -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER //handle mom if(gDoxm->mom) { @@ -1071,7 +1071,7 @@ static OCEntityHandlerResult HandleDoxmPostRequest(OCEntityHandlerRequest * ehRe LL_APPEND(gDoxm->subOwners, subowner); } } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER #endif // defined(__WITH_DTLS__) || defined (__WITH_TLS__) //Update new state in persistent storage @@ -1499,7 +1499,7 @@ const OicSecDoxm_t* GetDoxmResourceData() return gDoxm; } -#if defined(__WITH_DTLS__) && defined(_ENABLE_MULTIPLE_OWNER_) +#if defined(__WITH_DTLS__) && defined(MULTIPLE_OWNER) /** * Internal API to prepare MOT */ @@ -1545,7 +1545,7 @@ static void PrepareMOT(const OicSecDoxm_t* doxm) exit: OIC_LOG(WARNING, TAG, "Error in PrepareMOT"); } -#endif //defined(__WITH_DTLS__) && defined(_ENABLE_MULTIPLE_OWNER_) +#endif //defined(__WITH_DTLS__) && defined(MULTIPLE_OWNER) OCStackResult InitDoxmResource() { @@ -1595,13 +1595,13 @@ OCStackResult InitDoxmResource() } OICFree(data); -#if defined(__WITH_DTLS__) && defined(_ENABLE_MULTIPLE_OWNER_) +#if defined(__WITH_DTLS__) && defined(MULTIPLE_OWNER) //if MOT is enabled, MOT should be prepared. if(gDoxm && gDoxm->owned) { PrepareMOT(gDoxm); } -#endif // defined(__WITH_DTLS__) && defined(_ENABLE_MULTIPLE_OWNER_) +#endif // defined(__WITH_DTLS__) && defined(MULTIPLE_OWNER) return ret; } @@ -1731,7 +1731,7 @@ OCStackResult GetDoxmRownerId(OicUuid_t *rowneruuid) return retVal; } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER /** * Compare the UUID to SubOwner. * @@ -1761,7 +1761,7 @@ bool IsSubOwner(const OicUuid_t* uuid) } return retVal; } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER /** * Function to restore doxm resurce to initial status. diff --git a/resource/csdk/security/src/oxmpincommon.c b/resource/csdk/security/src/oxmpincommon.c index d3df5c4..26cc0b5 100644 --- a/resource/csdk/security/src/oxmpincommon.c +++ b/resource/csdk/security/src/oxmpincommon.c @@ -248,7 +248,7 @@ OCStackResult InputPin(char* pinBuffer, size_t bufferSize) return OC_STACK_OK; } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER OCStackResult SetPreconfigPin(const char *pinBuffer, size_t pinLength) { if(NULL == pinBuffer || OXM_PRECONFIG_PIN_MAX_SIZE < pinLength) @@ -261,7 +261,7 @@ OCStackResult SetPreconfigPin(const char *pinBuffer, size_t pinLength) return OC_STACK_OK; } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER #ifdef __WITH_DTLS__ @@ -348,7 +348,7 @@ int32_t GetDtlsPskForRandomPinOxm( CADtlsPskCredType_t type, return ret; } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER int32_t GetDtlsPskForMotRandomPinOxm( CADtlsPskCredType_t type, const unsigned char *UNUSED1, size_t UNUSED2, unsigned char *result, size_t result_length) @@ -611,6 +611,6 @@ int32_t GetDtlsPskForMotPreconfPinOxm( CADtlsPskCredType_t type, return ret; } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER #endif //__WITH_DTLS__ diff --git a/resource/csdk/security/src/policyengine.c b/resource/csdk/security/src/policyengine.c index d5ba721..3a2b953 100644 --- a/resource/csdk/security/src/policyengine.c +++ b/resource/csdk/security/src/policyengine.c @@ -152,7 +152,7 @@ static bool IsRequestFromDevOwner(PEContext_t *context) } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER /** * Compare the request's subject to SubOwner. * @@ -237,7 +237,7 @@ static bool IsValidRequestFromSubOwner(PEContext_t *context) return isValidRequest; } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER // TODO - remove these function placeholders as they are implemented @@ -587,7 +587,7 @@ SRMAccessResponse_t CheckPermission(PEContext_t *context, { context->retVal = ACCESS_GRANTED; } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER //Then check if request from SubOwner else if(IsRequestFromSubOwner(context)) { @@ -596,7 +596,7 @@ SRMAccessResponse_t CheckPermission(PEContext_t *context, context->retVal = ACCESS_GRANTED; } } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER // If not granted via DevOwner status and not a subowner, // then check if request is for a SVR and coming from rowner else if (IsRequestFromResourceOwner(context)) diff --git a/resource/csdk/security/src/secureresourcemanager.c b/resource/csdk/security/src/secureresourcemanager.c index fd13eff..fb4c126 100644 --- a/resource/csdk/security/src/secureresourcemanager.c +++ b/resource/csdk/security/src/secureresourcemanager.c @@ -207,14 +207,14 @@ void SRMRequestHandler(const CAEndpoint_t *endPoint, const CARequestInfo_t *requ } } } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER /* * In case of ACL and CRED, The payload required to verify the payload. * Payload information will be used for subowner's permission verification. */ g_policyEngineContext.payload = (uint8_t*)requestInfo->info.payload; g_policyEngineContext.payloadSize = requestInfo->info.payloadSize; -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER //New request are only processed if the policy engine state is AWAITING_REQUEST. if (AWAITING_REQUEST == g_policyEngineContext.state) diff --git a/resource/csdk/security/src/srmresourcestrings.c b/resource/csdk/security/src/srmresourcestrings.c index 9dd8ffe..55cfe25 100644 --- a/resource/csdk/security/src/srmresourcestrings.c +++ b/resource/csdk/security/src/srmresourcestrings.c @@ -94,15 +94,15 @@ const char * OIC_JSON_PERMISSION_NAME = "permission"; const char * OIC_JSON_OWNERS_NAME = "ownrs"; const char * OIC_JSON_OWNER_NAME = "ownr"; const char * OIC_JSON_DEVOWNERID_NAME = "devowneruuid"; -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER const char * OIC_JSON_SUBOWNERID_NAME = "subowneruuid"; -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER const char * OIC_JSON_OWNED_NAME = "owned"; const char * OIC_JSON_OXM_NAME = "oxm"; const char * OIC_JSON_OXMS_NAME = "oxms"; -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER const char * OIC_JSON_MOM_NAME = "mom"; -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER const char * OIC_JSON_OXM_TYPE_NAME = "oxmtype"; const char * OIC_JSON_OXM_SEL_NAME = "oxmsel"; const char * OIC_JSON_DEVICE_ID_FORMAT_NAME = "didformat"; @@ -146,9 +146,9 @@ const char * OIC_JSON_REL_NAME = OC_RSRVD_REL; const char * OIC_JSON_RT_NAME = OC_RSRVD_RESOURCE_TYPE; const char * OIC_JSON_IF_NAME = OC_RSRVD_INTERFACE; const char * OIC_JSON_ROWNERID_NAME = "rowneruuid"; -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER const char * OIC_JSON_EOWNERID_NAME = "eowneruuid"; -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER const char * OIC_JSON_ENCODING_NAME = "encoding"; const char * OIC_JSON_DATA_NAME = "data"; const char * OIC_JSON_SEC_V_NAME = "secv"; @@ -173,9 +173,9 @@ const char * WILDCARD_RESOURCE_URI = "*"; const char * OXM_JUST_WORKS = "oic.sec.doxm.jw"; const char * OXM_RANDOM_DEVICE_PIN = "oic.sec.doxm.rdp"; const char * OXM_MANUFACTURER_CERTIFICATE = "oic.sec.doxm.mfgcert"; -#ifdef _ENABLE_MULTIPLE_OWNER_ -const char * OXM_PRECONF_PIN = "oic.sec.doxm.pcp"; -#endif //_ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER +const char * OXM_PRECONF_PIN = "oic.sec..doxm.pcp"; +#endif //MULTIPLE_OWNER //Credential data encoding methods const char * OIC_SEC_ENCODING_BASE64 = "oic.sec.encoding.base64"; diff --git a/resource/csdk/security/src/srmutility.c b/resource/csdk/security/src/srmutility.c index ce509b3..6badf34 100644 --- a/resource/csdk/security/src/srmutility.c +++ b/resource/csdk/security/src/srmutility.c @@ -91,10 +91,10 @@ const char* GetOxmString(OicSecOxm_t oxmType) return OXM_RANDOM_DEVICE_PIN; case OIC_MANUFACTURER_CERTIFICATE: return OXM_MANUFACTURER_CERTIFICATE; -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER case OIC_PRECONFIG_PIN: return OXM_PRECONF_PIN; -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER default: return NULL; } diff --git a/resource/csdk/security/tool/json2cbor.c b/resource/csdk/security/tool/json2cbor.c index 9528634..c2ffd40 100644 --- a/resource/csdk/security/tool/json2cbor.c +++ b/resource/csdk/security/tool/json2cbor.c @@ -609,7 +609,7 @@ OicSecDoxm_t* JSONToDoxmBin(const char * jsonStr) doxm->owned = jsonObj->valueint; } -#ifdef _ENABLE_MULTIPLE_OWNER_ +#ifdef MULTIPLE_OWNER //mom -- Not Mandatory jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_MOM_NAME); if (jsonObj) @@ -619,7 +619,7 @@ OicSecDoxm_t* JSONToDoxmBin(const char * jsonStr) VERIFY_NON_NULL(TAG, doxm->mom, ERROR); doxm->mom->mode = (OicSecMomType_t)jsonObj->valueint; } -#endif //_ENABLE_MULTIPLE_OWNER_ +#endif //MULTIPLE_OWNER //DeviceId -- Mandatory jsonObj = cJSON_GetObjectItem(jsonDoxm, OIC_JSON_DEVICE_ID_NAME); diff --git a/resource/csdk/security/unittest/SConscript b/resource/csdk/security/unittest/SConscript index ddb8ef7..b284319 100644 --- a/resource/csdk/security/unittest/SConscript +++ b/resource/csdk/security/unittest/SConscript @@ -69,7 +69,7 @@ if srmtest_env.get('LOGGING') == '1': srmtest_env.AppendUnique(CPPDEFINES = ['TB_LOG']) if srmtest_env.get('MULTIPLE_OWNER') == '1': - srmtest_env.AppendUnique(CPPDEFINES=['_ENABLE_MULTIPLE_OWNER_']) + srmtest_env.AppendUnique(CPPDEFINES=['MULTIPLE_OWNER']) if target_os == 'windows': srmtest_env.AppendUnique(LINKFLAGS = ['/subsystem:CONSOLE']) diff --git a/resource/include/OCProvisioningManager.h b/resource/include/OCProvisioningManager.h index 359b47c..a6fbc7d 100644 --- a/resource/include/OCProvisioningManager.h +++ b/resource/include/OCProvisioningManager.h @@ -166,16 +166,40 @@ namespace OC const OicUuid_t* deviceID, std::shared_ptr &foundDevice); +#ifdef MULTIPLE_OWNER + /** + * API is responsible for discovery of MOT(Mutilple Owner Transfer) + * devices in current subnet. + * + * @param timeout Timeout in seconds, time until which function will listen to + * responses from server before returning the list of devices. + * @param list List of MOT enabled devices. + * @return ::OC_STACK_OK in case of success and other value otherwise. + */ + static OCStackResult discoverMultipleOwnerEnabledDevices(unsigned short timeout, + DeviceList_t &list); + + /** + * API is responsible for discovery of Multiple owned device in + * current subnet. + * + * @param timeout Timeout in seconds, time until which function will listen to + * responses from server before returning the list of devices. + * @param list List of Multiple Owned devices. + * @return ::OC_STACK_OK in case of success and other value otherwise. + */ + static OCStackResult discoverMultipleOwnedDevices(unsigned short timeout, + DeviceList_t &list); + +#endif + /** - * API for registering Ownership transfer methods for a particular transfer Type. + * API for registering Pin Callback. * - * @param oxm Ownership transfer method. - * @param callbackData CallbackData Methods for ownership transfer. - * @param inputPin Callback method to input pin for verification. + * @param InputPinCallback inputPin caaback function. * @return ::OC_STACK_OK in case of success and other value otherwise. */ - static OCStackResult setOwnerTransferCallbackData(OicSecOxm_t oxm, - OTMCallbackData_t* callbackData, InputPinCallback inputPin); + static OCStackResult setInputPinCallback(InputPinCallback inputPin); /** * API to get status of all the devices in current subnet. The status include endpoint @@ -438,6 +462,62 @@ namespace OC static void callbackWrapper(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool hasError); +#ifdef MULTIPLE_OWNER + /** + * API to update 'doxm.oxmsel' to resource server. + * + * @param resultCallback Callback provided by API user, callback will be + * called when credential revocation is finished. + * @param oxmSelVal Method of multiple ownership transfer (ref. oic.sec.oxm) + * @return ::OC_STACK_OK in case of success and other value otherwise. + */ + OCStackResult selectMOTMethod( const OicSecOxm_t oxmSelVal, + ResultCallBack resultCallback); + + /** + * API to update 'doxm.mom' to resource server. + * + * @param resultCallback Callback provided by API user, callback will be + * called when credential revocation is finished. + * @param momType Mode of multiple ownership transfer (ref. oic.sec.mom) + * @return ::OC_STACK_OK in case of success and other value otherwise. + */ + OCStackResult changeMOTMode( const OicSecMomType_t momType, + ResultCallBack resultCallback); + + /** + * API to add preconfigured PIN to local SVR DB. + * + * @param preconfPIN Preconfig PIN which is used while multiple owner authentication + * @param preconfPINLength Byte length of preconfig PIN + * @return ::OC_STACK_OK in case of success and other value otherwise. + */ + OCStackResult addPreconfigPIN(const char* preconfPIN, + size_t preconfPINLength); + + /** + * API to provision preconfigured PIN. + * + * @param resultCallback Callback provided by API user, callback will be called when + * credential revocation is finished. + * @param preconfPin Preconfig PIN which is used while multiple owner authentication + * @param preconfPinLength Byte length of preconfig PIN + * @return ::OC_STACK_OK in case of success and other value otherwise. + */ + OCStackResult provisionPreconfPin(const char * preconfPin, + size_t preconfPinLength, ResultCallBack resultCallback); + + /** + * API to do multiple ownership transfer for MOT enabled device. + * + * @param resultCallback Result callback function to be invoked when + * multiple ownership transfer finished. + * @return ::OC_STACK_OK in case of success and other value otherwise. + */ + OCStackResult doMultipleOwnershipTransfer(ResultCallBack resultCallback); + +#endif // MULTIPLE_OWNER + private: void validateSecureResource(); }; diff --git a/resource/provisioning/examples/SConscript b/resource/provisioning/examples/SConscript index 7b52c42..ed677ea 100644 --- a/resource/provisioning/examples/SConscript +++ b/resource/provisioning/examples/SConscript @@ -85,12 +85,15 @@ if target_os in ['darwin', 'ios']: if target_os == 'tizen': examples_env.AppendUnique(CPPDEFINES = ['__TIZEN__']) - +if examples_env.get('MULTIPLE_OWNER') == '1': + examples_env.AppendUnique(CPPDEFINES = ['MULTIPLE_OWNER']) ###################################################################### # Source files and Targets ###################################################################### provisioningclient = examples_env.Program('provisioningclient', 'provisioningclient.cpp') +if examples_env.get('MULTIPLE_OWNER') == '1': + subownerclient = examples_env.Program('subownerclient', 'subownerclient.cpp') if examples_env.get('WITH_TCP') == True: cloudClient = examples_env.Program('cloudClient',['cloudClient.cpp', 'cloudAuth.cpp', 'cloudWrapper.cpp']) @@ -102,6 +105,12 @@ svr_db_build_dir = examples_env.get('BUILD_DIR') +'/resource/provisioning/exampl clientjson = examples_env.Install(svr_db_build_dir, svr_db_src_dir + 'oic_svr_db_client.json') clientdat = examples_env.Install(svr_db_build_dir, svr_db_src_dir + 'oic_svr_db_client.dat') +if examples_env.get('MULTIPLE_OWNER') == '1': + subownerclientdat = examples_env.Install(svr_db_build_dir, + svr_db_src_dir + 'oic_svr_db_subowner_client.dat') + Alias("subowner", [subownerclientdat, subownerclient]) + examples_env.AppendTarget("subowner") + if examples_env.get('WITH_TCP') == True: clouddat = examples_env.Install(svr_db_build_dir, svr_db_src_dir + 'cloud.dat') diff --git a/resource/provisioning/examples/oic_svr_db_subowner_client.dat b/resource/provisioning/examples/oic_svr_db_subowner_client.dat new file mode 100644 index 0000000000000000000000000000000000000000..ae130bcc4f4e06a3f292ad681485c04c27970329 GIT binary patch literal 1027 zcmbVLL2kk@5TxZRJyl9TggEL?=&gypE)I^J+DV~D=sS9-%B8R16@3b4>UB^QQAHFE z)_Uz7@62YhqbZe-w{KhSqOjE`ODWj*uZ69%9B5V7f~EJufYr6Zn=P9g;Pa6dbmUGm zQ>}Bi50{G&Q^D5)Q^7+isR8-a0JsM*ET13CnJeDtV{w*RkV1jKbYSxbTXwPKd2C*S zDTK8`tJ_{Vn}%KC*;$|?rdLI)$%H<2noenU*r^s<+A6IOyg*SVZ1O(zCHy))s8+n& z!{>cH8g(x%Lsq832=$B)sD@;F)b~c0XKwUTfk9KO?&2tk$z;ldBq0!xIGF^~h|qvM zkeEO+jmFU!8+kvN(D@79aXLxxQ<{BzGhubP&uB5oDz|ho%xp2t8N3P#|L=Ge#d9Bw op$}$1I}CO`;21y-sHN2n;7Hj1VxrP1yKtIUY4d+)zmpG#Uv+VHF#rGn literal 0 HcmV?d00001 diff --git a/resource/provisioning/examples/oic_svr_db_subowner_client.json b/resource/provisioning/examples/oic_svr_db_subowner_client.json new file mode 100644 index 0000000..eba0cdd --- /dev/null +++ b/resource/provisioning/examples/oic_svr_db_subowner_client.json @@ -0,0 +1,85 @@ +{ + "acl": { + "aclist": { + "aces": [ + { + "subjectuuid": "*", + "resources": [ + { + "href": "/oic/res", + "rel": "", + "rt": ["oic.wk.res"], + "if": ["oic.if.ll"] + },{ + "href": "/oic/d", + "rel": "", + "rt": ["oic.wk.d"], + "if": ["oic.if.baseline", "oic.if.r"] + },{ + "href": "/oic/p", + "rel": "", + "rt": ["oic.wk.p"], + "if": ["oic.if.baseline", "oic.if.r"] + } + ], + "permission": 2 + }, + { + "subjectuuid": "*", + "resources": [ + { + "href": "/oic/sec/doxm", + "rel": "", + "rt": ["oic.r.doxm"], + "if": ["oic.if.baseline"] + }, + { + "href": "/oic/sec/pstat", + "rel": "", + "rt": ["oic.r.pstat"], + "if": ["oic.if.baseline"] + } + ], + "permission": 2 + }, + { + "subjectuuid": "*", + "resources": [ + { + "href": "/oic/sec/pconf", + "rel": "", + "rt": ["oic.r.pconf"], + "if": ["oic.if.baseline"] + }, + { + "href": "/oic/sec/dpairing", + "rel": "", + "rt": ["oic.r.dpairing"], + "if": ["oic.if.baseline"] + } + ], + "permission": 2 + } + ] + }, + "rowneruuid" : "5375624F-776E-6572-436C-69656E743030" + }, + "pstat": { + "isop": true, + "cm": 0, + "tm": 0, + "om": 3, + "sm": 3, + "deviceuuid": "5375624F-776E-6572-436C-69656E743030", + "rowneruuid": "5375624F-776E-6572-436C-69656E743030" + }, + "doxm": { + "oxms": [0], + "oxmsel": 0, + "sct": 1, + "owned": true, + "deviceuuid": "5375624F-776E-6572-436C-69656E743030", + "devowneruuid": "5375624F-776E-6572-436C-69656E743030", + "rowneruuid": "5375624F-776E-6572-436C-69656E743030" + } +} diff --git a/resource/provisioning/examples/provisioningclient.cpp b/resource/provisioning/examples/provisioningclient.cpp index a5d3fc4..6c4ffd1 100644 --- a/resource/provisioning/examples/provisioningclient.cpp +++ b/resource/provisioning/examples/provisioningclient.cpp @@ -65,7 +65,7 @@ static const OicSecPrm_t SUPPORTED_PRMS[1] = using namespace OC; -DeviceList_t pUnownedDevList, pOwnedDevList; +DeviceList_t pUnownedDevList, pOwnedDevList, pMOTEnabledDeviceList; static int transferDevIdx, ask = 1; static OicSecPconf_t g_pconf; static uint16_t g_credId = 0; @@ -96,6 +96,13 @@ void printMenu() std::cout << " 14. Provision the Trust Cert. Chain"<getDeviceID()<<" From IP: "; + std::cout << pMOTEnabledDeviceList[i]->getDevAddr() << std::endl; + } + } + + // select device + unsigned int dev_num = 0; + for( ; ; ) + { + std::cout << "Enter Device Number, to change the mode: "<> dev_num; + if(0 < dev_num && dev_count >= dev_num) + { + break; + } + std::cout << " Entered Wrong Number. Please Enter Again"< Enter Mode of Multiple Ownership Transfer :"<changeMOTMode( + (const OicSecMomType_t)momType,MOTMethodCB)) + { + OIC_LOG(ERROR, TAG, "changeMOTMode API error"); + } + } + else + { + if(dev_num <= pOwnedDevList.size()) + { + if(OC_STACK_OK != pOwnedDevList[dev_num-1]->changeMOTMode(momType, + MOTMethodCB)) + { + OIC_LOG(ERROR, TAG, "changeMOTMode API error"); + } + } + else + { + if(OC_STACK_OK != pMOTEnabledDeviceList[(dev_num - + pOwnedDevList.size() - 1)]->changeMOTMode(momType, + MOTMethodCB)) + { + OIC_LOG(ERROR, TAG, "changeMOTMode API error"); + } + } + } + break; + } + case 17: + { + if (!pMOTEnabledDeviceList.size()) + { + std::cout <<"Please discover the MOT device first. Use option 18"<> dev_num; + if(0 < dev_num && pMOTEnabledDeviceList.size() >=dev_num) + { + break; + } + std::cout << " Entered Wrong Number. Please Enter Again"< Enter Number of OxM for Multiple Ownership Transfer : "<> oxm; + if(0 == oxm) + { + secOxm = OIC_RANDOM_DEVICE_PIN; + break; + } + if(1 == oxm) + { + secOxm = OIC_PRECONFIG_PIN; + break; + } + std::cout << " Entered Wrong Number. Please Enter Again"<selectMOTMethod((const OicSecOxm_t)secOxm, + MOTMethodCB)) + { + OIC_LOG(ERROR, TAG, "selectMOTMethod API error"); + } + break; + } + case 18: + { + pMOTEnabledDeviceList.clear(); + std::cout << "Started MOT Enabled device discovery..." <> dev_num; + if(0 < dev_num && pMOTEnabledDeviceList.size() >=dev_num) + { + break; + } + std::cout << " Entered Wrong Number. Please Enter Again"< Input the 8 digit PreconfigPin (e.g. 12341234) :" <provisionPreconfPin(preconfigPin, + preconfPinLength, MOTMethodCB)) + { + OIC_LOG(ERROR, TAG, "provisionPreconfPin API error"); + } + break; + } + case 20: + { + if (!pMOTEnabledDeviceList.size()) + { + std::cout <<"Please discover the MOT device first. Use option 16"<> dev_num; + if(0 < dev_num && pMOTEnabledDeviceList.size() >=dev_num) + { + break; + } + std::cout << " Entered Wrong Number. Please Enter Again"< Input the 8 digit preconfPIN (e.g. 12341234) :" <addPreconfigPIN(preconfPIN, + preconfPinLength)) + { + OIC_LOG(ERROR, TAG, "addPreconfigPIN API error"); + } + break; + } +#endif //MULTIPLE_OWNER case 99: default: out = 1; diff --git a/resource/provisioning/examples/subownerclient.cpp b/resource/provisioning/examples/subownerclient.cpp new file mode 100644 index 0000000..a2b37e8 --- /dev/null +++ b/resource/provisioning/examples/subownerclient.cpp @@ -0,0 +1,394 @@ +/* ***************************************************************** + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#include "logger.h" +#include "oic_malloc.h" +#include "oic_string.h" +#include "OCPlatform.h" +#include "OCApi.h" +#include "OCProvisioningManager.hpp" +#include "oxmjustworks.h" +#include "oxmrandompin.h" +#include "aclresource.h" +#include "utlist.h" + +#define MAX_PERMISSION_LENGTH (5) +#define ACL_RESRC_ARRAY_SIZE (3) +#define CREATE (1) +#define READ (2) +#define UPDATE (4) +#define DELETE (8) +#define NOTIFY (16) +#define DASH '-' +#define PREDEFINED_TIMEOUT (10) +#define MAX_OWNED_DEVICE (10) +#define TAG "subownerclient" + +#define JSON_DB_PATH "./oic_svr_db_subowner_client.json" +#define DAT_DB_PATH "./oic_svr_db_subowner_client.dat" +#define DEV_STATUS_ON "DEV_STATUS_ON" +#define DEV_STATUS_OFF "DEV_STATUS_OFF" + +#define DISCOVERY_TIMEOUT 5 + +using namespace OC; + +DeviceList_t pMOwnedDeviceList, pMOTEnabledDeviceList; +static int transferDevIdx, ask = 1; + +static FILE* client_open(const char *UNUSED_PARAM, const char *mode) +{ + (void)UNUSED_PARAM; + return fopen(DAT_DB_PATH, mode); +} + +void printMenu() +{ + std::cout << "\nChoose an option:"<> ptr; + OICStrcpy(pinBuf, bufSize, ptr.c_str()); + return; + } +} + +void printUuid(OicUuid_t uuid) +{ + for (int i = 0; i < UUID_LENGTH; i++) + { + std::cout <at(0).deviceId); + delete result; + + moveTransferredDevice(); + } + ask = 1; +} + +void printStatus(int status) +{ + static std::map devStatus = {{1<<0, DEV_STATUS_ON}, {1<<1, DEV_STATUS_OFF}}; + + std::cout <getDeviceID() << " From IP: "; + std::cout << list[i]->getDevAddr() << std::endl; + } +} + +static void getCallback(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode) +{ + (void)(headerOptions); + try + { + if (OC_STACK_OK == eCode) + { + std::cout << "Callback Context for GET query recvd successfully" << std::endl; + std::cout << "Resource URI: " << rep.getUri() << std::endl; + + bool state = false; + int power = 0; + rep.getValue("state", state); + rep.getValue("power", power); + + std::cout << "\tstate: " << state << std::endl; + std::cout << "\tpower: " << power << std::endl; + } + else + { + std::cout << "getCallback Response error: " << eCode << std::endl; + } + } + catch(std::exception& e) + { + std::cout << "Exception: " << e.what() << " in onGet" << std::endl; + } +} + +void putCallback(const HeaderOptions& /*headerOptions*/, const OCRepresentation& rep, const int eCode) +{ + if(eCode == 0) + { + std::cout << "PUT request was successful !!!!!!" << std::endl; + } + else + { + std::cout << "onPut Response error !!!!!: " << eCode << std::endl; + } +} + +int main(void) +{ + OCPersistentStorage ps {client_open, fread, fwrite, fclose, unlink }; + + // Create PlatformConfig object + PlatformConfig cfg { + OC::ServiceType::InProc, + OC::ModeType::Both, + "0.0.0.0", + 0, + OC::QualityOfService::LowQos, + &ps + }; + + OCPlatform::Configure(cfg); + + //set Input Pin callback + OCSecure::setInputPinCallback(InputPinCB); + + try + { + int choice; + OicSecAcl_t *acl1 = nullptr, *acl2 = nullptr; + if (OCSecure::provisionInit("") != OC_STACK_OK) + { + std::cout <<"PM Init failed"<< std::endl; + return 1; + } + + for (int out = 0; !out;) + { + while (!ask) + { + sleep(1); + } + + printMenu(); + std::cin >> choice; + switch(choice) { + case 1: + { + pMOTEnabledDeviceList.clear(); + std::cout << "Started MOT enabled device discovery..." <getDeviceID(); + std::cout << " From IP:" << pMOTEnabledDeviceList[i]->getDevAddr() <> devNum; + if (devNum > pMOTEnabledDeviceList.size()) + { + std::cout <<"Invalid device number"<getDeviceID()<doMultipleOwnershipTransfer + (multipleOwnershipTransferCB) + != OC_STACK_OK) + { + std::cout<<"Multiple OwnershipTransferCallback is failed"<> choice; + choice--; + + std::vector ledTypes = {"core.led"}; + std::vector ifaces = {DEFAULT_INTERFACE}; + + OCProvisionDev_t *selDev = pMOwnedDeviceList[choice]->getDevPtr(); + std::stringstream host; + host << "coaps:://"; + host << pMOwnedDeviceList[choice]->getDevAddr(); + host << selDev->securePort; + + OCResource::Ptr led = OC::OCPlatform::constructResourceObject( + host.str(), "/a/led", selDev->connType, false, ledTypes, ifaces); + + if(!led) + { + std::cout << "Error: Led Object construction returned null" << std::endl; + break; + } + OCStackResult res = led->get(QueryParamsMap(), getCallback); + + if (OC_STACK_OK != res) + { + std::cout << "Error: get Failed for Led" << std::endl; + } + break; + } + break; + case 5: + { + std::cout << "- Send data(Put Request) to device(led server) -" << std::endl; + printDevices(pMOwnedDeviceList); + printMenu(); + std::cout << "Enter device number to GET data: "; + std::cin >> choice; + choice--; + + std::vector ledTypes = {"core.led"}; + std::vector ifaces = {DEFAULT_INTERFACE}; + + + OCProvisionDev_t *selDev = pMOwnedDeviceList[choice]->getDevPtr(); + std::stringstream host; + host << "coaps:://"; + host << pMOwnedDeviceList[choice]->getDevAddr(); + host << selDev->securePort; + + OCResource::Ptr led = OC::OCPlatform::constructResourceObject(host.str(), + "/a/led", selDev->connType, false, ledTypes, ifaces); + + if(!led) + { + std::cout << "Error: Led Object construction returned null" << std::endl; + break; + } + OCRepresentation rep; + bool state = true; + int power = 39; + rep.setValue("state", state); + rep.setValue("power", power); + OCStackResult res = led->put(rep, QueryParamsMap(), putCallback); + + if (OC_STACK_OK != res) + { + std::cout << "Error: put Failed for Led" << std::endl; + } + break; + } + break; + case 99: + default: + out = 1; + break; + } + } + } + catch(OCException& e) + { + oclog() << "Exception in main: "<= OIC_OXM_COUNT) + OCStackResult result; + OCProvisionDev_t *pDevList = nullptr, *pCurDev = nullptr, *tmp = nullptr; + auto csdkLock = OCPlatform_impl::Instance().csdkLock(); + auto cLock = csdkLock.lock(); + + if (cLock) { - oclog() <<"Invalid callbackData or OXM type"; - return OC_STACK_INVALID_PARAM; + std::lock_guard lock(*cLock); + result = OCDiscoverMultipleOwnerEnabledDevices(timeout, &pDevList); + if (result == OC_STACK_OK) + { + pCurDev = pDevList; + while (pCurDev) + { + tmp = pCurDev; + list.push_back(std::shared_ptr( + new OCSecureResource(csdkLock, pCurDev))); + pCurDev = pCurDev->next; + tmp->next = nullptr; + } + } + else + { + oclog() <<"MultipleOwner Enabled device discovery failed!"; + } } - - if ((OIC_RANDOM_DEVICE_PIN == oxm) && !inputPin) + else { - oclog() <<"for OXM type DEVICE_PIN, inputPin callback can't be null"; - return OC_STACK_INVALID_PARAM; + oclog() <<"Mutex not found"; + result = OC_STACK_ERROR; } + return result; + } + + OCStackResult OCSecure::discoverMultipleOwnedDevices(unsigned short timeout, + DeviceList_t &list) + { OCStackResult result; - auto cLock = OCPlatform_impl::Instance().csdkLock().lock(); + OCProvisionDev_t *pDevList = nullptr, *pCurDev = nullptr, *tmp = nullptr; + auto csdkLock = OCPlatform_impl::Instance().csdkLock(); + auto cLock = csdkLock.lock(); if (cLock) { std::lock_guard lock(*cLock); - result = OCSetOwnerTransferCallbackData(oxm, callbackData); - if (result == OC_STACK_OK && (OIC_RANDOM_DEVICE_PIN == oxm)) + result = OCDiscoverMultipleOwnedDevices(timeout, &pDevList); + if (result == OC_STACK_OK) + { + pCurDev = pDevList; + while (pCurDev) + { + tmp = pCurDev; + list.push_back(std::shared_ptr( + new OCSecureResource(csdkLock, pCurDev))); + pCurDev = pCurDev->next; + tmp->next = nullptr; + } + } + else { - SetInputPinCB(inputPin); + oclog() <<"Multiple Owned device discovery failed!"; } } else @@ -194,7 +235,27 @@ namespace OC } return result; + } +#endif + OCStackResult OCSecure::setInputPinCallback(InputPinCallback inputPin) + { + OCStackResult result; + auto cLock = OCPlatform_impl::Instance().csdkLock().lock(); + + if (cLock) + { + std::lock_guard lock(*cLock); + SetInputPinCB(inputPin); + result = OC_STACK_OK; + } + else + { + oclog() <<"Mutex not found"; + result = OC_STACK_ERROR; + } + + return result; } OCStackResult OCSecure::getDevInfoFromNetwork(unsigned short timeout, @@ -512,6 +573,35 @@ namespace OC return result; } +#ifdef MULTIPLE_OWNER + OCStackResult OCSecureResource::doMultipleOwnershipTransfer(ResultCallBack resultCallback) + { + if (!resultCallback) + { + oclog() <<"Result callback can't be null"; + return OC_STACK_INVALID_CALLBACK; + } + + OCStackResult result; + auto cLock = m_csdkLock.lock(); + + if (cLock) + { + ProvisionContext* context = new ProvisionContext(resultCallback); + + std::lock_guard lock(*cLock); + result = OCDoMultipleOwnershipTransfer(static_cast(context), + devPtr, &OCSecureResource::callbackWrapper); + } + else + { + oclog() <<"Mutex not found"; + result = OC_STACK_ERROR; + } + return result; + } + +#endif OCStackResult OCSecureResource::provisionACL( const OicSecAcl_t* acl, ResultCallBack resultCallback) { @@ -818,4 +908,134 @@ namespace OC throw OCException("Incomplete secure resource", OC_STACK_RESOURCE_ERROR); } } + +#ifdef MULTIPLE_OWNER + OCStackResult OCSecureResource::selectMOTMethod( const OicSecOxm_t oxmSelVal, + ResultCallBack resultCallback) + { + if (!resultCallback) + { + oclog() <<"result callback can not be null"; + return OC_STACK_INVALID_CALLBACK; + } + + OCStackResult result; + auto cLock = m_csdkLock.lock(); + + if (cLock) + { + ProvisionContext* context = new ProvisionContext(resultCallback); + + std::lock_guard lock(*cLock); + result = OCSelectMOTMethod(static_cast(context), + devPtr, oxmSelVal, + &OCSecureResource::callbackWrapper); + } + else + { + oclog() <<"Mutex not found"; + result = OC_STACK_ERROR; + } + return result; + } + + OCStackResult OCSecureResource::changeMOTMode( const OicSecMomType_t momType, + ResultCallBack resultCallback) + { + if (!resultCallback) + { + oclog() <<"result callback can not be null"; + return OC_STACK_INVALID_CALLBACK; + } + + OCStackResult result; + auto cLock = m_csdkLock.lock(); + + if (cLock) + { + ProvisionContext* context = new ProvisionContext(resultCallback); + + std::lock_guard lock(*cLock); + result = OCChangeMOTMode(static_cast(context), + devPtr, momType, + &OCSecureResource::callbackWrapper); + } + else + { + oclog() <<"Mutex not found"; + result = OC_STACK_ERROR; + } + return result; + } + + + OCStackResult OCSecureResource::addPreconfigPIN(const char* preconfPIN, + size_t preconfPINLength) + { + if (!preconfPIN) + { + oclog() <<"pre config pin can not be null"; + return OC_STACK_INVALID_PARAM; + } + if (preconfPINLength <= 0) + { + oclog() <<"pre config pin length can not be zero or less"; + return OC_STACK_INVALID_PARAM; + } + OCStackResult result; + auto cLock = m_csdkLock.lock(); + + if (cLock) + { + std::lock_guard lock(*cLock); + result = OCAddPreconfigPin(devPtr, preconfPIN, + preconfPINLength); + } + else + { + oclog() <<"Mutex not found"; + result = OC_STACK_ERROR; + } + return result; + } + + OCStackResult OCSecureResource::provisionPreconfPin(const char * preconfPin, + size_t preconfPinLength, ResultCallBack resultCallback) + { + if (!resultCallback) + { + oclog() <<"result callback can not be null"; + return OC_STACK_INVALID_CALLBACK; + } + if (!preconfPin) + { + oclog() <<"pre config pin can not be null"; + return OC_STACK_INVALID_PARAM; + } + if (preconfPinLength <= 0) + { + oclog() <<"pre config pin length can not be zero or less"; + return OC_STACK_INVALID_PARAM; + } + + OCStackResult result; + auto cLock = m_csdkLock.lock(); + + if (cLock) + { + ProvisionContext* context = new ProvisionContext(resultCallback); + + std::lock_guard lock(*cLock); + result = OCProvisionPreconfigPin(static_cast(context), + devPtr, preconfPin, preconfPinLength, + &OCSecureResource::callbackWrapper); + } + else + { + oclog() <<"Mutex not found"; + result = OC_STACK_ERROR; + } + return result; + } +#endif // MULTIPLE_OWNER } diff --git a/resource/provisioning/unittests/OCProvisioningTest.cpp b/resource/provisioning/unittests/OCProvisioningTest.cpp old mode 100755 new mode 100644 index 41567f0..5642dda --- a/resource/provisioning/unittests/OCProvisioningTest.cpp +++ b/resource/provisioning/unittests/OCProvisioningTest.cpp @@ -82,6 +82,32 @@ namespace OCProvisioningTest EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSecure::discoverUnownedDevices(0, list)); } +#ifdef MULTIPLE_OWNER + TEST(MOTDiscoveryTest, MultipleOwnerEnabledDevices) + { + DeviceList_t list; + EXPECT_EQ(OC_STACK_OK, OCSecure::discoverMultipleOwnerEnabledDevices(TIMEOUT, list)); + } + + TEST(MOTDiscoveryTest, MultipleOwnerEnabledDevicesZeroTimeOut) + { + DeviceList_t list; + EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSecure::discoverMultipleOwnerEnabledDevices(0, list)); + } + + TEST(MOTDiscoveryTest, MultipleOwnedDevices) + { + DeviceList_t list; + EXPECT_EQ(OC_STACK_OK, OCSecure::discoverMultipleOwnedDevices(TIMEOUT, list)); + } + + TEST(MOTDiscoveryTest, MultipleOwnedDevicesZeroTimeOut) + { + DeviceList_t list; + EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSecure::discoverMultipleOwnedDevices(0, list)); + } +#endif + TEST(DiscoveryTest, OwnedDevices) { DeviceList_t list; @@ -94,52 +120,47 @@ namespace OCProvisioningTest EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSecure::discoverOwnedDevices(0, list)); } - TEST(OwnershipTest, SetOwnershipTransferCBDataNull) + TEST(OwnershipTest, OwnershipTransferNullCallback) { - EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSecure::setOwnerTransferCallbackData( - OIC_JUST_WORKS, NULL, NULL)); + OCSecureResource device; + EXPECT_EQ(OC_STACK_INVALID_CALLBACK, device.doOwnershipTransfer(nullptr)); } - TEST(OwnershipTest, SetOwnershipTransferCBData) +#ifdef MULTIPLE_OWNER + TEST(MOTOwnershipTest, MOTOwnershipTransferNullCallback) { - OTMCallbackData_t justWorksCBData; - justWorksCBData.loadSecretCB = LoadSecretJustWorksCallback; - justWorksCBData.createSecureSessionCB = CreateSecureSessionJustWorksCallback; - justWorksCBData.createSelectOxmPayloadCB = CreateJustWorksSelectOxmPayload; - justWorksCBData.createOwnerTransferPayloadCB = CreateJustWorksOwnerTransferPayload; - EXPECT_EQ(OC_STACK_OK, OCSecure::setOwnerTransferCallbackData(OIC_JUST_WORKS, - &justWorksCBData, NULL)); + OCSecureResource device; + EXPECT_EQ(OC_STACK_INVALID_CALLBACK, device.doMultipleOwnershipTransfer(nullptr)); } - TEST(OwnershipTest, SetOwnershipTransferCBDataInvalidType) + TEST(selectMOTMethodTest, selectMOTMethodNullCallback) { - OTMCallbackData_t justWorksCBData; - justWorksCBData.loadSecretCB = LoadSecretJustWorksCallback; - justWorksCBData.createSecureSessionCB = CreateSecureSessionJustWorksCallback; - justWorksCBData.createSelectOxmPayloadCB = CreateJustWorksSelectOxmPayload; - justWorksCBData.createOwnerTransferPayloadCB = CreateJustWorksOwnerTransferPayload; - EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSecure::setOwnerTransferCallbackData(OIC_OXM_COUNT, - &justWorksCBData, NULL)); + OCSecureResource device; + const OicSecOxm_t stsecOxm = OIC_PRECONFIG_PIN; + EXPECT_EQ(OC_STACK_INVALID_CALLBACK, device.selectMOTMethod(stsecOxm, NULL)); } - TEST(OwnershipTest, SetOwnershipTransferCBDataNullInputPin) + TEST(changeMOTModeTest, changeMOTModeNullCallback) { - OTMCallbackData_t pinBasedCBData; - pinBasedCBData.loadSecretCB = InputPinCodeCallback; - pinBasedCBData.createSecureSessionCB = CreateSecureSessionRandomPinCallback; - pinBasedCBData.createSelectOxmPayloadCB = CreatePinBasedSelectOxmPayload; - pinBasedCBData.createOwnerTransferPayloadCB = CreatePinBasedOwnerTransferPayload; - OTMSetOwnershipTransferCallbackData(OIC_RANDOM_DEVICE_PIN, &pinBasedCBData); + OCSecureResource device; + const OicSecMomType_t momType = OIC_MULTIPLE_OWNER_ENABLE; + EXPECT_EQ(OC_STACK_INVALID_CALLBACK, device.changeMOTMode(momType, NULL)); + } - EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSecure::setOwnerTransferCallbackData( - OIC_RANDOM_DEVICE_PIN, &pinBasedCBData, NULL)); + TEST(addPreconfigPINTest, addPreconfigPINNullPin) + { + OCSecureResource device; + EXPECT_EQ(OC_STACK_INVALID_PARAM, device.addPreconfigPIN(NULL, 0)); } - TEST(OwnershipTest, OwnershipTransferNullCallback) + TEST(provisionPreconfPinTest, provisionPreconfPinNullCallback) { OCSecureResource device; - EXPECT_EQ(OC_STACK_INVALID_CALLBACK, device.doOwnershipTransfer(nullptr)); + const char *pin = "test"; + size_t PinLength = 4; + EXPECT_EQ(OC_STACK_INVALID_CALLBACK, device.provisionPreconfPin(pin, PinLength, NULL)); } +#endif TEST(DeviceInfoTest, DevInfoFromNetwork) { diff --git a/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp b/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp old mode 100755 new mode 100644 index c9b4285..7e39ff9 --- a/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp +++ b/service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp @@ -209,17 +209,13 @@ namespace OIC OCStackResult result = OC_STACK_ERROR; - OTMCallbackData_t justWorksCBData; - justWorksCBData.loadSecretCB = LoadSecretJustWorksCallback; - justWorksCBData.createSecureSessionCB = CreateSecureSessionJustWorksCallback; - justWorksCBData.createSelectOxmPayloadCB = CreateJustWorksSelectOxmPayload; - justWorksCBData.createOwnerTransferPayloadCB = - CreateJustWorksOwnerTransferPayload; - OCSecure::setOwnerTransferCallbackData(OIC_JUST_WORKS, &justWorksCBData, NULL); - OIC_LOG_V(DEBUG, ENROLEE_SECURITY_TAG, "Transfering ownership for : %s ", m_securedResource->getDeviceID().c_str()); + //In case of random pin, argument should be inputPinCallback func. + // for justwork, not required(NULL) + OCSecure::setInputPinCallback(NULL); + OC::ResultCallBack ownershipTransferCb = std::bind( &EnrolleeSecurity::ownershipTransferCb, this, std::placeholders::_1, std::placeholders::_2); -- 2.7.4