@@ -16,7 +16,8 @@ import {
1616 injectSystemCertificate ,
1717 stringAsStream ,
1818 hasCertInstalled ,
19- bringToFront
19+ bringToFront ,
20+ setChromeFlags
2021} from './adb-commands' ;
2122import { streamLatestApk , clearAllApks } from './fetch-apk' ;
2223import { parseCert , getCertificateFingerprint , getCertificateSubjectHash } from '../../certificates' ;
@@ -185,24 +186,32 @@ export class AndroidAdbInterceptor implements Interceptor {
185186 const subjectHash = getCertificateSubjectHash ( cert ) ;
186187 const fingerprint = getCertificateFingerprint ( cert ) ;
187188
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 {
189204 console . log ( "Cert already installed, nothing to do" ) ;
190- return ;
191205 }
192206
193- const certPath = `${ ANDROID_TEMP } /${ subjectHash } .0` ;
194- console . log ( `Adding cert file as ${ certPath } ` ) ;
207+ const spkiFingerprint = generateSPKIFingerprint ( certContent ) ;
195208
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' ) ;
206215 } catch ( e ) {
207216 reportError ( e ) ;
208217 }
0 commit comments