Debian Codegraph @

ansible_collections/community/crypto/tests/integration/targets/openssl_privatekey_info/tasks/impl.yml

raw
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 key 1 info
10 community.crypto.openssl_privatekey_info:
11 path: '{{ remote_tmp_dir }}/privatekey_1.pem'
12 select_crypto_backend: '{{ select_crypto_backend }}'
13 register: result
14
15 - name: Check that RSA key info is ok
16 ansible.builtin.assert:
17 that:
18 - "'public_key' in result"
19 - "'public_key_fingerprints' in result"
20 - "'type' in result"
21 - "result.type == 'RSA'"
22 - "'public_data' in result"
23 - "2 ** (result.public_data.size - 1) < result.public_data.modulus < 2 ** result.public_data.size"
24 - "result.public_data.exponent > 5"
25 - "'private_data' not in result"
26
27 - name: ({{ select_crypto_backend }}) Read private key
28 ansible.builtin.slurp:
29 src: '{{ remote_tmp_dir }}/privatekey_1.pem'
30 register: slurp
31
32 - name: ({{ select_crypto_backend }}) Get key 1 info directly
33 community.crypto.openssl_privatekey_info:
34 content: '{{ slurp.content | b64decode }}'
35 select_crypto_backend: '{{ select_crypto_backend }}'
36 register: result_direct
37
38 - name: ({{ select_crypto_backend }}) Compare output of direct and loaded info
39 ansible.builtin.assert:
40 that:
41 - >-
42 (result | dict2items | rejectattr("key", "equalto", "warnings") | list | items2dict)
43 ==
44 (result_direct | dict2items | rejectattr("key", "equalto", "warnings") | list | items2dict)
45
46 - name: ({{ select_crypto_backend }}) Get key 2 info
47 community.crypto.openssl_privatekey_info:
48 path: '{{ remote_tmp_dir }}/privatekey_2.pem'
49 return_private_key_data: true
50 select_crypto_backend: '{{ select_crypto_backend }}'
51 register: result
52
53 - name: Check that RSA key info is ok
54 ansible.builtin.assert:
55 that:
56 - "'public_key' in result"
57 - "'public_key_fingerprints' in result"
58 - "'type' in result"
59 - "result.type == 'RSA'"
60 - "'public_data' in result"
61 - "result.public_data.size == default_rsa_key_size"
62 - "2 ** (result.public_data.size - 1) < result.public_data.modulus < 2 ** result.public_data.size"
63 - "result.public_data.exponent > 5"
64 - "'private_data' in result"
65 - "result.public_data.modulus == result.private_data.p * result.private_data.q"
66 - "result.private_data.exponent > 5"
67
68 - name: ({{ select_crypto_backend }}) Get key 3 info (without passphrase)
69 community.crypto.openssl_privatekey_info:
70 path: '{{ remote_tmp_dir }}/privatekey_3.pem'
71 return_private_key_data: true
72 select_crypto_backend: '{{ select_crypto_backend }}'
73 ignore_errors: true
74 register: result
75
76 - name: Check that loading passphrase protected key without passphrase failed
77 ansible.builtin.assert:
78 that:
79 - result is failed
80 # Check that return values are there
81 - result.can_load_key is defined
82 - result.can_parse_key is defined
83 # Check that return values are correct
84 - result.can_load_key
85 - not result.can_parse_key
86 # Check that additional data isn't there
87 - "'pulic_key' not in result"
88 - "'pulic_key_fingerprints' not in result"
89 - "'type' not in result"
90 - "'public_data' not in result"
91 - "'private_data' not in result"
92
93 - name: ({{ select_crypto_backend }}) Get key 3 info (with wrong passphrase)
94 community.crypto.openssl_privatekey_info:
95 path: '{{ remote_tmp_dir }}/privatekey_3.pem'
96 return_private_key_data: true
97 select_crypto_backend: '{{ select_crypto_backend }}'
98 passphrase: blabla
99 ignore_errors: true
100 register: result
101
102 - name: Check that loading passphrase protected key with wrong passphrase failed
103 ansible.builtin.assert:
104 that:
105 - result is failed
106 # Check that return values are there
107 - result.can_load_key is defined
108 - result.can_parse_key is defined
109 # Check that return values are correct
110 - result.can_load_key
111 - not result.can_parse_key
112 # Check that additional data isn't there
113 - "'pulic_key' not in result"
114 - "'pulic_key_fingerprints' not in result"
115 - "'type' not in result"
116 - "'public_data' not in result"
117 - "'private_data' not in result"
118
119 - name: ({{ select_crypto_backend }}) Get key 3 info (with passphrase)
120 community.crypto.openssl_privatekey_info:
121 path: '{{ remote_tmp_dir }}/privatekey_3.pem'
122 passphrase: hunter2
123 return_private_key_data: true
124 select_crypto_backend: '{{ select_crypto_backend }}'
125 register: result
126
127 - name: Check that RSA key info is ok
128 ansible.builtin.assert:
129 that:
130 - "'public_key' in result"
131 - "'public_key_fingerprints' in result"
132 - "'type' in result"
133 - "result.type == 'RSA'"
134 - "'public_data' in result"
135 - "2 ** (result.public_data.size - 1) < result.public_data.modulus < 2 ** result.public_data.size"
136 - "result.public_data.exponent > 5"
137 - "'private_data' in result"
138 - "result.public_data.modulus == result.private_data.p * result.private_data.q"
139 - "result.private_data.exponent > 5"
140
141 - name: ({{ select_crypto_backend }}) Get key 4 info
142 community.crypto.openssl_privatekey_info:
143 path: '{{ remote_tmp_dir }}/privatekey_4.pem'
144 return_private_key_data: true
145 select_crypto_backend: '{{ select_crypto_backend }}'
146 register: result
147
148 - name: Check that ECC key info is ok
149 ansible.builtin.assert:
150 that:
151 - "'public_key' in result"
152 - "'public_key_fingerprints' in result"
153 - "'type' in result"
154 - "result.type == 'ECC'"
155 - "'public_data' in result"
156 - "result.public_data.curve is string"
157 - "result.public_data.x != 0"
158 - "result.public_data.y != 0"
159 - "result.public_data.exponent_size == (521 if (ansible_facts.distribution == 'CentOS' and ansible_facts.distribution_major_version == '6') else 256)"
160 - "'private_data' in result"
161 - "result.private_data.multiplier > 1024"
162
163 - name: ({{ select_crypto_backend }}) Get key 5 info
164 community.crypto.openssl_privatekey_info:
165 path: '{{ remote_tmp_dir }}/privatekey_5.pem'
166 return_private_key_data: true
167 select_crypto_backend: '{{ select_crypto_backend }}'
168 register: result
169
170 - name: Check that DSA key info is ok
171 ansible.builtin.assert:
172 that:
173 - "'public_key' in result"
174 - "'public_key_fingerprints' in result"
175 - "'type' in result"
176 - "result.type == 'DSA'"
177 - "'public_data' in result"
178 - "result.public_data.p > 2"
179 - "result.public_data.q > 2"
180 - "result.public_data.g >= 2"
181 - "result.public_data.y > 2"
182 - "'private_data' in result"
183 - "result.private_data.x > 2"
184
185 - name: ({{ select_crypto_backend }}) Get empty key info
186 community.crypto.openssl_privatekey_info:
187 content: ''
188 return_private_key_data: true
189 select_crypto_backend: '{{ select_crypto_backend }}'
190 register: result
191 ignore_errors: true
192
193 - name: Check that empty key loading failed
194 ansible.builtin.assert:
195 that:
196 - result is failed
197 # Check that return values are there
198 - result.can_load_key is defined
199 - result.can_parse_key is defined
200 # Check that return values are correct
201 - result.can_load_key
202 - not result.can_parse_key
203 # Check that additional data isn't there
204 - "'pulic_key' not in result"
205 - "'pulic_key_fingerprints' not in result"
206 - "'type' not in result"
207 - "'public_data' not in result"
208 - "'private_data' not in result"
209
210 - name: ({{ select_crypto_backend }}) Get corrupt key info
211 community.crypto.openssl_privatekey_info:
212 content: C0RRUPT
213 return_private_key_data: true
214 select_crypto_backend: '{{ select_crypto_backend }}'
215 register: result
216 ignore_errors: true
217
218 - name: Check that corrupt key loading failed
219 ansible.builtin.assert:
220 that:
221 - result is failed
222 # Check that return values are there
223 - result.can_load_key is defined
224 - result.can_parse_key is defined
225 # Check that return values are correct
226 - result.can_load_key
227 - not result.can_parse_key
228 # Check that additional data isn't there
229 - "'pulic_key' not in result"
230 - "'pulic_key_fingerprints' not in result"
231 - "'type' not in result"
232 - "'public_data' not in result"
233 - "'private_data' not in result"