From b3edff947d192ab69800eae489aa0009b52461b5 Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Sat, 14 Sep 2024 15:13:47 +0800 Subject: [PATCH] Update privatePublicKeyInput.vue Fixed issue mentioned in #375 --- .../privatePublicKeyInput.vue | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/static/app/src/components/configurationComponents/newPeersComponents/privatePublicKeyInput.vue b/src/static/app/src/components/configurationComponents/newPeersComponents/privatePublicKeyInput.vue index 315685c..54cd58f 100644 --- a/src/static/app/src/components/configurationComponents/newPeersComponents/privatePublicKeyInput.vue +++ b/src/static/app/src/components/configurationComponents/newPeersComponents/privatePublicKeyInput.vue @@ -30,12 +30,24 @@ export default { this.data.private_key = this.keypair.privateKey; this.data.public_key = this.keypair.publicKey; }, + testKey(key){ + const reg = /^[A-Za-z0-9+/]{43}=?=?$/; + return reg.test(key) + }, checkMatching(){ try{ - if (window.wireguard.generatePublicKey(this.keypair.privateKey) - !== this.keypair.publicKey){ - this.error = true; - this.dashboardStore.newMessage("WGDashboard", "Private Key and Public Key does not match.", "danger"); + if(this.keypair.privateKey){ + if(this.testKey(this.keypair.privateKey)){ + this.keypair.publicKey = window.wireguard.generatePublicKey(this.keypair.privateKey) + if (window.wireguard.generatePublicKey(this.keypair.privateKey) + !== this.keypair.publicKey){ + this.error = true; + this.dashboardStore.newMessage("WGDashboard", "Private Key and Public Key does not match.", "danger"); + }else{ + this.data.private_key = this.keypair.privateKey + this.data.public_key = this.keypair.publicKey + } + } } }catch (e){ this.error = true;