summaryrefslogtreecommitdiffhomepage
path: root/gui/src
diff options
context:
space:
mode:
authorEmīls Piņķis <emils@mullvad.net>2019-07-02 19:57:27 +0100
committerEmīls Piņķis <emils@mullvad.net>2019-07-05 16:49:28 +0100
commitdc5289a729dde3ece89c38e794f81a279b7546ad (patch)
treea09d9b7d3f09f0192611f7f041c619bf7fac4466 /gui/src
parent660cfa4ee78602db823c3b3f5753617e797a9f22 (diff)
downloadmullvadvpn-dc5289a729dde3ece89c38e794f81a279b7546ad.tar.xz
mullvadvpn-dc5289a729dde3ece89c38e794f81a279b7546ad.zip
Handle wireguard keygen events and fetch public key in main GUI process
Diffstat (limited to 'gui/src')
-rw-r--r--gui/src/main/index.ts48
1 files changed, 45 insertions, 3 deletions
diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts
index bdc1c4f5ec..a0dcbeb50b 100644
--- a/gui/src/main/index.ts
+++ b/gui/src/main/index.ts
@@ -13,6 +13,7 @@ import {
IRelayList,
IRelayListHostname,
ISettings,
+ KeygenEvent,
RelaySettings,
RelaySettingsUpdate,
TunnelState,
@@ -126,6 +127,8 @@ class ApplicationMain {
// The UI locale which is set once from onReady handler
private locale = 'en';
+ private wireguardPublicKey?: string;
+
public run() {
// Since electron's GPU blacklists are broken, GPU acceleration won't work on older distros
if (process.platform === 'linux') {
@@ -487,9 +490,7 @@ class ApplicationMain {
} else if ('relayList' in daemonEvent) {
this.setRelays(daemonEvent.relayList, this.settings.relaySettings);
} else if ('wireguardKey' in daemonEvent) {
- /// TODO: handle wireguard key events properly.
- log.info(`Received new key event`);
- log.info(daemonEvent);
+ this.handleWireguardKeygenEvent(daemonEvent.wireguardKey);
}
},
(error: Error) => {
@@ -512,6 +513,28 @@ class ApplicationMain {
}
}
+ private setWireguardKey(wireguardKey?: string) {
+ this.wireguardPublicKey = wireguardKey;
+ if (this.windowController) {
+ IpcMainEventChannel.wireguardKeys.notify(this.windowController.webContents, wireguardKey);
+ }
+ }
+
+ private handleWireguardKeygenEvent(event: KeygenEvent) {
+ switch (event) {
+ case 'too_many_keys':
+ case 'generation_failure':
+ this.notificationController.notifyKeyGenerationFailed();
+ this.wireguardPublicKey = undefined;
+ break;
+ default:
+ this.wireguardPublicKey = event.newKey;
+ }
+ if (this.windowController) {
+ IpcMainEventChannel.wireguardKeys.notifyKeygenEvent(this.windowController.webContents, event);
+ }
+ }
+
private setTunnelState(newState: TunnelState) {
this.tunnelState = newState;
this.updateTrayIcon(newState, this.settings.blockWhenDisconnected);
@@ -534,6 +557,7 @@ class ApplicationMain {
if (oldSettings.accountToken !== newSettings.accountToken) {
this.updateAccountHistory();
+ this.fetchWireguardKey();
}
if (this.windowController) {
@@ -831,6 +855,7 @@ class ApplicationMain {
currentVersion: this.currentVersion,
upgradeVersion: this.upgradeVersion,
guiSettings: this.guiSettings.state,
+ wireguardPublicKey: this.wireguardPublicKey,
}));
IpcMainEventChannel.settings.handleAllowLan((allowLan: boolean) =>
@@ -888,6 +913,15 @@ class ApplicationMain {
this.updateAccountHistory();
});
+ IpcMainEventChannel.wireguardKeys.handleGenerateKey(async () => {
+ try {
+ return await this.daemonRpc.generateWireguardKey();
+ } catch {
+ return 'generation_failure';
+ }
+ });
+ IpcMainEventChannel.wireguardKeys.handleVerifyKey(() => this.daemonRpc.verifyWireguardKey());
+
ipcMain.on('show-window', () => {
const windowController = this.windowController;
if (windowController) {
@@ -970,6 +1004,14 @@ class ApplicationMain {
}
}
+ private async fetchWireguardKey(): Promise<void> {
+ try {
+ this.setWireguardKey(await this.daemonRpc.getWireguardKey());
+ } catch (error) {
+ log.error(`Failed to fetch wireguard key: ${error.message}`);
+ }
+ }
+
private updateDaemonsAutoConnect() {
const daemonAutoConnect = this.guiSettings.autoConnect && getOpenAtLogin();
if (daemonAutoConnect !== this.settings.autoConnect) {