Reputation: 29
The server works correctly, tested with an echo client.
Altough when I run my app with:
final channel = IOWebSocketChannel.connect("wss://hostname:port");
channel.sink.add('test');
channel.stream.listen((message) {
debugPrint(message);
channel.sink.close(status.goingAway);
The debug console exceptions with this recurring message:
E/flutter (19705): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: WebSocketChannelException: WebSocketChannelException: HandshakeException: Handshake error in client (OS Error:
E/flutter (19705): CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:354))
I tried in many ways make my flutter app trust the Let`s Encrypt CA with no success.
Any response towards resolving my issue will be much appreciated!
Upvotes: 2
Views: 3028
Reputation: 1102
class MyHttpOverrides extends HttpOverrides {
@override
HttpClient createHttpClient(SecurityContext context) {
return super.createHttpClient(context)
..badCertificateCallback =
(X509Certificate cert, String host, int port) => true;
}
}
void main() {
HttpOverrides.global = new MyHttpOverrides();
runApp(MyApp());
}
Upvotes: 2
Reputation: 29
OK, i fixed it a week ago and forgot to post the answer. It's more of a workaround but it's stable nevertheless... I used an apache2 webserver that uses a reverse proxy to the websocket server. Now the apache server has the certificate in place and I used s_client on openssl to check whether the browser/client accepts the certificate, it did after I used apache2 as a reverse proxy.
Upvotes: 0