Skip to content

Commit e5da282

Browse files
committed
Extract consts for file and directory lists
1 parent 7ad6f4d commit e5da282

File tree

1 file changed

+42
-39
lines changed

1 file changed

+42
-39
lines changed

src/lib.rs

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,8 @@ pub unsafe fn try_init_openssl_env_vars() -> bool {
6060
pub fn probe() -> ProbeResult {
6161
let mut result = ProbeResult::from_env();
6262
for certs_dir in candidate_cert_dirs() {
63-
// cert.pem looks to be an openssl 1.0.1 thing, while
64-
// certs/ca-certificates.crt appears to be a 0.9.8 thing
65-
let cert_filenames = [
66-
"cert.pem",
67-
"certs.pem",
68-
"ca-bundle.pem",
69-
"cacert.pem",
70-
"ca-certificates.crt",
71-
"certs/ca-certificates.crt",
72-
"certs/ca-root-nss.crt",
73-
"certs/ca-bundle.crt",
74-
"CARootCertificates.pem",
75-
"tls-ca-bundle.pem",
76-
];
7763
if result.cert_file.is_none() {
78-
result.cert_file = cert_filenames
64+
result.cert_file = CERTIFICATE_FILE_NAMES
7965
.iter()
8066
.map(|fname| certs_dir.join(fname))
8167
.find(|p| p.exists());
@@ -98,30 +84,10 @@ pub fn probe() -> ProbeResult {
9884
///
9985
/// This will only search known system locations.
10086
pub fn candidate_cert_dirs() -> impl Iterator<Item = &'static Path> {
101-
// see http://gagravarr.org/writing/openssl-certs/others.shtml
102-
[
103-
"/var/ssl",
104-
"/usr/share/ssl",
105-
"/usr/local/ssl",
106-
"/usr/local/openssl",
107-
"/usr/local/etc/openssl",
108-
"/usr/local/share",
109-
"/usr/lib/ssl",
110-
"/usr/ssl",
111-
"/etc/openssl",
112-
"/etc/pki/ca-trust/extracted/pem",
113-
"/etc/pki/tls",
114-
"/etc/ssl",
115-
"/etc/certs",
116-
"/opt/etc/ssl", // Entware
117-
#[cfg(target_os = "android")]
118-
"/data/data/com.termux/files/usr/etc/tls",
119-
#[cfg(target_os = "haiku")]
120-
"/boot/system/data/ssl",
121-
]
122-
.iter()
123-
.map(Path::new)
124-
.filter(|p| p.exists())
87+
CERTIFICATE_DIRS
88+
.iter()
89+
.map(Path::new)
90+
.filter(|p| p.exists())
12591
}
12692

12793
/// Check whether the OpenSSL `SSL_CERT_FILE` and/or `SSL_CERT_DIR` environment variable is
@@ -150,6 +116,43 @@ impl ProbeResult {
150116
}
151117
}
152118

119+
// see http://gagravarr.org/writing/openssl-certs/others.shtml
120+
const CERTIFICATE_DIRS: &[&str] = &[
121+
"/var/ssl",
122+
"/usr/share/ssl",
123+
"/usr/local/ssl",
124+
"/usr/local/openssl",
125+
"/usr/local/etc/openssl",
126+
"/usr/local/share",
127+
"/usr/lib/ssl",
128+
"/usr/ssl",
129+
"/etc/openssl",
130+
"/etc/pki/ca-trust/extracted/pem",
131+
"/etc/pki/tls",
132+
"/etc/ssl",
133+
"/etc/certs",
134+
"/opt/etc/ssl", // Entware
135+
#[cfg(target_os = "android")]
136+
"/data/data/com.termux/files/usr/etc/tls",
137+
#[cfg(target_os = "haiku")]
138+
"/boot/system/data/ssl",
139+
];
140+
141+
// cert.pem looks to be an openssl 1.0.1 thing, while
142+
// certs/ca-certificates.crt appears to be a 0.9.8 thing
143+
const CERTIFICATE_FILE_NAMES: &[&str] = &[
144+
"cert.pem",
145+
"certs.pem",
146+
"ca-bundle.pem",
147+
"cacert.pem",
148+
"ca-certificates.crt",
149+
"certs/ca-certificates.crt",
150+
"certs/ca-root-nss.crt",
151+
"certs/ca-bundle.crt",
152+
"CARootCertificates.pem",
153+
"tls-ca-bundle.pem",
154+
];
155+
153156
/// The OpenSSL environment variable to configure what certificate file to use.
154157
pub const ENV_CERT_FILE: &'static str = "SSL_CERT_FILE";
155158

0 commit comments

Comments
 (0)