Mercurial > hg
comparison mercurial/sslutil.py @ 42269:c8d55ff80da1
sslutil: add support for SSLKEYLOGFILE to wrapsocket
I recently learned of a Firefox/Chrome feature that allows
wiresharking otherwise-TLS'd network connections. Gloriously, there's
a pypi module that enables this same feature on Python, so let's add
support for it to Mercurial in case we need to wireshark some HTTPs
connections.
Differential Revision: https://phab.mercurial-scm.org/D6343
author | Augie Fackler <augie@google.com> |
---|---|
date | Sat, 04 May 2019 23:31:42 -0400 |
parents | ce5f1232631f |
children | 2372284d9457 |
comparison
equal
deleted
inserted
replaced
42268:af13e2088f77 | 42269:c8d55ff80da1 |
---|---|
14 import re | 14 import re |
15 import ssl | 15 import ssl |
16 | 16 |
17 from .i18n import _ | 17 from .i18n import _ |
18 from . import ( | 18 from . import ( |
19 encoding, | |
19 error, | 20 error, |
20 node, | 21 node, |
21 pycompat, | 22 pycompat, |
22 util, | 23 util, |
23 ) | 24 ) |
345 server (and client) support SNI, this tells the server which certificate | 346 server (and client) support SNI, this tells the server which certificate |
346 to use. | 347 to use. |
347 """ | 348 """ |
348 if not serverhostname: | 349 if not serverhostname: |
349 raise error.Abort(_('serverhostname argument is required')) | 350 raise error.Abort(_('serverhostname argument is required')) |
351 | |
352 if b'SSLKEYLOGFILE' in encoding.environ: | |
353 try: | |
354 import sslkeylog | |
355 sslkeylog.set_keylog(pycompat.fsdecode( | |
356 encoding.environ[b'SSLKEYLOGFILE'])) | |
357 ui.warn( | |
358 b'sslkeylog enabled by SSLKEYLOGFILE environment variable\n') | |
359 except ImportError: | |
360 ui.warn(b'sslkeylog module missing, ' | |
361 b'but SSLKEYLOGFILE set in environment\n') | |
350 | 362 |
351 for f in (keyfile, certfile): | 363 for f in (keyfile, certfile): |
352 if f and not os.path.exists(f): | 364 if f and not os.path.exists(f): |
353 raise error.Abort( | 365 raise error.Abort( |
354 _('certificate file (%s) does not exist; cannot connect to %s') | 366 _('certificate file (%s) does not exist; cannot connect to %s') |