mirror of
https://github.com/OutlineFoundation/outline-server.git
synced 2026-08-04 14:37:34 +00:00
Avoid passing objects across the boundary
This commit is contained in:
parent
62b365979c
commit
a2562d690b
10 changed files with 16 additions and 33 deletions
|
|
@ -239,16 +239,17 @@ function main() {
|
|||
});
|
||||
|
||||
// Handle request to trust the certificate from the renderer process.
|
||||
const trustedFingerprints = new Map<string, string>();
|
||||
ipcMain.on('trust-certificate', (event: IpcEvent, anchor: HostAnchor) => {
|
||||
trustedFingerprints.set(anchor.host, `sha256/${anchor.fingerprint}`);
|
||||
const trustedFingerprints = new Set<string>();
|
||||
const makeKey = (host: string, fingerprint: string) => `${host};${fingerprint}`;
|
||||
ipcMain.on('trust-certificate', (event: IpcEvent, host: string, fingerprint: string) => {
|
||||
trustedFingerprints.add(makeKey(host, `sha256/${fingerprint}`));
|
||||
event.returnValue = true;
|
||||
});
|
||||
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
|
||||
event.preventDefault();
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
callback(trustedFingerprints.get(parsed.host) === certificate.fingerprint);
|
||||
callback(trustedFingerprints.has(makeKey(parsed.host, certificate.fingerprint)));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
callback(false);
|
||||
|
|
|
|||
|
|
@ -47,8 +47,8 @@ if (sentryDsn) {
|
|||
});
|
||||
}
|
||||
|
||||
contextBridge.exposeInMainWorld('trustCertificate', (anchor: HostAnchor) => {
|
||||
return ipcRenderer.sendSync('trust-certificate', anchor);
|
||||
contextBridge.exposeInMainWorld('trustCertificate', (host: string, fingerprint: string) => {
|
||||
return ipcRenderer.sendSync('trust-certificate', host, fingerprint);
|
||||
});
|
||||
|
||||
contextBridge.exposeInMainWorld('openImage', (basename: string) => {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
run_action server_manager/electron_app/build linux
|
||||
run_action server_manager/electron_app/build
|
||||
|
||||
cd "${BUILD_DIR}/server_manager/electron_app/static"
|
||||
|
||||
OUTLINE_DEBUG='true' \
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
"include": ["**/*.ts"],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"web_app/galery_app",
|
||||
"web_app/gallery_app",
|
||||
// FIXME: these tests fail with a runtime error because app.ts depends on
|
||||
// polymer, which targets the browser and uses ES6 imports.
|
||||
"web_app/app.spec.ts"
|
||||
|
|
|
|||
2
src/server_manager/types/preload.d.ts
vendored
2
src/server_manager/types/preload.d.ts
vendored
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
// Functions made available to the renderer process via preload.ts.
|
||||
|
||||
declare function trustCertificate(anchor: HostAnchor): boolean;
|
||||
declare function trustCertificate(host: string, fingerprint: string): boolean;
|
||||
declare function openImage(basename: string): void;
|
||||
declare function onUpdateDownloaded(callback: () => void): void;
|
||||
|
||||
|
|
|
|||
19
src/server_manager/types/trust_certificate.d.ts
vendored
19
src/server_manager/types/trust_certificate.d.ts
vendored
|
|
@ -1,19 +0,0 @@
|
|||
// Copyright 2022 The Outline Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/** Represents an additional trust anchor for a single host. */
|
||||
declare interface HostAnchor {
|
||||
host: string;
|
||||
fingerprint: string;
|
||||
}
|
||||
|
|
@ -13,8 +13,8 @@
|
|||
// limitations under the License.
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(window as any).trustCertificate = (anchor: HostAnchor) => {
|
||||
console.log(`Requested to trust certificate: ${anchor}`);
|
||||
(window as any).trustCertificate = (host: string, fingerprint: string) => {
|
||||
console.log(`Requested to trust certificate for ${host}: ${fingerprint}`);
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ export class DigitalOceanServer extends ShadowboxServer implements server.Manage
|
|||
const apiAddress = this.getManagementApiAddress();
|
||||
const parsed = new URL(apiAddress);
|
||||
// Loaded both the cert and url without exceptions, they can be set.
|
||||
trustCertificate({host: parsed.host, fingerprint: certificateFingerprint});
|
||||
trustCertificate(parsed.host, certificateFingerprint);
|
||||
this.setManagementApiUrl(apiAddress);
|
||||
return true;
|
||||
} catch (e) {
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ export class GcpServer extends ShadowboxServer implements server.ManagedServer {
|
|||
const apiUrl = outlineGuestAttributes.get('apiUrl');
|
||||
try {
|
||||
const parsed = new URL(apiUrl);
|
||||
trustCertificate({host: parsed.host, fingerprint: certSha256});
|
||||
trustCertificate(parsed.host, certSha256);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this.setInstallState(InstallState.FAILED);
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class ManualServer extends ShadowboxServer implements server.ManualServer {
|
|||
try {
|
||||
const parsed = new URL(manualServerConfig.apiUrl);
|
||||
const fingerprint = btoa(hexToString(manualServerConfig.certSha256));
|
||||
trustCertificate({host: parsed.host, fingerprint});
|
||||
trustCertificate(parsed.host, fingerprint);
|
||||
} catch (e) {
|
||||
// Error trusting certificate, may be due to bad user input.
|
||||
console.error('Error trusting certificate');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue