+/*
+ * Class: org_iotivity_base_OcProvisioning
+ * Method: saveTrustCertChain1
+ * Signature: (Lorg/iotivity/base/OcProvisioning/provisionTrustCertChain1;)V
+ */
+ JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_saveTrustCertChain1
+(JNIEnv *env, jobject thiz, jbyteArray trustCertChain, jint encodingType)
+{
+ LOGD("OcProvisioning_saveTrustCertChain1");
+#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
+ jbyte* trustCertChainBytes = env->GetByteArrayElements(trustCertChain, 0);
+ jsize arrayLength = env->GetArrayLength(trustCertChain);
+ uint16_t credId = -1;
+ unsigned char* trustedCertChar = new unsigned char[arrayLength];
+ try
+ {
+ env->GetByteArrayRegion (trustCertChain, 0, arrayLength, reinterpret_cast<jbyte*>(trustedCertChar));
+ OCStackResult result = OCSecure::saveTrustCertChain((uint8_t*)trustedCertChar, arrayLength,
+ (OicEncodingType_t)encodingType, &credId);
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "OcProvisioning_saveTrustCertChain1");
+ return -1;
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("%s", e.reason().c_str());
+ ThrowOcException(e.code(), e.reason().c_str());
+ }
+ return (jint)credId;
+#else
+ ThrowOcException(OC_STACK_INVALID_PARAM, "WITH_TLS not enabled");
+ return -1;
+#endif // __WITH_DTLS__ || __WITH_TLS__
+}
+
+/*
+ * Class: org_iotivity_base_OcProvisioning
+ * Method: setDeviceIdSeed1
+ * Signature: (Lorg/iotivity/base/OcProvisioning/provisionTrustCertChain1;)V
+ */
+ JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_setDeviceIdSeed1
+(JNIEnv *env, jobject thiz, jbyteArray seed)
+{
+ LOGD("OcProvisioning_setDeviceIdSeed1");
+#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
+ jbyte* byteSeed = env->GetByteArrayElements(seed, 0);
+ jsize arrayLength = env->GetArrayLength(seed);
+ try
+ {
+ env->GetByteArrayRegion (seed, 0, arrayLength, byteSeed);
+ OCStackResult result = OCSecure::setDeviceIdSeed((uint8_t*)byteSeed, arrayLength);
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "OcProvisioning_setDeviceIdSeed");
+ return -1;
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("%s", e.reason().c_str());
+ ThrowOcException(e.code(), e.reason().c_str());
+ }
+ return 0;
+#else
+ ThrowOcException(OC_STACK_INVALID_PARAM, "WITH_TLS not enabled");
+ return -1;
+#endif // __WITH_DTLS__ || __WITH_TLS__
+}
+
+/*
+ * Class: org_iotivity_base_OcProvisioning
+ * Method: saveACL
+ * Signature: (Ljava/lang/Object;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_saveACL
+ (JNIEnv *env , jclass thiz, jobject jacl)
+{
+ LOGD("OcProvisioning_saveACL");
+
+ if (!jacl)
+ {
+ ThrowOcException(OC_STACK_INVALID_PARAM, "acl can't be null");
+ }
+
+ OicSecAcl_t *acl = (OicSecAcl_t*)OICCalloc(1, sizeof(OicSecAcl_t));
+ if (!acl)
+ {
+ ThrowOcException(OC_STACK_NO_MEMORY, "acl allocation failed");
+ return;
+ }
+
+ if (OC_STACK_OK != JniSecureUtils::convertJavaACLToOCAcl(env, jacl, acl))
+ {
+ DeleteACLList(acl);
+ ThrowOcException(OC_STACK_INVALID_PARAM, "Failed to convert Java acl to OC acl");
+ return ;
+ }
+
+ try
+ {
+ OCStackResult result = OCSecure::saveACL(acl);
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "OCSecure::saveACL Failed");
+ return;
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("%s", e.reason().c_str());
+ ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+ }
+}
+
+/*
+ * Class: org_iotivity_base_OcProvisioning
+ * Method: doSelfOwnershiptransfer
+ * Signature: ()V
+ */
+ JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_doSelfOwnershiptransfer
+(JNIEnv *env, jclass thiz)
+{
+
+ LOGD("OcProvisioning_doSelfOwnershiptransfer");
+
+ try
+ {
+ OCStackResult result = OCSecure::configSelfOwnership();
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "OCSecure::configSelfOwnership Failed");
+ return;
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("%s", e.reason().c_str());
+ ThrowOcException(e.code(), e.reason().c_str());
+ return;
+ }
+}