@@ -35,30 +35,31 @@ interface DisplayCertificateErrorOptions {
3535}
3636
3737enum CertificateVerificationResult {
38- SUCCESS = 0 , // Indicates success and disables Certificate Transparency verification
38+ /** Indicates success and disables Certificate Transparency verification */
39+ SUCCESS = 0 ,
3940 FAILURE = - 2 ,
4041 USE_CHROMIUM_VALIDATION = - 3 ,
4142}
4243
44+ enum CHROMIUM_ERRORS {
45+ CERT_AUTHORITY_INVALID = - 202 ,
46+ CERT_COMMON_NAME_INVALID = - 200 ,
47+ }
48+
49+ enum RESPONSE {
50+ GO_BACK = 0 ,
51+ RETRY = 0 ,
52+ SAVE_CERTIFICATE = 1 ,
53+ SHOW_DETAILS = 1 ,
54+ }
55+
4356class CertificateVerifyProcManager {
4457 private static bypassCertificatePinning = false ;
4558 private static isDialogLocked = false ;
4659 public static mainWindow : BrowserWindow ;
4760
4861 private static readonly dialogUnlockTimeout = 6000 ;
4962
50- public static readonly CHROMIUM_ERRORS = {
51- CERT_AUTHORITY_INVALID : - 202 ,
52- CERT_COMMON_NAME_INVALID : - 200 ,
53- } ;
54-
55- private static readonly RESPONSE = {
56- GO_BACK : 0 ,
57- RETRY : 0 ,
58- SAVE_CERTIFICATE : 1 ,
59- SHOW_DETAILS : 1 ,
60- } ;
61-
6263 private static readonly LOCALE = {
6364 RETRY : getText ( 'certificateVerifyProcManagerRetry' ) ,
6465 SHOW_DETAILS : getText ( 'certificateVerifyProcManagerShowDetails' ) ,
@@ -78,7 +79,7 @@ class CertificateVerifyProcManager {
7879 certificate : Certificate ,
7980 options : DisplayCertificateErrorOptions ,
8081 ) : Promise < void > {
81- const goBack = async ( ) => {
82+ const goBack = async ( ) : Promise < void > => {
8283 // Go back to the dialog
8384 await this . displayCertificateError ( hostname , certificate , {
8485 ...options ,
@@ -101,13 +102,13 @@ class CertificateVerifyProcManager {
101102 // For Linux and Windows, use a message box with the ability to save the certificate
102103 const { response} = await dialog . showMessageBox ( this . mainWindow , {
103104 buttons : [ this . LOCALE . SHOW_DETAILS_GO_BACK , this . LOCALE . SHOW_DETAILS_SAVE_CERTIFICATE ] ,
104- cancelId : this . RESPONSE . GO_BACK ,
105+ cancelId : RESPONSE . GO_BACK ,
105106 detail : textDetails ,
106107 message : this . LOCALE . SHOW_DETAILS_TITLE ,
107108 type : 'info' ,
108109 } ) ;
109110 switch ( response ) {
110- case this . RESPONSE . SAVE_CERTIFICATE : {
111+ case RESPONSE . SAVE_CERTIFICATE : {
111112 const { filePath : chosenPath } = await dialog . showSaveDialog ( this . mainWindow , {
112113 defaultPath : `${ hostname } .pem` ,
113114 } ) ;
@@ -118,7 +119,7 @@ class CertificateVerifyProcManager {
118119 await this . displayCertificateDetails ( hostname , certificate , options ) ;
119120 break ;
120121 }
121- case this . RESPONSE . GO_BACK : {
122+ case RESPONSE . GO_BACK : {
122123 await goBack ( ) ;
123124 break ;
124125 }
@@ -152,16 +153,16 @@ class CertificateVerifyProcManager {
152153
153154 const { checkboxChecked, response} = await dialog . showMessageBox ( this . mainWindow , {
154155 buttons : [ this . LOCALE . RETRY , this . LOCALE . SHOW_DETAILS ] ,
155- cancelId : this . RESPONSE . RETRY ,
156+ cancelId : RESPONSE . RETRY ,
156157 checkboxChecked : isChromiumError ? undefined : isCheckboxChecked ,
157158 checkboxLabel : isChromiumError ? undefined : this . LOCALE . WARNING_BYPASS ,
158- defaultId : this . RESPONSE . RETRY ,
159+ defaultId : RESPONSE . RETRY ,
159160 detail : isChromiumError ? this . LOCALE . WARNING_TEXT_CHROMIUM : this . LOCALE . WARNING_TEXT_PINNING ,
160161 message : this . LOCALE . WARNING_TITLE ,
161162 type : 'warning' ,
162163 } ) ;
163164 switch ( response ) {
164- case this . RESPONSE . RETRY : {
165+ case RESPONSE . RETRY : {
165166 if ( ! isChromiumError ) {
166167 this . bypassCertificatePinning = checkboxChecked ;
167168 if ( this . bypassCertificatePinning ) {
@@ -174,7 +175,7 @@ class CertificateVerifyProcManager {
174175 break ;
175176 }
176177
177- case this . RESPONSE . SHOW_DETAILS : {
178+ case RESPONSE . SHOW_DETAILS : {
178179 await this . displayCertificateDetails ( hostname , certificate , {
179180 bypassDialogLock,
180181 isCheckboxChecked : checkboxChecked ,
@@ -186,14 +187,14 @@ class CertificateVerifyProcManager {
186187 }
187188}
188189
189- export const attachTo = ( main : BrowserWindow ) => {
190+ export const attachTo = ( main : BrowserWindow ) : void => {
190191 CertificateVerifyProcManager . mainWindow = main ;
191192} ;
192193
193194export const setCertificateVerifyProc = async (
194195 request : CertificateVerifyProcProcRequest ,
195196 cb : ( verificationResult : number ) => void ,
196- ) => {
197+ ) : Promise < void > => {
197198 const { hostname, validatedCertificate, verificationResult, errorCode} = request ;
198199 // Check browser results
199200 if ( verificationResult !== 'net::OK' ) {
@@ -202,8 +203,7 @@ export const setCertificateVerifyProc = async (
202203 ) ;
203204
204205 const isCommonCertificateError =
205- errorCode === CertificateVerifyProcManager . CHROMIUM_ERRORS . CERT_COMMON_NAME_INVALID ||
206- errorCode === CertificateVerifyProcManager . CHROMIUM_ERRORS . CERT_AUTHORITY_INVALID ;
206+ errorCode === CHROMIUM_ERRORS . CERT_COMMON_NAME_INVALID || errorCode === CHROMIUM_ERRORS . CERT_AUTHORITY_INVALID ;
207207 if ( isCommonCertificateError ) {
208208 await CertificateVerifyProcManager . displayCertificateChromiumError ( hostname , validatedCertificate ) ;
209209 }
0 commit comments