-
Notifications
You must be signed in to change notification settings - Fork 172
Closed
Description
The trait method for deserializing PKCS#1-encoded RSA private keys is documented as accepting PEM:
Lines 29 to 39 in 2898d39
| /// Deserialize PKCS#1-encoded private key from PEM. | |
| /// | |
| /// Keys in this format begin with the following: | |
| /// | |
| /// ```text | |
| /// -----BEGIN RSA PRIVATE KEY----- | |
| /// ``` | |
| #[cfg(feature = "pem")] | |
| #[cfg_attr(docsrs, doc(cfg(feature = "pem")))] | |
| fn from_pkcs1_pem(s: &str) -> Result<Self> { | |
| RsaPrivateKeyDocument::from_pkcs1_pem(s) |
However, via the call graph we can see it actually uses the pem-rfc7468 crate, which parses textual encodings that are a strict subset of PEM:
formats/pkcs1/src/document/private_key.rs
Lines 56 to 57 in 2898d39
| fn from_pkcs1_pem(s: &str) -> Result<Self> { | |
| let (label, der_bytes) = pem::decode_vec(s.as_bytes())?; |
Line 70 in 2898d39
| use pem_rfc7468 as pem; |
In particular, this makes the trait impl incompatible with legacy passphrase-encrypted OpenSSH keys:
Unlike legacy PEM encoding [RFC1421], OpenPGP ASCII armor, and the
OpenSSH key file format, textual encoding does *not* define or permit
headers to be encoded alongside the data. Empty space can appear
between the pre-encapsulation boundary and the base64, but generators
SHOULD NOT emit such any such spacing. (The provision for this empty
area is a throwback to PEM, which defined an "encapsulated header
portion".)
The documentation for FromRsaPrivateKey::from_pkcs1_pem should be updated to clarify that it only accepts RFC 7468 textual encodings, not arbitrary PEM.
Metadata
Metadata
Assignees
Labels
No labels