From ca7024bfb9863ab5e43ae847493857f90558256f Mon Sep 17 00:00:00 2001 From: Javier Guerra Melgares Date: Tue, 8 Oct 2019 12:12:25 +0200 Subject: [PATCH 1/5] Update IoTivity-lite library --- extlibs/iotivity-lite | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extlibs/iotivity-lite b/extlibs/iotivity-lite index 513d1c9..d301b81 160000 --- a/extlibs/iotivity-lite +++ b/extlibs/iotivity-lite @@ -1 +1 @@ -Subproject commit 513d1c9a707beaee87e7fe32742d66ab5bd897fc +Subproject commit d301b81dc3ce39f477318be219ede1d9ab835940 From 181bccde4215d4b0215d3f0e2ae3f11c4a670518 Mon Sep 17 00:00:00 2001 From: Javier Guerra Melgares Date: Tue, 8 Oct 2019 12:12:56 +0200 Subject: [PATCH 2/5] Add patch to fix the IoTivity-lite compilation --- README.md | 3 ++- extlibs/patchs/fix_oc_api.patch | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 extlibs/patchs/fix_oc_api.patch diff --git a/README.md b/README.md index 5854ac5..d6351e6 100644 --- a/README.md +++ b/README.md @@ -51,9 +51,10 @@ The steps required to build the binary of the IoTivity-lite Linux API are shown ``` git checkout swig ``` -2. Apply the patch of the OTGC in IoTivity-lite +2. Apply all patchs of the OTGC in IoTivity-lite ``` git apply /extlibs/patchs/remove_cred_by_credid.patch +git apply /extlibs/patchs/fix_oc_api.patch ``` 3. Go to the linux directory. ``` diff --git a/extlibs/patchs/fix_oc_api.patch b/extlibs/patchs/fix_oc_api.patch new file mode 100644 index 0000000..439ca33 --- /dev/null +++ b/extlibs/patchs/fix_oc_api.patch @@ -0,0 +1,13 @@ +diff --git a/swig/swig_interfaces/oc_api.i b/swig/swig_interfaces/oc_api.i +index e600456c..47ff85cb 100644 +--- a/swig/swig_interfaces/oc_api.i ++++ b/swig/swig_interfaces/oc_api.i +@@ -1372,7 +1372,7 @@ bool jni_oc_init_post(const char *uri, oc_endpoint_t *endpoint, const char *quer + OC_DBG("JNI - initPost failed releasing jni_sync_lock"); + OC_DBG("JNI: - unlock %s\n", __func__); + } +- return returnValue ++ return returnValue; + } + %} + From fccc192a21ce62a7be13cf33e0db1add56f06da2 Mon Sep 17 00:00:00 2001 From: Javier Guerra Melgares Date: Tue, 8 Oct 2019 12:15:39 +0200 Subject: [PATCH 3/5] Fix to do self ownership after reset --- .../otgc/domain/usecase/ResetObtModeUseCase.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/openconnectivity/otgc/domain/usecase/ResetObtModeUseCase.java b/src/main/java/org/openconnectivity/otgc/domain/usecase/ResetObtModeUseCase.java index 0004b09..8ba7212 100644 --- a/src/main/java/org/openconnectivity/otgc/domain/usecase/ResetObtModeUseCase.java +++ b/src/main/java/org/openconnectivity/otgc/domain/usecase/ResetObtModeUseCase.java @@ -53,6 +53,7 @@ public Completable execute() { .flatMapCompletable(device -> doxsRepository.resetDevice(device.getDeviceId())) .delay(delay, TimeUnit.SECONDS) .andThen(provisioningRepository.resetSvrDb()) + .andThen(provisioningRepository.doSelfOwnership()) .andThen(settingRepository.set(SettingRepository.MODE_KEY, OtgcMode.OBT)); } } From 06277e53f84064c790f96f7a89a167942ddedd0c Mon Sep 17 00:00:00 2001 From: Javier Guerra Melgares Date: Tue, 8 Oct 2019 12:16:42 +0200 Subject: [PATCH 4/5] Store Kyrion and EonTi certificates in factory presets callback --- .../domain/usecase/InitOicStackUseCase.java | 38 +++++++++++-------- .../otgc/utils/constant/OtgcConstant.java | 3 +- src/main/resources/data/eonti-root-cert.pem | 11 ++++++ 3 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 src/main/resources/data/eonti-root-cert.pem diff --git a/src/main/java/org/openconnectivity/otgc/domain/usecase/InitOicStackUseCase.java b/src/main/java/org/openconnectivity/otgc/domain/usecase/InitOicStackUseCase.java index 4be4d2e..0d3fc9b 100644 --- a/src/main/java/org/openconnectivity/otgc/domain/usecase/InitOicStackUseCase.java +++ b/src/main/java/org/openconnectivity/otgc/domain/usecase/InitOicStackUseCase.java @@ -69,28 +69,36 @@ public Completable execute() { } }); private void factoryResetHandler(long device) throws Exception { - /* my cert */ - byte[] eeCertificate = ioRepository.getBytesFromFile(OtgcConstant.KYRIO_EE_CERTIFICATE).blockingGet(); - - /* private key of my cert */ - byte[] eeKey = ioRepository.getBytesFromFile(OtgcConstant.KYRIO_EE_KEY).blockingGet(); - - /* intermediate cert */ - byte[] subcaCertificate = ioRepository.getBytesFromFile(OtgcConstant.KYRIO_SUBCA_CERTIFICATE).blockingGet(); - - /* root cert */ - byte[] rootcaCertificate = ioRepository.getBytesFromFile(OtgcConstant.KYRIO_ROOT_CERTIFICATE).blockingGet(); - - int credid = OCPki.addMfgCert(device, eeCertificate, eeKey); + /* Kyrio end-entity cert */ + byte[] kyrioEeCertificate = ioRepository.getBytesFromFile(OtgcConstant.KYRIO_EE_CERTIFICATE).blockingGet(); + /* private key of Kyrio end-entity cert */ + byte[] kyrioEeKey = ioRepository.getBytesFromFile(OtgcConstant.KYRIO_EE_KEY).blockingGet(); + int credid = OCPki.addMfgCert(device, kyrioEeCertificate, kyrioEeKey); if (credid == -1) { throw new Exception("Add identity certificate error"); } - if (OCPki.addMfgIntermediateCert(device, credid, subcaCertificate) == -1) { + /* Kyrio intermediate cert */ + byte[] kyrioSubcaCertificate = ioRepository.getBytesFromFile(OtgcConstant.KYRIO_SUBCA_CERTIFICATE).blockingGet(); + if (OCPki.addMfgIntermediateCert(device, credid, kyrioSubcaCertificate) == -1) { throw new Exception("Add intermediate certificate error"); } - if (OCPki.addMfgTrustAnchor(device, rootcaCertificate) == -1) { + /* Kyrio root cert */ + byte[] kyrioRootcaCertificate = ioRepository.getBytesFromFile(OtgcConstant.KYRIO_ROOT_CERTIFICATE).blockingGet(); + if (OCPki.addMfgTrustAnchor(device, kyrioRootcaCertificate) == -1) { + throw new Exception("Add root certificate error"); + } + if (OCPki.addTrustAnchor(device, kyrioRootcaCertificate) == -1) { + throw new Exception("Add root certificate error"); + } + + /* EonTi root cert */ + byte[] eontiRootcaCertificate = ioRepository.getBytesFromFile(OtgcConstant.EONTI_ROOT_CERTIFICATE).blockingGet(); + if (OCPki.addMfgTrustAnchor(device, eontiRootcaCertificate) == -1) { + throw new Exception("Add root certificate error"); + } + if (OCPki.addTrustAnchor(device, eontiRootcaCertificate) == -1) { throw new Exception("Add root certificate error"); } diff --git a/src/main/java/org/openconnectivity/otgc/utils/constant/OtgcConstant.java b/src/main/java/org/openconnectivity/otgc/utils/constant/OtgcConstant.java index 01fb222..1e3d524 100644 --- a/src/main/java/org/openconnectivity/otgc/utils/constant/OtgcConstant.java +++ b/src/main/java/org/openconnectivity/otgc/utils/constant/OtgcConstant.java @@ -35,10 +35,11 @@ private OtgcConstant() { // Credential directory public static final String OTGC_CREDS_DIR = DATA_PATH + "otgc_creds"; - // File databases for IoTivity + // File databases for IoTivity public static final String INTROSPECTION_CBOR_FILE = DATA_PATH + "introspection.dat"; /* Kyrio certificate chain */ + public static String EONTI_ROOT_CERTIFICATE = "eonti-root-cert.pem"; public static String KYRIO_ROOT_CERTIFICATE = "kyrio-root-cert.pem"; public static String KYRIO_SUBCA_CERTIFICATE = "kyrio-subca-cert.pem"; public static String KYRIO_EE_CERTIFICATE = "kyrio-ee-cert.pem"; diff --git a/src/main/resources/data/eonti-root-cert.pem b/src/main/resources/data/eonti-root-cert.pem new file mode 100644 index 0000000..17c0a68 --- /dev/null +++ b/src/main/resources/data/eonti-root-cert.pem @@ -0,0 +1,11 @@ +-----BEGIN CERTIFICATE----- +MIIBnTCCAUKgAwIBAgIUfKTxfZOGE/bSAF+l555yrmzbBZYwCgYIKoZIzj0EAwIw +KzEMMAoGA1UEChMDT0NGMRswGQYDVQQDExJURVNUIE9DRiBSb290IENBIDIwIBcN +MTgxMTI5MTY0MTIyWhgPMjA2ODExMjkxNjQxMjJaMCsxDDAKBgNVBAoTA09DRjEb +MBkGA1UEAxMSVEVTVCBPQ0YgUm9vdCBDQSAyMFkwEwYHKoZIzj0CAQYIKoZIzj0D +AQcDQgAED4xusXQP8CojjLCIy3Kc/6oDZUM2CxKiq4RfKi4A2hZ9uOKD1TrirCGh +yVLso63+OQv1Zi6Og9E4SYMDHqvwZKNCMEAwDgYDVR0PAQH/BAQDAgEGMB0GA1Ud +DgQWBBSYuivCP5E741G+c2v1466PlBfNizAPBgNVHRMBAf8EBTADAQH/MAoGCCqG +SM49BAMCA0kAMEYCIQCyF9qhRMdtJhM922E7BrTENwrwrYU9X66zgRtBTuzrVgIh +ANreyj+BcMMLqXLZUSw1Lbb+4fm+/2ETt92RbrZSwXYt +-----END CERTIFICATE----- From 81660e6c16f99083960db5dec5150315cb2acb8e Mon Sep 17 00:00:00 2001 From: Javier Guerra Melgares Date: Wed, 9 Oct 2019 08:47:08 +0200 Subject: [PATCH 5/5] Update version to 2.1.0 --- build/debian/control | 2 +- build/debian/otgc_native.sh | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/debian/control b/build/debian/control index cc89f2b..1c794e6 100644 --- a/build/debian/control +++ b/build/debian/control @@ -1,5 +1,5 @@ Package: OTGC -Version: 2.0.8 +Version: 2.1.0 Section: custom Priority: optional Architecture: amd64 diff --git a/build/debian/otgc_native.sh b/build/debian/otgc_native.sh index b73af39..b8e697a 100755 --- a/build/debian/otgc_native.sh +++ b/build/debian/otgc_native.sh @@ -11,7 +11,7 @@ # Constants PROJECT_NAME="otgc" -VERSION="2.0.8" +VERSION="2.1.0" program=$0 diff --git a/pom.xml b/pom.xml index ce0d2cf..0831b6c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ otgc otgc - 2.0.8 + 2.1.0 UTF-8