v1.0.0: AWG -> VLESS migration — ReVoltVPN debut
This commit is contained in:
1 parent
b679ba4d8f
commit
aaf9887f49
29 files changed
+1071
-1401
No files matched your search
@@ -1,16 +1,11 @@
|
||||
import 'dart:convert';
|
||||
import 'package:cryptography/cryptography.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class CryptoService {
|
||||
static const String _privKeyPref = 'wg_private_key';
|
||||
static const String _pubKeyPref = 'wg_public_key';
|
||||
static const String _deviceIdPref = 'device_uuid';
|
||||
|
||||
static const _storage = FlutterSecureStorage();
|
||||
|
||||
// ── Get or create the persistent device UUID ──────────────────────────────
|
||||
/// Get or create a persistent device UUID for server-side session tracking.
|
||||
static Future<String> getDeviceId() async {
|
||||
final existing = await _storage.read(key: _deviceIdPref);
|
||||
if (existing != null) return existing;
|
||||
@@ -19,28 +14,4 @@ class CryptoService {
|
||||
await _storage.write(key: _deviceIdPref, value: newId);
|
||||
return newId;
|
||||
}
|
||||
|
||||
// ── Get or create the X25519 keypair for WireGuard ────────────────────────
|
||||
static Future<Map<String, String>> getOrCreateKeys() async {
|
||||
String? privBase64 = await _storage.read(key: _privKeyPref);
|
||||
String? pubBase64 = await _storage.read(key: _pubKeyPref);
|
||||
|
||||
if (privBase64 != null && pubBase64 != null) {
|
||||
return {'privateKey': privBase64, 'publicKey': pubBase64};
|
||||
}
|
||||
|
||||
final algorithm = X25519();
|
||||
final keyPair = await algorithm.newKeyPair();
|
||||
|
||||
final privateKeyBytes = await keyPair.extractPrivateKeyBytes();
|
||||
final publicKey = await keyPair.extractPublicKey();
|
||||
|
||||
privBase64 = base64Encode(privateKeyBytes);
|
||||
pubBase64 = base64Encode(publicKey.bytes);
|
||||
|
||||
await _storage.write(key: _privKeyPref, value: privBase64);
|
||||
await _storage.write(key: _pubKeyPref, value: pubBase64);
|
||||
|
||||
return {'privateKey': privBase64, 'publicKey': pubBase64};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user