Commit d2f43781 authored by Joonghwan Lee's avatar Joonghwan Lee Committed by Randeep

Add direct-pairing feature

 <contents of modification/addition>
 : Added direct-pairing resouces and related types
 : Added direct-pairing provisioning feature for provisioning tool
 : Added D2D pairing operation feature(discovery, pairing) for client
 : Added RI layer APIs and data types for direct-pairing client
 : Modified provisioning tool for direct-pairing feature and created new sample client

-Patch 1: Initial
-Patch 2: Fix OSX build error.
-Patch 3: Add DPC(Direct Pairing Capability) resource and processing logic
-Patch 4: Fix dpc parse error when loading svr db
-Patch 5: Fix unnormal processing when duplicated request on dpairing resource & Change DPC default value as true
-Patch 6: Fix SVACE warning & Divide pconf and dpairing resource into another ACL entry in svr db
-Patch 7: Fix SVACE warning's positive false
-Patch 8: Fix device list management

Change-Id: I461626fe041a5927c0e27e78e63e74e215d61cd5
Signed-off-by: default avatarJoonghwan Lee <jh05.lee@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5673Reviewed-by: default avatarJongsung Lee <js126.lee@samsung.com>
Reviewed-by: default avatarKyungsun Cho <goodsun.cho@samsung.com>
Reviewed-by: default avatarChul Lee <chuls.lee@samsung.com>
Reviewed-by: default avatardongik Lee <dongik.lee@samsung.com>
Reviewed-by: Randeep's avatarRandeep Singh <randeep.s@samsung.com>
Tested-by: Randeep's avatarRandeep Singh <randeep.s@samsung.com>
parent e432aeff
......@@ -55,6 +55,7 @@ liboctbstack_env.PrependUnique(CPPPATH = [
'connectivity/external/inc',
'security/include',
'security/include/internal',
'security/provisioning/include',
])
if target_os not in ['arduino', 'windows', 'winrt']:
......
......@@ -52,7 +52,8 @@ libocsrm_env.PrependUnique(CPPPATH = [
'../connectivity/inc',
'../connectivity/api',
'../security/include',
'../security/include/internal'
'../security/include/internal',
'../security/provisioning/include'
])
if target_os not in ['arduino', 'windows', 'winrt']:
......@@ -97,6 +98,8 @@ if env.get('SECURED') == '1':
OCSRM_SRC + 'doxmresource.c',
OCSRM_SRC + 'credresource.c',
OCSRM_SRC + 'svcresource.c',
OCSRM_SRC + 'pconfresource.c',
OCSRM_SRC + 'dpairingresource.c',
OCSRM_SRC + 'policyengine.c',
OCSRM_SRC + 'psinterface.c',
OCSRM_SRC + 'srmresourcestrings.c',
......@@ -106,7 +109,8 @@ if env.get('SECURED') == '1':
OCSRM_SRC + 'base64.c',
#pbkdf2.c is required to PIN based OxM only.
#But we did not use a separate build options to prevent the build command becomes complicated.
OCSRM_SRC + 'pbkdf2.c'
OCSRM_SRC + 'pbkdf2.c',
OCSRM_SRC + 'directpairing.c'
]
else:
libocsrm_src = [
......@@ -119,12 +123,15 @@ else:
OCSRM_SRC + 'doxmresource.c',
OCSRM_SRC + 'credresource.c',
OCSRM_SRC + 'svcresource.c',
OCSRM_SRC + 'pconfresource.c',
OCSRM_SRC + 'dpairingresource.c',
OCSRM_SRC + 'policyengine.c',
OCSRM_SRC + 'psinterface.c',
OCSRM_SRC + 'srmresourcestrings.c',
OCSRM_SRC + 'srmutility.c',
OCSRM_SRC + 'iotvticalendar.c',
OCSRM_SRC + 'base64.c'
OCSRM_SRC + 'base64.c',
OCSRM_SRC + 'directpairing.c'
]
if env.get('DTLS_WITH_X509') == '1' and env.get('SECURED') == '1':
......
/* *****************************************************************
*
* Copyright 2016 Samsung Electronics All Rights Reserved.
*
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* *****************************************************************/
#ifndef _DIRECT_PAIRING_H_
#define _DIRECT_PAIRING_H_
#include <stdbool.h>
#include "ocstack.h"
#include "pmtypes.h"
#include "securevirtualresourcetypes.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
* Discover direct-pairing devices in the same IP subnet. .
*
* @param[in] waittime Timeout in seconds.
*
* @return OC_STACK_OK on success otherwise error.
*/
OCStackResult DPDeviceDiscovery(unsigned short waittime);
/**
* Start direct-pairing processes.
*
* @param[in] peer target device to establish direct-pairing.
* @param[in] pmSel selected pairing method.
* @param[in] pinNumber secret value for dtls connection.
* @param[in] resultCallback result event callback.
*
* @return OC_STACK_OK on success otherwise error.
*/
OCStackResult DPDirectPairing(OCDirectPairingDev_t* peer, OicSecPrm_t pmSel, char *pinNumber,
OCDirectPairingResultCB resultCallback);
/**
* This function returns discovered devices list in direct-pairing discovery
* Caller must NOT free returned constant pointer
*
* @return OCDirectPairingDev_t pointer on success otherwise NULL.
*/
const OCDirectPairingDev_t* DPGetDiscoveredDevices();
/**
* This function returns paired devices list until now
* Caller must NOT free returned constant pointer
*
* @return OCDirectPairingDev_t pointer on success otherwise NULL.
*/
const OCDirectPairingDev_t* DPGetPairedDevices();
/**
* This function delete both discovered devices and paired devices list
*
*/
void DPDeleteLists();
#ifdef __cplusplus
}
#endif
#endif //_DIRECT_PAIRING_H_
/* *****************************************************************
*
* Copyright 2016 Samsung Electronics All Rights Reserved.
*
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* *****************************************************************/
#ifndef IOTVT_SRM_DPAIRING_H
#define IOTVT_SRM_DPAIRING_H
#include "octypes.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Initialize DPAIRING resource by loading data from persistent storage.
*
* @retval OC_STACK_OK for Success, otherwise some error value
*/
OCStackResult InitDpairingResource();
/**
* Perform cleanup for DPAIRING resources.
*
* @retval OC_STACK_OK for Success, otherwise some error value
*/
OCStackResult DeInitDpairingResource();
/**
* This method converts JSON DPAIRING into binary DPAIRING.
* The JSON DPAIRING can be from persistent database or
* or received as POST request.
*
* @param[in] jsonStr pconf data in json string.
* @return pointer to OicSecDpairing_t.
*
* @note Caller needs to invoke OCFree after done
* using the return pointer
*/
OicSecDpairing_t * JSONToDpairingBin(const char * jsonStr);
/**
* This method converts DPAIRING data into JSON format.
* Caller needs to invoke 'free' when finished done using
* return string
*
* @param[in] dpair Pointer to OicSecDpairing_t.
* @return pointer to json string.
*
* @note Caller needs to invoke OCFree after done
* using the return pointer
*/
char * BinToDpairingJSON(const OicSecDpairing_t * dpair);
/** This function deallocates the memory for OicSecPconf_t .
*
* @param[in] dpair Pointer to OicSecDpairing_t.
*/
void DeleteDpairingBinData(OicSecDpairing_t* dpair);
#ifdef __WITH_DTLS__
/**
* Function to save PairingPSK.
*
* @param[in] endpoint current endpoint.
* @param[in] peerDevID peer device indentitiy.
* @param[in] isPairingServer indicate if it generates PairingPSK for server or client.
*
* @return OC_STACK_OK on success
*/
OCStackResult SavePairingPSK(OCDevAddr *endpoint,
OicUuid_t *peerDevID, OicUuid_t *owner, bool isPairingServer);
#endif // __WITH_DTLS__
#ifdef __cplusplus
}
#endif
#endif //IOTVT_SRM_DPAIRING_H
/* *****************************************************************
*
* Copyright 2016 Samsung Electronics All Rights Reserved.
*
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* *****************************************************************/
#ifndef IOTVT_SRM_PCONF_H
#define IOTVT_SRM_PCONF_H
#include "octypes.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Initialize PCONF resource by loading data from persistent storage.
*
* @retval OC_STACK_OK for Success, otherwise some error value
*/
OCStackResult InitPconfResource();
/**
* Perform cleanup for PCONF resources.
*
* @retval OC_STACK_OK for Success, otherwise some error value
*/
OCStackResult DeInitPconfResource();
/**
* This method is used by SRM to retrieve PCONF resource data..
*
* @retval reference to @ref OicSecPconf_t, binary format of Pconf resource data
*/
const OicSecPconf_t* GetPconfResourceData();
/**
* This method converts JSON PCONF into binary PCONF.
* The JSON PCONF can be from persistent database or
* or received as PUT request.
*
* @param[in] jsonStr pconf data in json string.
* @return pointer to OicSecPconf_t.
*
* @note Caller needs to invoke OCFree after done
* using the return pointer
*/
OicSecPconf_t * JSONToPconfBin(const char * jsonStr);
/**
* This method converts PCONF data into JSON format.
* Caller needs to invoke 'free' when finished done using
* return string
*
* @param[in] pconf Pointer to OicSecPconf_t.
* @return pointer to json string.
*
* @note Caller needs to invoke OCFree after done
* using the return pointer
*/
char * BinToPconfJSON(const OicSecPconf_t * pconf);
/**
* This method might be used to add a paired device id after direct-pairing process complete.
*
* @param pdeviceId ID of the paired device.
*
* @retval OC_STACK_OK for Success, otherwise some error value
*/
OCStackResult AddPairedDevice(OicUuid_t *pdeviceId);
/**
* This method might be used by PolicyEngine to retrieve PDACL for a Subject.
*
* @param subjectId ID of the subject for which PDACL is required.
* @param savePtr is used internally by @ref GetACLResourceData to maintain index between
* successive calls for same subjectId.
*
* @retval reference to @ref OicSecPdAcl_t if PDACL is found, else NULL
*/
const OicSecPdAcl_t* GetPdAclData(const OicUuid_t* subjectId, OicSecPdAcl_t **savePtr);
/**
* This method return whether device is paired or not.
*
* @param pdeviceId Target device ID to find in paired list.
* @retval ture if device is already paired, else false
*/
bool IsPairedDevice(const OicUuid_t* pdeviceId);
/** This function deallocates the memory for OicSecPconf_t .
*
* @param[in] pconf Pointer to OicSecPconf_t.
*/
void DeletePconfBinData(OicSecPconf_t* pconf);
/**
* This function frees OicSecPdAcl_t object's fields and object itself.
*/
void FreePdAclList(OicSecPdAcl_t* pdacls);
#ifdef __cplusplus
}
#endif
#endif //IOTVT_SRM_PCONF_H
......@@ -62,6 +62,16 @@ extern const char * OIC_RSRC_TYPE_SEC_SVC;
extern const char * OIC_RSRC_SVC_URI;
extern const char * OIC_JSON_SVC_NAME;
//PCONF
extern const char * OIC_RSRC_TYPE_SEC_PCONF;
extern const char * OIC_RSRC_PCONF_URI;
extern const char * OIC_JSON_PCONF_NAME;
//DPAIRING
extern const char * OIC_RSRC_TYPE_SEC_DPAIRING;
extern const char * OIC_RSRC_DPAIRING_URI;
extern const char * OIC_JSON_DPAIRING_NAME;
extern const char * OIC_JSON_SUBJECT_NAME;
extern const char * OIC_JSON_RESOURCES_NAME;
extern const char * OIC_JSON_AMSS_NAME;
......@@ -91,6 +101,15 @@ extern const char * OIC_JSON_SM_NAME;
extern const char * OIC_JSON_SERVICE_DEVICE_ID;
extern const char * OIC_JSON_SERVICE_TYPE;
extern const char * OIC_JSON_SUPPORTED_CRED_TYPE_NAME;
extern const char * OIC_JSON_DPC_NAME;
extern const char * OIC_JSON_EDP_NAME;
extern const char * OIC_JSON_PIN_NAME;
extern const char * OIC_JSON_PDACL_NAME;
extern const char * OIC_JSON_PDDEV_LIST_NAME;
extern const char * OIC_JSON_ROWNER_NAME;
extern const char * OIC_JSON_PRM_NAME;
extern const char * OIC_JSON_SPM_NAME;
extern const char * OIC_JSON_PDEVICE_ID_NAME;
extern OicUuid_t WILDCARD_SUBJECT_ID;
extern size_t WILDCARD_SUBJECT_ID_LEN;
......
......@@ -379,6 +379,7 @@ struct OicSecDoxm
//TODO: Need more clarification on deviceIDFormat field type.
//OicSecDvcIdFrmt_t deviceIDFormat; // 5:R:S:Y:UINT8
OicUuid_t deviceID; // 6:R:S:Y:oic.uuid
bool dpc; // 7:R:S:Y:Boolean
OicUuid_t owner; // 7:R:S:Y:oic.uuid
// NOTE: we are using UUID for Owner instead of Svc type for mid-April
// SRM version only; this will change to Svc type for full implementation.
......@@ -451,6 +452,83 @@ struct OicSecCrl
};
#endif /* __WITH_X509__ */
/**
* @brief direct pairing data type
*/
typedef struct OicPin OicDpPin_t;
typedef struct OicSecPdAcl OicSecPdAcl_t;
typedef struct OicSecPconf OicSecPconf_t;
typedef struct OicSecDpairing OicSecDpairing_t;
#define DP_PIN_LENGTH 8 // temporary length
/**
* @brief /oic/sec/prmtype (Pairing Method Type) data type.
* 0: not allowed
* 1: pre-configured pin
* 2: random pin
*/
typedef enum PRMBitmask
{
PRM_NOT_ALLOWED = 0x0,
PRM_PRE_CONFIGURED = (0x1 << 0),
PRM_RANDOM_PIN = (0x1 << 1),
} PRMBitmask_t;
typedef PRMBitmask_t OicSecPrm_t;
struct OicPin
{
uint8_t val[DP_PIN_LENGTH+1];
};
/**
* @brief oic.sec.dpacltype (Device Pairing Access Control List) data type.
*/
struct OicSecPdAcl
{
// <Attribute ID>:<Read/Write>:<Multiple/Single>:<Mandatory?>:<Type>
char **resources; // 0:R:M:Y:String
size_t resourcesLen; // the number of elts in Resources
uint16_t permission; // 1:R:S:Y:UINT16
char **periods; // 2:R:M*:N:String (<--M*; see Spec)
char **recurrences; // 3:R:M:N:String
size_t prdRecrLen; // the number of elts in Periods/Recurrences
OicSecPdAcl_t *next;
};
/**
* @brief /oic/sec/pconf (Pairing Configuration) data type
*/
struct OicSecPconf
{
// <Attribute ID>:<Read/Write>:<Multiple/Single>:<Mandatory?>:<Type>
bool edp; // 0:W:S:M:Boolean
OicSecPrm_t *prm; // 1:R:M:N:UINT16
size_t prmLen; // the number of elts in Prm
OicDpPin_t pin; // 2:R:S:Y:String
OicSecPdAcl_t *pdacls; // 3:R:M:Y:oic.sec.pdacltype
OicUuid_t *pddevs; // 4:R:M:Y:oic.uuid
size_t pddevLen; // the number of elts in pddev
OicUuid_t deviceID; // 5:R:S:Y:oic.uuid
OicUuid_t rowner; // 6:R:S:Y:oic.uuid
};
/**
* @brief /oic/sec/dpairing (Device Pairing) data type
*/
struct OicSecDpairing
{
// <Attribute ID>:<Read/Write>:<Multiple/Single>:<Mandatory?>:<Type>
OicSecPrm_t spm; // 0:R/W:S:Y:UINT16
OicUuid_t pdeviceID; // 1:R:S:Y:oic.uuid
OicUuid_t rowner; // 2:R:S:Y:oic.uuid
};
#ifdef __cplusplus
}
#endif
......
......@@ -42,6 +42,18 @@ extern "C"
OCStackResult SRPProvisionACL(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
OicSecAcl_t *acl, OCProvisionResultCB resultCallback);
/**
* API to send Direct-Pairing Configuration to a device.
*
* @param[in] selectedDeviceInfo Selected target device.
* @param[in] pconf PCONF pointer.
* @param[in] resultCallback callback provided by API user, callback will be called when
* provisioning request recieves a response from resource server.
* @return OC_STACK_OK in case of success and other value otherwise.
*/
OCStackResult SRPProvisionDirectPairing(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
OicSecPconf_t *pconf, OCProvisionResultCB resultCallback);
/**
* API to provision credential to devices.
*
......
......@@ -116,6 +116,19 @@ OCStackResult OCProvisionPairwiseDevices(void* ctx, OicSecCredType_t type, size_
OCStackResult OCProvisionACL(void *ctx, const OCProvisionDev_t *selectedDeviceInfo, OicSecAcl_t *acl,
OCProvisionResultCB resultCallback);
/**
* this function sends Direct-Pairing Configuration to a device.
*
* @param[in] ctx Application context would be returned in result callback.
* @param[in] selectedDeviceInfo Selected target device.
* @param[in] pconf PCONF pointer.
* @param[in] resultCallback callback provided by API user, callback will be called when provisioning
request recieves a response from resource server.
* @return OC_STACK_OK in case of success and other value otherwise.
*/
OCStackResult OCProvisionDirectPairing(void* ctx, const OCProvisionDev_t *selectedDeviceInfo, OicSecPconf_t *pconf,
OCProvisionResultCB resultCallback);
/**
* API to provision credential to devices.
*
......@@ -216,6 +229,13 @@ void OCDeleteUuidList(OCUuidList_t* pList);
* @param pAcl Pointer to OicSecAcl_t structure.
*/
void OCDeleteACLList(OicSecAcl_t* pAcl);
/**
* This function deletes PDACL data.
*
* @param pPdAcl Pointer to OicSecPdAcl_t structure.
*/
void OCDeletePdAclList(OicSecPdAcl_t* pPdAcl);
#ifdef __WITH_X509__
/**
......
......@@ -71,6 +71,22 @@ typedef struct OCProvisionDev
struct OCProvisionDev *next; /**< Next pointer. **/
}OCProvisionDev_t;
/**
* Device Information of discoverd direct pairing device(s).
*/
typedef struct OCDirectPairingDev
{
OCDevAddr endpoint;
OCConnectivityType connType;
uint16_t securePort;
bool edp;
OicSecPrm_t *prm;
size_t prmLen;
OicUuid_t deviceID;
OicUuid_t rowner;
struct OCDirectPairingDev *next;
} OCDirectPairingDev_t;
/**
* Result information for each target device.
*/
......@@ -90,6 +106,17 @@ typedef struct OCPMResult{
*/
typedef void (*OCProvisionResultCB)(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool hasError);
/**
* Callback function definition of direct-pairing
*
* @param[OUT] peer - pairing device info.
* @param[OUT} result - It's returned with 'OC_STACK_XXX'. It will return 'OC_STACK_OK'
* if D2D pairing is success without error
*/
typedef void (*OCDirectPairingResultCB)(OCDirectPairingDev_t *peer, OCStackResult result);
#ifdef __cplusplus
}
#endif
......
......@@ -25,6 +25,17 @@
"ownrs" : [
"anVzdHdvcmtzRGV2VVVJRA=="
]
},
{
"sub": "Kg==",
"rsrc": [
"/oic/sec/pconf",
"/oic/sec/dpairing"
],
"perms": 6,
"ownrs" : [
"anVzdHdvcmtzRGV2VVVJRA=="
]
}
],
"pstat": {
......@@ -41,6 +52,7 @@
"oxmsel": 0,
"sct": 1,
"owned": false,
"deviceid": "anVzdHdvcmtzRGV2VVVJRA=="
"deviceid": "anVzdHdvcmtzRGV2VVVJRA==",
"dpc": true
}
}
......@@ -25,6 +25,17 @@
"ownrs" : [
"cmFuZG9tUGluRGV2VVVJRA=="
]
},
{
"sub": "Kg==",
"rsrc": [
"/oic/sec/pconf",
"/oic/sec/dpairing"
],
"perms": 6,
"ownrs" : [
"cmFuZG9tUGluRGV2VVVJRA=="