Http: HTTP package: need a way to accept bad certificates

Created on 6 Jun 2015  路  6Comments  路  Source: dart-lang/http

Issue by kaisellgren
_Originally opened as dart-lang/sdk#17173_


I'm trying to read URIs such as http://devblog.paypal.com/feed/ that lead to a bad certificate exception.

Can we add a callback to handle bad certificates in the HTTP package? For .get, .read, etc.?

Simplest reproduce step is: http.read('http://devblog.paypal.com/feed/');

type-bug

Most helpful comment

This can be done by setting the innerClient within a 'IoClient'.

import 'dart:io';
import 'package:http/http.dart' as http;

bool _certificateCheck(X509Certificate cert, String host, int port) =>
    host == 'devblog.paypal.com';

http.Client paypalClient() {
  var ioClient = new HttpClient()
      ..badCertificateCallback = _certificateCheck;

  return new http.IOClient(ioClient);
}

All 6 comments

Comment by lrhn


_Added Pkg-Http, Area-Pkg, Triaged labels._

_This comment was originally written by f41ltastic...@gmail.com_


If this was triaged, I don't see where.

Comment by sgjesse


In dart.io the HttpClient have a callback to handle bad certificates, e.g.

import 'dart:io';
import 'dart:convert';

void main(List<String> args) {
  var client = new HttpClient();
  client.badCertificateCallback = (_, __, ___) => true;
  client.getUrl(Uri.parse("http://devblog.paypal.com/feed/"))
      .then((req) => req.close())
      .then((resp) => resp.transform(UTF8.decoder).join(''))
      .then(print)
      .whenComplete(() => client.close());
}

Comment by sgjesse


Issue dart-lang/sdk#20832 has been merged into this issue.

This can be done by setting the innerClient within a 'IoClient'.

import 'dart:io';
import 'package:http/http.dart' as http;

bool _certificateCheck(X509Certificate cert, String host, int port) =>
    host == 'devblog.paypal.com';

http.Client paypalClient() {
  var ioClient = new HttpClient()
      ..badCertificateCallback = _certificateCheck;

  return new http.IOClient(ioClient);
}

update,

'new http.IOClient()' might not build, now use IOClient() or new IOClient() directly with the following import :

import 'dart:io';
import 'package:http/http.dart' as http;

import 'package:http/io_client.dart'; //has IOClient


bool _certificateCheck(X509Certificate cert, String host, int port) => true;

 http.Client paypalClient() {
   var ioClient = new HttpClient()
       ..badCertificateCallback = _certificateCheck;

   return new IOClient(ioClient);
 }
Was this page helpful?
0 / 5 - 0 ratings