Skip to content

Commit 619f1a2

Browse files
authored
Merge pull request #3 from iotivity/v3.1.0
v3.1.0
2 parents 5b351c7 + e088c5f commit 619f1a2

28 files changed

+306
-69
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ cd <iotivity-lite>/port/android
5959
```
6060
3. Execute the command to build the library.
6161
```
62-
make NDK_HOME=<ndk-directory> ANDROID_API=21 DEBUG=1 SECURE=1 IPV4=1 TCP=0 PKI=1 DYNAMIC=1 CLOUD=0 JAVA=1 IDD=1
62+
make NDK_HOME=<ndk-directory> ANDROID_API=21 DEBUG=1 SECURE=1 IPV4=1 TCP=1 PKI=1 DYNAMIC=1 CLOUD=1 JAVA=1 IDD=1
6363
```
6464

6565
Once built, the library can be found at:

otgc/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ android {
3030
minSdkVersion 21
3131
targetSdkVersion 28
3232
versionCode 13
33-
versionName "3.0.0"
33+
versionName "3.1.0"
3434
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3535

3636
compileOptions {

otgc/src/main/assets/cloudca.pem

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIBhDCCASmgAwIBAgIQdAMxveYP9Nb48xe9kRm3ajAKBggqhkjOPQQDAjAxMS8w
3+
LQYDVQQDEyZPQ0YgQ2xvdWQgUHJpdmF0ZSBDZXJ0aWZpY2F0ZXMgUm9vdCBDQTAe
4+
Fw0xOTExMDYxMjAzNTJaFw0yOTExMDMxMjAzNTJaMDExLzAtBgNVBAMTJk9DRiBD
5+
bG91ZCBQcml2YXRlIENlcnRpZmljYXRlcyBSb290IENBMFkwEwYHKoZIzj0CAQYI
6+
KoZIzj0DAQcDQgAEaNJi86t5QlZiLcJ7uRMNlcwIpmFiJf9MOqyz2GGnGVBypU6H
7+
lwZHY2/l5juO/O4EH2s9h3HfcR+nUG2/tFzFEaMjMCEwDgYDVR0P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EgULMBo4ICYzCCAl8wCQYD
9+
VR0TBAIwADAOBgNVHQ8BAf8EBAMCA4gwKQYDVR0lBCIwIAYIKwYBBQUHAwIGCCsG
10+
AQUFBwMBBgorBgEEAYLefAEGMB0GA1UdDgQWBBRDsU3IcO3AHYvyWp0NjWm4ob6a
11+
uzAfBgNVHSMEGDAWgBQZc2oEGgsHcE9TeVM2h/wMunyuCzCBlgYIKwYBBQUHAQEE
12+
gYkwgYYwXQYIKwYBBQUHMAKGUWh0dHA6Ly90ZXN0cGtpLmt5cmlvLmNvbS9vY2Yv
13+
Y2FjZXJ0cy9CQkU2NEY5QTdFRTM3RDI5QTA1RTRCQjc3NTk1RjMwOEJFNDFFQjA3
14+
LmNydDAlBggrBgEFBQcwAYYZaHR0cDovL3Rlc3RvY3NwLmt5cmlvLmNvbTBfBgNV
15+
HR8EWDBWMFSgUqBQhk5odHRwOi8vdGVzdHBraS5reXJpby5jb20vb2NmL2NybHMv
16+
QkJFNjRGOUE3RUUzN0QyOUEwNUU0QkI3NzU5NUYzMDhCRTQxRUIwNy5jcmwwGAYD
17+
VR0gBBEwDzANBgsrBgEEAYORVgABAjBlBgorBgEEAYORVgEABFcwVTAJAgECAgEA
18+
AgEAMDYMGTEuMy42LjEuNC4xLjUxNDE0LjAuMC4xLjAMGTEuMy42LjEuNC4xLjUx
19+
NDE0LjAuMC4yLjAMC0RldmljZU5hbWUxDANPQ0YwKgYKKwYBBAGDkVYBAQQcMBoG
20+
CysGAQQBg5FWAQEABgsrBgEEAYORVgEBATAwBgorBgEEAYORVgECBCIwIAwOMS4z
21+
LjYuMS40LjEuNzEMCURpc2NvdmVyeQwDMS4wMAoGCCqGSM49BAMCA0kAMEYCIQCn
22+
bJELNfcNIMF/o7fD1GMVo5bipfBgKe45TkUTFxHqJAIhAJocMkb89i5l1htY6Zxh
23+
6IrWOduBtpU7LaNfhLyWQZA0
2424
-----END CERTIFICATE-----

otgc/src/main/assets/kyrio-ee-key.pem

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
BggqhkjOPQMBBw==
33
-----END EC PARAMETERS-----
44
-----BEGIN EC PRIVATE KEY-----
5-
MHcCAQEEIDFeXNSayEnCQIlEjbV+4vGKeqRAmjnspnA8ICW0FnAwoAoGCCqGSM49
6-
AwEHoUQDQgAEEqzUtIWvFwYkQ/kO5y/kd7l+3+RT4EDu+VofT6molS4TBXsBf2K2
7-
6/ioQnY/HujDc1hg21bTFXOfUQR8r4M24Q==
5+
MHcCAQEEIDKAzV1vjeRU1ET9HVHcQVTjr6ClMoGt1Yhjrky2MYyaoAoGCCqGSM49
6+
AwEHoUQDQgAET4YL6yN1RuSgwMuEEJz53SOHp/cqCCEFjvT2O4E+tJn8CBJR9j23
7+
hBScEvukZjbUpxnqNVW9lEMd24KRIFCzAQ==
88
-----END EC PRIVATE KEY-----

otgc/src/main/java/org/openconnectivity/otgc/data/repository/CmsRepository.java

+47
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,26 @@ public Completable provisionRoleCertificate(String deviceId, String roleId, Stri
142142
});
143143
}
144144

145+
public Completable provisionTrustAnchor(byte[] certificate, String sid, String deviceId) {
146+
return Completable.create(emitter -> {
147+
OCUuid di = OCUuidUtil.stringToUuid(deviceId);
148+
149+
OCObtStatusHandler handler = (int status) -> {
150+
if (status >= 0) {
151+
Timber.d("Provision trust anchor succeeded");
152+
emitter.onComplete();
153+
} else {
154+
emitter.onError(new Exception("Provision trust anchor error"));
155+
}
156+
};
157+
158+
int ret = OCObt.provisionTrustAnchor(certificate, sid, di, handler);
159+
if (ret < 0) {
160+
emitter.onError(new Exception("Provision trust anchor error"));
161+
}
162+
});
163+
}
164+
145165
public Completable provisionPairwiseCredential(String clientId, String serverId) {
146166
return Completable.create(emitter -> {
147167
OCUuid cliendDi = OCUuidUtil.stringToUuid(clientId);
@@ -250,4 +270,31 @@ public Completable removeTrustAnchor(long credid) {
250270
}
251271
});
252272
}
273+
274+
public Completable registerDeviceCloud(String deviceId, String deviceURL, String authProvider, String cloudUrl, String cloudUuid, String accessToken) {
275+
return Completable.create(emitter -> {
276+
OCCloudContext ctx = OCCloud.getContext(0);
277+
278+
OCUuid uuid = OCUuidUtil.stringToUuid(deviceId);
279+
280+
OCResponseHandler handler = (OCClientResponse response) -> {
281+
if (response.getCode() == OCStatus.OC_STATUS_CHANGED) {
282+
Timber.d("Register device on cloud success");
283+
emitter.onComplete();
284+
} else if (response.getCode() == OCStatus.OC_STATUS_CREATED) {
285+
Timber.d("Register device on cloud success");
286+
emitter.onComplete();
287+
} else {
288+
String error = "Register device on cloud error";
289+
Timber.e(error + ": " + response.getCode());
290+
emitter.onError(new Exception(error));
291+
}
292+
};
293+
294+
if (ctx != null) {
295+
OCObt.UpdateCloudConfDevice(uuid, deviceURL, accessToken, authProvider, cloudUrl, cloudUuid, handler);
296+
}
297+
emitter.onComplete();
298+
});
299+
}
253300
}

otgc/src/main/java/org/openconnectivity/otgc/data/repository/IotivityRepository.java

+16
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,22 @@ public Observable<Device> scanOwnedByOtherDevices() {
353353
.filter(device -> !device.getDeviceId().equals(getDeviceId().blockingGet()));
354354
}
355355

356+
public Single<String> getEndpoint(Device device) {
357+
return Single.create(emitter -> {
358+
String endpoint = device.getIpv6Host() != null ? device.getIpv6Host() : device.getIpv6TcpHost();
359+
if (endpoint == null) {
360+
endpoint = device.getIpv4Host() != null ? device.getIpv4Host() : device.getIpv4TcpHost();
361+
if (endpoint == null) {
362+
endpoint = device.getIpv6SecureHost() != null ? device.getIpv6SecureHost() : device.getIpv6TcpSecureHost();
363+
if (endpoint == null) {
364+
endpoint = device.getIpv4SecureHost() != null ? device.getIpv4SecureHost() : device.getIpv4TcpSecureHost();
365+
}
366+
}
367+
}
368+
emitter.onSuccess(endpoint);
369+
});
370+
}
371+
356372
public Single<String> getNonSecureEndpoint(Device device) {
357373
return Single.create(emitter -> {
358374
String endpoint = device.getIpv6Host() != null ? device.getIpv6Host() : device.getIpv6TcpHost();

otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/cred/OcCredential.java

+4
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,13 @@ public void parseOCRepresentation(OCCred cred) {
134134
this.setPublicData(publicData);
135135
}
136136
/* privatedata */
137+
// Reading Private Data fails sometimes on Android. As it not used, it has been commented
138+
/*
137139
OcCredPrivateData privateData = new OcCredPrivateData();
138140
privateData.parseOCRepresentation(cred.getPrivateData());
139141
this.setPrivateData(privateData);
142+
*/
143+
140144
/* roleid */
141145
if (cred.getRole() != null) {
142146
OcCredRole roleid = new OcCredRole();

otgc/src/main/java/org/openconnectivity/otgc/domain/model/resource/secure/doxm/OcDoxm.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ public void parseOCRepresentation(OCRepresentation rep) {
130130
this.setRowneruuid(rowneruuid);
131131
/* rt */
132132
String[] resourceTypes = OCRep.getStringArray(rep, OcfResourceAttributeKey.RESOURCE_TYPES_KEY);
133-
this.setResourceTypes(Arrays.asList(resourceTypes));
133+
this.setResourceTypes(resourceTypes != null ? Arrays.asList(resourceTypes) : null);
134134
/* if */
135135
String[] interfaces = OCRep.getStringArray(rep, OcfResourceAttributeKey.INTERFACES_KEY);
136-
this.setResourceTypes(Arrays.asList(interfaces));
136+
this.setInterfaces(interfaces != null ? Arrays.asList(interfaces) : null);
137137
}
138138

139139
public CborEncoder parseToCbor() {

otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/GetDeviceInfoUseCase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public GetDeviceInfoUseCase(IotivityRepository iotivityRepository,
5252
}
5353

5454
public Single<OcDeviceInfo> execute(Device device) {
55-
return iotivityRepository.getNonSecureEndpoint(device)
55+
return iotivityRepository.getEndpoint(device)
5656
.flatMap(iotivityRepository::getDeviceInfo)
5757
.delay(preferencesRepository.getRequestsDelay(), TimeUnit.SECONDS, schedulersFacade.ui());
5858
}

otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/GetDeviceRoleUseCase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public GetDeviceRoleUseCase(IotivityRepository iotivityRepository,
5555
}
5656

5757
public Single<DeviceRole> execute(Device device) {
58-
return iotivityRepository.getNonSecureEndpoint(device)
58+
return iotivityRepository.getEndpoint(device)
5959
.flatMap(endpoint ->
6060
iotivityRepository.findResources(endpoint)
6161
.timeout(iotivityRepository.getDiscoveryTimeout() + 5, TimeUnit.SECONDS)

otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/GetOTMethodsUseCase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public GetOTMethodsUseCase(IotivityRepository iotivityRepository,
4545
}
4646

4747
public Single<List<OcfOxmType>> execute(Device device) {
48-
return iotivityRepository.getNonSecureEndpoint(device)
48+
return iotivityRepository.getEndpoint(device)
4949
.flatMap(endpoint ->
5050
doxsRepository.retrieveOTMethods(endpoint)
5151
.map(doxm -> doxm.getOxms()));

otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/InitializeIotivityUseCase.java

+41-26
Original file line numberDiff line numberDiff line change
@@ -92,37 +92,40 @@ private void factoryResetHandler(long device) throws Exception {
9292
/* Current date */
9393
Date date = new Date();
9494

95-
/* Kyrio end-entity cert */
96-
InputStream inputStream = context.getAssets().open(OtgcConstant.KYRIO_EE_CERTIFICATE);
97-
X509Certificate eeCert = ioRepository.getFileAsX509Certificate(inputStream).blockingGet();
98-
if (date.after(eeCert.getNotBefore()) && date.before(eeCert.getNotAfter())) {
99-
byte[] kyrioEeCertificate = ioRepository.getBytesFromFile(OtgcConstant.KYRIO_EE_CERTIFICATE).blockingGet();
100-
/* private key of Kyrio end-entity cert */
101-
byte[] kyrioEeKey = ioRepository.getBytesFromFile(OtgcConstant.KYRIO_EE_KEY).blockingGet();
102-
int credid = OCPki.addMfgCert(device, kyrioEeCertificate, kyrioEeKey);
103-
if (credid == -1) {
104-
throw new Exception("Add identity certificate error");
105-
}
95+
// End-entity certs only loaded when using Client Mode
96+
if (settingRepository.getMode().equals(OtgcMode.CLIENT)) {
97+
/* Kyrio end-entity cert */
98+
InputStream inputStream = context.getAssets().open(OtgcConstant.KYRIO_EE_CERTIFICATE);
99+
X509Certificate eeCert = ioRepository.getFileAsX509Certificate(inputStream).blockingGet();
100+
if (date.after(eeCert.getNotBefore()) && date.before(eeCert.getNotAfter())) {
101+
byte[] kyrioEeCertificate = ioRepository.getBytesFromFile(OtgcConstant.KYRIO_EE_CERTIFICATE).blockingGet();
102+
/* private key of Kyrio end-entity cert */
103+
byte[] kyrioEeKey = ioRepository.getBytesFromFile(OtgcConstant.KYRIO_EE_KEY).blockingGet();
104+
int credid = OCPki.addMfgCert(device, kyrioEeCertificate, kyrioEeKey);
105+
if (credid == -1) {
106+
throw new Exception("Add identity certificate error");
107+
}
106108

107-
/* Kyrio intermediate cert */
108-
inputStream = context.getAssets().open(OtgcConstant.KYRIO_SUBCA_CERTIFICATE);
109-
X509Certificate subCaCert = ioRepository.getFileAsX509Certificate(inputStream).blockingGet();
110-
if (date.after(subCaCert.getNotBefore()) && date.before(subCaCert.getNotAfter())) {
111-
byte[] kyrioSubcaCertificate = ioRepository.getBytesFromFile(OtgcConstant.KYRIO_SUBCA_CERTIFICATE).blockingGet();
112-
if (OCPki.addMfgIntermediateCert(device, credid, kyrioSubcaCertificate) == -1) {
113-
throw new Exception("Add intermediate certificate error");
109+
/* Kyrio intermediate cert */
110+
inputStream = context.getAssets().open(OtgcConstant.KYRIO_SUBCA_CERTIFICATE);
111+
X509Certificate subCaCert = ioRepository.getFileAsX509Certificate(inputStream).blockingGet();
112+
if (date.after(subCaCert.getNotBefore()) && date.before(subCaCert.getNotAfter())) {
113+
byte[] kyrioSubcaCertificate = ioRepository.getBytesFromFile(OtgcConstant.KYRIO_SUBCA_CERTIFICATE).blockingGet();
114+
if (OCPki.addMfgIntermediateCert(device, credid, kyrioSubcaCertificate) == -1) {
115+
throw new Exception("Add intermediate certificate error");
116+
}
117+
} else {
118+
this.displayNotValidCertificateHandler.handler("Kyrio intermediate certificate is not valid");
114119
}
115120
} else {
116-
this.displayNotValidCertificateHandler.handler("Kyrio intermediate certificate is not valid");
121+
this.displayNotValidCertificateHandler.handler("Kyrio end entity certificate is not valid");
117122
}
118-
} else {
119-
this.displayNotValidCertificateHandler.handler("Kyrio end entity certificate is not valid");
120123
}
121124

122125
/* Kyrio root cert */
123-
inputStream = context.getAssets().open(OtgcConstant.KYRIO_ROOT_CERTIFICATE);
124-
X509Certificate caCert = ioRepository.getFileAsX509Certificate(inputStream).blockingGet();
125-
if (date.after(caCert.getNotBefore()) && date.before(caCert.getNotAfter())) {
126+
InputStream inputStream = context.getAssets().open(OtgcConstant.KYRIO_ROOT_CERTIFICATE);
127+
X509Certificate caCert1 = ioRepository.getFileAsX509Certificate(inputStream).blockingGet();
128+
if (date.after(caCert1.getNotBefore()) && date.before(caCert1.getNotAfter())) {
126129
byte[] kyrioRootcaCertificate = ioRepository.getBytesFromFile(OtgcConstant.KYRIO_ROOT_CERTIFICATE).blockingGet();
127130
if (OCPki.addMfgTrustAnchor(device, kyrioRootcaCertificate) == -1) {
128131
throw new Exception("Add root certificate error");
@@ -133,8 +136,8 @@ private void factoryResetHandler(long device) throws Exception {
133136

134137
/* EonTi root cert */
135138
inputStream = context.getAssets().open(OtgcConstant.EONTI_ROOT_CERTIFICATE);
136-
caCert = ioRepository.getFileAsX509Certificate(inputStream).blockingGet();
137-
if (date.after(caCert.getNotBefore()) && date.before(caCert.getNotAfter())) {
139+
X509Certificate caCert2 = ioRepository.getFileAsX509Certificate(inputStream).blockingGet();
140+
if (date.after(caCert2.getNotBefore()) && date.before(caCert2.getNotAfter())) {
138141
byte[] eontiRootcaCertificate = ioRepository.getBytesFromFile(OtgcConstant.EONTI_ROOT_CERTIFICATE).blockingGet();
139142
if (OCPki.addMfgTrustAnchor(device, eontiRootcaCertificate) == -1) {
140143
throw new Exception("Add root certificate error");
@@ -143,6 +146,18 @@ private void factoryResetHandler(long device) throws Exception {
143146
this.displayNotValidCertificateHandler.handler("EonTi root certificate is not valid");
144147
}
145148

149+
/* CloudCA root cert */
150+
inputStream = context.getAssets().open(OtgcConstant.CLOUD_ROOT_CERTIFICATE);
151+
X509Certificate cloudCert = ioRepository.getFileAsX509Certificate(inputStream).blockingGet();
152+
if (date.after(cloudCert.getNotBefore()) && date.before(cloudCert.getNotAfter())) {
153+
byte[] cloudRootcaCertificate = ioRepository.getBytesFromFile(OtgcConstant.CLOUD_ROOT_CERTIFICATE).blockingGet();
154+
if (OCPki.addMfgTrustAnchor(device, cloudRootcaCertificate) == -1) {
155+
throw new Exception("Add root certificate error");
156+
}
157+
} else {
158+
this.displayNotValidCertificateHandler.handler("Cloud CA root certificate is not valid");
159+
}
160+
146161
OCObt.shutdown();
147162
}
148163
}

otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/ResetClientModeUseCase.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ public ResetClientModeUseCase(ProvisioningRepository provisioningRepository,
2121
}
2222

2323
public Completable execute() {
24-
return provisioningRepository.resetSvrDb()
25-
.andThen(Completable.fromAction(() -> preferencesRepository.setMode(OtgcMode.CLIENT)));
24+
//return provisioningRepository.resetSvrDb()
25+
// .andThen(Completable.fromAction(() -> preferencesRepository.setMode(OtgcMode.CLIENT)));
26+
return Completable.fromAction(() -> preferencesRepository.setMode(OtgcMode.CLIENT))
27+
.andThen (provisioningRepository.resetSvrDb());
2628
}
2729
}

otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/ResetObtModeUseCase.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public Completable execute() {
3434
return iotivityRepository.scanOwnedDevices()
3535
.flatMapCompletable(device -> doxsRepository.resetDevice(device.getDeviceId()))
3636
.delay(preferencesRepository.getRequestsDelay(), TimeUnit.SECONDS)
37+
.andThen(Completable.fromAction(() -> preferencesRepository.setMode(OtgcMode.OBT)))
3738
.andThen(provisioningRepository.resetSvrDb())
38-
.andThen(provisioningRepository.doSelfOwnership())
39-
.andThen(Completable.fromAction(() -> preferencesRepository.setMode(OtgcMode.OBT)));
39+
.andThen(provisioningRepository.doSelfOwnership());
4040
}
4141
}

otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/RetrieveVerticalResourcesUseCase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public RetrieveVerticalResourcesUseCase(IotivityRepository iotivityRepository) {
4040
}
4141

4242
public Single<List<String>> execute(Device device) {
43-
return iotivityRepository.getNonSecureEndpoint(device)
43+
return iotivityRepository.getEndpoint(device)
4444
.flatMap(iotivityRepository::findResources)
4545
.map(ocRes -> {
4646
List<String> verticalResources = new ArrayList<>();

otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/client/GetPlatformInfoUseCase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public GetPlatformInfoUseCase(IotivityRepository iotivityRepository) {
3939
}
4040

4141
public Single<OcPlatformInfo> execute(Device device) {
42-
return iotivityRepository.getNonSecureEndpoint(device)
42+
return iotivityRepository.getEndpoint(device)
4343
.flatMap(iotivityRepository::getPlatformInfo);
4444
}
4545
}

otgc/src/main/java/org/openconnectivity/otgc/domain/usecase/client/IntrospectUseCase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public IntrospectUseCase(IotivityRepository iotivityRepository) {
4848
}
4949

5050
public Single<JSONObject> execute(Device device) {
51-
return iotivityRepository.getNonSecureEndpoint(device)
51+
return iotivityRepository.getEndpoint(device)
5252
.flatMap(endpoint -> iotivityRepository.findResource(endpoint, OcfResourceType.INTROSPECTION))
5353
.flatMap(res -> {
5454
OcResource introspectionResource = res.getResourceList().get(0);

0 commit comments

Comments
 (0)