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

openssl_privatekey*: add default value for cipher option #794

Merged
merged 4 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelogs/fragments/794-openssl_privatekey-cipher.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
minor_changes:
- "openssl_privatekey, openssl_privatekey_pipe - add default value ``auto`` for ``cipher`` option, which happens to be the only supported value
for this option anyway. Therefore it is no longer necessary to specify ``cipher=auto`` when providing ``passphrase``
(https://github.com/ansible-collections/community.crypto/issues/793, https://github.com/ansible-collections/community.crypto/pull/794)."
4 changes: 3 additions & 1 deletion plugins/doc_fragments/module_privatekey.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ class ModuleDocFragment(object):
type: str
cipher:
description:
- The cipher to encrypt the private key. Must be V(auto).
- The cipher to encrypt the private key. This is only used when O(passphrase) is provided.
- Must be V(auto).
type: str
default: auto
select_crypto_backend:
description:
- Determines which crypto backend to use.
Expand Down
5 changes: 1 addition & 4 deletions plugins/module_utils/crypto/module_backends/privatekey.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ def get_privatekey_argument_spec():
'sect283r1', 'sect409k1', 'sect409r1', 'sect571k1', 'sect571r1',
]),
passphrase=dict(type='str', no_log=True),
cipher=dict(type='str'),
cipher=dict(type='str', default='auto'),
format=dict(type='str', default='auto_ignore', choices=['pkcs1', 'pkcs8', 'raw', 'auto', 'auto_ignore']),
format_mismatch=dict(type='str', default='regenerate', choices=['regenerate', 'convert']),
select_crypto_backend=dict(type='str', choices=['auto', 'cryptography'], default='auto'),
Expand All @@ -524,9 +524,6 @@ def get_privatekey_argument_spec():
choices=['never', 'fail', 'partial_idempotence', 'full_idempotence', 'always']
),
),
required_together=[
['cipher', 'passphrase']
],
required_if=[
['type', 'ECC', ['curve']],
],
Expand Down
1 change: 0 additions & 1 deletion tests/integration/targets/acme_account/tasks/impl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
openssl_privatekey:
path: "{{ remote_tmp_dir }}/{{ item.name }}.pem"
passphrase: "{{ item.pass | default(omit) | default(omit, true) }}"
cipher: "{{ 'auto' if (item.pass | default(false)) else omit }}"
type: ECC
curve: secp256r1
force: true
Expand Down
1 change: 0 additions & 1 deletion tests/integration/targets/ecs_certificate/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
openssl_privatekey:
path: '{{ privatekey_path }}'
passphrase: '{{ privatekey_passphrase }}'
cipher: auto
type: RSA
size: 2048

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
openssl_privatekey:
path: '{{ remote_tmp_dir }}/privatekeypw.pem'
passphrase: hunter2
cipher: auto
size: '{{ default_rsa_key_size }}'

- name: Generate CSR 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
openssl_privatekey:
path: '{{ remote_tmp_dir }}/privatekey_3.pem'
passphrase: hunter2
cipher: auto
size: '{{ default_rsa_key_size }}'

- name: Generate privatekey 4 (ECC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
openssl_privatekey:
path: '{{ remote_tmp_dir }}/privatekeypw.pem'
passphrase: hunter2
cipher: auto
select_crypto_backend: cryptography
size: '{{ default_rsa_key_size_certifiates }}'

Expand Down
1 change: 0 additions & 1 deletion tests/integration/targets/openssl_csr/tasks/impl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@
openssl_privatekey:
path: '{{ remote_tmp_dir }}/privatekeypw.pem'
passphrase: hunter2
cipher: auto
select_crypto_backend: cryptography
size: '{{ default_rsa_key_size }}'

Expand Down
1 change: 0 additions & 1 deletion tests/integration/targets/openssl_csr_info/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
openssl_privatekey:
path: '{{ remote_tmp_dir }}/privatekeypw.pem'
passphrase: hunter2
cipher: auto
select_crypto_backend: cryptography
size: '{{ default_rsa_key_size }}'

Expand Down
1 change: 0 additions & 1 deletion tests/integration/targets/openssl_pkcs12/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
openssl_privatekey:
path: '{{ remote_tmp_dir }}/privatekeypw.pem'
passphrase: hunter2
cipher: auto
size: '{{ default_rsa_key_size }}'

- name: Generate CSRs
Expand Down
4 changes: 0 additions & 4 deletions tests/integration/targets/openssl_privatekey/tasks/impl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
openssl_privatekey:
path: '{{ remote_tmp_dir }}/privatekey6.pem'
passphrase: ànsïblé
cipher: auto
size: '{{ default_rsa_key_size }}'
select_crypto_backend: '{{ select_crypto_backend }}'

Expand Down Expand Up @@ -221,7 +220,6 @@
openssl_privatekey:
path: '{{ remote_tmp_dir }}/privatekeypw.pem'
passphrase: hunter2
cipher: auto
size: '{{ default_rsa_key_size }}'
select_crypto_backend: '{{ select_crypto_backend }}'
backup: true
Expand Down Expand Up @@ -257,7 +255,6 @@
openssl_privatekey:
path: '{{ remote_tmp_dir }}/privatekeypw.pem'
passphrase: hunter2
cipher: auto
size: '{{ default_rsa_key_size }}'
select_crypto_backend: '{{ select_crypto_backend }}'
backup: true
Expand All @@ -278,7 +275,6 @@
openssl_privatekey:
path: '{{ remote_tmp_dir }}/privatekeypw.pem'
passphrase: hunter2
cipher: auto
size: '{{ default_rsa_key_size }}'
select_crypto_backend: '{{ select_crypto_backend }}'
backup: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
type: '{{ item.type | default(omit) }}'
curve: '{{ item.curve | default(omit) }}'
passphrase: '{{ item.passphrase | default(omit) }}'
cipher: '{{ "auto" if item.passphrase is defined else omit }}'
format: '{{ item.format }}'
when: item.condition | default(true)
loop:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
openssl_privatekey:
path: '{{ remote_tmp_dir }}/privatekey_3.pem'
passphrase: hunter2
cipher: auto
size: '{{ default_rsa_key_size }}'
select_crypto_backend: cryptography

Expand Down
2 changes: 0 additions & 2 deletions tests/integration/targets/openssl_publickey/tasks/impl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
openssl_privatekey:
path: '{{ remote_tmp_dir }}/privatekey3.pem'
passphrase: ansible
cipher: auto
size: '{{ default_rsa_key_size }}'

- name: "({{ select_crypto_backend }}) Generate publickey3 - with passphrase protected privatekey"
Expand Down Expand Up @@ -156,7 +155,6 @@
openssl_privatekey:
path: '{{ remote_tmp_dir }}/privatekeypw.pem'
passphrase: hunter2
cipher: auto
select_crypto_backend: cryptography
size: '{{ default_rsa_key_size }}'

Expand Down
2 changes: 0 additions & 2 deletions tests/integration/targets/openssl_signature/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
- passwd: nopasswd
- passwd: passwd
privatekey_passphrase: hunter2
privatekey_cipher: auto

- name: Add cryptography backend
set_fact:
Expand Down Expand Up @@ -72,7 +71,6 @@
curve: '{{ item.curve | default(omit) }}'
size: '{{ item.size | default(omit) }}'
passphrase: '{{ item.privatekey_passphrase | default(omit) }}'
cipher: '{{ item.privatekey_cipher | default(omit) }}'
select_crypto_backend: cryptography
loop: '{{ all_tests }}'

Expand Down
1 change: 0 additions & 1 deletion tests/integration/targets/setup_acme/tasks/obtain-cert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
'secp521r1' if key_type == 'ec521' else
'invalid value for key_type!' }}
passphrase: "{{ certificate_passphrase | default(omit) | default(omit, true) }}"
cipher: "{{ 'auto' if certificate_passphrase | default() else omit }}"
force: true
## CSR ########################################################################################
- name: ({{ certgen_title }}) Create cert CSR
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/targets/x509_certificate/tasks/ownca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
openssl_privatekey:
path: '{{ remote_tmp_dir }}/ca_privatekey_pw.pem'
passphrase: hunter2
cipher: auto
select_crypto_backend: cryptography
size: '{{ default_rsa_key_size_certifiates }}'

Expand Down Expand Up @@ -589,7 +588,6 @@
openssl_privatekey:
path: '{{ remote_tmp_dir }}/ca_privatekey_{{ item }}.pem'
type: '{{ item }}'
cipher: auto
passphrase: Test123
ignore_errors: true
loop:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
openssl_privatekey:
path: '{{ remote_tmp_dir }}/privatekeypw.pem'
passphrase: hunter2
cipher: auto
select_crypto_backend: cryptography
size: '{{ default_rsa_key_size_certifiates }}'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
openssl_privatekey:
path: '{{ remote_tmp_dir }}/privatekeypw.pem'
passphrase: hunter2
cipher: auto
select_crypto_backend: cryptography
size: '{{ default_rsa_key_size_certifiates }}'

Expand Down
Loading