Add public key to peer info and implement public key generation from private key

This commit is contained in:
ImBenji
2025-08-05 18:43:13 +01:00
parent 62853ca63a
commit 573744a22d
2 changed files with 14 additions and 0 deletions

View File

@@ -46,6 +46,19 @@ class VpnSessionService {
} }
} }
/// Generates public key from private key
static Future<String> _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 /// Gets keepalive info for a specific peer
static Future<String> _getKeepaliveForPeer(String publicKey) async { static Future<String> _getKeepaliveForPeer(String publicKey) async {
try { try {

View File

@@ -31,6 +31,7 @@ class PeerRoutes {
'peer': { 'peer': {
'ip': peer.ip, 'ip': peer.ip,
'privateKey': peer.privateKey, 'privateKey': peer.privateKey,
'publicKey': peer.publicKey,
}, },
'server': { 'server': {
'publicKey': serverPublicKey, 'publicKey': serverPublicKey,