Skip to content

3.4.7 with OpenSSL 3.0.0 and FIPS fixes #77

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

Open
wants to merge 16 commits into
base: b3.4.7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/downstream.d/certbot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ case "${1}" in
git clone --depth=1 https://github.com/certbot/certbot
cd certbot
git rev-parse HEAD
tools/pip_install_editable.py ./acme[dev]
tools/pip_install_editable.py ./certbot[dev]
tools/pip_install_editable.py ./acme[test]
tools/pip_install_editable.py ./certbot[test]
;;
run)
cd certbot
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/build_openssl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ if [[ "${TYPE}" == "openssl" ]]; then
# avoid installing the docs (for performance)
# https://github.com/openssl/openssl/issues/6685#issuecomment-403838728
make install_sw install_ssldirs
# For OpenSSL 3.0.0 set up the FIPS config. This does not activate it by
# default, but allows programmatic activation at runtime
if [[ "${VERSION}" =~ 3.0.0 && "${CONFIG_FLAGS}" =~ enable-fips ]]; then
# As of alpha16 we have to install it separately and enable it in the config flags
make -j"$(nproc)" install_fips
pushd "${OSSL_PATH}"
# include the conf file generated as part of install_fips
sed -i "s:# .include fipsmodule.cnf:.include $(pwd)/ssl/fipsmodule.cnf:" ssl/openssl.cnf
# uncomment the FIPS section
sed -i 's:# fips = fips_sect:fips = fips_sect:' ssl/openssl.cnf
popd
fi
popd
elif [[ "${TYPE}" == "libressl" ]]; then
curl -O "https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-${VERSION}.tar.gz"
Expand Down
39 changes: 21 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,22 @@ jobs:
linux:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
PYTHON:
- {VERSION: "3.9", TOXENV: "flake,rust,docs", COVERAGE: "false"}
- {VERSION: "pypy3", TOXENV: "pypy3"}
- {VERSION: "3.9", TOXENV: "py39", OPENSSL: {TYPE: "openssl", VERSION: "1.1.0l"}}
- {VERSION: "3.9", TOXENV: "py39", OPENSSL: {TYPE: "openssl", VERSION: "1.1.1i"}}
- {VERSION: "3.9", TOXENV: "py39-ssh", OPENSSL: {TYPE: "openssl", VERSION: "1.1.1i"}}
- {VERSION: "3.9", TOXENV: "py39", OPENSSL: {TYPE: "openssl", VERSION: "1.1.1i", CONFIG_FLAGS: "no-engine no-rc2 no-srtp no-ct"}}
- {VERSION: "3.9", TOXENV: "py39", OPENSSL: {TYPE: "libressl", VERSION: "2.9.2"}}
- {VERSION: "3.9", TOXENV: "py39", OPENSSL: {TYPE: "libressl", VERSION: "3.0.2"}}
- {VERSION: "3.9", TOXENV: "py39", OPENSSL: {TYPE: "libressl", VERSION: "3.1.5"}}
- {VERSION: "3.9", TOXENV: "py39", OPENSSL: {TYPE: "libressl", VERSION: "3.2.3"}}
- {VERSION: "3.9", TOXENV: "py39", OPENSSL: {TYPE: "libressl", VERSION: "3.3.1"}}
- {VERSION: "3.9", TOXENV: "py39", OPENSSL: {TYPE: "openssl", VERSION: "1.1.1m"}}
- {VERSION: "3.9", TOXENV: "py39-ssh", OPENSSL: {TYPE: "openssl", VERSION: "1.1.1m"}}
- {VERSION: "3.9", TOXENV: "py39", OPENSSL: {TYPE: "openssl", VERSION: "1.1.1m", CONFIG_FLAGS: "no-engine no-rc2 no-srtp no-ct"}}
- {VERSION: "3.9", TOXENV: "py39", OPENSSL: {TYPE: "openssl", VERSION: "3.0.1"}}
- {VERSION: "3.9", TOXENV: "py39", TOXARGS: "--enable-fips=1", OPENSSL: {TYPE: "openssl", CONFIG_FLAGS: "enable-fips", VERSION: "3.0.1"}}
- {VERSION: "3.10", TOXENV: "py310"}
RUST:
- stable
name: "${{ matrix.PYTHON.TOXENV }} ${{ matrix.PYTHON.OPENSSL.TYPE }} ${{ matrix.PYTHON.OPENSSL.VERSION }} ${{ matrix.PYTHON.OPENSSL.CONFIG_FLAGS }}"
timeout-minutes: 30
name: "${{ matrix.PYTHON.TOXENV }} ${{ matrix.PYTHON.OPENSSL.TYPE }} ${{ matrix.PYTHON.OPENSSL.VERSION }} ${{ matrix.PYTHON.TOXARGS }} ${{ matrix.PYTHON.OPENSSL.CONFIG_FLAGS }}"
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
Expand Down Expand Up @@ -71,7 +70,7 @@ jobs:
path: ${{ github.workspace }}/osslcache
# When altering the openssl build process you may need to increment the value on the end of this cache key
# so that you can prevent it from fetching the cache and skipping the build step.
key: ${{ matrix.PYTHON.OPENSSL.TYPE }}-${{ matrix.PYTHON.OPENSSL.VERSION }}-${{ env.CONFIG_HASH }}-1
key: ${{ matrix.PYTHON.OPENSSL.TYPE }}-${{ matrix.PYTHON.OPENSSL.VERSION }}-${{ env.CONFIG_HASH }}-2
if: matrix.PYTHON.OPENSSL
- name: Build custom OpenSSL/LibreSSL
run: .github/workflows/build_openssl.sh
Expand All @@ -81,12 +80,12 @@ jobs:
if: matrix.PYTHON.OPENSSL && steps.ossl-cache.outputs.cache-hit != 'true'
- name: Set CFLAGS/LDFLAGS
run: |
echo "CFLAGS=${CFLAGS} -I${OSSL_PATH}/include" >> $GITHUB_ENV
echo "LDFLAGS=${LDFLAGS} -L${OSSL_PATH}/lib -Wl,-rpath=${OSSL_PATH}/lib" >> $GITHUB_ENV
echo "CFLAGS=${CFLAGS} -Werror=implicit-function-declaration -I${OSSL_PATH}/include" >> $GITHUB_ENV
echo "LDFLAGS=${LDFLAGS} -L${OSSL_PATH}/lib -L${OSSL_PATH}/lib64 -Wl,-rpath=${OSSL_PATH}/lib -Wl,-rpath=${OSSL_PATH}/lib64" >> $GITHUB_ENV
if: matrix.PYTHON.OPENSSL
- name: Tests
run: |
tox -r -- --color=yes --wycheproof-root=wycheproof
tox -r -- --color=yes --wycheproof-root=wycheproof ${{ matrix.PYTHON.TOXARGS }}
env:
TOXENV: ${{ matrix.PYTHON.TOXENV }}
- uses: ./.github/actions/upload-coverage
Expand All @@ -98,6 +97,7 @@ jobs:
runs-on: ubuntu-latest
container: ghcr.io/pyca/cryptography-runner-${{ matrix.IMAGE.IMAGE }}
strategy:
fail-fast: false
matrix:
IMAGE:
- {IMAGE: "centos8", TOXENV: "py36"}
Expand All @@ -107,10 +107,10 @@ jobs:
- {IMAGE: "sid", TOXENV: "py39"}
- {IMAGE: "ubuntu-bionic", TOXENV: "py36"}
- {IMAGE: "ubuntu-focal", TOXENV: "py38"}
- {IMAGE: "ubuntu-rolling", TOXENV: "py38"}
- {IMAGE: "ubuntu-rolling", TOXENV: "py38-randomorder"}
- {IMAGE: "ubuntu-rolling", TOXENV: "py39"}
- {IMAGE: "ubuntu-rolling", TOXENV: "py39-randomorder"}
- {IMAGE: "fedora", TOXENV: "py39"}
- {IMAGE: "alpine", TOXENV: "py38"}
- {IMAGE: "alpine", TOXENV: "py39"}
name: "${{ matrix.IMAGE.TOXENV }} on ${{ matrix.IMAGE.IMAGE }}"
timeout-minutes: 30
steps:
Expand Down Expand Up @@ -139,6 +139,7 @@ jobs:
linux-rust:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
PYTHON:
- {VERSION: "3.9", TOXENV: "py39"}
Expand Down Expand Up @@ -184,6 +185,7 @@ jobs:
macos:
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
PYTHON:
- {VERSION: "3.6", TOXENV: "py36", EXTRA_CFLAGS: ""}
Expand Down Expand Up @@ -239,6 +241,7 @@ jobs:
windows:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
WINDOWS:
- {ARCH: 'x86', WINDOWS: 'win32', RUST_TRIPLE: 'i686-pc-windows-msvc'}
Expand Down Expand Up @@ -297,11 +300,11 @@ jobs:
linux-downstream:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
DOWNSTREAM:
- paramiko
- pyopenssl
- twisted
- aws-encryption-sdk
- dynamodb-encryption-sdk
- certbot
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/wheel-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
runs-on: ubuntu-latest
container: ghcr.io/pyca/${{ matrix.MANYLINUX.CONTAINER }}
strategy:
fail-fast: false
matrix:
PYTHON: ["cp36-cp36m"]
MANYLINUX:
Expand Down Expand Up @@ -55,6 +56,7 @@ jobs:
macos:
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
PYTHON:
- VERSION: '3.8'
Expand Down Expand Up @@ -106,6 +108,7 @@ jobs:
windows:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
WINDOWS:
- {ARCH: 'x86', WINDOWS: 'win32', RUST_TRIPLE: 'i686-pc-windows-msvc'}
Expand Down
4 changes: 4 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@
r"https://info.isl.ntt.co.jp/crypt/eng/camellia/",
# Inconsistent small DH params they seem incapable of fixing
r"https://www.secg.org/sec1-v2.pdf",
# Incomplete cert chain
r"https://e-trust.gosuslugi.ru",
# Expired cert (1 week at time of writing)
r"https://www.cosic.esat.kuleuven.be",
]

autosectionlabel_prefix_document = True
2 changes: 2 additions & 0 deletions src/_cffi_src/build_openssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def _extra_compile_args(platform):
modules=[
# This goes first so we can define some cryptography-wide symbols.
"cryptography",
# Provider comes early as well so we define OSSL_LIB_CTX
"provider",
"aes",
"asn1",
"bignum",
Expand Down
3 changes: 3 additions & 0 deletions src/_cffi_src/openssl/cryptography.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

#define CRYPTOGRAPHY_OPENSSL_110F_OR_GREATER \
(OPENSSL_VERSION_NUMBER >= 0x1010006f && !CRYPTOGRAPHY_IS_LIBRESSL)
#define CRYPTOGRAPHY_OPENSSL_300_OR_GREATER \
(OPENSSL_VERSION_NUMBER >= 0x30000000 && !CRYPTOGRAPHY_IS_LIBRESSL)

#define CRYPTOGRAPHY_OPENSSL_LESS_THAN_110J \
(OPENSSL_VERSION_NUMBER < 0x101000af || CRYPTOGRAPHY_IS_LIBRESSL)
Expand All @@ -53,6 +55,7 @@

TYPES = """
static const int CRYPTOGRAPHY_OPENSSL_110F_OR_GREATER;
static const int CRYPTOGRAPHY_OPENSSL_300_OR_GREATER;

static const int CRYPTOGRAPHY_OPENSSL_LESS_THAN_111;
static const int CRYPTOGRAPHY_OPENSSL_LESS_THAN_111B;
Expand Down
1 change: 0 additions & 1 deletion src/_cffi_src/openssl/dh.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
void DH_free(DH *);
int DH_size(const DH *);
int DH_generate_key(DH *);
int DH_compute_key(unsigned char *, const BIGNUM *, DH *);
DH *DHparams_dup(DH *);

/* added in 1.1.0 when the DH struct was opaqued */
Expand Down
7 changes: 6 additions & 1 deletion src/_cffi_src/openssl/err.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

static const int ERR_LIB_EVP;
static const int ERR_LIB_PEM;
static const int ERR_LIB_PROV;
static const int ERR_LIB_ASN1;
static const int ERR_LIB_PKCS12;

Expand All @@ -39,10 +40,14 @@
void ERR_put_error(int, int, int, const char *, int);

int ERR_GET_LIB(unsigned long);
int ERR_GET_FUNC(unsigned long);
int ERR_GET_REASON(unsigned long);

"""

CUSTOMIZATIONS = """
/* This define is tied to provider support and is conditionally
removed if Cryptography_HAS_PROVIDERS is false */
#ifndef ERR_LIB_PROV
#define ERR_LIB_PROV 0
#endif
"""
12 changes: 12 additions & 0 deletions src/_cffi_src/openssl/evp.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
static const int Cryptography_HAS_ONESHOT_EVP_DIGEST_SIGN_VERIFY;
static const long Cryptography_HAS_RAW_KEY;
static const long Cryptography_HAS_EVP_DIGESTFINAL_XOF;
static const long Cryptography_HAS_300_FIPS;
"""

FUNCTIONS = """
Expand Down Expand Up @@ -165,6 +166,9 @@
size_t);
int EVP_PKEY_get_raw_private_key(const EVP_PKEY *, unsigned char *, size_t *);
int EVP_PKEY_get_raw_public_key(const EVP_PKEY *, unsigned char *, size_t *);

int EVP_default_properties_is_fips_enabled(OSSL_LIB_CTX *);
int EVP_default_properties_enable_fips(OSSL_LIB_CTX *, int);
"""

CUSTOMIZATIONS = """
Expand Down Expand Up @@ -269,4 +273,12 @@
#ifndef EVP_PKEY_POLY1305
#define EVP_PKEY_POLY1305 NID_poly1305
#endif

#if CRYPTOGRAPHY_OPENSSL_300_OR_GREATER
static const long Cryptography_HAS_300_FIPS = 1;
#else
static const long Cryptography_HAS_300_FIPS = 0;
int (*EVP_default_properties_is_fips_enabled)(OSSL_LIB_CTX *) = NULL;
int (*EVP_default_properties_enable_fips)(OSSL_LIB_CTX *, int) = NULL;
#endif
"""
2 changes: 1 addition & 1 deletion src/_cffi_src/openssl/fips.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""

CUSTOMIZATIONS = """
#if CRYPTOGRAPHY_IS_LIBRESSL
#if CRYPTOGRAPHY_IS_LIBRESSL || CRYPTOGRAPHY_OPENSSL_300_OR_GREATER
static const long Cryptography_HAS_FIPS = 0;
int (*FIPS_mode_set)(int) = NULL;
int (*FIPS_mode)(void) = NULL;
Expand Down
40 changes: 40 additions & 0 deletions src/_cffi_src/openssl/provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.


INCLUDES = """
#if CRYPTOGRAPHY_OPENSSL_300_OR_GREATER
#include <openssl/provider.h>
#include <openssl/proverr.h>
#endif
"""

TYPES = """
static const long Cryptography_HAS_PROVIDERS;

typedef ... OSSL_PROVIDER;
typedef ... OSSL_LIB_CTX;

static const long PROV_R_BAD_DECRYPT;
static const long PROV_R_WRONG_FINAL_BLOCK_LENGTH;
"""

FUNCTIONS = """
OSSL_PROVIDER *OSSL_PROVIDER_load(OSSL_LIB_CTX *, const char *);
int OSSL_PROVIDER_unload(OSSL_PROVIDER *prov);
"""

CUSTOMIZATIONS = """
#if CRYPTOGRAPHY_OPENSSL_300_OR_GREATER
static const long Cryptography_HAS_PROVIDERS = 1;
#else
static const long Cryptography_HAS_PROVIDERS = 0;
typedef void OSSL_PROVIDER;
typedef void OSSL_LIB_CTX;
static const long PROV_R_BAD_DECRYPT = 0;
static const long PROV_R_WRONG_FINAL_BLOCK_LENGTH = 0;
OSSL_PROVIDER *(*OSSL_PROVIDER_load)(OSSL_LIB_CTX *, const char *) = NULL;
int (*OSSL_PROVIDER_unload)(OSSL_PROVIDER *) = NULL;
#endif
"""
4 changes: 2 additions & 2 deletions src/cryptography/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# for complete details.


from enum import Enum
from cryptography import utils


class _Reasons(Enum):
class _Reasons(utils.Enum):
BACKEND_MISSING_INTERFACE = 0
UNSUPPORTED_HASH = 1
UNSUPPORTED_CIPHER = 2
Expand Down
Loading