Mercurial > hg
comparison mercurial/url.py @ 13422:ebce5196b9db
url: always create BetterHTTPS connections the same way
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Wed, 16 Feb 2011 04:28:17 +0100 |
parents | bd8bfa85d5a5 |
children | 08f9c587141f |
comparison
equal
deleted
inserted
replaced
13421:bd8bfa85d5a5 | 13422:ebce5196b9db |
---|---|
544 if has_https: | 544 if has_https: |
545 class BetterHTTPS(httplib.HTTPSConnection): | 545 class BetterHTTPS(httplib.HTTPSConnection): |
546 send = keepalive.safesend | 546 send = keepalive.safesend |
547 | 547 |
548 def connect(self): | 548 def connect(self): |
549 self.sock = _create_connection((self.host, self.port)) | |
550 | |
549 host = self.host | 551 host = self.host |
550 cacerts = self.ui.config('web', 'cacerts') | 552 cacerts = self.ui.config('web', 'cacerts') |
551 hostfingerprint = self.ui.config('hostfingerprints', host) | 553 hostfingerprint = self.ui.config('hostfingerprints', host) |
552 | 554 |
553 if cacerts and not hostfingerprint: | 555 if cacerts and not hostfingerprint: |
554 sock = _create_connection((self.host, self.port)) | |
555 self.sock = _ssl_wrap_socket(self.sock, self.key_file, | 556 self.sock = _ssl_wrap_socket(self.sock, self.key_file, |
556 self.cert_file, cert_reqs=CERT_REQUIRED, | 557 self.cert_file, cert_reqs=CERT_REQUIRED, |
557 ca_certs=util.expandpath(cacerts)) | 558 ca_certs=util.expandpath(cacerts)) |
558 msg = _verifycert(self.sock.getpeercert(), host) | 559 msg = _verifycert(self.sock.getpeercert(), host) |
559 if msg: | 560 if msg: |
560 raise util.Abort(_('%s certificate error: %s ' | 561 raise util.Abort(_('%s certificate error: %s ' |
561 '(use --insecure to connect ' | 562 '(use --insecure to connect ' |
562 'insecurely)') % (host, msg)) | 563 'insecurely)') % (host, msg)) |
563 self.ui.debug('%s certificate successfully verified\n' % host) | 564 self.ui.debug('%s certificate successfully verified\n' % host) |
564 else: | 565 else: |
565 httplib.HTTPSConnection.connect(self) | 566 self.sock = _ssl_wrap_socket(self.sock, self.key_file, |
567 self.cert_file) | |
566 if hasattr(self.sock, 'getpeercert'): | 568 if hasattr(self.sock, 'getpeercert'): |
567 peercert = self.sock.getpeercert(True) | 569 peercert = self.sock.getpeercert(True) |
568 peerfingerprint = util.sha1(peercert).hexdigest() | 570 peerfingerprint = util.sha1(peercert).hexdigest() |
569 nicefingerprint = ":".join([peerfingerprint[x:x + 2] | 571 nicefingerprint = ":".join([peerfingerprint[x:x + 2] |
570 for x in xrange(0, len(peerfingerprint), 2)]) | 572 for x in xrange(0, len(peerfingerprint), 2)]) |