Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for system proxy configuration. #435

Merged
merged 1 commit into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 2 additions & 52 deletions background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { URL } from 'url';

import Electron from 'electron';
import _ from 'lodash';
import MacCA from 'mac-ca';
import WinCA from 'win-ca';

import mainEvents from '@/main/mainEvents';
import { setupKim } from '@/main/kim';
Expand All @@ -18,6 +16,7 @@ import * as K8s from '@/k8s-engine/k8s';
import resources from '@/resources';
import Logging from '@/utils/logging';
import * as childProcess from '@/utils/childProcess';
import setupNetworking from '@/main/networking';
import setupUpdate from '@/main/update';

Electron.app.setName('Rancher Desktop');
Expand Down Expand Up @@ -53,10 +52,7 @@ Electron.app.whenReady().then(async() => {
} catch (err) {
console.log(`Can't get app version: ${ err }`);
}
if (os.platform().startsWith('win')) {
// Inject the Windows certs.
WinCA({ inject: '+' });
}
setupNetworking();
try {
tray = new Tray();
} catch (e) {
Expand Down Expand Up @@ -220,52 +216,6 @@ Electron.ipcMain.handle('settings-write', (event, arg: RecursivePartial<settings
event.sender.sendToFrame(event.frameId, 'settings-update', cfg);
});

// Set up certificate handling for system certificates on Windows and macOS
Electron.app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
if (error === 'net::ERR_CERT_INVALID') {
// If we're getting *this* particular error, it means it's an untrusted cert.
// Ask the system store.
console.log(`Attempting to check system certificates for ${ url } (${ certificate.subjectName }/${ certificate.fingerprint })`);
if (os.platform().startsWith('win')) {
const certs: string[] = [];

WinCA({
format: WinCA.der2.pem, ondata: certs, fallback: false
});
for (const cert of certs) {
// For now, just check that the PEM data matches exactly; this is
// probably a little more strict than necessary, but avoids issues like
// an attacker generating a cert with the same serial.
if (cert === certificate.data) {
console.log(`Accepting system certificate for ${ certificate.subjectName } (${ certificate.fingerprint })`);
// eslint-disable-next-line node/no-callback-literal
callback(true);

return;
}
}
} else if (os.platform() === 'darwin') {
for (const cert of MacCA.all(MacCA.der2.pem)) {
// For now, just check that the PEM data matches exactly; this is
// probably a little more strict than necessary, but avoids issues like
// an attacker generating a cert with the same serial.
if (cert === certificate.data) {
console.log(`Accepting system certificate for ${ certificate.subjectName } (${ certificate.fingerprint })`);
// eslint-disable-next-line node/no-callback-literal
callback(true);

return;
}
}
}
}

console.log(`Not handling certificate error ${ error } for ${ url }`);

// eslint-disable-next-line node/no-callback-literal
callback(false);
});

Electron.ipcMain.on('k8s-state', (event) => {
event.returnValue = k8smanager.state;
});
Expand Down
Loading