Show More
@@ -1,138 +1,139 b'' | |||
|
1 | 1 | # sslutil.py - SSL handling for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005, 2006, 2007, 2008 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # Copyright 2006, 2007 Alexis S. L. Carvalho <alexis@cecm.usp.br> |
|
5 | 5 | # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com> |
|
6 | 6 | # |
|
7 | 7 | # This software may be used and distributed according to the terms of the |
|
8 | 8 | # GNU General Public License version 2 or any later version. |
|
9 | 9 | import os |
|
10 | 10 | |
|
11 | 11 | from mercurial import util |
|
12 | 12 | from mercurial.i18n import _ |
|
13 | 13 | try: |
|
14 | 14 | # avoid using deprecated/broken FakeSocket in python 2.6 |
|
15 | 15 | import ssl |
|
16 | 16 | CERT_REQUIRED = ssl.CERT_REQUIRED |
|
17 | 17 | def ssl_wrap_socket(sock, keyfile, certfile, |
|
18 | 18 | cert_reqs=ssl.CERT_NONE, ca_certs=None): |
|
19 | 19 | sslsocket = ssl.wrap_socket(sock, keyfile, certfile, |
|
20 | 20 | cert_reqs=cert_reqs, ca_certs=ca_certs) |
|
21 | 21 | # check if wrap_socket failed silently because socket had been closed |
|
22 | 22 | # - see http://bugs.python.org/issue13721 |
|
23 | 23 | if not sslsocket.cipher(): |
|
24 | 24 | raise util.Abort(_('ssl connection failed')) |
|
25 | 25 | return sslsocket |
|
26 | 26 | except ImportError: |
|
27 | 27 | CERT_REQUIRED = 2 |
|
28 | 28 | |
|
29 | 29 | import socket, httplib |
|
30 | 30 | |
|
31 | 31 | def ssl_wrap_socket(sock, key_file, cert_file, |
|
32 | 32 | cert_reqs=CERT_REQUIRED, ca_certs=None): |
|
33 | 33 | if not util.safehasattr(socket, 'ssl'): |
|
34 | 34 | raise util.Abort(_('Python SSL support not found')) |
|
35 | 35 | if ca_certs: |
|
36 | 36 | raise util.Abort(_( |
|
37 | 37 | 'certificate checking requires Python 2.6')) |
|
38 | 38 | |
|
39 | 39 | ssl = socket.ssl(sock, key_file, cert_file) |
|
40 | 40 | return httplib.FakeSocket(sock, ssl) |
|
41 | 41 | |
|
42 | 42 | def _verifycert(cert, hostname): |
|
43 | 43 | '''Verify that cert (in socket.getpeercert() format) matches hostname. |
|
44 | 44 | CRLs is not handled. |
|
45 | 45 | |
|
46 | 46 | Returns error message if any problems are found and None on success. |
|
47 | 47 | ''' |
|
48 | 48 | if not cert: |
|
49 | 49 | return _('no certificate received') |
|
50 | 50 | dnsname = hostname.lower() |
|
51 | 51 | def matchdnsname(certname): |
|
52 | 52 | return (certname == dnsname or |
|
53 | 53 | '.' in dnsname and certname == '*.' + dnsname.split('.', 1)[1]) |
|
54 | 54 | |
|
55 | 55 | san = cert.get('subjectAltName', []) |
|
56 | 56 | if san: |
|
57 | 57 | certnames = [value.lower() for key, value in san if key == 'DNS'] |
|
58 | 58 | for name in certnames: |
|
59 | 59 | if matchdnsname(name): |
|
60 | 60 | return None |
|
61 | 61 | if certnames: |
|
62 | 62 | return _('certificate is for %s') % ', '.join(certnames) |
|
63 | 63 | |
|
64 | 64 | # subject is only checked when subjectAltName is empty |
|
65 | 65 | for s in cert.get('subject', []): |
|
66 | 66 | key, value = s[0] |
|
67 | 67 | if key == 'commonName': |
|
68 | 68 | try: |
|
69 | 69 | # 'subject' entries are unicode |
|
70 | 70 | certname = value.lower().encode('ascii') |
|
71 | 71 | except UnicodeEncodeError: |
|
72 | 72 | return _('IDN in certificate not supported') |
|
73 | 73 | if matchdnsname(certname): |
|
74 | 74 | return None |
|
75 | 75 | return _('certificate is for %s') % certname |
|
76 | 76 | return _('no commonName or subjectAltName found in certificate') |
|
77 | 77 | |
|
78 | 78 | |
|
79 | 79 | # CERT_REQUIRED means fetch the cert from the server all the time AND |
|
80 | 80 | # validate it against the CA store provided in web.cacerts. |
|
81 | 81 | # |
|
82 | 82 | # We COMPLETELY ignore CERT_REQUIRED on Python <= 2.5, as it's totally |
|
83 | 83 | # busted on those versions. |
|
84 | 84 | |
|
85 | 85 | def sslkwargs(ui, host): |
|
86 | 86 | cacerts = ui.config('web', 'cacerts') |
|
87 | 87 | hostfingerprint = ui.config('hostfingerprints', host) |
|
88 | 88 | if cacerts and not hostfingerprint: |
|
89 | 89 | cacerts = util.expandpath(cacerts) |
|
90 | 90 | if not os.path.exists(cacerts): |
|
91 | 91 | raise util.Abort(_('could not find web.cacerts: %s') % cacerts) |
|
92 | 92 | return {'ca_certs': cacerts, |
|
93 | 93 | 'cert_reqs': CERT_REQUIRED, |
|
94 | 94 | } |
|
95 | 95 | return {} |
|
96 | 96 | |
|
97 | 97 | class validator(object): |
|
98 | 98 | def __init__(self, ui, host): |
|
99 | 99 | self.ui = ui |
|
100 | 100 | self.host = host |
|
101 | 101 | |
|
102 | 102 | def __call__(self, sock): |
|
103 | 103 | host = self.host |
|
104 | 104 | cacerts = self.ui.config('web', 'cacerts') |
|
105 | 105 | hostfingerprint = self.ui.config('hostfingerprints', host) |
|
106 | 106 | if not getattr(sock, 'getpeercert', False): # python 2.5 ? |
|
107 | 107 | if hostfingerprint: |
|
108 | 108 | raise util.Abort(_("host fingerprint for %s can't be " |
|
109 | 109 | "verified (Python too old)") % host) |
|
110 | 110 | self.ui.warn(_("warning: certificate for %s can't be verified " |
|
111 | 111 | "(Python too old)\n") % host) |
|
112 | 112 | return |
|
113 | peercert = sock.getpeercert(True) | |
|
114 | peerfingerprint = util.sha1(peercert).hexdigest() | |
|
115 | nicefingerprint = ":".join([peerfingerprint[x:x + 2] | |
|
116 | for x in xrange(0, len(peerfingerprint), 2)]) | |
|
113 | 117 | if cacerts and not hostfingerprint: |
|
114 | 118 | msg = _verifycert(sock.getpeercert(), host) |
|
115 | 119 | if msg: |
|
116 |
raise util.Abort(_('%s certificate error: %s |
|
|
117 | '(use --insecure to connect ' | |
|
118 |
'insecurely |
|
|
120 | raise util.Abort(_('%s certificate error: %s') % (host, msg), | |
|
121 | hint=_('configure hostfingerprint %s or use ' | |
|
122 | '--insecure to connect insecurely') % | |
|
123 | nicefingerprint) | |
|
119 | 124 | self.ui.debug('%s certificate successfully verified\n' % host) |
|
120 | 125 | else: |
|
121 | peercert = sock.getpeercert(True) | |
|
122 | peerfingerprint = util.sha1(peercert).hexdigest() | |
|
123 | nicefingerprint = ":".join([peerfingerprint[x:x + 2] | |
|
124 | for x in xrange(0, len(peerfingerprint), 2)]) | |
|
125 | 126 | if hostfingerprint: |
|
126 | 127 | if peerfingerprint.lower() != \ |
|
127 | 128 | hostfingerprint.replace(':', '').lower(): |
|
128 | 129 | raise util.Abort(_('invalid certificate for %s ' |
|
129 | 130 | 'with fingerprint %s') % |
|
130 | 131 | (host, nicefingerprint)) |
|
131 | 132 | self.ui.debug('%s certificate matched fingerprint %s\n' % |
|
132 | 133 | (host, nicefingerprint)) |
|
133 | 134 | else: |
|
134 | 135 | self.ui.warn(_('warning: %s certificate ' |
|
135 | 136 | 'with fingerprint %s not verified ' |
|
136 | 137 | '(check hostfingerprints or web.cacerts ' |
|
137 | 138 | 'config setting)\n') % |
|
138 | 139 | (host, nicefingerprint)) |
@@ -1,275 +1,276 b'' | |||
|
1 | 1 | Proper https client requires the built-in ssl from Python 2.6. |
|
2 | 2 | |
|
3 | 3 | $ "$TESTDIR/hghave" serve ssl || exit 80 |
|
4 | 4 | |
|
5 | 5 | Certificates created with: |
|
6 | 6 | printf '.\n.\n.\n.\n.\nlocalhost\nhg@localhost\n' | \ |
|
7 | 7 | openssl req -newkey rsa:512 -keyout priv.pem -nodes -x509 -days 9000 -out pub.pem |
|
8 | 8 | Can be dumped with: |
|
9 | 9 | openssl x509 -in pub.pem -text |
|
10 | 10 | |
|
11 | 11 | $ cat << EOT > priv.pem |
|
12 | 12 | > -----BEGIN PRIVATE KEY----- |
|
13 | 13 | > MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEApjCWeYGrIa/Vo7LH |
|
14 | 14 | > aRF8ou0tbgHKE33Use/whCnKEUm34rDaXQd4lxxX6aDWg06n9tiVStAKTgQAHJY8 |
|
15 | 15 | > j/xgSwIDAQABAkBxHC6+Qlf0VJXGlb6NL16yEVVTQxqDS6hA9zqu6TZjrr0YMfzc |
|
16 | 16 | > EGNIiZGt7HCBL0zO+cPDg/LeCZc6HQhf0KrhAiEAzlJq4hWWzvguWFIJWSoBeBUG |
|
17 | 17 | > MF1ACazQO7PYE8M0qfECIQDONHHP0SKZzz/ZwBZcAveC5K61f/v9hONFwbeYulzR |
|
18 | 18 | > +wIgc9SvbtgB/5Yzpp//4ZAEnR7oh5SClCvyB+KSx52K3nECICbhQphhoXmI10wy |
|
19 | 19 | > aMTellaq0bpNMHFDziqH9RsqAHhjAiEAgYGxfzkftt5IUUn/iFK89aaIpyrpuaAh |
|
20 | 20 | > HY8gUVkVRVs= |
|
21 | 21 | > -----END PRIVATE KEY----- |
|
22 | 22 | > EOT |
|
23 | 23 | |
|
24 | 24 | $ cat << EOT > pub.pem |
|
25 | 25 | > -----BEGIN CERTIFICATE----- |
|
26 | 26 | > MIIBqzCCAVWgAwIBAgIJANAXFFyWjGnRMA0GCSqGSIb3DQEBBQUAMDExEjAQBgNV |
|
27 | 27 | > BAMMCWxvY2FsaG9zdDEbMBkGCSqGSIb3DQEJARYMaGdAbG9jYWxob3N0MB4XDTEw |
|
28 | 28 | > MTAxNDIwMzAxNFoXDTM1MDYwNTIwMzAxNFowMTESMBAGA1UEAwwJbG9jYWxob3N0 |
|
29 | 29 | > MRswGQYJKoZIhvcNAQkBFgxoZ0Bsb2NhbGhvc3QwXDANBgkqhkiG9w0BAQEFAANL |
|
30 | 30 | > ADBIAkEApjCWeYGrIa/Vo7LHaRF8ou0tbgHKE33Use/whCnKEUm34rDaXQd4lxxX |
|
31 | 31 | > 6aDWg06n9tiVStAKTgQAHJY8j/xgSwIDAQABo1AwTjAdBgNVHQ4EFgQUE6sA+amm |
|
32 | 32 | > r24dGX0kpjxOgO45hzQwHwYDVR0jBBgwFoAUE6sA+ammr24dGX0kpjxOgO45hzQw |
|
33 | 33 | > DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAANBAFArvQFiAZJgQczRsbYlG1xl |
|
34 | 34 | > t+truk37w5B3m3Ick1ntRcQrqs+hf0CO1q6Squ144geYaQ8CDirSR92fICELI1c= |
|
35 | 35 | > -----END CERTIFICATE----- |
|
36 | 36 | > EOT |
|
37 | 37 | $ cat priv.pem pub.pem >> server.pem |
|
38 | 38 | $ PRIV=`pwd`/server.pem |
|
39 | 39 | |
|
40 | 40 | $ cat << EOT > pub-other.pem |
|
41 | 41 | > -----BEGIN CERTIFICATE----- |
|
42 | 42 | > MIIBqzCCAVWgAwIBAgIJALwZS731c/ORMA0GCSqGSIb3DQEBBQUAMDExEjAQBgNV |
|
43 | 43 | > BAMMCWxvY2FsaG9zdDEbMBkGCSqGSIb3DQEJARYMaGdAbG9jYWxob3N0MB4XDTEw |
|
44 | 44 | > MTAxNDIwNDUxNloXDTM1MDYwNTIwNDUxNlowMTESMBAGA1UEAwwJbG9jYWxob3N0 |
|
45 | 45 | > MRswGQYJKoZIhvcNAQkBFgxoZ0Bsb2NhbGhvc3QwXDANBgkqhkiG9w0BAQEFAANL |
|
46 | 46 | > ADBIAkEAsxsapLbHrqqUKuQBxdpK4G3m2LjtyrTSdpzzzFlecxd5yhNP6AyWrufo |
|
47 | 47 | > K4VMGo2xlu9xOo88nDSUNSKPuD09MwIDAQABo1AwTjAdBgNVHQ4EFgQUoIB1iMhN |
|
48 | 48 | > y868rpQ2qk9dHnU6ebswHwYDVR0jBBgwFoAUoIB1iMhNy868rpQ2qk9dHnU6ebsw |
|
49 | 49 | > DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAANBAJ544f125CsE7J2t55PdFaF6 |
|
50 | 50 | > bBlNBb91FCywBgSjhBjf+GG3TNPwrPdc3yqeq+hzJiuInqbOBv9abmMyq8Wsoig= |
|
51 | 51 | > -----END CERTIFICATE----- |
|
52 | 52 | > EOT |
|
53 | 53 | |
|
54 | 54 | pub.pem patched with other notBefore / notAfter: |
|
55 | 55 | |
|
56 | 56 | $ cat << EOT > pub-not-yet.pem |
|
57 | 57 | > -----BEGIN CERTIFICATE----- |
|
58 | 58 | > MIIBqzCCAVWgAwIBAgIJANAXFFyWjGnRMA0GCSqGSIb3DQEBBQUAMDExEjAQBgNVBAMMCWxvY2Fs |
|
59 | 59 | > aG9zdDEbMBkGCSqGSIb3DQEJARYMaGdAbG9jYWxob3N0MB4XDTM1MDYwNTIwMzAxNFoXDTM1MDYw |
|
60 | 60 | > NTIwMzAxNFowMTESMBAGA1UEAwwJbG9jYWxob3N0MRswGQYJKoZIhvcNAQkBFgxoZ0Bsb2NhbGhv |
|
61 | 61 | > c3QwXDANBgkqhkiG9w0BAQEFAANLADBIAkEApjCWeYGrIa/Vo7LHaRF8ou0tbgHKE33Use/whCnK |
|
62 | 62 | > EUm34rDaXQd4lxxX6aDWg06n9tiVStAKTgQAHJY8j/xgSwIDAQABo1AwTjAdBgNVHQ4EFgQUE6sA |
|
63 | 63 | > +ammr24dGX0kpjxOgO45hzQwHwYDVR0jBBgwFoAUE6sA+ammr24dGX0kpjxOgO45hzQwDAYDVR0T |
|
64 | 64 | > BAUwAwEB/zANBgkqhkiG9w0BAQUFAANBAJXV41gWnkgC7jcpPpFRSUSZaxyzrXmD1CIqQf0WgVDb |
|
65 | 65 | > /12E0vR2DuZitgzUYtBaofM81aTtc0a2/YsrmqePGm0= |
|
66 | 66 | > -----END CERTIFICATE----- |
|
67 | 67 | > EOT |
|
68 | 68 | $ cat priv.pem pub-not-yet.pem > server-not-yet.pem |
|
69 | 69 | |
|
70 | 70 | $ cat << EOT > pub-expired.pem |
|
71 | 71 | > -----BEGIN CERTIFICATE----- |
|
72 | 72 | > MIIBqzCCAVWgAwIBAgIJANAXFFyWjGnRMA0GCSqGSIb3DQEBBQUAMDExEjAQBgNVBAMMCWxvY2Fs |
|
73 | 73 | > aG9zdDEbMBkGCSqGSIb3DQEJARYMaGdAbG9jYWxob3N0MB4XDTEwMTAxNDIwMzAxNFoXDTEwMTAx |
|
74 | 74 | > NDIwMzAxNFowMTESMBAGA1UEAwwJbG9jYWxob3N0MRswGQYJKoZIhvcNAQkBFgxoZ0Bsb2NhbGhv |
|
75 | 75 | > c3QwXDANBgkqhkiG9w0BAQEFAANLADBIAkEApjCWeYGrIa/Vo7LHaRF8ou0tbgHKE33Use/whCnK |
|
76 | 76 | > EUm34rDaXQd4lxxX6aDWg06n9tiVStAKTgQAHJY8j/xgSwIDAQABo1AwTjAdBgNVHQ4EFgQUE6sA |
|
77 | 77 | > +ammr24dGX0kpjxOgO45hzQwHwYDVR0jBBgwFoAUE6sA+ammr24dGX0kpjxOgO45hzQwDAYDVR0T |
|
78 | 78 | > BAUwAwEB/zANBgkqhkiG9w0BAQUFAANBAJfk57DTRf2nUbYaMSlVAARxMNbFGOjQhAUtY400GhKt |
|
79 | 79 | > 2uiKCNGKXVXD3AHWe13yHc5KttzbHQStE5Nm/DlWBWQ= |
|
80 | 80 | > -----END CERTIFICATE----- |
|
81 | 81 | > EOT |
|
82 | 82 | $ cat priv.pem pub-expired.pem > server-expired.pem |
|
83 | 83 | |
|
84 | 84 | $ hg init test |
|
85 | 85 | $ cd test |
|
86 | 86 | $ echo foo>foo |
|
87 | 87 | $ mkdir foo.d foo.d/bAr.hg.d foo.d/baR.d.hg |
|
88 | 88 | $ echo foo>foo.d/foo |
|
89 | 89 | $ echo bar>foo.d/bAr.hg.d/BaR |
|
90 | 90 | $ echo bar>foo.d/baR.d.hg/bAR |
|
91 | 91 | $ hg commit -A -m 1 |
|
92 | 92 | adding foo |
|
93 | 93 | adding foo.d/bAr.hg.d/BaR |
|
94 | 94 | adding foo.d/baR.d.hg/bAR |
|
95 | 95 | adding foo.d/foo |
|
96 | 96 | $ hg serve -p $HGPORT -d --pid-file=../hg0.pid --certificate=$PRIV |
|
97 | 97 | $ cat ../hg0.pid >> $DAEMON_PIDS |
|
98 | 98 | |
|
99 | 99 | cacert not found |
|
100 | 100 | |
|
101 | 101 | $ hg in --config web.cacerts=no-such.pem https://localhost:$HGPORT/ |
|
102 | 102 | abort: could not find web.cacerts: no-such.pem |
|
103 | 103 | [255] |
|
104 | 104 | |
|
105 | 105 | Test server address cannot be reused |
|
106 | 106 | |
|
107 | 107 | $ hg serve -p $HGPORT --certificate=$PRIV 2>&1 |
|
108 | 108 | abort: cannot start server at ':$HGPORT': Address already in use |
|
109 | 109 | [255] |
|
110 | 110 | $ cd .. |
|
111 | 111 | |
|
112 | 112 | clone via pull |
|
113 | 113 | |
|
114 | 114 | $ hg clone https://localhost:$HGPORT/ copy-pull |
|
115 | 115 | warning: localhost certificate with fingerprint 91:4f:1a:ff:87:24:9c:09:b6:85:9b:88:b1:90:6d:30:75:64:91:ca not verified (check hostfingerprints or web.cacerts config setting) |
|
116 | 116 | requesting all changes |
|
117 | 117 | adding changesets |
|
118 | 118 | adding manifests |
|
119 | 119 | adding file changes |
|
120 | 120 | added 1 changesets with 4 changes to 4 files |
|
121 | 121 | warning: localhost certificate with fingerprint 91:4f:1a:ff:87:24:9c:09:b6:85:9b:88:b1:90:6d:30:75:64:91:ca not verified (check hostfingerprints or web.cacerts config setting) |
|
122 | 122 | updating to branch default |
|
123 | 123 | 4 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
124 | 124 | $ hg verify -R copy-pull |
|
125 | 125 | checking changesets |
|
126 | 126 | checking manifests |
|
127 | 127 | crosschecking files in changesets and manifests |
|
128 | 128 | checking files |
|
129 | 129 | 4 files, 1 changesets, 4 total revisions |
|
130 | 130 | $ cd test |
|
131 | 131 | $ echo bar > bar |
|
132 | 132 | $ hg commit -A -d '1 0' -m 2 |
|
133 | 133 | adding bar |
|
134 | 134 | $ cd .. |
|
135 | 135 | |
|
136 | 136 | pull without cacert |
|
137 | 137 | |
|
138 | 138 | $ cd copy-pull |
|
139 | 139 | $ echo '[hooks]' >> .hg/hgrc |
|
140 | 140 | $ echo "changegroup = python '$TESTDIR'/printenv.py changegroup" >> .hg/hgrc |
|
141 | 141 | $ hg pull |
|
142 | 142 | warning: localhost certificate with fingerprint 91:4f:1a:ff:87:24:9c:09:b6:85:9b:88:b1:90:6d:30:75:64:91:ca not verified (check hostfingerprints or web.cacerts config setting) |
|
143 | 143 | pulling from https://localhost:$HGPORT/ |
|
144 | 144 | searching for changes |
|
145 | 145 | adding changesets |
|
146 | 146 | adding manifests |
|
147 | 147 | adding file changes |
|
148 | 148 | added 1 changesets with 1 changes to 1 files |
|
149 | 149 | warning: localhost certificate with fingerprint 91:4f:1a:ff:87:24:9c:09:b6:85:9b:88:b1:90:6d:30:75:64:91:ca not verified (check hostfingerprints or web.cacerts config setting) |
|
150 | 150 | changegroup hook: HG_NODE=5fed3813f7f5e1824344fdc9cf8f63bb662c292d HG_SOURCE=pull HG_URL=https://localhost:$HGPORT/ |
|
151 | 151 | (run 'hg update' to get a working copy) |
|
152 | 152 | $ cd .. |
|
153 | 153 | |
|
154 | 154 | cacert configured in local repo |
|
155 | 155 | |
|
156 | 156 | $ cp copy-pull/.hg/hgrc copy-pull/.hg/hgrc.bu |
|
157 | 157 | $ echo "[web]" >> copy-pull/.hg/hgrc |
|
158 | 158 | $ echo "cacerts=`pwd`/pub.pem" >> copy-pull/.hg/hgrc |
|
159 | 159 | $ hg -R copy-pull pull --traceback |
|
160 | 160 | pulling from https://localhost:$HGPORT/ |
|
161 | 161 | searching for changes |
|
162 | 162 | no changes found |
|
163 | 163 | $ mv copy-pull/.hg/hgrc.bu copy-pull/.hg/hgrc |
|
164 | 164 | |
|
165 | 165 | cacert configured globally, also testing expansion of environment |
|
166 | 166 | variables in the filename |
|
167 | 167 | |
|
168 | 168 | $ echo "[web]" >> $HGRCPATH |
|
169 | 169 | $ echo 'cacerts=$P/pub.pem' >> $HGRCPATH |
|
170 | 170 | $ P=`pwd` hg -R copy-pull pull |
|
171 | 171 | pulling from https://localhost:$HGPORT/ |
|
172 | 172 | searching for changes |
|
173 | 173 | no changes found |
|
174 | 174 | $ P=`pwd` hg -R copy-pull pull --insecure |
|
175 | 175 | warning: localhost certificate with fingerprint 91:4f:1a:ff:87:24:9c:09:b6:85:9b:88:b1:90:6d:30:75:64:91:ca not verified (check hostfingerprints or web.cacerts config setting) |
|
176 | 176 | pulling from https://localhost:$HGPORT/ |
|
177 | 177 | searching for changes |
|
178 | 178 | no changes found |
|
179 | 179 | |
|
180 | 180 | cacert mismatch |
|
181 | 181 | |
|
182 | 182 | $ hg -R copy-pull pull --config web.cacerts=pub.pem https://127.0.0.1:$HGPORT/ |
|
183 |
abort: 127.0.0.1 certificate error: certificate is for localhost |
|
|
183 | abort: 127.0.0.1 certificate error: certificate is for localhost | |
|
184 | (configure hostfingerprint 91:4f:1a:ff:87:24:9c:09:b6:85:9b:88:b1:90:6d:30:75:64:91:ca or use --insecure to connect insecurely) | |
|
184 | 185 | [255] |
|
185 | 186 | $ hg -R copy-pull pull --config web.cacerts=pub.pem https://127.0.0.1:$HGPORT/ --insecure |
|
186 | 187 | warning: 127.0.0.1 certificate with fingerprint 91:4f:1a:ff:87:24:9c:09:b6:85:9b:88:b1:90:6d:30:75:64:91:ca not verified (check hostfingerprints or web.cacerts config setting) |
|
187 | 188 | pulling from https://127.0.0.1:$HGPORT/ |
|
188 | 189 | searching for changes |
|
189 | 190 | no changes found |
|
190 | 191 | $ hg -R copy-pull pull --config web.cacerts=pub-other.pem |
|
191 | 192 | abort: error: *:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed (glob) |
|
192 | 193 | [255] |
|
193 | 194 | $ hg -R copy-pull pull --config web.cacerts=pub-other.pem --insecure |
|
194 | 195 | warning: localhost certificate with fingerprint 91:4f:1a:ff:87:24:9c:09:b6:85:9b:88:b1:90:6d:30:75:64:91:ca not verified (check hostfingerprints or web.cacerts config setting) |
|
195 | 196 | pulling from https://localhost:$HGPORT/ |
|
196 | 197 | searching for changes |
|
197 | 198 | no changes found |
|
198 | 199 | |
|
199 | 200 | Test server cert which isn't valid yet |
|
200 | 201 | |
|
201 | 202 | $ hg -R test serve -p $HGPORT1 -d --pid-file=hg1.pid --certificate=server-not-yet.pem |
|
202 | 203 | $ cat hg1.pid >> $DAEMON_PIDS |
|
203 | 204 | $ hg -R copy-pull pull --config web.cacerts=pub-not-yet.pem https://localhost:$HGPORT1/ |
|
204 | 205 | abort: error: *:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed (glob) |
|
205 | 206 | [255] |
|
206 | 207 | |
|
207 | 208 | Test server cert which no longer is valid |
|
208 | 209 | |
|
209 | 210 | $ hg -R test serve -p $HGPORT2 -d --pid-file=hg2.pid --certificate=server-expired.pem |
|
210 | 211 | $ cat hg2.pid >> $DAEMON_PIDS |
|
211 | 212 | $ hg -R copy-pull pull --config web.cacerts=pub-expired.pem https://localhost:$HGPORT2/ |
|
212 | 213 | abort: error: *:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed (glob) |
|
213 | 214 | [255] |
|
214 | 215 | |
|
215 | 216 | Fingerprints |
|
216 | 217 | |
|
217 | 218 | $ echo "[hostfingerprints]" >> copy-pull/.hg/hgrc |
|
218 | 219 | $ echo "localhost = 91:4f:1a:ff:87:24:9c:09:b6:85:9b:88:b1:90:6d:30:75:64:91:ca" >> copy-pull/.hg/hgrc |
|
219 | 220 | $ echo "127.0.0.1 = 914f1aff87249c09b6859b88b1906d30756491ca" >> copy-pull/.hg/hgrc |
|
220 | 221 | |
|
221 | 222 | - works without cacerts |
|
222 | 223 | $ hg -R copy-pull id https://localhost:$HGPORT/ --config web.cacerts= |
|
223 | 224 | 5fed3813f7f5 |
|
224 | 225 | |
|
225 | 226 | - fails when cert doesn't match hostname (port is ignored) |
|
226 | 227 | $ hg -R copy-pull id https://localhost:$HGPORT1/ |
|
227 | 228 | abort: invalid certificate for localhost with fingerprint 28:ff:71:bf:65:31:14:23:ad:62:92:b4:0e:31:99:18:fc:83:e3:9b |
|
228 | 229 | [255] |
|
229 | 230 | |
|
230 | 231 | - ignores that certificate doesn't match hostname |
|
231 | 232 | $ hg -R copy-pull id https://127.0.0.1:$HGPORT/ |
|
232 | 233 | 5fed3813f7f5 |
|
233 | 234 | |
|
234 | 235 | Prepare for connecting through proxy |
|
235 | 236 | |
|
236 | 237 | $ kill `cat hg1.pid` |
|
237 | 238 | $ sleep 1 |
|
238 | 239 | |
|
239 | 240 | $ ("$TESTDIR/tinyproxy.py" $HGPORT1 localhost >proxy.log 2>&1 </dev/null & |
|
240 | 241 | $ echo $! > proxy.pid) |
|
241 | 242 | $ cat proxy.pid >> $DAEMON_PIDS |
|
242 | 243 | $ sleep 2 |
|
243 | 244 | |
|
244 | 245 | $ echo "[http_proxy]" >> copy-pull/.hg/hgrc |
|
245 | 246 | $ echo "always=True" >> copy-pull/.hg/hgrc |
|
246 | 247 | $ echo "[hostfingerprints]" >> copy-pull/.hg/hgrc |
|
247 | 248 | $ echo "localhost =" >> copy-pull/.hg/hgrc |
|
248 | 249 | |
|
249 | 250 | Test unvalidated https through proxy |
|
250 | 251 | |
|
251 | 252 | $ http_proxy=http://localhost:$HGPORT1/ hg -R copy-pull pull --insecure --traceback |
|
252 | 253 | warning: localhost certificate with fingerprint 91:4f:1a:ff:87:24:9c:09:b6:85:9b:88:b1:90:6d:30:75:64:91:ca not verified (check hostfingerprints or web.cacerts config setting) |
|
253 | 254 | pulling from https://localhost:$HGPORT/ |
|
254 | 255 | searching for changes |
|
255 | 256 | no changes found |
|
256 | 257 | |
|
257 | 258 | Test https with cacert and fingerprint through proxy |
|
258 | 259 | |
|
259 | 260 | $ http_proxy=http://localhost:$HGPORT1/ hg -R copy-pull pull --config web.cacerts=pub.pem |
|
260 | 261 | pulling from https://localhost:$HGPORT/ |
|
261 | 262 | searching for changes |
|
262 | 263 | no changes found |
|
263 | 264 | $ http_proxy=http://localhost:$HGPORT1/ hg -R copy-pull pull https://127.0.0.1:$HGPORT/ |
|
264 | 265 | pulling from https://127.0.0.1:$HGPORT/ |
|
265 | 266 | searching for changes |
|
266 | 267 | no changes found |
|
267 | 268 | |
|
268 | 269 | Test https with cert problems through proxy |
|
269 | 270 | |
|
270 | 271 | $ http_proxy=http://localhost:$HGPORT1/ hg -R copy-pull pull --config web.cacerts=pub-other.pem |
|
271 | 272 | abort: error: *:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed (glob) |
|
272 | 273 | [255] |
|
273 | 274 | $ http_proxy=http://localhost:$HGPORT1/ hg -R copy-pull pull --config web.cacerts=pub-expired.pem https://localhost:$HGPORT2/ |
|
274 | 275 | abort: error: *:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed (glob) |
|
275 | 276 | [255] |
General Comments 0
You need to be logged in to leave comments.
Login now