|
@@ -37,12 +37,50 @@ public class FactoryPresetsHandler implements OCFactoryPresetsHandler {
|
|
|
|
|
|
private void setPKISecurityMfgCert(long deviceIndex) {
|
|
|
|
|
|
+ // load End Endtity cert
|
|
|
+ byte[] cert = getFileBytes("pki_certs/ee.pem");
|
|
|
+ if (cert == null) {
|
|
|
+ Log.e(TAG, "Failed to read certificates");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // load End Endtity private key
|
|
|
+ byte[] key = getFileBytes("pki_certs/key.pem");
|
|
|
+ if (key == null) {
|
|
|
+ Log.e(TAG, "Failed to read private key");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // add End Entity Cert
|
|
|
+ int eeCredId = OCPki.addMfgCert(deviceIndex, cert, key);
|
|
|
+ Log.d(TAG, "addMfgCert() credId = " + eeCredId);
|
|
|
+ if (eeCredId < 0) {
|
|
|
+ Log.e(TAG, "Error installing manufacturer ee certificate");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // load Sub CA
|
|
|
+ byte[] subCa = getFileBytes("pki_certs/subca1.pem");
|
|
|
+ if (subCa == null) {
|
|
|
+ Log.e(TAG, "Failed to read sub ca cetificate");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // add Sub CA
|
|
|
+ int subCaCredId = OCPki.addMfgIntermediateCert(deviceIndex, eeCredId, subCa);
|
|
|
+ Log.d(TAG, "addMfgIntermediateCert() result = " + subCaCredId);
|
|
|
+ if (subCaCredId < 0) {
|
|
|
+ Log.e(TAG, "Error installing intermediate ca certificate");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // load Root CA 1
|
|
|
byte[] rootCa1 = getFileBytes("pki_certs/rootca1.pem");
|
|
|
if (rootCa1 == null) {
|
|
|
Log.e(TAG, "Failed to read root ca1 certificate");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ // add Root CA 1
|
|
|
int rootCaCredId = OCPki.addMfgTrustAnchor(deviceIndex, rootCa1);
|
|
|
Log.d(TAG, "addMfgTrustAnchor() result = " + rootCaCredId);
|
|
|
if (rootCaCredId < 0) {
|
|
@@ -50,18 +88,37 @@ public class FactoryPresetsHandler implements OCFactoryPresetsHandler {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ // load Root CA 2
|
|
|
byte[] rootCa2 = getFileBytes("pki_certs/rootca2.pem");
|
|
|
if (rootCa2 == null) {
|
|
|
Log.e(TAG, "Failed to read root ca2 certificate");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ // add Root CA 2
|
|
|
rootCaCredId = OCPki.addMfgTrustAnchor(deviceIndex, rootCa2);
|
|
|
Log.d(TAG, "addMfgTrustAnchor() result = " + rootCaCredId);
|
|
|
if (rootCaCredId < 0) {
|
|
|
Log.e(TAG, "Error installing root ca2 certificate");
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
+ // load Root CA 3
|
|
|
+ byte[] rootCa3 = getFileBytes("pki_certs/rootca3.pem");
|
|
|
+ if (rootCa3 == null) {
|
|
|
+ Log.e(TAG, "Failed to read root ca3 certificate");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // add Root CA 3
|
|
|
+ rootCaCredId = OCPki.addMfgTrustAnchor(deviceIndex, rootCa3);
|
|
|
+ Log.d(TAG, "addMfgTrustAnchor() result = " + rootCaCredId);
|
|
|
+ if (rootCaCredId < 0) {
|
|
|
+ Log.e(TAG, "Error installing root ca3 certificate");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public byte[] getFileBytes(String filepath) {
|