Certificate Bypass Error Using Http

I am trying to create a proxy server that accesses a third-party API, but their development endpoint has a certificate error. Is there any way around the ssl error when using http.dart?

import 'package:http/http.dart' as http; Uri url = Uri.parse("https://url-with-ssl-error.com/endpoint"); http.get(url).then((response) => print(response.body)); 

and an error is returned here:

 Uncaught Error: SocketIOException: RawSecureSocket error (Unexpected handshake error in client) (OS Error: errno = -8172) Unhandled exception: SocketIOException: RawSecureSocket error (Unexpected handshake error in client) (OS Error: errno = -8172) #0 _FutureImpl._scheduleUnhandledError.<anonymous closure> (dart:async/future_impl.dart:207:9) #1 Timer.run.<anonymous closure> (dart:async/timer.dart:17:21) #2 Timer.run.<anonymous closure> (dart:async/timer.dart:25:13) #3 Timer.Timer.<anonymous closure> (dart:async-patch:15:15) #4 _Timer._createTimerHandler._handleTimeout (dart:io:6990:28) #5 _Timer._createTimerHandler._handleTimeout (dart:io:6998:7) #6 _Timer._createTimerHandler.<anonymous closure> (dart:io:7006:23) #7 _ReceivePortImpl._handleMessage (dart:isolate-patch:81:92) 
+4
source share
1 answer

The error -8172 means that "The recipient of the peer certificates was marked as not trusted by the user."

If you had access to raw sockets, then the connect method allows you to specify what to do in case of a bad certificate by providing an onBadCertificate callback. However, I'm not sure what the exact type of the http object is in your code example, so I can't tell if you can get around this or not. I thought it might be an HttpClient instance, but it does not have a get method that accepts a URI, so I'm not sure. If this is your own class, you probably have access to the underlying secure socket, so you can use onBadCertificate .

Also, for server sockets, you cannot rely on an implicit call to SecureSocket.initialize() . You need to call it explicitly with the db certificate information .

0
source

Source: https://habr.com/ru/post/1480504/


All Articles