about summary refs log tree commit diff stats
path: root/WWW/Library/Implementation/HTTP.c
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>2006-05-29 23:09:26 -0400
committerThomas E. Dickey <dickey@invisible-island.net>2006-05-29 23:09:26 -0400
commit38fbf2f2474aa1e66883014080fc504475297c4f (patch)
tree20f45b048fecb8271e5c386fd2a746488c59356b /WWW/Library/Implementation/HTTP.c
parent04a316621e7163aa1d3a747c47844da55c6aa4d6 (diff)
downloadlynx-snapshots-38fbf2f2474aa1e66883014080fc504475297c4f.tar.gz
snapshot of project "lynx", label v2-8-6dev_18
Diffstat (limited to 'WWW/Library/Implementation/HTTP.c')
-rw-r--r--WWW/Library/Implementation/HTTP.c98
1 files changed, 73 insertions, 25 deletions
diff --git a/WWW/Library/Implementation/HTTP.c b/WWW/Library/Implementation/HTTP.c
index 7ced53bf..687bab83 100644
--- a/WWW/Library/Implementation/HTTP.c
+++ b/WWW/Library/Implementation/HTTP.c
@@ -451,11 +451,14 @@ static int HTLoadHTTP(const char *arg,
     const char *connect_url = NULL;	/* The URL being proxied */
     char *connect_host = NULL;	/* The host being proxied */
     SSL *handle = NULL;		/* The SSL handle */
-    char ssl_dn[256];
+    char ssl_dn[1024];
     char *cert_host;
     char *ssl_host;
     char *p;
     char *msg = NULL;
+    int status_sslcertcheck;
+    char *ssl_dn_start;
+    char *ssl_all_cns;
 
 #if SSLEAY_VERSION_NUMBER >= 0x0900
     BOOL try_tls = TRUE;
@@ -621,34 +624,79 @@ static int HTLoadHTTP(const char *arg,
 
 	X509_NAME_oneline(X509_get_subject_name(SSL_get_peer_certificate(handle)),
 			  ssl_dn, sizeof(ssl_dn));
-	if ((cert_host = strstr(ssl_dn, "/CN=")) == NULL) {
+
+	/*
+	 * X.509 DN validation taking ALL CN fields into account
+	 * (c) 2006 Thorsten Glaser <tg@mirbsd.de>
+	 */
+
+	/* initialise status information */
+	status_sslcertcheck = 0;	/* 0 = no CN found in DN */
+	ssl_dn_start = ssl_dn;
+	ssl_all_cns = NULL;
+	/* get host we're connecting to */
+	ssl_host = HTParse(url, "", PARSE_HOST);
+	/* strip port number */
+	if ((p = strchr(ssl_host, ':')) != NULL)
+	    *p = '\0';
+	/* validate all CNs found in DN */
+	while ((cert_host = strstr(ssl_dn_start, "/CN=")) != NULL) {
+	    status_sslcertcheck = 1;	/* 1 = could not verify CN */
+	    /* start of CommonName */
+	    cert_host += 4;
+	    /* find next part of DistinguishedName */
+	    if ((p = strchr(cert_host, '/')) != NULL) {
+		*p = '\0';
+		ssl_dn_start = p;	/* yes this points to the NUL byte */
+	    } else
+		ssl_dn_start = NULL;
+	    /* strip port number */
+	    if ((p = strchr(cert_host, ':')) != NULL)
+		*p = '\0';
+	    /* verify this CN */
+	    if (!strcasecomp_asterisk(ssl_host, cert_host)) {
+		status_sslcertcheck = 2;	/* 2 = verified peer */
+		/* I think this is cool to have in the logs --mirabilos */
+		HTSprintf0(&msg,
+			   gettext("Verified connection to %s (cert=%s)"),
+			   ssl_host, cert_host);
+		_HTProgress(msg);
+		FREE(msg);
+		/* no need to continue the verification loop */
+		break;
+	    }
+	    /* add this CN to list of failed CNs */
+	    if (ssl_all_cns == NULL) {
+		StrAllocCopy(ssl_all_cns, cert_host);
+	    } else {
+		StrAllocCat(ssl_all_cns, ":");
+		StrAllocCat(ssl_all_cns, cert_host);
+	    }
+	    /* if we cannot retry, don't try it */
+	    if (ssl_dn_start == NULL)
+		break;
+	    /* now retry next CN found in DN */
+	    *ssl_dn_start = '/';	/* formerly NUL byte */
+	}
+
+	/* if an error occurred, format the appropriate message */
+	if (status_sslcertcheck == 0) {
 	    HTSprintf0(&msg,
 		       gettext("SSL error:Can't find common name in certificate-Continue?"));
+	} else if (status_sslcertcheck == 1) {
+	    HTSprintf0(&msg,
+		       gettext("SSL error:host(%s)!=cert(%s)-Continue?"),
+		       ssl_host, ssl_all_cns);
+	}
+
+	/* if an error occurred, let the user decide how much he trusts */
+	if (status_sslcertcheck < 2) {
 	    if (!HTForcedPrompt(ssl_noprompt, msg, YES)) {
 		status = HT_NOT_LOADED;
 		FREE(msg);
+		FREE(ssl_all_cns);
 		goto done;
 	    }
-	} else {
-	    cert_host += 4;
-	    if ((p = strchr(cert_host, '/')) != NULL)
-		*p = '\0';
-	    if ((p = strchr(cert_host, ':')) != NULL)
-		*p = '\0';
-	    ssl_host = HTParse(url, "", PARSE_HOST);
-	    if ((p = strchr(ssl_host, ':')) != NULL)
-		*p = '\0';
-	    if (strcasecomp(ssl_host, cert_host)) {
-		HTSprintf0(&msg,
-			   gettext("SSL error:host(%s)!=cert(%s)-Continue?"),
-			   ssl_host,
-			   cert_host);
-		if (!HTForcedPrompt(ssl_noprompt, msg, YES)) {
-		    status = HT_NOT_LOADED;
-		    FREE(msg);
-		    goto done;
-		}
-	    }
 	}
 
 	HTSprintf0(&msg,
@@ -834,7 +882,7 @@ static int HTLoadHTTP(const char *arg,
 	 *
 	 * If there ever is a need to send "Negotiate:  trans" and really mean
 	 * it, we should send "Negotiate:  trans,trans" or similar, since that
-	 * is semantically equivalent and some servers may ignore "Negotiate: 
+	 * is semantically equivalent and some servers may ignore "Negotiate:
 	 * trans" as a special case when it comes from Lynx (to work around the
 	 * old faulty behavior).  - kw
 	 *
@@ -957,7 +1005,7 @@ static int HTLoadHTTP(const char *arg,
 		} else if (auth && *auth == '\0') {
 		    /*
 		     * If auth is a zero-length string, the user either
-		     * cancelled or goofed at the username and password prompt. 
+		     * cancelled or goofed at the username and password prompt.
 		     * - FM
 		     */
 		    if (!(traversal || dump_output_immediately) &&
@@ -1624,7 +1672,7 @@ static int HTLoadHTTP(const char *arg,
 		 * would include POST content, we seek confirmation from an
 		 * interactive user, with option to use 303 for 301 (but not
 		 * for 307), and otherwise refuse the redirection.  We also
-		 * don't allow permanent redirection if we keep POST content. 
+		 * don't allow permanent redirection if we keep POST content.
 		 * If we don't find the Location header or it's value is
 		 * zero-length, we display whatever the server returned, and
 		 * the user should RELOAD that to try again, or make a
='oid'>2c678a4e ^
204dae92 ^

201458e3 ^
204dae92 ^






201458e3 ^
204dae92 ^








201458e3 ^
204dae92 ^
2c91ac0c ^
204dae92 ^
bfa3f5ba ^
9e751bb8 ^
bfa3f5ba ^
1c2d788b ^
9e751bb8 ^
204dae92 ^


201458e3 ^
204dae92 ^
201458e3 ^
204dae92 ^


1c2d788b ^
2c678a4e ^
204dae92 ^
1c2d788b ^
2c678a4e ^
204dae92 ^



9e751bb8 ^
2c678a4e ^
9e751bb8 ^
1c2d788b ^
2c678a4e ^
9e751bb8 ^

204dae92 ^








201458e3 ^
204dae92 ^

2b37bbea ^
204dae92 ^



201458e3 ^
204dae92 ^





201458e3 ^
204dae92 ^
201458e3 ^
204dae92 ^


bfa3f5ba ^
201458e3 ^
204dae92 ^


201458e3 ^
204dae92 ^





201458e3 ^
204dae92 ^





201458e3 ^
204dae92 ^











201458e3 ^

204dae92 ^






201458e3 ^
204dae92 ^


2c678a4e ^
9e751bb8 ^


204dae92 ^



201458e3 ^

204dae92 ^
1c2d788b ^



















































































32b8fac2 ^



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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298