IoTivity C++ SDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OCProvisioningManager.hpp
Go to the documentation of this file.
1 //****************************************************************
2 //
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20 
21 #ifndef OC_PROVISIONINGMANAGER_CXX_H_
22 #define OC_PROVISIONINGMANAGER_CXX_H_
23 
24 #include <thread>
25 
26 #include "pinoxmcommon.h"
27 #include "ocprovisioningmanager.h"
28 #include "OCApi.h"
29 #include "OCPlatform_impl.h"
30 #include "oxmverifycommon.h"
31 #include "experimental/securevirtualresourcetypes.h"
32 
33 namespace OC
34 {
36 
37  typedef std::vector<std::shared_ptr<OCSecureResource>> DeviceList_t;
38  typedef std::vector<OicUuid_t> UuidList_t;
39  typedef std::vector<OCProvisionResult_t> PMResultList_t;
40  typedef std::function<void(PMResultList_t *result, int hasError)> ResultCallBack;
41  typedef std::function<void(uint16_t credId, uint8_t *trustCertChain,
42  size_t chainSize)>CertChainCallBack;
43  typedef std::function<OCStackResult(uint8_t verifNum[])> DisplayNumCB;
44  typedef std::function<OCStackResult()> UserConfirmNumCB;
45  typedef std::function<void(char* pinData, size_t pinSize)> DisplayPinCB;
46  typedef std::function<void(OicUuid_t deviceId, char* pinBuffer, size_t pinBufferSize)> InputPinCB;
47 
49  {
52  };
53 
55  {
58  };
59 
61  {
64  };
65 
67  {
70  };
71 
73  {
76  };
77 
79  {
82  };
83 
86 
97  class Credential
98  {
99  OicSecCredType_t m_type;
100  size_t m_keySize;
101  public:
102  Credential() = default;
103  Credential(OicSecCredType_t type, size_t size) : m_type(type), m_keySize(size)
104  {}
105 
110  OicSecCredType_t getCredentialType() const
111  {
112  return m_type;
113  }
114 
119  size_t getCredentialKeySize() const
120  {
121  return m_keySize;
122  }
123 
134  void setCredentialType(OicSecCredType_t type)
135  {
136  this->m_type = type;
137  }
138 
144  void setCredentialKeySize(size_t keySize)
145  {
146  this->m_keySize = keySize;
147  }
148  };
149 
150  class OCSecure
151  {
152  private:
156  static void callbackWrapper(void* ctx, size_t nOfRes,
157  OCProvisionResult_t *arr, bool hasError);
158 
167  static OCStackResult OC_CALL displayNumCallbackWrapper(void* ctx,
168  uint8_t verifNum[MUTUAL_VERIF_NUM_LEN]);
169 
175  static OCStackResult OC_CALL confirmUserCallbackWrapper(void* ctx);
176 
185  static void certCallbackWrapper(void* ctx, uint16_t credId, uint8_t *trustCertChain,
186  size_t chainSize);
187 
188  public:
199  static OCStackResult provisionInit(const std::string& dbPath);
200 
208  static OCStackResult provisionClose();
209 
219  static OCStackResult discoverUnownedDevices(unsigned short timeout,
220  DeviceList_t &list);
221 
231  static OCStackResult discoverOwnedDevices(unsigned short timeout,
232  DeviceList_t &list);
233 
246  static OCStackResult discoverSingleDevice(unsigned short timeout,
247  const OicUuid_t* deviceID,
248  std::shared_ptr<OCSecureResource> &foundDevice);
249 
260  static OCStackResult setOwnerTransferCallbackData(OicSecOxm_t oxm,
261  OTMCallbackData_t* callbackData, InputPinCallback inputPin);
262 
277  static OCStackResult discoverSingleDeviceInUnicast(unsigned short timeout,
278  const OicUuid_t* deviceID,
279  const std::string& hostAddress,
280  OCConnectivityType connType,
281  std::shared_ptr<OCSecureResource> &foundDevice);
282 
283 #ifdef MULTIPLE_OWNER
284 
293  static OCStackResult discoverMultipleOwnerEnabledDevices(unsigned short timeout,
294  DeviceList_t &list);
295 
305  static OCStackResult discoverMultipleOwnedDevices(unsigned short timeout,
306  DeviceList_t &list);
307 
321  static OCStackResult discoverMultipleOwnerEnabledDevice(unsigned short timeout,
322  const OicUuid_t* deviceID,
323  std::shared_ptr<OCSecureResource> &foundDevice);
324 
325 #endif
326 
339  static OCStackResult setInputPinCallback(InputPinCallback inputPin);
340 
349 
362  static OCStackResult registerInputPinCallback(InputPinCB inputPinCB, InputPinCallbackHandle* inputPinCallbackHandle);
363 
370  static OCStackResult deregisterInputPinCallback(InputPinCallbackHandle inputPinCallbackHandle);
371 
384  static OCStackResult setDisplayPinCB(GeneratePinCallback displayPin);
385 
394 
402  static OCStackResult setRandomPinPolicy(size_t pinSize, OicSecPinType_t pinType);
403 
416  static OCStackResult registerDisplayPinCallback(DisplayPinCB displayPinCB, DisplayPinCallbackHandle* displayPinCallbackHandle);
417 
425 
439  static OCStackResult getDevInfoFromNetwork(unsigned short timeout,
440  DeviceList_t &ownedDevList,
441  DeviceList_t &unownedDevList);
442 
453  static OCStackResult removeDeviceWithUuid(unsigned short waitTimeForOwnedDeviceDiscovery,
454  std::string uuid,
455  ResultCallBack resultCallback);
456 
463  static OCStackResult saveACL(const OicSecAcl_t* acl);
464 
472 
479 
486 
493 
498  static OCStackResult setVerifyOptionMask(VerifyOptionBitmask_t optionMask);
499 
500 
508 
509 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
510 
519  static OCStackResult saveTrustCertChain(uint8_t *trustCertChain, size_t chainSize,
520  OicEncodingType_t encodingType, uint16_t *credId);
521 
530  static OCStackResult readTrustCertChain(uint16_t credId, uint8_t **trustCertChain,
531  size_t *chainSize);
532 
541  static OCStackResult registerTrustCertChangeNotifier(CertChainCallBack);
542 
548  static OCStackResult removeTrustCertChangeNotifier();
549 
556  static OCStackResult setDeviceIdSeed(const uint8_t* seed, size_t seedSize);
557 #endif // __WITH_DTLS__ || __WITH_TLS__
558 
559 
566  };
567 
573  {
574  private:
575  std::weak_ptr<std::recursive_mutex> m_csdkLock;
576  OCProvisionDev_t *devPtr; // pointer to device.
577 
578  public:
580  OCSecureResource(std::weak_ptr<std::recursive_mutex> csdkLock, OCProvisionDev_t *dPtr);
581 
583 
596  OCStackResult provisionPairwiseDevices(const Credential &cred, const OicSecAcl_t* acl1,
597  const OCSecureResource &device2, const OicSecAcl_t* acl2,
598  ResultCallBack resultCallback);
599 
608 
617  OCStackResult provisionACL(const OicSecAcl_t* acl,
618  ResultCallBack resultCallback);
619 
630  const OCSecureResource &device2,
631  ResultCallBack resultCallback);
632 
642  ResultCallBack resultCallback);
643 
653  OCStackResult removeDevice(unsigned short waitTimeForOwnedDeviceDiscovery,
654  ResultCallBack resultCallback);
655 
656 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
657 
666  OCStackResult provisionTrustCertChain(OicSecCredType_t type, uint16_t credId,
667  ResultCallBack resultCallback);
668 
669 #endif // __WITH_DTLS__ or __WITH_TLS__
670 
678 
683  std::string getDeviceID();
684 
689  OCProvisionDev_t* getDevPtr()const;
690 
695  std::string getDevAddr();
696 
701  int getDeviceStatus();
702 
707  bool getOwnedStatus();
708 
714 
722  OCStackResult getOTMethod(OicSecOxm_t* oxm);
723 
724 #ifdef MULTIPLE_OWNER
725 
733  OCStackResult selectMOTMethod( const OicSecOxm_t oxmSelVal,
734  ResultCallBack resultCallback);
735 
744  OCStackResult changeMOTMode( const OicSecMomType_t momType,
745  ResultCallBack resultCallback);
746 
754  OCStackResult addPreconfigPIN(const char* preconfPIN,
755  size_t preconfPINLength);
756 
766  OCStackResult provisionPreconfPin(const char * preconfPin,
767  size_t preconfPinLength, ResultCallBack resultCallback);
768 
776  OCStackResult doMultipleOwnershipTransfer(ResultCallBack resultCallback);
777 
785  OCStackResult isSubownerOfDevice(bool* subowner);
786 
794  OCStackResult getMOTMethod( OicSecOxm_t* oxm);
795 
801  bool isMOTSupported();
802 
808  bool isMOTEnabled();
809 
810 #endif // MULTIPLE_OWNER
811 
812  private:
816  static void callbackWrapper(void* ctx, size_t nOfRes,
817  OCProvisionResult_t *arr, bool hasError);
818 
819  void validateSecureResource();
820  };
821 
822 }
823 #endif // OC_PROVISIONINGMANAGER_CXX_H_
OCStackResult provisionCredentials(const Credential &cred, const OCSecureResource &device2, ResultCallBack resultCallback)
API to provision credential to devices.
std::function< void(char *pinData, size_t pinSize)> DisplayPinCB
Definition: OCProvisioningManager.hpp:45
DisplayPinContext(DisplayPinCB cb)
Definition: OCProvisioningManager.hpp:63
CertChainCallBack callback
Definition: OCProvisioningManager.hpp:56
static OCStackResult deregisterInputPinCallback(InputPinCallbackHandle inputPinCallbackHandle)
API to de-register the callback to input a pin.
OCProvisionDev_t * getDevPtr() const
API to get the information of device for provisioning.
Definition: OCProvisioningManager.hpp:60
OicSecOxm_t getSelectedOwnershipTransferMethod()
This function provides the selected ownership transfer method of the device.
TrustCertChainContext(CertChainCallBack cb)
Definition: OCProvisioningManager.hpp:57
Credential(OicSecCredType_t type, size_t size)
Definition: OCProvisioningManager.hpp:103
InputPinContext(InputPinCB cb)
Definition: OCProvisioningManager.hpp:69
Definition: OCProvisioningManager.hpp:48
void setCredentialType(OicSecCredType_t type)
API to set credential type of device.
Definition: OCProvisioningManager.hpp:134
static OCStackResult setRandomPinPolicy(size_t pinSize, OicSecPinType_t pinType)
API to set Pin Type policy.
UserConfirmNumContext(UserConfirmNumCB cb)
Definition: OCProvisioningManager.hpp:81
static OCStackResult pdmCleanupForTimeout()
API to cleanup PDM in case of timeout.
ProvisionContext(ResultCallBack cb)
Definition: OCProvisioningManager.hpp:51
static OCStackResult setDisplayPinCB(GeneratePinCallback displayPin)
API to register a callback to display the stack generated PIN.
static OCStackResult saveACL(const OicSecAcl_t *acl)
API to save ACL which has several ACE into Acl of SVR.
static OCStackResult unsetInputPinCallback()
API for de-registering a pin callback.
DisplayPinCB callback
Definition: OCProvisioningManager.hpp:62
static OCStackResult unsetDisplayPinCB()
API for de-registering the display pin callback.
size_t getCredentialKeySize() const
API to get size of credential key type.
Definition: OCProvisioningManager.hpp:119
Definition: OCProvisioningManager.hpp:66
static OCStackResult registerDisplayPinCallback(DisplayPinCB displayPinCB, DisplayPinCallbackHandle *displayPinCallbackHandle)
API to register for a callback to display a pin.
static OCStackResult discoverSingleDeviceInUnicast(unsigned short timeout, const OicUuid_t *deviceID, const std::string &hostAddress, OCConnectivityType connType, std::shared_ptr< OCSecureResource > &foundDevice)
API is responsible for discovery of devices in specified endpoint/deviceID.
static OCStackResult setInputPinCallback(InputPinCallback inputPin)
API for registering a pin input callback.
int getDeviceStatus()
This function returns the device's Status.
static OCStackResult deregisterDisplayNumCallback()
API to De-register Callback for displaying verifNum in verification Just-Works.
static OCStackResult removeDeviceWithUuid(unsigned short waitTimeForOwnedDeviceDiscovery, std::string uuid, ResultCallBack resultCallback)
API to remove device credential and ACL from all devices in subnet.
static OCStackResult configSelfOwnership()
This function configures SVR DB as self-ownership.
InputPinContext * InputPinCallbackHandle
Definition: OCProvisioningManager.hpp:84
std::function< void(OicUuid_t deviceId, char *pinBuffer, size_t pinBufferSize)> InputPinCB
Definition: OCProvisioningManager.hpp:46
static OCStackResult provisionInit(const std::string &dbPath)
The API is responsible for initialization of the provisioning manager.
This class represents a secure virtual device, which can be provisioned by the provisioning client...
Definition: OCProvisioningManager.hpp:572
bool getOwnedStatus()
This function provides the owned status of the device.
OicSecCredType_t getCredentialType() const
API to get credential type of device.
Definition: OCProvisioningManager.hpp:110
std::function< OCStackResult()> UserConfirmNumCB
Definition: OCProvisioningManager.hpp:44
OCStackResult
Declares Stack Results & Errors.
Definition: octypes.h:1054
Definition: OCProvisioningManager.hpp:150
DisplayNumCB callback
Definition: OCProvisioningManager.hpp:74
std::string getDevAddr()
This function returns the device's IP address.
DisplayPinContext * DisplayPinCallbackHandle
Definition: OCProvisioningManager.hpp:85
OCConnectivityType
This enum type includes elements of both OCTransportAdapter and OCTransportFlags. ...
Definition: octypes.h:829
Definition: OCProvisioningManager.hpp:72
ResultCallBack callback
Definition: OCProvisioningManager.hpp:50
This class is for credential's to be set to devices.
Definition: OCProvisioningManager.hpp:97
static OCStackResult deregisterDisplayPinCallback(DisplayPinCallbackHandle displayPinCallbackHandle)
API to de-register the callback to display a pin.
static OCStackResult discoverUnownedDevices(unsigned short timeout, DeviceList_t &list)
API is responsible for discovery of devices in it's subnet.
InputPinCB callback
Definition: OCProvisioningManager.hpp:68
std::function< OCStackResult(uint8_t verifNum[])> DisplayNumCB
Definition: OCProvisioningManager.hpp:43
std::string getDeviceID()
API to get the device ID of this resource.
OCStackResult getLinkedDevices(UuidList_t &uuidList)
This method is used to get linked devices' IDs.
OCStackResult getOTMethod(OicSecOxm_t *oxm)
API to get the proper OxM for OT.
static OCStackResult discoverOwnedDevices(unsigned short timeout, DeviceList_t &list)
API is responsible for discovery of devices in it's subnet.
static OCStackResult setOwnerTransferCallbackData(OicSecOxm_t oxm, OTMCallbackData_t *callbackData, InputPinCallback inputPin)
API for registering Ownership transfer methods for a particular transfer Type.
std::function< void(PMResultList_t *result, int hasError)> ResultCallBack
Definition: OCProvisioningManager.hpp:40
Credential()=default
static OCStackResult provisionClose()
This method is used by provisioning manager to close provisioning database.
static OCStackResult deregisterUserConfirmCallback()
API to De-register Callback for getting user confirmation in verification Just-Works.
static OCStackResult registerUserConfirmCallback(UserConfirmNumCB userConfirmCB)
API to reister Callback for getting user confirmation in verification Just-Works. ...
OCStackResult removeDevice(unsigned short waitTimeForOwnedDeviceDiscovery, ResultCallBack resultCallback)
API to remove device credential from all devices in subnet.
OCStackResult provisionACL(const OicSecAcl_t *acl, ResultCallBack resultCallback)
API to send ACL information to resource.
DisplayNumContext(DisplayNumCB cb)
Definition: OCProvisioningManager.hpp:75
static OCStackResult discoverSingleDevice(unsigned short timeout, const OicUuid_t *deviceID, std::shared_ptr< OCSecureResource > &foundDevice)
API is responsible for discovery of devices in specified endpoint/deviceID.
static OCStackResult registerInputPinCallback(InputPinCB inputPinCB, InputPinCallbackHandle *inputPinCallbackHandle)
API to register for a callback to input a pin.
UserConfirmNumCB callback
Definition: OCProvisioningManager.hpp:80
void setCredentialKeySize(size_t keySize)
API to set size of credential key type.
Definition: OCProvisioningManager.hpp:144
static OCStackResult registerDisplayNumCallback(DisplayNumCB displayNumCB)
api to register Callback for displaying verifNum in verification Just-Works
std::vector< std::shared_ptr< OCSecureResource > > DeviceList_t
Definition: OCProvisioningManager.hpp:35
static OCStackResult getDevInfoFromNetwork(unsigned short timeout, DeviceList_t &ownedDevList, DeviceList_t &unownedDevList)
API to get status of all the devices in current subnet.
Definition: OCProvisioningManager.hpp:54
Definition: OCProvisioningManager.hpp:78
std::function< void(uint16_t credId, uint8_t *trustCertChain, size_t chainSize)> CertChainCallBack
Definition: OCProvisioningManager.hpp:42
std::vector< OicUuid_t > UuidList_t
Definition: OCProvisioningManager.hpp:38
std::vector< OCProvisionResult_t > PMResultList_t
Definition: OCProvisioningManager.hpp:39
static OCStackResult setVerifyOptionMask(VerifyOptionBitmask_t optionMask)
Set option for Mutual Verified Just-Works The default is both display PIN and get user confirmation...
OCStackResult unlinkDevices(const OCSecureResource &device2, ResultCallBack resultCallback)
API to remove the credential & relationship between the two devices.
OCStackResult provisionPairwiseDevices(const Credential &cred, const OicSecAcl_t *acl1, const OCSecureResource &device2, const OicSecAcl_t *acl2, ResultCallBack resultCallback)
API to provision credentials between two devices and ACLs for the devices who act as a server...
OCStackResult doOwnershipTransfer(ResultCallBack resultCallback)
API to do ownership transfer for un-owned device.