Show More
@@ -423,6 +423,24 b' Example for ``~/.hgrc``::' | |||||
423 | myfeature = ~/.hgext/myfeature.py |
|
423 | myfeature = ~/.hgext/myfeature.py | |
424 |
|
424 | |||
425 |
|
425 | |||
|
426 | ``hostfingerprints`` | |||
|
427 | """""""""""""""""""" | |||
|
428 | ||||
|
429 | Fingerprints of the certificates of known HTTPS servers. | |||
|
430 | A HTTPS connection to a server with a fingerprint configured here will | |||
|
431 | only succeed if the servers certificate matches the fingerprint. | |||
|
432 | This is very similar to how ssh known hosts works. | |||
|
433 | The fingerprint is the SHA-1 hash value of the DER encoded certificate. | |||
|
434 | The CA chain and web.cacerts is not used for servers with a fingerprint. | |||
|
435 | ||||
|
436 | For example:: | |||
|
437 | ||||
|
438 | [hostfingerprints] | |||
|
439 | hg.intevation.org = 38:76:52:7c:87:26:9a:8f:4a:f8:d3:de:08:45:3b:ea:d6:4b:ee:cc | |||
|
440 | ||||
|
441 | This feature is only supported when using Python 2.6 or later. | |||
|
442 | ||||
|
443 | ||||
426 | ``format`` |
|
444 | ``format`` | |
427 | """""""""" |
|
445 | """""""""" | |
428 |
|
446 |
@@ -544,7 +544,7 b' def remoteui(src, opts):' | |||||
544 | dst.setconfig('bundle', 'mainreporoot', r) |
|
544 | dst.setconfig('bundle', 'mainreporoot', r) | |
545 |
|
545 | |||
546 | # copy selected local settings to the remote ui |
|
546 | # copy selected local settings to the remote ui | |
547 | for sect in ('auth', 'http_proxy'): |
|
547 | for sect in ('auth', 'hostfingerprints', 'http_proxy'): | |
548 | for key, val in src.configitems(sect): |
|
548 | for key, val in src.configitems(sect): | |
549 | dst.setconfig(sect, key, val) |
|
549 | dst.setconfig(sect, key, val) | |
550 | v = src.config('web', 'cacerts') |
|
550 | v = src.config('web', 'cacerts') |
@@ -551,7 +551,8 b' if has_https:' | |||||
551 | else: |
|
551 | else: | |
552 | cacerts = None |
|
552 | cacerts = None | |
553 |
|
553 | |||
554 | if cacerts: |
|
554 | hostfingerprint = self.ui.config('hostfingerprints', self.host) | |
|
555 | if cacerts and not hostfingerprint: | |||
555 | sock = _create_connection((self.host, self.port)) |
|
556 | sock = _create_connection((self.host, self.port)) | |
556 | self.sock = _ssl_wrap_socket(sock, self.key_file, |
|
557 | self.sock = _ssl_wrap_socket(sock, self.key_file, | |
557 | self.cert_file, cert_reqs=CERT_REQUIRED, |
|
558 | self.cert_file, cert_reqs=CERT_REQUIRED, | |
@@ -563,10 +564,33 b' if has_https:' | |||||
563 | self.ui.debug('%s certificate successfully verified\n' % |
|
564 | self.ui.debug('%s certificate successfully verified\n' % | |
564 | self.host) |
|
565 | self.host) | |
565 | else: |
|
566 | else: | |
566 | self.ui.warn(_("warning: %s certificate not verified " |
|
|||
567 | "(check web.cacerts config setting)\n") % |
|
|||
568 | self.host) |
|
|||
569 | httplib.HTTPSConnection.connect(self) |
|
567 | httplib.HTTPSConnection.connect(self) | |
|
568 | if hasattr(self.sock, 'getpeercert'): | |||
|
569 | peercert = self.sock.getpeercert(True) | |||
|
570 | peerfingerprint = util.sha1(peercert).hexdigest() | |||
|
571 | nicefingerprint = ":".join([peerfingerprint[x:x + 2] | |||
|
572 | for x in xrange(0, len(peerfingerprint), 2)]) | |||
|
573 | if hostfingerprint: | |||
|
574 | if peerfingerprint.lower() != \ | |||
|
575 | hostfingerprint.replace(':', '').lower(): | |||
|
576 | raise util.Abort(_('invalid certificate for %s ' | |||
|
577 | 'with fingerprint %s') % | |||
|
578 | (self.host, nicefingerprint)) | |||
|
579 | self.ui.debug('%s certificate matched fingerprint %s\n' % | |||
|
580 | (self.host, nicefingerprint)) | |||
|
581 | else: | |||
|
582 | self.ui.warn(_('warning: %s certificate ' | |||
|
583 | 'with fingerprint %s not verified ' | |||
|
584 | '(check hostfingerprints or web.cacerts ' | |||
|
585 | 'config setting)\n') % | |||
|
586 | (self.host, nicefingerprint)) | |||
|
587 | else: # python 2.5 ? | |||
|
588 | if hostfingerprint: | |||
|
589 | raise util.Abort(_('no certificate for %s ' | |||
|
590 | 'with fingerprint') % self.host) | |||
|
591 | self.ui.warn(_('warning: %s certificate not verified ' | |||
|
592 | '(check web.cacerts config setting)\n') % | |||
|
593 | self.host) | |||
570 |
|
594 | |||
571 | class httpsconnection(BetterHTTPS): |
|
595 | class httpsconnection(BetterHTTPS): | |
572 | response_class = keepalive.HTTPResponse |
|
596 | response_class = keepalive.HTTPResponse |
@@ -106,7 +106,7 b' Test server address cannot be reused' | |||||
106 | clone via pull |
|
106 | clone via pull | |
107 |
|
107 | |||
108 | $ hg clone https://localhost:$HGPORT/ copy-pull |
|
108 | $ hg clone https://localhost:$HGPORT/ copy-pull | |
109 | warning: localhost certificate not verified (check web.cacerts config setting) |
|
109 | 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) | |
110 | requesting all changes |
|
110 | requesting all changes | |
111 | adding changesets |
|
111 | adding changesets | |
112 | adding manifests |
|
112 | adding manifests | |
@@ -132,7 +132,7 b' pull without cacert' | |||||
132 | $ echo '[hooks]' >> .hg/hgrc |
|
132 | $ echo '[hooks]' >> .hg/hgrc | |
133 | $ echo "changegroup = python '$TESTDIR'/printenv.py changegroup" >> .hg/hgrc |
|
133 | $ echo "changegroup = python '$TESTDIR'/printenv.py changegroup" >> .hg/hgrc | |
134 | $ hg pull |
|
134 | $ hg pull | |
135 | warning: localhost certificate not verified (check web.cacerts config setting) |
|
135 | 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) | |
136 | changegroup hook: HG_NODE=5fed3813f7f5e1824344fdc9cf8f63bb662c292d HG_SOURCE=pull HG_URL=https://localhost:$HGPORT/ |
|
136 | changegroup hook: HG_NODE=5fed3813f7f5e1824344fdc9cf8f63bb662c292d HG_SOURCE=pull HG_URL=https://localhost:$HGPORT/ | |
137 | pulling from https://localhost:$HGPORT/ |
|
137 | pulling from https://localhost:$HGPORT/ | |
138 | searching for changes |
|
138 | searching for changes | |
@@ -188,3 +188,22 b' Test server cert which no longer is vali' | |||||
188 | $ hg -R copy-pull pull --config web.cacerts=pub-expired.pem https://localhost:$HGPORT2/ |
|
188 | $ hg -R copy-pull pull --config web.cacerts=pub-expired.pem https://localhost:$HGPORT2/ | |
189 | abort: error: *:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed (glob) |
|
189 | abort: error: *:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed (glob) | |
190 | [255] |
|
190 | [255] | |
|
191 | ||||
|
192 | Fingerprints | |||
|
193 | ||||
|
194 | $ echo "[hostfingerprints]" >> copy-pull/.hg/hgrc | |||
|
195 | $ 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 | |||
|
196 | $ echo "127.0.0.1 = 914f1aff87249c09b6859b88b1906d30756491ca" >> copy-pull/.hg/hgrc | |||
|
197 | ||||
|
198 | - works without cacerts | |||
|
199 | $ hg -R copy-pull id https://localhost:$HGPORT/ --config web.cacerts= | |||
|
200 | 5fed3813f7f5 | |||
|
201 | ||||
|
202 | - fails when cert doesn't match hostname (port is ignored) | |||
|
203 | $ hg -R copy-pull id https://localhost:$HGPORT1/ | |||
|
204 | 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 | |||
|
205 | [255] | |||
|
206 | ||||
|
207 | - ignores that certificate doesn't match hostname | |||
|
208 | $ hg -R copy-pull id https://127.0.0.1:$HGPORT/ | |||
|
209 | 5fed3813f7f5 |
General Comments 0
You need to be logged in to leave comments.
Login now