From 573744a22dcc279dc09448fe7fbf3e924a9a5be7 Mon Sep 17 00:00:00 2001 From: ImBenji Date: Tue, 5 Aug 2025 18:43:13 +0100 Subject: [PATCH] Add public key to peer info and implement public key generation from private key --- lib/services/vpn_session_service.dart | 13 +++++++++++++ lib/web/peer_routes.dart | 1 + 2 files changed, 14 insertions(+) diff --git a/lib/services/vpn_session_service.dart b/lib/services/vpn_session_service.dart index cf39fb3..7416528 100644 --- a/lib/services/vpn_session_service.dart +++ b/lib/services/vpn_session_service.dart @@ -46,6 +46,19 @@ class VpnSessionService { } } + /// Generates public key from private key + static Future _getPublicKeyFromPrivateKey(String privateKey) async { + try { + final pubProcess = await Process.start('wg', ['pubkey']); + pubProcess.stdin.writeln(privateKey); + await pubProcess.stdin.close(); + final publicKey = await pubProcess.stdout.transform(utf8.decoder).join(); + return publicKey.trim(); + } catch (e) { + return 'Error generating public key: $e'; + } + } + /// Gets keepalive info for a specific peer static Future _getKeepaliveForPeer(String publicKey) async { try { diff --git a/lib/web/peer_routes.dart b/lib/web/peer_routes.dart index b6995d7..f04071a 100644 --- a/lib/web/peer_routes.dart +++ b/lib/web/peer_routes.dart @@ -31,6 +31,7 @@ class PeerRoutes { 'peer': { 'ip': peer.ip, 'privateKey': peer.privateKey, + 'publicKey': peer.publicKey, }, 'server': { 'publicKey': serverPublicKey,