@@ -22,110 +22,116 @@ export class CertCheckServer {
2222 this . server . get ( '/download-cert' ) . thenReply ( 200 , certificatePem , {
2323 'Content-type' : 'application/x-x509-ca-cert'
2424 } ) ,
25- this . server . get ( '/check-cert' ) . thenReply ( 200 , `
26- <html>
27- <title>${ this . config . appName } Certificate Setup</title>
28- <meta charset="UTF-8" />
29- <link href="http://fonts.googleapis.com/css?family=Lato" rel="stylesheet" />
30- <style>
31- body {
32- margin: 0;
33- padding: 20px;
34- background-color: #d8e2e6;
35- font-family: Lato, Arial;
36-
37- position: absolute;
38- bottom: 0;
39- width: 100%;
40- box-sizing: border-box;
41- text-align: center;
42- }
43-
44- body:not(.show-content) > * {
45- display: none;
46- }
47-
48- p {
49- font-size: 16pt;
50- }
51-
52- iframe {
53- display: none;
54- }
55- </style>
56- <script>
57- let installingCert = false;
58- const targetUrl = ${ JSON . stringify ( targetUrl ) } ;
59-
60- function ensureCertificateIsInstalled() {
61- const testUrl = window.location.href.replace('http://', 'https://').replace('check-cert', 'test-https');
62- const downloadUrl = window.location.href.replace('check-cert', 'download-cert');
63- const reportSuccessUrl = window.location.href.replace('check-cert', 'report-success');
64-
65- fetch(testUrl)
66- .then(() => true)
67- .catch(() => false)
68- .then((certificateIsTrusted) => {
69- if (certificateIsTrusted) {
70- // Report success (ignoring errors) then continue.
71- fetch(reportSuccessUrl).catch(() => {}).then(() => {
72- window.location.replace(targetUrl);
25+ this . server . get ( '/check-cert' ) . thenCallback ( ( ) => {
26+ console . log ( 'Request to /check-cert received' ) ;
27+ return {
28+ statusCode : 200 ,
29+ body : `
30+ <html>
31+ <title>${ this . config . appName } Certificate Setup</title>
32+ <meta charset="UTF-8" />
33+ <link href="http://fonts.googleapis.com/css?family=Lato" rel="stylesheet" />
34+ <style>
35+ body {
36+ margin: 0;
37+ padding: 20px;
38+ background-color: #d8e2e6;
39+ font-family: Lato, Arial;
40+
41+ position: absolute;
42+ bottom: 0;
43+ width: 100%;
44+ box-sizing: border-box;
45+ text-align: center;
46+ }
47+
48+ body:not(.show-content) > * {
49+ display: none;
50+ }
51+
52+ p {
53+ font-size: 16pt;
54+ }
55+
56+ iframe {
57+ display: none;
58+ }
59+ </style>
60+ <script>
61+ let installingCert = false;
62+ const targetUrl = ${ JSON . stringify ( targetUrl ) } ;
63+
64+ function ensureCertificateIsInstalled() {
65+ const testUrl = window.location.href.replace('http://', 'https://').replace('check-cert', 'test-https');
66+ const downloadUrl = window.location.href.replace('check-cert', 'download-cert');
67+ const reportSuccessUrl = window.location.href.replace('check-cert', 'report-success');
68+
69+ fetch(testUrl)
70+ .then(() => true)
71+ .catch(() => false)
72+ .then((certificateIsTrusted) => {
73+ if (certificateIsTrusted) {
74+ // Report success (ignoring errors) then continue.
75+ fetch(reportSuccessUrl).catch(() => {}).then(() => {
76+ window.location.replace(targetUrl);
77+ });
78+ } else {
79+ // Start trying to prompt the user to install the cert
80+ if (!installingCert) {
81+ installingCert = true;
82+ document.body.className = 'show-content';
83+ const iframe = document.createElement('iframe');
84+ iframe.src = downloadUrl;
85+ document.body.appendChild(iframe);
86+ setInterval(ensureCertificateIsInstalled, 500);
87+ }
88+ }
7389 });
74- } else {
75- // Start trying to prompt the user to install the cert
76- if (!installingCert) {
77- installingCert = true;
78- document.body.className = 'show-content';
79- const iframe = document.createElement('iframe');
80- iframe.src = downloadUrl;
81- document.body.appendChild(iframe);
82- setInterval(ensureCertificateIsInstalled, 500);
83- }
8490 }
85- } );
86- }
87- ensureCertificateIsInstalled();
88- </script>
89- <body>
90- < svg
91- version="1.1 "
92- xmlns="http://www.w3.org/2000/svg "
93- xmlns:xlink="http://www.w3.org/1999/xlink "
94- x="0px "
95- y="0px "
96- width="400px "
97- height="400px "
98- viewBox="0 0 50 50"
99- style="enable-background:new 0 0 50 50;"
100- >
101- <path fill="#b6c2ca" d="M25.251,6.461c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615V6.461z">
102- <animateTransform
103- attributeType="xml "
104- attributeName="transform "
105- type="rotate "
106- from="0 25 25 "
107- to="360 25 25 "
108- dur="6s"
109- repeatCount="indefinite"
110- / >
111- </path>
112- </svg >
113-
114- <p >
115- To intercept HTTPS traffic, you need to trust the ${ this . config . appName } certificate .
116- <br/ >
117- This will only apply to this standalone Firefox profile, not your normal browser.
118- </p>
119- <p><strong >
120- Select 'Trust this CA to identify web sites' and press 'OK' to continue.
121- </strong></p>
122- < p>
123- Made a mistake? Quit Firefox and start again to retry.
124- </p >
125- </div >
126- </body>
127- </html>
128- ` ) ,
91+ ensureCertificateIsInstalled( );
92+ </script>
93+ <body>
94+ <svg
95+ version="1.1"
96+ xmlns="http://www.w3.org/2000/ svg"
97+ xmlns:xlink="http://www.w3.org/1999/xlink "
98+ x="0px "
99+ y="0px "
100+ width="400px "
101+ height="400px "
102+ viewBox="0 0 50 50 "
103+ style="enable-background:new 0 0 50 50; "
104+ >
105+ <path fill="#b6c2ca" d="M25.251,6.461c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615V6.461z">
106+ <animateTransform
107+ attributeType="xml"
108+ attributeName="transform"
109+ type="rotate "
110+ from="0 25 25 "
111+ to="360 25 25 "
112+ dur="6s "
113+ repeatCount="indefinite "
114+ />
115+ </path>
116+ </svg >
117+
118+ <p >
119+ To intercept HTTPS traffic, you need to trust the ${ this . config . appName } certificate.
120+ <br/ >
121+ This will only apply to this standalone Firefox profile, not your normal browser .
122+ </p >
123+ <p><strong>
124+ Select 'Trust this CA to identify web sites' and press 'OK' to continue.
125+ </strong></p >
126+ <p>
127+ Made a mistake? Quit Firefox and start again to retry.
128+ </ p>
129+ </div>
130+ </body >
131+ </html >
132+ `
133+ } ;
134+ } ) ,
129135 this . server . get ( '/spinner' ) . thenReply ( 200 , `
130136 <html>
131137 <title>${ this . config . appName } Certificate Setup</title>
@@ -181,6 +187,7 @@ export class CertCheckServer {
181187 async waitForSuccess ( ) : Promise < void > {
182188 return new Promise < void > ( ( resolve ) =>
183189 this . server ! . get ( '/report-success' ) . thenCallback ( ( ) => {
190+ console . log ( "Cert check successful" ) ;
184191 resolve ( ) ;
185192 return { status : 200 } ;
186193 } )
0 commit comments