handshake method
Socks handshake.
Implementation
Future<bool> handshake() async {
if (state != SocksConnectionState.initial) {
throw StateError(
'Handshake cannot be called after initial negotiations is done.',
);
}
state = SocksConnectionState.handshaking;
await _checkSocksVersion();
int authenticationMethodsCount;
authenticationMethodsCount = await readUint8();
List<int> authenticationMethods;
authenticationMethods = await readBytes(authenticationMethodsCount);
if (authHandler != null) {
if (!authenticationMethods.contains(AuthenticationMethod.password.byte)) {
// No available authentication methods
add([
0x05, // Socks version
AuthenticationMethod.invalid.byte,
]);
return false;
} else {
await _passwordAuth();
}
} else {
// No auth
await _noAuth();
}
return true;
}