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