Skip to content
This repository has been archived by the owner on Jun 29, 2021. It is now read-only.

Commit

Permalink
Merge pull request #5 from openconnectivity/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
javiguerra authored Aug 14, 2019
2 parents 9d07b40 + b05ea22 commit 267ffdb
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 34 deletions.
2 changes: 1 addition & 1 deletion otgc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ android {
minSdkVersion 21
targetSdkVersion 28
versionCode 13
versionName "2.0.2"
versionName "2.0.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

compileOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ public DeviceEntity(@NonNull String id, String name, OCEndpoint endpoints, @Null
mHosts = new ArrayList<>();

while(endpoints != null) {
String[] endpointStr = new String[1];
OCEndpointUtil.toString(endpoints, endpointStr);
mHosts.add(endpointStr[0]);
String endpointStr = OCEndpointUtil.toString(endpoints);
mHosts.add(endpointStr);

endpoints = endpoints.getNext();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public Completable doOwnershipTransfer(String deviceId, OcfOxmType oxm) {
emitter.onError(new Exception(error));
}
});
} else if (oxm == OcfOxmType.OC_OXMTYPE_MFG_CERT) {
ret = OCObt.performCertOtm(uuid, handler);
}

if (ret >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public Completable initOICStack() {
public int initialize() {
Timber.d("In OCMainInitHandler.initilize()");
int ret = OCMain.initPlatform("OCF");
ret |= OCMain.addDevice("/oic/d", "oic.d.phone", "OTGC", "ocf.1.0.0", "ocf.res.1.3.0");
ret |= OCMain.addDevice("/oic/d", "oic.d.phone", "OTGC", "ocf.2.4.0", "ocf.res.1.3.0");
return ret;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,16 @@ public Device(DeviceType type, String deviceId, OcDeviceInfo deviceInfo, OCEndpo
this.permits = permits;

while(endpoints != null) {
String[] endpointStr = new String[1];
OCEndpointUtil.toString(endpoints, endpointStr);

if (endpointStr[0].startsWith("coaps://") && endpointStr[0].contains(".")) {
ipv4SecureHost = endpointStr[0];
} else if (endpointStr[0].startsWith("coaps://")) {
ipv6SecureHost = endpointStr[0];
} else if (endpointStr[0].startsWith("coap://") && endpointStr[0].contains(".")) {
ipv4Host = endpointStr[0];
} else if (endpointStr[0].startsWith("coap://")){
ipv6Host = endpointStr[0];
String endpointStr = OCEndpointUtil.toString(endpoints);

if (endpointStr.startsWith("coaps://") && endpointStr.contains(".")) {
ipv4SecureHost = endpointStr;
} else if (endpointStr.startsWith("coaps://")) {
ipv6SecureHost = endpointStr;
} else if (endpointStr.startsWith("coap://") && endpointStr.contains(".")) {
ipv4Host = endpointStr;
} else if (endpointStr.startsWith("coap://")){
ipv6Host = endpointStr;
}

endpoints = endpoints.getNext();
Expand Down Expand Up @@ -206,13 +205,38 @@ public boolean hasCREDpermit() {

@Override
public int compareTo(Device device) {
if (this.getDeviceInfo().getName().compareTo(device.getDeviceInfo().getName()) == 0) {
return this.getDeviceId().compareTo(device.getDeviceId());
} else if (this.getDeviceInfo().getName().isEmpty()) {
return "Unnamed".compareTo(device.getDeviceInfo().getName());
} else if (device.getDeviceInfo().getName().isEmpty()) {
return this.getDeviceInfo().getName().compareTo("Unnamed");
int res;

if (this.getDeviceType() == device.getDeviceType()) { // Same types
int nameComparision;
if (this.getDeviceInfo().getName() == null && device.getDeviceInfo().getName() == null) {
nameComparision = 0;
} else if (this.getDeviceInfo().getName() == null) {
nameComparision = -1;
} else if (device.getDeviceInfo().getName() == null) {
nameComparision = 1;
} else {
nameComparision = this.getDeviceInfo().getName().compareTo(device.getDeviceInfo().getName());
}

int uuidComparision = this.getDeviceId().compareTo(device.getDeviceId());

// order by name or order by UUID if the names are equals
res = (nameComparision == 0) ? uuidComparision : nameComparision;

} else { // Different types

if (this.getDeviceType() == DeviceType.UNOWNED) { // Is device1 unowned?
res = -1;
} else if (device.getDeviceType() == DeviceType.UNOWNED) { // Is device2 unowned?
res = 1;
} else {
int permissionComparision = this.getPermits() - device.getPermits();
res = -1 * permissionComparision;
}

}
return this.getDeviceInfo().getName().compareTo(device.getDeviceInfo().getName());

return res;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public Completable execute(Device device, String roleId, String roleAuthority) {
String rootCert = certRepository.x509CertificateToPemString(rootCa).blockingGet();

// Generate the identity certificate in PEM format
X509Certificate idCert = certRepository.generateIdentityCertificate("*", publicKey, caPrivateKey).blockingGet();
//X509Certificate idCert = certRepository.generateIdentityCertificate(device.getDeviceId(), publicKey, caPrivateKey).blockingGet();
//X509Certificate idCert = certRepository.generateIdentityCertificate("*", publicKey, caPrivateKey).blockingGet();
X509Certificate idCert = certRepository.generateIdentityCertificate(device.getDeviceId(), publicKey, caPrivateKey).blockingGet();
String identityCert = certRepository.x509CertificateToPemString(idCert).blockingGet();

// Generate the role certificate in PEM format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public Completable execute(Device device, String roleId, String roleAuthority) {
String rootCert = certRepository.x509CertificateToPemString(rootCa).blockingGet();

// Generate the certificate in PEM format
X509Certificate cert = certRepository.generateIdentityCertificate("*", publicKey, caPrivateKey).blockingGet();
//X509Certificate cert = certRepository.generateIdentityCertificate(device.getDeviceId(), publicKey, caPrivateKey).blockingGet();
//X509Certificate cert = certRepository.generateIdentityCertificate("*", publicKey, caPrivateKey).blockingGet();
X509Certificate cert = certRepository.generateIdentityCertificate(device.getDeviceId(), publicKey, caPrivateKey).blockingGet();
String identityCert = certRepository.x509CertificateToPemString(cert).blockingGet();

return cmsRepository.provisionIdentityCertificate(endpoint, device.getDeviceId(), rootCert, identityCert);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public Completable execute(Device client, Device server)
String rootCert = certRepository.x509CertificateToPemString(rootCa).blockingGet();

// Generate the identity certificate in PEM format
X509Certificate idCert = certRepository.generateIdentityCertificate("*", publicKey, caPrivateKey).blockingGet();
//X509Certificate idCert = certRepository.generateIdentityCertificate(device.getDeviceId(), publicKey, caPrivateKey).blockingGet();
//X509Certificate idCert = certRepository.generateIdentityCertificate("*", publicKey, caPrivateKey).blockingGet();
X509Certificate idCert = certRepository.generateIdentityCertificate(client.getDeviceId(), publicKey, caPrivateKey).blockingGet();
String identityCert = certRepository.x509CertificateToPemString(idCert).blockingGet();

return cmsRepository.provisionIdentityCertificate(endpoint, client.getDeviceId(), rootCert, identityCert);
Expand All @@ -136,8 +136,8 @@ public Completable execute(Device client, Device server)
String rootCert = certRepository.x509CertificateToPemString(rootCa).blockingGet();

// Generate the certificate in PEM format
X509Certificate cert = certRepository.generateIdentityCertificate("*", publicKey, caPrivateKey).blockingGet();
//X509Certificate cert = certRepository.generateIdentityCertificate(device.getDeviceId(), publicKey, caPrivateKey).blockingGet();
//X509Certificate cert = certRepository.generateIdentityCertificate("*", publicKey, caPrivateKey).blockingGet();
X509Certificate cert = certRepository.generateIdentityCertificate(server.getDeviceId(), publicKey, caPrivateKey).blockingGet();
String identityCert = certRepository.x509CertificateToPemString(cert).blockingGet();

return cmsRepository.provisionIdentityCertificate(endpoint, server.getDeviceId(), rootCert, identityCert);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.openconnectivity.otgc.utils.viewmodel.ViewModelError;
import org.openconnectivity.otgc.viewmodel.TrustAnchorViewModel;
import org.spongycastle.jce.provider.BouncyCastleProvider;
import org.spongycastle.util.encoders.Base64;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
Expand Down Expand Up @@ -166,9 +167,22 @@ public void onInfoClick(int position, View v) {
// set title
alertDialogBuilder.setTitle("Trust Anchor - Information");
// set dialog message
alertDialogBuilder
.setMessage(showX509CertificateInformation(mAdapter.mDataset.get(position).getPublicData().getDerData()))
.setCancelable(false)

if (mAdapter.mDataset.get(position).getPublicData().getDerData() != null) {
alertDialogBuilder
.setMessage(showX509CertificateInformation(mAdapter.mDataset.get(position).getPublicData().getDerData()));
} else if (mAdapter.mDataset.get(position).getPublicData().getPemData() != null) {
String pem = mAdapter.mDataset.get(position).getPublicData().getPemData();
String base64 = pem.replaceAll("\\s", "")
.replaceAll("\\r\\n", "")
.replace("-----BEGINCERTIFICATE-----", "")
.replace("-----ENDCERTIFICATE-----", "");
byte[] der = Base64.decode(base64.getBytes());
alertDialogBuilder
.setMessage(showX509CertificateInformation(der));
}

alertDialogBuilder.setCancelable(false)
.setPositiveButton("OK", (dialog, id) -> dialog.dismiss());

// create alert dialog
Expand Down

0 comments on commit 267ffdb

Please sign in to comment.