@@ -92,37 +92,40 @@ private void factoryResetHandler(long device) throws Exception {
92
92
/* Current date */
93
93
Date date = new Date ();
94
94
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
+ }
106
108
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" );
114
119
}
115
120
} else {
116
- this .displayNotValidCertificateHandler .handler ("Kyrio intermediate certificate is not valid" );
121
+ this .displayNotValidCertificateHandler .handler ("Kyrio end entity certificate is not valid" );
117
122
}
118
- } else {
119
- this .displayNotValidCertificateHandler .handler ("Kyrio end entity certificate is not valid" );
120
123
}
121
124
122
125
/* 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 ())) {
126
129
byte [] kyrioRootcaCertificate = ioRepository .getBytesFromFile (OtgcConstant .KYRIO_ROOT_CERTIFICATE ).blockingGet ();
127
130
if (OCPki .addMfgTrustAnchor (device , kyrioRootcaCertificate ) == -1 ) {
128
131
throw new Exception ("Add root certificate error" );
@@ -133,8 +136,8 @@ private void factoryResetHandler(long device) throws Exception {
133
136
134
137
/* EonTi root cert */
135
138
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 ())) {
138
141
byte [] eontiRootcaCertificate = ioRepository .getBytesFromFile (OtgcConstant .EONTI_ROOT_CERTIFICATE ).blockingGet ();
139
142
if (OCPki .addMfgTrustAnchor (device , eontiRootcaCertificate ) == -1 ) {
140
143
throw new Exception ("Add root certificate error" );
@@ -143,6 +146,18 @@ private void factoryResetHandler(long device) throws Exception {
143
146
this .displayNotValidCertificateHandler .handler ("EonTi root certificate is not valid" );
144
147
}
145
148
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
+
146
161
OCObt .shutdown ();
147
162
}
148
163
}
0 commit comments