@@ -16,7 +16,8 @@ import {
16
16
injectSystemCertificate ,
17
17
stringAsStream ,
18
18
hasCertInstalled ,
19
- bringToFront
19
+ bringToFront ,
20
+ setChromeFlags
20
21
} from './adb-commands' ;
21
22
import { streamLatestApk , clearAllApks } from './fetch-apk' ;
22
23
import { parseCert , getCertificateFingerprint , getCertificateSubjectHash } from '../../certificates' ;
@@ -185,24 +186,32 @@ export class AndroidAdbInterceptor implements Interceptor {
185
186
const subjectHash = getCertificateSubjectHash ( cert ) ;
186
187
const fingerprint = getCertificateFingerprint ( cert ) ;
187
188
188
- if ( await hasCertInstalled ( this . adbClient , deviceId , subjectHash , fingerprint ) ) {
189
+ if ( ! await hasCertInstalled ( this . adbClient , deviceId , subjectHash , fingerprint ) ) {
190
+ const certPath = `${ ANDROID_TEMP } /${ subjectHash } .0` ;
191
+ console . log ( `Adding cert file as ${ certPath } ` ) ;
192
+
193
+ await pushFile (
194
+ this . adbClient ,
195
+ deviceId ,
196
+ stringAsStream ( certContent . replace ( '\r\n' , '\n' ) ) ,
197
+ certPath ,
198
+ 0o444
199
+ ) ;
200
+
201
+ await injectSystemCertificate ( this . adbClient , deviceId , rootCmd , certPath ) ;
202
+ console . log ( `Cert injected` ) ;
203
+ } else {
189
204
console . log ( "Cert already installed, nothing to do" ) ;
190
- return ;
191
205
}
192
206
193
- const certPath = `${ ANDROID_TEMP } /${ subjectHash } .0` ;
194
- console . log ( `Adding cert file as ${ certPath } ` ) ;
207
+ const spkiFingerprint = generateSPKIFingerprint ( certContent ) ;
195
208
196
- await pushFile (
197
- this . adbClient ,
198
- deviceId ,
199
- stringAsStream ( certContent . replace ( '\r\n' , '\n' ) ) ,
200
- certPath ,
201
- 0o444
202
- ) ;
203
-
204
- await injectSystemCertificate ( this . adbClient , deviceId , rootCmd , certPath ) ;
205
- console . log ( `Cert injected` ) ;
209
+ // Chrome requires system certificates to use certificate transparency, which we can't do. To work
210
+ // around this, we need to explicitly trust our certificate in Chrome:
211
+ await setChromeFlags ( this . adbClient , deviceId , rootCmd , [
212
+ `--ignore-certificate-errors-spki-list=${ spkiFingerprint } `
213
+ ] ) ;
214
+ console . log ( 'Android Chrome flags set' ) ;
206
215
} catch ( e ) {
207
216
reportError ( e ) ;
208
217
}
0 commit comments