]>
git.proxmox.com Git - proxmox-perl-rs.git/blob - common/pkg/Proxmox/Lib/SslProbe.pm
e6de8904e83e34cb6492cfaccd2cc135cad523d9
1 package Proxmox
::Lib
::SslProbe
;
6 =head1 Environment Variable Safety
8 Perl's handling of environment variables was completely messed up until v5.38.
9 Using `setenv` such as use din the `openssl-probe` crate would cause it to
10 crash later on, therefore we provide a perl-version of env var probing instead,
11 and override the crate with one that doesn't replace the variables if they are
12 already set correctly.
17 # Copied from openssl-probe
23 "/usr/local/etc/openssl",
28 "/etc/pki/ca-trust/extracted/pem",
33 "/data/data/com.termux/files/usr/etc/tls",
34 "/boot/system/data/ssl",
37 # Copied from openssl-probe
38 my @cert_file_names = (
43 "ca-certificates.crt",
44 "certs/ca-certificates.crt",
45 "certs/ca-root-nss.crt",
46 "certs/ca-bundle.crt",
47 "CARootCertificates.pem",
51 my $probed_ssl_vars = 0;
53 # The algorithm here is taken from the `openssl-probe` crate and should
54 # produce the exact same result in order to ensure the rust code does not
56 my sub probe_ssl_vars
: prototype() {
57 return if $probed_ssl_vars;
60 my $result_file = $ENV{SSL_CERT_FILE
};
61 my $result_file_changed = 0;
62 my $result_dir = $ENV{SSL_CERT_DIR
};
63 my $result_dir_changed = 0;
65 for my $certs_dir (@cert_dirs) {
66 if (!defined($result_file)) {
67 for my $file (@cert_file_names) {
68 my $path = "$certs_dir/$file";
71 $result_file_changed = 1;
76 if (!defined($result_dir)) {
77 for my $file (@cert_file_names) {
78 my $path = "$certs_dir/certs";
81 $result_dir_changed = 1;
86 last if defined($result_file) && defined($result_dir);
89 if ($result_file_changed && defined($result_file)) {
90 $ENV{SSL_CERT_FILE
} = $result_file;
92 if ($result_dir_changed && defined($result_dir)) {
93 $ENV{SSL_CERT_DIR
} = $result_dir;