Skip to content

Commit bfa06cc

Browse files
committed
CDRIVER-1964 Windows CA stores should be opened with read-only flag
1 parent 333cbc2 commit bfa06cc

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/mongoc/mongoc-openssl.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,20 @@ _mongoc_openssl_import_cert_store (LPWSTR store_name, DWORD dwFlags, X509_STORE*
120120
store_name); /* system store name. "My" or "Root" */
121121

122122
if (cert_store == NULL) {
123-
MONGOC_WARNING ("error opening system CA store");
123+
LPTSTR msg = NULL;
124+
FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |
125+
FORMAT_MESSAGE_FROM_SYSTEM |
126+
FORMAT_MESSAGE_ARGUMENT_ARRAY,
127+
NULL,
128+
GetLastError (),
129+
LANG_NEUTRAL,
130+
(LPTSTR) &msg,
131+
0,
132+
NULL);
133+
MONGOC_ERROR ("Can't open CA store: 0x%.8X: '%s'",
134+
GetLastError (),
135+
msg);
136+
LocalFree (msg);
124137
return false;
125138
}
126139

@@ -151,11 +164,11 @@ _mongoc_openssl_import_cert_stores (SSL_CTX *context)
151164
return false;
152165
}
153166

154-
retval = _mongoc_openssl_import_cert_store (L"root", CERT_SYSTEM_STORE_CURRENT_USER, store);
167+
retval = _mongoc_openssl_import_cert_store (L"root", CERT_SYSTEM_STORE_CURRENT_USER|CERT_STORE_READONLY_FLAG, store);
155168
if (retval) {
156169
return retval;
157170
}
158-
return _mongoc_openssl_import_cert_store (L"CA", CERT_SYSTEM_STORE_CURRENT_USER, store);
171+
return _mongoc_openssl_import_cert_store (L"CA", CERT_SYSTEM_STORE_CURRENT_USER|CERT_STORE_READONLY_FLAG, store);
159172
}
160173
#endif
161174

0 commit comments

Comments
 (0)