##// END OF EJS Templates
tests: increase test-https malform error glob...
Durham Goode -
r29356:93b83ef7 default
parent child Browse files
Show More
@@ -1,369 +1,369 b''
1 1 #require serve ssl
2 2
3 3 Proper https client requires the built-in ssl from Python 2.6.
4 4
5 5 Make server certificates:
6 6
7 7 $ CERTSDIR="$TESTDIR/sslcerts"
8 8 $ cat "$CERTSDIR/priv.pem" "$CERTSDIR/pub.pem" >> server.pem
9 9 $ PRIV=`pwd`/server.pem
10 10 $ cat "$CERTSDIR/priv.pem" "$CERTSDIR/pub-not-yet.pem" > server-not-yet.pem
11 11 $ cat "$CERTSDIR/priv.pem" "$CERTSDIR/pub-expired.pem" > server-expired.pem
12 12
13 13 $ hg init test
14 14 $ cd test
15 15 $ echo foo>foo
16 16 $ mkdir foo.d foo.d/bAr.hg.d foo.d/baR.d.hg
17 17 $ echo foo>foo.d/foo
18 18 $ echo bar>foo.d/bAr.hg.d/BaR
19 19 $ echo bar>foo.d/baR.d.hg/bAR
20 20 $ hg commit -A -m 1
21 21 adding foo
22 22 adding foo.d/bAr.hg.d/BaR
23 23 adding foo.d/baR.d.hg/bAR
24 24 adding foo.d/foo
25 25 $ hg serve -p $HGPORT -d --pid-file=../hg0.pid --certificate=$PRIV
26 26 $ cat ../hg0.pid >> $DAEMON_PIDS
27 27
28 28 cacert not found
29 29
30 30 $ hg in --config web.cacerts=no-such.pem https://localhost:$HGPORT/
31 31 abort: could not find web.cacerts: no-such.pem
32 32 [255]
33 33
34 34 Test server address cannot be reused
35 35
36 36 #if windows
37 37 $ hg serve -p $HGPORT --certificate=$PRIV 2>&1
38 38 abort: cannot start server at ':$HGPORT':
39 39 [255]
40 40 #else
41 41 $ hg serve -p $HGPORT --certificate=$PRIV 2>&1
42 42 abort: cannot start server at ':$HGPORT': Address already in use
43 43 [255]
44 44 #endif
45 45 $ cd ..
46 46
47 47 Our test cert is not signed by a trusted CA. It should fail to verify if
48 48 we are able to load CA certs.
49 49
50 50 #if defaultcacerts
51 51 $ hg clone https://localhost:$HGPORT/ copy-pull
52 52 abort: error: *certificate verify failed* (glob)
53 53 [255]
54 54 #endif
55 55
56 56 Specifying a per-host certificate file that doesn't exist will abort
57 57
58 58 $ hg --config hostsecurity.localhost:verifycertsfile=/does/not/exist clone https://localhost:$HGPORT/
59 59 abort: path specified by hostsecurity.localhost:verifycertsfile does not exist: /does/not/exist
60 60 [255]
61 61
62 62 A malformed per-host certificate file will raise an error
63 63
64 64 $ echo baddata > badca.pem
65 65 $ hg --config hostsecurity.localhost:verifycertsfile=badca.pem clone https://localhost:$HGPORT/
66 abort: error: unknown error* (glob)
66 abort: error: * (glob)
67 67 [255]
68 68
69 69 A per-host certificate mismatching the server will fail verification
70 70
71 71 $ hg --config hostsecurity.localhost:verifycertsfile="$CERTSDIR/client-cert.pem" clone https://localhost:$HGPORT/
72 72 abort: error: *certificate verify failed* (glob)
73 73 [255]
74 74
75 75 A per-host certificate matching the server's cert will be accepted
76 76
77 77 $ hg --config hostsecurity.localhost:verifycertsfile="$CERTSDIR/pub.pem" clone -U https://localhost:$HGPORT/ perhostgood1
78 78 requesting all changes
79 79 adding changesets
80 80 adding manifests
81 81 adding file changes
82 82 added 1 changesets with 4 changes to 4 files
83 83
84 84 A per-host certificate with multiple certs and one matching will be accepted
85 85
86 86 $ cat "$CERTSDIR/client-cert.pem" "$CERTSDIR/pub.pem" > perhost.pem
87 87 $ hg --config hostsecurity.localhost:verifycertsfile=perhost.pem clone -U https://localhost:$HGPORT/ perhostgood2
88 88 requesting all changes
89 89 adding changesets
90 90 adding manifests
91 91 adding file changes
92 92 added 1 changesets with 4 changes to 4 files
93 93
94 94 Defining both per-host certificate and a fingerprint will print a warning
95 95
96 96 $ hg --config hostsecurity.localhost:verifycertsfile="$CERTSDIR/pub.pem" --config hostsecurity.localhost:fingerprints=sha1:914f1aff87249c09b6859b88b1906d30756491ca clone -U https://localhost:$HGPORT/ caandfingerwarning
97 97 (hostsecurity.localhost:verifycertsfile ignored when host fingerprints defined; using host fingerprints for verification)
98 98 requesting all changes
99 99 adding changesets
100 100 adding manifests
101 101 adding file changes
102 102 added 1 changesets with 4 changes to 4 files
103 103
104 104 $ DISABLECACERTS="--config devel.disableloaddefaultcerts=true"
105 105
106 106 clone via pull
107 107
108 108 $ hg clone https://localhost:$HGPORT/ copy-pull $DISABLECACERTS
109 109 warning: certificate for localhost not verified (set hostsecurity.localhost:certfingerprints=sha256:62:09:97:2f:97:60:e3:65:8f:12:5d:78:9e:35:a1:36:7a:65:4b:0e:9f:ac:db:c3:bc:6e:b6:a3:c0:16:e0:30 or web.cacerts config settings)
110 110 requesting all changes
111 111 adding changesets
112 112 adding manifests
113 113 adding file changes
114 114 added 1 changesets with 4 changes to 4 files
115 115 updating to branch default
116 116 4 files updated, 0 files merged, 0 files removed, 0 files unresolved
117 117 $ hg verify -R copy-pull
118 118 checking changesets
119 119 checking manifests
120 120 crosschecking files in changesets and manifests
121 121 checking files
122 122 4 files, 1 changesets, 4 total revisions
123 123 $ cd test
124 124 $ echo bar > bar
125 125 $ hg commit -A -d '1 0' -m 2
126 126 adding bar
127 127 $ cd ..
128 128
129 129 pull without cacert
130 130
131 131 $ cd copy-pull
132 132 $ echo '[hooks]' >> .hg/hgrc
133 133 $ echo "changegroup = printenv.py changegroup" >> .hg/hgrc
134 134 $ hg pull $DISABLECACERTS
135 135 pulling from https://localhost:$HGPORT/
136 136 warning: certificate for localhost not verified (set hostsecurity.localhost:certfingerprints=sha256:62:09:97:2f:97:60:e3:65:8f:12:5d:78:9e:35:a1:36:7a:65:4b:0e:9f:ac:db:c3:bc:6e:b6:a3:c0:16:e0:30 or web.cacerts config settings)
137 137 searching for changes
138 138 adding changesets
139 139 adding manifests
140 140 adding file changes
141 141 added 1 changesets with 1 changes to 1 files
142 142 changegroup hook: HG_NODE=5fed3813f7f5e1824344fdc9cf8f63bb662c292d HG_NODE_LAST=5fed3813f7f5e1824344fdc9cf8f63bb662c292d HG_SOURCE=pull HG_TXNID=TXN:* HG_URL=https://localhost:$HGPORT/ (glob)
143 143 (run 'hg update' to get a working copy)
144 144 $ cd ..
145 145
146 146 cacert configured in local repo
147 147
148 148 $ cp copy-pull/.hg/hgrc copy-pull/.hg/hgrc.bu
149 149 $ echo "[web]" >> copy-pull/.hg/hgrc
150 150 $ echo "cacerts=$CERTSDIR/pub.pem" >> copy-pull/.hg/hgrc
151 151 $ hg -R copy-pull pull --traceback
152 152 pulling from https://localhost:$HGPORT/
153 153 searching for changes
154 154 no changes found
155 155 $ mv copy-pull/.hg/hgrc.bu copy-pull/.hg/hgrc
156 156
157 157 cacert configured globally, also testing expansion of environment
158 158 variables in the filename
159 159
160 160 $ echo "[web]" >> $HGRCPATH
161 161 $ echo 'cacerts=$P/pub.pem' >> $HGRCPATH
162 162 $ P="$CERTSDIR" hg -R copy-pull pull
163 163 pulling from https://localhost:$HGPORT/
164 164 searching for changes
165 165 no changes found
166 166 $ P="$CERTSDIR" hg -R copy-pull pull --insecure
167 167 pulling from https://localhost:$HGPORT/
168 168 warning: connection security to localhost is disabled per current settings; communication is susceptible to eavesdropping and tampering
169 169 searching for changes
170 170 no changes found
171 171
172 172 cacert mismatch
173 173
174 174 $ hg -R copy-pull pull --config web.cacerts="$CERTSDIR/pub.pem" \
175 175 > https://127.0.0.1:$HGPORT/
176 176 pulling from https://127.0.0.1:$HGPORT/
177 177 abort: 127.0.0.1 certificate error: certificate is for localhost
178 178 (set hostsecurity.127.0.0.1:certfingerprints=sha256:62:09:97:2f:97:60:e3:65:8f:12:5d:78:9e:35:a1:36:7a:65:4b:0e:9f:ac:db:c3:bc:6e:b6:a3:c0:16:e0:30 config setting or use --insecure to connect insecurely)
179 179 [255]
180 180 $ hg -R copy-pull pull --config web.cacerts="$CERTSDIR/pub.pem" \
181 181 > https://127.0.0.1:$HGPORT/ --insecure
182 182 pulling from https://127.0.0.1:$HGPORT/
183 183 warning: connection security to 127.0.0.1 is disabled per current settings; communication is susceptible to eavesdropping and tampering
184 184 searching for changes
185 185 no changes found
186 186 $ hg -R copy-pull pull --config web.cacerts="$CERTSDIR/pub-other.pem"
187 187 pulling from https://localhost:$HGPORT/
188 188 abort: error: *certificate verify failed* (glob)
189 189 [255]
190 190 $ hg -R copy-pull pull --config web.cacerts="$CERTSDIR/pub-other.pem" \
191 191 > --insecure
192 192 pulling from https://localhost:$HGPORT/
193 193 warning: connection security to localhost is disabled per current settings; communication is susceptible to eavesdropping and tampering
194 194 searching for changes
195 195 no changes found
196 196
197 197 Test server cert which isn't valid yet
198 198
199 199 $ hg serve -R test -p $HGPORT1 -d --pid-file=hg1.pid --certificate=server-not-yet.pem
200 200 $ cat hg1.pid >> $DAEMON_PIDS
201 201 $ hg -R copy-pull pull --config web.cacerts="$CERTSDIR/pub-not-yet.pem" \
202 202 > https://localhost:$HGPORT1/
203 203 pulling from https://localhost:$HGPORT1/
204 204 abort: error: *certificate verify failed* (glob)
205 205 [255]
206 206
207 207 Test server cert which no longer is valid
208 208
209 209 $ hg serve -R test -p $HGPORT2 -d --pid-file=hg2.pid --certificate=server-expired.pem
210 210 $ cat hg2.pid >> $DAEMON_PIDS
211 211 $ hg -R copy-pull pull --config web.cacerts="$CERTSDIR/pub-expired.pem" \
212 212 > https://localhost:$HGPORT2/
213 213 pulling from https://localhost:$HGPORT2/
214 214 abort: error: *certificate verify failed* (glob)
215 215 [255]
216 216
217 217 Fingerprints
218 218
219 219 - works without cacerts (hostkeyfingerprints)
220 220 $ hg -R copy-pull id https://localhost:$HGPORT/ --insecure --config hostfingerprints.localhost=91:4f:1a:ff:87:24:9c:09:b6:85:9b:88:b1:90:6d:30:75:64:91:ca
221 221 5fed3813f7f5
222 222
223 223 - works without cacerts (hostsecurity)
224 224 $ hg -R copy-pull id https://localhost:$HGPORT/ --config hostsecurity.localhost:fingerprints=sha1:914f1aff87249c09b6859b88b1906d30756491ca
225 225 5fed3813f7f5
226 226
227 227 $ hg -R copy-pull id https://localhost:$HGPORT/ --config hostsecurity.localhost:fingerprints=sha256:62:09:97:2f:97:60:e3:65:8f:12:5d:78:9e:35:a1:36:7a:65:4b:0e:9f:ac:db:c3:bc:6e:b6:a3:c0:16:e0:30
228 228 5fed3813f7f5
229 229
230 230 - multiple fingerprints specified and first matches
231 231 $ hg --config 'hostfingerprints.localhost=914f1aff87249c09b6859b88b1906d30756491ca, deadbeefdeadbeefdeadbeefdeadbeefdeadbeef' -R copy-pull id https://localhost:$HGPORT/ --insecure
232 232 5fed3813f7f5
233 233
234 234 $ hg --config 'hostsecurity.localhost:fingerprints=sha1:914f1aff87249c09b6859b88b1906d30756491ca, sha1:deadbeefdeadbeefdeadbeefdeadbeefdeadbeef' -R copy-pull id https://localhost:$HGPORT/
235 235 5fed3813f7f5
236 236
237 237 - multiple fingerprints specified and last matches
238 238 $ hg --config 'hostfingerprints.localhost=deadbeefdeadbeefdeadbeefdeadbeefdeadbeef, 914f1aff87249c09b6859b88b1906d30756491ca' -R copy-pull id https://localhost:$HGPORT/ --insecure
239 239 5fed3813f7f5
240 240
241 241 $ hg --config 'hostsecurity.localhost:fingerprints=sha1:deadbeefdeadbeefdeadbeefdeadbeefdeadbeef, sha1:914f1aff87249c09b6859b88b1906d30756491ca' -R copy-pull id https://localhost:$HGPORT/
242 242 5fed3813f7f5
243 243
244 244 - multiple fingerprints specified and none match
245 245
246 246 $ hg --config 'hostfingerprints.localhost=deadbeefdeadbeefdeadbeefdeadbeefdeadbeef, aeadbeefdeadbeefdeadbeefdeadbeefdeadbeef' -R copy-pull id https://localhost:$HGPORT/ --insecure
247 247 abort: certificate for localhost has unexpected fingerprint 91:4f:1a:ff:87:24:9c:09:b6:85:9b:88:b1:90:6d:30:75:64:91:ca
248 248 (check hostfingerprint configuration)
249 249 [255]
250 250
251 251 $ hg --config 'hostsecurity.localhost:fingerprints=sha1:deadbeefdeadbeefdeadbeefdeadbeefdeadbeef, sha1:aeadbeefdeadbeefdeadbeefdeadbeefdeadbeef' -R copy-pull id https://localhost:$HGPORT/
252 252 abort: certificate for localhost has unexpected fingerprint sha1:91:4f:1a:ff:87:24:9c:09:b6:85:9b:88:b1:90:6d:30:75:64:91:ca
253 253 (check hostsecurity configuration)
254 254 [255]
255 255
256 256 - fails when cert doesn't match hostname (port is ignored)
257 257 $ hg -R copy-pull id https://localhost:$HGPORT1/ --config hostfingerprints.localhost=914f1aff87249c09b6859b88b1906d30756491ca
258 258 abort: certificate for localhost has unexpected fingerprint 28:ff:71:bf:65:31:14:23:ad:62:92:b4:0e:31:99:18:fc:83:e3:9b
259 259 (check hostfingerprint configuration)
260 260 [255]
261 261
262 262
263 263 - ignores that certificate doesn't match hostname
264 264 $ hg -R copy-pull id https://127.0.0.1:$HGPORT/ --config hostfingerprints.127.0.0.1=914f1aff87249c09b6859b88b1906d30756491ca
265 265 5fed3813f7f5
266 266
267 267 HGPORT1 is reused below for tinyproxy tests. Kill that server.
268 268 $ killdaemons.py hg1.pid
269 269
270 270 Prepare for connecting through proxy
271 271
272 272 $ tinyproxy.py $HGPORT1 localhost >proxy.log </dev/null 2>&1 &
273 273 $ while [ ! -f proxy.pid ]; do sleep 0; done
274 274 $ cat proxy.pid >> $DAEMON_PIDS
275 275
276 276 $ echo "[http_proxy]" >> copy-pull/.hg/hgrc
277 277 $ echo "always=True" >> copy-pull/.hg/hgrc
278 278 $ echo "[hostfingerprints]" >> copy-pull/.hg/hgrc
279 279 $ echo "localhost =" >> copy-pull/.hg/hgrc
280 280
281 281 Test unvalidated https through proxy
282 282
283 283 $ http_proxy=http://localhost:$HGPORT1/ hg -R copy-pull pull --insecure --traceback
284 284 pulling from https://localhost:$HGPORT/
285 285 warning: connection security to localhost is disabled per current settings; communication is susceptible to eavesdropping and tampering
286 286 searching for changes
287 287 no changes found
288 288
289 289 Test https with cacert and fingerprint through proxy
290 290
291 291 $ http_proxy=http://localhost:$HGPORT1/ hg -R copy-pull pull \
292 292 > --config web.cacerts="$CERTSDIR/pub.pem"
293 293 pulling from https://localhost:$HGPORT/
294 294 searching for changes
295 295 no changes found
296 296 $ http_proxy=http://localhost:$HGPORT1/ hg -R copy-pull pull https://127.0.0.1:$HGPORT/ --config hostfingerprints.127.0.0.1=914f1aff87249c09b6859b88b1906d30756491ca
297 297 pulling from https://127.0.0.1:$HGPORT/
298 298 searching for changes
299 299 no changes found
300 300
301 301 Test https with cert problems through proxy
302 302
303 303 $ http_proxy=http://localhost:$HGPORT1/ hg -R copy-pull pull \
304 304 > --config web.cacerts="$CERTSDIR/pub-other.pem"
305 305 pulling from https://localhost:$HGPORT/
306 306 abort: error: *certificate verify failed* (glob)
307 307 [255]
308 308 $ http_proxy=http://localhost:$HGPORT1/ hg -R copy-pull pull \
309 309 > --config web.cacerts="$CERTSDIR/pub-expired.pem" https://localhost:$HGPORT2/
310 310 pulling from https://localhost:$HGPORT2/
311 311 abort: error: *certificate verify failed* (glob)
312 312 [255]
313 313
314 314
315 315 $ killdaemons.py hg0.pid
316 316
317 317 #if sslcontext
318 318
319 319 Start patched hgweb that requires client certificates:
320 320
321 321 $ cat << EOT > reqclientcert.py
322 322 > import ssl
323 323 > from mercurial.hgweb import server
324 324 > class _httprequesthandlersslclientcert(server._httprequesthandlerssl):
325 325 > @staticmethod
326 326 > def preparehttpserver(httpserver, ssl_cert):
327 327 > sslcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
328 328 > sslcontext.verify_mode = ssl.CERT_REQUIRED
329 329 > sslcontext.load_cert_chain(ssl_cert)
330 330 > # verify clients by server certificate
331 331 > sslcontext.load_verify_locations(ssl_cert)
332 332 > httpserver.socket = sslcontext.wrap_socket(httpserver.socket,
333 333 > server_side=True)
334 334 > server._httprequesthandlerssl = _httprequesthandlersslclientcert
335 335 > EOT
336 336 $ cd test
337 337 $ hg serve -p $HGPORT -d --pid-file=../hg0.pid --certificate=$PRIV \
338 338 > --config extensions.reqclientcert=../reqclientcert.py
339 339 $ cat ../hg0.pid >> $DAEMON_PIDS
340 340 $ cd ..
341 341
342 342 without client certificate:
343 343
344 344 $ P="$CERTSDIR" hg id https://localhost:$HGPORT/
345 345 abort: error: *handshake failure* (glob)
346 346 [255]
347 347
348 348 with client certificate:
349 349
350 350 $ cat << EOT >> $HGRCPATH
351 351 > [auth]
352 352 > l.prefix = localhost
353 353 > l.cert = $CERTSDIR/client-cert.pem
354 354 > l.key = $CERTSDIR/client-key.pem
355 355 > EOT
356 356
357 357 $ P="$CERTSDIR" hg id https://localhost:$HGPORT/ \
358 358 > --config auth.l.key="$CERTSDIR/client-key-decrypted.pem"
359 359 5fed3813f7f5
360 360
361 361 $ printf '1234\n' | env P="$CERTSDIR" hg id https://localhost:$HGPORT/ \
362 362 > --config ui.interactive=True --config ui.nontty=True
363 363 passphrase for */client-key.pem: 5fed3813f7f5 (glob)
364 364
365 365 $ env P="$CERTSDIR" hg id https://localhost:$HGPORT/
366 366 abort: error: * (glob)
367 367 [255]
368 368
369 369 #endif
General Comments 0
You need to be logged in to leave comments. Login now