Commit 40c004d5 authored by Sunil Kumar K R's avatar Sunil Kumar K R Committed by Randeep

Added jni/android implementation for trust cert chain

Provisioning client modified for save and provision cert chain

Change-Id: Iad4b7286ed9076026399d7f7088c4fc39d58c624
Signed-off-by: default avatarSunil Kumar K R <sunil.k14@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/11001Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Randeep's avatarRandeep Singh <randeep.s@samsung.com>
(cherry picked from commit 98ca3768)
Reviewed-on: https://gerrit.iotivity.org/gerrit/11721Tested-by: Randeep's avatarRandeep Singh <randeep.s@samsung.com>
parent cd1381c1
......@@ -16,6 +16,11 @@ if env.get('WITH_CLOUD'):
else:
ANDROID_CLOUD=0
if env.get('WITH_TCP'):
ANDROID_TCP=1
else:
ANDROID_TCP=0
ANDROID_MQ = env.get('WITH_MQ')
ANDROID_MQ_SUB = 0
ANDROID_MQ_PUB = 0
......@@ -83,11 +88,11 @@ def ensure_libs(target, source, env):
# build android_api
jdk_env = Environment(ENV=os.environ)
jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + os.getcwd()+'/build.gradle -PWITH_TRANSPORT_EDR=%s -PWITH_TRANSPORT_BLE=%s -PWITH_TRANSPORT_NFC=%s -PTARGET_ARCH=%s -PRELEASE=%s -PSECURED=%s -DSECURE=%s -PWITH_CLOUD=%s -PRD_MODE=%s -PWITH_MQ_PUB=%s -PWITH_MQ_SUB=%s -PWITH_MQ_BROKER=%s --stacktrace' %(ANDROID_TRANSPORT_EDR, ANDROID_TRANSPORT_BLE, ANDROID_TRANSPORT_NFC, ANDROID_TARGET_ARCH, ANDROID_RELEASE, ANDROID_SECURED, ANDROID_SECURED, ANDROID_CLOUD, ANDROID_RD_MODE, ANDROID_MQ_PUB, ANDROID_MQ_SUB, ANDROID_MQ_BROKER), emitter = ensure_libs)
jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + os.getcwd()+'/build.gradle -PWITH_TRANSPORT_EDR=%s -PWITH_TRANSPORT_BLE=%s -PWITH_TRANSPORT_NFC=%s -PTARGET_ARCH=%s -PRELEASE=%s -PSECURED=%s -DSECURE=%s -PWITH_CLOUD=%s -PRD_MODE=%s -PWITH_MQ_PUB=%s -PWITH_MQ_SUB=%s -PWITH_MQ_BROKER=%s -PWITH_TCP=%s --stacktrace' %(ANDROID_TRANSPORT_EDR, ANDROID_TRANSPORT_BLE, ANDROID_TRANSPORT_NFC, ANDROID_TARGET_ARCH, ANDROID_RELEASE, ANDROID_SECURED, ANDROID_SECURED, ANDROID_CLOUD, ANDROID_RD_MODE, ANDROID_MQ_PUB, ANDROID_MQ_SUB, ANDROID_MQ_BROKER, ANDROID_TCP), emitter = ensure_libs)
jdk_env['BUILD_DIR'] = env.get('BUILD_DIR')
cmdBuildApi=jdk_env.Gradle(target="base/objs", source="base/src/main/java/org/iotivity/base/OcResource.java")
jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + 'android/examples/build.gradle -DWITH_TRANSPORT_EDR=%s -DWITH_TRANSPORT_BLE=%s -DWITH_TRANSPORT_NFC=%s -PTARGET_ARCH=%s -PRELEASE=%s -PSECURED=%s -DSECURE=%s -PWITH_CLOUD=%s -PRD_MODE=%s -PWITH_MQ_PUB=%s -PWITH_MQ_SUB=%s -PWITH_MQ_BROKER=%s --stacktrace' %(ANDROID_TRANSPORT_EDR, ANDROID_TRANSPORT_BLE, ANDROID_TRANSPORT_NFC, ANDROID_TARGET_ARCH, ANDROID_RELEASE, ANDROID_SECURED, ANDROID_SECURED, ANDROID_CLOUD, ANDROID_RD_MODE, ANDROID_MQ_PUB, ANDROID_MQ_SUB, ANDROID_MQ_BROKER))
jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + 'android/examples/build.gradle -DWITH_TRANSPORT_EDR=%s -DWITH_TRANSPORT_BLE=%s -DWITH_TRANSPORT_NFC=%s -PTARGET_ARCH=%s -PRELEASE=%s -PSECURED=%s -DSECURE=%s -PWITH_CLOUD=%s -PRD_MODE=%s -PWITH_MQ_PUB=%s -PWITH_MQ_SUB=%s -PWITH_MQ_BROKER=%s -PWITH_TCP=%s --stacktrace' %(ANDROID_TRANSPORT_EDR, ANDROID_TRANSPORT_BLE, ANDROID_TRANSPORT_NFC, ANDROID_TARGET_ARCH, ANDROID_RELEASE, ANDROID_SECURED, ANDROID_SECURED, ANDROID_CLOUD, ANDROID_RD_MODE, ANDROID_MQ_PUB, ANDROID_MQ_SUB, ANDROID_MQ_BROKER, ANDROID_TCP))
cmdBuildExamples=jdk_env.Gradle(target="../examples/devicediscoveryclient/apk", source="../examples/devicediscoveryclient/src/main/java/org/iotivity/base/examples/DeviceDiscoveryClient.java")
# android examples require android api to be built before being invoked
......
......@@ -43,6 +43,7 @@ android {
versionCode 1
versionName "1.2.0"
buildConfigField 'int', 'SECURED', SECURED
buildConfigField 'int', 'WITH_TCP', WITH_TCP
buildConfigField 'int', 'WITH_CLOUD', WITH_CLOUD
buildConfigField "int", 'WITH_MQ_PUB', WITH_MQ_PUB
buildConfigField "int", 'WITH_MQ_SUB', WITH_MQ_SUB
......@@ -119,7 +120,7 @@ task buildNative(type: Exec) {
//for windows use 'ndk-build.cmd'
//def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build.cmd')
def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build')
commandLine ndkBuild, "APP_ABI=$TARGET_ARCH", "APP_OPTIM=$RELEASE", "SECURE=$SECURED", "WITH_CLOUD=$WITH_CLOUD", "RD_MODE=$RD_MODE", "WITH_MQ_PUB=$WITH_MQ_PUB", "WITH_MQ_SUB=$WITH_MQ_SUB", "WITH_MQ_BROKER=$WITH_MQ_BROKER"
commandLine ndkBuild, "APP_ABI=$TARGET_ARCH", "APP_OPTIM=$RELEASE", "SECURE=$SECURED", "WITH_CLOUD=$WITH_CLOUD", "RD_MODE=$RD_MODE", "WITH_MQ_PUB=$WITH_MQ_PUB", "WITH_MQ_SUB=$WITH_MQ_SUB", "WITH_MQ_BROKER=$WITH_MQ_BROKER", "WITH_TCP=$WITH_TCP"
} else {
println '##################'
println 'Skipping NDK build'
......
......@@ -2,6 +2,7 @@ LOCAL_PATH := $(call my-dir)
TARGET_ARCH_ABI := $(APP_ABI)
SECURED := $(SECURE)
WITH_CLOUD := $(WITH_CLOUD)
WITH_TCP := $(WITH_TCP)
WITH_MQ_PUB := $(WITH_MQ_PUB)
WITH_MQ_SUB := $(WITH_MQ_SUB)
WITH_MQ_BROKER := $(WITH_MQ_BROKER)
......@@ -64,6 +65,11 @@ ifeq ($(WITH_CLOUD), 1)
LOCAL_CPPFLAGS += -DWITH_CLOUD
endif
ifeq ($(WITH_TCP), 1)
LOCAL_CPPFLAGS += -DWITH_TCP
LOCAL_CPPFLAGS += -D__WITH_TLS__
endif
MQ_FLAG = 0
ifeq ($(WITH_MQ_PUB), 1)
LOCAL_CFLAGS += -DWITH_MQ -DMQ_PUBLISHER
......@@ -157,5 +163,6 @@ LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include/internal
LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/include
LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/include/internal
LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/connectivity/api
LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/connectivity/inc/pkix
LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/connectivity/lib/libcoap-4.1.1
include $(BUILD_SHARED_LIBRARY)
......@@ -288,3 +288,39 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_setDisplayPinListen
ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
}
}
/*
* 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_X509__) || defined(__WITH_TLS__)
jbyte* trustCertChainBytes = env->GetByteArrayElements(trustCertChain, 0);
jsize arrayLength = env->GetArrayLength(trustCertChain);
uint16_t credId;
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_X509__ || __WITH_TLS__
}
......@@ -85,7 +85,13 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_setDisplayPinListen
*/
JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_getDeviceStatusList1
(JNIEnv *, jclass, jint);
/*
* Class: org_iotivity_base_OcProvisioning
* Method: saveTrustCertChain1
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_saveTrustCertChain1
(JNIEnv *, jobject, jbyteArray, jint);
#ifdef __cplusplus
}
#endif
......
......@@ -209,6 +209,22 @@ OCStackResult JniOcSecureResource::provisionCredentials(JNIEnv* env, jint type,
resultCallback);
}
#if defined(__WITH_TLS__)
OCStackResult JniOcSecureResource::provisionTrustCertChain(JNIEnv* env, jint type, jint credId,
jobject jListener)
{
JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener);
ResultCallBack resultCallback = [resultListener](PMResultList_t *result, int hasError)
{
resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::PROVISIONTRUSTCERTCHAIN);
};
return m_sharedSecureResource->provisionTrustCertChain((OicSecCredType_t)type, credId,
resultCallback);
}
#endif
OCStackResult JniOcSecureResource::provisionACL(JNIEnv* env, jobject _acl, jobject jListener)
{
OCStackResult ret;
......@@ -524,7 +540,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_unlinkDevices
* Method: provisionCredentials1
* Signature: (Lorg/iotivity/base/OcSecureResource/provisionCredentials;)V
*/
JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionCredentials1
JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionCredentials1
(JNIEnv *env, jobject thiz, jint type, jint keySize, jobject device2, jobject jListener)
{
LOGD("OcSecureResource_provisionCredentials");
......@@ -563,6 +579,49 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionCredenti
}
}
/*
* Class: org_iotivity_base_OcSecureResource
* Method: provisionTrustCertChain1
* Signature: (Lorg/iotivity/base/OcSecureResource/provisionTrustCertChain1;)V
*/
JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionTrustCertChain1
(JNIEnv *env, jobject thiz, jint type, jint credId, jobject jListener)
{
LOGD("OcSecureResource_provisionTrustCertChain1");
#if defined(__WITH_X509__) || defined(__WITH_TLS__)
if (!jListener)
{
ThrowOcException(OC_STACK_INVALID_PARAM, "provisionTrustCertChainListener cannot be null");
return;
}
JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz);
if (!secureResource)
{
return;
}
try
{
OCStackResult result = secureResource->provisionTrustCertChain(env, type, credId,
jListener);
if (OC_STACK_OK != result)
{
ThrowOcException(result, "OcSecureResource_provisionTrustCertChain1");
return;
}
}
catch (OCException& e)
{
LOGE("%s", e.reason().c_str());
ThrowOcException(e.code(), e.reason().c_str());
}
#else
ThrowOcException(OC_STACK_INVALID_PARAM, "WITH_TLS not enabled");
return;
#endif // __WITH_X509__ || __WITH_TLS__
}
/*
* Class: org_iotivity_base_OcSecureResource
* Method: provisionACL
......
......@@ -53,6 +53,8 @@ class JniOcSecureResource
jobject acl1, jobject device2, jobject acl2, jobject jListener);
OCStackResult provisionCredentials(JNIEnv* env, jint type, jint keySize,
jobject device2, jobject jListener);
OCStackResult provisionTrustCertChain(JNIEnv* env, jint type, jint credId,
jobject jListener);
OCStackResult unlinkDevices(JNIEnv* env, jobject device2, jobject jListener);
OCStackResult removeDevice(JNIEnv* env, jint timeout, jobject jListener);
OCStackResult provisionDirectPairing(JNIEnv* env, jobjectArray jpdacls,jobject jListener,
......@@ -99,7 +101,15 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_unlinkDevices
* Signature: (IILjava/lang/Object;Lorg/iotivity/base/OcSecureResource/ProvisionCredentialsListener;)V
*/
JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionCredentials1
(JNIEnv *, jobject, jint, jint, jobject, jobject);
(JNIEnv *, jobject, jint, jint, jobject, jobject);
/*
* Class: org_iotivity_base_OcSecureResource
* Method: provisionTrustCertChain1
* Signature: (Lorg/iotivity/base/OcSecureResource/ProvisionTrustCertChainListener;)V
*/
JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionTrustCertChain1
(JNIEnv *, jobject, jint, jint, jobject);
/*
* Class: org_iotivity_base_OcSecureResource
......@@ -107,7 +117,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionCredenti
* Signature: (Ljava/lang/Object;Lorg/iotivity/base/OcSecureResource/ProvisionAclListener;)V
*/
JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionACL
(JNIEnv *, jobject, jobject, jobject);
(JNIEnv *, jobject, jobject, jobject);
/*
* Class: org_iotivity_base_OcSecureResource
......
......@@ -112,6 +112,11 @@ void JniProvisionResultListner::ProvisionResultCallback(PMResultList_t *result,
calledFunc = "provisionCredentialsListener";
}
break;
case ListenerFunc::PROVISIONTRUSTCERTCHAIN:
{
calledFunc = "provisionTrustCertChainListener";
}
break;
case ListenerFunc::UNLINKDEVICES:
{
calledFunc = "unlinkDevicesListener";
......
......@@ -33,6 +33,7 @@ enum class ListenerFunc
OWNERSHIPTRANSFER = 1,
PROVISIONACL,
PROVISIONCREDENTIALS,
PROVISIONTRUSTCERTCHAIN,
UNLINKDEVICES,
REMOVEDEVICE,
PROVISIONPAIRWISEDEVICES,
......
/*
*******************************************************************
*
* Copyright 2016 Samsung Electronics All Rights Reserved.
*
*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
package org.iotivity.base;
public enum EncodingType {
OIC_ENCODING_UNKNOW (0),
OIC_ENCODING_RAW (1),
OIC_ENCODING_BASE64 (2),
OIC_ENCODING_PEM (3),
OIC_ENCODING_DER (4);
private int value;
private EncodingType(int value) {
this.value = value;
}
public int getValue() {
return this.value;
}
}
......@@ -112,4 +112,17 @@ public class OcProvisioning {
return Arrays.asList(OcProvisioning.getDeviceStatusList1(timeout));
}
private static native OcSecureResource[] getDeviceStatusList1(int timeout) throws OcException;
/**
* Method to save the Trust certificate chain to SVR.
*
* @param byte[] trustCertChain
* @param EncodingType encodingType
* @throws OcException
*/
public static int saveTrustCertChain(byte[] trustCertChain, EncodingType encodingType) throws OcException {
return saveTrustCertChain1(trustCertChain,encodingType.getValue());
}
private static native int saveTrustCertChain1(byte[] trustCertChain, int encodingType)
throws OcException;
}
......@@ -89,6 +89,30 @@ public class OcSecureResource {
ProvisionCredentialsListener provisionCredentialsListener)
throws OcException;
/**
* Method to provision the Trust certificate chain to secured device.
*
* @param EnumSet<CredType> OR'ed Cred Types
* @param int credId
* @param ProvisionTrustCertChainListener Callback function, which will be called after
* proviosion trust certificate chain.
* @throws OcException
*/
public void provisionTrustCertChain(EnumSet<CredType> credTypeSet, int credId,
ProvisionTrustCertChainListener provisionTrustCertChainListener) throws OcException {
int credTypeInt = 0;
for (CredType credType : CredType.values()) {
if (credTypeSet.contains(credType))
credTypeInt |= credType.getValue();
}
this.provisionTrustCertChain1(credTypeInt, credId,
provisionTrustCertChainListener);
}
private native void provisionTrustCertChain1(int credType, int credId,
ProvisionTrustCertChainListener provisionTrustCertChainListener)
throws OcException;
/**
* Method send ACL information to resource.
*
......@@ -210,6 +234,16 @@ public class OcSecureResource {
int hasError);
}
/**
* provisionTrustCertChainListener can be registered with ProvisionTrustCertChainListener
* call.
* Listener notified asynchronously.
*/
public interface ProvisionTrustCertChainListener {
public void provisionTrustCertChainListener(List<ProvisionResult> provisionResultList,
int hasError);
}
/**
* provisionAclListener can be registered with provisionAclListener
* call.
......
-----BEGIN CERTIFICATE-----
MIIC/jCCAeYCAQEwDQYJKoZIhvcNAQELBQAwRTELMAkGA1UEBhMCQVUxEzARBgNV
BAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0
ZDAeFw0xNjA2MjgwNTMzNThaFw0yNjA2MjYwNTMzNThaMEUxCzAJBgNVBAYTAkFV
MRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRz
IFB0eSBMdGQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC1HHkfMG9c
BJ7ZeCIBKe7pSjpptvi+hzpdV72W7szpWDlTQdUaRxKL9aoNxbyuF5OL8xAQ9s28
IqIxdPW7X3JAmkLigzMCo2xtXHz/OyvomU6fhibneQw5De+iUoD68zdG+/k1NcAW
xx+VEAMw4fvZvYSVEQ1aKFnjtrQ8o6Zfe5+MRTvBq+G0+jwZWJEoKbpxIPpNWPGx
AV17tEpe+lg27jEYDYG1QUiL2TG80ZjQQL95OjETYf8EIxoqrKHvHCvDin0zdd+E
qPN0Y+Rhkl3PYoxWm7d8z0p1mD7lcwOMvy1KgEgtJ7SHy0D2SIW/KaDox/kRPC1P
ksFeAS2B0Z9zAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAAtHjimMywXn893Ifu1v
tNnL9ITMpQhsHAlg1QBVEyjGZLIjUgMhsWljVwTC1PdBrO7V0ElYbeV+LKYGwDk6
fjBJogCLgZiUw18F8TjHC/qDsoWEsm1iB4KcTZkk0nm/2vidHK0TMLzCohR71/vN
KS2rtiQDYGKe9EzjNSO3GlCWkVTYtJNhALa/BfDza5keRkwmldJYhlx4rQH5yVRn
t5k87vjX0h7m8MzIwiAb2s/b9XBlM1FuFx3FxcVjBl7KtUAU7twU8v5LenjWDSH1
D1jnKiZUUspgovhosPRqmxGNXldaX1E+RJmxdtqUVg4co/zjAbTY7C+7ZYIZBo46
Ll0=
-----END CERTIFICATE-----
......@@ -16,6 +16,7 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import org.iotivity.base.CredType;
import org.iotivity.base.EncodingType;
import org.iotivity.base.DeviceStatus;
import org.iotivity.base.KeySize;
import org.iotivity.base.ModeType;
......@@ -50,6 +51,7 @@ OcSecureResource.DoOwnershipTransferListener, OcSecureResource.ProvisionPairwise
private static final String TAG = "Provisioning Client: ";
private static final int BUFFER_SIZE = 1024;
private int credId=0;
int unownedDevCount = StringConstants.NUMBER_ZERO;
OcProvisioning.PinCallbackListener pinCallbackListener =
new OcProvisioning.PinCallbackListener() {
......@@ -96,7 +98,7 @@ OcSecureResource.DoOwnershipTransferListener, OcSecureResource.ProvisionPairwise
logMessage("Error: ACL Provision failed !!");
} else {
logMessage("ACL Provision Done !!");
new DeviceRevocationAsyncTask().execute();
provisionCertChain();
}
}
};
......@@ -114,6 +116,22 @@ OcSecureResource.DoOwnershipTransferListener, OcSecureResource.ProvisionPairwise
}
}
};
OcSecureResource.ProvisionTrustCertChainListener provisionTrustCertListener =
new OcSecureResource.ProvisionTrustCertChainListener() {
@Override
public void provisionTrustCertChainListener(List<ProvisionResult> provisionResults,
int hasError) {
Log.d(TAG, "Inside provisionTrustCertChainListener ");
if (hasError == StringConstants.ERROR_CODE) {
logMessage("Error: Provision TrustCertChain failed !!");
} else {
logMessage("Provision TrustCertChain Done !!");
new DeviceRevocationAsyncTask().execute();
}
}
};
OcSecureResource.UnlinkDevicesListener unlinkDevicesListener =
new OcSecureResource.UnlinkDevicesListener() {
@Override
......@@ -163,6 +181,7 @@ OcSecureResource.DoOwnershipTransferListener, OcSecureResource.ProvisionPairwise
editor.commit();
}
initOICStack();
saveCertChain();
}
/**
......@@ -313,6 +332,59 @@ OcSecureResource.DoOwnershipTransferListener, OcSecureResource.ProvisionPairwise
doDPProvisioning();
}
}
/**
* get cert from asset folder & save trusted cert chain
*/
private void saveCertChain() {
InputStream inputStream = null;
try {
inputStream = getAssets().open(StringConstants.CRT_FILE);
byte[] fileBytes = new byte[inputStream.available()+1];
inputStream.read(fileBytes);
fileBytes[inputStream.available()]=0x00;
credId = OcProvisioning.saveTrustCertChain(fileBytes,
EncodingType.OIC_ENCODING_PEM);
logMessage(TAG + "saveTrustCertChain return credId = " + credId);
} catch (IOException e) {
logMessage(TAG + "Cert file not exist in Assets" + e.getMessage());
Log.e(TAG, e.getMessage());
} catch (OcException e) {
logMessage(TAG + "saveTrustCertChain failed " + e.getMessage());
Log.e(TAG, e.getMessage());
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
Log.e(TAG, e.getMessage());
}
}
}
}
/**
* Provision cert chain
*/
private void provisionCertChain() {
if (ownedDeviceList.size() > 0) {
try {
OcSecureResource ocSecureResource = ownedDeviceList.get(0);
logMessage(TAG + "Initiate provision cert chain credId = "
+ credId);
ocSecureResource.provisionTrustCertChain(
EnumSet.of(CredType.SIGNED_ASYMMETRIC_KEY), credId,
provisionTrustCertListener);
} catch (OcException e) {
logMessage(TAG + "Provision cert chain error: "
+ e.getMessage());
Log.e(TAG, e.getMessage());
}
}
}
/**
* Copy svr db CBOR dat file from assets folder to app data files dir
......
......@@ -30,6 +30,7 @@ public interface StringConstants {
public static final String DEFAULT_PERIOD = "12-12-16";
public static final int DEFAULT_PERMISSION = 31;
public static final String OIC_CLIENT_CBOR_DB_FILE = "oic_svr_db_client.dat";
public static final String CRT_FILE = "rootca.crt";
public static final String MESSAGE = "message";
public static final String OIC_SQL_DB_FILE = "Pdm.db";
public static final int CREDENTIAL_TYPE=1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment