From 581ceae70d3e3a768cb45e24a55ab87a3c7ca546 Mon Sep 17 00:00:00 2001 From: Nikola Irinchev Date: Fri, 10 Nov 2023 09:57:28 +0100 Subject: [PATCH] Handle duplicate certificates (#1425) --- lib/src/app.dart | 15 ++++++++++++--- topic.md | 0 2 files changed, 12 insertions(+), 3 deletions(-) delete mode 100644 topic.md diff --git a/lib/src/app.dart b/lib/src/app.dart index 4116c1c34..90d499f32 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -64,9 +64,18 @@ he8Y4IWS6wY7bCkjCWDcRQJMEhg76fsO3txE+FiYruq9RUWhiF1myv4Q6W+CyBFC Dfvp7OOGAN6dEOM4+qR9sdjoSYKEBpsr6GtPAQw4dy753ec5 -----END CERTIFICATE-----'''; - final context = SecurityContext(withTrustedRoots: true); - context.setTrustedCertificatesBytes(const AsciiEncoder().convert(isrgRootX1CertPEM)); - return HttpClient(context: context); + try { + final context = SecurityContext(withTrustedRoots: true); + context.setTrustedCertificatesBytes(const AsciiEncoder().convert(isrgRootX1CertPEM)); + return HttpClient(context: context); + } on TlsException catch (e) { + if (e.osError?.message.contains("CERT_ALREADY_IN_HASH_TABLE") == true) { + // certificate is already trusted. Nothing to do here + return HttpClient(); + } else { + rethrow; + } + } }(); /// A class exposing configuration options for an [App] diff --git a/topic.md b/topic.md deleted file mode 100644 index e69de29bb..000000000