Use setCertificateVerifyProc to verify lens proxy certificate (#7118)

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen authored and GitHub committed 2023-02-08 05:51:55 -05:00
1 parent ac2d0e46ff
commit ccab5fda1c
1 file changed
+15 -7
@@ -27,6 +27,12 @@ export interface UrlSource {
}
export type ContentSource = RequireExactlyOne<FileSource & UrlSource>;
enum ChromiumNetError {
SUCCESS = 0,
FAILURE = 1,
RESULT_FROM_CHROMIUM,
}
export interface ElectronWindowConfiguration {
id: string;
title: string;
@@ -112,6 +118,15 @@ const createElectronWindowInjectable = getInjectable({
applicationWindowState.manage(browserWindow);
browserWindow.webContents.session.setCertificateVerifyProc((request, shouldBeTrusted) => {
const { certificate } = request;
const cert = new X509Certificate(certificate.data);
const shouldTrustCert = cert.raw.length === lensProxyX509Cert.raw.length
&& timingSafeEqual(cert.raw, lensProxyX509Cert.raw);
shouldBeTrusted(shouldTrustCert ? ChromiumNetError.SUCCESS : ChromiumNetError.RESULT_FROM_CHROMIUM);
});
browserWindow
.on("focus", () => {
configuration.onFocus?.();
@@ -126,13 +141,6 @@ const createElectronWindowInjectable = getInjectable({
.webContents.on("dom-ready", () => {
configuration.onDomReady?.();
})
.on("certificate-error", (event, url, error, certificate, shouldBeTrusted) => {
const cert = new X509Certificate(certificate.data);
const shouldTrustCert = cert.raw.length === lensProxyX509Cert.raw.length
&& timingSafeEqual(cert.raw, lensProxyX509Cert.raw);
shouldBeTrusted(shouldTrustCert);
})
.on("did-fail-load", (_event, code, desc) => {
logger.error(
`[CREATE-ELECTRON-WINDOW]: Failed to load window "${configuration.id}"`,