Skip to main content

Service identity verification for pyOpenSSL.

Project description

https://travis-ci.org/hynek/service_identity.png?branch=master https://coveralls.io/repos/hynek/service_identity/badge.png

WARNING

This software is currently alpha and under review. Use it at your own peril.

Any part is subject to change, but feedback is very welcome!

Pitch

service_identity aspires to give you all the tools you need for verifying whether a certificate is valid for the intended purposes.

In the simplest case, this means host name verification. However, service_identity implements RFC 6125 fully and plans to add other relevant RFCs too.

Features

Present

  • dNSName with fallback to CN (DNS-ID, aka host names, RFC 6125).

  • uniformResourceIdentifier (URI-ID, RFC 6125).

  • SRV-ID (RFC 6125)

Future

Usage

Verify a Hostname

The simplest, most common, and most important usage:

from __future__ import absolute_import, division, print_function

import socket

from OpenSSL import SSL
from service_identity import VerificationError
from service_identity.pyopenssl import verify_hostname


ctx = SSL.Context(SSL.SSLv23_METHOD)
ctx.set_verify(SSL.VERIFY_PEER, lambda conn, cert, errno, depth, ok: ok)
ctx.set_default_verify_paths()

hostname = u"twistedmatrix.com"
conn = SSL.Connection(ctx, socket.socket(socket.AF_INET, socket.SOCK_STREAM))
conn.connect((hostname, 443))

try:
    conn.do_handshake()
    verify_hostname(conn, hostname)
    # Do your super-secure stuff here.
except SSL.Error as e:
    print("TLS Handshake failed: {0!r}.".format(e.args[0]))
except VerificationError:
    print("Presented certificate is not valid for {0}.".format(hostname))
finally:
    conn.shutdown()
    conn.close()

Requirements

Python 2.6, 2.7, 3.2, 3.3, and 3.4 as well as PyPy are supported.

Additionally, the following PyPI modules are required:

Optionally, idna can be used for internationalized domain names (IDN), aka non-ASCII domains. Please note, that idna is not available for Python 3.2 and is required because Python’s stdlib support is outdated.

History

0.2.0 (2014-04-06)

This release contains multiple backward-incompatible changes.

  • Refactor into a multi-module package. Most notably, verify_hostname and extract_ids live in the service_identity.pyopenssl module now.

  • verify_hostname now takes an OpenSSL.SSL.Connection for the first argument.

  • Less false positives in IP address detection.

  • Officially support Python 3.4 too.

  • More strict checks for URI_IDs.

0.1.0 (2014-03-03)

  • Initial release.

Authors

service_identity is currently maintained by Hynek Schlawack.

If you think you’ve found a security-relevant bug, please contact me privately and ideally encrypt your message using PGP. I will then work with you on a responsible resolution. You can find my contact information and PGP data on my homepage.

Contributors

The following wonderful people contributed directly or indirectly to this project:

Please add yourself here alphabetically when you submit your first pull request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

service_identity-0.2.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

service_identity-0.2-py2.py3-none-any.whl (12.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file service_identity-0.2.tar.gz.

File metadata

File hashes

Hashes for service_identity-0.2.tar.gz
Algorithm Hash digest
SHA256 adb0f07b541fb40b9c023f40e1e7520ea382d8d692c22d37e08236dc2552e1f4
MD5 5fd2b5103291e71b3afe23aaeefb89f2
BLAKE2b-256 ab22d6c2eed070cc6b95681925560a611c80438e44e7bb4cd2b1201597255ddf

See more details on using hashes here.

File details

Details for the file service_identity-0.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for service_identity-0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f3a288ddb23448e8c6498af3d7a1f1348569b3a18a4c3e645c72e180692523d1
MD5 859428617de6ac522b781a3d0a1d6689
BLAKE2b-256 4c0a0e7f5420f90d99846163a1ffa9a6b1be29fffbaf7e6d3827cda4293f53ae

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page