|
8 | 8 | #include "mamba/core/invoke.hpp" |
9 | 9 | #include "mamba/core/thread_utils.hpp" |
10 | 10 | #include "mamba/core/util.hpp" |
| 11 | +#include "mamba/core/util_os.hpp" |
11 | 12 | #include "mamba/core/util_scope.hpp" |
12 | 13 | #include "mamba/download/downloader.hpp" |
13 | 14 | #include "mamba/util/build.hpp" |
@@ -84,23 +85,60 @@ namespace mamba::download |
84 | 85 | // from `conda-forge::ca-certificates` and the system CA certificates. |
85 | 86 | else if (remote_fetch_params.ssl_verify == "<system>") |
86 | 87 | { |
87 | | - // Use the CA certificates from `conda-forge::ca-certificates` installed in the |
88 | | - // root prefix or the system CA certificates if the certificate is not present. |
89 | | - fs::u8path root_prefix = detail::get_root_prefix(); |
90 | | - fs::u8path env_prefix_conda_cert = root_prefix / "ssl" / "cacert.pem"; |
91 | | - |
92 | | - LOG_INFO << "Checking for CA certificates at the root prefix: " |
| 88 | + // See the location of the CA certificates as distributed by |
| 89 | + // `conda-forge::ca-certificates`: |
| 90 | + // https://github.com/conda-forge/ca-certificates-feedstock/blob/main/recipe/meta.yaml#L25-L29 |
| 91 | + const fs::u8path prefix_relative_conda_cert_path = (util::on_win ? fs::u8path("Library") / "ssl" / "cacert.pem" : fs::u8path("ssl") / "cert.pem"); |
| 92 | + |
| 93 | + const fs::u8path executable_path = get_self_exe_path(); |
| 94 | + |
| 95 | + // Find the environment prefix using the path of the `mamba` or `micromamba` |
| 96 | + // executable (we cannot assume the existence of an environment variable or |
| 97 | + // etc.). |
| 98 | + // |
| 99 | + // `mamba` or `micromamba` is installed at: |
| 100 | + // |
| 101 | + // - `${PREFIX}/bin/{mamba,micromamba}` on Unix |
| 102 | + // - `${PREFIX}/Library/bin/{mamba,micromamba}.exe` on Windows |
| 103 | + // |
| 104 | + const fs::u8path env_prefix |
| 105 | + = (util::on_win ? executable_path.parent_path().parent_path().parent_path() |
| 106 | + : executable_path.parent_path().parent_path()); |
| 107 | + |
| 108 | + const fs::u8path env_prefix_conda_cert = env_prefix |
| 109 | + / prefix_relative_conda_cert_path; |
| 110 | + |
| 111 | + LOG_INFO << "Checking for CA certificates in the same prefix as the executable installation: " |
93 | 112 | << env_prefix_conda_cert; |
94 | 113 |
|
95 | 114 | if (fs::exists(env_prefix_conda_cert)) |
96 | 115 | { |
97 | | - LOG_INFO << "Using CA certificates from `conda-forge::ca-certificates` installed in the root prefix " |
98 | | - << "(i.e " << env_prefix_conda_cert << ")"; |
| 116 | + LOG_INFO << "Using CA certificates from `conda-forge::ca-certificates` installed in the same prefix " |
| 117 | + << "as the executable installation (i.e " << env_prefix_conda_cert |
| 118 | + << ")"; |
99 | 119 | remote_fetch_params.ssl_verify = env_prefix_conda_cert; |
100 | 120 | remote_fetch_params.curl_initialized = true; |
101 | 121 | return; |
102 | 122 | } |
103 | 123 |
|
| 124 | + // Try to use the CA certificates from `conda-forge::ca-certificates` installed |
| 125 | + // in the root prefix. |
| 126 | + const fs::u8path root_prefix = detail::get_root_prefix(); |
| 127 | + const fs::u8path root_prefix_conda_cert = root_prefix |
| 128 | + / prefix_relative_conda_cert_path; |
| 129 | + |
| 130 | + LOG_INFO << "Checking for CA certificates at the root prefix: " |
| 131 | + << root_prefix_conda_cert; |
| 132 | + |
| 133 | + if (fs::exists(root_prefix_conda_cert)) |
| 134 | + { |
| 135 | + LOG_INFO << "Using CA certificates from `conda-forge::ca-certificates` installed in the root prefix " |
| 136 | + << "(i.e " << root_prefix_conda_cert << ")"; |
| 137 | + remote_fetch_params.ssl_verify = root_prefix_conda_cert; |
| 138 | + remote_fetch_params.curl_initialized = true; |
| 139 | + return; |
| 140 | + } |
| 141 | + |
104 | 142 | // Fallback on system CA certificates. |
105 | 143 | bool found = false; |
106 | 144 |
|
|
0 commit comments