OCStackResult SRPResetDevice(const OCProvisionDev_t* pTargetDev,
OCProvisionResultCB resultCallback);
+/*
+ * Function to read Trust certificate chain from SVR.
+ * Caller must free when done using the returned trust certificate
+ * @param[in] credId CredId of trust certificate chain in SVR.
+ * @param[out] trustCertChain Trust certificate chain.
+ * @param[out] chainSize Size of trust certificate chain
+ * @return OC_STACK_OK in case of success and other value otherwise.
+ */
+OCStackResult SRPReadTrustCertChain(uint16_t credId, uint8_t **trustCertChain,
+ size_t *chainSize);
#ifdef __cplusplus
}
#endif
OCStackResult OCSaveTrustCertChain(uint8_t *trustCertChain, size_t chainSize,\r
OicEncodingType_t encodingType, uint16_t *credId);\r
\r
+/*\r
+ * Function to read Trust certificate chain from SVR.\r
+ * Caller must free when done using the returned trust certificate\r
+ * @param[in] credId CredId of trust certificate chain in SVR.\r
+ * @param[out] trustCertChain Trust certificate chain.\r
+ * @param[out] chainSize Size of trust certificate chain\r
+ * @return OC_STACK_OK in case of success and other value otherwise.\r
+ */\r
+OCStackResult OCReadTrustCertChain(uint16_t credId, uint8_t **trustCertChain,\r
+ size_t *chainSize);\r
+\r
#endif // __WITH_DTLS__ || __WITH_TLS__\r
\r
\r
return SRPGetACLResource(ctx, selectedDeviceInfo, resultCallback);
}
+
+OCStackResult OCReadTrustCertChain(uint16_t credId, uint8_t **trustCertChain,
+ size_t *chainSize)
+{
+ return SRPReadTrustCertChain(credId, trustCertChain, chainSize);
+}
/**
* function to provision credential to devices.
*
return OC_STACK_OK;
}
+
+OCStackResult SRPReadTrustCertChain(uint16_t credId, uint8_t **trustCertChain,
+ size_t *chainSize)
+{
+ OIC_LOG(DEBUG, TAG, "IN SRPReadTrustCertChain");
+
+ OCStackResult res = OC_STACK_ERROR;
+ int secureFlag = 0;
+ OicSecCred_t* credData = GetCredEntryByCredId(credId);
+ if(credData)
+ {
+ res = CredToCBORPayload((const OicSecCred_t*) credData, trustCertChain,
+ chainSize, secureFlag);
+ if(OC_STACK_OK != res)
+ {
+ OIC_LOG(INFO, TAG, "CredToCBORPayload failed");
+ }
+ }
+ DeleteCredList(credData);
+ return res;
+}
*/
static OCStackResult saveTrustCertChain(uint8_t *trustCertChain, size_t chainSize,
OicEncodingType_t encodingType, uint16_t *credId);
+
+
+ /*
+ * API to read Trust certificate chain from SVR.
+ * Caller must free when done using the returned trust certificate
+ * @param[in] credId CredId of trust certificate chain in SVR.
+ * @param[out] trustCertChain Trust certificate chain.
+ * @param[out] chainSize Size of trust certificate chain
+ * @return OC_STACK_OK in case of success and other value otherwise.
+ */
+ static OCStackResult readTrustCertChain(uint16_t credId, uint8_t **trustCertChain,
+ size_t *chainSize);
#endif // __WITH_DTLS__ || __WITH_TLS__
};
#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
std::cout << " 13. Save the Trust Cert. Chain into Cred of SVR"<<std::endl;
std::cout << " 14. Provision the Trust Cert. Chain"<<std::endl;
+ std::cout << " 15. Read trust cert chain"<<std::endl;
#endif // __WITH_DTLS__ || __WITH_TLS__
std::cout << " 99. Exit loop"<<std::endl;
}
}
break;
}
+ case 15:
+ {
+ if (0==g_credId)
+ {
+ std::cout<<"please save cert using option 13.";
+ }
+ else
+ {
+ uint8_t *trustCertChain = NULL;
+ size_t chainSize = 0;
+ if (OC_STACK_OK != OCSecure::readTrustCertChain(g_credId, &trustCertChain,&chainSize))
+ {
+ std::cout <<"issue in read trust chain"<< std::endl;
+ }
+ else
+ {
+ std::cout<<"size of cert : "<<chainSize<<std::endl;
+ }
+ }
+ break;
+ }
#endif //__WITH_DTLS__ || __WITH_TLS__
case 99:
default:
}
return result;
}
+
+ OCStackResult OCSecure::readTrustCertChain(uint16_t credId, uint8_t **trustCertChain,
+ size_t *chainSize)
+ {
+ OCStackResult result;
+ auto cLock = OCPlatform_impl::Instance().csdkLock().lock();
+
+ if (cLock)
+ {
+ std::lock_guard<std::recursive_mutex> lock(*cLock);
+ result = OCReadTrustCertChain(credId, trustCertChain, chainSize);
+ }
+ else
+ {
+ oclog() <<"Mutex not found";
+ result = OC_STACK_ERROR;
+ }
+ return result;
+ }
#endif // __WITH_DTLS__ || __WITH_TLS__
void OCSecureResource::callbackWrapper(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool hasError)