Update and use more RustCrypto crates #58
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We previously used the
x509-parser
crate to parse X.509 certificates; this migrates to the RustCryptox509-cert
crate instead. The motivation for this change is that Permission Slip uses the latter crate (since it needs full ser/de for certificates), and now that it supports owned types, we can pass around e.g., deserialized objects of typeCertificate
instead of DER serializedVec<u8>
. A forthcoming PR will migrate Permission Slip to this new interface, and we'll need a similar one for hubtools. Draft status on this PR can be removed once those are up and ready to merge along with this one, but reviews would be welcome in the meantime.The RustCrypto
x509-cert
crate does lack a few convenience methods thatx509-parser
had (e.g.,public_key
,verify_signature
), but they were easily replaced with trivial functions. The one behavioral difference I found was thatx509-cert
returns an error if the buffer containing a DER message is larger than the message itself, butx509-parser
does not (it just ignores the excess bytes); this matters tolpc55_sign verify-signed-image
because the certificates in the image table are padded to 4-byte boundaries. The work-around is to peek at the DER header, compute the actual message length, and pass a slice with just the message bytes.As a user convenience,
lpc55_sign
also now auto-detects PEM encoded certificates and decodes them transparently. In particular, this means you don't have to DER encode the output certificates from the OKS ceremony.