mercurial/sslutil.py
changeset 29411 e1778b9c8d53
parent 29410 222f6834c69a
child 29446 2f7f1e10f840
equal deleted inserted replaced
29410:222f6834c69a 29411:e1778b9c8d53
   205         if cafile or (_canloaddefaultcerts and s['allowloaddefaultcerts']):
   205         if cafile or (_canloaddefaultcerts and s['allowloaddefaultcerts']):
   206             s['verifymode'] = ssl.CERT_REQUIRED
   206             s['verifymode'] = ssl.CERT_REQUIRED
   207         else:
   207         else:
   208             # At this point we don't have a fingerprint, aren't being
   208             # At this point we don't have a fingerprint, aren't being
   209             # explicitly insecure, and can't load CA certs. Connecting
   209             # explicitly insecure, and can't load CA certs. Connecting
   210             # at this point is insecure. But we do it for BC reasons.
   210             # is insecure. We allow the connection and abort during
   211             # TODO abort here to make secure by default.
   211             # validation (once we have the fingerprint to print to the
       
   212             # user).
   212             s['verifymode'] = ssl.CERT_NONE
   213             s['verifymode'] = ssl.CERT_NONE
   213 
   214 
   214     assert s['verifymode'] is not None
   215     assert s['verifymode'] is not None
   215 
   216 
   216     return s
   217     return s
   411             nice = '%s:%s' % (hash, fmtfingerprint(peerfingerprints[hash]))
   412             nice = '%s:%s' % (hash, fmtfingerprint(peerfingerprints[hash]))
   412         raise error.Abort(_('certificate for %s has unexpected '
   413         raise error.Abort(_('certificate for %s has unexpected '
   413                             'fingerprint %s') % (host, nice),
   414                             'fingerprint %s') % (host, nice),
   414                           hint=_('check %s configuration') % section)
   415                           hint=_('check %s configuration') % section)
   415 
   416 
       
   417     # Security is enabled but no CAs are loaded. We can't establish trust
       
   418     # for the cert so abort.
   416     if not sock._hgstate['caloaded']:
   419     if not sock._hgstate['caloaded']:
   417         ui.warn(_('warning: certificate for %s not verified '
   420         raise error.Abort(
   418                   '(set hostsecurity.%s:certfingerprints=%s or web.cacerts '
   421             _('unable to verify security of %s (no loaded CA certificates); '
   419                   'config settings)\n') % (host, host, nicefingerprint))
   422               'refusing to connect') % host,
   420         return
   423             hint=_('see https://mercurial-scm.org/wiki/SecureConnections for '
       
   424                    'how to configure Mercurial to avoid this error or set '
       
   425                    'hostsecurity.%s:fingerprints=%s to trust this server') %
       
   426                    (host, nicefingerprint))
   421 
   427 
   422     msg = _verifycert(peercert2, host)
   428     msg = _verifycert(peercert2, host)
   423     if msg:
   429     if msg:
   424         raise error.Abort(_('%s certificate error: %s') % (host, msg),
   430         raise error.Abort(_('%s certificate error: %s') % (host, msg),
   425                          hint=_('set hostsecurity.%s:certfingerprints=%s '
   431                          hint=_('set hostsecurity.%s:certfingerprints=%s '