openssl_pkcs12: do not crash when there's no certificate and/or private key in existing PKCS#12 file (#109)

* Do not crash when PKCS#12 file contains no private key and/or main certificate.

* Add changelog fragment.

* Call getters only once each, check explicitly for None.

* Add test.

* Also 'parse' correctly PKCS#12 file with no private key.
This commit is contained in:
Felix Fontein
2020-09-16 11:25:24 +02:00
committed by GitHub
parent 1b3ff44bc2
commit 7cdfdc1bfb
4 changed files with 40 additions and 5 deletions

View File

@@ -213,6 +213,29 @@
state: absent
backup: true
register: p12_backup_5
- name: Generate 'empty' PKCS#12 file
openssl_pkcs12:
path: '{{ output_dir }}/ansible_empty.p12'
friendly_name: abracadabra
ca_certificates:
- '{{ output_dir }}/ansible2.crt'
- '{{ output_dir }}/ansible3.crt'
state: present
register: p12_empty
- name: Generate 'empty' PKCS#12 file (idempotent)
openssl_pkcs12:
path: '{{ output_dir }}/ansible_empty.p12'
friendly_name: abracadabra
ca_certificates:
- '{{ output_dir }}/ansible2.crt'
- '{{ output_dir }}/ansible3.crt'
state: present
register: p12_empty_idem
- name: Generate 'empty' PKCS#12 file (parse)
openssl_pkcs12:
src: '{{ output_dir }}/ansible_empty.p12'
path: '{{ output_dir }}/ansible_empty.pem'
action: parse
- import_tasks: ../tests/validate.yml
always:
- name: Delete PKCS#12 file
@@ -226,3 +249,4 @@
- ansible_pw1
- ansible_pw2
- ansible_pw3
- ansible_empty

View File

@@ -55,3 +55,10 @@
- p12_backup_5 is not changed
- p12_backup_5.backup_file is undefined
- p12_backup_4.pkcs12 is none
- name: Check 'empty' file
assert:
that:
- p12_empty is changed
- p12_empty_idem is not changed
- "lookup('file', output_dir ~ '/ansible_empty.pem') == lookup('file', output_dir ~ '/ansible3.crt') ~ '\n' ~ lookup('file', output_dir ~ '/ansible2.crt')"