forked from Siegfried-Gottlich-Wotansson/wget-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindows-openssl.diff
113 lines (109 loc) · 3.2 KB
/
windows-openssl.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
--- src/openssl.c 2021-01-09 01:51:43.000000000 +0300
+++ src/openssl.c.windows 2021-03-15 21:31:22.597135391 +0300
@@ -174,6 +174,72 @@
Returns true on success, false otherwise. */
+/* Start: Windows SSL Cert Changes */
+#ifdef WINDOWS
+/* Local version of CERT_CONTEXT, to prevent from bringing in a specific
+ version of the Windows SDK */
+typedef struct _CERT_CONTEXT
+{
+ unsigned int dwCertEncodingType;
+ unsigned char *pbCertEncoded;
+ unsigned int cbCertEncoded;
+ void* pCertInfo;
+ void* hCertStore;
+} CERT_CONTEXT, *PCERT_CONTEXT;typedef const CERT_CONTEXT *PCCERT_CONTEXT;
+
+/* Load crypt32.dll manually to prevent bringing it in unless used */
+HMODULE Local_Crypt32()
+{
+ static HMODULE ret = NULL;
+ if (!ret)
+ {
+ ret = LoadLibraryA("Crypt32.dll");
+ }
+ return ret;
+}
+
+/* Bounce these APIs to our loaded version of crypt32.dll */
+void* Local_CertOpenSystemStoreA(void* hprov, char* szSubsystemProtocol)
+{
+ if (Local_Crypt32())
+ {
+ static FARPROC ret = NULL;
+ if (!ret)
+ {
+ ret = GetProcAddress(Local_Crypt32(), "CertOpenSystemStoreA");
+ }
+ if (ret)
+ {
+ typedef void* (WINAPI * PFN_Func)(void*, char*);
+ return ((PFN_Func) ret)(hprov, szSubsystemProtocol);
+ }
+ }
+ return NULL;
+}
+
+void* Local_CertEnumCertificatesInStore(void* hCertStore, void* pPrevCertContext)
+{
+ if (Local_Crypt32())
+ {
+ static FARPROC ret = NULL;
+ if (!ret)
+ {
+ ret = GetProcAddress(Local_Crypt32(), "CertEnumCertificatesInStore");
+ }
+ if (ret)
+ {
+ typedef void* (WINAPI * PFN_Func)(void*, void*);
+ return ((PFN_Func) ret)(hCertStore, pPrevCertContext);
+ }
+ }
+ return NULL;
+}
+
+#define PKCS_7_ASN_ENCODING 0x00010000
+#endif
+/* End: Windows SSL Cert Changes */
+
+
bool
ssl_init (void)
{
@@ -335,6 +401,37 @@
}
SSL_CTX_set_default_verify_paths (ssl_ctx);
+
+ /* Start: Windows SSL Cert Changes */
+#ifdef WINDOWS
+ /* Only attempt to use the Windows store if one is not specified */
+ if (!opt.ca_cert)
+ {
+ /* Open the default Windows cert store */
+ void* hStore = Local_CertOpenSystemStoreA(NULL, "ROOT");
+ if (hStore)
+ {
+ /* And then open the OpenSSL store */
+ X509_STORE * store = SSL_CTX_get_cert_store(ssl_ctx);
+ CERT_CONTEXT * pCertCtx = NULL;
+ /* Loop through all the certs in the Windows cert store */
+ for ( pCertCtx = Local_CertEnumCertificatesInStore(hStore, NULL);
+ pCertCtx != NULL;
+ pCertCtx = Local_CertEnumCertificatesInStore(hStore, pCertCtx) )
+ {
+ if (!((pCertCtx->dwCertEncodingType & PKCS_7_ASN_ENCODING) == PKCS_7_ASN_ENCODING))
+ {
+ /* Add all certs we find to OpenSSL's store */
+ X509 *cert = d2i_X509(NULL, (const unsigned char**)&pCertCtx->pbCertEncoded, pCertCtx->cbCertEncoded);
+ X509_STORE_add_cert(store, cert);
+ X509_free(cert);
+ }
+ }
+ }
+ }
+#endif
+ /* End: Windows SSL Cert Changes */
+
SSL_CTX_load_verify_locations (ssl_ctx, opt.ca_cert, opt.ca_directory);
#ifdef X509_V_FLAG_PARTIAL_CHAIN