Skip to content
Merged
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
14 changes: 12 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,24 @@ concurrency:
jobs:
test:

runs-on: ubuntu-latest
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
strategy:
fail-fast: false
matrix:
python:
- "3.8"
- "3.12"
- "3.x"
include:
- os: ubuntu-22.04
python: "3.7"

steps:
- uses: actions/checkout@v4
- name: setup
uses: actions/setup-python@v5
with:
python-version: '3.x'
python-version: ${{ matrix.python }}
- name: install
run: |
python -m pip install --upgrade pip
Expand Down
4 changes: 4 additions & 0 deletions certipy/certipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,10 @@ def create_signed_pair(
cacert = ca_bundle.cert.load()
cakey = ca_bundle.key.load()

extensions.append(
(x509.AuthorityKeyIdentifier.from_issuer_public_key(cacert.public_key()), False)
Copy link
Collaborator Author

@minrk minrk Mar 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what was requires to pass default ssl checks in Python 3.13

)

now = datetime.now(timezone.utc)
eol = now + timedelta(days=years * 365)
cert = self.sign(
Expand Down
21 changes: 14 additions & 7 deletions certipy/test/test_certipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@

import os
import pytest
import requests
import socket
import ssl
from urllib.request import urlopen, URLError
from contextlib import closing, contextmanager
from datetime import datetime, timedelta, timezone
from flask import Flask
from requests.exceptions import SSLError
from tempfile import TemporaryDirectory
from threading import Thread
from werkzeug.serving import make_server
Expand Down Expand Up @@ -54,14 +53,16 @@ def make_flask_app():
@app.route("/")
def working():
return "working"

return app


@contextmanager
def tls_server(certfile: str, keyfile: str, host: str = "localhost", port: int = 0):
if port == 0:
port = find_free_port()

ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ssl_context.load_cert_chain(certfile, keyfile)
server = make_server(
host, port, make_flask_app(), ssl_context=ssl_context, threaded=True
Expand Down Expand Up @@ -373,10 +374,16 @@ def test_certs():
) as server:
# Execute/Verify
url = f"https://{server.host}:{server.port}"

# Fails without specifying a CA for verification
with pytest.raises(SSLError):
requests.get(url)
with pytest.raises(URLError, match="SSL"):
with urlopen(url):
pass

ssl_context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH, cafile=ca_record["files"]["cert"])
ssl_context.verify_mode = ssl.CERT_REQUIRED
ssl_context.load_default_certs()
ssl_context.load_cert_chain(ca_record["files"]["cert"], ca_record["files"]["key"])

# Succeeds when supplying the CA cert
requests.get(url, verify=ca_record["files"]["cert"])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, the reason I switched from requests to urlopen here is that requests does not use the default ssl config and this test still passed, even on 3.13. Only http libraries that use more default ssl setup (urllib, httpx, tornado, etc.) see this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I figured that might have been why you did that. So it seems the default ssl setup is more strict than what requests is enforcing. Thanks for letting me know.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, requests predates a lot of the standard library SSL stuff and is pretty hardcore about not changing default behavior no matter what, so changes in the standard library often don't affect requests.

with urlopen(url, context=ssl_context):
pass
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# SPDX-License-Identifier: BSD-3-Clause
###############################################################################
[build-system]
requires = ["setuptools>=64", "setuptools_scm>=8"]
requires = ["setuptools>=64", "setuptools_scm>=7"]
build-backend = "setuptools.build_meta"

[project]
Expand Down Expand Up @@ -41,7 +41,7 @@ requires-python = ">=3.7"
dependencies = ["cryptography"]

[project.optional-dependencies]
dev = ["pytest", "flask", "build", "requests", "pre-commit", "ruff", "bump-my-version"]
dev = ["pytest", "flask", "build", "pre-commit", "ruff", "bump-my-version"]

[tool.setuptools.dynamic]
version = {attr = "certipy.version.__version__"}
Expand Down