Skip to content

Commit c020650

Browse files
committed
Search only canonical paths on FreeBSD
FreeBSD contains a canonical certstore managed by certctl(8) located in the base system (/etc/ssl), search there first. Alternatively, a user can populate a custom store in distbase (/usr/local/etc/ssl) with certctl(8) which shall be queried if the former does not exist. At last, there is a store for OpenSSL from the ports (/usr/local/openssl) outside of certctl(8)'s reach. This fixes #20 and fixes #37
1 parent 4221247 commit c020650

File tree

1 file changed

+39
-21
lines changed

1 file changed

+39
-21
lines changed

src/lib.rs

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,38 @@ pub const ENV_CERT_FILE: &'static str = "SSL_CERT_FILE";
77
/// The OpenSSL environment variable to configure what certificates directory to use.
88
pub const ENV_CERT_DIR: &'static str = "SSL_CERT_DIR";
99

10+
// see http://gagravarr.org/writing/openssl-certs/others.shtml
11+
#[cfg(not(target_os = "freebsd"))]
12+
const CANDIDATE_CERT_DIRS: &'static [&'static str] = &[
13+
"/var/ssl",
14+
"/usr/share/ssl",
15+
"/usr/local/ssl",
16+
"/usr/local/openssl",
17+
"/usr/local/etc/openssl",
18+
"/usr/local/share",
19+
"/usr/lib/ssl",
20+
"/usr/ssl",
21+
"/etc/openssl",
22+
"/etc/pki/ca-trust/extracted/pem",
23+
"/etc/pki/tls",
24+
"/etc/ssl",
25+
"/etc/certs",
26+
"/opt/etc/ssl", // Entware
27+
#[cfg(target_os = "android")]
28+
"/data/data/com.termux/files/usr/etc/tls",
29+
#[cfg(target_os = "haiku")]
30+
"/boot/system/data/ssl",
31+
];
32+
33+
// see manpage of certctl(8): https://man.freebsd.org/cgi/man.cgi?query=certctl&sektion=8
34+
// see security/openssl* ports
35+
#[cfg(target_os = "freebsd")]
36+
const CANDIDATE_CERT_DIRS: &'static [&'static str] = &[
37+
"/etc/ssl",
38+
"/usr/local/etc/ssl",
39+
"/usr/local/openssl",
40+
];
41+
1042
pub struct ProbeResult {
1143
pub cert_file: Option<PathBuf>,
1244
pub cert_dir: Option<PathBuf>,
@@ -27,27 +59,7 @@ pub fn find_certs_dirs() -> Vec<PathBuf> {
2759
///
2860
/// This will only search known system locations.
2961
pub fn candidate_cert_dirs() -> impl Iterator<Item = &'static Path> {
30-
// see http://gagravarr.org/writing/openssl-certs/others.shtml
31-
[
32-
"/var/ssl",
33-
"/usr/share/ssl",
34-
"/usr/local/ssl",
35-
"/usr/local/openssl",
36-
"/usr/local/etc/openssl",
37-
"/usr/local/share",
38-
"/usr/lib/ssl",
39-
"/usr/ssl",
40-
"/etc/openssl",
41-
"/etc/pki/ca-trust/extracted/pem",
42-
"/etc/pki/tls",
43-
"/etc/ssl",
44-
"/etc/certs",
45-
"/opt/etc/ssl", // Entware
46-
#[cfg(target_os = "android")]
47-
"/data/data/com.termux/files/usr/etc/tls",
48-
#[cfg(target_os = "haiku")]
49-
"/boot/system/data/ssl",
50-
]
62+
CANDIDATE_CERT_DIRS
5163
.iter()
5264
.map(Path::new)
5365
.filter(|p| p.exists())
@@ -169,6 +181,7 @@ pub fn probe() -> ProbeResult {
169181
for certs_dir in candidate_cert_dirs() {
170182
// cert.pem looks to be an openssl 1.0.1 thing, while
171183
// certs/ca-certificates.crt appears to be a 0.9.8 thing
184+
#[cfg(not(target_os = "freebsd"))]
172185
let cert_filenames = [
173186
"cert.pem",
174187
"certs.pem",
@@ -181,6 +194,11 @@ pub fn probe() -> ProbeResult {
181194
"CARootCertificates.pem",
182195
"tls-ca-bundle.pem",
183196
];
197+
#[cfg(target_os = "freebsd")]
198+
let cert_filenames = [
199+
"cert.pem",
200+
"ca-root-nss.crt",
201+
];
184202
if result.cert_file.is_none() {
185203
result.cert_file = cert_filenames
186204
.iter()

0 commit comments

Comments
 (0)