Fix Android VPN startup and verify automatic subnet routing
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -11,7 +12,7 @@ const target = '10.253.79.1:17007';
|
||||
String config(String mode) =>
|
||||
'''
|
||||
hostname = "Android-validation"
|
||||
ipv4 = "10.253.83.11/24"
|
||||
ipv4 = "10.253.83.${mode == 'application' ? '11' : '12'}/24"
|
||||
listeners = []
|
||||
stun_servers = []
|
||||
stun_servers_v6 = []
|
||||
@@ -30,8 +31,10 @@ Future<void> waitForRoutes(
|
||||
bool installed = false,
|
||||
}) async {
|
||||
final deadline = DateTime.now().add(const Duration(seconds: 40));
|
||||
Map<String, dynamic>? lastState;
|
||||
while (DateTime.now().isBefore(deadline)) {
|
||||
final state = await client.status();
|
||||
lastState = state;
|
||||
final platform = state['platform_network'] as Map? ?? {};
|
||||
final routes =
|
||||
platform[installed ? 'installed_subnet_routes' : 'subnet_routes']
|
||||
@@ -40,6 +43,7 @@ Future<void> waitForRoutes(
|
||||
if (withdrawn ? routes.isEmpty : routes.contains('10.253.79.0/24')) return;
|
||||
await Future<void>.delayed(const Duration(milliseconds: 200));
|
||||
}
|
||||
debugPrint('ANDROID_ROUTE_TIMEOUT_STATE ${jsonEncode(lastState)}');
|
||||
throw StateError('Automatic subnet route transition timed out');
|
||||
}
|
||||
|
||||
@@ -91,13 +95,24 @@ void main() {
|
||||
try {
|
||||
await vpn.start(config('system_vpn'));
|
||||
await waitForRoutes(vpn, installed: true);
|
||||
expect(await channel.invokeMethod<bool>('debug_os_echo'), true);
|
||||
debugPrint('ANDROID_JAVA_OS_TCP_UDP_PASS');
|
||||
// Plain OS sockets prove that traffic from other applications can use
|
||||
// the VPN. No SDK stream is used for these transfers.
|
||||
final socket = await Socket.connect(
|
||||
'10.253.79.1',
|
||||
17007,
|
||||
timeout: const Duration(seconds: 10),
|
||||
);
|
||||
late Socket socket;
|
||||
debugPrint('ANDROID_SYSTEM_SOCKET_START');
|
||||
try {
|
||||
socket = await Socket.connect(
|
||||
'10.253.79.1',
|
||||
17007,
|
||||
timeout: const Duration(seconds: 30),
|
||||
);
|
||||
} catch (_) {
|
||||
debugPrint(
|
||||
'ANDROID_OS_TCP_FAILURE_STATE ${jsonEncode(await vpn.status())}',
|
||||
);
|
||||
rethrow;
|
||||
}
|
||||
try {
|
||||
socket.add(utf8.encode('OS TCP Android'));
|
||||
await socket.flush();
|
||||
@@ -111,16 +126,27 @@ void main() {
|
||||
socket.destroy();
|
||||
}
|
||||
final udp = await RawDatagramSocket.bind(InternetAddress.anyIPv4, 0);
|
||||
final received = Completer<Datagram>();
|
||||
final subscription = udp.listen((event) {
|
||||
if (event == RawSocketEvent.read) {
|
||||
final packet = udp.receive();
|
||||
if (packet != null && !received.isCompleted) {
|
||||
received.complete(packet);
|
||||
}
|
||||
}
|
||||
}, onError: received.completeError);
|
||||
try {
|
||||
final reply = udp.firstWhere((event) => event == RawSocketEvent.read);
|
||||
udp.send(
|
||||
utf8.encode('OS UDP Android'),
|
||||
InternetAddress('10.253.79.1'),
|
||||
17007,
|
||||
);
|
||||
await reply.timeout(const Duration(seconds: 10));
|
||||
expect(utf8.decode(udp.receive()!.data), 'OS UDP Android');
|
||||
final reply = await received.future.timeout(
|
||||
const Duration(seconds: 10),
|
||||
);
|
||||
expect(utf8.decode(reply.data), 'OS UDP Android');
|
||||
} finally {
|
||||
await subscription.cancel();
|
||||
udp.close();
|
||||
}
|
||||
debugPrint('ANDROID_SYSTEM_VPN_TCP_UDP_PASS');
|
||||
|
||||
Reference in New Issue
Block a user