| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 18ceefb commit d74799d
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -812,6 +812,23 @@ static std::vector<X509*>& GetSystemStoreCACertificates() { | |||
| 812 | 812 | return system_store_certs; | |
| 813 | 813 | } | |
| 814 | 814 | ||
| 815 | + static void LoadSystemCACertificates(void* data) { | ||
| 816 | + GetSystemStoreCACertificates(); | ||
| 817 | + } | ||
| 818 | + | ||
| 819 | + static uv_thread_t system_ca_thread; | ||
| 820 | + static bool system_ca_thread_started = false; | ||
| 821 | + int LoadSystemCACertificatesOffThread() { | ||
| 822 | + // This is only run once during the initialization of the process, so | ||
| 823 | + // it is safe to use a static thread here. | ||
| 824 | + int r = | ||
| 825 | + uv_thread_create(&system_ca_thread, LoadSystemCACertificates, nullptr); | ||
| 826 | + if (r == 0) { | ||
| 827 | + system_ca_thread_started = true; | ||
| 828 | + } | ||
| 829 | + return r; | ||
| 830 | + } | ||
| 831 | + | ||
| 815 | 832 | static std::vector<X509*> InitializeExtraCACertificates() { | |
| 816 | 833 | std::vector<X509*> extra_certs; | |
| 817 | 834 | unsigned long err = LoadCertsFromFile( // NOLINT(runtime/int) | |
@@ -923,6 +940,10 @@ void CleanupCachedRootCertificates() { | |||
| 923 | 940 | X509_free(cert); | |
| 924 | 941 | } | |
| 925 | 942 | } | |
| 943 | + if (system_ca_thread_started) { | ||
| 944 | + uv_thread_join(&system_ca_thread); | ||
| 945 | + system_ca_thread_started = false; | ||
| 946 | + } | ||
| 926 | 947 | } | |
| 927 | 948 | ||
| 928 | 949 | void GetBundledRootCertificates(const FunctionCallbackInfo<Value>& args) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,6 +62,7 @@ void InitCryptoOnce(); | |||
| 62 | 62 | void InitCrypto(v8::Local<v8::Object> target); | |
| 63 | 63 | ||
| 64 | 64 | extern void UseExtraCaCerts(const std::string& file); | |
| 65 | + extern int LoadSystemCACertificatesOffThread(); | ||
| 65 | 66 | void CleanupCachedRootCertificates(); | |
| 66 | 67 | ||
| 67 | 68 | int PasswordCallback(char* buf, int size, int rwflag, void* u); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1245,6 +1245,20 @@ InitializeOncePerProcessInternal(const std::vector<std::string>& args, | |||
| 1245 | 1245 | return result; | |
| 1246 | 1246 | } | |
| 1247 | 1247 | ||
| 1248 | + if (per_process::cli_options->use_system_ca) { | ||
| 1249 | + // Load the system CA certificates eagerly off the main thread to avoid | ||
| 1250 | + // blocking the main thread when the first TLS connection is made. We | ||
| 1251 | + // don't need to wait for the thread to finish with code here, as | ||
| 1252 | + // GetSystemStoreCACertificates() has a function-local static and any | ||
| 1253 | + // actual user of it will wait for that to complete initialization. | ||
| 1254 | + int r = crypto::LoadSystemCACertificatesOffThread(); | ||
| 1255 | + if (r != 0) { | ||
| 1256 | + FPrintF( | ||
| 1257 | + stderr, | ||
| 1258 | + "Warning: Failed to load system CA certificates off thread: %s\n", | ||
| 1259 | + uv_strerror(r)); | ||
| 1260 | + } | ||
| 1261 | + } | ||
| 1248 | 1262 | // Ensure CSPRNG is properly seeded. | |
| 1249 | 1263 | CHECK(ncrypto::CSPRNG(nullptr, 0)); | |
| 1250 | 1264 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments