Skip to content

Commit

Permalink
Merge pull request #1304 from tahoe-lafs/3998-new-pyopenssl
Browse files Browse the repository at this point in the history
Switch to using officially support constants, now part of pyOpenSSL's public API

Fixes: ticket:3998
  • Loading branch information
exarkun committed Jun 13, 2023
2 parents 839140c + cb082b2 commit 07a288f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
Empty file added newsfragments/3998.minor
Empty file.
10 changes: 10 additions & 0 deletions nix/pyopenssl.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{ pyopenssl, fetchPypi, isPyPy }:
pyopenssl.overrideAttrs (old: rec {
pname = "pyOpenSSL";
version = "23.2.0";
name = "${pname}-${version}";
src = fetchPypi {
inherit pname version;
sha256 = "J2+TH1WkUufeppxxc+mE6ypEB85BPJGKo0tV+C+bi6w=";
};
})
14 changes: 10 additions & 4 deletions nix/python-overrides.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ in {
inherit (super) txtorcon;
};

# Update the version of pyopenssl.
pyopenssl = self.callPackage ./pyopenssl.nix {
pyopenssl =
# Building the docs requires sphinx which brings in a dependency on babel,
# the test suite of which fails.
onPyPy (dontBuildDocs { sphinx-rtd-theme = null; })
# Avoid infinite recursion.
super.pyopenssl;
};

# collections-extended is currently broken for Python 3.11 in nixpkgs but
# we know where a working version lives.
collections-extended = self.callPackage ./collections-extended.nix {
Expand Down Expand Up @@ -63,10 +73,6 @@ in {
# a5f8184fb816a4fd5ae87136838c9981e0d22c67.
six = onPyPy dontCheck super.six;

# Building the docs requires sphinx which brings in a dependency on babel,
# the test suite of which fails.
pyopenssl = onPyPy (dontBuildDocs { sphinx-rtd-theme = null; }) super.pyopenssl;

# Likewise for beautifulsoup4.
beautifulsoup4 = onPyPy (dontBuildDocs {}) super.beautifulsoup4;

Expand Down
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ def read_version_py(infname):
# Twisted[conch] also depends on cryptography and Twisted[tls]
# transitively depends on cryptography. So it's anyone's guess what
# version of cryptography will *really* be installed.
"cryptography >= 2.6",

# * cryptography 40 broke constants we need; should really be using them
# * via pyOpenSSL; will be fixed in
# * https://github.com/pyca/pyopenssl/issues/1201
"cryptography >= 2.6, < 40",
# * Used for custom HTTPS validation
"pyOpenSSL >= 23.2.0",

# * The SFTP frontend depends on Twisted 11.0.0 to fix the SSH server
# rekeying bug <https://twistedmatrix.com/trac/ticket/4395>
Expand Down
13 changes: 5 additions & 8 deletions src/allmydata/storage/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
from treq.client import HTTPClient
from treq.testing import StubTreq
from OpenSSL import SSL
from cryptography.hazmat.bindings.openssl.binding import Binding
from werkzeug.http import parse_content_range_header

from .http_common import (
Expand All @@ -61,8 +60,6 @@
from ..util.hashutil import timing_safe_compare
from ..util.deferredutil import async_to_deferred

_OPENSSL = Binding().lib


def _encode_si(si): # type: (bytes) -> str
"""Encode the storage index into Unicode string."""
Expand Down Expand Up @@ -257,11 +254,11 @@ def always_validate(conn, cert, errno, depth, preverify_ok):
# not the usual TLS concerns about invalid CAs or revoked
# certificates.
things_are_ok = (
_OPENSSL.X509_V_OK,
_OPENSSL.X509_V_ERR_CERT_NOT_YET_VALID,
_OPENSSL.X509_V_ERR_CERT_HAS_EXPIRED,
_OPENSSL.X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT,
_OPENSSL.X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN,
SSL.X509VerificationCodes.OK,
SSL.X509VerificationCodes.ERR_CERT_NOT_YET_VALID,
SSL.X509VerificationCodes.ERR_CERT_HAS_EXPIRED,
SSL.X509VerificationCodes.ERR_DEPTH_ZERO_SELF_SIGNED_CERT,
SSL.X509VerificationCodes.ERR_SELF_SIGNED_CERT_IN_CHAIN,
)
# TODO can we do this once instead of multiple times?
if errno in things_are_ok and timing_safe_compare(
Expand Down

0 comments on commit 07a288f

Please sign in to comment.