summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2015-09-05 08:58:07 -0400
committerAlex Gaynor <alex.gaynor@gmail.com>2015-09-05 08:58:07 -0400
commit4e2fe97e20e5ea2af3017c963a040f25a01dc206 (patch)
tree044ca39a405e681b3bcf202a172b1dd1b3ef574a
parentb9521c8ec871abbe784af36467f46a7dd00c8d8a (diff)
parent8594f700d90e2846c2ede68079a41ff5a8665087 (diff)
downloadpyopenssl-4e2fe97e20e5ea2af3017c963a040f25a01dc206.tar.gz
Merge branch 'master' into alex-patch-2
-rw-r--r--OpenSSL/SSL.py9
-rw-r--r--OpenSSL/_util.py7
-rw-r--r--OpenSSL/crypto.py6
-rw-r--r--OpenSSL/rand.py1
-rw-r--r--OpenSSL/test/test_crypto.py18
-rw-r--r--OpenSSL/test/test_ssl.py31
-rw-r--r--OpenSSL/tsafe.py1
-rw-r--r--README.rst4
-rw-r--r--doc/conf.py2
-rw-r--r--examples/proxy.py2
-rw-r--r--setup.cfg3
11 files changed, 46 insertions, 38 deletions
diff --git a/OpenSSL/SSL.py b/OpenSSL/SSL.py
index 17775d2..ef37fd2 100644
--- a/OpenSSL/SSL.py
+++ b/OpenSSL/SSL.py
@@ -291,9 +291,9 @@ class _NpnSelectHelper(_CallbackExceptionHelper):
protolist = []
while instr:
l = indexbytes(instr, 0)
- proto = instr[1:l+1]
+ proto = instr[1:l + 1]
protolist.append(proto)
- instr = instr[l+1:]
+ instr = instr[l + 1:]
# Call the callback
outstr = callback(conn, protolist)
@@ -1146,7 +1146,10 @@ class Connection(object):
Look up attributes on the wrapped socket object if they are not found on
the Connection object.
"""
- return getattr(self._socket, name)
+ if self._socket is None:
+ raise AttributeError("'" + self.__class__.__name__ + "' object has no attribute '" + name + "'")
+ else:
+ return getattr(self._socket, name)
def _raise_ssl_error(self, ssl, result):
diff --git a/OpenSSL/_util.py b/OpenSSL/_util.py
index 0cc34d8..b3ea8f7 100644
--- a/OpenSSL/_util.py
+++ b/OpenSSL/_util.py
@@ -41,9 +41,9 @@ def exception_from_error_queue(exception_type):
if error == 0:
break
errors.append((
- text(lib.ERR_lib_error_string(error)),
- text(lib.ERR_func_error_string(error)),
- text(lib.ERR_reason_error_string(error))))
+ text(lib.ERR_lib_error_string(error)),
+ text(lib.ERR_func_error_string(error)),
+ text(lib.ERR_reason_error_string(error))))
raise exception_type(errors)
@@ -104,6 +104,7 @@ _TEXT_WARNING = (
text_type.__name__ + " for {0} is no longer accepted, use bytes"
)
+
def text_to_bytes_and_warn(label, obj):
"""
If ``obj`` is text, emit a warning that it should be bytes instead and try
diff --git a/OpenSSL/crypto.py b/OpenSSL/crypto.py
index 92ec815..0ff65dc 100644
--- a/OpenSSL/crypto.py
+++ b/OpenSSL/crypto.py
@@ -1579,7 +1579,7 @@ class X509StoreContext(object):
Convert an OpenSSL native context error failure into a Python
exception.
- When a call to native OpenSSL X509_verify_cert fails, additonal information
+ When a call to native OpenSSL X509_verify_cert fails, additional information
about the failure can be obtained from the store context.
"""
errors = [
@@ -1617,7 +1617,7 @@ class X509StoreContext(object):
:param store_ctx: The :py:class:`X509StoreContext` to verify.
- :raises X509StoreContextError: If an error occured when validating a
+ :raises X509StoreContextError: If an error occurred when validating a
certificate in the context. Sets ``certificate`` attribute to indicate
which certificate caused the error.
"""
@@ -1785,7 +1785,7 @@ class Revoked(object):
b"cessationOfOperation",
b"certificateHold",
# b"removeFromCRL",
- ]
+ ]
def __init__(self):
revoked = _lib.X509_REVOKED_new()
diff --git a/OpenSSL/rand.py b/OpenSSL/rand.py
index 3adf693..27d9f7e 100644
--- a/OpenSSL/rand.py
+++ b/OpenSSL/rand.py
@@ -26,6 +26,7 @@ _unspecified = object()
_builtin_bytes = bytes
+
def bytes(num_bytes):
"""
Get some random bytes as a string.
diff --git a/OpenSSL/test/test_crypto.py b/OpenSSL/test/test_crypto.py
index 8b310dd..5b8ab77 100644
--- a/OpenSSL/test/test_crypto.py
+++ b/OpenSSL/test/test_crypto.py
@@ -426,7 +426,7 @@ class X509ExtTests(TestCase):
self.x509.set_issuer(self.subject)
self.x509.set_pubkey(self.pkey)
now = b(datetime.now().strftime("%Y%m%d%H%M%SZ"))
- expire = b((datetime.now() + timedelta(days=100)).strftime("%Y%m%d%H%M%SZ"))
+ expire = b((datetime.now() + timedelta(days=100)).strftime("%Y%m%d%H%M%SZ"))
self.x509.set_notBefore(now)
self.x509.set_notAfter(expire)
@@ -754,9 +754,9 @@ class PKeyTests(TestCase):
"""
key = PKey()
for type, bits in [(TYPE_RSA, 512), (TYPE_DSA, 576)]:
- key.generate_key(type, bits)
- self.assertEqual(key.type(), type)
- self.assertEqual(key.bits(), bits)
+ key.generate_key(type, bits)
+ self.assertEqual(key.type(), type)
+ self.assertEqual(key.bits(), bits)
def test_inconsistentKey(self):
@@ -1940,7 +1940,7 @@ class PKCS12Tests(TestCase):
self.assertRaises(TypeError, p12.set_ca_certificates, 3)
self.assertRaises(TypeError, p12.set_ca_certificates, X509())
self.assertRaises(TypeError, p12.set_ca_certificates, (3, 4))
- self.assertRaises(TypeError, p12.set_ca_certificates, ( PKey(), ))
+ self.assertRaises(TypeError, p12.set_ca_certificates, (PKey(),))
self.assertRaises(TypeError, p12.set_friendlyname, 6)
self.assertRaises(TypeError, p12.set_friendlyname, ('foo', 'bar'))
@@ -2173,8 +2173,8 @@ class PKCS12Tests(TestCase):
"""
passwd = 'whatever'
e = self.assertRaises(Error, load_pkcs12, b'fruit loops', passwd)
- self.assertEqual( e.args[0][0][0], 'asn1 encoding routines')
- self.assertEqual( len(e.args[0][0]), 3)
+ self.assertEqual(e.args[0][0][0], 'asn1 encoding routines')
+ self.assertEqual(len(e.args[0][0]), 3)
def test_replace(self):
@@ -3043,7 +3043,7 @@ class CRLTests(TestCase):
that it is empty
"""
crl = CRL()
- self.assertTrue( isinstance(crl, CRL) )
+ self.assertTrue(isinstance(crl, CRL))
self.assertEqual(crl.get_revoked(), None)
@@ -3222,7 +3222,7 @@ class CRLTests(TestCase):
def test_export_unknown_digest(self):
"""
- Calling :py:obj:`OpenSSL.CRL.export` with a unsupported digest results
+ Calling :py:obj:`OpenSSL.CRL.export` with an unsupported digest results
in a :py:obj:`ValueError` being raised.
"""
crl = CRL()
diff --git a/OpenSSL/test/test_ssl.py b/OpenSSL/test/test_ssl.py
index a71aed9..4d41b15 100644
--- a/OpenSSL/test/test_ssl.py
+++ b/OpenSSL/test/test_ssl.py
@@ -2193,6 +2193,17 @@ class ConnectionTests(TestCase, _LoopbackMixin):
self.assertRaises(TypeError, connection.connect)
self.assertRaises(TypeError, connection.connect, ("127.0.0.1", 1), None)
+ def test_connection_undefined_attr(self):
+ """
+ :py:obj:`Connection.connect` raises :py:obj:`TypeError` if called with a non-address
+ argument or with the wrong number of arguments.
+ """
+
+ def attr_access_test(connection):
+ return connection.an_attribute_which_is_not_defined
+
+ connection = Connection(Context(TLSv1_METHOD), None)
+ self.assertRaises(AttributeError, attr_access_test, connection)
def test_connect_refused(self):
"""
@@ -2297,9 +2308,9 @@ class ConnectionTests(TestCase, _LoopbackMixin):
self.assertRaises(ZeroReturnError, client.recv, 1024)
self.assertEquals(client.get_shutdown(), RECEIVED_SHUTDOWN)
client.shutdown()
- self.assertEquals(client.get_shutdown(), SENT_SHUTDOWN|RECEIVED_SHUTDOWN)
+ self.assertEquals(client.get_shutdown(), SENT_SHUTDOWN | RECEIVED_SHUTDOWN)
self.assertRaises(ZeroReturnError, server.recv, 1024)
- self.assertEquals(server.get_shutdown(), SENT_SHUTDOWN|RECEIVED_SHUTDOWN)
+ self.assertEquals(server.get_shutdown(), SENT_SHUTDOWN | RECEIVED_SHUTDOWN)
def test_shutdown_closed(self):
@@ -2773,7 +2784,7 @@ class ConnectionTests(TestCase, _LoopbackMixin):
def test_get_protocol_version(self):
"""
- :py:obj:`Connection.get_protocol_version()` returns an integer
+ :py:obj:`Connection.get_protocol_version()` returns an integer
giving the protocol version of the current connection.
"""
server, client = self._loopback()
@@ -3374,8 +3385,8 @@ class MemoryBIOTests(TestCase, _LoopbackMixin):
# Create the server side Connection. This is mostly setup boilerplate
# - use TLSv1, use a particular certificate, etc.
server_ctx = Context(TLSv1_METHOD)
- server_ctx.set_options(OP_NO_SSLv2 | OP_NO_SSLv3 | OP_SINGLE_DH_USE )
- server_ctx.set_verify(VERIFY_PEER|VERIFY_FAIL_IF_NO_PEER_CERT|VERIFY_CLIENT_ONCE, verify_cb)
+ server_ctx.set_options(OP_NO_SSLv2 | OP_NO_SSLv3 | OP_SINGLE_DH_USE)
+ server_ctx.set_verify(VERIFY_PEER | VERIFY_FAIL_IF_NO_PEER_CERT | VERIFY_CLIENT_ONCE, verify_cb)
server_store = server_ctx.get_cert_store()
server_ctx.use_privatekey(load_privatekey(FILETYPE_PEM, server_key_pem))
server_ctx.use_certificate(load_certificate(FILETYPE_PEM, server_cert_pem))
@@ -3396,8 +3407,8 @@ class MemoryBIOTests(TestCase, _LoopbackMixin):
# Now create the client side Connection. Similar boilerplate to the
# above.
client_ctx = Context(TLSv1_METHOD)
- client_ctx.set_options(OP_NO_SSLv2 | OP_NO_SSLv3 | OP_SINGLE_DH_USE )
- client_ctx.set_verify(VERIFY_PEER|VERIFY_FAIL_IF_NO_PEER_CERT|VERIFY_CLIENT_ONCE, verify_cb)
+ client_ctx.set_options(OP_NO_SSLv2 | OP_NO_SSLv3 | OP_SINGLE_DH_USE)
+ client_ctx.set_verify(VERIFY_PEER | VERIFY_FAIL_IF_NO_PEER_CERT | VERIFY_CLIENT_ONCE, verify_cb)
client_store = client_ctx.get_cert_store()
client_ctx.use_privatekey(load_privatekey(FILETYPE_PEM, client_key_pem))
client_ctx.use_certificate(load_certificate(FILETYPE_PEM, client_cert_pem))
@@ -3484,9 +3495,9 @@ class MemoryBIOTests(TestCase, _LoopbackMixin):
context = Context(SSLv3_METHOD)
client = socket()
clientSSL = Connection(context, client)
- self.assertRaises( TypeError, clientSSL.bio_read, 100)
- self.assertRaises( TypeError, clientSSL.bio_write, "foo")
- self.assertRaises( TypeError, clientSSL.bio_shutdown )
+ self.assertRaises(TypeError, clientSSL.bio_read, 100)
+ self.assertRaises(TypeError, clientSSL.bio_write, "foo")
+ self.assertRaises(TypeError, clientSSL.bio_shutdown)
def test_outgoingOverflow(self):
diff --git a/OpenSSL/tsafe.py b/OpenSSL/tsafe.py
index 3a9c710..28df8cb 100644
--- a/OpenSSL/tsafe.py
+++ b/OpenSSL/tsafe.py
@@ -25,4 +25,3 @@ class Connection:
return self._ssl_conn.%s(*args)
finally:
self._lock.release()\n""" % (f, f))
-
diff --git a/README.rst b/README.rst
index e00ec67..ee95c1f 100644
--- a/README.rst
+++ b/README.rst
@@ -1,10 +1,6 @@
pyOpenSSL -- A Python wrapper around the OpenSSL library
--------------------------------------------------------
-.. image:: https://img.shields.io/pypi/v/pyOpenSSL.svg
- :target: https://pypi.python.org/pypi/pyOpenSSL/
- :alt: Latest Version
-
.. image:: https://readthedocs.org/projects/pyopenssl/badge/?version=latest
:target: https://pyopenssl.readthedocs.org/
:alt: Latest Docs
diff --git a/doc/conf.py b/doc/conf.py
index 5d34ae7..7d0fe9c 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -23,7 +23,7 @@ HERE = os.path.abspath(os.path.dirname(__file__))
def read_file(*parts):
"""
- Build an absolute path from *parts* and and return the contents of the
+ Build an absolute path from *parts* and return the contents of the
resulting file. Assume UTF-8 encoding.
"""
with codecs.open(os.path.join(HERE, *parts), "rb", "ascii") as f:
diff --git a/examples/proxy.py b/examples/proxy.py
index b094864..b1c4253 100644
--- a/examples/proxy.py
+++ b/examples/proxy.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# This script demostrates how one can use pyOpenSSL to speak SSL over an HTTP
+# This script demonstrates how one can use pyOpenSSL to speak SSL over an HTTP
# proxy
# The challenge here is to start talking SSL over an already connected socket
#
diff --git a/setup.cfg b/setup.cfg
index f0b8316..5d01381 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -11,6 +11,3 @@ build-requires = openssl-devel python-devel python-sphinx
group = Development/Libraries
build_script = rpm/build_script
doc-files = doc/_build/html
-
-[flake8]
-ignore = E303