2022-11-08 11:24:54 +00:00
|
|
|
import 'dart:convert';
|
2022-11-07 22:20:45 +00:00
|
|
|
import 'dart:io';
|
2022-11-08 11:24:54 +00:00
|
|
|
import 'dart:typed_data';
|
2022-11-07 22:20:45 +00:00
|
|
|
import 'package:moxxmpp_socket/src/ssl.dart';
|
|
|
|
|
|
|
|
void main(List<String> argv) async {
|
2022-11-08 11:24:54 +00:00
|
|
|
if (argv.length < 2) {
|
2022-11-07 22:20:45 +00:00
|
|
|
print('Usage: test_wrong_host.dart server-addr host-name');
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
final server = argv[0];
|
|
|
|
final hostname = argv[1];
|
2022-11-08 11:24:54 +00:00
|
|
|
final port = argv.length == 3 ? argv[2] : '5223';
|
|
|
|
|
2022-11-07 22:20:45 +00:00
|
|
|
final ctx = MbedSockCtx('/etc/ssl/certs/');
|
|
|
|
final sock = MbedSock(ctx);
|
|
|
|
|
2022-11-08 11:24:54 +00:00
|
|
|
print('Connecting to $server:$port while indicating $hostname...');
|
2022-11-07 22:20:45 +00:00
|
|
|
final done = sock.connectSecure(
|
|
|
|
server,
|
2022-11-08 11:24:54 +00:00
|
|
|
port,
|
2022-11-07 22:20:45 +00:00
|
|
|
alpn: 'xmpp-client',
|
|
|
|
hostname: hostname,
|
|
|
|
);
|
|
|
|
|
|
|
|
print('Success? $done');
|
|
|
|
print('Secure? ${sock.isSecure()}');
|
|
|
|
|
2022-11-08 11:24:54 +00:00
|
|
|
final write = sock.write(
|
|
|
|
"<?xml version='1.0'?><stream:stream to='$hostname' version='1.0' xml:lang='en' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>"
|
|
|
|
);
|
|
|
|
print('Write: $write');
|
|
|
|
|
|
|
|
Uint8List? read = Uint8List(0);
|
|
|
|
do {
|
|
|
|
read = sock.read();
|
|
|
|
if (read != null) {
|
|
|
|
final str = utf8.decode(read);
|
|
|
|
print('Read: $str');
|
|
|
|
} else {
|
|
|
|
print('Read: Null');
|
|
|
|
}
|
|
|
|
} while (read != null);
|
|
|
|
|
2022-11-07 22:20:45 +00:00
|
|
|
sock.free();
|
|
|
|
ctx.free();
|
|
|
|
print('OKAY');
|
|
|
|
}
|