Skip to content

Handshake Exception Handshake error in client (OS Error: Certificate Verify Failed Application Verification Failure Handshake.cc:393) #963

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
AmmarMohamed21 opened this issue Jun 15, 2023 · 4 comments
Labels
package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@AmmarMohamed21
Copy link

I have a flutter app which works well for many users Android and iOS
A single user receives this exception while sending a post request

Handshake Exception Handshake error in client (OS Error: Certificate Verify Failed Application Verification Failure Handshake.cc:393)

his device is iPad 6, iOS 14.8.1

what could be the problem?

@AmmarMohamed21 AmmarMohamed21 added package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jun 15, 2023
@hurkanugur
Copy link

hurkanugur commented Jun 20, 2023

If you use HTTPS and receive this error, you must make your HTTP client trust the server you wish to send requests.
To do this:

  1. You need to download the web certificate and put it in the assets folder
  2. Read the web certificate and set it as a trusted certificate
  3. Inject it into your HTTP client

Example Code:

// Load from assets
final ByteData certificateData = await rootBundle.load('assets/my_certificate.cer');

// Make the SecurityContext.defaultContext trust your certificate
SecurityContext.defaultContext.setTrustedCertificatesBytes(certificateData.buffer.asUint8List());

// Inject SecurityContext.defaultContext into your HTTP client
final http.Client client = http.Client();
final HttpClient httpClient = HttpClient(context: SecurityContext.defaultContext);
final http.Client clientWithHttpClient = http.Client(
  httpClient: httpClient,
);

Note that I don't use this http client (I'm using Dio package for this).
So I don't know whether the last part of the code works or not.
I hope it works for you!

@deezaster
Copy link

What happens when the certificate after expiring is refreshed? Do I have do donwload the certificate again?

@natebosch
Copy link
Member

Closing since there aren't any changes we can make in this package to impact security behavior. See comments for dart:io usable workarounds.

Questions about specific implementation patterns are best asked in places like stack overflow or the flutter discord.

@devDawata
Copy link

Any solution for this

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

No branches or pull requests

5 participants