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

Allow to select openssl_privatekey format #59253

Closed
bkmeneguello opened this issue Jul 18, 2019 · 14 comments · Fixed by #60388
Closed

Allow to select openssl_privatekey format #59253

bkmeneguello opened this issue Jul 18, 2019 · 14 comments · Fixed by #60388
Labels
affects_2.9 This issue/PR affects Ansible v2.9 crypto Crypto community (ACME, openssl, letsencrypt) feature This issue/PR relates to a feature request. has_pr This issue has an associated PR. module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community.

Comments

@bkmeneguello
Copy link
Contributor

SUMMARY

Allow to specify a new "format" parameter in "openssl_privatekey". Today the output format is decided by a very simple heuristic which requires further commands to work properly.
I need, for example, to generate a RSA private key but in PKCS8 format. The current heuristic uses OpenSSH format for RSA keys and only uses PKCS8 for Ed25519 and similar. This makes me use a "command" with "openssl" to convert the generated key, which leads to idempotency problems and unnecessary complexity.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

openssl_privatekey

ADDITIONAL INFORMATION

The current heuristic should be kept unless overwritten by user.

openssl_privatekey:
  path: /etc/ssl/private/ansible.com.pem
  format: pkcs8

The values allowed are pkcs1, raw and pkcs8

@ansibot
Copy link
Contributor

ansibot commented Jul 18, 2019

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Jul 18, 2019

@ansibot ansibot added affects_2.9 This issue/PR affects Ansible v2.9 crypto Crypto community (ACME, openssl, letsencrypt) feature This issue/PR relates to a feature request. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. labels Jul 18, 2019
@felixfontein
Copy link
Contributor

That would mean there would be four values, the fourth being auto (or something like that), which would also be the default.

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Jul 18, 2019
@MarkusTeufelberger
Copy link
Contributor

Since I wondered what raw would even mean: https://cryptography.io/en/latest/hazmat/primitives/asymmetric/serialization/#serialization-formats raw is "A raw format used by X448 key exchange. It is a binary format and is invalid for other key types."

@felixfontein
Copy link
Contributor

Not every key type will support every format. Also, I'm not sure what the PyOpenSSL backend will be able to do with this.

@MarkusTeufelberger
Copy link
Contributor

I'd anyways propose to deprecate pyOpenSSL support starting with 2.9 (will have to be in there for a while longer), since Debian Jessie is EOL now. Ubuntu Xenial might keep us back on pyOpenSSL though. :-(

@felixfontein
Copy link
Contributor

Yes, I wanted to propose that as well. We will still need it for some modules which have no other backend (or no corresponding code in cryptography they can use, like openssl_pkcs12), but for modules which have good cryptography support, let's really get rid of it!

@felixfontein
Copy link
Contributor

(On pyOpenSSL deprecation: I've created a PR for that in #59907)

@felixfontein
Copy link
Contributor

raw is only supported for the X448 key exchange, BTW (see https://cryptography.io/en/latest/hazmat/primitives/asymmetric/serialization/#cryptography.hazmat.primitives.serialization.PrivateFormat.Raw). There can potentially be another option, encoding, which could be PEM (default) or DER.

@felixfontein felixfontein added waiting_on_contributor This would be accepted but there are no plans to actively work on it. and removed waiting_on_contributor This would be accepted but there are no plans to actively work on it. labels Aug 11, 2019
@felixfontein
Copy link
Contributor

If you want this feature in Ansible 2.9, there's some help needed: #60388 (comment)

@ansibot ansibot added has_pr This issue has an associated PR. waiting_on_contributor This would be accepted but there are no plans to actively work on it. labels Aug 18, 2019
@bkmeneguello
Copy link
Contributor Author

Ok, the formal spec of PKCS#8 textual representation can be found here: https://tools.ietf.org/html/rfc7468#page-12
It defines the Encapsulation Boundary as five dashes ----- followed by the keyword BEGIN followed by the optional ENCRYPTED keyword followed by PRIVATE KEY and five more dashes -----, so:
-----BEGIN PRIVATE KEY----- or -----BEGIN ENCRYPTED PRIVATE KEY-----

For PKCS#1 there is no formal reference, but openssl convention is -----BEGIN RSA PRIVATE KEY-----

@felixfontein
Copy link
Contributor

Hmm, so we only know when a key is definitely not PKCS#8. But if it starts with -----BEGIN PRIVATE KEY----- or -----BEGIN ENCRYPTED PRIVATE KEY-----, it could be both PKCS#1 or PKCS#8. And then there are raw keys. I'm not sure if a header-based detection is good enough. Maybe we have to look at the content?

@bkmeneguello
Copy link
Contributor Author

@felixfontein
Copy link
Contributor

It would also be nice to have support for JSON Web Keys, and being able to convert between different key formats (i.e. if everything fits but the key format, don't regenerate, but convert).

@ansible ansible locked and limited conversation to collaborators Nov 14, 2019
@sivel sivel removed the waiting_on_contributor This would be accepted but there are no plans to actively work on it. label Dec 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.9 This issue/PR affects Ansible v2.9 crypto Crypto community (ACME, openssl, letsencrypt) feature This issue/PR relates to a feature request. has_pr This issue has an associated PR. module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants