Skip to content
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

CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:354)) #956

Closed
s2yed opened this issue Oct 7, 2020 · 8 comments

Comments

@s2yed
Copy link

s2yed commented Oct 7, 2020

82): ╔╣ DioError ║ DioErrorType.DEFAULT
I/flutter ( 8182): ║ HandshakeException: Handshake error in client (OS Error:
I/flutter ( 8182): CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:354))
I/flutter ( 8182): ╚══════════════════════════════════════════════════════════════════════════════════════════
E/flutter ( 8182): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: DioError [DioErrorType.DEFAULT]: HandshakeException: Handshake error in client (OS Error:
E/flutter ( 8182): CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:354))
E/flutter ( 8182): #0 DioMixin._request._errorInterceptorWrapper... (package:dio/src/dio.dart:870:17)
E/flutter ( 8182): #1 _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter ( 8182): #2 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 8182): #3 _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
E/flutter ( 8182): #4 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
E/flutter ( 8182): #5 Future._propagateToListeners (dart:async/future_impl.dart:725:32)
E/flutter ( 8182): #6 Future._completeWithValue (dart:async/future_impl.dart:529:5)
E/flutter ( 8182): #7 Future._asyncCompleteWithValue. (dart:async/future_impl.dart:567:7)
E/flutter ( 8182): #8 _rootRun (dart:async/zone.dart:1190:13)
E/flutter ( 8182): #9 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter ( 8182): #10 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter ( 8182): #11 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1037:23)
E/flutter ( 8182): #12 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter ( 8182): #13 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
E/flutter ( 8182):

@stale
Copy link

stale bot commented Nov 7, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

@stale stale bot added the stale label Nov 7, 2020
@stale stale bot closed this as completed Nov 16, 2020
@Phat0M
Copy link

Phat0M commented Dec 15, 2020

This problem still actual

@putheng
Copy link

putheng commented Jan 1, 2021

Me too
DioError [DioErrorType.DEFAULT]: HandshakeException: Handshake error in client (OS Error:
I/flutter (11588): CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:354))

@gmeles
Copy link

gmeles commented Feb 1, 2021

For me the problem solved on the server side (as it should be) with no change in the code. Everything is valid now. The configuration is Centos/Apache/LetEncrypt/Python3.8/Django3.1.5/Mod_wsgi/ but I guess that the solution is valid for most installations of Apache/LetEncrypt

The steps to resolve are

Locate the line "SSLCACertificateFile" on the Virtual Host you wish to config. For example:
SSLCACertificateFile /etc/httpd/conf/ssl.crt/my_ca.crt

Download https://letsencrypt.org/certs/lets-encrypt-r3-cross-signed.txt At the end of /etc/httpd/conf/ssl.crt/my_ca.crt (after the -----END CERTIFICATE-----) start a new line and paste from lets-encrypt-r3-cross-signed.txt everything bellow -----BEGIN CERTIFICATE----- (including -----BEGIN CERTIFICATE-----)
Save /etc/httpd/conf/ssl.crt/my_ca.crt
Restart Apache httpd
References: https://access.redhat.com/solutions/43575 https://letsencrypt.org/certs

Also you can check the validity of your cert in https://www.digicert.com/help/.

@hipoojan
Copy link

I found the cause for this (at least for my situation) whenever I change device Date and Time to more than 5 months ahead of the actual Date and Time this happens, seems weird.

@gmeles
Copy link

gmeles commented Mar 19, 2021

I found the cause for this (at least for my situation) whenever I change device Date and Time to more than 5 months ahead of the actual Date and Time this happens, seems weird.

Not weird. If you change date, ssl fails to evaluate. It suppose counterfeit

@saytoonz
Copy link

saytoonz commented Jan 26, 2022

#956

  • Download cert from https://letsencrypt.org/certs/lets-encrypt-r3.pem
  • Add this file to assets/ca/ Flutter project root directory
  • Add assets/ca/ assets directory in pubspec.yaml
  • Add this code on your app initialization inside the lib/main.dart file:

class MyHttpoverrides extends HttpOverrides {
@OverRide
HttpClient createHttpClient(SecurityContext? context) {
return super.createHttpClient(context)
..badCertificateCallback =
(X509Certificate cert, String host, int port) => true;
}
}

void main() async {
WidgetsFlutterBinding.ensureInitialized();

HttpOverrides.global = MyHttpoverrides();
ByteData data = await PlatformAssetBundle().load('assets/ca/lets-encrypt-r3.pem');
SecurityContext.defaultContext.setTrustedCertificatesBytes(data.buffer.asUint8List());

runApp(MyApp());
}

guchengxi1994 added a commit to guchengxi1994/a-cool-app that referenced this issue Apr 6, 2022
@mmgarrido
Copy link

mmgarrido commented Jul 1, 2022

I got this issue while trying to post to a rest endpoint. The error occurs only when running the app on Android simulator.
It works and does not give error when running the app on iOS simulator.

    try {
      final Map<String, dynamic> headers = {'Accept': 'application/json', 'ContentType': 'application/json'};

      final response = await dio.post(url, data: userForm.toJson(), options: Options(headers: headers));

      if (response.data['success']) {
        final Map<String, dynamic> content = response.data['content'];
        final employee = Employee.fromMap(content);

        return employee;
      } else {
        throw ApplicationException.fromHk(response.data['errorMessage']);
      }
    } on DioError catch (dioError) {
      throw ApplicationException.fromDioError(dioError);
    }

Below are the error info and stacktrace:

dioError:
   [DioErrorType.other]:
   type: HandshakeException
   message: Handshake error in client
   osError (OS Error) CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:393)
   errorCode -1
   stacktrace:
        DioMixin.fetch (package:dio/src/dio_mixin.dart:488:35)
#1      DioMixin.request (package:dio/src/dio_mixin.dart:483:12)
#2      DioMixin.post (package:dio/src/dio_mixin.dart:97:12)
#3      LoginService.retrieve (package:sample_app/services/login_service.dart:43:34)
#4      _LoginPageState.buildLoginButton.<anonymous closure> (package:sample_app/pages/login_page.dart:200:43)
#5      _LoginPageState.buildLoginButton.<anonymous closure> (package:sample_app/pages/login_page.dart:194:18)
#6      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:1005:21)
#7      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:198:24)
#8      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:613:11)
#9      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:298:5)
#10     BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:269:7)
#11     GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:157:27)
#12     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:449:20)
#13     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:425:22)
#14     RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:329:11)
#15     GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:380:7)
#16     GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:344:5)
#17     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:302:7)
#18     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:285:7)
#19     _rootRunUnary (dart:async/zone.dart:1442:13)
#20     _CustomZone.runUnary (dart:async/zone.dart:1335:19)
#21     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
#22     _invoke1 (dart:ui/hooks.dart:170:10)
#23     PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:331:7)
#24     _dispatchPointerDataPacket (dart:ui/hooks.dart:94:31)

I am using Dio v4.0.4
Flutter Doctor output

Flutter (Channel stable, 3.0.3, on macOS 12.4 21F79 darwin-x64, locale en-PH)
Android toolchain - develop for Android devices (Android SDK version 31.0.0)
Xcode - develop for iOS and macOS (Xcode 13.4.1)
Chrome - develop for the web
Android Studio (version 2021.2)
IntelliJ IDEA Community Edition (version 2021.1.1)
VS Code (version 1.68.1)
Connected device (3 available)
HTTP Host Availability

UPDATE:
The #956 fix cited above solved my problem. I only needed to change lets-encrypt-r3.pem to lets-encrypt-r3.cer since the latter is name of the file downloaded from the link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants