Skip to content

Commit 912209d

Browse files
authored
CDRIVER-5998 import persisted private keys for SChannel (#2059)
* CDRIVER-6000 test MONGODB-X509 with cloud-dev * CDRIVER-5998 import private keys as persisted To fix error sending client cert to servers requiring newer signatures. Sending a client cert is required for MONGODB-X509. Fixes observed error sending client cert to servers not accepting SHA1 for client cert signature: > 0x80090331: The client and server cannot communicate, because they do not possess a common algorithm. * fix CRL test and add instructions to manually remove CRL file * use `size_t` for hex/bin helpers To avoid casts with `uint32_t`. Add an overflow check. Rename variables to distinguish hex and binary lengths. * use `mlib_nat64_parse` to parse hex To avoid behavior in `sscanf` skipping whitespace. The skipped whitespace could result in the loop in `hex_to_bin` reading beyond the input.
1 parent a12649f commit 912209d

File tree

10 files changed

+447
-99
lines changed

10 files changed

+447
-99
lines changed

.evergreen/scripts/run-auth-tests.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,20 @@ secrets_dir="$(to_absolute "${mongoc_dir}/../secrets")"
2424
mkdir -p "${secrets_dir}"
2525
chmod 700 "${secrets_dir}"
2626

27-
# Create certificate to test X509 auth with Atlas:
27+
# Create certificate to test X509 auth with Atlas on cloud-prod:
2828
atlas_x509_path="${secrets_dir:?}/atlas_x509.pem"
2929
echo "${atlas_x509_cert_base64:?}" | base64 --decode > "${secrets_dir:?}/atlas_x509.pem"
3030
# Fix path on Windows:
3131
if $IS_WINDOWS; then
32-
atlas_x509_path="$(cygpath -m "${secrets_dir:?}/atlas_x509.pem")"
32+
atlas_x509_path="$(cygpath -m "${atlas_x509_path}")"
33+
fi
34+
35+
# Create certificate to test X509 auth with Atlas on cloud-dev
36+
atlas_x509_dev_path="${secrets_dir:?}/atlas_x509_dev.pem"
37+
echo "${atlas_x509_dev_cert_base64:?}" | base64 --decode > "${atlas_x509_dev_path:?}"
38+
# Fix path on Windows:
39+
if $IS_WINDOWS; then
40+
atlas_x509_dev_path="$(cygpath -m "${atlas_x509_dev_path}")"
3341
fi
3442

3543
# Create Kerberos config and keytab files.
@@ -187,9 +195,12 @@ if [[ "${ssl}" != "OFF" ]]; then
187195
LD_LIBRARY_PATH="${openssl_lib_prefix}" "${ping}" "${atlas_serverless:?}&${c_timeout}"
188196
fi
189197

190-
echo "Connecting to Atlas with X509"
198+
echo "Connecting to Atlas (cloud-prod) with X509"
191199
LD_LIBRARY_PATH="${openssl_lib_prefix}" "${ping}" "${atlas_x509:?}&tlsCertificateKeyFile=${atlas_x509_path}&${c_timeout}"
192200

201+
echo "Connecting to Atlas (cloud-dev) with X509"
202+
LD_LIBRARY_PATH="${openssl_lib_prefix}" "${ping}" "${atlas_x509_dev:?}&tlsCertificateKeyFile=${atlas_x509_dev_path}&${c_timeout}"
203+
193204
fi
194205

195206
echo "Authenticating using PLAIN"

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ If you start `mongod` with SSL, set these variables to configure how
179179
* `MONGOC_TEST_SSL_CRL_FILE`: path to a certificate revocation list.
180180
* `MONGOC_TEST_SSL_WEAK_CERT_VALIDATION`: set to `on` to relax the client's
181181
validation of the server's certificate.
182+
* `MONGOC_TEST_SCHANNEL_CRL=on`: set to `on` to enable Windows Secure Channel tests loading CRL files.
183+
* If CRL tests abort before deleting the CRL file, this may cause later test errors like `The certificate is revoked`. Manually remove the CRL file with:
184+
```powershell
185+
$crl = ".\src\libmongoc\tests\x509gen\crl.pem"
186+
$fingerprint = (openssl crl -in ".\src\libmongoc\tests\x509gen\crl.pem" -noout -fingerprint) -replace 'SHA1 Fingerprint=', '' -replace ':', ''
187+
certutil -delstore Root $fingerprint
188+
```
182189
183190
The SASL / GSSAPI / Kerberos tests are skipped by default. To run them, set up a
184191
separate `mongod` with Kerberos and set its host and Kerberos principal name

src/libmongoc/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ endfunction()
204204
# Per-backend link libs/options:
205205
set(SecureTransport/LINK_LIBRARIES "-framework CoreFoundation" "-framework Security")
206206
set(SecureTransport/pkg_config_LIBS -framework Corefoundation -framework Security)
207-
set(SecureChannel/LINK_LIBRARIES secur32.lib crypt32.lib Bcrypt.lib)
207+
set(SecureChannel/LINK_LIBRARIES secur32.lib crypt32.lib Bcrypt.lib ncrypt.lib)
208208
set(SecureChannel/pkg_config_LIBS ${SecureChannel/LINK_LIBRARIES})
209209
set(OpenSSL/LINK_LIBRARIES OpenSSL::SSL OpenSSL::Crypto $<$<PLATFORM_ID:Windows>:crypt32.lib>)
210210
set(OpenSSL/pkg_config_LIBS -lssl -lcrypto $<$<PLATFORM_ID:Windows>:crypt32.lib>)

0 commit comments

Comments
 (0)