Skip to content

Commit

Permalink
Use setCertificateVerifyProc to verify lens proxy certificate (#7118)
Browse files Browse the repository at this point in the history
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
  • Loading branch information
jakolehm committed Feb 8, 2023
1 parent ac2d0e4 commit ccab5fd
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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?.();
Expand All @@ -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}"`,
Expand Down

0 comments on commit ccab5fd

Please sign in to comment.