Skip to content

Commit 2142d8e

Browse files
rmacnak-googleCommit Queue
authored andcommitted
Search in more locations for the system's root certificates.
TEST=access pub under wolfi Bug: #56734 Change-Id: Ie2033d3551966180dfdf3eff1b5ef39ac0b79ce7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388080 Reviewed-by: Brian Quinlan <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent 5fab16a commit 2142d8e

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

runtime/bin/security_context_linux.cc

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,33 @@ void SSLCertContext::TrustBuiltinRoots() {
6262
// discussion of the complexities of this endeavor can be found here:
6363
//
6464
// https://www.happyassassin.net/2015/01/12/a-note-about-ssltls-trusted-certificate-stores-and-platforms/
65-
const char* bundle = "/etc/pki/tls/certs/ca-bundle.crt";
66-
const char* cachedir = "/etc/ssl/certs";
67-
if (File::Exists(nullptr, bundle)) {
68-
LoadRootCertFile(bundle);
69-
return;
65+
//
66+
// This set of locations was copied from gRPC.
67+
const char* kCertFiles[] = {
68+
"/etc/ssl/certs/ca-certificates.crt",
69+
"/etc/pki/tls/certs/ca-bundle.crt",
70+
"/etc/ssl/ca-bundle.pem",
71+
"/etc/pki/tls/cacert.pem",
72+
"/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem",
73+
};
74+
const char* kCertDirectories[] = {
75+
"/etc/ssl/certs", "/system/etc/security/cacerts",
76+
"/usr/local/share/certs", "/etc/pki/tls/certs",
77+
"/etc/openssl/certs",
78+
};
79+
for (size_t i = 0; i < ARRAY_SIZE(kCertFiles); i++) {
80+
const char* bundle = kCertFiles[i];
81+
if (File::Exists(nullptr, bundle)) {
82+
LoadRootCertFile(bundle);
83+
return;
84+
}
7085
}
71-
72-
if (Directory::Exists(nullptr, cachedir) == Directory::EXISTS) {
73-
LoadRootCertCache(cachedir);
74-
return;
86+
for (size_t i = 0; i < ARRAY_SIZE(kCertDirectories); i++) {
87+
const char* cachedir = kCertDirectories[i];
88+
if (Directory::Exists(nullptr, cachedir) == Directory::EXISTS) {
89+
LoadRootCertCache(cachedir);
90+
return;
91+
}
7592
}
7693
#endif
7794
}

runtime/platform/globals.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,14 @@ constexpr double MicrosecondsToMilliseconds(int64_t micros) {
575575
return static_cast<double>(micros) / kMicrosecondsPerMillisecond;
576576
}
577577

578+
// The expression ARRAY_SIZE(array) is a compile-time constant of type
579+
// size_t which represents the number of elements of the given
580+
// array. You should only use ARRAY_SIZE on statically allocated
581+
// arrays.
582+
#define ARRAY_SIZE(array) \
583+
((sizeof(array) / sizeof(*(array))) / \
584+
static_cast<intptr_t>(!(sizeof(array) % sizeof(*(array))))) // NOLINT
585+
578586
// A macro to disallow the copy constructor and operator= functions.
579587
// This should be used in the private: declarations for a class.
580588
#if !defined(DISALLOW_COPY_AND_ASSIGN)

runtime/vm/globals.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,6 @@ const intptr_t kDefaultNewGenSemiMaxSize = (kWordSize <= 4) ? 8 : 16;
6565
#define kPosInfinity bit_cast<double>(DART_UINT64_C(0x7ff0000000000000))
6666
#define kNegInfinity bit_cast<double>(DART_UINT64_C(0xfff0000000000000))
6767

68-
// The expression ARRAY_SIZE(array) is a compile-time constant of type
69-
// size_t which represents the number of elements of the given
70-
// array. You should only use ARRAY_SIZE on statically allocated
71-
// arrays.
72-
#define ARRAY_SIZE(array) \
73-
((sizeof(array) / sizeof(*(array))) / \
74-
static_cast<intptr_t>(!(sizeof(array) % sizeof(*(array))))) // NOLINT
75-
7668
#if defined(PRODUCT) && defined(DEBUG)
7769
#error Both PRODUCT and DEBUG defined.
7870
#endif // defined(PRODUCT) && defined(DEBUG)

0 commit comments

Comments
 (0)