##// END OF EJS Templates
tests: stop killing (most) https servers individually...
Matt Harbison -
r53183:e03bc887 default
parent child Browse files
Show More
@@ -1,597 +1,590
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 Disable the system configuration which may set stricter TLS requirements.
6 6 This test expects that legacy TLS versions are supported.
7 7
8 8 $ OPENSSL_CONF=
9 9 $ export OPENSSL_CONF
10 10
11 11 Make server certificates:
12 12
13 13 $ CERTSDIR="$TESTDIR/sslcerts"
14 14 $ cat "$CERTSDIR/priv.pem" "$CERTSDIR/pub.pem" >> server.pem
15 15 $ PRIV=`pwd`/server.pem
16 16 $ cat "$CERTSDIR/priv.pem" "$CERTSDIR/pub-not-yet.pem" > server-not-yet.pem
17 17 $ cat "$CERTSDIR/priv.pem" "$CERTSDIR/pub-expired.pem" > server-expired.pem
18 18
19 19 $ hg init test
20 20 $ cd test
21 21 $ echo foo>foo
22 22 $ mkdir foo.d foo.d/bAr.hg.d foo.d/baR.d.hg
23 23 $ echo foo>foo.d/foo
24 24 $ echo bar>foo.d/bAr.hg.d/BaR
25 25 $ echo bar>foo.d/baR.d.hg/bAR
26 26 $ hg commit -A -m 1
27 27 adding foo
28 28 adding foo.d/bAr.hg.d/BaR
29 29 adding foo.d/baR.d.hg/bAR
30 30 adding foo.d/foo
31 31 $ hg serve -p $HGPORT -d --pid-file=../hg0.pid --certificate=$PRIV
32 32 $ cat ../hg0.pid >> $DAEMON_PIDS
33 33
34 34 cacert not found
35 35
36 36 $ hg in --config web.cacerts=no-such.pem https://localhost:$HGPORT/
37 37 abort: could not find web.cacerts: no-such.pem
38 38 [255]
39 39
40 40 Test server address cannot be reused
41 41
42 42 $ hg serve -p $HGPORT --certificate=$PRIV 2>&1
43 43 abort: cannot start server at 'localhost:$HGPORT': $EADDRINUSE$
44 44 [255]
45 45
46 46 $ cd ..
47 47
48 48 Our test cert is not signed by a trusted CA. It should fail to verify if
49 49 we are able to load CA certs.
50 50
51 51 #if no-defaultcacertsloaded
52 52 $ hg clone https://localhost:$HGPORT/ copy-pull
53 53 (an attempt was made to load CA certificates but none were loaded; see https://mercurial-scm.org/wiki/SecureConnections for how to configure Mercurial to avoid this error)
54 54 abort: error: *certificate verify failed* (glob)
55 55 [100]
56 56 #endif
57 57
58 58 #if defaultcacertsloaded
59 59 $ hg clone https://localhost:$HGPORT/ copy-pull
60 60 (the full certificate chain may not be available locally; see "hg help debugssl") (windows !)
61 61 abort: error: *certificate verify failed* (glob)
62 62 [100]
63 63 #endif
64 64
65 65 Specifying a per-host certificate file that doesn't exist will abort. The full
66 66 C:/path/to/msysroot will print on Windows.
67 67
68 68 $ hg --config hostsecurity.localhost:verifycertsfile=/does/not/exist clone https://localhost:$HGPORT/
69 69 abort: path specified by hostsecurity.localhost:verifycertsfile does not exist: */does/not/exist (glob)
70 70 [255]
71 71
72 72 A malformed per-host certificate file will raise an error
73 73
74 74 $ echo baddata > badca.pem
75 75 $ hg --config hostsecurity.localhost:verifycertsfile=badca.pem clone https://localhost:$HGPORT/
76 76 abort: error loading CA file badca.pem: * (glob)
77 77 (file is empty or malformed?)
78 78 [255]
79 79
80 80 A per-host certificate mismatching the server will fail verification
81 81
82 82 (modern ssl is able to discern whether the loaded cert is a CA cert)
83 83 $ hg --config hostsecurity.localhost:verifycertsfile="$CERTSDIR/client-cert.pem" clone https://localhost:$HGPORT/
84 84 (an attempt was made to load CA certificates but none were loaded; see https://mercurial-scm.org/wiki/SecureConnections for how to configure Mercurial to avoid this error)
85 85 (the full certificate chain may not be available locally; see "hg help debugssl") (windows !)
86 86 abort: error: *certificate verify failed* (glob)
87 87 [100]
88 88
89 89 A per-host certificate matching the server's cert will be accepted
90 90
91 91 $ hg --config hostsecurity.localhost:verifycertsfile="$CERTSDIR/pub.pem" clone -U https://localhost:$HGPORT/ perhostgood1
92 92 requesting all changes
93 93 adding changesets
94 94 adding manifests
95 95 adding file changes
96 96 added 1 changesets with 4 changes to 4 files
97 97 new changesets 8b6053c928fe
98 98
99 99 A per-host certificate with multiple certs and one matching will be accepted
100 100
101 101 $ cat "$CERTSDIR/client-cert.pem" "$CERTSDIR/pub.pem" > perhost.pem
102 102 $ hg --config hostsecurity.localhost:verifycertsfile=perhost.pem clone -U https://localhost:$HGPORT/ perhostgood2
103 103 requesting all changes
104 104 adding changesets
105 105 adding manifests
106 106 adding file changes
107 107 added 1 changesets with 4 changes to 4 files
108 108 new changesets 8b6053c928fe
109 109
110 110 Defining both per-host certificate and a fingerprint will print a warning
111 111
112 112 $ hg --config hostsecurity.localhost:verifycertsfile="$CERTSDIR/pub.pem" --config hostsecurity.localhost:fingerprints=sha1:ecd87cd6b386d04fc1b8b41c9d8f5e168eef1c03 clone -U https://localhost:$HGPORT/ caandfingerwarning
113 113 (hostsecurity.localhost:verifycertsfile ignored when host fingerprints defined; using host fingerprints for verification)
114 114 requesting all changes
115 115 adding changesets
116 116 adding manifests
117 117 adding file changes
118 118 added 1 changesets with 4 changes to 4 files
119 119 new changesets 8b6053c928fe
120 120
121 121 $ DISABLECACERTS="--config devel.disableloaddefaultcerts=true"
122 122
123 123 Inability to verify peer certificate will result in abort
124 124
125 125 $ hg clone https://localhost:$HGPORT/ copy-pull $DISABLECACERTS
126 126 abort: unable to verify security of localhost (no loaded CA certificates); refusing to connect
127 127 (see https://mercurial-scm.org/wiki/SecureConnections for how to configure Mercurial to avoid this error or set hostsecurity.localhost:fingerprints=sha256:20:de:b3:ad:b4:cd:a5:42:f0:74:41:1c:a2:70:1e:da:6e:c0:5c:16:9e:e7:22:0f:f1:b7:e5:6e:e4:92:af:7e to trust this server)
128 128 [150]
129 129
130 130 $ hg clone --insecure https://localhost:$HGPORT/ copy-pull
131 131 warning: connection security to localhost is disabled per current settings; communication is susceptible to eavesdropping and tampering
132 132 requesting all changes
133 133 adding changesets
134 134 adding manifests
135 135 adding file changes
136 136 added 1 changesets with 4 changes to 4 files
137 137 new changesets 8b6053c928fe
138 138 updating to branch default
139 139 4 files updated, 0 files merged, 0 files removed, 0 files unresolved
140 140 $ hg verify -R copy-pull -q
141 141 $ cd test
142 142 $ echo bar > bar
143 143 $ hg commit -A -d '1 0' -m 2
144 144 adding bar
145 145 $ cd ..
146 146
147 147 pull without cacert
148 148
149 149 $ cd copy-pull
150 150 $ cat >> .hg/hgrc <<EOF
151 151 > [hooks]
152 152 > changegroup = sh -c "printenv.py --line changegroup"
153 153 > EOF
154 154 $ hg pull $DISABLECACERTS
155 155 pulling from https://localhost:$HGPORT/
156 156 abort: unable to verify security of localhost (no loaded CA certificates); refusing to connect
157 157 (see https://mercurial-scm.org/wiki/SecureConnections for how to configure Mercurial to avoid this error or set hostsecurity.localhost:fingerprints=sha256:20:de:b3:ad:b4:cd:a5:42:f0:74:41:1c:a2:70:1e:da:6e:c0:5c:16:9e:e7:22:0f:f1:b7:e5:6e:e4:92:af:7e to trust this server)
158 158 [150]
159 159
160 160 $ hg pull --insecure
161 161 pulling from https://localhost:$HGPORT/
162 162 warning: connection security to localhost is disabled per current settings; communication is susceptible to eavesdropping and tampering
163 163 searching for changes
164 164 adding changesets
165 165 adding manifests
166 166 adding file changes
167 167 added 1 changesets with 1 changes to 1 files
168 168 new changesets 5fed3813f7f5
169 169 changegroup hook: HG_HOOKNAME=changegroup
170 170 HG_HOOKTYPE=changegroup
171 171 HG_NODE=5fed3813f7f5e1824344fdc9cf8f63bb662c292d
172 172 HG_NODE_LAST=5fed3813f7f5e1824344fdc9cf8f63bb662c292d
173 173 HG_SOURCE=pull
174 174 HG_TXNID=TXN:$ID$
175 175 HG_TXNNAME=pull
176 176 https://localhost:$HGPORT/
177 177 HG_URL=https://localhost:$HGPORT/
178 178
179 179 (run 'hg update' to get a working copy)
180 180 $ cd ..
181 181
182 182 cacert configured in local repo
183 183
184 184 $ cp copy-pull/.hg/hgrc copy-pull/.hg/hgrc.bu
185 185 $ echo "[web]" >> copy-pull/.hg/hgrc
186 186 $ echo "cacerts=$CERTSDIR/pub.pem" >> copy-pull/.hg/hgrc
187 187 $ hg -R copy-pull pull
188 188 pulling from https://localhost:$HGPORT/
189 189 searching for changes
190 190 no changes found
191 191 $ mv copy-pull/.hg/hgrc.bu copy-pull/.hg/hgrc
192 192
193 193 cacert configured globally, also testing expansion of environment
194 194 variables in the filename
195 195
196 196 $ echo "[web]" >> $HGRCPATH
197 197 $ echo 'cacerts=$P/pub.pem' >> $HGRCPATH
198 198 $ P="$CERTSDIR" hg -R copy-pull pull
199 199 pulling from https://localhost:$HGPORT/
200 200 searching for changes
201 201 no changes found
202 202 $ P="$CERTSDIR" hg -R copy-pull pull --insecure
203 203 pulling from https://localhost:$HGPORT/
204 204 warning: connection security to localhost is disabled per current settings; communication is susceptible to eavesdropping and tampering
205 205 searching for changes
206 206 no changes found
207 207
208 208 empty cacert file
209 209
210 210 $ touch emptycafile
211 211
212 212 $ hg --config web.cacerts=emptycafile -R copy-pull pull
213 213 pulling from https://localhost:$HGPORT/
214 214 abort: error loading CA file emptycafile: * (glob)
215 215 (file is empty or malformed?)
216 216 [255]
217 217
218 218 cacert mismatch
219 219
220 220 $ hg -R copy-pull pull --config web.cacerts="$CERTSDIR/pub.pem" \
221 221 > https://$LOCALIP:$HGPORT/
222 222 pulling from https://*:$HGPORT/ (glob)
223 223 abort: $LOCALIP certificate error: certificate is for localhost (glob)
224 224 (set hostsecurity.$LOCALIP:certfingerprints=sha256:20:de:b3:ad:b4:cd:a5:42:f0:74:41:1c:a2:70:1e:da:6e:c0:5c:16:9e:e7:22:0f:f1:b7:e5:6e:e4:92:af:7e config setting or use --insecure to connect insecurely)
225 225 [150]
226 226 $ hg -R copy-pull pull --config web.cacerts="$CERTSDIR/pub.pem" \
227 227 > https://$LOCALIP:$HGPORT/ --insecure
228 228 pulling from https://*:$HGPORT/ (glob)
229 229 warning: connection security to $LOCALIP is disabled per current settings; communication is susceptible to eavesdropping and tampering (glob)
230 230 searching for changes
231 231 no changes found
232 232 $ hg -R copy-pull pull --config web.cacerts="$CERTSDIR/pub-other.pem"
233 233 pulling from https://localhost:$HGPORT/
234 234 (the full certificate chain may not be available locally; see "hg help debugssl") (windows !)
235 235 abort: error: *certificate verify failed* (glob)
236 236 [100]
237 237 $ hg -R copy-pull pull --config web.cacerts="$CERTSDIR/pub-other.pem" \
238 238 > --insecure
239 239 pulling from https://localhost:$HGPORT/
240 240 warning: connection security to localhost is disabled per current settings; communication is susceptible to eavesdropping and tampering
241 241 searching for changes
242 242 no changes found
243 243
244 244 Test server cert which isn't valid yet
245 245
246 246 $ hg serve -R test -p $HGPORT1 -d --pid-file=hg1.pid --certificate=server-not-yet.pem
247 247 $ cat hg1.pid >> $DAEMON_PIDS
248 248 $ hg -R copy-pull pull --config web.cacerts="$CERTSDIR/pub-not-yet.pem" \
249 249 > https://localhost:$HGPORT1/
250 250 pulling from https://localhost:$HGPORT1/
251 251 (the full certificate chain may not be available locally; see "hg help debugssl") (windows !)
252 252 abort: error: *certificate verify failed* (glob)
253 253 [100]
254 254
255 255 Test server cert which no longer is valid
256 256
257 257 $ hg serve -R test -p $HGPORT2 -d --pid-file=hg2.pid --certificate=server-expired.pem
258 258 $ cat hg2.pid >> $DAEMON_PIDS
259 259 $ hg -R copy-pull pull --config web.cacerts="$CERTSDIR/pub-expired.pem" \
260 260 > https://localhost:$HGPORT2/
261 261 pulling from https://localhost:$HGPORT2/
262 262 (the full certificate chain may not be available locally; see "hg help debugssl") (windows !)
263 263 abort: error: *certificate verify failed* (glob)
264 264 [100]
265 265
266 266 Setting ciphers to an invalid value aborts
267 267 $ P="$CERTSDIR" hg --config hostsecurity.ciphers=invalid -R copy-pull id https://localhost:$HGPORT/
268 268 abort: could not set ciphers: No cipher can be selected.
269 269 (change cipher string (invalid) in config)
270 270 [255]
271 271
272 272 $ P="$CERTSDIR" hg --config hostsecurity.localhost:ciphers=invalid -R copy-pull id https://localhost:$HGPORT/
273 273 abort: could not set ciphers: No cipher can be selected.
274 274 (change cipher string (invalid) in config)
275 275 [255]
276 276
277 277 Changing the cipher string works
278 278
279 279 $ P="$CERTSDIR" hg --config hostsecurity.ciphers=HIGH -R copy-pull id https://localhost:$HGPORT/
280 280 5fed3813f7f5
281 281
282 282 Fingerprints
283 283
284 284 - works without cacerts (hostfingerprints)
285 285 $ hg -R copy-pull id https://localhost:$HGPORT/ --insecure --config hostfingerprints.localhost=ec:d8:7c:d6:b3:86:d0:4f:c1:b8:b4:1c:9d:8f:5e:16:8e:ef:1c:03
286 286 (SHA-1 fingerprint for localhost found in legacy [hostfingerprints] section; if you trust this fingerprint, remove the old SHA-1 fingerprint from [hostfingerprints] and add the following entry to the new [hostsecurity] section: localhost:fingerprints=sha256:20:de:b3:ad:b4:cd:a5:42:f0:74:41:1c:a2:70:1e:da:6e:c0:5c:16:9e:e7:22:0f:f1:b7:e5:6e:e4:92:af:7e)
287 287 5fed3813f7f5
288 288
289 289 - works without cacerts (hostsecurity)
290 290 $ hg -R copy-pull id https://localhost:$HGPORT/ --config hostsecurity.localhost:fingerprints=sha1:ecd87cd6b386d04fc1b8b41c9d8f5e168eef1c03
291 291 5fed3813f7f5
292 292
293 293 $ hg -R copy-pull id https://localhost:$HGPORT/ --config hostsecurity.localhost:fingerprints=sha256:20:de:b3:ad:b4:cd:a5:42:f0:74:41:1c:a2:70:1e:da:6e:c0:5c:16:9e:e7:22:0f:f1:b7:e5:6e:e4:92:af:7e
294 294 5fed3813f7f5
295 295
296 296 - multiple fingerprints specified and first matches
297 297 $ hg --config 'hostfingerprints.localhost=ecd87cd6b386d04fc1b8b41c9d8f5e168eef1c03, deadbeefdeadbeefdeadbeefdeadbeefdeadbeef' -R copy-pull id https://localhost:$HGPORT/ --insecure
298 298 (SHA-1 fingerprint for localhost found in legacy [hostfingerprints] section; if you trust this fingerprint, remove the old SHA-1 fingerprint from [hostfingerprints] and add the following entry to the new [hostsecurity] section: localhost:fingerprints=sha256:20:de:b3:ad:b4:cd:a5:42:f0:74:41:1c:a2:70:1e:da:6e:c0:5c:16:9e:e7:22:0f:f1:b7:e5:6e:e4:92:af:7e)
299 299 5fed3813f7f5
300 300
301 301 $ hg --config 'hostsecurity.localhost:fingerprints=sha1:ecd87cd6b386d04fc1b8b41c9d8f5e168eef1c03, sha1:deadbeefdeadbeefdeadbeefdeadbeefdeadbeef' -R copy-pull id https://localhost:$HGPORT/
302 302 5fed3813f7f5
303 303
304 304 - multiple fingerprints specified and last matches
305 305 $ hg --config 'hostfingerprints.localhost=deadbeefdeadbeefdeadbeefdeadbeefdeadbeef, ecd87cd6b386d04fc1b8b41c9d8f5e168eef1c03' -R copy-pull id https://localhost:$HGPORT/ --insecure
306 306 (SHA-1 fingerprint for localhost found in legacy [hostfingerprints] section; if you trust this fingerprint, remove the old SHA-1 fingerprint from [hostfingerprints] and add the following entry to the new [hostsecurity] section: localhost:fingerprints=sha256:20:de:b3:ad:b4:cd:a5:42:f0:74:41:1c:a2:70:1e:da:6e:c0:5c:16:9e:e7:22:0f:f1:b7:e5:6e:e4:92:af:7e)
307 307 5fed3813f7f5
308 308
309 309 $ hg --config 'hostsecurity.localhost:fingerprints=sha1:deadbeefdeadbeefdeadbeefdeadbeefdeadbeef, sha1:ecd87cd6b386d04fc1b8b41c9d8f5e168eef1c03' -R copy-pull id https://localhost:$HGPORT/
310 310 5fed3813f7f5
311 311
312 312 - multiple fingerprints specified and none match
313 313
314 314 $ hg --config 'hostfingerprints.localhost=deadbeefdeadbeefdeadbeefdeadbeefdeadbeef, aeadbeefdeadbeefdeadbeefdeadbeefdeadbeef' -R copy-pull id https://localhost:$HGPORT/ --insecure
315 315 abort: certificate for localhost has unexpected fingerprint ec:d8:7c:d6:b3:86:d0:4f:c1:b8:b4:1c:9d:8f:5e:16:8e:ef:1c:03
316 316 (check hostfingerprint configuration)
317 317 [150]
318 318
319 319 $ hg --config 'hostsecurity.localhost:fingerprints=sha1:deadbeefdeadbeefdeadbeefdeadbeefdeadbeef, sha1:aeadbeefdeadbeefdeadbeefdeadbeefdeadbeef' -R copy-pull id https://localhost:$HGPORT/
320 320 abort: certificate for localhost has unexpected fingerprint sha1:ec:d8:7c:d6:b3:86:d0:4f:c1:b8:b4:1c:9d:8f:5e:16:8e:ef:1c:03
321 321 (check hostsecurity configuration)
322 322 [150]
323 323
324 324 - fails when cert doesn't match hostname (port is ignored)
325 325 $ hg -R copy-pull id https://localhost:$HGPORT1/ --config hostfingerprints.localhost=ecd87cd6b386d04fc1b8b41c9d8f5e168eef1c03
326 326 abort: certificate for localhost has unexpected fingerprint f4:2f:5a:0c:3e:52:5b:db:e7:24:a8:32:1d:18:97:6d:69:b5:87:84
327 327 (check hostfingerprint configuration)
328 328 [150]
329 329
330 330
331 331 - ignores that certificate doesn't match hostname
332 332 $ hg -R copy-pull id https://$LOCALIP:$HGPORT/ --config hostfingerprints.$LOCALIP=ecd87cd6b386d04fc1b8b41c9d8f5e168eef1c03
333 333 (SHA-1 fingerprint for $LOCALIP found in legacy [hostfingerprints] section; if you trust this fingerprint, remove the old SHA-1 fingerprint from [hostfingerprints] and add the following entry to the new [hostsecurity] section: $LOCALIP:fingerprints=sha256:20:de:b3:ad:b4:cd:a5:42:f0:74:41:1c:a2:70:1e:da:6e:c0:5c:16:9e:e7:22:0f:f1:b7:e5:6e:e4:92:af:7e)
334 334 5fed3813f7f5
335 335
336 336 Ports used by next test. Kill servers.
337 337
338 $ killdaemons.py hg0.pid
339 $ killdaemons.py hg1.pid
340 $ killdaemons.py hg2.pid
338 $ killdaemons.py $DAEMON_PIDS
341 339
342 340 #if tls1.2
343 341 Start servers running supported TLS versions
344 342
345 343 $ cd test
346 344 $ hg serve -p $HGPORT -d --pid-file=../hg0.pid --certificate=$PRIV \
347 345 > --config devel.server-insecure-exact-protocol=tls1.0
348 346 $ cat ../hg0.pid >> $DAEMON_PIDS
349 347 $ hg serve -p $HGPORT1 -d --pid-file=../hg1.pid --certificate=$PRIV \
350 348 > --config devel.server-insecure-exact-protocol=tls1.1
351 349 $ cat ../hg1.pid >> $DAEMON_PIDS
352 350 $ hg serve -p $HGPORT2 -d --pid-file=../hg2.pid --certificate=$PRIV \
353 351 > --config devel.server-insecure-exact-protocol=tls1.2
354 352 $ cat ../hg2.pid >> $DAEMON_PIDS
355 353 #if tls1.3
356 354 $ hg serve -p $HGPORT3 -d --pid-file=../hg3.pid --certificate=$PRIV \
357 355 > --config devel.server-insecure-exact-protocol=tls1.3
358 356 $ cat ../hg3.pid >> $DAEMON_PIDS
359 357 #endif
360 358 $ cd ..
361 359
362 360 Clients talking same TLS versions work
363 361
364 362 $ P="$CERTSDIR" hg --config hostsecurity.minimumprotocol=tls1.0 --config hostsecurity.ciphers="DEFAULT:@SECLEVEL=0" id https://localhost:$HGPORT/
365 363 5fed3813f7f5
366 364 $ P="$CERTSDIR" hg --config hostsecurity.minimumprotocol=tls1.1 --config hostsecurity.ciphers="DEFAULT:@SECLEVEL=0" id https://localhost:$HGPORT1/
367 365 5fed3813f7f5
368 366 $ P="$CERTSDIR" hg --config hostsecurity.minimumprotocol=tls1.2 id https://localhost:$HGPORT2/
369 367 5fed3813f7f5
370 368 #if tls1.3
371 369 $ P="$CERTSDIR" hg --config hostsecurity.minimumprotocol=tls1.3 id https://localhost:$HGPORT3/
372 370 5fed3813f7f5
373 371 #endif
374 372
375 373 Clients requiring newer TLS version than what server supports fail
376 374
377 375 $ P="$CERTSDIR" hg id https://localhost:$HGPORT/
378 376 (could not negotiate a common security protocol (tls1.1+) with localhost; the likely cause is Mercurial is configured to be more secure than the server can support)
379 377 (consider contacting the operator of this server and ask them to support modern TLS protocol versions; or, set hostsecurity.localhost:minimumprotocol=tls1.0 to allow use of legacy, less secure protocols when communicating with this server)
380 378 (see https://mercurial-scm.org/wiki/SecureConnections for more info)
381 379 abort: error: .*(unsupported protocol|wrong ssl version|alert protocol version).* (re)
382 380 [100]
383 381
384 382 $ P="$CERTSDIR" hg --config hostsecurity.minimumprotocol=tls1.1 id https://localhost:$HGPORT/
385 383 (could not negotiate a common security protocol (tls1.1+) with localhost; the likely cause is Mercurial is configured to be more secure than the server can support)
386 384 (consider contacting the operator of this server and ask them to support modern TLS protocol versions; or, set hostsecurity.localhost:minimumprotocol=tls1.0 to allow use of legacy, less secure protocols when communicating with this server)
387 385 (see https://mercurial-scm.org/wiki/SecureConnections for more info)
388 386 abort: error: .*(unsupported protocol|wrong ssl version|alert protocol version).* (re)
389 387 [100]
390 388 $ P="$CERTSDIR" hg --config hostsecurity.minimumprotocol=tls1.2 id https://localhost:$HGPORT/
391 389 (could not negotiate a common security protocol (tls1.2+) with localhost; the likely cause is Mercurial is configured to be more secure than the server can support)
392 390 (consider contacting the operator of this server and ask them to support modern TLS protocol versions; or, set hostsecurity.localhost:minimumprotocol=tls1.0 to allow use of legacy, less secure protocols when communicating with this server)
393 391 (see https://mercurial-scm.org/wiki/SecureConnections for more info)
394 392 abort: error: .*(unsupported protocol|wrong ssl version|alert protocol version).* (re)
395 393 [100]
396 394 $ P="$CERTSDIR" hg --config hostsecurity.minimumprotocol=tls1.2 id https://localhost:$HGPORT1/
397 395 (could not negotiate a common security protocol (tls1.2+) with localhost; the likely cause is Mercurial is configured to be more secure than the server can support)
398 396 (consider contacting the operator of this server and ask them to support modern TLS protocol versions; or, set hostsecurity.localhost:minimumprotocol=tls1.0 to allow use of legacy, less secure protocols when communicating with this server)
399 397 (see https://mercurial-scm.org/wiki/SecureConnections for more info)
400 398 abort: error: .*(unsupported protocol|wrong ssl version|alert protocol version).* (re)
401 399 [100]
402 400
403 401 #if tls1.3
404 402 $ P="$CERTSDIR" hg --config hostsecurity.minimumprotocol=tls1.3 id https://localhost:$HGPORT/
405 403 (could not negotiate a common security protocol (tls1.3+) with localhost; the likely cause is Mercurial is configured to be more secure than the server can support)
406 404 (consider contacting the operator of this server and ask them to support modern TLS protocol versions; or, set hostsecurity.localhost:minimumprotocol=tls1.0 to allow use of legacy, less secure protocols when communicating with this server)
407 405 (see https://mercurial-scm.org/wiki/SecureConnections for more info)
408 406 abort: error: .*(unsupported protocol|wrong ssl version|alert protocol version).* (re)
409 407 [100]
410 408 $ P="$CERTSDIR" hg --config hostsecurity.minimumprotocol=tls1.3 id https://localhost:$HGPORT1/
411 409 (could not negotiate a common security protocol (tls1.3+) with localhost; the likely cause is Mercurial is configured to be more secure than the server can support)
412 410 (consider contacting the operator of this server and ask them to support modern TLS protocol versions; or, set hostsecurity.localhost:minimumprotocol=tls1.0 to allow use of legacy, less secure protocols when communicating with this server)
413 411 (see https://mercurial-scm.org/wiki/SecureConnections for more info)
414 412 abort: error: .*(unsupported protocol|wrong ssl version|alert protocol version).* (re)
415 413 [100]
416 414 $ P="$CERTSDIR" hg --config hostsecurity.minimumprotocol=tls1.3 id https://localhost:$HGPORT2/
417 415 (could not negotiate a common security protocol (tls1.3+) with localhost; the likely cause is Mercurial is configured to be more secure than the server can support)
418 416 (consider contacting the operator of this server and ask them to support modern TLS protocol versions; or, set hostsecurity.localhost:minimumprotocol=tls1.0 to allow use of legacy, less secure protocols when communicating with this server)
419 417 (see https://mercurial-scm.org/wiki/SecureConnections for more info)
420 418 abort: error: .*(unsupported protocol|wrong ssl version|alert protocol version).* (re)
421 419 [100]
422 420 #endif
423 421
424 422
425 423 --insecure will allow TLS 1.0 connections and override configs
426 424
427 425 $ hg --config hostsecurity.minimumprotocol=tls1.2 id --insecure https://localhost:$HGPORT1/
428 426 warning: connection security to localhost is disabled per current settings; communication is susceptible to eavesdropping and tampering
429 427 5fed3813f7f5
430 428
431 429 #if tls1.3
432 430 $ hg --config hostsecurity.minimumprotocol=tls1.3 id --insecure https://localhost:$HGPORT2/
433 431 warning: connection security to localhost is disabled per current settings; communication is susceptible to eavesdropping and tampering
434 432 5fed3813f7f5
435 433 #endif
436 434
437 435 The per-host config option overrides the default
438 436
439 437 $ P="$CERTSDIR" hg id https://localhost:$HGPORT/ \
440 438 > --config hostsecurity.ciphers="DEFAULT:@SECLEVEL=0" \
441 439 > --config hostsecurity.minimumprotocol=tls1.2 \
442 440 > --config hostsecurity.localhost:minimumprotocol=tls1.0
443 441 5fed3813f7f5
444 442
445 443 The per-host config option by itself works
446 444
447 445 $ P="$CERTSDIR" hg id https://localhost:$HGPORT/ \
448 446 > --config hostsecurity.localhost:minimumprotocol=tls1.2
449 447 (could not negotiate a common security protocol (tls1.2+) with localhost; the likely cause is Mercurial is configured to be more secure than the server can support)
450 448 (consider contacting the operator of this server and ask them to support modern TLS protocol versions; or, set hostsecurity.localhost:minimumprotocol=tls1.0 to allow use of legacy, less secure protocols when communicating with this server)
451 449 (see https://mercurial-scm.org/wiki/SecureConnections for more info)
452 450 abort: error: .*(unsupported protocol|wrong ssl version|alert protocol version).* (re)
453 451 [100]
454 452
455 453 .hg/hgrc file [hostsecurity] settings are applied to remote ui instances (issue5305)
456 454
457 455 $ cat >> copy-pull/.hg/hgrc << EOF
458 456 > [hostsecurity]
459 457 > localhost:minimumprotocol=tls1.2
460 458 > EOF
461 459 $ P="$CERTSDIR" hg -R copy-pull id https://localhost:$HGPORT/
462 460 (could not negotiate a common security protocol (tls1.2+) with localhost; the likely cause is Mercurial is configured to be more secure than the server can support)
463 461 (consider contacting the operator of this server and ask them to support modern TLS protocol versions; or, set hostsecurity.localhost:minimumprotocol=tls1.0 to allow use of legacy, less secure protocols when communicating with this server)
464 462 (see https://mercurial-scm.org/wiki/SecureConnections for more info)
465 463 abort: error: .*(unsupported protocol|wrong ssl version|alert protocol version).* (re)
466 464 [100]
467 465
468 $ killdaemons.py hg0.pid
469 $ killdaemons.py hg1.pid
470 $ killdaemons.py hg2.pid
471 #if tls1.3
472 $ killdaemons.py hg3.pid
473 #endif
466 $ killdaemons.py $DAEMON_PIDS
474 467 #endif
475 468
476 469 Prepare for connecting through proxy
477 470
478 471 $ hg serve -R test -p $HGPORT -d --pid-file=hg0.pid --certificate=$PRIV
479 472 $ cat hg0.pid >> $DAEMON_PIDS
480 473 $ hg serve -R test -p $HGPORT2 -d --pid-file=hg2.pid --certificate=server-expired.pem
481 474 $ cat hg2.pid >> $DAEMON_PIDS
482 475 tinyproxy.py doesn't fully detach, so killing it may result in extra output
483 476 from the shell. So don't kill it.
484 477 $ tinyproxy.py $HGPORT1 localhost >proxy.log </dev/null 2>&1 &
485 478 $ while [ ! -f proxy.pid ]; do sleep 0; done
486 479 $ cat proxy.pid >> $DAEMON_PIDS
487 480
488 481 $ echo "[http_proxy]" >> copy-pull/.hg/hgrc
489 482 $ echo "always=True" >> copy-pull/.hg/hgrc
490 483 $ echo "[hostfingerprints]" >> copy-pull/.hg/hgrc
491 484 $ echo "localhost =" >> copy-pull/.hg/hgrc
492 485
493 486 Test unvalidated https through proxy
494 487
495 488 $ http_proxy=http://localhost:$HGPORT1/ hg -R copy-pull pull --insecure
496 489 pulling from https://localhost:$HGPORT/
497 490 warning: connection security to localhost is disabled per current settings; communication is susceptible to eavesdropping and tampering
498 491 searching for changes
499 492 no changes found
500 493
501 494 Test https with cacert and fingerprint through proxy
502 495
503 496 $ http_proxy=http://localhost:$HGPORT1/ hg -R copy-pull pull \
504 497 > --config web.cacerts="$CERTSDIR/pub.pem"
505 498 pulling from https://localhost:$HGPORT/
506 499 searching for changes
507 500 no changes found
508 501 $ http_proxy=http://localhost:$HGPORT1/ hg -R copy-pull pull https://localhost:$HGPORT/ --config hostfingerprints.localhost=ecd87cd6b386d04fc1b8b41c9d8f5e168eef1c03 --trace
509 502 pulling from https://*:$HGPORT/ (glob)
510 503 (SHA-1 fingerprint for localhost found in legacy [hostfingerprints] section; if you trust this fingerprint, remove the old SHA-1 fingerprint from [hostfingerprints] and add the following entry to the new [hostsecurity] section: localhost:fingerprints=sha256:20:de:b3:ad:b4:cd:a5:42:f0:74:41:1c:a2:70:1e:da:6e:c0:5c:16:9e:e7:22:0f:f1:b7:e5:6e:e4:92:af:7e)
511 504 searching for changes
512 505 no changes found
513 506
514 507 Test https with cert problems through proxy
515 508
516 509 $ http_proxy=http://localhost:$HGPORT1/ hg -R copy-pull pull \
517 510 > --config web.cacerts="$CERTSDIR/pub-other.pem"
518 511 pulling from https://localhost:$HGPORT/
519 512 (the full certificate chain may not be available locally; see "hg help debugssl") (windows !)
520 513 abort: error: *certificate verify failed* (glob)
521 514 [100]
522 515 $ http_proxy=http://localhost:$HGPORT1/ hg -R copy-pull pull \
523 516 > --config web.cacerts="$CERTSDIR/pub-expired.pem" https://localhost:$HGPORT2/
524 517 pulling from https://localhost:$HGPORT2/
525 518 (the full certificate chain may not be available locally; see "hg help debugssl") (windows !)
526 519 abort: error: *certificate verify failed* (glob)
527 520 [100]
528 521
529 522 Test when proxy can't connect to server
530 523
531 524 $ http_proxy=http://localhost:$HGPORT1/ hg -R copy-pull pull --insecure https://localhost:0/
532 525 pulling from https://localhost:0/
533 526 abort: error: Tunnel connection failed: 404 (\$ECONNREFUSED\$|\$EADDRNOTAVAIL\$) (re)
534 527 [100]
535 528
536 529
537 530 $ killdaemons.py hg0.pid
538 531
539 532 $ cd test
540 533
541 534 Missing certificate file(s) are detected
542 535
543 536 $ hg serve -p $HGPORT --certificate=/missing/certificate \
544 537 > --config devel.servercafile=$PRIV --config devel.serverrequirecert=true
545 538 abort: referenced certificate file (*/missing/certificate) does not exist (glob)
546 539 [255]
547 540
548 541 $ hg serve -p $HGPORT --certificate=$PRIV \
549 542 > --config devel.servercafile=/missing/cafile --config devel.serverrequirecert=true
550 543 abort: referenced certificate file (*/missing/cafile) does not exist (glob)
551 544 [255]
552 545
553 546 Start hgweb that requires client certificates:
554 547
555 548 $ hg serve -p $HGPORT -d --pid-file=../hg0.pid --certificate=$PRIV \
556 549 > --config devel.servercafile=$PRIV --config devel.serverrequirecert=true
557 550 $ cat ../hg0.pid >> $DAEMON_PIDS
558 551 $ cd ..
559 552
560 553 without client certificate:
561 554
562 555 $ P="$CERTSDIR" hg id https://localhost:$HGPORT/
563 556 abort: error: .*(\$ECONNRESET\$|certificate required|handshake failure|EOF occurred).* (re)
564 557 [100]
565 558
566 559 with client certificate:
567 560
568 561 $ cat << EOT >> $HGRCPATH
569 562 > [auth]
570 563 > l.prefix = localhost
571 564 > l.cert = $CERTSDIR/client-cert.pem
572 565 > l.key = $CERTSDIR/client-key.pem
573 566 > EOT
574 567
575 568 $ P="$CERTSDIR" hg id https://localhost:$HGPORT/ \
576 569 > --config auth.l.key="$CERTSDIR/client-key-decrypted.pem"
577 570 5fed3813f7f5
578 571
579 572 $ printf '1234\n' | env P="$CERTSDIR" hg id https://localhost:$HGPORT/ \
580 573 > --config ui.interactive=True --config ui.nontty=True
581 574 passphrase for */client-key.pem: 5fed3813f7f5 (glob)
582 575
583 576 $ env P="$CERTSDIR" hg id https://localhost:$HGPORT/
584 577 abort: error: * (glob)
585 578 [100]
586 579
587 580 Missing certficate and key files result in error
588 581
589 582 $ hg id https://localhost:$HGPORT/ --config auth.l.cert=/missing/cert
590 583 abort: certificate file (*/missing/cert) does not exist; cannot connect to localhost (glob)
591 584 (restore missing file or fix references in Mercurial config)
592 585 [255]
593 586
594 587 $ hg id https://localhost:$HGPORT/ --config auth.l.key=/missing/key
595 588 abort: certificate file (*/missing/key) does not exist; cannot connect to localhost (glob)
596 589 (restore missing file or fix references in Mercurial config)
597 590 [255]
General Comments 0
You need to be logged in to leave comments. Login now