-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SSL certificate verification. #791
Merged
Merged
Changes from all commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
b9ea089
Changing the default index URL to use HTTPS.
246e974
Added certificate validation against root CA file.
db79f83
Added CA file to MANIFEST.in
39d84ab
Adding PEM file to package data.
d54c695
Adding code to match_hostname.
7776cfc
added install_requires
b97969f
'package_dir' not needed
qwcode 6bd3bd4
won't be installing the ssl backport as a dependency
qwcode 11ebe01
warn before installing if no ssl module
qwcode c612db0
match_hostname from py32
qwcode 73c4614
backwardcompat logic for ssl and match_hostname
qwcode 4bb5ac6
use standard opener when no ssl
qwcode 7e20fd8
move cert_path to locations module
qwcode b2e0b6d
log relevant message if URLError.reason is SSLError or CertificateError
qwcode a4a9197
py25 import fixes
qwcode d50a3b7
license for CA Root Certificates
qwcode 7fac01a
misc test fixes
qwcode 8496406
--cert-path and --no-ssl options
qwcode 226768d
allow py25 tests to work without ssl
qwcode 193562b
more py25 test fixes
qwcode d8fe463
tun py25 test logic and add assert_raises_regexp
qwcode 456ea80
fix param name in exception message
qwcode fe17bb4
OpenerDirector for ssl should not contain the default http handler
qwcode d77380d
ssl cert tests
qwcode 609cfe9
remove duplicate backwardcompat imports and excess logic
qwcode 6dc3212
pypy ssl test fix
qwcode bb7ba1a
shorter metavar for --cert-path
qwcode e338436
update authors and changelog
qwcode 857f64e
latest mozilla ca certs aquired securely and generated to pem form
qwcode 49563cf
ssl cert docs updates
qwcode f92052f
py25 socket patch to work with ssl backport
qwcode 76b5ebc
use the more common phrase 'CA bundle'
qwcode 83d8b37
only show --allow-no-ssl when no ssl
qwcode 912784f
ssl docs fix
qwcode 9cda4d6
--allow-no-ssl test fix
qwcode 8fc02eb
py25 install tests with ssl backport
qwcode 1cf1a7e
refactor pip.backwardcompat from module to package
qwcode a6a0ee3
update installation docs related to ssl
qwcode 84f8134
remove HTTPHandler explictly
qwcode f13f879
unable to get ssl backport to install on travis
qwcode 9b57f89
use local packages, not 'mock', which has invalid ssl download link
qwcode 7c8470a
more local test packages
qwcode d0c3138
merge with develop
qwcode 809a996
clear up connection compatibility logic
qwcode 22bf924
merge with develop
qwcode b2a17e5
remove old cert from pem file
qwcode 1857ece
fix import syntax
qwcode c4753b2
add missing sys import
qwcode 26f9c14
move CA license to our license file
qwcode f72ddaa
our next virtualenv release will be 1.9
qwcode a2ba2dc
remove yum/apt-get instructions, since they will likely install non-s…
qwcode e3f1ce8
proper list indents
qwcode 559d77a
from --cert-path to --cert
qwcode 4a4a141
from --allow-no-ssl to --insecure
qwcode 039e1fc
have 'pip search' use https index url
qwcode 2cbc7fa
improve ssl exception text and docs
qwcode 889e1a0
custom NoSSLError exception instead of util function
qwcode db9c92a
remove extra indents in docs
qwcode d6bb9a5
add TODO about options passing
qwcode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
patch for py25 socket to work with http://pypi.python.org/pypi/ssl/ | ||
copy-paste from py2.6 stdlib socket.py | ||
https://gist.github.com/zed/1347055 | ||
""" | ||
import socket | ||
import sys | ||
|
||
_GLOBAL_DEFAULT_TIMEOUT = getattr(socket, '_GLOBAL_DEFAULT_TIMEOUT', object()) | ||
def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT, | ||
source_address=None): | ||
"""Connect to *address* and return the socket object. | ||
|
||
Convenience function. Connect to *address* (a 2-tuple ``(host, | ||
port)``) and return the socket object. Passing the optional | ||
*timeout* parameter will set the timeout on the socket instance | ||
before attempting to connect. If no *timeout* is supplied, the | ||
global default timeout setting returned by :func:`getdefaulttimeout` | ||
is used. | ||
""" | ||
|
||
host, port = address | ||
err = None | ||
for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM): | ||
af, socktype, proto, canonname, sa = res | ||
sock = None | ||
try: | ||
sock = socket.socket(af, socktype, proto) | ||
if timeout is not _GLOBAL_DEFAULT_TIMEOUT: | ||
sock.settimeout(timeout) | ||
if source_address: | ||
sock.bind(source_address) | ||
sock.connect(sa) | ||
return sock | ||
|
||
except socket.error: | ||
err = sys.exc_info()[1] | ||
if sock is not None: | ||
sock.close() | ||
|
||
if err is not None: | ||
raise err | ||
else: | ||
raise socket.error("getaddrinfo returns an empty list") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"""The match_hostname() function from Python 3.2, essential when using SSL.""" | ||
|
||
import re | ||
|
||
__version__ = '3.2a3' | ||
|
||
class CertificateError(ValueError): | ||
pass | ||
|
||
def _dnsname_to_pat(dn): | ||
pats = [] | ||
for frag in dn.split(r'.'): | ||
if frag == '*': | ||
# When '*' is a fragment by itself, it matches a non-empty dotless | ||
# fragment. | ||
pats.append('[^.]+') | ||
else: | ||
# Otherwise, '*' matches any dotless fragment. | ||
frag = re.escape(frag) | ||
pats.append(frag.replace(r'\*', '[^.]*')) | ||
return re.compile(r'\A' + r'\.'.join(pats) + r'\Z', re.IGNORECASE) | ||
|
||
def match_hostname(cert, hostname): | ||
"""Verify that *cert* (in decoded format as returned by | ||
SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 rules | ||
are mostly followed, but IP addresses are not accepted for *hostname*. | ||
|
||
CertificateError is raised on failure. On success, the function | ||
returns nothing. | ||
""" | ||
if not cert: | ||
raise ValueError("empty or no certificate") | ||
dnsnames = [] | ||
san = cert.get('subjectAltName', ()) | ||
for key, value in san: | ||
if key == 'DNS': | ||
if _dnsname_to_pat(value).match(hostname): | ||
return | ||
dnsnames.append(value) | ||
if not san: | ||
# The subject is only checked when subjectAltName is empty | ||
for sub in cert.get('subject', ()): | ||
for key, value in sub: | ||
# XXX according to RFC 2818, the most specific Common Name | ||
# must be used. | ||
if key == 'commonName': | ||
if _dnsname_to_pat(value).match(hostname): | ||
return | ||
dnsnames.append(value) | ||
if len(dnsnames) > 1: | ||
raise CertificateError("hostname %r " | ||
"doesn't match either of %s" | ||
% (hostname, ', '.join(map(repr, dnsnames)))) | ||
elif len(dnsnames) == 1: | ||
raise CertificateError("hostname %r " | ||
"doesn't match %r" | ||
% (hostname, dnsnames[0])) | ||
else: | ||
raise CertificateError("no appropriate commonName or " | ||
"subjectAltName fields were found") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sys
is undefined here.