Unverified Commit 2202d108 authored by Javier Guerra's avatar Javier Guerra Committed by GitHub

Merge pull request #12 from openconnectivity/develop

Merge develop into master
parents dfe275ec 799b0b53
......@@ -37,7 +37,7 @@ To import the IoTivity-lite Android API Binary into the OTGC Android App project
2. Copy **iotivity-lite.jar** into <otgc-android>/otgc/src/main/jniLibs.
3. Copy **libiotivity-lite-jni.so** into <otgc-android>/otgc/src/main/<target_arch>
3. Copy **libiotivity-lite-jni.so** into <otgc-android>/otgc/src/main/jniLibs/<target_arch>
where <target_arch> is one of the following values: x86, x86_64, armeabi, armeabi-v7a, armeabi-v7a-hard or arm64-v8a.
......
......@@ -30,7 +30,7 @@ android {
minSdkVersion 21
targetSdkVersion 28
versionCode 13
versionName "2.0.9"
versionName "2.0.10"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
compileOptions {
......
......@@ -55,20 +55,6 @@ public class IORepositoryTest {
.assertError(FileNotFoundException.class);
}
@Test
public void getBytesFromFile_rootCrtFile() {
repo.getBytesFromFile("root.crt")
.test()
.assertComplete();
}
@Test
public void getBytesFromFile_rootPrvFile() {
repo.getBytesFromFile("root.prv")
.test()
.assertComplete();
}
@Test
public void getBytesFromFile_missingFileReturnsFileNotFoundException() {
repo.getBytesFromFile("dummy.file")
......
-----BEGIN CERTIFICATE-----
MIIEEzCCA7mgAwIBAgIJAI0K+3tTskzXMAoGCCqGSM49BAMCMFsxDDAKBgNVBAoM
A09DRjEiMCAGA1UECwwZS3lyaW8gVGVzdCBJbmZyYXN0cnVjdHVyZTEnMCUGA1UE
AwweS3lyaW8gVEVTVCBJbnRlcm1lZGlhdGUgQ0EwMDAyMB4XDTE5MDkyMzA5MjUx
OFoXDTE5MTAyMzA5MjUxOFowYTEMMAoGA1UECgwDT0NGMSIwIAYDVQQLDBlLeXJp
byBUZXN0IEluZnJhc3RydWN0dXJlMS0wKwYDVQQDDCQxZTFiZWJmYi04ZjAzLTQ3
ODUtNWZhNy0xYjcwNGU2NTQzNjAwWTATBgcq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W9uMRAwDgYD
VQQDDAdSb290IENBMB4XDTE5MDUyMjA4MDY1NFoXDTI5MDUxOTA4MDY1NFowRjEL
MAkGA1UEBhMCVVMxJTAjBgNVBAoMHE9wZW4gQ29ubmVjdGl2aXR5IEZvdW5kYXRp
b24xEDAOBgNVBAMMB1Jvb3QgQ0EwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAS7
0B6uWQzda/OaUHs0gRhWt5DzuUgou3M1aBF5HFCHRJ8IFpG5nRDhbbCRLu6xyj1p
4BQaARhfwLfjBGHrdHHPo0IwQDAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQE
AwIBhjAdBgNVHQ4EFgQUUX9CUMUNAmLssx+15jZuJh8eAR8wCgYIKoZIzj0EAwID
RwAwRAIgOCJ4e6o9rm+i9fICRSTI/JoS18MUi3JX/EmnBa2aGzkCIEw8XrZDwP7l
hKESMzNh2IZJelimA+mPY/49iF6qPtK4
-----END CERTIFICATE-----
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIKdtJZE9IghVFGRm0LZRfnhwQEZK6DqjSe96i+oBlFVPoAoGCCqGSM49
AwEHoUQDQgAEu9AerlkM3WvzmlB7NIEYVreQ87lIKLtzNWgReRxQh0SfCBaRuZ0Q
4W2wkS7usco9aeAUGgEYX8C34wRh63Rxzw==
-----END EC PRIVATE KEY-----
......@@ -140,6 +140,7 @@ public class IotivityRepository {
}
OCIntrospection.setIntrospectionData(0 /* First device */, introspectionData);
OCBufferSettings.setMaxAppDataSize(16384); // 16 KB
OCMain.setConResAnnounced(false);
int ret = OCMain.mainInit(new OCMainInitHandler() {
@Override
......
......@@ -25,23 +25,11 @@ package org.openconnectivity.otgc.domain.usecase;
import org.iotivity.OCFactoryPresetsHandler;
import org.iotivity.OCObt;
import org.iotivity.OCPki;
import org.openconnectivity.otgc.data.repository.CertRepository;
import org.openconnectivity.otgc.data.repository.IORepository;
import org.openconnectivity.otgc.data.repository.IotivityRepository;
import org.openconnectivity.otgc.data.repository.PreferencesRepository;
import org.openconnectivity.otgc.utils.constant.OtgcConstant;
import org.openconnectivity.otgc.utils.constant.OtgcMode;
import org.spongycastle.asn1.ASN1Sequence;
import org.spongycastle.asn1.pkcs.PrivateKeyInfo;
import org.spongycastle.asn1.sec.ECPrivateKey;
import org.spongycastle.jce.provider.BouncyCastleProvider;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.X509Certificate;
import java.security.spec.ECGenParameterSpec;
import javax.inject.Inject;
......@@ -49,17 +37,14 @@ import io.reactivex.Completable;
public class InitializeIotivityUseCase {
private final IotivityRepository iotivityRepository;
private final CertRepository certRepository;
private final IORepository ioRepository;
private final PreferencesRepository settingRepository;
@Inject
public InitializeIotivityUseCase(IotivityRepository iotivityRepository,
CertRepository certRepository,
IORepository ioRepository,
PreferencesRepository settingRepository) {
this.iotivityRepository = iotivityRepository;
this.certRepository = certRepository;
this.ioRepository = ioRepository;
this.settingRepository = settingRepository;
}
......@@ -91,38 +76,29 @@ public class InitializeIotivityUseCase {
}
});
private void factoryResetHandler(long device) throws Exception {
String uuid = iotivityRepository.getDeviceId().blockingGet();
/* my cert */
byte[] eeCertificate = ioRepository.getBytesFromFile(OtgcConstant.KYRIO_EE_CERTIFICATE).blockingGet();
X509Certificate caCertificate = ioRepository.getAssetAsX509Certificate(OtgcConstant.ROOT_CERTIFICATE).blockingGet();
PrivateKey caPrivateKey = ioRepository.getAssetAsPrivateKey(OtgcConstant.ROOT_PRIVATE_KEY).blockingGet();
/* private key of my cert */
byte[] eeKey = ioRepository.getBytesFromFile(OtgcConstant.KYRIO_EE_KEY).blockingGet();
// Store root CA as trusted anchor
String strCACertificate = certRepository.x509CertificateToPemString(caCertificate).blockingGet();
if (OCPki.addTrustAnchor(device, strCACertificate.getBytes()) == -1) {
throw new Exception("Add trust anchor error");
/* 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);
if (credid == -1) {
throw new Exception("Add identity certificate error");
}
if (OCPki.addMfgTrustAnchor(device, strCACertificate.getBytes()) == -1) {
throw new Exception("Add manufacturer trust anchor error");
if (OCPki.addMfgIntermediateCert(device, credid, subcaCertificate) == -1) {
throw new Exception("Add intermediate certificate error");
}
// public/private key pair that we are creating certificate for
ECGenParameterSpec ecParamSpec = new ECGenParameterSpec("secp256r1");
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("EC", BouncyCastleProvider.PROVIDER_NAME);
keyPairGenerator.initialize(ecParamSpec);
KeyPair keyPair = keyPairGenerator.generateKeyPair();
// Public key
PublicKey publicKey = keyPair.getPublic();
// PrivateKey
ASN1Sequence pkSeq = (ASN1Sequence)ASN1Sequence.fromByteArray(keyPair.getPrivate().getEncoded());
PrivateKeyInfo pkInfo = PrivateKeyInfo.getInstance(pkSeq);
ECPrivateKey privateKey = ECPrivateKey.getInstance(pkInfo.parsePrivateKey());
String strPrivateKey = certRepository.privateKeyToPemString(privateKey).blockingGet();
X509Certificate identityCertificate = certRepository.generateIdentityCertificate(uuid, publicKey, caPrivateKey).blockingGet();
String strIdentityCertificate = certRepository.x509CertificateToPemString(identityCertificate).blockingGet();
if (OCPki.addMfgCert(device, strIdentityCertificate.getBytes(), strPrivateKey.getBytes()) == -1) {
throw new Exception("Add identity certificate error");
if (OCPki.addMfgTrustAnchor(device, rootcaCertificate) == -1) {
throw new Exception("Add root certificate error");
}
OCObt.shutdown();
......
......@@ -38,8 +38,9 @@ public class OtgcConstant {
// File databases for IoTivity
public static final String INTROSPECTION_CBOR_FILE = "introspection.dat";
// Root certificate and keypair
public static String ROOT_CERTIFICATE = "root.crt";
public static String ROOT_PRIVATE_KEY = "root.prv";
public static String ROOT_PUBLIC_KEY = "root.pub";
/* Kyrio certificate chain */
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";
public static String KYRIO_EE_KEY = "kyrio-ee-key.pem";
}
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