Skip to content

HTTP package: need a way to accept bad certificates #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DartBot opened this issue Jun 5, 2015 · 10 comments
Closed

HTTP package: need a way to accept bad certificates #14

DartBot opened this issue Jun 5, 2015 · 10 comments
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@DartBot
Copy link

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/148256?v=3" align="left" width="96" height="96"hspace="10"> 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/');

@DartBot DartBot added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Jun 5, 2015
@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/4865287?v=3" align="left" width="48" height="48"hspace="10"> Comment by lrhn


Added Pkg-Http, Area-Pkg, Triaged labels.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

This comment was originally written by [email protected]


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

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/1343914?v=3" align="left" width="48" height="48"hspace="10"> 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());
}

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/1343914?v=3" align="left" width="48" height="48"hspace="10"> Comment by sgjesse


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

@donny-dont
Copy link

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);
}

@gsynuh
Copy link

gsynuh commented Jul 22, 2020

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);
 }

@micheltonon
Copy link

it always returns the called host even with a bad certificate. :(

@vasilich6107
Copy link

all this solutions is not valid for web(

@nassimus26
Copy link

Hi what's the solution for the web please ?

@WolfCrazy
Copy link

WolfCrazy commented Aug 15, 2024

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);
 }

Hi!
Thanks!
Good job.

final http.Client client = IOClient(HttpClient()
                                 ..badCertificateCallback = (X509Certificate cert, String host, int port) => true);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

8 participants