DeviceList_t pUnownedDevList, pOwnedDevList;
static int transferDevIdx, ask = 1;
static OicSecPconf_t g_pconf;
+static uint16_t g_credId = 0;
static FILE* client_open(const char *UNUSED_PARAM, const char *mode)
{
std::cout << " 10. Get Linked Devices"<<std::endl;
std::cout << " 11. Get Device Status"<<std::endl;
std::cout << " 12. Provision Direct-Pairing Configuration"<<std::endl;
- std::cout << " 13. Exit loop"<<std::endl;
+#if defined(__WITH_X509__) || 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;
+#endif // __WITH_X509__ || __WITH_TLS__
+ std::cout << " 99. Exit loop"<<std::endl;
}
void moveTransferredDevice()
ask = 1;
}
+#ifdef __WITH_TLS__
+static int saveTrustCert(void)
+{
+
+ // call |OCSaveTrustCertChainBin| API actually
+ printf(" Save Trust Cert. Chain into Cred of SVR.\n");
+
+ ByteArray trustCertChainArray = {0, 0};
+
+ FILE *fp = fopen("rootca.crt", "rb+");
+
+ if (fp)
+ {
+ size_t fsize;
+ if (fseeko(fp, 0, SEEK_END) == 0 && (fsize = ftello(fp)) >= 0)
+ {
+ trustCertChainArray.data = (uint8_t*)OICMalloc(fsize);
+ trustCertChainArray.len = fsize;
+ if (NULL == trustCertChainArray.data)
+ {
+ OIC_LOG(ERROR,TAG,"malloc");
+ fclose(fp);
+ return -1;
+ }
+ rewind(fp);
+ fsize = fread(trustCertChainArray.data, 1, fsize, fp);
+ fclose(fp);
+ }
+ }
+ OIC_LOG_BUFFER(DEBUG, TAG, trustCertChainArray.data, trustCertChainArray.len);
+
+ if(OC_STACK_OK != OCSecure::saveTrustCertChain(trustCertChainArray.data, trustCertChainArray.len,
+ OIC_ENCODING_PEM,&g_credId))
+ {
+ OIC_LOG(ERROR, TAG, "OCSaveTrustCertChainBin API error");
+ return -1;
+ }
+ printf("CredId of Saved Trust Cert. Chain into Cred of SVR : %d.\n", g_credId);
+
+ return 0;
+}
+#endif //__WITH_TLS__
+
int main(void)
{
OCPersistentStorage ps {client_open, fread, fwrite, fclose, unlink };
break;
}
+#if defined(__WITH_X509__) || defined(__WITH_TLS__)
case 13:
+ {
+ if(saveTrustCert())
+ {
+ std::cout<<"Error in saving cert"<<std::endl;
+ }
+ break;
+ }
+ case 14:
+ {
+ int index;
+
+ if (0 != readDeviceNumber(pOwnedDevList, 1, &index)) break;
+
+ std::cout << "Provision cert for : "<<
+ pOwnedDevList[index]->getDeviceID()<< std::endl;
+
+ ask = 0;
+
+ if (pOwnedDevList[index]->provisionTrustCertChain(SIGNED_ASYMMETRIC_KEY,
+ g_credId,provisionCB ) != OC_STACK_OK)
+ {
+ ask = 1;
+ std::cout <<"provision cert is failed"<< std::endl;
+ }
+ break;
+ }
+#endif //__WITH_X509__ || __WITH_TLS__
+ case 99:
default:
out = 1;
break;