Added C++ wrapper for cert provisioning apis
authorRandeep Singh <randeep.s@samsung.com>
Sat, 27 Aug 2016 09:02:12 +0000 (14:32 +0530)
committerRandeep Singh <randeep.s@samsung.com>
Wed, 31 Aug 2016 10:45:50 +0000 (10:45 +0000)
[Patch #2,#3] Updated code according to review comments.
           Moved saveTrustCertChain to OCSecure as static api.

Change-Id: I8fe3fa316a6c4822f642ad0094d97585f77253d5
Signed-off-by: Randeep Singh <randeep.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/10997
Reviewed-by: dongik Lee <dongik.lee@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
resource/include/OCProvisioningManager.h [changed mode: 0755->0644]
resource/provisioning/src/OCProvisioningManager.cpp [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index add8105..b917b3d
@@ -208,6 +208,20 @@ namespace OC
                     std::string uuid,
                     ResultCallBack resultCallback);
 
+#if defined(__WITH_X509__) || defined(__WITH_TLS__)
+            /**
+             * API to save Trust certificate chain into Cred of SVR.
+             *
+             * @param[in] trustCertChain Trust certificate chain to be saved in Cred of SVR.
+             * @param[in] chainSize Size of trust certificate chain to be saved in Cred of SVR
+             * @param[in] encodingType Encoding type of trust certificate chain to be saved in Cred of SVR
+             * @param[out] credId CredId of saved trust certificate chain in Cred of SVR.
+             * @return  OC_STACK_OK in case of success and other value otherwise.
+             */
+            static OCStackResult saveTrustCertChain(uint8_t *trustCertChain, size_t chainSize,
+                                        OicEncodingType_t encodingType, uint16_t *credId);
+#endif // __WITH_X509__ || __WITH_TLS__
+
     };
 
     /**
@@ -309,6 +323,21 @@ namespace OC
             OCStackResult provisionDirectPairing(const OicSecPconf_t *pconf,
                     ResultCallBack resultCallback);
 
+#if defined(__WITH_X509__) || defined(__WITH_TLS__)
+            /**
+             * API to provision cert.
+             *
+             * @param type type of cred.
+             * @param credId id of cert.
+             * @param resultCallback Callback will be called when provisioning request
+             *                           receives a response from resource server.
+             * @return  ::OC_STACK_OK in case of success and other value otherwise.
+             */
+            OCStackResult provisionTrustCertChain(OicSecCredType_t type, uint16_t credId,
+                    ResultCallBack resultCallback);
+
+#endif // __WITH_X509__ || __WITH_TLS__
+
             /**
              * This method is used to get linked devices' IDs.
              *
old mode 100755 (executable)
new mode 100644 (file)
index 822297a..ac4ed83
@@ -310,6 +310,37 @@ namespace OC
         return result;
     }
 
+#if defined(__WITH_X509__) || defined(__WITH_TLS__)
+    OCStackResult OCSecure::saveTrustCertChain(uint8_t *trustCertChain, size_t chainSize,
+                                        OicEncodingType_t encodingType, uint16_t *credId)
+    {
+        if (!trustCertChain)
+        {
+            oclog() <<"trustCertChain can't be null";
+            return OC_STACK_INVALID_PARAM;
+        }
+        if (!credId)
+        {
+            oclog() <<"cred ID can not be null";
+            return OC_STACK_INVALID_PARAM;
+        }
+
+        OCStackResult result;
+        auto cLock = OCPlatform_impl::Instance().csdkLock().lock();
+
+        if (cLock)
+        {
+            std::lock_guard<std::recursive_mutex> lock(*cLock);
+            result = OCSaveTrustCertChain(trustCertChain, chainSize, encodingType, credId );
+        }
+        else
+        {
+            oclog() <<"Mutex not found";
+            result = OC_STACK_ERROR;
+        }
+        return result;
+    }
+#endif // __WITH_X509__ || __WITH_TLS__
 
     void OCSecureResource::callbackWrapper(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool hasError)
     {
@@ -603,6 +634,42 @@ namespace OC
         return result;
     }
 
+#if defined(__WITH_X509__) || defined(__WITH_TLS__)
+    OCStackResult OCSecureResource::provisionTrustCertChain(OicSecCredType_t type, uint16_t credId,
+                    ResultCallBack resultCallback)
+    {
+        if (SIGNED_ASYMMETRIC_KEY != type)
+        {
+            oclog() <<"Invalid key type";
+            return OC_STACK_INVALID_PARAM;
+        }
+        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<std::recursive_mutex> lock(*cLock);
+            result = OCProvisionTrustCertChain(static_cast<void*>(context),
+                    type, credId, devPtr,
+                    &OCSecureResource::callbackWrapper);
+        }
+        else
+        {
+            oclog() <<"Mutex not found";
+            result = OC_STACK_ERROR;
+        }
+        return result;
+    }
+#endif // __WITH_X509__ || __WITH_TLS__
+
     std::string OCSecureResource::getDeviceID()
     {
         std::ostringstream deviceId("");