Skip to content
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

Path validation: builder/verifier API skeletons #9405

Merged
merged 72 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
36fef28
src, tests: flatten all changes
woodruffw Aug 11, 2023
e4e300f
cryptography, rust: lintage
woodruffw Aug 13, 2023
35a4e28
Merge branch 'main' into tob-x509-api-breakout
woodruffw Aug 13, 2023
bb76afe
cryptography, rust: lintage, add Policy.subject API
woodruffw Aug 13, 2023
3a67770
src, tests: initial PolicyBuilder tests
woodruffw Aug 13, 2023
6cabf0d
verify: Policy.validation_time getter
woodruffw Aug 14, 2023
8157ce4
push Store into rust
woodruffw Aug 14, 2023
5a69a28
cleanup, fixup
woodruffw Aug 14, 2023
539a7b2
Merge remote-tracking branch 'upstream/main' into tob-x509-api-breakout
woodruffw Aug 14, 2023
f6933ca
Merge branch 'main' into tob-x509-api-breakout
woodruffw Aug 14, 2023
91ef5c4
tests: lintage
woodruffw Aug 14, 2023
fbe4132
src: lintage
woodruffw Aug 14, 2023
2b46371
Merge remote-tracking branch 'upstream/main' into tob-x509-api-breakout
woodruffw Aug 17, 2023
1f5ee07
Merge branch 'main' into tob-x509-api-breakout
facutuesca Sep 7, 2023
c96f4b8
tests: fix linter warning
facutuesca Sep 7, 2023
5493338
policy: apply the relevant parts of trail-of-forks/cryptography/pull/3
woodruffw Sep 7, 2023
d900a6e
Merge branch 'main' into tob-x509-api-breakout
woodruffw Sep 12, 2023
0789d73
policy: typo
woodruffw Sep 12, 2023
7852430
fixup type hints
woodruffw Sep 12, 2023
a5154e1
drop dep
woodruffw Sep 12, 2023
08df667
Revert "drop dep"
woodruffw Sep 12, 2023
d2d54c4
Merge remote-tracking branch 'upstream/main' into tob-x509-api-breakout
woodruffw Sep 12, 2023
2c1017b
mod: remove permits_* bodies
woodruffw Sep 12, 2023
fafafcd
src: drop certificate helpers as well
woodruffw Sep 12, 2023
35c3d9f
verify: remove unneeded explicit lifetimes
woodruffw Sep 12, 2023
9b62075
tests: builder API coverage
woodruffw Sep 12, 2023
438e59d
tests: more coverage
woodruffw Sep 12, 2023
318393c
type hints
woodruffw Sep 12, 2023
cf3ad95
unused derives
woodruffw Sep 12, 2023
27f7628
validation: more coverage
woodruffw Sep 12, 2023
00af5ca
policy: more cov
woodruffw Sep 12, 2023
7d1b0c1
policy: more coverage
woodruffw Sep 12, 2023
9ec4154
policy: add some known bad testcases
woodruffw Sep 13, 2023
92804f1
policy: coverage
woodruffw Sep 13, 2023
6b45a77
Merge remote-tracking branch 'upstream/main' into tob-x509-api-breakout
woodruffw Sep 13, 2023
e956dd6
validation: remove trust_store
woodruffw Sep 13, 2023
26cee8b
ops: add NullOps test
woodruffw Sep 13, 2023
aa45a4f
x509: reimplement verify_directly_issued_by via CryptoOps
woodruffw Sep 13, 2023
7f3cef1
Merge branch 'main' into tob-x509-api-breakout
woodruffw Sep 13, 2023
69538d8
ops: use results
woodruffw Sep 13, 2023
1f7dc3a
src, tests: last cov, hopefully
woodruffw Sep 13, 2023
d355128
test: lintage
woodruffw Sep 13, 2023
a4e7d34
docs: fill in API docs
woodruffw Sep 13, 2023
083ad34
Merge branch 'main' into tob-x509-api-breakout
woodruffw Sep 14, 2023
f217a36
Merge branch 'main' into tob-x509-api-breakout
woodruffw Sep 15, 2023
cd3887a
rust: uniform imports
woodruffw Sep 15, 2023
fb078fc
minimize for MVP
woodruffw Sep 15, 2023
a48d6af
verify: remove old NOTE
woodruffw Sep 15, 2023
9920ef1
verify: remove another old NOTE
woodruffw Sep 15, 2023
1aa0253
src, tests: fixup tests
woodruffw Sep 15, 2023
640d735
docs: cleanup
woodruffw Sep 15, 2023
96269ce
src, tests: drop support for missing subjects
woodruffw Sep 15, 2023
8aefa1c
profile: remove old comments
woodruffw Sep 15, 2023
00d960e
policy: remove some verify-adjacent APIs
woodruffw Sep 15, 2023
03fb4b7
policy: remove more verify-adjacent APIs
woodruffw Sep 15, 2023
9ffbc9d
policy: remove some From impls
woodruffw Sep 15, 2023
ad90a81
policy: remove rfc5280 constructor
woodruffw Sep 15, 2023
3610191
docs: declutter diff
woodruffw Sep 15, 2023
05fb380
profile: prune even more state
woodruffw Sep 15, 2023
d0842ce
policy: remove old TODO
woodruffw Sep 15, 2023
924c749
policy: remove PolicyError
woodruffw Sep 15, 2023
7cad491
docs: typo
woodruffw Sep 15, 2023
92259c7
ops: remove NullOps
woodruffw Sep 15, 2023
a5a88e6
rust: remove dev-dep, don't use import
woodruffw Sep 16, 2023
5e18f8e
rust: fix IP_ADDRESS rename
woodruffw Sep 16, 2023
de2c7b0
docs: clarify time behavior
woodruffw Sep 16, 2023
a1a7c57
rename webpki() to new()
woodruffw Sep 16, 2023
2e7bd70
docs: relocate
woodruffw Sep 16, 2023
35f5e6f
verify: FixedPolicy -> PyCryptoPolicy
woodruffw Sep 16, 2023
3c036bc
verify: simplify SubjectOwner substantially
woodruffw Sep 16, 2023
fbb2e6a
verify: remove getter helper
woodruffw Sep 16, 2023
0f91265
verify: reloc TODO
woodruffw Sep 16, 2023
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
35 changes: 30 additions & 5 deletions docs/x509/verification.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ chain building, etc.
OS's root of trust, from a well-known source such as a browser CA bundle,
or from a small set of manually pre-trusted entities.

:param certs: A list of one or more :class:`~cryptography.x509.Certificate`
:param certs: A list of one or more :class:`cryptography.x509.Certificate`
instances.

.. class:: Subject
Expand All @@ -30,6 +30,31 @@ chain building, etc.
:class:`cryptography.x509.general_name.DNSName`,
:class:`cryptography.x509.general_name.IPAddress`.

.. class:: ServerVerifier

.. versionadded:: 42.0.0

A ServerVerifier verifies server certificates.

It contains and describes various pieces of configurable path
validation logic, such as which subject to expect, how deep prospective
validation chains may go, which signature algorithms are allowed, and
so forth.

ServerVerifier instances cannot be constructed directly;
:class:`PolicyBuilder` must be used.

.. attribute:: subject

:type: :class:`Subject`

The verifier's subject.

.. attribute:: validation_time

:type: :class:`datetime.datetime`

The verifier's validation time.

.. class:: PolicyBuilder

Expand All @@ -40,16 +65,16 @@ chain building, etc.

.. method:: time(new_time)

Sets the policy's verification time.
Sets the verifier's verification time.

:param new_time: The :class:`datetime.datetime` to use in the policy
:param new_time: The :class:`datetime.datetime` to use in the verifier

:returns: A new instance of :class:`PolicyBuilder`

.. method:: build_server_verifier(subject)

Builds a verifier for verifying server certificates.

:param subject: A :class:`Subject` to use in the policy
:param subject: A :class:`Subject` to use in the verifier

:raises NotImplementedError: This API is not implemented yet.
:returns: An instance of :class:`ServerVerifier`
12 changes: 12 additions & 0 deletions src/cryptography/hazmat/bindings/_rust/x509.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.

import datetime

from cryptography import x509
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric.padding import PSS, PKCS1v15
Expand Down Expand Up @@ -35,12 +37,22 @@ def create_x509_crl(
private_key: PrivateKeyTypes,
hash_algorithm: hashes.HashAlgorithm | None,
) -> x509.CertificateRevocationList: ...
def create_server_verifier(
name: x509.verification.Subject,
time: datetime.datetime | None,
) -> x509.verification.ServerVerifier: ...

class Sct: ...
class Certificate: ...
class RevokedCertificate: ...
class CertificateRevocationList: ...
class CertificateSigningRequest: ...

class ServerVerifier:
@property
def subject(self) -> x509.verification.Subject: ...
@property
def validation_time(self) -> datetime.datetime: ...

class Store:
def __init__(self, certs: list[x509.Certificate]) -> None: ...
1 change: 1 addition & 0 deletions src/cryptography/x509/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@

__all__ = [
"certificate_transparency",
"verification",
"load_pem_x509_certificate",
"load_pem_x509_certificates",
"load_der_x509_certificate",
Expand Down
8 changes: 5 additions & 3 deletions src/cryptography/x509/verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
from cryptography.hazmat.bindings._rust import x509 as rust_x509
from cryptography.x509.general_name import DNSName, IPAddress

__all__ = ["Store", "Subject", "PolicyBuilder"]
__all__ = ["Store", "Subject", "ServerVerifier", "PolicyBuilder"]

Store = rust_x509.Store

Subject = typing.Union[DNSName, IPAddress]

ServerVerifier = rust_x509.ServerVerifier


class PolicyBuilder:
def __init__(
Expand All @@ -36,9 +38,9 @@ def time(self, new_time: datetime.datetime) -> PolicyBuilder:
time=new_time,
)

def build_server_verifier(self, subject: Subject) -> typing.NoReturn:
def build_server_verifier(self, subject: Subject) -> ServerVerifier:
"""
Builds a verifier for verifying server certificates.
"""

raise NotImplementedError
return rust_x509.create_server_verifier(subject, self._time)
20 changes: 18 additions & 2 deletions src/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/rust/cryptography-x509-validation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ rust-version = "1.63.0"
asn1 = { version = "0.15.5", default-features = false }
cryptography-x509 = { path = "../cryptography-x509" }
once_cell = "1"

[dev-dependencies]
pem = "1.1"
woodruffw marked this conversation as resolved.
Show resolved Hide resolved
36 changes: 36 additions & 0 deletions src/rust/cryptography-x509-validation/src/policy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use cryptography_x509::common::{
PSS_SHA512_MASK_GEN_ALG,
};

use crate::ops::CryptoOps;
use crate::types::{DNSName, IPAddress};

// RSASSA‐PKCS1‐v1_5 with SHA‐256
static RSASSA_PKCS1V15_SHA256: AlgorithmIdentifier<'_> = AlgorithmIdentifier {
oid: asn1::DefinedByMarker::marker(),
Expand Down Expand Up @@ -97,6 +100,39 @@ pub static WEBPKI_PERMITTED_ALGORITHMS: Lazy<HashSet<&AlgorithmIdentifier<'_>>>
])
});

/// Represents a logical certificate "subject," i.e. a principal matching
/// one of the names listed in a certificate's `subjectAltNames` extension.
pub enum Subject<'a> {
DNS(DNSName<'a>),
IP(IPAddress),
}

/// A `Policy` describes user-configurable aspects of X.509 path validation.
pub struct Policy<'a, B: CryptoOps> {
_ops: B,

/// A subject (i.e. DNS name or other name format) that any EE certificates
/// validated by this policy must match.
/// If `None`, the EE certificate must not contain a SAN.
pub subject: Option<Subject<'a>>,

/// The validation time. All certificates validated by this policy must
/// be valid at this time.
pub validation_time: asn1::DateTime,
}

impl<'a, B: CryptoOps> Policy<'a, B> {
/// Create a new policy with defaults for the certificate profile defined in
/// the CA/B Forum's Basic Requirements.
pub fn webpki(ops: B, subject: Option<Subject<'a>>, time: asn1::DateTime) -> Self {
Self {
_ops: ops,
subject,
validation_time: time,
}
}
}

woodruffw marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(test)]
mod tests {
use std::ops::Deref;
Expand Down
2 changes: 1 addition & 1 deletion src/rust/cryptography-x509-validation/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::str::FromStr;
/// # use cryptography_x509_validation::types::DNSName;
/// assert_eq!(DNSName::new("foo.com").unwrap(), DNSName::new("FOO.com").unwrap());
/// ```
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct DNSName<'a>(asn1::IA5String<'a>);

impl<'a> DNSName<'a> {
Expand Down
Loading
Loading