| 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 |
#################################################################### |
| 7 |
# WARNING: These are designed specifically for Ansible tests # |
| 8 |
# and should not be used as examples of how to write Ansible roles # |
| 9 |
#################################################################### |
| 10 |
|
| 11 |
# Test matrix: |
| 12 |
# * cryptography |
| 13 |
# * DSA or ECC or ... |
| 14 |
# * password protected private key or not |
| 15 |
|
| 16 |
- name: Set up test combinations |
| 17 |
ansible.builtin.set_fact: |
| 18 |
all_tests: [] |
| 19 |
backends: [] |
| 20 |
key_types: [] |
| 21 |
key_password: |
| 22 |
- passwd: nopasswd |
| 23 |
- passwd: passwd |
| 24 |
privatekey_passphrase: hunter2 |
| 25 |
|
| 26 |
- name: Add cryptography backend |
| 27 |
ansible.builtin.set_fact: |
| 28 |
backends: "{{ backends + [{'backend': 'cryptography'}] }}" |
| 29 |
|
| 30 |
- name: Add RSA tests |
| 31 |
ansible.builtin.set_fact: |
| 32 |
key_types: "{{ key_types + [{'type': 'RSA', 'size': default_rsa_key_size}] }}" |
| 33 |
|
| 34 |
- name: Add DSA + ECDSA tests |
| 35 |
ansible.builtin.set_fact: |
| 36 |
key_types: "{{ key_types + [{'type': 'DSA', 'size': 2048}, {'type': 'ECC', 'curve': 'secp256r1'}] }}" |
| 37 |
when: |
| 38 |
# FreeBSD 11 fails on secp256r1 keys |
| 39 |
- not ansible_facts.os_family == 'FreeBSD' |
| 40 |
|
| 41 |
- name: Add Ed25519 + Ed448 tests |
| 42 |
ansible.builtin.set_fact: |
| 43 |
key_types: "{{ key_types + [{'type': 'Ed25519'}, {'type': 'Ed448'}] }}" |
| 44 |
when: |
| 45 |
# FreeBSD doesn't have support for Ed448/25519 |
| 46 |
- not ansible_facts.os_family == 'FreeBSD' |
| 47 |
|
| 48 |
- name: Create all test combinations |
| 49 |
ansible.builtin.set_fact: |
| 50 |
all_tests: "{{ [backends, key_types, key_password] | openssl_signatures_combiner }}" |
| 51 |
|
| 52 |
- name: Generate private keys |
| 53 |
community.crypto.openssl_privatekey: |
| 54 |
path: '{{ remote_tmp_dir }}/{{ item.backend }}_privatekey_{{ item.type }}_{{ item.passwd }}.pem' |
| 55 |
type: '{{ item.type }}' |
| 56 |
curve: '{{ item.curve | default(omit) }}' |
| 57 |
size: '{{ item.size | default(omit) }}' |
| 58 |
passphrase: '{{ item.privatekey_passphrase | default(omit) }}' |
| 59 |
select_crypto_backend: cryptography |
| 60 |
loop: '{{ all_tests }}' |
| 61 |
|
| 62 |
- name: Generate public keys |
| 63 |
community.crypto.openssl_publickey: |
| 64 |
path: '{{ remote_tmp_dir }}/{{ item.backend }}_publickey_{{ item.type }}_{{ item.passwd }}.pem' |
| 65 |
privatekey_path: '{{ remote_tmp_dir }}/{{ item.backend }}_privatekey_{{ item.type }}_{{ item.passwd }}.pem' |
| 66 |
privatekey_passphrase: '{{ item.privatekey_passphrase | default(omit) }}' |
| 67 |
loop: '{{ all_tests }}' |
| 68 |
|
| 69 |
- name: Generate CSRs |
| 70 |
community.crypto.openssl_csr: |
| 71 |
path: '{{ remote_tmp_dir }}/{{ item.backend }}_{{ item.type }}_{{ item.passwd }}.csr' |
| 72 |
privatekey_path: '{{ remote_tmp_dir }}/{{ item.backend }}_privatekey_{{ item.type }}_{{ item.passwd }}.pem' |
| 73 |
privatekey_passphrase: '{{ item.privatekey_passphrase | default(omit) }}' |
| 74 |
loop: '{{ all_tests }}' |
| 75 |
|
| 76 |
- name: Generate selfsigned certificates |
| 77 |
community.crypto.x509_certificate: |
| 78 |
provider: selfsigned |
| 79 |
path: '{{ remote_tmp_dir }}/{{ item.backend }}_certificate_{{ item.type }}_{{ item.passwd }}.pem' |
| 80 |
privatekey_path: '{{ remote_tmp_dir }}/{{ item.backend }}_privatekey_{{ item.type }}_{{ item.passwd }}.pem' |
| 81 |
privatekey_passphrase: '{{ item.privatekey_passphrase | default(omit) }}' |
| 82 |
csr_path: '{{ remote_tmp_dir }}/{{ item.backend }}_{{ item.type }}_{{ item.passwd }}.csr' |
| 83 |
loop: '{{ all_tests }}' |
| 84 |
|
| 85 |
- name: Create statement to be signed |
| 86 |
ansible.builtin.copy: |
| 87 |
content: "Erst wenn der Subwoofer die Katze inhaliert, fickt der Bass richtig übel. -- W.A. Mozart" |
| 88 |
dest: '{{ remote_tmp_dir }}/statement.txt' |
| 89 |
|
| 90 |
- name: Loop over all variants |
| 91 |
ansible.builtin.include_tasks: loop.yml |
| 92 |
loop: '{{ all_tests }}' |