Skip to content
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

Validate PEM Format for RSA Private Key #47

Open
tromboman opened this issue Sep 18, 2022 · 0 comments
Open

Validate PEM Format for RSA Private Key #47

tromboman opened this issue Sep 18, 2022 · 0 comments

Comments

@tromboman
Copy link

According to RFC 7468 PKIX Textual Encodings (Chapter 10/11) the Textual Encoding of Private Key Info use the "PRIVATE KEY" label. Encrypted Private Key Info use the "ENCRYPTED PRIVATE KEY" label.
So the key file can also start/end with the following lines

-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----

or

-----BEGIN ENCRYPTED PRIVATE KEY-----
...
-----END ENCRYPTED PRIVATE KEY-----

depending on the application, which creates the key file.

For example, the openssl application with the genpkey command creates PEM files with the aforementioned labels.
Also the openssl req command with the -newkey rsa:2048 option creates this kind of label.
According to the man page, the openssl genrsa command is superseded by genpkey for the generation of RSA Private Keys.

Therefore, it might be a good idea to replace

 openssl genrsa -out $CERT_NAME.key 2048

by

 openssl genpkey -out $CERT_NAME.key -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:2048

in the README.rst

if not value.startswith('-----BEGIN RSA PRIVATE KEY-----') or not value.endswith('-----END RSA PRIVATE KEY-----'):

openssl genrsa -out $CERT_NAME.key 2048

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant