Skip to content

Hardcoded length of PEM-encoding causes interoperability issues #195

Description

@Eusebius1920

When creating ssh-keys with terraform

resource"tls_private_key""test" {
algorithm="ED25519"
}
// using: tls_private_key.test.private_key_openssh leads to a private key like this/*-----BEGIN OPENSSH PRIVATE KEY-----b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZWQyNTUxOQAAACBsiA4fEAFmnafsQ3/nfd0U3OfqD05qhIKNaaIecZVBNgAAAIirzgwtq84MLQAAAAtzc2gtZWQyNTUxOQAAACBsiA4fEAFmnafsQ3/nfd0U3OfqD05qhIKNaaIecZVBNgAAAEDwfMr2enmcI1eTBwBgJ6DyKFFiKE/rmVkRNz97QHWFBWyIDh8QAWadp+xDf+d93RTc5+oPTmqEgo1poh5xlUE2AAAAAAECAwQF-----END OPENSSH PRIVATE KEY-----*/

each line of the private key has 64 characters. A similar thing occurs when creating a private key with pythons cryptography library:

fromcryptography.hazmat.primitives.asymmetricimported25519fromcryptography.hazmat.primitives.serializationimportEncodingfromcryptography.hazmat.primitives.serializationimportPrivateFormatfromcryptography.hazmat.primitives.serializationimportNoEncryptionkey=ed25519.Ed25519PrivateKey.generate()
key.private_bytes(
encoding=Encoding.PEM,
format=PrivateFormat.OpenSSH,
encryption_algorithm=NoEncryption(),
)
# leads to"""-----BEGIN OPENSSH PRIVATE KEY-----b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZWQyNTUxOQAAACBbsSlccs9iGtCYk98px79gJ2yifXxJqM/hBqky1Uy06QAAAIgmw48RJsOPEQAAAAtzc2gtZWQyNTUxOQAAACBbsSlccs9iGtCYk98px79gJ2yifXxJqM/hBqky1Uy06QAAAEA/6vNn5cXUt1Ws/YuqOmJUvs4NyxeI143TpJdZs9Y6nluxKVxyz2Ia0JiT3ynHv2AnbKJ9fEmoz+EGqTLVTLTpAAAAAAECAwQF-----END OPENSSH PRIVATE KEY-----"""

where every line has 76 characters.

I dug into the RFC for PEM-encoding and found nothing about the line width. Both of those private keys are not readable by this library, because it assumes a fixed line width of 70 characters which is the same as ssh-keygen would produce (as suggested by the comment inside the linked file). Dedcoding one of the private key files directly above then yields to an Error-Result:

Encoding(Pem(Base64(InvalidEncoding)))

So to maintain interoperability one has to reformat all private keys to a fixed line-length of 70. Can we change that?

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