-
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 2 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 |
|---|---|---|
|
|
@@ -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") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| -----BEGIN 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. All the vectors need to be documented in test-vectors.rst.
Contributor
Author
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. I wasn't aware of that, I now have added descriptions. |
||
| MIIHsjALBglghkgBZQMEAxIDggehAEmY+PxTxQ6zA0dcjbORjEqHcKTYkwhplHtt | ||
| GWhpQVaJGoNtgKCNJi+YX7qymzoqSFyJS8OWJV1CRh+GQOSukU4cQ1/YQsAR952Y | ||
| BQaukFoh78z/ps9uZ/Gkk/ffENIwPijYWfFrubEwJ44UaudhardIYMmPvSv2OyOp | ||
| W6sZXItG+Iw+B0WyIaUrGtbSULAvp1I53hx+YAH/BSmCs9HzStdXMDaA6vFp1snF | ||
| LwadK7MAzgOiZ4IOXZ+oifOYge+mxoJfZ6One0Ej6KHkFlMH01VHxofLUcE7Xr2U | ||
| vOg8C436tnUf1vS1kNE0hoyiDeWXJRmXe9ivfTbppAvFbImveenMzLfveKbSyyuE | ||
| fPjR9bADBzQKMygdh7O4s9TSQQzR9I0E1lWoGqlUcfUP3fnPuVflUiA6vMIKMn1v | ||
| c9TmRGB0uIoUSHgf/rRTEdfZ1XcFNxJpUkELNZzKdn14XEUr0VmlAgapfyz6Rsuf | ||
| 81vpQ7uIWkifxudgY+w5C4HV+Aofij6I0B8cHgN2KzQnru4mn2KoBB8DNdhepkol | ||
| tug64H66o6WQXhubFnOCXhhEbqK3FG7s+DuxtBxEyem/k98Y2B8mLwQyvF4j+l2Z | ||
| 2tCwGRSMciZcJajhNQpAncAe4q6sX8byIKp2Qw24eitLA4spfeua0qwnW/sQZOR3 | ||
| rZLsfnnyKBhS7j6ug6anCWn0oIL0yInFpZHocFCaaa9fXvSL1VXCYOYUDfRlr4KJ | ||
| tYPExz0k/tpMEmzyKDBbUvI/2Cjcjc2FK+aF7essFdaBIPqEDsy17EZoo8yePW4s | ||
| Gx/0bgH7hL1QrgviD487yOBG76zXMm2LqyxKZThuZLf45yP50bnpR5mrz8+6kSAM | ||
| rFDK0mP4ODXz0AC/+ap2psz91z/F2A6Yj4j5ngTJLfk5XE0G0x45YP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U+lVKVj12rjdlJlFKMq8uI58bHxWrcVsFKZ9DQElfMe+nwq+knqHs | ||
| pBYGjCSu3IP/ZTKuttT0yVayqJasSyOG0BSe38ZeFTHRxiXHRwQoknEsLwiJqMqG | ||
| hfS7kiydLG+RiauU4Qf0OKhD6MnAnr5tRo7uKG6uL/Go2WD4HnCP2jygMffzVepr | ||
| No6hJhcKuPeMRhfPA9aikV28DuMrx0AHEU28nSqYV6TwGvqT5gFyAOuQie4Y6jgE | ||
| aAgEu3S9UoQxhfnmBHZshJNly8KaF/MHsCRIxQm/cCht/t9FZ030o/ECPSiqQ6uW | ||
| vQrGCGoh9VHf3P2MPVCy/3HcWKJ5MXcdZArep0Aag2K6VdvuW+KKCo4LC9XBTIQ8 | ||
| W2FtjGEYtFCW16J2Umpwyb+b5kgapIvxq/sSGh4yfR8pWDNiVzhOqdOzb0rujEQY | ||
| Dmv3RqWJ984PAIe/PnHRiM08mvGL/K4jiit7nk8BGmfmOuVUKrdeBghfPp6/BBPc | ||
| sh/Kxob+XVZhdcSXagjhsp3qtJ9RyXsTiJAXdVX2NIjrpTyMU0LzbDy2OvC3pkXB | ||
| yDtWSLM226w3NJFqo0YkJ1RQnaUlSA92JhHnjgtw2AjGP41xov8zMLKNAqzEVPog | ||
| kjtKSIRrOMk79Tk6HC/c6/MSBs3NI/BgNJELtMyHCcGOjIQCeLUe+b58n79vm8bR | ||
| vCZ/GVKv | ||
| -----END PUBLIC KEY----- | ||
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.
This needs to be documented
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.
Looking at this more, why not refactor
is_signature_validto have it take an optional public key to handle this case?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.
It can'tm because it's a property. But I do think it'd be more appropriate to name this
verify_directly_signed_byor something so what it's checking is clear.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.
Indeed, I considered allowing an optional public key (as with
CertificateRevocationList) , but that would break existing code because the function would always evaluate to a truthy value.I've renamed the
validatefunction toverify_directly_signed_by, and aligned its behaviour withCertificate.verify_directly_issued_by: made the public key mandatory and raise exceptions instead of returning a boolean. I've also added appropriate test cases.