Skip to content

Commit 0ca3627

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 0ca3627

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn find_certs_dirs() -> Vec<PathBuf> {
2626
/// found.
2727
///
2828
/// This will only search known system locations.
29+
#[cfg(not(target_os = "freebsd"))]
2930
pub fn candidate_cert_dirs() -> impl Iterator<Item = &'static Path> {
3031
// see http://gagravarr.org/writing/openssl-certs/others.shtml
3132
[
@@ -52,6 +53,19 @@ pub fn candidate_cert_dirs() -> impl Iterator<Item = &'static Path> {
5253
.map(Path::new)
5354
.filter(|p| p.exists())
5455
}
56+
#[cfg(target_os = "freebsd")]
57+
pub fn candidate_cert_dirs() -> impl Iterator<Item = &'static Path> {
58+
// see manpage of certctl(8): https://man.freebsd.org/cgi/man.cgi?query=certctl&sektion=8
59+
// see security/openssl* ports
60+
[
61+
"/etc/ssl",
62+
"/usr/local/etc/ssl",
63+
"/usr/local/openssl",
64+
]
65+
.iter()
66+
.map(Path::new)
67+
.filter(|p| p.exists())
68+
}
5569

5670
/// Deprecated as this isn't sound, use [`init_openssl_env_vars`] instead.
5771
#[doc(hidden)]
@@ -169,6 +183,7 @@ pub fn probe() -> ProbeResult {
169183
for certs_dir in candidate_cert_dirs() {
170184
// cert.pem looks to be an openssl 1.0.1 thing, while
171185
// certs/ca-certificates.crt appears to be a 0.9.8 thing
186+
#[cfg(not(target_os = "freebsd"))]
172187
let cert_filenames = [
173188
"cert.pem",
174189
"certs.pem",
@@ -181,6 +196,11 @@ pub fn probe() -> ProbeResult {
181196
"CARootCertificates.pem",
182197
"tls-ca-bundle.pem",
183198
];
199+
#[cfg(target_os = "freebsd")]
200+
let cert_filenames = [
201+
"cert.pem",
202+
"ca-root-nss.crt",
203+
];
184204
if result.cert_file.is_none() {
185205
result.cert_file = cert_filenames
186206
.iter()

0 commit comments

Comments
 (0)