Skip to content

Commit 396ccb2

Browse files
committed
CDRIVER-3408 schannel support + tests on Windows
1 parent ccaf9eb commit 396ccb2

File tree

7 files changed

+258
-30
lines changed

7 files changed

+258
-30
lines changed

.evergreen/config.yml

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12640,6 +12640,31 @@ tasks:
1264012640
set -o errexit
1264112641
set -o xtrace
1264212642
TEST_COLUMN=TEST_3 CERT_TYPE=rsa USE_DELEGATE=on sh .evergreen/run-ocsp-test.sh
12643+
- name: ocsp-winssl-test_3-rsa-delegate
12644+
tags:
12645+
- ocsp-winssl
12646+
depends_on:
12647+
name: debug-compile-nosasl-winssl
12648+
commands:
12649+
- func: fetch build
12650+
vars:
12651+
BUILD_NAME: debug-compile-nosasl-winssl
12652+
- func: bootstrap mongo-orchestration
12653+
vars:
12654+
OCSP: 'on'
12655+
ORCHESTRATION_FILE: rsa-basic-tls-ocsp-disableStapling
12656+
SSL: ssl
12657+
TOPOLOGY: server
12658+
VERSION: latest
12659+
- command: shell.exec
12660+
type: test
12661+
params:
12662+
working_dir: mongoc
12663+
shell: bash
12664+
script: |-
12665+
set -o errexit
12666+
set -o xtrace
12667+
TEST_COLUMN=TEST_3 CERT_TYPE=rsa USE_DELEGATE=on sh .evergreen/run-ocsp-test.sh
1264312668
- name: ocsp-openssl-test_3-ecdsa-delegate
1264412669
tags:
1264512670
- ocsp-openssl
@@ -12690,6 +12715,31 @@ tasks:
1269012715
set -o errexit
1269112716
set -o xtrace
1269212717
TEST_COLUMN=TEST_3 CERT_TYPE=rsa USE_DELEGATE=off sh .evergreen/run-ocsp-test.sh
12718+
- name: ocsp-winssl-test_3-rsa-nodelegate
12719+
tags:
12720+
- ocsp-winssl
12721+
depends_on:
12722+
name: debug-compile-nosasl-winssl
12723+
commands:
12724+
- func: fetch build
12725+
vars:
12726+
BUILD_NAME: debug-compile-nosasl-winssl
12727+
- func: bootstrap mongo-orchestration
12728+
vars:
12729+
OCSP: 'on'
12730+
ORCHESTRATION_FILE: rsa-basic-tls-ocsp-disableStapling
12731+
SSL: ssl
12732+
TOPOLOGY: server
12733+
VERSION: latest
12734+
- command: shell.exec
12735+
type: test
12736+
params:
12737+
working_dir: mongoc
12738+
shell: bash
12739+
script: |-
12740+
set -o errexit
12741+
set -o xtrace
12742+
TEST_COLUMN=TEST_3 CERT_TYPE=rsa USE_DELEGATE=off sh .evergreen/run-ocsp-test.sh
1269312743
- name: ocsp-openssl-test_3-ecdsa-nodelegate
1269412744
tags:
1269512745
- ocsp-openssl
@@ -12715,6 +12765,56 @@ tasks:
1271512765
set -o errexit
1271612766
set -o xtrace
1271712767
TEST_COLUMN=TEST_3 CERT_TYPE=ecdsa USE_DELEGATE=off sh .evergreen/run-ocsp-test.sh
12768+
- name: ocsp-winssl-test_4-rsa-delegate
12769+
tags:
12770+
- ocsp-winssl
12771+
depends_on:
12772+
name: debug-compile-nosasl-winssl
12773+
commands:
12774+
- func: fetch build
12775+
vars:
12776+
BUILD_NAME: debug-compile-nosasl-winssl
12777+
- func: bootstrap mongo-orchestration
12778+
vars:
12779+
OCSP: 'on'
12780+
ORCHESTRATION_FILE: rsa-basic-tls-ocsp-disableStapling
12781+
SSL: ssl
12782+
TOPOLOGY: server
12783+
VERSION: latest
12784+
- command: shell.exec
12785+
type: test
12786+
params:
12787+
working_dir: mongoc
12788+
shell: bash
12789+
script: |-
12790+
set -o errexit
12791+
set -o xtrace
12792+
TEST_COLUMN=TEST_4 CERT_TYPE=rsa USE_DELEGATE=on sh .evergreen/run-ocsp-test.sh
12793+
- name: ocsp-winssl-test_4-rsa-nodelegate
12794+
tags:
12795+
- ocsp-winssl
12796+
depends_on:
12797+
name: debug-compile-nosasl-winssl
12798+
commands:
12799+
- func: fetch build
12800+
vars:
12801+
BUILD_NAME: debug-compile-nosasl-winssl
12802+
- func: bootstrap mongo-orchestration
12803+
vars:
12804+
OCSP: 'on'
12805+
ORCHESTRATION_FILE: rsa-basic-tls-ocsp-disableStapling
12806+
SSL: ssl
12807+
TOPOLOGY: server
12808+
VERSION: latest
12809+
- command: shell.exec
12810+
type: test
12811+
params:
12812+
working_dir: mongoc
12813+
shell: bash
12814+
script: |-
12815+
set -o errexit
12816+
set -o xtrace
12817+
TEST_COLUMN=TEST_4 CERT_TYPE=rsa USE_DELEGATE=off sh .evergreen/run-ocsp-test.sh
1271812818
- name: ocsp-openssl-soft_fail_test-rsa-nodelegate
1271912819
tags:
1272012820
- ocsp-openssl
@@ -12740,6 +12840,31 @@ tasks:
1274012840
set -o errexit
1274112841
set -o xtrace
1274212842
TEST_COLUMN=SOFT_FAIL_TEST CERT_TYPE=rsa USE_DELEGATE=off sh .evergreen/run-ocsp-test.sh
12843+
- name: ocsp-winssl-soft_fail_test-rsa-nodelegate
12844+
tags:
12845+
- ocsp-winssl
12846+
depends_on:
12847+
name: debug-compile-nosasl-winssl
12848+
commands:
12849+
- func: fetch build
12850+
vars:
12851+
BUILD_NAME: debug-compile-nosasl-winssl
12852+
- func: bootstrap mongo-orchestration
12853+
vars:
12854+
OCSP: 'on'
12855+
ORCHESTRATION_FILE: rsa-basic-tls-ocsp-disableStapling
12856+
SSL: ssl
12857+
TOPOLOGY: server
12858+
VERSION: latest
12859+
- command: shell.exec
12860+
type: test
12861+
params:
12862+
working_dir: mongoc
12863+
shell: bash
12864+
script: |-
12865+
set -o errexit
12866+
set -o xtrace
12867+
TEST_COLUMN=SOFT_FAIL_TEST CERT_TYPE=rsa USE_DELEGATE=off sh .evergreen/run-ocsp-test.sh
1274312868
- name: ocsp-openssl-soft_fail_test-ecdsa-nodelegate
1274412869
tags:
1274512870
- ocsp-openssl
@@ -12765,6 +12890,81 @@ tasks:
1276512890
set -o errexit
1276612891
set -o xtrace
1276712892
TEST_COLUMN=SOFT_FAIL_TEST CERT_TYPE=ecdsa USE_DELEGATE=off sh .evergreen/run-ocsp-test.sh
12893+
- name: ocsp-winssl-malicious_server_test_1-rsa-delegate
12894+
tags:
12895+
- ocsp-winssl
12896+
depends_on:
12897+
name: debug-compile-nosasl-winssl
12898+
commands:
12899+
- func: fetch build
12900+
vars:
12901+
BUILD_NAME: debug-compile-nosasl-winssl
12902+
- func: bootstrap mongo-orchestration
12903+
vars:
12904+
OCSP: 'on'
12905+
ORCHESTRATION_FILE: rsa-basic-tls-ocsp-mustStaple-disableStapling
12906+
SSL: ssl
12907+
TOPOLOGY: server
12908+
VERSION: latest
12909+
- command: shell.exec
12910+
type: test
12911+
params:
12912+
working_dir: mongoc
12913+
shell: bash
12914+
script: |-
12915+
set -o errexit
12916+
set -o xtrace
12917+
TEST_COLUMN=MALICIOUS_SERVER_TEST_1 CERT_TYPE=rsa USE_DELEGATE=on sh .evergreen/run-ocsp-test.sh
12918+
- name: ocsp-winssl-malicious_server_test_1-rsa-nodelegate
12919+
tags:
12920+
- ocsp-winssl
12921+
depends_on:
12922+
name: debug-compile-nosasl-winssl
12923+
commands:
12924+
- func: fetch build
12925+
vars:
12926+
BUILD_NAME: debug-compile-nosasl-winssl
12927+
- func: bootstrap mongo-orchestration
12928+
vars:
12929+
OCSP: 'on'
12930+
ORCHESTRATION_FILE: rsa-basic-tls-ocsp-mustStaple-disableStapling
12931+
SSL: ssl
12932+
TOPOLOGY: server
12933+
VERSION: latest
12934+
- command: shell.exec
12935+
type: test
12936+
params:
12937+
working_dir: mongoc
12938+
shell: bash
12939+
script: |-
12940+
set -o errexit
12941+
set -o xtrace
12942+
TEST_COLUMN=MALICIOUS_SERVER_TEST_1 CERT_TYPE=rsa USE_DELEGATE=off sh .evergreen/run-ocsp-test.sh
12943+
- name: ocsp-winssl-malicious_server_test_2-rsa-nodelegate
12944+
tags:
12945+
- ocsp-winssl
12946+
depends_on:
12947+
name: debug-compile-nosasl-winssl
12948+
commands:
12949+
- func: fetch build
12950+
vars:
12951+
BUILD_NAME: debug-compile-nosasl-winssl
12952+
- func: bootstrap mongo-orchestration
12953+
vars:
12954+
OCSP: 'on'
12955+
ORCHESTRATION_FILE: rsa-basic-tls-ocsp-mustStaple-disableStapling
12956+
SSL: ssl
12957+
TOPOLOGY: server
12958+
VERSION: latest
12959+
- command: shell.exec
12960+
type: test
12961+
params:
12962+
working_dir: mongoc
12963+
shell: bash
12964+
script: |-
12965+
set -o errexit
12966+
set -o xtrace
12967+
TEST_COLUMN=MALICIOUS_SERVER_TEST_2 CERT_TYPE=rsa USE_DELEGATE=off sh .evergreen/run-ocsp-test.sh
1276812968
buildvariants:
1276912969
- name: releng
1277012970
display_name: '**Release Archive Creator'
@@ -13446,6 +13646,12 @@ buildvariants:
1344613646
- name: debug-compile-nosasl-openssl
1344713647
distros:
1344813648
- ubuntu1804-test
13649+
- name: debug-compile-nosasl-winssl
13650+
distros:
13651+
- windows-64-vs2017-test
1344913652
- name: .ocsp-openssl
1345013653
distros:
1345113654
- ubuntu1804-test
13655+
- name: .ocsp-winssl
13656+
distros:
13657+
- windows-64-vs2017-test

.evergreen/run-ocsp-test.sh

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,6 @@ expect_failure () {
111111
fi
112112
}
113113

114-
# Start a mock responder if necessary.
115-
if curl localhost:8100 > /dev/null 2>&1; then
116-
echo "Detected process listening on port 8100. Attempting to kill running mock responders.";
117-
pkill -f "ocsp_mock" || true
118-
fi
119-
120114
# Same responder is used for both server and client. So even stapling tests require a responder.
121115
if [ "TEST_1" = "$TEST_COLUMN" ]; then
122116
RESPONDER_REQUIRED="valid"
@@ -132,33 +126,52 @@ else
132126
RESPONDER_REQUIRED=""
133127
fi
134128

135-
if [ "ON" = "$USE_DELEGATE" ]; then
136-
DELEGATE_TOKEN="delegate"
137-
fi
138-
139129
if [ -n "$RESPONDER_REQUIRED" ]; then
140130
echo "Starting mock responder"
141131
if [ -z "$SKIP_PIP_INSTALL" ]; then
142132
echo "Installing python dependencies"
143133
# Installing dependencies.
144-
/opt/mongodbtoolchain/v3/bin/python3 -m venv ./venv
145-
. ./venv/bin/activate
146-
pip install oscrypto bottle asn1crypto
134+
if [ "$OS" = "WINDOWS" ]; then
135+
/cygdrive/c/python/Python36/python --version
136+
/cygdrive/c/python/Python36/python -m virtualenv venv_ocsp
137+
PYTHON="$(pwd)/venv_ocsp/Scripts/python"
138+
else
139+
/opt/mongodbtoolchain/v3/bin/python3 -m venv ./venv_ocsp
140+
PYTHON=./venv_ocsp/bin/python
141+
fi
142+
$PYTHON -m pip install oscrypto bottle asn1crypto
147143
fi
148144
cd "$CDRIVER_ROOT/.evergreen/ocsp/$CERT_TYPE"
149-
./mock-$DELEGATE_TOKEN$RESPONDER_REQUIRED.sh > $CDRIVER_BUILD/responder.log 2>&1 &
145+
if [ "$RESPONDER_REQUIRED" = "invalid" ]; then
146+
FAULT="--fault revoked"
147+
fi
148+
if [ "ON" = "$USE_DELEGATE" ]; then
149+
RESPONDER_SIGNER="ocsp-responder"
150+
else
151+
RESPONDER_SIGNER="ca"
152+
fi
153+
$PYTHON ../ocsp_mock.py \
154+
--ca_file ca.pem \
155+
--ocsp_responder_cert $RESPONDER_SIGNER.crt \
156+
--ocsp_responder_key $RESPONDER_SIGNER.key \
157+
-p 8100 -v $FAULT \
158+
> $CDRIVER_BUILD/responder.log 2>&1 &
150159
cd -
151160
fi
152161

153162
echo "Clearing OCSP cache for macOS/Windows"
154163
if [ "$OS" = "MACOS" ]; then
155-
find ~/profile/Library/Keychains -name 'ocspcache.sqlite3' -exec sqlite3 "{}" 'DELETE FROM responses' \;
164+
find ~/profile/Library/Keychains -name 'ocspcache.sqlite3' -exec sqlite3 "{}" 'DELETE FROM responses' \; || true
156165
elif [ "$OS" = "WINDOWS" ]; then
157-
certutil -urlcache "*" delete
166+
certutil -urlcache "*" delete || true
158167
fi
159168

160169
# Always add the tlsCAFile
161-
BASE_URI="mongodb://localhost:$MONGODB_PORT/?tls=true&tlsCAFile=$CDRIVER_ROOT/.evergreen/ocsp/$CERT_TYPE/ca.pem"
170+
CA_PATH=$CDRIVER_ROOT/.evergreen/ocsp/$CERT_TYPE/ca.pem
171+
if [ "$OS" = "WINDOWS" ]; then
172+
CA_PATH=$(cygpath -m -a $CA_PATH)
173+
fi
174+
BASE_URI="mongodb://localhost:$MONGODB_PORT/?tls=true&tlsCAFile=$CA_PATH"
162175
MONGODB_URI="$BASE_URI"
163176

164177
# Only a handful of cases are expected to fail.

build/evergreen_config_lib/tasks.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -938,8 +938,7 @@ def to_dict(self):
938938
def _check_allowed(self):
939939
# Current latest macOS does not support the disableStapling failpoint.
940940
# There are no tests that can run on macOS in current evergreen configuration.
941-
# Removing windows for now too.
942-
if self.ssl == 'darwinssl' or self.ssl == 'winssl':
941+
if self.ssl == 'darwinssl':
943942
# TODO: remove this when macOS latest download is updated
944943
prohibit (True)
945944

@@ -950,12 +949,9 @@ def _check_allowed(self):
950949
# OCSP stapling is not supported on macOS or Windows.
951950
if self.ssl == 'darwinssl' or self.ssl == 'winssl':
952951
prohibit (self.test in ['test_1', 'test_2'])
952+
953953
if self.test == 'soft_fail_test' or self.test == 'malicious_server_test_2':
954954
prohibit(self.delegate == 'delegate')
955-
956-
# Until soft-fail is supported on Windows, skip test.
957-
if self.ssl == 'winssl':
958-
prohibit (self.test == 'soft_fail_test')
959955

960956
# Until OCSP is supported in OpenSSL, skip tests that expect to be revoked.
961957
if self.ssl == 'openssl':

build/evergreen_config_lib/variants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,9 +616,9 @@
616616
Variant ('ocsp', 'OCSP tests', 'ubuntu1804-test', [
617617
OD([('name', 'debug-compile-nosasl-openssl'), ('distros', ['ubuntu1804-test'])]),
618618
#OD([('name', 'debug-compile-nosasl-darwinssl'), ('distros', ['macos-1014'])]),
619-
#OD([('name', 'debug-compile-nosasl-winssl'), ('distros', ['windows-64-vs2017-test'])]),
619+
OD([('name', 'debug-compile-nosasl-winssl'), ('distros', ['windows-64-vs2017-test'])]),
620620
OD([('name', '.ocsp-openssl'), ('distros', ['ubuntu1804-test'])]),
621621
#OD([('name', '.ocsp-darwinssl'), ('distros', ['macos-1014'])]),
622-
#OD([('name', '.ocsp-winssl'), ('distros', ['windows-64-vs2017-test'])])
622+
OD([('name', '.ocsp-winssl'), ('distros', ['windows-64-vs2017-test'])])
623623
])
624624
]

src/libmongoc/doc/mongoc_ssl_opt_t.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ When compiled against the Windows native libraries, the ``ca_dir`` option is not
9696

9797
Encrypted PEM files (e.g., requiring ``pem_pwd``) are also not supported, and will result in error when attempting to load them.
9898

99-
When ``ca_file`` is provided, the driver will only allow server certificates issued by the authority (or authorities) provided. When no ``ca_file`` is provided, the driver will look up the Certificate Authority using the ``System Local Machine Root`` certificate store to confirm the provided certificate.
99+
When ``ca_file`` is provided, the driver will only allow server certificates issued by the authority (or authorities) provided. When no ``ca_file`` is provided, the driver will look up the Certificate Authority using the ``System Local Machine Root`` certificate store to confirm the provided certificate or the ``Current user certificate store`` if the ``System Local Machine Root`` certificate store is unavailable.
100100

101101
When ``crl_file`` is provided, the driver will import the revocation list to the ``System Local Machine Root`` certificate store.
102102

src/libmongoc/src/mongoc/mongoc-secure-channel.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,17 @@ mongoc_secure_channel_setup_ca (
383383
L"Root"); /* system store name. "My" or "Root" */
384384

385385
if (cert_store == NULL) {
386-
MONGOC_ERROR ("Error opening certificate store");
387-
return false;
386+
cert_store = CertOpenStore (
387+
CERT_STORE_PROV_SYSTEM, /* provider */
388+
X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, /* certificate encoding */
389+
0, /* unused */
390+
CERT_SYSTEM_STORE_CURRENT_USER, /* dwFlags */
391+
L"My"); /* system store name. "My" or "Root" */
392+
393+
if (cert_store == NULL) {
394+
MONGOC_ERROR ("Error opening certificate store");
395+
return false;
396+
}
388397
}
389398

390399
if (CertAddCertificateContextToStore (

0 commit comments

Comments
 (0)