Skip to content

pkcs1: Document that it only accepts RFC 7468 textual encodings #112

@str4d

Description

@str4d

The trait method for deserializing PKCS#1-encoded RSA private keys is documented as accepting PEM:

/// 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:

fn from_pkcs1_pem(s: &str) -> Result<Self> {
let (label, der_bytes) = pem::decode_vec(s.as_bytes())?;

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions