Skip to content

Commit

Permalink
add letsencrypt root certificate for versions prior to android 7.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewwahid committed Jul 3, 2023
1 parent 03911f0 commit fa1b34c
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 26 deletions.
33 changes: 33 additions & 0 deletions assets/ca/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Android versions prior to 7.1.1 don't have Let's encrypt (LE) root certificate in the OS' system ca-certificates.

Because many 3rd party services use LE's SSL certificates, we need to add LE's ISRG Root X1 to the set of trusted X509 certificates.

```dart
Future<void> _addLERootCertificate() async {
if (Platform.isAndroid){
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
// if android version is prior to 7.1.1
if (androidInfo.version.sdkInt <= 25){
try {
var isrgX1 = await rootBundle.loadString('assets/ca/isrgrootx1.pem');
SecurityContext.defaultContext.setTrustedCertificatesBytes(ascii.encode(isrgX1));
} catch (e) {/* ignore errors */}
}
}
}
```

You can find the certificate in `"assets/ca/isrgrootx1.pem"`

You can verify the certificate from\
https://letsencrypt.org/certificates/

You can also verify that this exact certificate was added to Android's system ca-certificates for versions >= 7.1.1\
https://android.googlesource.com/platform/system/ca-certificates/+/51300a813051dcaaf3dc07000e92ed40a27a2b21/files/6187b673.0

You can read more about this issue:
1. https://letsencrypt.org/2020/11/06/own-two-feet.html#if-you-are-an-app-developer
2. https://community.letsencrypt.org/t/mobile-client-workarounds-for-isrg-issue/137807
3. https://github.com/square/okhttp/issues/6403
4. https://stackoverflow.com/questions/69511057/flutter-on-android-7-certificate-verify-failed-with-letsencrypt-ssl-cert-after-s
31 changes: 31 additions & 0 deletions assets/ca/isrgrootx1.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-----BEGIN CERTIFICATE-----
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
TzELMAkGA1UEBhM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bl5AFzgAiIyBpY9umbbjANBgkq
hkiG9w0BAQsFAAOCAgEAVR9YqbyyqFDQDLHYGmkgJykIrGF1XIpu+ILlaS/V9lZL
ubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ
3BebYhtF8GaV0nxvwuo77x/Py9auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KK
NFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5
ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur
TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC
jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
-----END CERTIFICATE-----
23 changes: 23 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
import 'dart:convert';
import 'dart:io';

import 'package:bot_toast/bot_toast.dart';
import 'package:candide_mobile_app/config/env.dart';
import 'package:candide_mobile_app/config/theme.dart';
import 'package:candide_mobile_app/screens/home/components/magic_relayer_widget.dart';
import 'package:candide_mobile_app/screens/splashscreen.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:hive_flutter/hive_flutter.dart';

// Please read assets/ca/README.md
Future<void> _addLERootCertificate() async {
if (Platform.isAndroid){
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
// if android version is prior to 7.1.1
if (androidInfo.version.sdkInt <= 25){
try {
var isrgX1 = await rootBundle.loadString('assets/ca/isrgrootx1.pem');
SecurityContext.defaultContext.setTrustedCertificatesBytes(ascii.encode(isrgX1));
} catch (e) {/* ignore errors */}
}
}
}

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await _addLERootCertificate();
//
await Env.initialize();
await Hive.initFlutter();
runApp(const CandideApp());
Expand Down
72 changes: 48 additions & 24 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ packages:
dependency: transitive
description:
name: archive
sha256: d6347d54a2d8028e0437e3c099f66fdb8ae02c4720c1e7534c9f24c10351f85d
sha256: "0c8368c9b3f0abbc193b9d6133649a614204b528982bebc7026372d61677ce3a"
url: "https://pub.dev"
source: hosted
version: "3.3.6"
version: "3.3.7"
args:
dependency: transitive
description:
Expand All @@ -53,10 +53,10 @@ packages:
dependency: "direct main"
description:
name: biometric_storage
sha256: f6d7f5f4c28323797658423e4c5982c9dee42e18f59a8a8d4bc5df38eaf2e2f1
sha256: "97d28f1f87fd6cb42a657086ed570279985e0a26ba68f2952771e6bee8e9e9c4"
url: "https://pub.dev"
source: hosted
version: "4.1.3"
version: "5.0.0"
blockchain_signer:
dependency: transitive
description:
Expand Down Expand Up @@ -201,6 +201,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.3.2"
device_info_plus:
dependency: "direct main"
description:
name: device_info_plus
sha256: "2c35b6d1682b028e42d07b3aee4b98fa62996c10bc12cb651ec856a80d6a761b"
url: "https://pub.dev"
source: hosted
version: "9.0.2"
device_info_plus_platform_interface:
dependency: transitive
description:
name: device_info_plus_platform_interface
sha256: d3b01d5868b50ae571cd1dc6e502fc94d956b665756180f7b16ead09e836fd64
url: "https://pub.dev"
source: hosted
version: "7.0.0"
dio:
dependency: "direct main"
description:
Expand Down Expand Up @@ -524,10 +540,10 @@ packages:
dependency: "direct main"
description:
name: logger
sha256: "5076f09225f91dc49289a4ccb92df2eeea9ea01cf7c26d49b3a1f04c6a49eec1"
sha256: "7ad7215c15420a102ec687bb320a7312afd449bac63bfb1c60d9787c27b9767f"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
version: "1.4.0"
logging:
dependency: transitive
description:
Expand Down Expand Up @@ -612,10 +628,10 @@ packages:
dependency: "direct main"
description:
name: package_info_plus
sha256: f619162573096d428ccde2e33f92e05b5a179cd6f0e3120c1005f181bee8ed16
sha256: "10259b111176fba5c505b102e3a5b022b51dd97e30522e906d6922c745584745"
url: "https://pub.dev"
source: hosted
version: "3.0.2"
version: "3.1.2"
package_info_plus_platform_interface:
dependency: transitive
description:
Expand Down Expand Up @@ -692,10 +708,10 @@ packages:
dependency: transitive
description:
name: path_provider_windows
sha256: bcabbe399d4042b8ee687e17548d5d3f527255253b4a639f5f8d2094a9c2b45c
sha256: "1cb68ba4cd3a795033de62ba1b7b4564dace301f952de6bfb3cd91b202b6ee96"
url: "https://pub.dev"
source: hosted
version: "2.1.3"
version: "2.1.7"
pausable_timer:
dependency: "direct main"
description:
Expand Down Expand Up @@ -884,18 +900,18 @@ packages:
dependency: "direct main"
description:
name: share_plus
sha256: e387077716f80609bb979cd199331033326033ecd1c8f200a90c5f57b1c9f55e
sha256: ed3fcea4f789ed95913328e629c0c53e69e80e08b6c24542f1b3576046c614e8
url: "https://pub.dev"
source: hosted
version: "6.3.0"
version: "7.0.2"
share_plus_platform_interface:
dependency: transitive
description:
name: share_plus_platform_interface
sha256: "82ddd4ab9260c295e6e39612d4ff00390b9a7a21f1bb1da771e2f232d80ab8a1"
sha256: "0c6e61471bd71b04a138b8b588fa388e66d8b005e6f2deda63371c5c505a0981"
url: "https://pub.dev"
source: hosted
version: "3.2.0"
version: "3.2.1"
short_uuids:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1049,10 +1065,10 @@ packages:
dependency: transitive
description:
name: url_launcher_linux
sha256: "318c42cba924e18180c029be69caf0a1a710191b9ec49bb42b5998fdcccee3cc"
sha256: "207f4ddda99b95b4d4868320a352d374b0b7e05eefad95a4a26f57da413443f5"
url: "https://pub.dev"
source: hosted
version: "3.0.2"
version: "3.0.5"
url_launcher_macos:
dependency: transitive
description:
Expand All @@ -1065,26 +1081,26 @@ packages:
dependency: transitive
description:
name: url_launcher_platform_interface
sha256: "4eae912628763eb48fc214522e58e942fd16ce195407dbf45638239523c759a6"
sha256: bfdfa402f1f3298637d71ca8ecfe840b4696698213d5346e9d12d4ab647ee2ea
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.3"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
sha256: "44d79408ce9f07052095ef1f9a693c258d6373dc3944249374e30eff7219ccb0"
sha256: "6bb1e5d7fe53daf02a8fee85352432a40b1f868a81880e99ec7440113d5cfcab"
url: "https://pub.dev"
source: hosted
version: "2.0.14"
version: "2.0.17"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
sha256: b6217370f8eb1fd85c8890c539f5a639a01ab209a36db82c921ebeacefc7a615
sha256: "254708f17f7c20a9c8c471f67d86d76d4a3f9c1591aad1e15292008aceb82771"
url: "https://pub.dev"
source: hosted
version: "3.0.3"
version: "3.0.6"
uuid:
dependency: transitive
description:
Expand Down Expand Up @@ -1178,10 +1194,18 @@ packages:
dependency: transitive
description:
name: win32
sha256: c9ebe7ee4ab0c2194e65d3a07d8c54c5d00bb001b76081c4a04cdb8448b59e46
sha256: "5a751eddf9db89b3e5f9d50c20ab8612296e4e8db69009788d6c8b060a84191c"
url: "https://pub.dev"
source: hosted
version: "3.1.3"
version: "4.1.4"
win32_registry:
dependency: transitive
description:
name: win32_registry
sha256: "1c52f994bdccb77103a6231ad4ea331a244dbcef5d1f37d8462f713143b0bfae"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
xdg_directories:
dependency: transitive
description:
Expand Down
6 changes: 4 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencies:
eth_sig_util: ^0.0.9
walletconnect_dart: ^0.0.11
# Auth
biometric_storage: ^4.1.3
biometric_storage: ^5.0.0
# State
get: ^4.6.5
event_bus: ^2.0.0
Expand Down Expand Up @@ -72,7 +72,7 @@ dependencies:
decimal: ^2.3.2
url_launcher: ^6.1.5
flutter_dotenv: ^5.0.2
share_plus: ^6.2.0
share_plus: ^7.0.2
qr_code_scanner: ^1.0.0
intl: ^0.17.0
logger: ^1.1.0
Expand All @@ -82,6 +82,7 @@ dependencies:
flutter_cache_manager: ^3.3.0
permission_handler: ^10.2.0
version: ^3.0.0
device_info_plus: ^9.0.2
#
flutter:
sdk: flutter
Expand Down Expand Up @@ -118,6 +119,7 @@ flutter:
- assets/images/
- assets/animations/
- .env
- assets/ca/isrgrootx1.pem

fonts:
- family: Gilroy
Expand Down

0 comments on commit fa1b34c

Please sign in to comment.