| 1 |
--- |
| 2 |
# Copyright (c) Ansible Project |
| 3 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
|
| 6 |
- block: |
| 7 |
- name: "({{ select_crypto_backend }}) Generate PKCS#12 file (check mode)" |
| 8 |
community.crypto.openssl_pkcs12: |
| 9 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 10 |
path: '{{ remote_tmp_dir }}/ansible.p12' |
| 11 |
friendly_name: abracadabra |
| 12 |
privatekey_path: '{{ remote_tmp_dir }}/ansible_pkey1.pem' |
| 13 |
certificate_path: '{{ remote_tmp_dir }}/ansible1.crt' |
| 14 |
state: present |
| 15 |
return_content: true |
| 16 |
check_mode: true |
| 17 |
register: p12_standard_check |
| 18 |
|
| 19 |
- name: "({{ select_crypto_backend }}) Generate PKCS#12 file" |
| 20 |
community.crypto.openssl_pkcs12: |
| 21 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 22 |
path: '{{ remote_tmp_dir }}/ansible.p12' |
| 23 |
friendly_name: abracadabra |
| 24 |
privatekey_path: '{{ remote_tmp_dir }}/ansible_pkey1.pem' |
| 25 |
certificate_path: '{{ remote_tmp_dir }}/ansible1.crt' |
| 26 |
state: present |
| 27 |
return_content: true |
| 28 |
register: p12_standard |
| 29 |
|
| 30 |
- name: "({{ select_crypto_backend }}) Generate PKCS#12 file again, idempotency (check mode)" |
| 31 |
community.crypto.openssl_pkcs12: |
| 32 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 33 |
path: '{{ remote_tmp_dir }}/ansible.p12' |
| 34 |
friendly_name: abracadabra |
| 35 |
privatekey_path: '{{ remote_tmp_dir }}/ansible_pkey1.pem' |
| 36 |
certificate_path: '{{ remote_tmp_dir }}/ansible1.crt' |
| 37 |
state: present |
| 38 |
return_content: true |
| 39 |
check_mode: true |
| 40 |
register: p12_standard_idempotency_check |
| 41 |
|
| 42 |
- name: "({{ select_crypto_backend }}) Generate PKCS#12 file again, idempotency" |
| 43 |
community.crypto.openssl_pkcs12: |
| 44 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 45 |
path: '{{ remote_tmp_dir }}/ansible.p12' |
| 46 |
friendly_name: abracadabra |
| 47 |
privatekey_path: '{{ remote_tmp_dir }}/ansible_pkey1.pem' |
| 48 |
certificate_path: '{{ remote_tmp_dir }}/ansible1.crt' |
| 49 |
state: present |
| 50 |
return_content: true |
| 51 |
register: p12_standard_idempotency |
| 52 |
|
| 53 |
- name: "({{ select_crypto_backend }}) Generate PKCS#12 file again, idempotency (empty other_certificates)" |
| 54 |
community.crypto.openssl_pkcs12: |
| 55 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 56 |
path: '{{ remote_tmp_dir }}/ansible.p12' |
| 57 |
friendly_name: abracadabra |
| 58 |
privatekey_path: '{{ remote_tmp_dir }}/ansible_pkey1.pem' |
| 59 |
certificate_path: '{{ remote_tmp_dir }}/ansible1.crt' |
| 60 |
state: present |
| 61 |
return_content: true |
| 62 |
other_certificates: [] |
| 63 |
register: p12_standard_idempotency_no_certs |
| 64 |
|
| 65 |
- name: "({{ select_crypto_backend }}) Read ansible_pkey1.pem" |
| 66 |
ansible.builtin.slurp: |
| 67 |
src: '{{ remote_tmp_dir }}/ansible_pkey1.pem' |
| 68 |
register: ansible_pkey_content |
| 69 |
|
| 70 |
- name: "({{ select_crypto_backend }}) Read ansible1.crt" |
| 71 |
ansible.builtin.slurp: |
| 72 |
src: '{{ remote_tmp_dir }}/ansible1.crt' |
| 73 |
register: ansible_crt_content |
| 74 |
|
| 75 |
- name: "({{ select_crypto_backend }}) Generate PKCS#12 file again, idempotency (private key from file)" |
| 76 |
community.crypto.openssl_pkcs12: |
| 77 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 78 |
path: '{{ remote_tmp_dir }}/ansible.p12' |
| 79 |
friendly_name: abracadabra |
| 80 |
privatekey_content: '{{ ansible_pkey_content.content | b64decode }}' |
| 81 |
certificate_content: '{{ ansible_crt_content.content | b64decode }}' |
| 82 |
state: present |
| 83 |
return_content: true |
| 84 |
register: p12_standard_idempotency_2 |
| 85 |
|
| 86 |
- name: "({{ select_crypto_backend }}) Read ansible.p12" |
| 87 |
ansible.builtin.slurp: |
| 88 |
src: '{{ remote_tmp_dir }}/ansible.p12' |
| 89 |
register: ansible_p12_content |
| 90 |
|
| 91 |
- name: "({{ select_crypto_backend }}) Validate PKCS#12" |
| 92 |
ansible.builtin.assert: |
| 93 |
that: |
| 94 |
- p12_standard.pkcs12 == ansible_p12_content.content |
| 95 |
- p12_standard_idempotency.pkcs12 == p12_standard.pkcs12 |
| 96 |
|
| 97 |
- name: "({{ select_crypto_backend }}) Generate PKCS#12 file (force)" |
| 98 |
community.crypto.openssl_pkcs12: |
| 99 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 100 |
path: '{{ remote_tmp_dir }}/ansible.p12' |
| 101 |
friendly_name: abracadabra |
| 102 |
privatekey_path: '{{ remote_tmp_dir }}/ansible_pkey1.pem' |
| 103 |
certificate_path: '{{ remote_tmp_dir }}/ansible1.crt' |
| 104 |
state: present |
| 105 |
force: true |
| 106 |
register: p12_force |
| 107 |
|
| 108 |
- name: "({{ select_crypto_backend }}) Generate PKCS#12 file (force + change mode)" |
| 109 |
community.crypto.openssl_pkcs12: |
| 110 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 111 |
path: '{{ remote_tmp_dir }}/ansible.p12' |
| 112 |
friendly_name: abracadabra |
| 113 |
privatekey_path: '{{ remote_tmp_dir }}/ansible_pkey1.pem' |
| 114 |
certificate_path: '{{ remote_tmp_dir }}/ansible1.crt' |
| 115 |
state: present |
| 116 |
force: true |
| 117 |
mode: '0644' |
| 118 |
register: p12_force_and_mode |
| 119 |
|
| 120 |
- name: "({{ select_crypto_backend }}) Dump PKCS#12" |
| 121 |
community.crypto.openssl_pkcs12: |
| 122 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 123 |
src: '{{ remote_tmp_dir }}/ansible.p12' |
| 124 |
path: '{{ remote_tmp_dir }}/ansible_parse.pem' |
| 125 |
action: parse |
| 126 |
state: present |
| 127 |
register: p12_dumped |
| 128 |
|
| 129 |
- name: "({{ select_crypto_backend }}) Dump PKCS#12 file again, idempotency" |
| 130 |
community.crypto.openssl_pkcs12: |
| 131 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 132 |
src: '{{ remote_tmp_dir }}/ansible.p12' |
| 133 |
path: '{{ remote_tmp_dir }}/ansible_parse.pem' |
| 134 |
action: parse |
| 135 |
state: present |
| 136 |
register: p12_dumped_idempotency |
| 137 |
|
| 138 |
- name: "({{ select_crypto_backend }}) Dump PKCS#12, check mode" |
| 139 |
community.crypto.openssl_pkcs12: |
| 140 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 141 |
src: '{{ remote_tmp_dir }}/ansible.p12' |
| 142 |
path: '{{ remote_tmp_dir }}/ansible_parse.pem' |
| 143 |
action: parse |
| 144 |
state: present |
| 145 |
check_mode: true |
| 146 |
register: p12_dumped_check_mode |
| 147 |
|
| 148 |
- name: "({{ select_crypto_backend }}) Generate PKCS#12 file with multiple certs and passphrase" |
| 149 |
community.crypto.openssl_pkcs12: |
| 150 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 151 |
path: '{{ remote_tmp_dir }}/ansible_multi_certs.p12' |
| 152 |
friendly_name: abracadabra |
| 153 |
passphrase: hunter3 |
| 154 |
privatekey_path: '{{ remote_tmp_dir }}/ansible_pkey1.pem' |
| 155 |
certificate_path: '{{ remote_tmp_dir }}/ansible1.crt' |
| 156 |
other_certificates: |
| 157 |
- '{{ remote_tmp_dir }}/ansible2.crt' |
| 158 |
- '{{ remote_tmp_dir }}/ansible3.crt' |
| 159 |
state: present |
| 160 |
register: p12_multiple_certs |
| 161 |
|
| 162 |
- name: "({{ select_crypto_backend }}) Read ansible2.crt / ansible3.crt.crt" |
| 163 |
ansible.builtin.slurp: |
| 164 |
src: "{{ item }}" |
| 165 |
loop: |
| 166 |
- "{{ remote_tmp_dir ~ '/ansible2.crt' }}" |
| 167 |
- "{{ remote_tmp_dir ~ '/ansible3.crt' }}" |
| 168 |
register: ansible_other_content |
| 169 |
|
| 170 |
- name: "({{ select_crypto_backend }}) Generate PKCS#12 file with multiple certs and passphrase, again (idempotency)" |
| 171 |
community.crypto.openssl_pkcs12: |
| 172 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 173 |
path: '{{ remote_tmp_dir }}/ansible_multi_certs.p12' |
| 174 |
friendly_name: abracadabra |
| 175 |
passphrase: hunter3 |
| 176 |
privatekey_path: '{{ remote_tmp_dir }}/ansible_pkey1.pem' |
| 177 |
certificate_path: '{{ remote_tmp_dir }}/ansible1.crt' |
| 178 |
other_certificates_content: |
| 179 |
- "{{ ansible_other_content.results[0].content | b64decode }}" |
| 180 |
- "{{ ansible_other_content.results[1].content | b64decode }}" |
| 181 |
state: present |
| 182 |
register: p12_multiple_certs_idempotency |
| 183 |
|
| 184 |
- name: "({{ select_crypto_backend }}) Dump PKCS#12 with multiple certs and passphrase" |
| 185 |
community.crypto.openssl_pkcs12: |
| 186 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 187 |
src: '{{ remote_tmp_dir }}/ansible_multi_certs.p12' |
| 188 |
path: '{{ remote_tmp_dir }}/ansible_parse_multi_certs.pem' |
| 189 |
passphrase: hunter3 |
| 190 |
action: parse |
| 191 |
state: present |
| 192 |
|
| 193 |
- name: "({{ select_crypto_backend }}) Generate PKCS#12 file (password fail 1)" |
| 194 |
community.crypto.openssl_pkcs12: |
| 195 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 196 |
path: '{{ remote_tmp_dir }}/ansible_pw1.p12' |
| 197 |
friendly_name: abracadabra |
| 198 |
privatekey_path: '{{ remote_tmp_dir }}/ansible_pkey1.pem' |
| 199 |
privatekey_passphrase: hunter2 |
| 200 |
certificate_path: '{{ remote_tmp_dir }}/ansible1.crt' |
| 201 |
state: present |
| 202 |
ignore_errors: true |
| 203 |
register: passphrase_error_1 |
| 204 |
|
| 205 |
- name: "({{ select_crypto_backend }}) Generate PKCS#12 file (password fail 2)" |
| 206 |
community.crypto.openssl_pkcs12: |
| 207 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 208 |
path: '{{ remote_tmp_dir }}/ansible_pw2.p12' |
| 209 |
friendly_name: abracadabra |
| 210 |
privatekey_path: '{{ remote_tmp_dir }}/privatekeypw.pem' |
| 211 |
privatekey_passphrase: wrong_password |
| 212 |
certificate_path: '{{ remote_tmp_dir }}/ansible1.crt' |
| 213 |
state: present |
| 214 |
ignore_errors: true |
| 215 |
register: passphrase_error_2 |
| 216 |
|
| 217 |
- name: "({{ select_crypto_backend }}) Generate PKCS#12 file (password fail 3)" |
| 218 |
community.crypto.openssl_pkcs12: |
| 219 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 220 |
path: '{{ remote_tmp_dir }}/ansible_pw3.p12' |
| 221 |
friendly_name: abracadabra |
| 222 |
privatekey_path: '{{ remote_tmp_dir }}/privatekeypw.pem' |
| 223 |
certificate_path: '{{ remote_tmp_dir }}/ansible1.crt' |
| 224 |
state: present |
| 225 |
ignore_errors: true |
| 226 |
register: passphrase_error_3 |
| 227 |
|
| 228 |
- name: "({{ select_crypto_backend }}) Generate PKCS#12 file, no privatekey" |
| 229 |
community.crypto.openssl_pkcs12: |
| 230 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 231 |
path: '{{ remote_tmp_dir }}/ansible_no_pkey.p12' |
| 232 |
friendly_name: abracadabra |
| 233 |
certificate_path: '{{ remote_tmp_dir }}/ansible1.crt' |
| 234 |
state: present |
| 235 |
register: p12_no_pkey |
| 236 |
|
| 237 |
- name: "({{ select_crypto_backend }}) Create broken PKCS#12" |
| 238 |
ansible.builtin.copy: |
| 239 |
dest: '{{ remote_tmp_dir }}/broken.p12' |
| 240 |
content: broken |
| 241 |
|
| 242 |
- name: "({{ select_crypto_backend }}) Regenerate broken PKCS#12" |
| 243 |
community.crypto.openssl_pkcs12: |
| 244 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 245 |
path: '{{ remote_tmp_dir }}/broken.p12' |
| 246 |
friendly_name: abracadabra |
| 247 |
privatekey_path: '{{ remote_tmp_dir }}/ansible_pkey1.pem' |
| 248 |
certificate_path: '{{ remote_tmp_dir }}/ansible1.crt' |
| 249 |
state: present |
| 250 |
force: true |
| 251 |
mode: '0644' |
| 252 |
register: output_broken |
| 253 |
|
| 254 |
- name: "({{ select_crypto_backend }}) Generate PKCS#12 file" |
| 255 |
community.crypto.openssl_pkcs12: |
| 256 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 257 |
path: '{{ remote_tmp_dir }}/ansible_backup.p12' |
| 258 |
friendly_name: abracadabra |
| 259 |
privatekey_path: '{{ remote_tmp_dir }}/ansible_pkey1.pem' |
| 260 |
certificate_path: '{{ remote_tmp_dir }}/ansible1.crt' |
| 261 |
state: present |
| 262 |
backup: true |
| 263 |
register: p12_backup_1 |
| 264 |
|
| 265 |
- name: "({{ select_crypto_backend }}) Generate PKCS#12 file (idempotent)" |
| 266 |
community.crypto.openssl_pkcs12: |
| 267 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 268 |
path: '{{ remote_tmp_dir }}/ansible_backup.p12' |
| 269 |
friendly_name: abracadabra |
| 270 |
privatekey_path: '{{ remote_tmp_dir }}/ansible_pkey1.pem' |
| 271 |
certificate_path: '{{ remote_tmp_dir }}/ansible1.crt' |
| 272 |
state: present |
| 273 |
backup: true |
| 274 |
register: p12_backup_2 |
| 275 |
|
| 276 |
- name: "({{ select_crypto_backend }}) Generate PKCS#12 file (change)" |
| 277 |
community.crypto.openssl_pkcs12: |
| 278 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 279 |
path: '{{ remote_tmp_dir }}/ansible_backup.p12' |
| 280 |
friendly_name: abra |
| 281 |
privatekey_path: '{{ remote_tmp_dir }}/ansible_pkey1.pem' |
| 282 |
certificate_path: '{{ remote_tmp_dir }}/ansible1.crt' |
| 283 |
state: present |
| 284 |
force: true |
| 285 |
backup: true |
| 286 |
register: p12_backup_3 |
| 287 |
|
| 288 |
- name: "({{ select_crypto_backend }}) Generate PKCS#12 file (remove)" |
| 289 |
community.crypto.openssl_pkcs12: |
| 290 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 291 |
path: '{{ remote_tmp_dir }}/ansible_backup.p12' |
| 292 |
state: absent |
| 293 |
backup: true |
| 294 |
return_content: true |
| 295 |
register: p12_backup_4 |
| 296 |
|
| 297 |
- name: "({{ select_crypto_backend }}) Generate PKCS#12 file (remove, idempotent)" |
| 298 |
community.crypto.openssl_pkcs12: |
| 299 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 300 |
path: '{{ remote_tmp_dir }}/ansible_backup.p12' |
| 301 |
state: absent |
| 302 |
backup: true |
| 303 |
register: p12_backup_5 |
| 304 |
|
| 305 |
- name: "({{ select_crypto_backend }}) Generate 'empty' PKCS#12 file" |
| 306 |
community.crypto.openssl_pkcs12: |
| 307 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 308 |
path: '{{ remote_tmp_dir }}/ansible_empty.p12' |
| 309 |
friendly_name: abracadabra |
| 310 |
other_certificates: |
| 311 |
- '{{ remote_tmp_dir }}/ansible2.crt' |
| 312 |
- '{{ remote_tmp_dir }}/ansible3.crt' |
| 313 |
state: present |
| 314 |
register: p12_empty |
| 315 |
|
| 316 |
|
| 317 |
- name: "({{ select_crypto_backend }}) Generate 'empty' PKCS#12 file (idempotent)" |
| 318 |
community.crypto.openssl_pkcs12: |
| 319 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 320 |
path: '{{ remote_tmp_dir }}/ansible_empty.p12' |
| 321 |
friendly_name: abracadabra |
| 322 |
other_certificates: |
| 323 |
- '{{ remote_tmp_dir }}/ansible3.crt' |
| 324 |
- '{{ remote_tmp_dir }}/ansible2.crt' |
| 325 |
state: present |
| 326 |
register: p12_empty_idem |
| 327 |
|
| 328 |
- name: "({{ select_crypto_backend }}) Generate 'empty' PKCS#12 file (idempotent, concatenated other certificates)" |
| 329 |
community.crypto.openssl_pkcs12: |
| 330 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 331 |
path: '{{ remote_tmp_dir }}/ansible_empty.p12' |
| 332 |
friendly_name: abracadabra |
| 333 |
other_certificates: |
| 334 |
- '{{ remote_tmp_dir }}/ansible23.crt' |
| 335 |
other_certificates_parse_all: true |
| 336 |
state: present |
| 337 |
register: p12_empty_concat_idem |
| 338 |
|
| 339 |
- name: "({{ select_crypto_backend }}) Read ansible23.crt" |
| 340 |
ansible.builtin.slurp: |
| 341 |
src: "{{ remote_tmp_dir ~ '/ansible23.crt' }}" |
| 342 |
register: ansible_other_content_concat |
| 343 |
|
| 344 |
- name: "({{ select_crypto_backend }}) Generate 'empty' PKCS#12 file (idempotent, concatenated other certificates)" |
| 345 |
community.crypto.openssl_pkcs12: |
| 346 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 347 |
path: '{{ remote_tmp_dir }}/ansible_empty.p12' |
| 348 |
friendly_name: abracadabra |
| 349 |
other_certificates_content: |
| 350 |
- "{{ ansible_other_content_concat.content | b64decode }}" |
| 351 |
other_certificates_parse_all: true |
| 352 |
state: present |
| 353 |
register: p12_empty_concat_content_idem |
| 354 |
|
| 355 |
- name: "({{ select_crypto_backend }}) Generate 'empty' PKCS#12 file (parse)" |
| 356 |
community.crypto.openssl_pkcs12: |
| 357 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 358 |
src: '{{ remote_tmp_dir }}/ansible_empty.p12' |
| 359 |
path: '{{ remote_tmp_dir }}/ansible_empty.pem' |
| 360 |
action: parse |
| 361 |
|
| 362 |
- name: "({{ select_crypto_backend }}) Generate PKCS#12 file passphrase and compatibility encryption" |
| 363 |
community.crypto.openssl_pkcs12: |
| 364 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 365 |
path: '{{ remote_tmp_dir }}/ansible_compatibility2022.p12' |
| 366 |
friendly_name: compat_fn |
| 367 |
encryption_level: compatibility2022 |
| 368 |
iter_size: 3210 |
| 369 |
passphrase: magicpassword |
| 370 |
privatekey_path: '{{ remote_tmp_dir }}/ansible_pkey1.pem' |
| 371 |
certificate_path: '{{ remote_tmp_dir }}/ansible1.crt' |
| 372 |
other_certificates: |
| 373 |
- '{{ remote_tmp_dir }}/ansible2.crt' |
| 374 |
- '{{ remote_tmp_dir }}/ansible3.crt' |
| 375 |
state: present |
| 376 |
register: p12_compatibility2022 |
| 377 |
when: |
| 378 |
- select_crypto_backend == 'cryptography' |
| 379 |
- cryptography_version is version('38.0.0', '>=') |
| 380 |
|
| 381 |
- ansible.builtin.import_tasks: ../tests/validate.yml |
| 382 |
|
| 383 |
always: |
| 384 |
- name: "({{ select_crypto_backend }}) Delete PKCS#12 file" |
| 385 |
community.crypto.openssl_pkcs12: |
| 386 |
state: absent |
| 387 |
path: '{{ remote_tmp_dir }}/{{ item }}.p12' |
| 388 |
loop: |
| 389 |
- ansible |
| 390 |
- ansible_no_pkey |
| 391 |
- ansible_multi_certs |
| 392 |
- ansible_pw1 |
| 393 |
- ansible_pw2 |
| 394 |
- ansible_pw3 |
| 395 |
- ansible_empty |
| 396 |
- ansible_compatibility2022 |