| 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 |
- ansible.builtin.debug: |
| 7 |
msg: "Executing tests with backend {{ select_crypto_backend }}" |
| 8 |
|
| 9 |
- name: ({{ select_crypto_backend }}) Get certificate info |
| 10 |
community.crypto.x509_certificate_info: |
| 11 |
path: '{{ remote_tmp_dir }}/cert_1.pem' |
| 12 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 13 |
register: result |
| 14 |
|
| 15 |
- name: ({{ select_crypto_backend }}) Get certificate info (IDNA encoding) |
| 16 |
community.crypto.x509_certificate_info: |
| 17 |
path: '{{ remote_tmp_dir }}/cert_1.pem' |
| 18 |
name_encoding: idna |
| 19 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 20 |
register: result_idna |
| 21 |
|
| 22 |
- name: ({{ select_crypto_backend }}) Get certificate info (Unicode encoding) |
| 23 |
community.crypto.x509_certificate_info: |
| 24 |
path: '{{ remote_tmp_dir }}/cert_1.pem' |
| 25 |
name_encoding: unicode |
| 26 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 27 |
register: result_unicode |
| 28 |
|
| 29 |
- name: Check whether issuer and subject and extensions behave as expected |
| 30 |
ansible.builtin.assert: |
| 31 |
that: |
| 32 |
- result.issuer.organizationalUnitName == 'ACME Department' |
| 33 |
- "['organizationalUnitName', 'Crypto Department'] in result.issuer_ordered" |
| 34 |
- "['organizationalUnitName', 'ACME Department'] in result.issuer_ordered" |
| 35 |
- result.subject.organizationalUnitName == 'ACME Department' |
| 36 |
- "['organizationalUnitName', 'Crypto Department'] in result.subject_ordered" |
| 37 |
- "['organizationalUnitName', 'ACME Department'] in result.subject_ordered" |
| 38 |
- result.public_key_type == 'RSA' |
| 39 |
- result.public_key_data.size == (default_rsa_key_size_certificates | int) |
| 40 |
- "result.subject_alt_name == [ |
| 41 |
'DNS:www.ansible.com', |
| 42 |
'DNS:xn--7ca3a.com', |
| 43 |
'DNS:xn--74h.com', |
| 44 |
'IP:1.2.3.4', |
| 45 |
'IP:::1', |
| 46 |
'email:[email protected]', |
| 47 |
'URI:https://example.org/test/index.html' |
| 48 |
]" |
| 49 |
- "result_idna.subject_alt_name == [ |
| 50 |
'DNS:www.ansible.com', |
| 51 |
'DNS:xn--7ca3a.com', |
| 52 |
'DNS:xn--74h.com', |
| 53 |
'IP:1.2.3.4', |
| 54 |
'IP:::1', |
| 55 |
'email:[email protected]', |
| 56 |
'URI:https://example.org/test/index.html' |
| 57 |
]" |
| 58 |
- "result_unicode.subject_alt_name == [ |
| 59 |
'DNS:www.ansible.com', |
| 60 |
'DNS:öç.com', |
| 61 |
'DNS:☺.com', |
| 62 |
'IP:1.2.3.4', |
| 63 |
'IP:::1', |
| 64 |
'email:[email protected]', |
| 65 |
'URI:https://example.org/test/index.html' |
| 66 |
]" |
| 67 |
# TLS Feature |
| 68 |
- result.extensions_by_oid['1.3.6.1.5.5.7.1.24'].critical == false |
| 69 |
- result.extensions_by_oid['1.3.6.1.5.5.7.1.24'].value == 'MAMCAQU=' |
| 70 |
# Key Usage |
| 71 |
- result.extensions_by_oid['2.5.29.15'].critical == true |
| 72 |
- result.extensions_by_oid['2.5.29.15'].value in ['AwMA/4A=', 'AwMH/4A='] |
| 73 |
# Subject Alternative Names |
| 74 |
- result.extensions_by_oid['2.5.29.17'].critical == false |
| 75 |
- > |
| 76 |
result.extensions_by_oid['2.5.29.17'].value == ( |
| 77 |
'MHyCD3d3dy5hbnNpYmxlLmNvbYINeG4tLTdjYTNhLmNvbYILeG4tLTc0aC5jb22HBAECAwSHEAAAAAAAAAAAAAAAAAAAAAGBEHRlc3RAZXhhbXBsZS5vcmeGI2h0dHBzOi8vZXhhbXBsZS5vcmcvdGVzdC9pbmRleC5odG1s' |
| 78 |
) |
| 79 |
# Basic Constraints |
| 80 |
- result.extensions_by_oid['2.5.29.19'].critical == true |
| 81 |
- result.extensions_by_oid['2.5.29.19'].value == 'MAYBAf8CARc=' |
| 82 |
# Extended Key Usage |
| 83 |
- result.extensions_by_oid['2.5.29.37'].critical == false |
| 84 |
- result.extensions_by_oid['2.5.29.37'].value == 'MHQGCCsGAQUFBwMBBggrBgEFBQcDAQYIKwYBBQUHAwIGCCsGAQUFBwMDBggrBgEFBQcDBAYIKwYBBQUHAwgGCCsGAQUFBwMJBgRVHSUABggrBgEFBQcBAwYIKwYBBQUHAwoGCCsGAQUFBwMHBggrBgEFBQcBAg==' |
| 85 |
|
| 86 |
- name: Check SubjectKeyIdentifier and AuthorityKeyIdentifier |
| 87 |
ansible.builtin.assert: |
| 88 |
that: |
| 89 |
- result.subject_key_identifier == "00:11:22:33" |
| 90 |
- result.authority_key_identifier == "44:55:66:77" |
| 91 |
- result.authority_cert_issuer == expected_authority_cert_issuer |
| 92 |
- result.authority_cert_serial_number == 12345 |
| 93 |
# Subject Key Identifier |
| 94 |
- result.extensions_by_oid['2.5.29.14'].critical == false |
| 95 |
# Authority Key Identifier |
| 96 |
- result.extensions_by_oid['2.5.29.35'].critical == false |
| 97 |
vars: |
| 98 |
expected_authority_cert_issuer: |
| 99 |
- "DNS:ca.example.org" |
| 100 |
- "IP:1.2.3.4" |
| 101 |
|
| 102 |
- name: ({{ select_crypto_backend }}) Read file |
| 103 |
ansible.builtin.slurp: |
| 104 |
src: '{{ remote_tmp_dir }}/cert_1.pem' |
| 105 |
register: slurp |
| 106 |
|
| 107 |
- name: ({{ select_crypto_backend }}) Get certificate info directly |
| 108 |
community.crypto.x509_certificate_info: |
| 109 |
content: '{{ slurp.content | b64decode }}' |
| 110 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 111 |
register: result_direct |
| 112 |
|
| 113 |
- name: ({{ select_crypto_backend }}) Compare output of direct and loaded info |
| 114 |
ansible.builtin.assert: |
| 115 |
that: |
| 116 |
- >- |
| 117 |
(result | dict2items | rejectattr("key", "equalto", "warnings") | list | items2dict) |
| 118 |
== |
| 119 |
(result_direct | dict2items | rejectattr("key", "equalto", "warnings") | list | items2dict) |
| 120 |
|
| 121 |
- name: ({{ select_crypto_backend }}) Get certificate info |
| 122 |
community.crypto.x509_certificate_info: |
| 123 |
path: '{{ remote_tmp_dir }}/cert_2.pem' |
| 124 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 125 |
valid_at: |
| 126 |
today: "+0d" |
| 127 |
past: "20190101235901Z" |
| 128 |
twentydays: "+20d" |
| 129 |
register: result |
| 130 |
- ansible.builtin.assert: |
| 131 |
that: |
| 132 |
- result.valid_at.today |
| 133 |
- not result.valid_at.past |
| 134 |
- not result.valid_at.twentydays |
| 135 |
|
| 136 |
- name: ({{ select_crypto_backend }}) Get certificate info |
| 137 |
community.crypto.x509_certificate_info: |
| 138 |
path: '{{ remote_tmp_dir }}/cert_3.pem' |
| 139 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 140 |
register: result |
| 141 |
|
| 142 |
- name: Check AuthorityKeyIdentifier |
| 143 |
ansible.builtin.assert: |
| 144 |
that: |
| 145 |
- result.authority_key_identifier is none |
| 146 |
- result.authority_cert_issuer == expected_authority_cert_issuer |
| 147 |
- result.authority_cert_serial_number == 12345 |
| 148 |
vars: |
| 149 |
expected_authority_cert_issuer: |
| 150 |
- "DNS:ca.example.org" |
| 151 |
- "IP:1.2.3.4" |
| 152 |
|
| 153 |
- name: ({{ select_crypto_backend }}) Get certificate info |
| 154 |
community.crypto.x509_certificate_info: |
| 155 |
path: '{{ remote_tmp_dir }}/cert_4.pem' |
| 156 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 157 |
register: result |
| 158 |
|
| 159 |
- name: Check AuthorityKeyIdentifier |
| 160 |
ansible.builtin.assert: |
| 161 |
that: |
| 162 |
- result.authority_key_identifier == "44:55:66:77" |
| 163 |
- result.authority_cert_issuer is none |
| 164 |
- result.authority_cert_serial_number is none |
| 165 |
|
| 166 |
- name: Copy packed cert 1 to remote |
| 167 |
ansible.builtin.copy: |
| 168 |
src: cert1.pem |
| 169 |
dest: '{{ remote_tmp_dir }}/packed-cert-1.pem' |
| 170 |
|
| 171 |
- name: ({{ select_crypto_backend }}) Get certificate info for packaged cert 1 |
| 172 |
community.crypto.x509_certificate_info: |
| 173 |
path: '{{ remote_tmp_dir }}/packed-cert-1.pem' |
| 174 |
select_crypto_backend: '{{ select_crypto_backend }}' |
| 175 |
register: result |
| 176 |
- name: Check extensions |
| 177 |
ansible.builtin.assert: |
| 178 |
that: |
| 179 |
- "'ocsp_uri' in result" |
| 180 |
- "result.ocsp_uri == 'http://ocsp.foobarbaz.example.com'" |
| 181 |
- "'issuer_uri' in result" |
| 182 |
- "result.issuer_uri == 'http://cert.foobarbaz.example.com/inter.pem'" |
| 183 |
- result.extensions_by_oid | length == 9 |
| 184 |
# Precert Signed Certificate Timestamps |
| 185 |
- result.extensions_by_oid['1.3.6.1.4.1.11129.2.4.2'].critical == false |
| 186 |
- >- |
| 187 |
result.extensions_by_oid['1.3.6.1.4.1.11129.2.4.2'].value == |
| 188 |
'BIHvAO0AdADd3Mo0ldfhFgXnlTL6x5/4PRxQ39sAOhQSdgosrLvIKgAAAZYL7QgtAAAEAwBFMEMCIAXku/W4fMbkoOkHguRt8RfxVy6dgwpi9A8IDTRkOn1XAh9g9RjiBvMJdM/+UQS+WNXaxOqA5JzUfvCFjbYLbEZ5AHUADeHyMCvTDcFAYhIJ6lUu/Ed0fLHX6TDvDkIetH5OqjQAAAGWC+0H2AAABAMARjBEAiB26F5G8YPuZ11gAfEXqAFpVk01VcbOsS6w3dn2CJf6zgIgeEWCpg9tsQ8dB7/hU1zOmkZom62VDXvk8Cs+yscbQq4=' |
| 189 |
# Authority Information Access |
| 190 |
- result.extensions_by_oid['1.3.6.1.5.5.7.1.1'].critical == false |
| 191 |
- result.extensions_by_oid['1.3.6.1.5.5.7.1.1'].value == 'MGgwLQYIKwYBBQUHMAGGIWh0dHA6Ly9vY3NwLmZvb2JhcmJhei5leGFtcGxlLmNvbTA3BggrBgEFBQcwAoYraHR0cDovL2NlcnQuZm9vYmFyYmF6LmV4YW1wbGUuY29tL2ludGVyLnBlbQ==' |
| 192 |
# Subject Key Identifier |
| 193 |
- result.extensions_by_oid['2.5.29.14'].critical == false |
| 194 |
- result.extensions_by_oid['2.5.29.14'].value == 'BBSq0oNG47DU/2s2mDG6sXXx3vBVoA==' |
| 195 |
# Key Usage |
| 196 |
- result.extensions_by_oid['2.5.29.15'].critical == true |
| 197 |
- result.extensions_by_oid['2.5.29.15'].value == 'AwIFoA==' |
| 198 |
# Subject Alternative Names |
| 199 |
- result.extensions_by_oid['2.5.29.17'].critical == false |
| 200 |
- result.extensions_by_oid['2.5.29.17'].value == 'MHWCC2V4YW1wbGUubmV0gg93d3cuZXhhbXBsZS5uZXSCD2Zvby5leGFtcGxlLm5ldIIPYmFyLmV4YW1wbGUubmV0gg9iYXouZXhhbXBsZS5uZXSCD2JhbS5leGFtcGxlLm5ldIIRKi5iYW0uZXhhbXBsZS5uZXQ=' |
| 201 |
# Basic Constraints |
| 202 |
- result.extensions_by_oid['2.5.29.19'].critical == true |
| 203 |
- result.extensions_by_oid['2.5.29.19'].value == 'MAA=' |
| 204 |
# Certificate Policies |
| 205 |
- result.extensions_by_oid['2.5.29.32'].critical == false |
| 206 |
- result.extensions_by_oid['2.5.29.32'].value == 'MHMwCAYGZ4EMAQIBMGcGCysGAQQBgt8TAQEBMFgwNgYIKwYBBQUHAgEWKmh0dHA6Ly9jcHMuZm9vYmFyYmF6LmV4YW1wbGUuY29tL3NvbWV0aGluZzAeBggrBgEFBQcCAjASDBBCbGFibGEgd2hhdGV2ZXIu' |
| 207 |
# Authority Key Identifier |
| 208 |
- result.extensions_by_oid['2.5.29.35'].critical == false |
| 209 |
- result.extensions_by_oid['2.5.29.35'].value == 'MBaAFGgVOaTes3MnP1bD3KkShc1RApS4' |
| 210 |
# Extended Key Usage |
| 211 |
- result.extensions_by_oid['2.5.29.37'].critical == false |
| 212 |
- result.extensions_by_oid['2.5.29.37'].value == 'MBQGCCsGAQUFBwMBBggrBgEFBQcDAg==' |
| 213 |
- name: Check fingerprints |
| 214 |
ansible.builtin.assert: |
| 215 |
that: |
| 216 |
- (result.fingerprints.sha256 == '08:26:60:3d:29:11:f2:88:09:3f:40:71:bb:67:cb:59:9c:6e:cf:e0:49:22:ab:e8:60:bd:f6:9a:01:e3:0e:2c' if result.fingerprints.sha256 is defined else true) |
| 217 |
- (result.fingerprints.sha1 == '5a:32:7f:22:61:f3:2e:ad:a7:d8:77:07:1c:7f:08:cd:ab:7f:bc:11' if result.fingerprints.sha1 is defined else true) |