-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Allow separate public key in CSR #15400
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1615,6 +1615,23 @@ X.509 CSR (Certificate Signing Request) Builder Object | |
| :returns: A new | ||
| :class:`~cryptography.x509.CertificateSigningRequest`. | ||
|
|
||
| .. method:: verify_directly_signed_by(public_key) | ||
|
|
||
| .. versionadded:: 51.0.0 | ||
|
|
||
| :param public_key: One of | ||
| :data:`~cryptography.hazmat.primitives.asymmetric.types.PublicKeyTypes`. | ||
|
|
||
| Validates that the request is signed by the private key belonging to | ||
| provided public key. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docs need to explain what is actually going on here -- the conventional CSR is self-signed, so why would one need this? |
||
|
|
||
| :return: None | ||
| :raise ValueError: If the signature algorithms of the request and | ||
| provided public key do not match. | ||
| :raise TypeError: If the signer does not have a supported public | ||
| key type. | ||
| :raise cryptography.exceptions.InvalidSignature: If the | ||
| signature fails to verify. | ||
|
|
||
| .. class:: Name | ||
| :canonical: cryptography.x509.name.Name | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -183,13 +183,15 @@ class CertificateSigningRequestBuilder: | |
| def __init__( | ||
| self, | ||
| subject_name: Name | None = None, | ||
| public_key: CertificatePublicKeyTypes | None = None, | ||
| extensions: list[Extension[ExtensionType]] = [], | ||
| attributes: list[tuple[ObjectIdentifier, bytes, int | None]] = [], | ||
| ): | ||
| """ | ||
| Creates an empty X.509 certificate request (v1). | ||
| """ | ||
| self._subject_name = subject_name | ||
| self._public_key = public_key | ||
| self._extensions = extensions | ||
| self._attributes = attributes | ||
|
|
||
|
|
@@ -202,7 +204,45 @@ def subject_name(self, name: Name) -> CertificateSigningRequestBuilder: | |
| if self._subject_name is not None: | ||
| raise ValueError("The subject name may only be set once.") | ||
| return CertificateSigningRequestBuilder( | ||
| name, self._extensions, self._attributes | ||
| name, self._public_key, self._extensions, self._attributes | ||
| ) | ||
|
|
||
| def public_key( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be documented (with teh same caveats of why you'd need it) |
||
| self, | ||
| public_key: CertificatePublicKeyTypes, | ||
| ) -> CertificateSigningRequestBuilder: | ||
| """ | ||
| Sets the requestor's public key. | ||
| """ | ||
| if not isinstance( | ||
| public_key, | ||
| ( | ||
| dsa.DSAPublicKey, | ||
| rsa.RSAPublicKey, | ||
| ec.EllipticCurvePublicKey, | ||
| ed25519.Ed25519PublicKey, | ||
| ed448.Ed448PublicKey, | ||
| mldsa.MLDSA44PublicKey, | ||
| mldsa.MLDSA65PublicKey, | ||
| mldsa.MLDSA87PublicKey, | ||
| mlkem.MLKEM768PublicKey, | ||
| mlkem.MLKEM1024PublicKey, | ||
| x25519.X25519PublicKey, | ||
| x448.X448PublicKey, | ||
| ), | ||
| ): | ||
| raise TypeError( | ||
| "Expecting one of DSAPublicKey, RSAPublicKey," | ||
| " EllipticCurvePublicKey, Ed25519PublicKey," | ||
| " Ed448PublicKey, MLDSA44PublicKey, MLDSA65PublicKey," | ||
| " MLDSA87PublicKey, MLKEM768PublicKey, MLKEM1024PublicKey," | ||
| " X25519PublicKey or X448PublicKey." | ||
| ) | ||
|
|
||
| if self._public_key is not None: | ||
| raise ValueError("The public key may only be set once.") | ||
| return CertificateSigningRequestBuilder( | ||
| self._subject_name, public_key, self._extensions, self._attributes | ||
| ) | ||
|
|
||
| def add_extension( | ||
|
|
@@ -219,6 +259,7 @@ def add_extension( | |
|
|
||
| return CertificateSigningRequestBuilder( | ||
| self._subject_name, | ||
| self._public_key, | ||
| [*self._extensions, extension], | ||
| self._attributes, | ||
| ) | ||
|
|
@@ -251,6 +292,7 @@ def add_attribute( | |
|
|
||
| return CertificateSigningRequestBuilder( | ||
| self._subject_name, | ||
| self._public_key, | ||
| self._extensions, | ||
| [*self._attributes, (oid, value, tag)], | ||
| ) | ||
|
|
@@ -265,7 +307,9 @@ def sign( | |
| ecdsa_deterministic: bool | None = None, | ||
| ) -> CertificateSigningRequest: | ||
| """ | ||
| Signs the request using the requestor's private key. | ||
| Signs the request using the requestor's private key. If no public key | ||
| was indicated, the public key associated with specified private key | ||
| will be included instead. | ||
| """ | ||
| if self._subject_name is None: | ||
| raise ValueError("A CertificateSigningRequest must have a subject") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having troubled reading this, I think it's saying that mldsa-mlkem768.pem is the CSR and -pubkey.pem is the public key assosciated with it?