I am trying to connect to my school's intranet. Connecting with anything else than Dart is possible (in Python, PHP, with curl -s -L "https://intra.42.fr/?format=json", and so on).

But the Dart VM considers that the TLS certificate in use in my school is bad. With this code:

# pubspec.yaml
name: handshake-fail
dependencies:
  http: any
import 'package:http/http.dart' as http;

main() { 
  var client = new http.Client();
  client.post('https://intra.42.fr/?format=json', body: {"login": "test", "password": "test"})
    .then((response) => print(response.body)
    );
}

I get the following exception:

Uncaught Error: HandshakeException: Handshake error in client (OS Error: Peer's Certificate issuer is not recognized., errno = -8179)
Unhandled exception:
HandshakeException: Handshake error in client (OS Error: Peer's Certificate issuer is not recognized., errno = -8179)
#0      _rootHandleUncaughtError.<anonymous closure>.<anonymous closure> (dart:async/zone.dart:700)
#1      _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:23)
#2      _asyncRunCallback (dart:async/schedule_microtask.dart:32)
#3      _asyncRunCallback (dart:async/schedule_microtask.dart:36)
#4      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:119)

The question Bypass Certificate Error Using Http points to a bug report that suggests:

Optional parameters to [SecureSocket].initialize let you specify a certificate database (a directory containing cert9.db and key4.db), and whether or not to use the builtin well-known authorities.

My question is, how to do that?

有帮助吗?

解决方案

I think you are looking for this

var cl = new HttpClient();
cl.badCertificateCallback = () => print(x);

dartdoc of badCertificateCallback

* Sets a callback that will decide whether to accept a secure connection
* with a server certificate that cannot be authenticated by any of our
* trusted root certificates.
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top