mirror of
https://github.com/ansible-collections/community.crypto.git
synced 2026-05-06 13:22:58 +00:00
Compare commits
606 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a50cc1e7a | ||
|
|
fa36f75812 | ||
|
|
1a96fe0bbc | ||
|
|
365229dac9 | ||
|
|
070891b873 | ||
|
|
f94dc9227a | ||
|
|
03c4679dfb | ||
|
|
5cd9087e00 | ||
|
|
46a787798c | ||
|
|
cb0137baca | ||
|
|
0b36567667 | ||
|
|
e7b1854253 | ||
|
|
305a1fc922 | ||
|
|
bfce6df1bb | ||
|
|
bb40d15b45 | ||
|
|
4cd397382e | ||
|
|
d966acbef4 | ||
|
|
f3b43185bf | ||
|
|
4c5962788d | ||
|
|
13ea1de2f3 | ||
|
|
b1ae295fb7 | ||
|
|
4a7d18cad5 | ||
|
|
670d0b4dcf | ||
|
|
bb216ed164 | ||
|
|
94c0260fb3 | ||
|
|
b1e4777b4d | ||
|
|
26b90d5542 | ||
|
|
9f7aba4d20 | ||
|
|
46dc971922 | ||
|
|
911ed33c2e | ||
|
|
b5a9a41913 | ||
|
|
e91f8ec520 | ||
|
|
9b497dddbc | ||
|
|
93ab7089f7 | ||
|
|
8049b0f013 | ||
|
|
1f822f17e8 | ||
|
|
c9c3a41291 | ||
|
|
7d2b30ce90 | ||
|
|
81c3ae5d84 | ||
|
|
9cbf9fc6ec | ||
|
|
74e9abf1f6 | ||
|
|
2b6c932f64 | ||
|
|
83806cafc7 | ||
|
|
663d1a1321 | ||
|
|
9d47921749 | ||
|
|
15c31812c2 | ||
|
|
f41ed4579a | ||
|
|
87096afa07 | ||
|
|
64aa85031e | ||
|
|
1b86848a6f | ||
|
|
5420f9baaf | ||
|
|
6f0c58f483 | ||
|
|
59e2e73710 | ||
|
|
9db655e7fd | ||
|
|
250230e763 | ||
|
|
bd5f3b4c7c | ||
|
|
f85e912d83 | ||
|
|
0f8a09e70e | ||
|
|
3ce86fbf97 | ||
|
|
520e7c6278 | ||
|
|
1da1fdc3b0 | ||
|
|
c5135496c8 | ||
|
|
05864d366c | ||
|
|
43ba69e495 | ||
|
|
62b4535465 | ||
|
|
c0072d29f5 | ||
|
|
1bfee3c23b | ||
|
|
7f7704ece8 | ||
|
|
7cc52204a8 | ||
|
|
8e76660e80 | ||
|
|
114c98928d | ||
|
|
ba5c551a29 | ||
|
|
09c45551fe | ||
|
|
75413d0b08 | ||
|
|
dfff658f34 | ||
|
|
1dd771c0c4 | ||
|
|
bc16487882 | ||
|
|
ec2d662320 | ||
|
|
690561ecd9 | ||
|
|
1aa313ab96 | ||
|
|
0636123f56 | ||
|
|
05c9e09d20 | ||
|
|
f219cac94c | ||
|
|
b4303b3a32 | ||
|
|
84f0c7f163 | ||
|
|
b3fea5b7df | ||
|
|
55ae448036 | ||
|
|
e294890a5e | ||
|
|
b2ab04861e | ||
|
|
2f7a77c84d | ||
|
|
fcb50ed142 | ||
|
|
4212918cfc | ||
|
|
b908b5986a | ||
|
|
6c304a2964 | ||
|
|
1a47427683 | ||
|
|
c7489b8d3c | ||
|
|
bd070e85a3 | ||
|
|
7a4d73af2e | ||
|
|
087aa70fe9 | ||
|
|
d4fa1d094a | ||
|
|
ea2245444c | ||
|
|
58bde04672 | ||
|
|
e537ea122f | ||
|
|
056ae1cf69 | ||
|
|
d83a923325 | ||
|
|
ec063d8515 | ||
|
|
e90d4d2b0f | ||
|
|
a6b5884fc6 | ||
|
|
64e2b46eec | ||
|
|
f68b0d0c08 | ||
|
|
576a06b5b2 | ||
|
|
d1a8137d91 | ||
|
|
82522fc07f | ||
|
|
6d273bc5b7 | ||
|
|
31933955e3 | ||
|
|
8792635bef | ||
|
|
7241d5543a | ||
|
|
52b21b5177 | ||
|
|
b8adc3b241 | ||
|
|
f3db4eeea5 | ||
|
|
1b05480354 | ||
|
|
43ea6148df | ||
|
|
41b71bb60c | ||
|
|
3fd94c354a | ||
|
|
94416989a8 | ||
|
|
b08afe4237 | ||
|
|
7294841a28 | ||
|
|
9b8e4e81a9 | ||
|
|
efda8596a5 | ||
|
|
318462fa24 | ||
|
|
a3a5284f97 | ||
|
|
990b40df3e | ||
|
|
5fbf35df86 | ||
|
|
56f004dc63 | ||
|
|
44bcc8cebc | ||
|
|
a5a4e022ba | ||
|
|
f758d94fba | ||
|
|
82f0176773 | ||
|
|
8156468898 | ||
|
|
12f958c955 | ||
|
|
83beb7148c | ||
|
|
645b7bf9ed | ||
|
|
fbcb89f092 | ||
|
|
86db561193 | ||
|
|
0b8f3306c7 | ||
|
|
5231ac8f3f | ||
|
|
e8fec768cc | ||
|
|
ef230011fd | ||
|
|
65872e884f | ||
|
|
641e63b08c | ||
|
|
d8f838c365 | ||
|
|
266082db72 | ||
|
|
718021b714 | ||
|
|
d368d1943d | ||
|
|
f73a1ce590 | ||
|
|
5bcbd4d0f4 | ||
|
|
797bd8a6e2 | ||
|
|
23de865563 | ||
|
|
4e8a0e456b | ||
|
|
278dcc5dda | ||
|
|
805771d2ed | ||
|
|
5ab56c431f | ||
|
|
aec1826c34 | ||
|
|
04a0d38e3b | ||
|
|
aa9e7b6dfb | ||
|
|
ac134ee5f5 | ||
|
|
154f3c6cd7 | ||
|
|
594ece1a70 | ||
|
|
33ef158b09 | ||
|
|
51a4f76f26 | ||
|
|
f04f0c883e | ||
|
|
72d04577df | ||
|
|
194ab4694e | ||
|
|
04967efe26 | ||
|
|
dbff2a69e2 | ||
|
|
d8773697de | ||
|
|
046aeab5e2 | ||
|
|
a9d6e0048c | ||
|
|
a2d821f960 | ||
|
|
b1451b3460 | ||
|
|
8dabbd8f94 | ||
|
|
a1669d490f | ||
|
|
9ac42ffb11 | ||
|
|
e58fe63dde | ||
|
|
0d1f260328 | ||
|
|
ba55ba7381 | ||
|
|
260bdb1572 | ||
|
|
7d5ebad188 | ||
|
|
78d9fe5813 | ||
|
|
a42e541326 | ||
|
|
673b18d9a9 | ||
|
|
2a99218162 | ||
|
|
e1763e22ae | ||
|
|
2433fdab98 | ||
|
|
cb6edf1a5f | ||
|
|
3d4c5346c6 | ||
|
|
a8aa05ac4e | ||
|
|
0e122e5f56 | ||
|
|
47ea1af180 | ||
|
|
3951e6ceb4 | ||
|
|
bf70f8d717 | ||
|
|
214794d056 | ||
|
|
b9fa5b5193 | ||
|
|
5366b9e5ba | ||
|
|
fd67767538 | ||
|
|
ae35be3437 | ||
|
|
01e7bf1f33 | ||
|
|
49354f2121 | ||
|
|
072318466e | ||
|
|
248250514f | ||
|
|
2419e6c6ad | ||
|
|
029e009db1 | ||
|
|
cfd524f345 | ||
|
|
355480601d | ||
|
|
f956ddcc77 | ||
|
|
ccb4ecfbd8 | ||
|
|
95886d1cf9 | ||
|
|
9b53f4b382 | ||
|
|
3f0e292246 | ||
|
|
0d4b16aadb | ||
|
|
db04914ab6 | ||
|
|
abb0d67774 | ||
|
|
05c442ab5e | ||
|
|
4ce9745d35 | ||
|
|
37af200ecb | ||
|
|
ddbcf49868 | ||
|
|
942be86635 | ||
|
|
2ed7f69b83 | ||
|
|
91504cda85 | ||
|
|
16434d9ad8 | ||
|
|
9e10cfb53a | ||
|
|
32047dccc5 | ||
|
|
0f7c5f0de1 | ||
|
|
8b831dbe59 | ||
|
|
8e33aafdba | ||
|
|
1b134f2d13 | ||
|
|
7adca3efff | ||
|
|
6731b38baa | ||
|
|
feee571bc8 | ||
|
|
21e344e283 | ||
|
|
7c93b61532 | ||
|
|
dd8b90f9d3 | ||
|
|
e1c0ab5bd2 | ||
|
|
a57be5ceb3 | ||
|
|
6d4a8435c7 | ||
|
|
a39b3bc882 | ||
|
|
30a16c8f60 | ||
|
|
0638512cf9 | ||
|
|
4ee90e5ea2 | ||
|
|
9cdd28c2ca | ||
|
|
db871c2686 | ||
|
|
5a2dff7b74 | ||
|
|
2d82f49adc | ||
|
|
1095c0be41 | ||
|
|
019b0fd725 | ||
|
|
80c129941a | ||
|
|
eeb6152703 | ||
|
|
e140642ba4 | ||
|
|
a49711d383 | ||
|
|
f0b8073ea5 | ||
|
|
49f64aecee | ||
|
|
dc49cc6e26 | ||
|
|
e42f8e0d0c | ||
|
|
114a29f4ea | ||
|
|
bb1cdef4c6 | ||
|
|
cd0444bd53 | ||
|
|
cb3f55076e | ||
|
|
e1e60892a8 | ||
|
|
d509af540d | ||
|
|
c8767ede77 | ||
|
|
f7c0a85c72 | ||
|
|
8935ab8fdc | ||
|
|
1f39b0ff2a | ||
|
|
b02fb8e9a0 | ||
|
|
d50c3cc944 | ||
|
|
4c26fada5e | ||
|
|
d13d1868b6 | ||
|
|
6a0953b19f | ||
|
|
6ba06f24ce | ||
|
|
577d86265e | ||
|
|
1c1b59b719 | ||
|
|
518847a92c | ||
|
|
aa30b4c803 | ||
|
|
a9dab608c7 | ||
|
|
e6643fd2dd | ||
|
|
f58606b64d | ||
|
|
5e60bee9c0 | ||
|
|
33410b1d57 | ||
|
|
e365ae3226 | ||
|
|
5f6e0095b0 | ||
|
|
dc052bee21 | ||
|
|
38849514f3 | ||
|
|
7810e2c3bf | ||
|
|
5d4cbbb038 | ||
|
|
58a81374d6 | ||
|
|
c29c34bab2 | ||
|
|
b4452d4be1 | ||
|
|
7fc3ad0263 | ||
|
|
65ea02a73d | ||
|
|
00d23753ca | ||
|
|
3d8c68e189 | ||
|
|
d7a0723a52 | ||
|
|
67bf3a7991 | ||
|
|
82251c2d80 | ||
|
|
f43fa94549 | ||
|
|
29ac3cbe81 | ||
|
|
5e59c5261e | ||
|
|
aa82575a78 | ||
|
|
f3c9cb7a8a | ||
|
|
f82b335916 | ||
|
|
553ab45f46 | ||
|
|
59606d48ad | ||
|
|
0a15be1017 | ||
|
|
9501a28a93 | ||
|
|
d906914737 | ||
|
|
33d278ad8f | ||
|
|
6d4fc589ae | ||
|
|
9614b09f7a | ||
|
|
af5f4b57f8 | ||
|
|
c6fbe58382 | ||
|
|
afe7f7522c | ||
|
|
0c62837296 | ||
|
|
d71637c77d | ||
|
|
3899f79f97 | ||
|
|
8ce0051f9b | ||
|
|
4be691da50 | ||
|
|
8fe012cf09 | ||
|
|
27a9ff14fb | ||
|
|
ae548de502 | ||
|
|
1b75f1aa9c | ||
|
|
7e33398d5c | ||
|
|
50c2c4db29 | ||
|
|
ee0ceea118 | ||
|
|
b98cec74ae | ||
|
|
05cc5fe82b | ||
|
|
fad3c1352b | ||
|
|
4167d2c4b3 | ||
|
|
ff1504dc58 | ||
|
|
08adb6b297 | ||
|
|
42ba0a88f4 | ||
|
|
1736602ce7 | ||
|
|
6b1a3d6e68 | ||
|
|
51591891d3 | ||
|
|
d1a229c255 | ||
|
|
d9698a6eff | ||
|
|
37fed289e6 | ||
|
|
9ec8680936 | ||
|
|
87af1f2761 | ||
|
|
da30487119 | ||
|
|
b57aa4a2ca | ||
|
|
a5f5ea1128 | ||
|
|
91dd7cd4dc | ||
|
|
2913826352 | ||
|
|
0bc15598d7 | ||
|
|
fb3f68ca96 | ||
|
|
a4edf22a9c | ||
|
|
97e44c4ba5 | ||
|
|
453adb5d04 | ||
|
|
033b456b7a | ||
|
|
73dbb84fc6 | ||
|
|
780fb28946 | ||
|
|
815ce43d17 | ||
|
|
170d837122 | ||
|
|
b5269b25a3 | ||
|
|
f12e814344 | ||
|
|
5d5a21fddf | ||
|
|
67f1d1129b | ||
|
|
d9362a2ce9 | ||
|
|
4e5966e477 | ||
|
|
22e24f24c6 | ||
|
|
35b47f73f4 | ||
|
|
9cc1731767 | ||
|
|
c592eaa35a | ||
|
|
525a8a5df4 | ||
|
|
e4ba0861e5 | ||
|
|
29cd0b3bde | ||
|
|
f2ebae635a | ||
|
|
75934cdd8c | ||
|
|
cf1fe027dd | ||
|
|
e9dbc1a5a5 | ||
|
|
6bd5eee9b0 | ||
|
|
fc707c7e31 | ||
|
|
eba7e32df1 | ||
|
|
6504e67139 | ||
|
|
428550165a | ||
|
|
a150e77507 | ||
|
|
d1299c11d6 | ||
|
|
fccc9d32ee | ||
|
|
d63c195bff | ||
|
|
e7515584b1 | ||
|
|
0d010968e5 | ||
|
|
5f4fc95c50 | ||
|
|
b2a92ef0bf | ||
|
|
01cdc4a572 | ||
|
|
cdfc881b32 | ||
|
|
d7293aa1cd | ||
|
|
1e78918ad3 | ||
|
|
526b3c4393 | ||
|
|
5d2bfddc15 | ||
|
|
5ac603bbcc | ||
|
|
e41a50af97 | ||
|
|
d3737f5ef7 | ||
|
|
addbd067c8 | ||
|
|
62c842548d | ||
|
|
5526fcac27 | ||
|
|
55c94eb5c0 | ||
|
|
e64d617de6 | ||
|
|
ba456c5eaf | ||
|
|
5e630ffe78 | ||
|
|
9ae75d4840 | ||
|
|
78eeb1219a | ||
|
|
54b2163c56 | ||
|
|
1ca0d2f21d | ||
|
|
2a789f8b01 | ||
|
|
cffba005f0 | ||
|
|
6c72734652 | ||
|
|
83af72a3bc | ||
|
|
ed6285e083 | ||
|
|
57a8c7e652 | ||
|
|
b40a1c54f7 | ||
|
|
8fa4dc75c9 | ||
|
|
99d1521266 | ||
|
|
c78536dfeb | ||
|
|
288dc5be2c | ||
|
|
9ae28e2fab | ||
|
|
f27b66baa3 | ||
|
|
230f0b51f2 | ||
|
|
1f84d0a317 | ||
|
|
2f64d42855 | ||
|
|
9c07a8354e | ||
|
|
a7e9bb7618 | ||
|
|
ad118bbbd6 | ||
|
|
d823382732 | ||
|
|
3a5d9129b2 | ||
|
|
17702d1a76 | ||
|
|
9305bfe190 | ||
|
|
0d30a3793a | ||
|
|
a402c485a3 | ||
|
|
05ad2e5008 | ||
|
|
e3bc22f7d5 | ||
|
|
c703dd6056 | ||
|
|
153de3ffef | ||
|
|
3bcc0db4fc | ||
|
|
142403c6cb | ||
|
|
a2d4554c78 | ||
|
|
a89fd2733b | ||
|
|
39bba05a17 | ||
|
|
a8f27f93b7 | ||
|
|
ce3299f106 | ||
|
|
c568923478 | ||
|
|
54eeb8d563 | ||
|
|
e6a0d2884a | ||
|
|
ceabef7e58 | ||
|
|
0be88ab458 | ||
|
|
30756b12ea | ||
|
|
ec354a8a91 | ||
|
|
1a4b22dff8 | ||
|
|
50a26191ea | ||
|
|
a28b02b0ac | ||
|
|
0829bc641e | ||
|
|
b997773139 | ||
|
|
9044f25f33 | ||
|
|
f8bd224c99 | ||
|
|
4d21f1c19c | ||
|
|
5a3e21788d | ||
|
|
816a97ab47 | ||
|
|
d4509bce5f | ||
|
|
ced0e30506 | ||
|
|
2fb543b144 | ||
|
|
b08f6eefe8 | ||
|
|
65d1881f12 | ||
|
|
b000491514 | ||
|
|
70c4585b88 | ||
|
|
aea3713484 | ||
|
|
7f040011f0 | ||
|
|
c6429eae4f | ||
|
|
d2a30d2801 | ||
|
|
a122be7942 | ||
|
|
61f431dff3 | ||
|
|
b19c83578d | ||
|
|
ddfb18b609 | ||
|
|
095434a4c1 | ||
|
|
8a80ced4b8 | ||
|
|
ef2bb6d510 | ||
|
|
889cfdf47e | ||
|
|
c173449c46 | ||
|
|
c08bae8308 | ||
|
|
80f7b084c0 | ||
|
|
5d24d04adf | ||
|
|
7cc9a70e43 | ||
|
|
5ddfb2c2ca | ||
|
|
242c15bf4c | ||
|
|
867f407401 | ||
|
|
54f49f38f2 | ||
|
|
83d2a782f6 | ||
|
|
d6dd8e0d45 | ||
|
|
9029f8ce34 | ||
|
|
ca23b2ed9a | ||
|
|
664f34f2ac | ||
|
|
1c2c404ca9 | ||
|
|
eef4df9063 | ||
|
|
176da44faf | ||
|
|
619d7d1dfe | ||
|
|
2eab4ec19c | ||
|
|
05eff13ec8 | ||
|
|
4d28266eba | ||
|
|
ba9c50c358 | ||
|
|
e1e5dfccc1 | ||
|
|
1097371cf4 | ||
|
|
0b08d6bc52 | ||
|
|
72ed39a481 | ||
|
|
d4683d941f | ||
|
|
f853108d69 | ||
|
|
045ff10826 | ||
|
|
2a746115ca | ||
|
|
37fddc61d8 | ||
|
|
a050250153 | ||
|
|
42e27a360d | ||
|
|
95b9df187f | ||
|
|
7bbe8f467c | ||
|
|
0c67afb6c3 | ||
|
|
68b7c0d38c | ||
|
|
9ba0e25bfe | ||
|
|
9a64347ea6 | ||
|
|
e4e2b804bc | ||
|
|
4533b3e934 | ||
|
|
fd71773668 | ||
|
|
b17d57f737 | ||
|
|
f5d98e3148 | ||
|
|
5f9536af06 | ||
|
|
7c41b31c37 | ||
|
|
a5c43c26f3 | ||
|
|
82aa1480af | ||
|
|
516be406e0 | ||
|
|
1f4840ba2f | ||
|
|
52bc2cb266 | ||
|
|
18502d5250 | ||
|
|
b3f589df62 | ||
|
|
8ebf1279f9 | ||
|
|
19161ae4a0 | ||
|
|
c24e5c63e8 | ||
|
|
e656570d13 | ||
|
|
9e4209b837 | ||
|
|
ed52123206 | ||
|
|
d10bcd3d6c | ||
|
|
45e81a1b0c | ||
|
|
829707fc5a | ||
|
|
a0d862e1f1 | ||
|
|
1dcc135da5 | ||
|
|
95626abdd3 | ||
|
|
152c5422f1 | ||
|
|
98bfdb322a | ||
|
|
d0d99c31b0 | ||
|
|
0e15d6cea8 | ||
|
|
ed03b1aa7f | ||
|
|
0379fb5614 | ||
|
|
fd1263c9aa | ||
|
|
c0bab015a4 | ||
|
|
4428daa411 | ||
|
|
f821fa0f2d | ||
|
|
2dafef1fab | ||
|
|
d83f7639be | ||
|
|
e08efe2598 | ||
|
|
e4ebca0945 | ||
|
|
6bf3ef47e1 | ||
|
|
7deb0a6db9 | ||
|
|
c106638648 | ||
|
|
4dcbbfba5b | ||
|
|
036c4c8e6f | ||
|
|
9ed4526fee | ||
|
|
b16f12faa3 | ||
|
|
9df02aa335 | ||
|
|
d60d3fe1cb | ||
|
|
a554a588c9 | ||
|
|
4a1842c004 | ||
|
|
39ec208171 | ||
|
|
899de8227d | ||
|
|
5af4a16e57 | ||
|
|
fc07de73e3 | ||
|
|
f5ccc1516b | ||
|
|
de0ec1f739 | ||
|
|
b29f238083 | ||
|
|
2941bb9bb8 | ||
|
|
297b44f24b | ||
|
|
429ed5faa5 | ||
|
|
b3029f75cd | ||
|
|
f7bc3aa77c | ||
|
|
cb77d81f8d | ||
|
|
b87617945e | ||
|
|
9289ce8534 | ||
|
|
798d12b499 | ||
|
|
5146760def | ||
|
|
48649d50b5 | ||
|
|
ccd66419f4 | ||
|
|
80334884fb | ||
|
|
4ab45e8c21 | ||
|
|
c566a7abf3 | ||
|
|
fd0048827d | ||
|
|
74960eaeac | ||
|
|
c49102d688 | ||
|
|
40cf8ba2ce | ||
|
|
ffc0ab2d40 | ||
|
|
7183596586 | ||
|
|
5664bfe4b6 | ||
|
|
4074ff4132 | ||
|
|
e7f9885aa3 |
29
.ansible-lint
Normal file
29
.ansible-lint
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
skip_list:
|
||||||
|
# Ignore rules that make no sense:
|
||||||
|
- galaxy[tags]
|
||||||
|
- galaxy[version-incorrect]
|
||||||
|
- meta-runtime[unsupported-version]
|
||||||
|
- no-changed-when
|
||||||
|
- sanity[cannot-ignore] # some of the rules you cannot ignore actually MUST be ignored, like yamllint:unparsable-with-libyaml
|
||||||
|
- yaml # we're using yamllint ourselves
|
||||||
|
|
||||||
|
# To be checked and maybe fixed:
|
||||||
|
- ignore-errors
|
||||||
|
- key-order[task]
|
||||||
|
- name[casing]
|
||||||
|
- name[missing]
|
||||||
|
- name[play]
|
||||||
|
- name[template]
|
||||||
|
- no-free-form
|
||||||
|
- no-handler
|
||||||
|
- risky-file-permissions
|
||||||
|
- risky-shell-pipe
|
||||||
|
- var-naming[no-reserved]
|
||||||
|
- var-naming[no-role-prefix]
|
||||||
|
- var-naming[pattern]
|
||||||
|
- var-naming[read-only]
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
|
<!--
|
||||||
|
Copyright (c) Ansible Project
|
||||||
|
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
-->
|
||||||
|
|
||||||
## Azure Pipelines Configuration
|
## Azure Pipelines Configuration
|
||||||
|
|
||||||
Please see the [Documentation](https://github.com/ansible/community/wiki/Testing:-Azure-Pipelines) for more information.
|
Please see the [Documentation](https://github.com/ansible/community/wiki/Testing:-Azure-Pipelines) for more information.
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
---
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
batch: true
|
batch: true
|
||||||
branches:
|
branches:
|
||||||
@@ -31,8 +36,6 @@ variables:
|
|||||||
value: ansible_collections/community/crypto
|
value: ansible_collections/community/crypto
|
||||||
- name: coverageBranches
|
- name: coverageBranches
|
||||||
value: main
|
value: main
|
||||||
- name: pipelinesCoverage
|
|
||||||
value: coverage
|
|
||||||
- name: entryPoint
|
- name: entryPoint
|
||||||
value: tests/utils/shippable/shippable.sh
|
value: tests/utils/shippable/shippable.sh
|
||||||
- name: fetchDepth
|
- name: fetchDepth
|
||||||
@@ -41,7 +44,7 @@ variables:
|
|||||||
resources:
|
resources:
|
||||||
containers:
|
containers:
|
||||||
- container: default
|
- container: default
|
||||||
image: quay.io/ansible/azure-pipelines-test-container:1.9.0
|
image: quay.io/ansible/azure-pipelines-test-container:7.0.0
|
||||||
|
|
||||||
pool: Standard
|
pool: Standard
|
||||||
|
|
||||||
@@ -56,65 +59,63 @@ stages:
|
|||||||
targets:
|
targets:
|
||||||
- name: Sanity
|
- name: Sanity
|
||||||
test: 'devel/sanity/1'
|
test: 'devel/sanity/1'
|
||||||
- name: Sanity Extra # Only on devel
|
|
||||||
test: 'devel/sanity/extra'
|
|
||||||
- name: Units
|
- name: Units
|
||||||
test: 'devel/units/1'
|
test: 'devel/units/1'
|
||||||
- stage: Ansible_2_13
|
- stage: Ansible_2_21
|
||||||
displayName: Sanity & Units 2.13
|
displayName: Sanity & Units 2.21
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
targets:
|
targets:
|
||||||
- name: Sanity
|
- name: Sanity
|
||||||
test: '2.13/sanity/1'
|
test: '2.21/sanity/1'
|
||||||
- name: Units
|
- name: Units
|
||||||
test: '2.13/units/1'
|
test: '2.21/units/1'
|
||||||
- stage: Ansible_2_12
|
- stage: Ansible_2_20
|
||||||
displayName: Sanity & Units 2.12
|
displayName: Sanity & Units 2.20
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
targets:
|
targets:
|
||||||
- name: Sanity
|
- name: Sanity
|
||||||
test: '2.12/sanity/1'
|
test: '2.20/sanity/1'
|
||||||
- name: Units
|
- name: Units
|
||||||
test: '2.12/units/1'
|
test: '2.20/units/1'
|
||||||
- stage: Ansible_2_11
|
- stage: Ansible_2_19
|
||||||
displayName: Sanity & Units 2.11
|
displayName: Sanity & Units 2.19
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
targets:
|
targets:
|
||||||
- name: Sanity
|
- name: Sanity
|
||||||
test: '2.11/sanity/1'
|
test: '2.19/sanity/1'
|
||||||
- name: Units
|
- name: Units
|
||||||
test: '2.11/units/1'
|
test: '2.19/units/1'
|
||||||
- stage: Ansible_2_10
|
- stage: Ansible_2_18
|
||||||
displayName: Sanity & Units 2.10
|
displayName: Sanity & Units 2.18
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
targets:
|
targets:
|
||||||
- name: Sanity
|
- name: Sanity
|
||||||
test: '2.10/sanity/1'
|
test: '2.18/sanity/1'
|
||||||
- name: Units
|
- name: Units
|
||||||
test: '2.10/units/1'
|
test: '2.18/units/1'
|
||||||
- stage: Ansible_2_9
|
- stage: Ansible_2_17
|
||||||
displayName: Sanity & Units 2.9
|
displayName: Sanity & Units 2.17
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
targets:
|
targets:
|
||||||
- name: Sanity
|
- name: Sanity
|
||||||
test: '2.9/sanity/1'
|
test: '2.17/sanity/1'
|
||||||
- name: Units
|
- name: Units
|
||||||
test: '2.9/units/1'
|
test: '2.17/units/1'
|
||||||
### Docker
|
### Docker
|
||||||
- stage: Docker_devel
|
- stage: Docker_devel
|
||||||
displayName: Docker devel
|
displayName: Docker devel
|
||||||
@@ -122,86 +123,98 @@ stages:
|
|||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
testFormat: devel/linux/{0}/1
|
testFormat: devel/linux/{0}
|
||||||
targets:
|
targets:
|
||||||
- name: CentOS 7
|
- name: Fedora 44
|
||||||
test: centos7
|
test: fedora44
|
||||||
- name: Fedora 34
|
- name: Ubuntu 24.04
|
||||||
test: fedora34
|
test: ubuntu2404
|
||||||
- name: Fedora 35
|
- name: Alpine 3.23
|
||||||
test: fedora35
|
test: alpine323
|
||||||
- name: openSUSE 15
|
groups:
|
||||||
test: opensuse15
|
- 1
|
||||||
- name: Ubuntu 18.04
|
- 2
|
||||||
test: ubuntu1804
|
- stage: Docker_2_21
|
||||||
- name: Ubuntu 20.04
|
displayName: Docker 2.21
|
||||||
test: ubuntu2004
|
|
||||||
- name: Alpine 3
|
|
||||||
test: alpine3
|
|
||||||
- stage: Docker_2_13
|
|
||||||
displayName: Docker 2.13
|
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
testFormat: 2.13/linux/{0}/1
|
testFormat: 2.21/linux/{0}
|
||||||
targets:
|
targets:
|
||||||
- name: openSUSE 15 py2
|
- name: Fedora 43
|
||||||
test: opensuse15py2
|
test: fedora43
|
||||||
- name: Ubuntu 18.04
|
- name: Ubuntu 24.04
|
||||||
test: ubuntu1804
|
test: ubuntu2404
|
||||||
- name: Alpine 3
|
# - name: Alpine 3.23
|
||||||
test: alpine3
|
# test: alpine323
|
||||||
- stage: Docker_2_12
|
groups:
|
||||||
displayName: Docker 2.12
|
- 1
|
||||||
|
- 2
|
||||||
|
- stage: Docker_2_20
|
||||||
|
displayName: Docker 2.20
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
testFormat: 2.12/linux/{0}/1
|
testFormat: 2.20/linux/{0}
|
||||||
targets:
|
targets:
|
||||||
- name: CentOS 6
|
- name: Fedora 42
|
||||||
test: centos6
|
test: fedora42
|
||||||
- name: Fedora 33
|
- name: Alpine 3.22
|
||||||
test: fedora33
|
test: alpine322
|
||||||
- stage: Docker_2_11
|
groups:
|
||||||
displayName: Docker 2.11
|
- 1
|
||||||
|
- 2
|
||||||
|
- stage: Docker_2_19
|
||||||
|
displayName: Docker 2.19
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
testFormat: 2.11/linux/{0}/1
|
testFormat: 2.19/linux/{0}
|
||||||
targets:
|
targets:
|
||||||
- name: CentOS 7
|
- name: Fedora 41
|
||||||
test: centos7
|
test: fedora41
|
||||||
- name: Fedora 32
|
- name: Alpine 3.21
|
||||||
test: fedora32
|
test: alpine321
|
||||||
- name: Alpine 3
|
groups:
|
||||||
test: alpine3
|
- 1
|
||||||
- stage: Docker_2_10
|
- 2
|
||||||
displayName: Docker 2.10
|
- stage: Docker_2_18
|
||||||
|
displayName: Docker 2.18
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
testFormat: 2.10/linux/{0}/1
|
testFormat: 2.18/linux/{0}
|
||||||
targets:
|
targets:
|
||||||
- name: CentOS 6
|
- name: Fedora 40
|
||||||
test: centos6
|
test: fedora40
|
||||||
- name: Fedora 31
|
- name: Ubuntu 24.04
|
||||||
test: fedora31
|
test: ubuntu2404
|
||||||
- stage: Docker_2_9
|
- name: Alpine 3.20
|
||||||
displayName: Docker 2.9
|
test: alpine320
|
||||||
|
groups:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
- stage: Docker_2_17
|
||||||
|
displayName: Docker 2.17
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
testFormat: 2.9/linux/{0}/1
|
testFormat: 2.17/linux/{0}
|
||||||
targets:
|
targets:
|
||||||
- name: Fedora 31
|
- name: Fedora 39
|
||||||
test: fedora31
|
test: fedora39
|
||||||
- name: Ubuntu 18.04
|
- name: Ubuntu 22.04
|
||||||
test: ubuntu1804
|
test: ubuntu2204
|
||||||
|
- name: Alpine 3.19
|
||||||
|
test: alpine319
|
||||||
|
groups:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
|
||||||
### Community Docker
|
### Community Docker
|
||||||
- stage: Docker_community_devel
|
- stage: Docker_community_devel
|
||||||
@@ -210,165 +223,217 @@ stages:
|
|||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
testFormat: devel/linux-community/{0}/1
|
testFormat: devel/linux-community/{0}
|
||||||
targets:
|
targets:
|
||||||
- name: Debian Bullseye
|
- name: Debian 13 Trixie
|
||||||
|
test: debian-13-trixie/3.13
|
||||||
|
- name: Debian 12 Bookworm
|
||||||
|
test: debian-bookworm/3.11
|
||||||
|
- name: Debian 11 Bullseye
|
||||||
test: debian-bullseye/3.9
|
test: debian-bullseye/3.9
|
||||||
- name: ArchLinux
|
- name: ArchLinux
|
||||||
test: archlinux/3.10
|
test: archlinux/3.14
|
||||||
- name: CentOS Stream 8
|
groups:
|
||||||
test: centos-stream8/3.8
|
- 1
|
||||||
|
- 2
|
||||||
|
|
||||||
### Remote
|
### Remote
|
||||||
|
- stage: Remote_devel_extra_vms
|
||||||
|
displayName: Remote devel extra VMs
|
||||||
|
dependsOn: []
|
||||||
|
jobs:
|
||||||
|
- template: templates/matrix.yml
|
||||||
|
parameters:
|
||||||
|
testFormat: devel/{0}
|
||||||
|
targets:
|
||||||
|
- name: Alpine 3.23
|
||||||
|
test: alpine/3.23
|
||||||
|
- name: Fedora 44
|
||||||
|
test: fedora/44
|
||||||
|
- name: Ubuntu 22.04
|
||||||
|
test: ubuntu/22.04
|
||||||
|
- name: Ubuntu 24.04
|
||||||
|
test: ubuntu/24.04
|
||||||
|
groups:
|
||||||
|
- vm
|
||||||
- stage: Remote_devel
|
- stage: Remote_devel
|
||||||
displayName: Remote devel
|
displayName: Remote devel
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
testFormat: devel/{0}/1
|
testFormat: devel/{0}
|
||||||
targets:
|
targets:
|
||||||
- name: macOS 12.0
|
- name: macOS 26.3
|
||||||
test: macos/12.0
|
test: macos/26.3
|
||||||
- name: RHEL 7.9
|
- name: RHEL 10.1
|
||||||
test: rhel/7.9
|
test: rhel/10.1
|
||||||
- name: RHEL 8.5
|
- name: RHEL 9.7
|
||||||
test: rhel/8.5
|
test: rhel/9.7
|
||||||
- name: FreeBSD 12.3
|
- name: FreeBSD 15.0
|
||||||
test: freebsd/12.3
|
test: freebsd/15.0
|
||||||
- name: FreeBSD 13.0
|
- name: FreeBSD 14.4
|
||||||
test: freebsd/13.0
|
test: freebsd/14.4
|
||||||
- stage: Remote_2_13
|
groups:
|
||||||
displayName: Remote 2.13
|
- 1
|
||||||
|
- 2
|
||||||
|
- stage: Remote_2_21
|
||||||
|
displayName: Remote 2.21
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
testFormat: 2.13/{0}/1
|
testFormat: 2.21/{0}
|
||||||
targets:
|
targets:
|
||||||
- name: macOS 12.0
|
# - name: macOS 26.3
|
||||||
test: macos/12.0
|
# test: macos/26.3
|
||||||
- name: RHEL 8.5
|
- name: RHEL 10.1
|
||||||
test: rhel/8.5
|
test: rhel/10.1
|
||||||
- stage: Remote_2_12
|
# - name: RHEL 9.7
|
||||||
displayName: Remote 2.12
|
# test: rhel/9.7
|
||||||
|
# - name: FreeBSD 15.0
|
||||||
|
# test: freebsd/15.0
|
||||||
|
# - name: FreeBSD 14.4
|
||||||
|
# test: freebsd/14.4
|
||||||
|
groups:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
- stage: Remote_2_20
|
||||||
|
displayName: Remote 2.20
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
testFormat: 2.12/{0}/1
|
testFormat: 2.20/{0}
|
||||||
targets:
|
targets:
|
||||||
- name: macOS 11.1
|
- name: macOS 15.3
|
||||||
test: macos/11.1
|
test: macos/15.3
|
||||||
- name: RHEL 8.4
|
- name: RHEL 9.7
|
||||||
test: rhel/8.4
|
test: rhel/9.7
|
||||||
- stage: Remote_2_11
|
- name: FreeBSD 14.3
|
||||||
displayName: Remote 2.11
|
test: freebsd/14.3
|
||||||
|
groups:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
- stage: Remote_2_19
|
||||||
|
displayName: Remote 2.19
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
testFormat: 2.11/{0}/1
|
testFormat: 2.19/{0}
|
||||||
targets:
|
targets:
|
||||||
- name: RHEL 7.9
|
- name: RHEL 10.1
|
||||||
test: rhel/7.9
|
test: rhel/10.1
|
||||||
- name: RHEL 8.3
|
- name: FreeBSD 14.2
|
||||||
test: rhel/8.3
|
test: freebsd/14.2
|
||||||
- name: FreeBSD 12.2
|
groups:
|
||||||
test: freebsd/12.2
|
- 1
|
||||||
- stage: Remote_2_10
|
- 2
|
||||||
displayName: Remote 2.10
|
- stage: Remote_2_18
|
||||||
|
displayName: Remote 2.18
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
testFormat: 2.10/{0}/1
|
testFormat: 2.18/{0}
|
||||||
targets:
|
targets:
|
||||||
- name: OS X 10.11
|
# - name: macOS 14.3
|
||||||
test: osx/10.11
|
# test: macos/14.3
|
||||||
- name: macOS 10.15
|
- name: FreeBSD 14.1
|
||||||
test: macos/10.15
|
test: freebsd/14.1
|
||||||
- name: FreeBSD 12.1
|
groups:
|
||||||
test: freebsd/12.1
|
- 1
|
||||||
- stage: Remote_2_9
|
- 2
|
||||||
displayName: Remote 2.9
|
### Generic
|
||||||
dependsOn: []
|
- stage: Generic_devel
|
||||||
jobs:
|
displayName: Generic devel
|
||||||
- template: templates/matrix.yml
|
|
||||||
parameters:
|
|
||||||
testFormat: 2.9/{0}/1
|
|
||||||
targets:
|
|
||||||
- name: 'RHEL 7.8'
|
|
||||||
test: 'rhel/7.8'
|
|
||||||
### cloud
|
|
||||||
- stage: Cloud_devel
|
|
||||||
displayName: Cloud devel
|
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
nameFormat: Python {0}
|
nameFormat: Python {0}
|
||||||
testFormat: devel/cloud/{0}/1
|
testFormat: devel/generic/{0}
|
||||||
targets:
|
targets:
|
||||||
- test: 2.7
|
- test: "3.9"
|
||||||
- test: 3.5
|
|
||||||
- test: 3.6
|
|
||||||
- test: 3.7
|
|
||||||
- test: 3.8
|
|
||||||
- test: 3.9
|
|
||||||
- test: "3.10"
|
- test: "3.10"
|
||||||
- stage: Cloud_2_13
|
- test: "3.11"
|
||||||
displayName: Cloud 2.13
|
- test: "3.13"
|
||||||
|
- test: "3.14"
|
||||||
|
- test: "3.15"
|
||||||
|
groups:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
- stage: Generic_2_21
|
||||||
|
displayName: Generic 2.21
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
nameFormat: Python {0}
|
nameFormat: Python {0}
|
||||||
testFormat: 2.13/cloud/{0}/1
|
testFormat: 2.21/generic/{0}
|
||||||
targets:
|
targets:
|
||||||
- test: 2.7
|
- test: "3.11"
|
||||||
- test: 3.7
|
- test: "3.14"
|
||||||
- stage: Cloud_2_12
|
groups:
|
||||||
displayName: Cloud 2.12
|
- 1
|
||||||
|
- 2
|
||||||
|
- stage: Generic_2_20
|
||||||
|
displayName: Generic 2.20
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
nameFormat: Python {0}
|
nameFormat: Python {0}
|
||||||
testFormat: 2.12/cloud/{0}/1
|
testFormat: 2.20/generic/{0}
|
||||||
targets:
|
targets:
|
||||||
- test: 2.6
|
- test: "3.10"
|
||||||
- test: 3.9
|
- test: "3.14"
|
||||||
- stage: Cloud_2_11
|
groups:
|
||||||
displayName: Cloud 2.11
|
- 1
|
||||||
|
- 2
|
||||||
|
- stage: Generic_2_19
|
||||||
|
displayName: Generic 2.19
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
nameFormat: Python {0}
|
nameFormat: Python {0}
|
||||||
testFormat: 2.11/cloud/{0}/1
|
testFormat: 2.19/generic/{0}
|
||||||
targets:
|
targets:
|
||||||
- test: 3.8
|
- test: "3.9"
|
||||||
- stage: Cloud_2_10
|
- test: "3.13"
|
||||||
displayName: Cloud 2.10
|
groups:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
- stage: Generic_2_18
|
||||||
|
displayName: Generic 2.18
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
nameFormat: Python {0}
|
nameFormat: Python {0}
|
||||||
testFormat: 2.10/cloud/{0}/1
|
testFormat: 2.18/generic/{0}
|
||||||
targets:
|
targets:
|
||||||
- test: 3.6
|
- test: "3.8"
|
||||||
- stage: Cloud_2_9
|
- test: "3.13"
|
||||||
displayName: Cloud 2.9
|
groups:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
- stage: Generic_2_17
|
||||||
|
displayName: Generic 2.17
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
parameters:
|
parameters:
|
||||||
nameFormat: Python {0}
|
nameFormat: Python {0}
|
||||||
testFormat: 2.9/cloud/{0}/1
|
testFormat: 2.17/generic/{0}
|
||||||
targets:
|
targets:
|
||||||
- test: 2.7
|
- test: "3.7"
|
||||||
|
- test: "3.12"
|
||||||
|
groups:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
|
||||||
## Finally
|
## Finally
|
||||||
|
|
||||||
@@ -376,29 +441,29 @@ stages:
|
|||||||
condition: succeededOrFailed()
|
condition: succeededOrFailed()
|
||||||
dependsOn:
|
dependsOn:
|
||||||
- Ansible_devel
|
- Ansible_devel
|
||||||
- Ansible_2_13
|
- Ansible_2_21
|
||||||
- Ansible_2_12
|
- Ansible_2_20
|
||||||
- Ansible_2_11
|
- Ansible_2_19
|
||||||
- Ansible_2_10
|
- Ansible_2_18
|
||||||
- Ansible_2_9
|
- Ansible_2_17
|
||||||
|
- Remote_devel_extra_vms
|
||||||
- Remote_devel
|
- Remote_devel
|
||||||
- Remote_2_13
|
- Remote_2_21
|
||||||
- Remote_2_12
|
- Remote_2_20
|
||||||
- Remote_2_11
|
- Remote_2_19
|
||||||
- Remote_2_10
|
- Remote_2_18
|
||||||
- Remote_2_9
|
|
||||||
- Docker_devel
|
- Docker_devel
|
||||||
- Docker_2_13
|
- Docker_2_21
|
||||||
- Docker_2_12
|
- Docker_2_20
|
||||||
- Docker_2_11
|
- Docker_2_19
|
||||||
- Docker_2_10
|
- Docker_2_18
|
||||||
- Docker_2_9
|
- Docker_2_17
|
||||||
- Docker_community_devel
|
- Docker_community_devel
|
||||||
- Cloud_devel
|
- Generic_devel
|
||||||
- Cloud_2_13
|
- Generic_2_21
|
||||||
- Cloud_2_12
|
- Generic_2_20
|
||||||
- Cloud_2_11
|
- Generic_2_19
|
||||||
- Cloud_2_10
|
- Generic_2_18
|
||||||
- Cloud_2_9
|
- Generic_2_17
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/coverage.yml
|
- template: templates/coverage.yml
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
# Aggregate code coverage results for later processing.
|
# Aggregate code coverage results for later processing.
|
||||||
|
|
||||||
set -o pipefail -eu
|
set -o pipefail -eu
|
||||||
@@ -9,6 +13,10 @@ PATH="${PWD}/bin:${PATH}"
|
|||||||
|
|
||||||
mkdir "${agent_temp_directory}/coverage/"
|
mkdir "${agent_temp_directory}/coverage/"
|
||||||
|
|
||||||
|
if [[ "$(ansible --version)" =~ \ 2\.9\. ]]; then
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
options=(--venv --venv-system-site-packages --color -v)
|
options=(--venv --venv-system-site-packages --color -v)
|
||||||
|
|
||||||
ansible-test coverage combine --group-by command --export "${agent_temp_directory}/coverage/" "${options[@]}"
|
ansible-test coverage combine --group-by command --export "${agent_temp_directory}/coverage/" "${options[@]}"
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Combine coverage data from multiple jobs, keeping the data only from the most recent attempt from each job.
|
Combine coverage data from multiple jobs, keeping the data only from the most recent attempt from each job.
|
||||||
Coverage artifacts must be named using the format: "Coverage $(System.JobAttempt) {StableUniqueNameForEachJob}"
|
Coverage artifacts must be named using the format: "Coverage $(System.JobAttempt) {StableUniqueNameForEachJob}"
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
# Check the test results and set variables for use in later steps.
|
# Check the test results and set variables for use in later steps.
|
||||||
|
|
||||||
set -o pipefail -eu
|
set -o pipefail -eu
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Upload code coverage reports to codecov.io.
|
Upload code coverage reports to codecov.io.
|
||||||
Multiple coverage files from multiple languages are accepted and aggregated after upload.
|
Multiple coverage files from multiple languages are accepted and aggregated after upload.
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
# Generate code coverage reports for uploading to Azure Pipelines and codecov.io.
|
# Generate code coverage reports for uploading to Azure Pipelines and codecov.io.
|
||||||
|
|
||||||
set -o pipefail -eu
|
set -o pipefail -eu
|
||||||
|
|
||||||
PATH="${PWD}/bin:${PATH}"
|
PATH="${PWD}/bin:${PATH}"
|
||||||
|
|
||||||
|
if [[ "$(ansible --version)" =~ \ 2\.9\. ]]; then
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
if ! ansible-test --help >/dev/null 2>&1; then
|
if ! ansible-test --help >/dev/null 2>&1; then
|
||||||
# Install the devel version of ansible-test for generating code coverage reports.
|
# Install the devel version of ansible-test for generating code coverage reports.
|
||||||
# This is only used by Ansible Collections, which are typically tested against multiple Ansible versions (in separate jobs).
|
# This is only used by Ansible Collections, which are typically tested against multiple Ansible versions (in separate jobs).
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
# Configure the test environment and run the tests.
|
# Configure the test environment and run the tests.
|
||||||
|
|
||||||
set -o pipefail -eu
|
set -o pipefail -eu
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
"""Prepends a relative timestamp to each input line from stdin and writes it to stdout."""
|
"""Prepends a relative timestamp to each input line from stdin and writes it to stdout."""
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
---
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
# This template adds a job for processing code coverage data.
|
# This template adds a job for processing code coverage data.
|
||||||
# It will upload results to Azure Pipelines and codecov.io.
|
# It will upload results to Azure Pipelines and codecov.io.
|
||||||
# Use it from a job stage that completes after all other jobs have completed.
|
# Use it from a job stage that completes after all other jobs have completed.
|
||||||
@@ -23,16 +28,6 @@ jobs:
|
|||||||
- bash: .azure-pipelines/scripts/report-coverage.sh
|
- bash: .azure-pipelines/scripts/report-coverage.sh
|
||||||
displayName: Generate Coverage Report
|
displayName: Generate Coverage Report
|
||||||
condition: gt(variables.coverageFileCount, 0)
|
condition: gt(variables.coverageFileCount, 0)
|
||||||
- task: PublishCodeCoverageResults@1
|
|
||||||
inputs:
|
|
||||||
codeCoverageTool: Cobertura
|
|
||||||
# Azure Pipelines only accepts a single coverage data file.
|
|
||||||
# That means only Python or PowerShell coverage can be uploaded, but not both.
|
|
||||||
# Set the "pipelinesCoverage" variable to determine which type is uploaded.
|
|
||||||
# Use "coverage" for Python and "coverage-powershell" for PowerShell.
|
|
||||||
summaryFileLocation: "$(outputPath)/reports/$(pipelinesCoverage).xml"
|
|
||||||
displayName: Publish to Azure Pipelines
|
|
||||||
condition: gt(variables.coverageFileCount, 0)
|
|
||||||
- bash: .azure-pipelines/scripts/publish-codecov.py "$(outputPath)"
|
- bash: .azure-pipelines/scripts/publish-codecov.py "$(outputPath)"
|
||||||
displayName: Publish to codecov.io
|
displayName: Publish to codecov.io
|
||||||
condition: gt(variables.coverageFileCount, 0)
|
condition: gt(variables.coverageFileCount, 0)
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
---
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
# This template uses the provided targets and optional groups to generate a matrix which is then passed to the test template.
|
# This template uses the provided targets and optional groups to generate a matrix which is then passed to the test template.
|
||||||
# If this matrix template does not provide the required functionality, consider using the test template directly instead.
|
# If this matrix template does not provide the required functionality, consider using the test template directly instead.
|
||||||
|
|
||||||
@@ -45,11 +50,11 @@ jobs:
|
|||||||
parameters:
|
parameters:
|
||||||
jobs:
|
jobs:
|
||||||
- ${{ if eq(length(parameters.groups), 0) }}:
|
- ${{ if eq(length(parameters.groups), 0) }}:
|
||||||
- ${{ each target in parameters.targets }}:
|
|
||||||
- name: ${{ format(parameters.nameFormat, coalesce(target.name, target.test)) }}
|
|
||||||
test: ${{ format(parameters.testFormat, coalesce(target.test, target.name)) }}
|
|
||||||
- ${{ if not(eq(length(parameters.groups), 0)) }}:
|
|
||||||
- ${{ each group in parameters.groups }}:
|
|
||||||
- ${{ each target in parameters.targets }}:
|
- ${{ each target in parameters.targets }}:
|
||||||
- name: ${{ format(format(parameters.nameGroupFormat, parameters.nameFormat), coalesce(target.name, target.test), group) }}
|
- name: ${{ format(parameters.nameFormat, coalesce(target.name, target.test)) }}
|
||||||
test: ${{ format(format(parameters.testGroupFormat, parameters.testFormat), coalesce(target.test, target.name), group) }}
|
test: ${{ format(parameters.testFormat, coalesce(target.test, target.name)) }}
|
||||||
|
- ${{ if not(eq(length(parameters.groups), 0)) }}:
|
||||||
|
- ${{ each group in parameters.groups }}:
|
||||||
|
- ${{ each target in parameters.targets }}:
|
||||||
|
- name: ${{ format(format(parameters.nameGroupFormat, parameters.nameFormat), coalesce(target.name, target.test), group) }}
|
||||||
|
test: ${{ format(format(parameters.testGroupFormat, parameters.testFormat), coalesce(target.test, target.name), group) }}
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
---
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
# This template uses the provided list of jobs to create test one or more test jobs.
|
# This template uses the provided list of jobs to create test one or more test jobs.
|
||||||
# It can be used directly if needed, or through the matrix template.
|
# It can be used directly if needed, or through the matrix template.
|
||||||
|
|
||||||
@@ -9,37 +14,37 @@ parameters:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
- ${{ each job in parameters.jobs }}:
|
- ${{ each job in parameters.jobs }}:
|
||||||
- job: test_${{ replace(replace(replace(job.test, '/', '_'), '.', '_'), '-', '_') }}
|
- job: test_${{ replace(replace(replace(job.test, '/', '_'), '.', '_'), '-', '_') }}
|
||||||
displayName: ${{ job.name }}
|
displayName: ${{ job.name }}
|
||||||
container: default
|
container: default
|
||||||
workspace:
|
workspace:
|
||||||
clean: all
|
clean: all
|
||||||
steps:
|
steps:
|
||||||
- checkout: self
|
- checkout: self
|
||||||
fetchDepth: $(fetchDepth)
|
fetchDepth: $(fetchDepth)
|
||||||
path: $(checkoutPath)
|
path: $(checkoutPath)
|
||||||
- bash: .azure-pipelines/scripts/run-tests.sh "$(entryPoint)" "${{ job.test }}" "$(coverageBranches)"
|
- bash: .azure-pipelines/scripts/run-tests.sh "$(entryPoint)" "${{ job.test }}" "$(coverageBranches)"
|
||||||
displayName: Run Tests
|
displayName: Run Tests
|
||||||
- bash: .azure-pipelines/scripts/process-results.sh
|
- bash: .azure-pipelines/scripts/process-results.sh
|
||||||
condition: succeededOrFailed()
|
condition: succeededOrFailed()
|
||||||
displayName: Process Results
|
displayName: Process Results
|
||||||
- bash: .azure-pipelines/scripts/aggregate-coverage.sh "$(Agent.TempDirectory)"
|
- bash: .azure-pipelines/scripts/aggregate-coverage.sh "$(Agent.TempDirectory)"
|
||||||
condition: eq(variables.haveCoverageData, 'true')
|
condition: eq(variables.haveCoverageData, 'true')
|
||||||
displayName: Aggregate Coverage Data
|
displayName: Aggregate Coverage Data
|
||||||
- task: PublishTestResults@2
|
- task: PublishTestResults@2
|
||||||
condition: eq(variables.haveTestResults, 'true')
|
condition: eq(variables.haveTestResults, 'true')
|
||||||
inputs:
|
inputs:
|
||||||
testResultsFiles: "$(outputPath)/junit/*.xml"
|
testResultsFiles: "$(outputPath)/junit/*.xml"
|
||||||
displayName: Publish Test Results
|
displayName: Publish Test Results
|
||||||
- task: PublishPipelineArtifact@1
|
- task: PublishPipelineArtifact@1
|
||||||
condition: eq(variables.haveBotResults, 'true')
|
condition: eq(variables.haveBotResults, 'true')
|
||||||
displayName: Publish Bot Results
|
displayName: Publish Bot Results
|
||||||
inputs:
|
inputs:
|
||||||
targetPath: "$(outputPath)/bot/"
|
targetPath: "$(outputPath)/bot/"
|
||||||
artifactName: "Bot $(System.JobAttempt) $(System.StageDisplayName) $(System.JobDisplayName)"
|
artifactName: "Bot $(System.JobAttempt) $(System.StageDisplayName) $(System.JobDisplayName)"
|
||||||
- task: PublishPipelineArtifact@1
|
- task: PublishPipelineArtifact@1
|
||||||
condition: eq(variables.haveCoverageData, 'true')
|
condition: eq(variables.haveCoverageData, 'true')
|
||||||
displayName: Publish Coverage Data
|
displayName: Publish Coverage Data
|
||||||
inputs:
|
inputs:
|
||||||
targetPath: "$(Agent.TempDirectory)/coverage/"
|
targetPath: "$(Agent.TempDirectory)/coverage/"
|
||||||
artifactName: "Coverage $(System.JobAttempt) $(System.StageDisplayName) $(System.JobDisplayName)"
|
artifactName: "Coverage $(System.JobAttempt) $(System.StageDisplayName) $(System.JobDisplayName)"
|
||||||
|
|||||||
13
.flake8
Normal file
13
.flake8
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
# SPDX-FileCopyrightText: 2025 Felix Fontein <felix@fontein.de>
|
||||||
|
|
||||||
|
[flake8]
|
||||||
|
extend-ignore = E203, E402, F401
|
||||||
|
count = true
|
||||||
|
# TODO: decrease this to ~10
|
||||||
|
max-complexity = 60
|
||||||
|
# black's max-line-length is 89, but it doesn't touch long string literals.
|
||||||
|
# Since ansible-test's limit is 160, let's use that here.
|
||||||
|
max-line-length = 160
|
||||||
|
statistics = true
|
||||||
12
.git-blame-ignore-revs
Normal file
12
.git-blame-ignore-revs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Reformat YAML: https://github.com/ansible-collections/community.crypto/pull/866
|
||||||
|
33ef158b094f16d5e04ea9db3ed8bad010744d02
|
||||||
|
# Reformat with black, keeping Python 2 compatibility: https://github.com/ansible-collections/community.crypto/pull/871
|
||||||
|
aec1826c34051b9e7f8af7950489915b661e320b
|
||||||
|
# Reformat with black another time, this time without Python 2 compatibility
|
||||||
|
797bd8a6e2a6f4a37a89ecb15ca34ec88b33258d
|
||||||
|
# Reformat with ruff check --fix instead of isort
|
||||||
|
9cbf9fc6eca4631e34f91ce927c5192966dbe3f6
|
||||||
15
.github/dependabot.yml
vendored
Normal file
15
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
---
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
groups:
|
||||||
|
ci:
|
||||||
|
patterns:
|
||||||
|
- "*"
|
||||||
4
.github/patchback.yml
vendored
4
.github/patchback.yml
vendored
@@ -1,4 +1,8 @@
|
|||||||
---
|
---
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
backport_branch_prefix: patchback/backports/
|
backport_branch_prefix: patchback/backports/
|
||||||
backport_label_prefix: backport-
|
backport_label_prefix: backport-
|
||||||
target_branch_prefix: stable-
|
target_branch_prefix: stable-
|
||||||
|
|||||||
96
.github/workflows/docs-pr.yml
vendored
Normal file
96
.github/workflows/docs-pr.yml
vendored
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
---
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
name: Collection Docs
|
||||||
|
concurrency:
|
||||||
|
group: docs-pr-${{ github.head_ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
'on':
|
||||||
|
pull_request_target:
|
||||||
|
types: [opened, synchronize, reopened, closed]
|
||||||
|
|
||||||
|
env:
|
||||||
|
GHP_BASE_URL: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-docs:
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
name: Build Ansible Docs
|
||||||
|
uses: ansible-community/github-docs-build/.github/workflows/_shared-docs-build-pr.yml@main
|
||||||
|
with:
|
||||||
|
ansible-ref: devel
|
||||||
|
collection-name: community.crypto
|
||||||
|
init-lenient: false
|
||||||
|
init-fail-on-error: true
|
||||||
|
squash-hierarchy: true
|
||||||
|
init-project: Community.Crypto Collection
|
||||||
|
init-copyright: Community.Crypto Contributors
|
||||||
|
init-title: Community.Crypto Collection Documentation
|
||||||
|
init-html-short-title: Community.Crypto Collection Docs
|
||||||
|
init-extra-html-theme-options: |
|
||||||
|
documentation_home_url=https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/branch/main/
|
||||||
|
render-file-line: '> * `$<status>` [$<path_tail>](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr/${{ github.event.number }}/$<path_tail>)'
|
||||||
|
|
||||||
|
publish-docs-gh-pages:
|
||||||
|
# for now we won't run this on forks
|
||||||
|
if: github.repository == 'ansible-collections/community.crypto'
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
pages: write
|
||||||
|
id-token: write
|
||||||
|
needs: [build-docs]
|
||||||
|
name: Publish Ansible Docs
|
||||||
|
uses: ansible-community/github-docs-build/.github/workflows/_shared-docs-build-publish-gh-pages.yml@main
|
||||||
|
with:
|
||||||
|
artifact-name: ${{ needs.build-docs.outputs.artifact-name }}
|
||||||
|
action: ${{ (github.event.action == 'closed' || needs.build-docs.outputs.changed != 'true') && 'teardown' || 'publish' }}
|
||||||
|
publish-gh-pages-branch: true
|
||||||
|
secrets:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
comment:
|
||||||
|
permissions:
|
||||||
|
pull-requests: write
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [build-docs, publish-docs-gh-pages]
|
||||||
|
name: PR comments
|
||||||
|
steps:
|
||||||
|
- name: PR comment
|
||||||
|
uses: ansible-community/github-docs-build/actions/ansible-docs-build-comment@main
|
||||||
|
with:
|
||||||
|
body-includes: '## Docs Build'
|
||||||
|
reactions: heart
|
||||||
|
action: ${{ needs.build-docs.outputs.changed != 'true' && 'remove' || '' }}
|
||||||
|
on-closed-body: |
|
||||||
|
## Docs Build 📝
|
||||||
|
|
||||||
|
This PR is closed and any previously published docsite has been unpublished.
|
||||||
|
on-merged-body: |
|
||||||
|
## Docs Build 📝
|
||||||
|
|
||||||
|
Thank you for contribution!✨
|
||||||
|
|
||||||
|
This PR has been merged and the docs are now incorporated into `main`:
|
||||||
|
${{ env.GHP_BASE_URL }}/branch/main
|
||||||
|
body: |
|
||||||
|
## Docs Build 📝
|
||||||
|
|
||||||
|
Thank you for contribution!✨
|
||||||
|
|
||||||
|
The docs for **this PR** have been published here:
|
||||||
|
${{ env.GHP_BASE_URL }}/pr/${{ github.event.number }}
|
||||||
|
|
||||||
|
You can compare to the docs for the `main` branch here:
|
||||||
|
${{ env.GHP_BASE_URL }}/branch/main
|
||||||
|
|
||||||
|
The docsite for **this PR** is also available for download as an artifact from this run:
|
||||||
|
${{ needs.build-docs.outputs.artifact-url }}
|
||||||
|
|
||||||
|
File changes:
|
||||||
|
|
||||||
|
${{ needs.build-docs.outputs.diff-files-rendered }}
|
||||||
|
|
||||||
|
${{ needs.build-docs.outputs.diff-rendered }}
|
||||||
56
.github/workflows/docs-push.yml
vendored
Normal file
56
.github/workflows/docs-push.yml
vendored
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
---
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
name: Collection Docs
|
||||||
|
concurrency:
|
||||||
|
group: docs-push-${{ github.sha }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
'on':
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- stable-*
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
# Run CI once per day (at 09:00 UTC)
|
||||||
|
schedule:
|
||||||
|
- cron: '0 9 * * *'
|
||||||
|
# Allow manual trigger (for newer antsibull-docs, sphinx-ansible-theme, ... versions)
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-docs:
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
name: Build Ansible Docs
|
||||||
|
uses: ansible-community/github-docs-build/.github/workflows/_shared-docs-build-push.yml@main
|
||||||
|
with:
|
||||||
|
ansible-ref: devel
|
||||||
|
collection-name: community.crypto
|
||||||
|
init-lenient: false
|
||||||
|
init-fail-on-error: true
|
||||||
|
squash-hierarchy: true
|
||||||
|
init-project: Community.Crypto Collection
|
||||||
|
init-copyright: Community.Crypto Contributors
|
||||||
|
init-title: Community.Crypto Collection Documentation
|
||||||
|
init-html-short-title: Community.Crypto Collection Docs
|
||||||
|
init-extra-html-theme-options: |
|
||||||
|
documentation_home_url=https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/branch/main/
|
||||||
|
|
||||||
|
publish-docs-gh-pages:
|
||||||
|
# for now we won't run this on forks
|
||||||
|
if: github.repository == 'ansible-collections/community.crypto'
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
pages: write
|
||||||
|
id-token: write
|
||||||
|
needs: [build-docs]
|
||||||
|
name: Publish Ansible Docs
|
||||||
|
uses: ansible-community/github-docs-build/.github/workflows/_shared-docs-build-publish-gh-pages.yml@main
|
||||||
|
with:
|
||||||
|
artifact-name: ${{ needs.build-docs.outputs.artifact-name }}
|
||||||
|
publish-gh-pages-branch: true
|
||||||
|
secrets:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
109
.github/workflows/ee.yml
vendored
109
.github/workflows/ee.yml
vendored
@@ -1,109 +0,0 @@
|
|||||||
---
|
|
||||||
name: execution environment
|
|
||||||
on:
|
|
||||||
# Run CI against all pushes (direct commits, also merged PRs), Pull Requests
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
- stable-*
|
|
||||||
pull_request:
|
|
||||||
# Run CI once per day (at 04:45 UTC)
|
|
||||||
# This ensures that even if there haven't been commits that we are still testing against latest version of ansible-builder
|
|
||||||
schedule:
|
|
||||||
- cron: '45 4 * * *'
|
|
||||||
|
|
||||||
env:
|
|
||||||
NAMESPACE: community
|
|
||||||
COLLECTION_NAME: crypto
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
name: Build and test EE (Ⓐ${{ matrix.runner_tag }})
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
runner_tag:
|
|
||||||
- devel
|
|
||||||
- stable-2.12-latest
|
|
||||||
- stable-2.11-latest
|
|
||||||
- stable-2.9-latest
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Check out code
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
path: ansible_collections/${{ env.NAMESPACE }}/${{ env.COLLECTION_NAME }}
|
|
||||||
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v3
|
|
||||||
with:
|
|
||||||
python-version: '3.10'
|
|
||||||
|
|
||||||
- name: Install ansible-builder and ansible-navigator
|
|
||||||
run: pip install ansible-builder ansible-navigator
|
|
||||||
|
|
||||||
- name: Verify requirements
|
|
||||||
run: ansible-builder introspect --sanitize .
|
|
||||||
|
|
||||||
- name: Make sure galaxy.yml has version entry
|
|
||||||
run: >-
|
|
||||||
python -c
|
|
||||||
'import yaml ;
|
|
||||||
f = open("galaxy.yml", "rb") ;
|
|
||||||
data = yaml.safe_load(f) ;
|
|
||||||
f.close() ;
|
|
||||||
data["version"] = data.get("version") or "0.0.1" ;
|
|
||||||
f = open("galaxy.yml", "wb") ;
|
|
||||||
f.write(yaml.dump(data).encode("utf-8")) ;
|
|
||||||
f.close() ;
|
|
||||||
'
|
|
||||||
working-directory: ansible_collections/${{ env.NAMESPACE }}/${{ env.COLLECTION_NAME }}
|
|
||||||
|
|
||||||
- name: Build collection
|
|
||||||
run: |
|
|
||||||
ansible-galaxy collection build --output-path ../../../
|
|
||||||
working-directory: ansible_collections/${{ env.NAMESPACE }}/${{ env.COLLECTION_NAME }}
|
|
||||||
|
|
||||||
- name: Create files for building execution environment
|
|
||||||
run: |
|
|
||||||
COLLECTION_FILENAME="$(ls "${{ env.NAMESPACE }}-${{ env.COLLECTION_NAME }}"-*.tar.gz)"
|
|
||||||
|
|
||||||
# EE config
|
|
||||||
cat > execution-environment.yml <<EOF
|
|
||||||
---
|
|
||||||
version: 1
|
|
||||||
build_arg_defaults:
|
|
||||||
EE_BASE_IMAGE: 'quay.io/ansible/ansible-runner:${{ matrix.runner_tag }}'
|
|
||||||
dependencies:
|
|
||||||
galaxy: requirements.yml
|
|
||||||
EOF
|
|
||||||
echo "::group::execution-environment.yml"
|
|
||||||
cat execution-environment.yml
|
|
||||||
echo "::endgroup::"
|
|
||||||
|
|
||||||
# Requirements
|
|
||||||
cat > requirements.yml <<EOF
|
|
||||||
---
|
|
||||||
collections:
|
|
||||||
- name: ${COLLECTION_FILENAME}
|
|
||||||
type: file
|
|
||||||
EOF
|
|
||||||
echo "::group::requirements.yml"
|
|
||||||
cat requirements.yml
|
|
||||||
echo "::endgroup::"
|
|
||||||
|
|
||||||
- name: Build image based on ${{ matrix.runner_tag }}
|
|
||||||
run: |
|
|
||||||
mkdir -p context/_build/
|
|
||||||
cp "${{ env.NAMESPACE }}-${{ env.COLLECTION_NAME }}"-*.tar.gz context/_build/
|
|
||||||
ansible-builder build -v 3 -t test-ee:latest --container-runtime=podman
|
|
||||||
|
|
||||||
- name: Run basic tests
|
|
||||||
run: >
|
|
||||||
ansible-navigator run
|
|
||||||
--mode stdout
|
|
||||||
--pull-policy never
|
|
||||||
--set-environment-variable ANSIBLE_PRIVATE_ROLE_VARS=true
|
|
||||||
--execution-environment-image test-ee:latest
|
|
||||||
-v
|
|
||||||
all.yml
|
|
||||||
working-directory: ansible_collections/${{ env.NAMESPACE }}/${{ env.COLLECTION_NAME }}/tests/ee
|
|
||||||
31
.github/workflows/nox.yml
vendored
Normal file
31
.github/workflows/nox.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
---
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
name: nox
|
||||||
|
'on':
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- stable-*
|
||||||
|
pull_request:
|
||||||
|
# Run CI once per day (at 09:00 UTC)
|
||||||
|
schedule:
|
||||||
|
- cron: '0 9 * * *'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
nox:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: "Run extra sanity tests"
|
||||||
|
steps:
|
||||||
|
- name: Check out collection
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Run nox
|
||||||
|
uses: ansible-community/antsibull-nox@main
|
||||||
|
|
||||||
|
ansible-test:
|
||||||
|
uses: ansible-community/antsibull-nox/.github/workflows/reusable-nox-matrix.yml@main
|
||||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,5 +1,10 @@
|
|||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
# Community.crypt specific things
|
# Community.crypt specific things
|
||||||
/changelogs/.plugin-cache.yaml
|
/changelogs/.plugin-cache.yaml
|
||||||
|
/tests/integration/inventory
|
||||||
|
|
||||||
|
|
||||||
# Created by https://www.gitignore.io/api/git,linux,pydev,python,windows,pycharm+all,jupyternotebook,vim,webstorm,emacs,dotenv
|
# Created by https://www.gitignore.io/api/git,linux,pydev,python,windows,pycharm+all,jupyternotebook,vim,webstorm,emacs,dotenv
|
||||||
|
|||||||
19
.mypy.ini
Normal file
19
.mypy.ini
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
[mypy]
|
||||||
|
check_untyped_defs = True
|
||||||
|
disallow_untyped_defs = True
|
||||||
|
|
||||||
|
# strict = True -- only try to enable once everything (including dependencies!) is typed
|
||||||
|
strict_equality = True
|
||||||
|
strict_bytes = True
|
||||||
|
|
||||||
|
warn_redundant_casts = True
|
||||||
|
# warn_return_any = True
|
||||||
|
warn_unreachable = True
|
||||||
|
|
||||||
|
[mypy-ansible.*]
|
||||||
|
# ansible-core has partial typing information
|
||||||
|
follow_untyped_imports = True
|
||||||
591
.pylintrc
Normal file
591
.pylintrc
Normal file
@@ -0,0 +1,591 @@
|
|||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
# SPDX-FileCopyrightText: 2025 Felix Fontein <felix@fontein.de>
|
||||||
|
|
||||||
|
[MAIN]
|
||||||
|
|
||||||
|
# Clear in-memory caches upon conclusion of linting. Useful if running pylint
|
||||||
|
# in a server-like mode.
|
||||||
|
clear-cache-post-run=no
|
||||||
|
|
||||||
|
# Load and enable all available extensions. Use --list-extensions to see a list
|
||||||
|
# all available extensions.
|
||||||
|
#enable-all-extensions=
|
||||||
|
|
||||||
|
# Specify a score threshold under which the program will exit with error.
|
||||||
|
fail-under=10
|
||||||
|
|
||||||
|
# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the
|
||||||
|
# number of processors available to use, and will cap the count on Windows to
|
||||||
|
# avoid hangs.
|
||||||
|
jobs=0
|
||||||
|
|
||||||
|
# Minimum Python version to use for version dependent checks. Will default to
|
||||||
|
# the version used to run pylint.
|
||||||
|
py-version=3.7
|
||||||
|
|
||||||
|
# Allow loading of arbitrary C extensions. Extensions are imported into the
|
||||||
|
# active Python interpreter and may run arbitrary code.
|
||||||
|
unsafe-load-any-extension=no
|
||||||
|
|
||||||
|
# In verbose mode, extra non-checker-related info will be displayed.
|
||||||
|
#verbose=
|
||||||
|
|
||||||
|
|
||||||
|
[BASIC]
|
||||||
|
|
||||||
|
# Naming style matching correct argument names.
|
||||||
|
argument-naming-style=snake_case
|
||||||
|
|
||||||
|
# Regular expression matching correct argument names. Overrides argument-
|
||||||
|
# naming-style. If left empty, argument names will be checked with the set
|
||||||
|
# naming style.
|
||||||
|
#argument-rgx=
|
||||||
|
|
||||||
|
# Naming style matching correct attribute names.
|
||||||
|
attr-naming-style=snake_case
|
||||||
|
|
||||||
|
# Regular expression matching correct attribute names. Overrides attr-naming-
|
||||||
|
# style. If left empty, attribute names will be checked with the set naming
|
||||||
|
# style.
|
||||||
|
#attr-rgx=
|
||||||
|
|
||||||
|
# Bad variable names which should always be refused, separated by a comma.
|
||||||
|
bad-names=foo,
|
||||||
|
bar,
|
||||||
|
baz,
|
||||||
|
toto,
|
||||||
|
tutu,
|
||||||
|
tata
|
||||||
|
|
||||||
|
# Bad variable names regexes, separated by a comma. If names match any regex,
|
||||||
|
# they will always be refused
|
||||||
|
bad-names-rgxs=
|
||||||
|
|
||||||
|
# Naming style matching correct class attribute names.
|
||||||
|
class-attribute-naming-style=any
|
||||||
|
|
||||||
|
# Regular expression matching correct class attribute names. Overrides class-
|
||||||
|
# attribute-naming-style. If left empty, class attribute names will be checked
|
||||||
|
# with the set naming style.
|
||||||
|
#class-attribute-rgx=
|
||||||
|
|
||||||
|
# Naming style matching correct class constant names.
|
||||||
|
class-const-naming-style=UPPER_CASE
|
||||||
|
|
||||||
|
# Regular expression matching correct class constant names. Overrides class-
|
||||||
|
# const-naming-style. If left empty, class constant names will be checked with
|
||||||
|
# the set naming style.
|
||||||
|
#class-const-rgx=
|
||||||
|
|
||||||
|
# Naming style matching correct class names.
|
||||||
|
class-naming-style=PascalCase
|
||||||
|
|
||||||
|
# Regular expression matching correct class names. Overrides class-naming-
|
||||||
|
# style. If left empty, class names will be checked with the set naming style.
|
||||||
|
#class-rgx=
|
||||||
|
|
||||||
|
# Naming style matching correct constant names.
|
||||||
|
const-naming-style=UPPER_CASE
|
||||||
|
|
||||||
|
# Regular expression matching correct constant names. Overrides const-naming-
|
||||||
|
# style. If left empty, constant names will be checked with the set naming
|
||||||
|
# style.
|
||||||
|
#const-rgx=
|
||||||
|
|
||||||
|
# Minimum line length for functions/classes that require docstrings, shorter
|
||||||
|
# ones are exempt.
|
||||||
|
docstring-min-length=-1
|
||||||
|
|
||||||
|
# Naming style matching correct function names.
|
||||||
|
function-naming-style=snake_case
|
||||||
|
|
||||||
|
# Regular expression matching correct function names. Overrides function-
|
||||||
|
# naming-style. If left empty, function names will be checked with the set
|
||||||
|
# naming style.
|
||||||
|
#function-rgx=
|
||||||
|
|
||||||
|
# Good variable names which should always be accepted, separated by a comma.
|
||||||
|
good-names=i,
|
||||||
|
j,
|
||||||
|
k,
|
||||||
|
ex,
|
||||||
|
Run,
|
||||||
|
_
|
||||||
|
|
||||||
|
# Good variable names regexes, separated by a comma. If names match any regex,
|
||||||
|
# they will always be accepted
|
||||||
|
good-names-rgxs=
|
||||||
|
|
||||||
|
# Include a hint for the correct naming format with invalid-name.
|
||||||
|
include-naming-hint=yes
|
||||||
|
|
||||||
|
# Naming style matching correct inline iteration names.
|
||||||
|
inlinevar-naming-style=any
|
||||||
|
|
||||||
|
# Regular expression matching correct inline iteration names. Overrides
|
||||||
|
# inlinevar-naming-style. If left empty, inline iteration names will be checked
|
||||||
|
# with the set naming style.
|
||||||
|
#inlinevar-rgx=
|
||||||
|
|
||||||
|
# Naming style matching correct method names.
|
||||||
|
method-naming-style=snake_case
|
||||||
|
|
||||||
|
# Regular expression matching correct method names. Overrides method-naming-
|
||||||
|
# style. If left empty, method names will be checked with the set naming style.
|
||||||
|
#method-rgx=
|
||||||
|
|
||||||
|
# Naming style matching correct module names.
|
||||||
|
module-naming-style=snake_case
|
||||||
|
|
||||||
|
# Regular expression matching correct module names. Overrides module-naming-
|
||||||
|
# style. If left empty, module names will be checked with the set naming style.
|
||||||
|
#module-rgx=
|
||||||
|
|
||||||
|
# Colon-delimited sets of names that determine each other's naming style when
|
||||||
|
# the name regexes allow several styles.
|
||||||
|
name-group=
|
||||||
|
|
||||||
|
# Regular expression which should only match function or class names that do
|
||||||
|
# not require a docstring.
|
||||||
|
no-docstring-rgx=^_
|
||||||
|
|
||||||
|
# List of decorators that produce properties, such as abc.abstractproperty. Add
|
||||||
|
# to this list to register other decorators that produce valid properties.
|
||||||
|
# These decorators are taken in consideration only for invalid-name.
|
||||||
|
property-classes=abc.abstractproperty
|
||||||
|
|
||||||
|
# Regular expression matching correct type alias names. If left empty, type
|
||||||
|
# alias names will be checked with the set naming style.
|
||||||
|
typealias-rgx = ^_{0,2}(?!T[A-Z]|Type)[A-Z]+[a-z0-9]+(?:[A-Z][a-z0-9]+)*T?$
|
||||||
|
|
||||||
|
# Regular expression matching correct type variable names. If left empty, type
|
||||||
|
# variable names will be checked with the set naming style.
|
||||||
|
#typevar-rgx=
|
||||||
|
|
||||||
|
# Naming style matching correct variable names.
|
||||||
|
variable-naming-style=snake_case
|
||||||
|
|
||||||
|
# Regular expression matching correct variable names. Overrides variable-
|
||||||
|
# naming-style. If left empty, variable names will be checked with the set
|
||||||
|
# naming style.
|
||||||
|
#variable-rgx=
|
||||||
|
|
||||||
|
|
||||||
|
[CLASSES]
|
||||||
|
|
||||||
|
# Warn about protected attribute access inside special methods
|
||||||
|
check-protected-access-in-special-methods=no
|
||||||
|
|
||||||
|
# List of method names used to declare (i.e. assign) instance attributes.
|
||||||
|
defining-attr-methods=__init__,
|
||||||
|
__new__,
|
||||||
|
setUp,
|
||||||
|
asyncSetUp,
|
||||||
|
__post_init__
|
||||||
|
|
||||||
|
# List of member names, which should be excluded from the protected access
|
||||||
|
# warning.
|
||||||
|
exclude-protected=_asdict,_fields,_replace,_source,_make,os._exit
|
||||||
|
|
||||||
|
# List of valid names for the first argument in a class method.
|
||||||
|
valid-classmethod-first-arg=cls
|
||||||
|
|
||||||
|
# List of valid names for the first argument in a metaclass class method.
|
||||||
|
valid-metaclass-classmethod-first-arg=mcs
|
||||||
|
|
||||||
|
|
||||||
|
[DESIGN]
|
||||||
|
|
||||||
|
# List of regular expressions of class ancestor names to ignore when counting
|
||||||
|
# public methods (see R0903)
|
||||||
|
exclude-too-few-public-methods=
|
||||||
|
|
||||||
|
# List of qualified class names to ignore when counting class parents (see
|
||||||
|
# R0901)
|
||||||
|
ignored-parents=
|
||||||
|
|
||||||
|
# Maximum number of arguments for function / method.
|
||||||
|
max-args=5
|
||||||
|
|
||||||
|
# Maximum number of attributes for a class (see R0902).
|
||||||
|
max-attributes=7
|
||||||
|
|
||||||
|
# Maximum number of boolean expressions in an if statement (see R0916).
|
||||||
|
max-bool-expr=5
|
||||||
|
|
||||||
|
# Maximum number of branch for function / method body.
|
||||||
|
max-branches=12
|
||||||
|
|
||||||
|
# Maximum number of locals for function / method body.
|
||||||
|
max-locals=15
|
||||||
|
|
||||||
|
# Maximum number of parents for a class (see R0901).
|
||||||
|
max-parents=7
|
||||||
|
|
||||||
|
# Maximum number of positional arguments for function / method.
|
||||||
|
max-positional-arguments=5
|
||||||
|
|
||||||
|
# Maximum number of public methods for a class (see R0904).
|
||||||
|
max-public-methods=20
|
||||||
|
|
||||||
|
# Maximum number of return / yield for function / method body.
|
||||||
|
max-returns=6
|
||||||
|
|
||||||
|
# Maximum number of statements in function / method body.
|
||||||
|
max-statements=50
|
||||||
|
|
||||||
|
# Minimum number of public methods for a class (see R0903).
|
||||||
|
min-public-methods=2
|
||||||
|
|
||||||
|
|
||||||
|
[EXCEPTIONS]
|
||||||
|
|
||||||
|
# Exceptions that will emit a warning when caught.
|
||||||
|
overgeneral-exceptions=builtins.BaseException,builtins.Exception
|
||||||
|
|
||||||
|
|
||||||
|
[FORMAT]
|
||||||
|
|
||||||
|
# Expected format of line ending, e.g. empty (any line ending), LF or CRLF.
|
||||||
|
expected-line-ending-format=
|
||||||
|
|
||||||
|
# Regexp for a line that is allowed to be longer than the limit.
|
||||||
|
ignore-long-lines=^\s*(# )?<?https?://\S+>?$
|
||||||
|
|
||||||
|
# Number of spaces of indent required inside a hanging or continued line.
|
||||||
|
indent-after-paren=4
|
||||||
|
|
||||||
|
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
|
||||||
|
# tab).
|
||||||
|
indent-string=' '
|
||||||
|
|
||||||
|
# Maximum number of characters on a single line.
|
||||||
|
max-line-length=160
|
||||||
|
|
||||||
|
# Maximum number of lines in a module.
|
||||||
|
max-module-lines=1000
|
||||||
|
|
||||||
|
# Allow the body of a class to be on the same line as the declaration if body
|
||||||
|
# contains single statement.
|
||||||
|
single-line-class-stmt=no
|
||||||
|
|
||||||
|
# Allow the body of an if to be on the same line as the test if there is no
|
||||||
|
# else.
|
||||||
|
single-line-if-stmt=no
|
||||||
|
|
||||||
|
|
||||||
|
[IMPORTS]
|
||||||
|
|
||||||
|
# List of modules that can be imported at any level, not just the top level
|
||||||
|
# one.
|
||||||
|
allow-any-import-level=
|
||||||
|
|
||||||
|
# Allow explicit reexports by alias from a package __init__.
|
||||||
|
allow-reexport-from-package=no
|
||||||
|
|
||||||
|
# Allow wildcard imports from modules that define __all__.
|
||||||
|
allow-wildcard-with-all=no
|
||||||
|
|
||||||
|
# Deprecated modules which should not be used, separated by a comma.
|
||||||
|
deprecated-modules=
|
||||||
|
|
||||||
|
# Output a graph (.gv or any supported image format) of external dependencies
|
||||||
|
# to the given file (report RP0402 must not be disabled).
|
||||||
|
ext-import-graph=
|
||||||
|
|
||||||
|
# Output a graph (.gv or any supported image format) of all (i.e. internal and
|
||||||
|
# external) dependencies to the given file (report RP0402 must not be
|
||||||
|
# disabled).
|
||||||
|
import-graph=
|
||||||
|
|
||||||
|
# Output a graph (.gv or any supported image format) of internal dependencies
|
||||||
|
# to the given file (report RP0402 must not be disabled).
|
||||||
|
int-import-graph=
|
||||||
|
|
||||||
|
# Force import order to recognize a module as part of the standard
|
||||||
|
# compatibility libraries.
|
||||||
|
known-standard-library=
|
||||||
|
|
||||||
|
# Force import order to recognize a module as part of a third party library.
|
||||||
|
known-third-party=enchant
|
||||||
|
|
||||||
|
# Couples of modules and preferred modules, separated by a comma.
|
||||||
|
preferred-modules=
|
||||||
|
|
||||||
|
|
||||||
|
[LOGGING]
|
||||||
|
|
||||||
|
# The type of string formatting that logging methods do. `old` means using %
|
||||||
|
# formatting, `new` is for `{}` formatting.
|
||||||
|
logging-format-style=old
|
||||||
|
|
||||||
|
# Logging modules to check that the string format arguments are in logging
|
||||||
|
# function parameter format.
|
||||||
|
logging-modules=logging
|
||||||
|
|
||||||
|
|
||||||
|
[MESSAGES CONTROL]
|
||||||
|
|
||||||
|
# Only show warnings with the listed confidence levels. Leave empty to show
|
||||||
|
# all. Valid levels: HIGH, CONTROL_FLOW, INFERENCE, INFERENCE_FAILURE,
|
||||||
|
# UNDEFINED.
|
||||||
|
confidence=HIGH,
|
||||||
|
CONTROL_FLOW,
|
||||||
|
INFERENCE,
|
||||||
|
INFERENCE_FAILURE,
|
||||||
|
UNDEFINED
|
||||||
|
|
||||||
|
# Disable the message, report, category or checker with the given id(s). You
|
||||||
|
# can either give multiple identifiers separated by comma (,) or put this
|
||||||
|
# option multiple times (only on the command line, not in the configuration
|
||||||
|
# file where it should appear only once). You can also use "--disable=all" to
|
||||||
|
# disable everything first and then re-enable specific checks. For example, if
|
||||||
|
# you want to run only the similarities checker, you can use "--disable=all
|
||||||
|
# --enable=similarities". If you want to run only the classes checker, but have
|
||||||
|
# no Warning level messages displayed, use "--disable=all --enable=classes
|
||||||
|
# --disable=W".
|
||||||
|
disable=raw-checker-failed,
|
||||||
|
bad-inline-option,
|
||||||
|
deprecated-pragma,
|
||||||
|
duplicate-code,
|
||||||
|
file-ignored,
|
||||||
|
import-outside-toplevel,
|
||||||
|
missing-class-docstring,
|
||||||
|
missing-function-docstring,
|
||||||
|
missing-module-docstring,
|
||||||
|
locally-disabled,
|
||||||
|
suppressed-message,
|
||||||
|
use-implicit-booleaness-not-comparison,
|
||||||
|
use-implicit-booleaness-not-comparison-to-string,
|
||||||
|
use-implicit-booleaness-not-comparison-to-zero,
|
||||||
|
superfluous-parens,
|
||||||
|
too-few-public-methods,
|
||||||
|
too-many-arguments,
|
||||||
|
too-many-boolean-expressions,
|
||||||
|
too-many-branches,
|
||||||
|
too-many-function-args,
|
||||||
|
too-many-instance-attributes,
|
||||||
|
too-many-lines,
|
||||||
|
too-many-locals,
|
||||||
|
too-many-nested-blocks,
|
||||||
|
too-many-positional-arguments,
|
||||||
|
too-many-return-statements,
|
||||||
|
too-many-statements,
|
||||||
|
ungrouped-imports,
|
||||||
|
useless-parent-delegation,
|
||||||
|
wrong-import-order,
|
||||||
|
wrong-import-position,
|
||||||
|
# To clean up:
|
||||||
|
broad-exception-caught,
|
||||||
|
broad-exception-raised,
|
||||||
|
fixme,
|
||||||
|
unused-argument,
|
||||||
|
# Cannot remove yet due to inadequacy of rules
|
||||||
|
inconsistent-return-statements, # doesn't notice that fail_json() does not return
|
||||||
|
|
||||||
|
# Enable the message, report, category or checker with the given id(s). You can
|
||||||
|
# either give multiple identifier separated by comma (,) or put this option
|
||||||
|
# multiple time (only on the command line, not in the configuration file where
|
||||||
|
# it should appear only once). See also the "--disable" option for examples.
|
||||||
|
enable=
|
||||||
|
|
||||||
|
|
||||||
|
[METHOD_ARGS]
|
||||||
|
|
||||||
|
# List of qualified names (i.e., library.method) which require a timeout
|
||||||
|
# parameter e.g. 'requests.api.get,requests.api.post'
|
||||||
|
timeout-methods=requests.api.delete,requests.api.get,requests.api.head,requests.api.options,requests.api.patch,requests.api.post,requests.api.put,requests.api.request
|
||||||
|
|
||||||
|
|
||||||
|
[MISCELLANEOUS]
|
||||||
|
|
||||||
|
# List of note tags to take in consideration, separated by a comma.
|
||||||
|
notes=FIXME,
|
||||||
|
XXX,
|
||||||
|
TODO
|
||||||
|
|
||||||
|
# Regular expression of note tags to take in consideration.
|
||||||
|
notes-rgx=
|
||||||
|
|
||||||
|
|
||||||
|
[REFACTORING]
|
||||||
|
|
||||||
|
# Maximum number of nested blocks for function / method body
|
||||||
|
max-nested-blocks=5
|
||||||
|
|
||||||
|
# Complete name of functions that never returns. When checking for
|
||||||
|
# inconsistent-return-statements if a never returning function is called then
|
||||||
|
# it will be considered as an explicit return statement and no message will be
|
||||||
|
# printed.
|
||||||
|
never-returning-functions=sys.exit,argparse.parse_error
|
||||||
|
|
||||||
|
# Let 'consider-using-join' be raised when the separator to join on would be
|
||||||
|
# non-empty (resulting in expected fixes of the type: ``"- " + " -
|
||||||
|
# ".join(items)``)
|
||||||
|
suggest-join-with-non-empty-separator=yes
|
||||||
|
|
||||||
|
|
||||||
|
[REPORTS]
|
||||||
|
|
||||||
|
# Python expression which should return a score less than or equal to 10. You
|
||||||
|
# have access to the variables 'fatal', 'error', 'warning', 'refactor',
|
||||||
|
# 'convention', and 'info' which contain the number of messages in each
|
||||||
|
# category, as well as 'statement' which is the total number of statements
|
||||||
|
# analyzed. This score is used by the global evaluation report (RP0004).
|
||||||
|
evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10))
|
||||||
|
|
||||||
|
# Template used to display messages. This is a python new-style format string
|
||||||
|
# used to format the message information. See doc for all details.
|
||||||
|
msg-template=
|
||||||
|
|
||||||
|
# Set the output format. Available formats are: text, parseable, colorized,
|
||||||
|
# json2 (improved json format), json (old json format) and msvs (visual
|
||||||
|
# studio). You can also give a reporter class, e.g.
|
||||||
|
# mypackage.mymodule.MyReporterClass.
|
||||||
|
#output-format=
|
||||||
|
|
||||||
|
# Tells whether to display a full report or only the messages.
|
||||||
|
reports=no
|
||||||
|
|
||||||
|
# Activate the evaluation score.
|
||||||
|
score=yes
|
||||||
|
|
||||||
|
|
||||||
|
[SIMILARITIES]
|
||||||
|
|
||||||
|
# Comments are removed from the similarity computation
|
||||||
|
ignore-comments=yes
|
||||||
|
|
||||||
|
# Docstrings are removed from the similarity computation
|
||||||
|
ignore-docstrings=yes
|
||||||
|
|
||||||
|
# Imports are removed from the similarity computation
|
||||||
|
ignore-imports=yes
|
||||||
|
|
||||||
|
# Signatures are removed from the similarity computation
|
||||||
|
ignore-signatures=yes
|
||||||
|
|
||||||
|
# Minimum lines number of a similarity.
|
||||||
|
min-similarity-lines=4
|
||||||
|
|
||||||
|
|
||||||
|
[SPELLING]
|
||||||
|
|
||||||
|
# Limits count of emitted suggestions for spelling mistakes.
|
||||||
|
max-spelling-suggestions=4
|
||||||
|
|
||||||
|
# Spelling dictionary name. No available dictionaries : You need to install
|
||||||
|
# both the python package and the system dependency for enchant to work.
|
||||||
|
spelling-dict=
|
||||||
|
|
||||||
|
# List of comma separated words that should be considered directives if they
|
||||||
|
# appear at the beginning of a comment and should not be checked.
|
||||||
|
spelling-ignore-comment-directives=fmt: on,fmt: off,noqa:,noqa,nosec,isort:skip,mypy:
|
||||||
|
|
||||||
|
# List of comma separated words that should not be checked.
|
||||||
|
spelling-ignore-words=
|
||||||
|
|
||||||
|
# A path to a file that contains the private dictionary; one word per line.
|
||||||
|
spelling-private-dict-file=
|
||||||
|
|
||||||
|
# Tells whether to store unknown words to the private dictionary (see the
|
||||||
|
# --spelling-private-dict-file option) instead of raising a message.
|
||||||
|
spelling-store-unknown-words=no
|
||||||
|
|
||||||
|
|
||||||
|
[STRING]
|
||||||
|
|
||||||
|
# This flag controls whether inconsistent-quotes generates a warning when the
|
||||||
|
# character used as a quote delimiter is used inconsistently within a module.
|
||||||
|
check-quote-consistency=no
|
||||||
|
|
||||||
|
# This flag controls whether the implicit-str-concat should generate a warning
|
||||||
|
# on implicit string concatenation in sequences defined over several lines.
|
||||||
|
check-str-concat-over-line-jumps=no
|
||||||
|
|
||||||
|
|
||||||
|
[TYPECHECK]
|
||||||
|
|
||||||
|
# List of decorators that produce context managers, such as
|
||||||
|
# contextlib.contextmanager. Add to this list to register other decorators that
|
||||||
|
# produce valid context managers.
|
||||||
|
contextmanager-decorators=contextlib.contextmanager
|
||||||
|
|
||||||
|
# List of members which are set dynamically and missed by pylint inference
|
||||||
|
# system, and so shouldn't trigger E1101 when accessed. Python regular
|
||||||
|
# expressions are accepted.
|
||||||
|
generated-members=
|
||||||
|
|
||||||
|
# Tells whether to warn about missing members when the owner of the attribute
|
||||||
|
# is inferred to be None.
|
||||||
|
ignore-none=yes
|
||||||
|
|
||||||
|
# This flag controls whether pylint should warn about no-member and similar
|
||||||
|
# checks whenever an opaque object is returned when inferring. The inference
|
||||||
|
# can return multiple potential results while evaluating a Python object, but
|
||||||
|
# some branches might not be evaluated, which results in partial inference. In
|
||||||
|
# that case, it might be useful to still emit no-member and other checks for
|
||||||
|
# the rest of the inferred objects.
|
||||||
|
ignore-on-opaque-inference=yes
|
||||||
|
|
||||||
|
# List of symbolic message names to ignore for Mixin members.
|
||||||
|
ignored-checks-for-mixins=no-member,
|
||||||
|
not-async-context-manager,
|
||||||
|
not-context-manager,
|
||||||
|
attribute-defined-outside-init
|
||||||
|
|
||||||
|
# List of class names for which member attributes should not be checked (useful
|
||||||
|
# for classes with dynamically set attributes). This supports the use of
|
||||||
|
# qualified names.
|
||||||
|
ignored-classes=optparse.Values,thread._local,_thread._local,argparse.Namespace
|
||||||
|
|
||||||
|
# Show a hint with possible names when a member name was not found. The aspect
|
||||||
|
# of finding the hint is based on edit distance.
|
||||||
|
missing-member-hint=yes
|
||||||
|
|
||||||
|
# The minimum edit distance a name should have in order to be considered a
|
||||||
|
# similar match for a missing member name.
|
||||||
|
missing-member-hint-distance=1
|
||||||
|
|
||||||
|
# The total number of similar names that should be taken in consideration when
|
||||||
|
# showing a hint for a missing member.
|
||||||
|
missing-member-max-choices=1
|
||||||
|
|
||||||
|
# Regex pattern to define which classes are considered mixins.
|
||||||
|
mixin-class-rgx=.*[Mm]ixin
|
||||||
|
|
||||||
|
# List of decorators that change the signature of a decorated function.
|
||||||
|
signature-mutators=
|
||||||
|
|
||||||
|
|
||||||
|
[VARIABLES]
|
||||||
|
|
||||||
|
# List of additional names supposed to be defined in builtins. Remember that
|
||||||
|
# you should avoid defining new builtins when possible.
|
||||||
|
additional-builtins=
|
||||||
|
|
||||||
|
# Tells whether unused global variables should be treated as a violation.
|
||||||
|
allow-global-unused-variables=yes
|
||||||
|
|
||||||
|
# List of names allowed to shadow builtins
|
||||||
|
allowed-redefined-builtins=
|
||||||
|
|
||||||
|
# List of strings which can identify a callback function by name. A callback
|
||||||
|
# name must start or end with one of those strings.
|
||||||
|
callbacks=cb_,
|
||||||
|
_cb
|
||||||
|
|
||||||
|
# A regular expression matching the name of dummy variables (i.e. expected to
|
||||||
|
# not be used).
|
||||||
|
dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_
|
||||||
|
|
||||||
|
# Argument names that match this expression will be ignored.
|
||||||
|
ignored-argument-names=_.*|^ignored_|^unused_
|
||||||
|
|
||||||
|
# Tells whether we should check for unused import in __init__ files.
|
||||||
|
init-import=no
|
||||||
|
|
||||||
|
# List of qualified module names which can have objects that can redefine
|
||||||
|
# builtins.
|
||||||
|
redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io
|
||||||
53
.yamllint
Normal file
53
.yamllint
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
---
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
# SPDX-FileCopyrightText: 2025 Felix Fontein <felix@fontein.de>
|
||||||
|
|
||||||
|
extends: default
|
||||||
|
|
||||||
|
ignore: |
|
||||||
|
/changelogs/
|
||||||
|
|
||||||
|
rules:
|
||||||
|
line-length:
|
||||||
|
max: 300
|
||||||
|
level: error
|
||||||
|
document-start:
|
||||||
|
present: true
|
||||||
|
document-end: false
|
||||||
|
truthy:
|
||||||
|
level: error
|
||||||
|
allowed-values:
|
||||||
|
- 'true'
|
||||||
|
- 'false'
|
||||||
|
indentation:
|
||||||
|
spaces: 2
|
||||||
|
indent-sequences: true
|
||||||
|
key-duplicates: enable
|
||||||
|
trailing-spaces: enable
|
||||||
|
new-line-at-end-of-file: disable
|
||||||
|
hyphens:
|
||||||
|
max-spaces-after: 1
|
||||||
|
empty-lines:
|
||||||
|
max: 2
|
||||||
|
max-start: 0
|
||||||
|
max-end: 0
|
||||||
|
commas:
|
||||||
|
max-spaces-before: 0
|
||||||
|
min-spaces-after: 1
|
||||||
|
max-spaces-after: 1
|
||||||
|
colons:
|
||||||
|
max-spaces-before: 0
|
||||||
|
max-spaces-after: 1
|
||||||
|
brackets:
|
||||||
|
min-spaces-inside: 0
|
||||||
|
max-spaces-inside: 0
|
||||||
|
braces:
|
||||||
|
min-spaces-inside: 0
|
||||||
|
max-spaces-inside: 1
|
||||||
|
octal-values:
|
||||||
|
forbid-implicit-octal: true
|
||||||
|
forbid-explicit-octal: true
|
||||||
|
comments:
|
||||||
|
min-spaces-from-content: 1
|
||||||
|
comments-indentation: false
|
||||||
54
.yamllint-docs
Normal file
54
.yamllint-docs
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
---
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
# SPDX-FileCopyrightText: 2025 Felix Fontein <felix@fontein.de>
|
||||||
|
|
||||||
|
extends: default
|
||||||
|
|
||||||
|
ignore: |
|
||||||
|
/changelogs/
|
||||||
|
|
||||||
|
rules:
|
||||||
|
line-length:
|
||||||
|
max: 160
|
||||||
|
level: error
|
||||||
|
document-start:
|
||||||
|
present: false
|
||||||
|
document-end:
|
||||||
|
present: false
|
||||||
|
truthy:
|
||||||
|
level: error
|
||||||
|
allowed-values:
|
||||||
|
- 'true'
|
||||||
|
- 'false'
|
||||||
|
indentation:
|
||||||
|
spaces: 2
|
||||||
|
indent-sequences: true
|
||||||
|
key-duplicates: enable
|
||||||
|
trailing-spaces: enable
|
||||||
|
new-line-at-end-of-file: disable
|
||||||
|
hyphens:
|
||||||
|
max-spaces-after: 1
|
||||||
|
empty-lines:
|
||||||
|
max: 2
|
||||||
|
max-start: 0
|
||||||
|
max-end: 0
|
||||||
|
commas:
|
||||||
|
max-spaces-before: 0
|
||||||
|
min-spaces-after: 1
|
||||||
|
max-spaces-after: 1
|
||||||
|
colons:
|
||||||
|
max-spaces-before: 0
|
||||||
|
max-spaces-after: 1
|
||||||
|
brackets:
|
||||||
|
min-spaces-inside: 0
|
||||||
|
max-spaces-inside: 0
|
||||||
|
braces:
|
||||||
|
min-spaces-inside: 0
|
||||||
|
max-spaces-inside: 1
|
||||||
|
octal-values:
|
||||||
|
forbid-implicit-octal: true
|
||||||
|
forbid-explicit-octal: true
|
||||||
|
comments:
|
||||||
|
min-spaces-from-content: 1
|
||||||
|
comments-indentation: false
|
||||||
54
.yamllint-examples
Normal file
54
.yamllint-examples
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
---
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
# SPDX-FileCopyrightText: 2025 Felix Fontein <felix@fontein.de>
|
||||||
|
|
||||||
|
extends: default
|
||||||
|
|
||||||
|
ignore: |
|
||||||
|
/changelogs/
|
||||||
|
|
||||||
|
rules:
|
||||||
|
line-length:
|
||||||
|
max: 160
|
||||||
|
level: error
|
||||||
|
document-start:
|
||||||
|
present: true
|
||||||
|
document-end:
|
||||||
|
present: false
|
||||||
|
truthy:
|
||||||
|
level: error
|
||||||
|
allowed-values:
|
||||||
|
- 'true'
|
||||||
|
- 'false'
|
||||||
|
indentation:
|
||||||
|
spaces: 2
|
||||||
|
indent-sequences: true
|
||||||
|
key-duplicates: enable
|
||||||
|
trailing-spaces: enable
|
||||||
|
new-line-at-end-of-file: disable
|
||||||
|
hyphens:
|
||||||
|
max-spaces-after: 1
|
||||||
|
empty-lines:
|
||||||
|
max: 2
|
||||||
|
max-start: 0
|
||||||
|
max-end: 0
|
||||||
|
commas:
|
||||||
|
max-spaces-before: 0
|
||||||
|
min-spaces-after: 1
|
||||||
|
max-spaces-after: 1
|
||||||
|
colons:
|
||||||
|
max-spaces-before: 0
|
||||||
|
max-spaces-after: 1
|
||||||
|
brackets:
|
||||||
|
min-spaces-inside: 0
|
||||||
|
max-spaces-inside: 0
|
||||||
|
braces:
|
||||||
|
min-spaces-inside: 0
|
||||||
|
max-spaces-inside: 1
|
||||||
|
octal-values:
|
||||||
|
forbid-implicit-octal: true
|
||||||
|
forbid-explicit-octal: true
|
||||||
|
comments:
|
||||||
|
min-spaces-from-content: 1
|
||||||
|
comments-indentation: false
|
||||||
53
.yamllint-extra-docs
Normal file
53
.yamllint-extra-docs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
---
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
# SPDX-FileCopyrightText: 2025 Felix Fontein <felix@fontein.de>
|
||||||
|
|
||||||
|
extends: default
|
||||||
|
|
||||||
|
ignore: |
|
||||||
|
/changelogs/
|
||||||
|
|
||||||
|
rules:
|
||||||
|
line-length:
|
||||||
|
max: 160
|
||||||
|
level: error
|
||||||
|
document-start: disable
|
||||||
|
document-end:
|
||||||
|
present: false
|
||||||
|
truthy:
|
||||||
|
level: error
|
||||||
|
allowed-values:
|
||||||
|
- 'true'
|
||||||
|
- 'false'
|
||||||
|
indentation:
|
||||||
|
spaces: 2
|
||||||
|
indent-sequences: true
|
||||||
|
key-duplicates: enable
|
||||||
|
trailing-spaces: enable
|
||||||
|
new-line-at-end-of-file: disable
|
||||||
|
hyphens:
|
||||||
|
max-spaces-after: 1
|
||||||
|
empty-lines:
|
||||||
|
max: 2
|
||||||
|
max-start: 0
|
||||||
|
max-end: 0
|
||||||
|
commas:
|
||||||
|
max-spaces-before: 0
|
||||||
|
min-spaces-after: 1
|
||||||
|
max-spaces-after: 1
|
||||||
|
colons:
|
||||||
|
max-spaces-before: 0
|
||||||
|
max-spaces-after: 1
|
||||||
|
brackets:
|
||||||
|
min-spaces-inside: 0
|
||||||
|
max-spaces-inside: 0
|
||||||
|
braces:
|
||||||
|
min-spaces-inside: 0
|
||||||
|
max-spaces-inside: 1
|
||||||
|
octal-values:
|
||||||
|
forbid-implicit-octal: true
|
||||||
|
forbid-explicit-octal: true
|
||||||
|
comments:
|
||||||
|
min-spaces-from-content: 1
|
||||||
|
comments-indentation: false
|
||||||
1899
CHANGELOG.md
Normal file
1899
CHANGELOG.md
Normal file
File diff suppressed because it is too large
Load Diff
3
CHANGELOG.md.license
Normal file
3
CHANGELOG.md.license
Normal file
@@ -0,0 +1,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)
|
||||||
|
SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
SPDX-FileCopyrightText: Ansible Project
|
||||||
983
CHANGELOG.rst
983
CHANGELOG.rst
File diff suppressed because it is too large
Load Diff
3
CHANGELOG.rst.license
Normal file
3
CHANGELOG.rst.license
Normal file
@@ -0,0 +1,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)
|
||||||
|
SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
SPDX-FileCopyrightText: Ansible Project
|
||||||
202
LICENSES/Apache-2.0.txt
Normal file
202
LICENSES/Apache-2.0.txt
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
https://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
27
LICENSES/BSD-3-Clause.txt
Normal file
27
LICENSES/BSD-3-Clause.txt
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
Copyright (c) Individual contributors.
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
3. Neither the name of PyCA Cryptography nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this software
|
||||||
|
without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
1
LICENSES/GPL-3.0-or-later.txt
Symbolic link
1
LICENSES/GPL-3.0-or-later.txt
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../COPYING
|
||||||
92
README.md
92
README.md
@@ -1,7 +1,16 @@
|
|||||||
|
<!--
|
||||||
|
Copyright (c) Ansible Project
|
||||||
|
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
-->
|
||||||
|
|
||||||
# Ansible Community Crypto Collection
|
# Ansible Community Crypto Collection
|
||||||
|
|
||||||
|
[](https://docs.ansible.com/ansible/devel/collections/community/crypto/)
|
||||||
[](https://dev.azure.com/ansible/community.crypto/_build?definitionId=21)
|
[](https://dev.azure.com/ansible/community.crypto/_build?definitionId=21)
|
||||||
|
[](https://github.com/ansible-collections/community.crypto/actions)
|
||||||
[](https://codecov.io/gh/ansible-collections/community.crypto)
|
[](https://codecov.io/gh/ansible-collections/community.crypto)
|
||||||
|
[](https://api.reuse.software/info/github.com/ansible-collections/community.crypto)
|
||||||
|
|
||||||
Provides modules for [Ansible](https://www.ansible.com/community) for various cryptographic operations.
|
Provides modules for [Ansible](https://www.ansible.com/community) for various cryptographic operations.
|
||||||
|
|
||||||
@@ -9,51 +18,44 @@ You can find [documentation for this collection on the Ansible docs site](https:
|
|||||||
|
|
||||||
Please note that this collection does **not** support Windows targets.
|
Please note that this collection does **not** support Windows targets.
|
||||||
|
|
||||||
|
## Code of Conduct
|
||||||
|
|
||||||
|
We follow [Ansible Code of Conduct](https://docs.ansible.com/ansible/latest/community/code_of_conduct.html) in all our interactions within this project.
|
||||||
|
|
||||||
|
If you encounter abusive behavior violating the [Ansible Code of Conduct](https://docs.ansible.com/ansible/latest/community/code_of_conduct.html), please refer to the [policy violations](https://docs.ansible.com/ansible/latest/community/code_of_conduct.html#policy-violations) section of the Code of Conduct for information on how to raise a complaint.
|
||||||
|
|
||||||
|
## Communication
|
||||||
|
|
||||||
|
* Join the Ansible forum:
|
||||||
|
* [Get Help](https://forum.ansible.com/c/help/6): get help or help others. Please add appropriate tags if you start new discussions, for example the `crypto` or `acme` tags.
|
||||||
|
* [Posts tagged with 'crypto'](https://forum.ansible.com/tag/crypto): subscribe to participate in cryptography related conversations.
|
||||||
|
* [Posts tagged with 'acme'](https://forum.ansible.com/tag/acme): subscribe to participate in ACME (RFC 8555) related conversations.
|
||||||
|
* [Social Spaces](https://forum.ansible.com/c/chat/4): gather and interact with fellow enthusiasts.
|
||||||
|
* [News & Announcements](https://forum.ansible.com/c/news/5): track project-wide announcements including social events.
|
||||||
|
|
||||||
|
* The Ansible [Bullhorn newsletter](https://docs.ansible.com/ansible/devel/community/communication.html#the-bullhorn): used to announce releases and important changes.
|
||||||
|
|
||||||
|
For more information about communication, see the [Ansible communication guide](https://docs.ansible.com/ansible/devel/community/communication.html).
|
||||||
|
|
||||||
## Tested with Ansible
|
## Tested with Ansible
|
||||||
|
|
||||||
Tested with the current Ansible 2.9, ansible-base 2.10, ansible-core 2.11, ansible-core 2.12 and ansible-core 2.13 releases and the current development version of ansible-core. Ansible versions before 2.9.10 are not supported.
|
Tested with the current ansible-core-2.17, ansible-core 2.18, ansible-core 2.19, ansible-core 2.20, ansible-core 2.21 releases and the current development version of ansible-core. Ansible-core versions before 2.17 are not supported; please use community.crypto 2.x.y with these.
|
||||||
|
|
||||||
## External requirements
|
## External requirements
|
||||||
|
|
||||||
The exact requirements for every module are listed in the module documentation.
|
The exact requirements for every module are listed in the module documentation.
|
||||||
|
|
||||||
Most modules require a recent enough version of [the Python cryptography library](https://pypi.org/project/cryptography/). See the module documentations for the minimal version supported for each module.
|
Most modules require a recent enough version of [the Python cryptography library](https://pypi.org/project/cryptography/); the minimum supported version by this collection is 3.3. See the module documentations for the minimal version supported for each module.
|
||||||
|
|
||||||
## Included content
|
## Collection Documentation
|
||||||
|
|
||||||
- OpenSSL / PKI modules:
|
Browsing the [**latest** collection documentation](https://docs.ansible.com/ansible/latest/collections/community/crypto) will show docs for the _latest version released in the Ansible package_, not the latest version of the collection released on Galaxy.
|
||||||
- openssl_csr_info
|
|
||||||
- openssl_csr
|
|
||||||
- openssl_dhparam
|
|
||||||
- openssl_pkcs12
|
|
||||||
- openssl_privatekey_info
|
|
||||||
- openssl_privatekey
|
|
||||||
- openssl_publickey
|
|
||||||
- openssl_signature_info
|
|
||||||
- openssl_signature
|
|
||||||
- x509_certificate_info
|
|
||||||
- x509_certificate
|
|
||||||
- x509_crl_info
|
|
||||||
- x509_crl
|
|
||||||
- certificate_complete_chain
|
|
||||||
- OpenSSH modules:
|
|
||||||
- openssh_cert
|
|
||||||
- openssh_keypair
|
|
||||||
- ACME modules:
|
|
||||||
- acme_account_info
|
|
||||||
- acme_account
|
|
||||||
- acme_certificate
|
|
||||||
- acme_certificate_revoke
|
|
||||||
- acme_challenge_cert_helper
|
|
||||||
- acme_inspect
|
|
||||||
- ECS modules:
|
|
||||||
- ecs_certificate
|
|
||||||
- ecs_domain
|
|
||||||
- Miscellaneous modules:
|
|
||||||
- get_certificate
|
|
||||||
- luks_device
|
|
||||||
|
|
||||||
You can also find a list of all modules with documentation on the [Ansible docs site](https://docs.ansible.com/ansible/latest/collections/community/crypto/).
|
Browsing the [**devel** collection documentation](https://docs.ansible.com/ansible/devel/collections/community/crypto) shows docs for the _latest version released on Galaxy_.
|
||||||
|
|
||||||
|
We also separately publish [**latest commit** collection documentation](https://ansible-collections.github.io/community.crypto/branch/main/) which shows docs for the _latest commit in the `main` branch_.
|
||||||
|
|
||||||
|
If you use the Ansible package and do not update collections independently, use **latest**. If you install or update this collection directly from Galaxy, use **devel**. If you are looking to contribute, use **latest commit**.
|
||||||
|
|
||||||
## Using this collection
|
## Using this collection
|
||||||
|
|
||||||
@@ -85,20 +87,12 @@ See [Ansible's dev guide](https://docs.ansible.com/ansible/devel/dev_guide/devel
|
|||||||
|
|
||||||
## Release notes
|
## Release notes
|
||||||
|
|
||||||
See the [changelog](https://github.com/ansible-collections/community.crypto/blob/main/CHANGELOG.rst).
|
See the [changelog](https://github.com/ansible-collections/community.crypto/blob/main/CHANGELOG.md).
|
||||||
|
|
||||||
## Roadmap
|
## Roadmap
|
||||||
|
|
||||||
We plan to regularly release minor and patch versions, whenever new features are added or bugs fixed. Our collection follows [semantic versioning](https://semver.org/), so breaking changes will only happen in major releases.
|
We plan to regularly release minor and patch versions, whenever new features are added or bugs fixed. Our collection follows [semantic versioning](https://semver.org/), so breaking changes will only happen in major releases.
|
||||||
|
|
||||||
Most modules will drop PyOpenSSL support in version 2.0.0 of the collection, i.e. in the next major version. We currently plan to release 2.0.0 somewhen during 2021. Around then, the supported versions of the most common distributions will contain a new enough version of ``cryptography``.
|
|
||||||
|
|
||||||
Once 2.0.0 has been released, bugfixes will still be backported to 1.0.0 for some time, and some features might also be backported. If we do not want to backport something ourselves because we think it is not worth the effort, backport PRs by non-maintainers are usually accepted.
|
|
||||||
|
|
||||||
In 2.0.0, the following notable features will be removed:
|
|
||||||
* PyOpenSSL backends of all modules, except ``openssl_pkcs12`` which does not have a ``cryptography`` backend due to lack of support of PKCS#12 functionality in ``cryptography``.
|
|
||||||
* The ``assertonly`` provider of ``x509_certificate`` will be removed.
|
|
||||||
|
|
||||||
## More information
|
## More information
|
||||||
|
|
||||||
- [Ansible Collection overview](https://github.com/ansible-collections/overview)
|
- [Ansible Collection overview](https://github.com/ansible-collections/overview)
|
||||||
@@ -108,6 +102,10 @@ In 2.0.0, the following notable features will be removed:
|
|||||||
|
|
||||||
## Licensing
|
## Licensing
|
||||||
|
|
||||||
GNU General Public License v3.0 or later.
|
This collection is primarily licensed and distributed as a whole under the GNU General Public License v3.0 or later.
|
||||||
|
|
||||||
See [COPYING](https://www.gnu.org/licenses/gpl-3.0.txt) to see the full text.
|
See [LICENSES/GPL-3.0-or-later.txt](https://github.com/ansible-collections/community.crypto/blob/main/COPYING) for the full text.
|
||||||
|
|
||||||
|
Parts of the collection are licensed under the [Apache 2.0 license](https://github.com/ansible-collections/community.crypto/blob/main/LICENSES/Apache-2.0.txt) (`plugins/module_utils/_crypto/_obj2txt.py` and `plugins/module_utils/_crypto/_objects_data.py`) and the [BSD 3-Clause license](https://github.com/ansible-collections/community.crypto/blob/main/LICENSES/BSD-3-Clause.txt) (`plugins/module_utils/_crypto/_obj2txt.py`). This only applies to vendored files in ``plugins/module_utils/``.
|
||||||
|
|
||||||
|
All files have a machine readable `SDPX-License-Identifier:` comment denoting its respective license(s) or an equivalent entry in an accompanying `.license` file. Only changelog fragments (which will not be part of a release) are covered by a blanket statement in `REUSE.toml`. This conforms to the [REUSE specification](https://reuse.software/spec/).
|
||||||
|
|||||||
11
REUSE.toml
Normal file
11
REUSE.toml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
version = 1
|
||||||
|
|
||||||
|
[[annotations]]
|
||||||
|
path = "changelogs/fragments/**"
|
||||||
|
precedence = "aggregate"
|
||||||
|
SPDX-FileCopyrightText = "Ansible Project"
|
||||||
|
SPDX-License-Identifier = "GPL-3.0-or-later"
|
||||||
127
antsibull-nox.toml
Normal file
127
antsibull-nox.toml
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
# SPDX-FileCopyrightText: 2025 Felix Fontein <felix@fontein.de>
|
||||||
|
|
||||||
|
[collection_sources]
|
||||||
|
"community.general" = "git+https://github.com/ansible-collections/community.general.git,main"
|
||||||
|
"community.internal_test_tools" = "git+https://github.com/ansible-collections/community.internal_test_tools.git,main"
|
||||||
|
|
||||||
|
[vcs]
|
||||||
|
vcs = "git"
|
||||||
|
development_branch = "main"
|
||||||
|
stable_branches = [ "stable-*" ]
|
||||||
|
|
||||||
|
[sessions]
|
||||||
|
|
||||||
|
[sessions.lint]
|
||||||
|
run_isort = false
|
||||||
|
run_black = true
|
||||||
|
run_ruff_autofix = true
|
||||||
|
ruff_autofix_config = "ruff.toml"
|
||||||
|
ruff_autofix_select = [
|
||||||
|
"I",
|
||||||
|
"RUF022",
|
||||||
|
]
|
||||||
|
run_ruff_check = true
|
||||||
|
ruff_check_config = "ruff.toml"
|
||||||
|
run_flake8 = true
|
||||||
|
flake8_config = ".flake8"
|
||||||
|
run_pylint = true
|
||||||
|
pylint_rcfile = ".pylintrc"
|
||||||
|
pylint_ansible_core_package = "ansible-core>=2.19.0"
|
||||||
|
run_yamllint = true
|
||||||
|
yamllint_config = ".yamllint"
|
||||||
|
yamllint_config_plugins = ".yamllint-docs"
|
||||||
|
yamllint_config_plugins_examples = ".yamllint-examples"
|
||||||
|
yamllint_config_extra_docs = ".yamllint-extra-docs"
|
||||||
|
run_mypy = true
|
||||||
|
mypy_ansible_core_package = "ansible-core>=2.19.0"
|
||||||
|
mypy_config = ".mypy.ini"
|
||||||
|
mypy_extra_deps = [
|
||||||
|
"cryptography",
|
||||||
|
"types-mock",
|
||||||
|
"types-PyYAML",
|
||||||
|
]
|
||||||
|
|
||||||
|
[sessions.docs_check]
|
||||||
|
validate_collection_refs="all"
|
||||||
|
codeblocks_restrict_types = [
|
||||||
|
"ansible-output",
|
||||||
|
"yaml",
|
||||||
|
"yaml+jinja",
|
||||||
|
]
|
||||||
|
codeblocks_restrict_type_exact_case = true
|
||||||
|
codeblocks_allow_without_type = false
|
||||||
|
codeblocks_allow_literal_blocks = false
|
||||||
|
|
||||||
|
[sessions.license_check]
|
||||||
|
run_reuse = true
|
||||||
|
|
||||||
|
[sessions.extra_checks]
|
||||||
|
run_no_unwanted_files = true
|
||||||
|
no_unwanted_files_module_extensions = [".py"]
|
||||||
|
no_unwanted_files_yaml_extensions = [".yml"]
|
||||||
|
run_action_groups = true
|
||||||
|
run_no_trailing_whitespace = true
|
||||||
|
no_trailing_whitespace_skip_paths = [
|
||||||
|
"tests/integration/targets/luks_device/files/keyfile3",
|
||||||
|
]
|
||||||
|
no_trailing_whitespace_skip_directories = [
|
||||||
|
"tests/unit/plugins/module_utils/_acme/fixtures/",
|
||||||
|
]
|
||||||
|
run_avoid_characters = true
|
||||||
|
|
||||||
|
[[sessions.extra_checks.action_groups_config]]
|
||||||
|
name = "acme"
|
||||||
|
pattern = "^acme_.*$"
|
||||||
|
exclusions = [
|
||||||
|
"acme_ari_info", # does not support ACME account
|
||||||
|
"acme_certificate_renewal_info", # does not support ACME account
|
||||||
|
"acme_challenge_cert_helper", # does not support (and need) any common parameters
|
||||||
|
]
|
||||||
|
doc_fragment = "community.crypto._attributes.actiongroup_acme"
|
||||||
|
|
||||||
|
[[sessions.extra_checks.avoid_character_group]]
|
||||||
|
name = "tab"
|
||||||
|
regex = "\\x09"
|
||||||
|
skip_paths = [
|
||||||
|
"tests/integration/targets/luks_device/files/keyfile3",
|
||||||
|
]
|
||||||
|
|
||||||
|
[sessions.build_import_check]
|
||||||
|
run_galaxy_importer = true
|
||||||
|
|
||||||
|
[sessions.ansible_lint]
|
||||||
|
|
||||||
|
[[sessions.ee_check.execution_environments]]
|
||||||
|
name = "devel-ubi-9"
|
||||||
|
description = "ansible-core devel @ RHEL UBI 9"
|
||||||
|
test_playbooks = ["tests/ee/all.yml"]
|
||||||
|
config.images.base_image.name = "docker.io/redhat/ubi9:latest"
|
||||||
|
config.dependencies.ansible_core.package_pip = "https://github.com/ansible/ansible/archive/devel.tar.gz"
|
||||||
|
config.dependencies.ansible_runner.package_pip = "ansible-runner"
|
||||||
|
config.dependencies.python_interpreter.package_system = "python3.12 python3.12-pip python3.12-wheel python3.12-cryptography"
|
||||||
|
config.dependencies.python_interpreter.python_path = "/usr/bin/python3.12"
|
||||||
|
runtime_environment = {"ANSIBLE_PRIVATE_ROLE_VARS" = "true"}
|
||||||
|
|
||||||
|
[[sessions.ee_check.execution_environments]]
|
||||||
|
name = "2.17-rocky-9"
|
||||||
|
description = "ansible-core 2.17 @ Rocky Linux 9"
|
||||||
|
test_playbooks = ["tests/ee/all.yml"]
|
||||||
|
config.images.base_image.name = "quay.io/rockylinux/rockylinux:9"
|
||||||
|
config.dependencies.ansible_core.package_pip = "https://github.com/ansible/ansible/archive/stable-2.17.tar.gz"
|
||||||
|
config.dependencies.ansible_runner.package_pip = "ansible-runner"
|
||||||
|
config.dependencies.python_interpreter.package_system = "python3.11 python3.11-pip python3.11-wheel python3.11-cryptography"
|
||||||
|
config.dependencies.python_interpreter.python_path = "/usr/bin/python3.11"
|
||||||
|
runtime_environment = {"ANSIBLE_PRIVATE_ROLE_VARS" = "true"}
|
||||||
|
|
||||||
|
[[sessions.ee_check.execution_environments]]
|
||||||
|
name = "2.18-centos-stream-9"
|
||||||
|
description = "ansible-core 2.18 @ CentOS Stream 9"
|
||||||
|
test_playbooks = ["tests/ee/all.yml"]
|
||||||
|
config.images.base_image.name = "quay.io/centos/centos:stream9"
|
||||||
|
config.dependencies.ansible_core.package_pip = "https://github.com/ansible/ansible/archive/stable-2.18.tar.gz"
|
||||||
|
config.dependencies.ansible_runner.package_pip = "ansible-runner"
|
||||||
|
config.dependencies.python_interpreter.package_system = "python3.11 python3.11-pip python3.11-wheel python3.11-cryptography"
|
||||||
|
config.dependencies.python_interpreter.python_path = "/usr/bin/python3.11"
|
||||||
|
runtime_environment = {"ANSIBLE_PRIVATE_ROLE_VARS" = "true"}
|
||||||
File diff suppressed because it is too large
Load Diff
3
changelogs/changelog.yaml.license
Normal file
3
changelogs/changelog.yaml.license
Normal file
@@ -0,0 +1,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)
|
||||||
|
SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
SPDX-FileCopyrightText: Ansible Project
|
||||||
@@ -1,28 +1,43 @@
|
|||||||
|
---
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
changelog_filename_template: ../CHANGELOG.rst
|
changelog_filename_template: ../CHANGELOG.rst
|
||||||
changelog_filename_version_depth: 0
|
changelog_filename_version_depth: 0
|
||||||
changes_file: changelog.yaml
|
changes_file: changelog.yaml
|
||||||
changes_format: combined
|
changes_format: combined
|
||||||
|
ignore_other_fragment_extensions: true
|
||||||
keep_fragments: false
|
keep_fragments: false
|
||||||
mention_ancestor: true
|
mention_ancestor: true
|
||||||
new_plugins_after_name: removed_features
|
new_plugins_after_name: removed_features
|
||||||
notesdir: fragments
|
notesdir: fragments
|
||||||
|
output_formats:
|
||||||
|
- md
|
||||||
|
- rst
|
||||||
prelude_section_name: release_summary
|
prelude_section_name: release_summary
|
||||||
prelude_section_title: Release Summary
|
prelude_section_title: Release Summary
|
||||||
sections:
|
sections:
|
||||||
- - major_changes
|
- - major_changes
|
||||||
- Major Changes
|
- Major Changes
|
||||||
- - minor_changes
|
- - minor_changes
|
||||||
- Minor Changes
|
- Minor Changes
|
||||||
- - breaking_changes
|
- - breaking_changes
|
||||||
- Breaking Changes / Porting Guide
|
- Breaking Changes / Porting Guide
|
||||||
- - deprecated_features
|
- - deprecated_features
|
||||||
- Deprecated Features
|
- Deprecated Features
|
||||||
- - removed_features
|
- - removed_features
|
||||||
- Removed Features (previously deprecated)
|
- Removed Features (previously deprecated)
|
||||||
- - security_fixes
|
- - security_fixes
|
||||||
- Security Fixes
|
- Security Fixes
|
||||||
- - bugfixes
|
- - bugfixes
|
||||||
- Bugfixes
|
- Bugfixes
|
||||||
- - known_issues
|
- - known_issues
|
||||||
- Known Issues
|
- Known Issues
|
||||||
title: Community Crypto
|
title: Community Crypto
|
||||||
|
trivial_section_name: trivial
|
||||||
|
use_fqcn: true
|
||||||
|
add_plugin_period: true
|
||||||
|
changelog_nice_yaml: true
|
||||||
|
changelog_sort: version
|
||||||
|
vcs: auto
|
||||||
|
|||||||
2
changelogs/fragments/1005-openssl-4.yml
Normal file
2
changelogs/fragments/1005-openssl-4.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
bugfixes:
|
||||||
|
- "acme_* modules - adjust OpenSSL RSA private key output parsing to OpenSSL 4.0.0 (https://github.com/ansible-collections/community.crypto/pull/1005)."
|
||||||
2
changelogs/fragments/1007-cryptography-47.yml
Normal file
2
changelogs/fragments/1007-cryptography-47.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
bugfixes:
|
||||||
|
- "acme_challenge_cert_helper - adjust private key check for new private key types in cryptography 47.0.0 (https://github.com/ansible-collections/community.crypto/pull/1007)."
|
||||||
7
docs/docsite/config.yml
Normal file
7
docs/docsite/config.yml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
changelog:
|
||||||
|
write_changelog: true
|
||||||
@@ -1,4 +1,8 @@
|
|||||||
---
|
---
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
sections:
|
sections:
|
||||||
- title: Scenario Guides
|
- title: Scenario Guides
|
||||||
toctree:
|
toctree:
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
---
|
---
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
edit_on_github:
|
edit_on_github:
|
||||||
repository: ansible-collections/community.crypto
|
repository: ansible-collections/community.crypto
|
||||||
branch: main
|
branch: main
|
||||||
path_prefix: ''
|
path_prefix: ''
|
||||||
|
|
||||||
extra_links:
|
extra_links:
|
||||||
|
- description: Ask for help (crypto)
|
||||||
|
url: https://forum.ansible.com/tags/c/help/6/none/crypto
|
||||||
|
- description: Ask for help (ACME)
|
||||||
|
url: https://forum.ansible.com/tags/c/help/6/none/acme
|
||||||
- description: Submit a bug report
|
- description: Submit a bug report
|
||||||
url: https://github.com/ansible-collections/community.crypto/issues/new?assignees=&labels=&template=bug_report.md
|
url: https://github.com/ansible-collections/community.crypto/issues/new?assignees=&labels=&template=bug_report.md
|
||||||
- description: Request a feature
|
- description: Request a feature
|
||||||
@@ -18,6 +26,13 @@ communication:
|
|||||||
- topic: General usage and support questions
|
- topic: General usage and support questions
|
||||||
network: Libera
|
network: Libera
|
||||||
channel: '#ansible'
|
channel: '#ansible'
|
||||||
mailing_lists:
|
forums:
|
||||||
- topic: Ansible Project List
|
- topic: "Ansible Forum: General usage and support questions"
|
||||||
url: https://groups.google.com/g/ansible-project
|
# The following URL directly points to the "Get Help" section
|
||||||
|
url: https://forum.ansible.com/c/help/6/none
|
||||||
|
- topic: "Ansible Forum: Discussions about cryptography"
|
||||||
|
# The following URL directly points to the "crpyto" tag
|
||||||
|
url: https://forum.ansible.com/tag/crpyto
|
||||||
|
- topic: "Ansible Forum: Discussions about ACME (RFC 8555)"
|
||||||
|
# The following URL directly points to the "acme" tag
|
||||||
|
url: https://forum.ansible.com/tag/acme
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
|
..
|
||||||
|
Copyright (c) Ansible Project
|
||||||
|
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
.. _ansible_collections.community.crypto.docsite.guide_ownca:
|
.. _ansible_collections.community.crypto.docsite.guide_ownca:
|
||||||
|
|
||||||
How to create a small CA
|
How to create a small CA
|
||||||
========================
|
========================
|
||||||
|
|
||||||
The `community.crypto collection <https://galaxy.ansible.com/community/crypto>`_ offers multiple modules that create private keys, certificate signing requests, and certificates. This guide shows how to create your own small CA and how to use it to sign certificates.
|
The `community.crypto collection <https://galaxy.ansible.com/ui/repo/published/community/crypto/>`_ offers multiple modules that create private keys, certificate signing requests, and certificates. This guide shows how to create your own small CA and how to use it to sign certificates.
|
||||||
|
|
||||||
In all examples, we assume that the CA's private key is password protected, where the password is provided in the ``secret_ca_passphrase`` variable.
|
In all examples, we assume that the CA's private key is password protected, where the password is provided in the ``secret_ca_passphrase`` variable.
|
||||||
|
|
||||||
@@ -29,7 +34,7 @@ The following instructions show how to set up a simple self-signed CA certificat
|
|||||||
use_common_name_for_san: false # since we do not specify SANs, don't use CN as a SAN
|
use_common_name_for_san: false # since we do not specify SANs, don't use CN as a SAN
|
||||||
basic_constraints:
|
basic_constraints:
|
||||||
- 'CA:TRUE'
|
- 'CA:TRUE'
|
||||||
basic_constraints_critical: yes
|
basic_constraints_critical: true
|
||||||
key_usage:
|
key_usage:
|
||||||
- keyCertSign
|
- keyCertSign
|
||||||
key_usage_critical: true
|
key_usage_critical: true
|
||||||
@@ -46,7 +51,7 @@ The following instructions show how to set up a simple self-signed CA certificat
|
|||||||
Use the CA to sign a certificate
|
Use the CA to sign a certificate
|
||||||
--------------------------------
|
--------------------------------
|
||||||
|
|
||||||
To sign a certificate, you must pass a CSR to the :ref:`community.crypto.x509_certificate module <ansible_collections.community.crypto.x509_certificate_module>` or :ref:`community.crypto.x509_certificate_pipe module <ansible_collections.community.crypto.x509_certificate_pipe_module>`.
|
To sign a certificate, you must pass a CSR to the :ansplugin:`community.crypto.x509_certificate module <community.crypto.x509_certificate#module>` or :ansplugin:`community.crypto.x509_certificate_pipe module <community.crypto.x509_certificate_pipe#module>`.
|
||||||
|
|
||||||
In the following example, we assume that the certificate to sign (including its private key) are on ``server_1``, while our CA certificate is on ``server_2``. We do not want any key material to leave each respective server.
|
In the following example, we assume that the certificate to sign (including its private key) are on ``server_1``, while our CA certificate is on ``server_2``. We do not want any key material to leave each respective server.
|
||||||
|
|
||||||
@@ -89,7 +94,7 @@ In the following example, we assume that the certificate to sign (including its
|
|||||||
delegate_to: server_1
|
delegate_to: server_1
|
||||||
run_once: true
|
run_once: true
|
||||||
|
|
||||||
Please note that the above procedure is **not idempotent**. The following extended example reads the existing certificate from ``server_1`` (if exists) and provides it to the :ref:`community.crypto.x509_certificate_pipe module <ansible_collections.community.crypto.x509_certificate_pipe_module>`, and only writes the result back if it was changed:
|
Please note that the above procedure is **not idempotent**. The following extended example reads the existing certificate from ``server_1`` (if exists) and provides it to the :ansplugin:`community.crypto.x509_certificate_pipe module <community.crypto.x509_certificate_pipe#module>`, and only writes the result back if it was changed:
|
||||||
|
|
||||||
.. code-block:: yaml+jinja
|
.. code-block:: yaml+jinja
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
|
..
|
||||||
|
Copyright (c) Ansible Project
|
||||||
|
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
.. _ansible_collections.community.crypto.docsite.guide_selfsigned:
|
.. _ansible_collections.community.crypto.docsite.guide_selfsigned:
|
||||||
|
|
||||||
How to create self-signed certificates
|
How to create self-signed certificates
|
||||||
======================================
|
======================================
|
||||||
|
|
||||||
The `community.crypto collection <https://galaxy.ansible.com/community/crypto>`_ offers multiple modules that create private keys, certificate signing requests, and certificates. This guide shows how to create self-signed certificates.
|
The `community.crypto collection <https://galaxy.ansible.com/ui/repo/published/community/crypto/>`_ offers multiple modules that create private keys, certificate signing requests, and certificates. This guide shows how to create self-signed certificates.
|
||||||
|
|
||||||
For creating any kind of certificate, you always have to start with a private key. You can use the :ref:`community.crypto.openssl_privatekey module <ansible_collections.community.crypto.openssl_privatekey_module>` to create a private key. If you only specify ``path``, the default parameters will be used. This will result in a 4096 bit RSA private key:
|
For creating any kind of certificate, you always have to start with a private key. You can use the :ansplugin:`community.crypto.openssl_privatekey module <community.crypto.openssl_privatekey#module>` to create a private key. If you only specify :ansopt:`community.crypto.openssl_privatekey#module:path`, the default parameters will be used. This will result in a 4096 bit RSA private key:
|
||||||
|
|
||||||
.. code-block:: yaml+jinja
|
.. code-block:: yaml+jinja
|
||||||
|
|
||||||
@@ -13,7 +18,7 @@ For creating any kind of certificate, you always have to start with a private ke
|
|||||||
community.crypto.openssl_privatekey:
|
community.crypto.openssl_privatekey:
|
||||||
path: /path/to/certificate.key
|
path: /path/to/certificate.key
|
||||||
|
|
||||||
You can specify ``type`` to select another key type, ``size`` to select a different key size (only available for RSA and DSA keys), or ``passphrase`` if you want to store the key password-protected:
|
You can specify :ansopt:`community.crypto.openssl_privatekey#module:type` to select another key type, :ansopt:`community.crypto.openssl_privatekey#module:size` to select a different key size (only available for RSA and DSA keys), or :ansopt:`community.crypto.openssl_privatekey#module:passphrase` if you want to store the key password-protected:
|
||||||
|
|
||||||
.. code-block:: yaml+jinja
|
.. code-block:: yaml+jinja
|
||||||
|
|
||||||
@@ -23,7 +28,7 @@ You can specify ``type`` to select another key type, ``size`` to select a differ
|
|||||||
type: X25519
|
type: X25519
|
||||||
passphrase: changeme
|
passphrase: changeme
|
||||||
|
|
||||||
To create a very simple self-signed certificate with no specific information, you can proceed directly with the :ref:`community.crypto.x509_certificate module <ansible_collections.community.crypto.x509_certificate_module>`:
|
To create a very simple self-signed certificate with no specific information, you can proceed directly with the :ansplugin:`community.crypto.x509_certificate module <community.crypto.x509_certificate#module>`:
|
||||||
|
|
||||||
.. code-block:: yaml+jinja
|
.. code-block:: yaml+jinja
|
||||||
|
|
||||||
@@ -33,11 +38,11 @@ To create a very simple self-signed certificate with no specific information, yo
|
|||||||
privatekey_path: /path/to/certificate.key
|
privatekey_path: /path/to/certificate.key
|
||||||
provider: selfsigned
|
provider: selfsigned
|
||||||
|
|
||||||
(If you used ``passphrase`` for the private key, you have to provide ``privatekey_passphrase``.)
|
(If you used :ansopt:`community.crypto.openssl_privatekey#module:passphrase` for the private key, you have to provide :ansopt:`community.crypto.x509_certificate#module:privatekey_passphrase`.)
|
||||||
|
|
||||||
You can use ``selfsigned_not_after`` to define when the certificate expires (default: in roughly 10 years), and ``selfsigned_not_before`` to define from when the certificate is valid (default: now).
|
You can use :ansopt:`community.crypto.x509_certificate#module:selfsigned_not_after` to define when the certificate expires (default: in roughly 10 years), and :ansopt:`community.crypto.x509_certificate#module:selfsigned_not_before` to define from when the certificate is valid (default: now).
|
||||||
|
|
||||||
To define further properties of the certificate, like the subject, Subject Alternative Names (SANs), key usages, name constraints, etc., you need to first create a Certificate Signing Request (CSR) and provide it to the :ref:`community.crypto.x509_certificate module <ansible_collections.community.crypto.x509_certificate_module>`. If you do not need the CSR file, you can use the :ref:`community.crypto.openssl_csr_pipe module <ansible_collections.community.crypto.openssl_csr_pipe_module>` as in the example below. (To store it to disk, use the :ref:`community.crypto.openssl_csr module <ansible_collections.community.crypto.openssl_csr_module>` instead.)
|
To define further properties of the certificate, like the subject, Subject Alternative Names (SANs), key usages, name constraints, etc., you need to first create a Certificate Signing Request (CSR) and provide it to the :ansplugin:`community.crypto.x509_certificate module <community.crypto.x509_certificate#module>`. If you do not need the CSR file, you can use the :ansplugin:`community.crypto.openssl_csr_pipe module <community.crypto.openssl_csr_pipe#module>` as in the example below. (To store it to disk, use the :ansplugin:`community.crypto.openssl_csr module <community.crypto.openssl_csr#module>` instead.)
|
||||||
|
|
||||||
.. code-block:: yaml+jinja
|
.. code-block:: yaml+jinja
|
||||||
|
|
||||||
|
|||||||
17
galaxy.yml
17
galaxy.yml
@@ -1,11 +1,22 @@
|
|||||||
|
---
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
namespace: community
|
namespace: community
|
||||||
name: crypto
|
name: crypto
|
||||||
version: 2.3.0
|
version: 3.3.0
|
||||||
readme: README.md
|
readme: README.md
|
||||||
authors:
|
authors:
|
||||||
- Ansible (github.com/ansible)
|
- Ansible (github.com/ansible)
|
||||||
description: null
|
description: Provides modules and plugins for many cryptographic operations.
|
||||||
license_file: COPYING
|
license:
|
||||||
|
- GPL-3.0-or-later
|
||||||
|
- Apache-2.0
|
||||||
|
- BSD-2-Clause
|
||||||
|
- BSD-3-Clause
|
||||||
|
- PSF-2.0
|
||||||
|
# license_file: COPYING
|
||||||
tags:
|
tags:
|
||||||
- acme
|
- acme
|
||||||
- certificate
|
- certificate
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
cryptsetup [platform:dpkg]
|
cryptsetup [platform:dpkg]
|
||||||
cryptsetup [platform:rpm]
|
cryptsetup [platform:rpm]
|
||||||
openssh-client [platform:dpkg]
|
openssh-client [platform:dpkg]
|
||||||
@@ -7,4 +11,3 @@ openssl [platform:rpm]
|
|||||||
python3-cryptography [platform:dpkg]
|
python3-cryptography [platform:dpkg]
|
||||||
python3-cryptography [platform:rpm]
|
python3-cryptography [platform:rpm]
|
||||||
python3-openssl [platform:dpkg]
|
python3-openssl [platform:dpkg]
|
||||||
python3-pyOpenSSL [platform:rpm]
|
|
||||||
|
|||||||
@@ -1 +1,5 @@
|
|||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
PyYAML
|
PyYAML
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
---
|
---
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
version: 1
|
version: 1
|
||||||
dependencies:
|
dependencies:
|
||||||
python: meta/ee-requirements.txt
|
python: meta/ee-requirements.txt
|
||||||
|
|||||||
@@ -1,16 +1,33 @@
|
|||||||
requires_ansible: '>=2.9.10'
|
---
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
requires_ansible: '>=2.17.0'
|
||||||
|
|
||||||
action_groups:
|
action_groups:
|
||||||
acme:
|
acme:
|
||||||
- acme_inspect
|
- acme_inspect
|
||||||
- acme_certificate_revoke
|
- acme_certificate
|
||||||
- acme_certificate
|
- acme_certificate_deactivate_authz
|
||||||
- acme_account
|
- acme_certificate_order_create
|
||||||
- acme_account_facts
|
- acme_certificate_order_finalize
|
||||||
- acme_account_info
|
- acme_certificate_order_info
|
||||||
|
- acme_certificate_order_validate
|
||||||
|
- acme_certificate_revoke
|
||||||
|
- acme_account
|
||||||
|
- acme_account_info
|
||||||
|
|
||||||
plugin_routing:
|
plugin_routing:
|
||||||
modules:
|
modules:
|
||||||
|
ecs_certificate:
|
||||||
|
tombstone:
|
||||||
|
removal_version: 3.0.0
|
||||||
|
warning_text: The 'community.crypto.ecs_certificate' module has been removed due to the upcoming sunsetting of the ECS service. Please use community.crypto 2.x.y to continue using this module
|
||||||
|
ecs_domain:
|
||||||
|
tombstone:
|
||||||
|
removal_version: 3.0.0
|
||||||
|
warning_text: The 'community.crypto.ecs_domain' module has been removed due to the upcoming sunsetting of the ECS service. Please use community.crypto 2.x.y to continue using this module.
|
||||||
acme_account_facts:
|
acme_account_facts:
|
||||||
tombstone:
|
tombstone:
|
||||||
removal_version: 2.0.0
|
removal_version: 2.0.0
|
||||||
|
|||||||
39
noxfile.py
Normal file
39
noxfile.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
# SPDX-FileCopyrightText: 2025 Felix Fontein <felix@fontein.de>
|
||||||
|
|
||||||
|
# /// script
|
||||||
|
# dependencies = ["nox>=2025.02.09", "antsibull-nox"]
|
||||||
|
# ///
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import nox
|
||||||
|
|
||||||
|
try:
|
||||||
|
import antsibull_nox
|
||||||
|
except ImportError:
|
||||||
|
print("You need to install antsibull-nox in the same Python environment as nox.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
antsibull_nox.load_antsibull_nox_toml()
|
||||||
|
|
||||||
|
|
||||||
|
@nox.session(name="create-certificates", default=False)
|
||||||
|
def create_certificates(session: nox.Session) -> None:
|
||||||
|
"""
|
||||||
|
Regenerate some vendored certificates.
|
||||||
|
"""
|
||||||
|
session.install("cryptography<39.0.0") # we want support for SHA1 signatures
|
||||||
|
session.run("python", "tests/create-certificates.py")
|
||||||
|
session.warn(
|
||||||
|
"Note that you need to modify some values in tests/integration/targets/x509_certificate_info/tasks/impl.yml"
|
||||||
|
" and tests/integration/targets/filter_x509_certificate_info/tasks/impl.yml!"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Allow to run the noxfile with `python noxfile.py`, `pipx run noxfile.py`, or similar.
|
||||||
|
# Requires nox >= 2025.02.09
|
||||||
|
if __name__ == "__main__":
|
||||||
|
nox.main()
|
||||||
@@ -1,90 +1,100 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# Copyright (c) 2020, Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
# Copyright: (c) 2020, Felix Fontein <felix@fontein.de>
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
|
import typing as t
|
||||||
|
|
||||||
from ansible.module_utils.common.text.converters import to_native, to_bytes
|
from ansible.module_utils.common.text.converters import to_bytes
|
||||||
|
|
||||||
from ansible_collections.community.crypto.plugins.plugin_utils.action_module import ActionModuleBase
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.basic import (
|
||||||
|
|
||||||
from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import (
|
|
||||||
OpenSSLObjectError,
|
OpenSSLObjectError,
|
||||||
)
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.module_backends.privatekey import (
|
||||||
from ansible_collections.community.crypto.plugins.module_utils.crypto.module_backends.privatekey import (
|
|
||||||
select_backend,
|
|
||||||
get_privatekey_argument_spec,
|
get_privatekey_argument_spec,
|
||||||
|
select_backend,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.plugin_utils._action_module import (
|
||||||
|
ActionModuleBase,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if t.TYPE_CHECKING:
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._argspec import ( # pragma: no cover
|
||||||
|
ArgumentSpec,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.module_backends.privatekey import ( # pragma: no cover
|
||||||
|
PrivateKeyBackend,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.plugin_utils._action_module import ( # pragma: no cover
|
||||||
|
AnsibleActionModule,
|
||||||
|
)
|
||||||
|
|
||||||
class PrivateKeyModule(object):
|
|
||||||
def __init__(self, module, module_backend):
|
class PrivateKeyModule:
|
||||||
|
def __init__(
|
||||||
|
self, module: AnsibleActionModule, module_backend: PrivateKeyBackend
|
||||||
|
) -> None:
|
||||||
self.module = module
|
self.module = module
|
||||||
self.module_backend = module_backend
|
self.module_backend = module_backend
|
||||||
self.check_mode = module.check_mode
|
self.check_mode = module.check_mode
|
||||||
self.changed = False
|
self.changed = False
|
||||||
self.return_current_key = module.params['return_current_key']
|
self.return_current_key: bool = module.params["return_current_key"]
|
||||||
|
|
||||||
if module.params['content'] is not None:
|
content: str | None = module.params["content"]
|
||||||
if module.params['content_base64']:
|
content_base64: bool = module.params["content_base64"]
|
||||||
|
if content is not None:
|
||||||
|
if content_base64:
|
||||||
try:
|
try:
|
||||||
data = base64.b64decode(module.params['content'])
|
data = base64.b64decode(content)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
module.fail_json(msg='Cannot decode Base64 encoded data: {0}'.format(e))
|
module.fail_json(msg=f"Cannot decode Base64 encoded data: {e}")
|
||||||
else:
|
else:
|
||||||
data = to_bytes(module.params['content'])
|
data = to_bytes(content)
|
||||||
module_backend.set_existing(data)
|
module_backend.set_existing(privatekey_bytes=data)
|
||||||
|
|
||||||
def generate(self, module):
|
def generate(self, module: AnsibleActionModule) -> None:
|
||||||
"""Generate a keypair."""
|
"""Generate a keypair."""
|
||||||
|
|
||||||
if self.module_backend.needs_regeneration():
|
if self.module_backend.needs_regeneration():
|
||||||
# Regenerate
|
# Regenerate
|
||||||
if not self.check_mode:
|
self.module_backend.generate_private_key()
|
||||||
self.module_backend.generate_private_key()
|
# Call get_private_key_data() to make sure that exceptions are raised now:
|
||||||
privatekey_data = self.module_backend.get_private_key_data()
|
self.module_backend.get_private_key_data()
|
||||||
self.privatekey_bytes = privatekey_data
|
|
||||||
self.changed = True
|
self.changed = True
|
||||||
elif self.module_backend.needs_conversion():
|
elif self.module_backend.needs_conversion():
|
||||||
# Convert
|
# Convert
|
||||||
if not self.check_mode:
|
self.module_backend.convert_private_key()
|
||||||
self.module_backend.convert_private_key()
|
# Call get_private_key_data() to make sure that exceptions are raised now:
|
||||||
privatekey_data = self.module_backend.get_private_key_data()
|
self.module_backend.get_private_key_data()
|
||||||
self.privatekey_bytes = privatekey_data
|
|
||||||
self.changed = True
|
self.changed = True
|
||||||
|
|
||||||
def dump(self):
|
def dump(self) -> dict[str, t.Any]:
|
||||||
"""Serialize the object into a dictionary."""
|
"""Serialize the object into a dictionary."""
|
||||||
result = self.module_backend.dump(include_key=self.changed or self.return_current_key)
|
result = self.module_backend.dump(
|
||||||
result['changed'] = self.changed
|
include_key=self.changed or self.return_current_key
|
||||||
|
)
|
||||||
|
result["changed"] = self.changed
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(ActionModuleBase):
|
class ActionModule(ActionModuleBase):
|
||||||
@staticmethod
|
def setup_module(self) -> tuple[ArgumentSpec, dict[str, t.Any]]:
|
||||||
def setup_module():
|
|
||||||
argument_spec = get_privatekey_argument_spec()
|
argument_spec = get_privatekey_argument_spec()
|
||||||
argument_spec.argument_spec.update(dict(
|
argument_spec.argument_spec.update(
|
||||||
content=dict(type='str', no_log=True),
|
{
|
||||||
content_base64=dict(type='bool', default=False),
|
"content": {"type": "str", "no_log": True},
|
||||||
return_current_key=dict(type='bool', default=False),
|
"content_base64": {"type": "bool", "default": False},
|
||||||
))
|
"return_current_key": {"type": "bool", "default": False},
|
||||||
return argument_spec, dict(
|
}
|
||||||
supports_check_mode=True,
|
|
||||||
)
|
)
|
||||||
|
return argument_spec, {
|
||||||
|
"supports_check_mode": True,
|
||||||
|
}
|
||||||
|
|
||||||
@staticmethod
|
def run_module(self, module: AnsibleActionModule) -> None:
|
||||||
def run_module(module):
|
module_backend = select_backend(module=module)
|
||||||
backend, module_backend = select_backend(
|
|
||||||
module=module,
|
|
||||||
backend=module.params['select_crypto_backend'],
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
private_key = PrivateKeyModule(module, module_backend)
|
private_key = PrivateKeyModule(module, module_backend)
|
||||||
@@ -98,10 +108,10 @@ class ActionModule(ActionModuleBase):
|
|||||||
# `module.no_log = True`, this should be safe.
|
# `module.no_log = True`, this should be safe.
|
||||||
module.no_log = True
|
module.no_log = True
|
||||||
try:
|
try:
|
||||||
module.no_log_values.remove(module.params['content'])
|
module.no_log_values.remove(module.params["content"])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
module.params['content'] = 'ANSIBLE_NO_LOG_VALUE'
|
module.params["content"] = "ANSIBLE_NO_LOG_VALUE"
|
||||||
module.exit_json(**result)
|
module.exit_json(**result)
|
||||||
except OpenSSLObjectError as exc:
|
except OpenSSLObjectError as exc:
|
||||||
module.fail_json(msg=to_native(exc))
|
module.fail_json(msg=str(exc))
|
||||||
|
|||||||
153
plugins/doc_fragments/_acme.py
Normal file
153
plugins/doc_fragments/_acme.py
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
# Copyright (c) 2016 Michael Gruener <michael.gruener@chaosmoon.net>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this doc fragment is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleDocFragment:
|
||||||
|
# Basic documentation fragment without account data
|
||||||
|
BASIC = r"""
|
||||||
|
notes:
|
||||||
|
- Although the defaults are chosen so that the module can be used with the L(Let's Encrypt,https://letsencrypt.org/) CA,
|
||||||
|
the module can in principle be used with any CA providing an ACME endpoint.
|
||||||
|
- So far, the ACME modules have only been tested by the developers against Let's Encrypt (staging and production),
|
||||||
|
ZeroSSL (production), and L(Pebble testing server,https://github.com/letsencrypt/Pebble).
|
||||||
|
We have got community feedback that they also work with Sectigo ACME Service for InCommon and with HARICA.
|
||||||
|
If you experience problems with another ACME server, please
|
||||||
|
L(create an issue, https://github.com/ansible-collections/community.crypto/issues/new/choose)
|
||||||
|
to help us supporting it. Feedback that an ACME server not mentioned does work is also appreciated.
|
||||||
|
requirements:
|
||||||
|
- either C(openssl)
|
||||||
|
- or L(cryptography,https://cryptography.io/) >= 3.3
|
||||||
|
options:
|
||||||
|
acme_version:
|
||||||
|
description:
|
||||||
|
- The ACME version of the endpoint.
|
||||||
|
- Must be V(2) for standardized ACME v2 endpoints.
|
||||||
|
- The value V(1) is no longer supported since community.crypto 3.0.0.
|
||||||
|
type: int
|
||||||
|
default: 2
|
||||||
|
choices:
|
||||||
|
- 2
|
||||||
|
acme_directory:
|
||||||
|
description:
|
||||||
|
- The ACME directory to use. This is the entry point URL to access the ACME CA server API.
|
||||||
|
- For safety reasons the default is set to the Let's Encrypt staging server (for the ACME v1 protocol). This will create
|
||||||
|
technically correct, but untrusted certificates.
|
||||||
|
- "For Let's Encrypt, all staging endpoints can be found here: U(https://letsencrypt.org/docs/staging-environment/)."
|
||||||
|
- For B(Let's Encrypt), the production directory URL for ACME v2 is U(https://acme-v02.api.letsencrypt.org/directory).
|
||||||
|
- For B(ZeroSSL), the production directory URL for ACME v2 is U(https://acme.zerossl.com/v2/DV90).
|
||||||
|
- For B(Sectigo), the production directory URL for ACME v2 is U(https://acme-qa.secure.trust-provider.com/v2/DV).
|
||||||
|
- For B(HARICA), the production directory URL for ACME v2 is U(https://acme.harica.gr/XXX/directory) with XXX being specific to your account.
|
||||||
|
- The notes for this module contain a list of ACME services this module has been tested against.
|
||||||
|
required: true
|
||||||
|
type: str
|
||||||
|
validate_certs:
|
||||||
|
description:
|
||||||
|
- Whether calls to the ACME directory will validate TLS certificates.
|
||||||
|
- B(Warning:) Should B(only ever) be set to V(false) for testing purposes, for example when testing against a local
|
||||||
|
Pebble server.
|
||||||
|
type: bool
|
||||||
|
default: true
|
||||||
|
select_crypto_backend:
|
||||||
|
description:
|
||||||
|
- Determines which crypto backend to use.
|
||||||
|
- The default choice is V(auto), which tries to use C(cryptography) if available, and falls back to C(openssl).
|
||||||
|
- If set to V(openssl), will try to use the C(openssl) binary.
|
||||||
|
- If set to V(cryptography), will try to use the L(cryptography,https://cryptography.io/) library.
|
||||||
|
type: str
|
||||||
|
default: auto
|
||||||
|
choices: [auto, cryptography, openssl]
|
||||||
|
request_timeout:
|
||||||
|
description:
|
||||||
|
- The time Ansible should wait for a response from the ACME API.
|
||||||
|
- This timeout is applied to all HTTP(S) requests (HEAD, GET, POST).
|
||||||
|
type: int
|
||||||
|
default: 10
|
||||||
|
version_added: 2.3.0
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Account data documentation fragment
|
||||||
|
ACCOUNT = r"""
|
||||||
|
notes:
|
||||||
|
- If a new enough version of the C(cryptography) library is available (see Requirements for details), it will be used instead
|
||||||
|
of the C(openssl) binary. This can be explicitly disabled or enabled with the O(select_crypto_backend) option. Note that
|
||||||
|
using the C(openssl) binary will be slower and less secure, as private key contents always have to be stored on disk (see
|
||||||
|
O(account_key_content)).
|
||||||
|
options:
|
||||||
|
account_key_src:
|
||||||
|
description:
|
||||||
|
- Path to a file containing the ACME account RSA or Elliptic Curve key.
|
||||||
|
- "For Elliptic Curve keys only the following curves are supported: V(secp256r1), V(secp384r1), and V(secp521r1)."
|
||||||
|
- 'Private keys can be created with the M(community.crypto.openssl_privatekey) or M(community.crypto.openssl_privatekey_pipe)
|
||||||
|
modules. If the requisite (cryptography) is not available, keys can also be created directly with the C(openssl) command
|
||||||
|
line tool: RSA keys can be created with C(openssl genrsa ...). Elliptic curve keys can be created with C(openssl ecparam
|
||||||
|
-genkey ...). Any other tool creating private keys in PEM format can be used as well.'
|
||||||
|
- Mutually exclusive with O(account_key_content).
|
||||||
|
- Required if O(account_key_content) is not used.
|
||||||
|
type: path
|
||||||
|
aliases:
|
||||||
|
- account_key
|
||||||
|
account_key_content:
|
||||||
|
description:
|
||||||
|
- Content of the ACME account RSA or Elliptic Curve key.
|
||||||
|
- "For Elliptic Curve keys only the following curves are supported: V(secp256r1), V(secp384r1), and V(secp521r1)."
|
||||||
|
- Mutually exclusive with O(account_key_src).
|
||||||
|
- Required if O(account_key_src) is not used.
|
||||||
|
- B(Warning:) the content will be written into a temporary file, which will be deleted by Ansible when the module completes.
|
||||||
|
Since this is an important private key — it can be used to change the account key, or to revoke your certificates
|
||||||
|
without knowing their private keys —, this might not be acceptable.
|
||||||
|
- In case C(cryptography) is used, the content is not written into a temporary file. It can still happen that it is
|
||||||
|
written to disk by Ansible in the process of moving the module with its argument to the node where it is executed.
|
||||||
|
type: str
|
||||||
|
account_key_passphrase:
|
||||||
|
description:
|
||||||
|
- Passphrase to use to decode the account key.
|
||||||
|
- B(Note:) this is not supported by the C(openssl) backend, only by the C(cryptography) backend.
|
||||||
|
type: str
|
||||||
|
version_added: 1.6.0
|
||||||
|
account_uri:
|
||||||
|
description:
|
||||||
|
- If specified, assumes that the account URI is as given. If the account key does not match this account, or an account
|
||||||
|
with this URI does not exist, the module fails.
|
||||||
|
type: str
|
||||||
|
"""
|
||||||
|
|
||||||
|
# No account data documentation fragment
|
||||||
|
NO_ACCOUNT = r"""
|
||||||
|
notes:
|
||||||
|
- "If a new enough version of the C(cryptography) library
|
||||||
|
is available (see Requirements for details), it will be used
|
||||||
|
instead of the C(openssl) binary. This can be explicitly disabled
|
||||||
|
or enabled with the O(select_crypto_backend) option. Note that using
|
||||||
|
the C(openssl) binary will be slower."
|
||||||
|
options: {}
|
||||||
|
"""
|
||||||
|
|
||||||
|
CERTIFICATE = r"""
|
||||||
|
options:
|
||||||
|
csr:
|
||||||
|
description:
|
||||||
|
- File containing the CSR for the new certificate.
|
||||||
|
- Can be created with M(community.crypto.openssl_csr).
|
||||||
|
- The CSR may contain multiple Subject Alternate Names, but each one will lead to an individual challenge that must
|
||||||
|
be fulfilled for the CSR to be signed.
|
||||||
|
- 'B(Note): the private key used to create the CSR B(must not) be the account key. This is a bad idea from a security
|
||||||
|
point of view, and the CA should not accept the CSR. The ACME server should return an error in this case.'
|
||||||
|
- Precisely one of O(csr) or O(csr_content) must be specified.
|
||||||
|
type: path
|
||||||
|
csr_content:
|
||||||
|
description:
|
||||||
|
- Content of the CSR for the new certificate.
|
||||||
|
- Can be created with M(community.crypto.openssl_csr_pipe).
|
||||||
|
- The CSR may contain multiple Subject Alternate Names, but each one will lead to an individual challenge that must
|
||||||
|
be fulfilled for the CSR to be signed.
|
||||||
|
- 'B(Note): the private key used to create the CSR B(must not) be the account key. This is a bad idea from a security
|
||||||
|
point of view, and the CA should not accept the CSR. The ACME server should return an error in this case.'
|
||||||
|
- Precisely one of O(csr) or O(csr_content) must be specified.
|
||||||
|
type: str
|
||||||
|
"""
|
||||||
98
plugins/doc_fragments/_attributes.py
Normal file
98
plugins/doc_fragments/_attributes.py
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this doc fragment is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleDocFragment:
|
||||||
|
# Standard documentation fragment
|
||||||
|
DOCUMENTATION = r"""
|
||||||
|
options: {}
|
||||||
|
attributes:
|
||||||
|
check_mode:
|
||||||
|
description: Can run in C(check_mode) and return changed status prediction without modifying target.
|
||||||
|
diff_mode:
|
||||||
|
description: Will return details on what has changed (or possibly needs changing in C(check_mode)), when in diff mode.
|
||||||
|
idempotent:
|
||||||
|
description:
|
||||||
|
- When run twice in a row outside check mode, with the same arguments, the second invocation indicates no change.
|
||||||
|
- This assumes that the system controlled/queried by the module has not changed in a relevant way.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Should be used together with the standard fragment
|
||||||
|
IDEMPOTENT_NOT_MODIFY_STATE = r"""
|
||||||
|
options: {}
|
||||||
|
attributes:
|
||||||
|
idempotent:
|
||||||
|
support: full
|
||||||
|
details:
|
||||||
|
- This action does not modify state.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Should be used together with the standard fragment
|
||||||
|
INFO_MODULE = r"""
|
||||||
|
options: {}
|
||||||
|
attributes:
|
||||||
|
check_mode:
|
||||||
|
support: full
|
||||||
|
details:
|
||||||
|
- This action does not modify state.
|
||||||
|
diff_mode:
|
||||||
|
support: N/A
|
||||||
|
details:
|
||||||
|
- This action does not modify state.
|
||||||
|
"""
|
||||||
|
|
||||||
|
ACTIONGROUP_ACME = r"""
|
||||||
|
options: {}
|
||||||
|
attributes:
|
||||||
|
action_group:
|
||||||
|
description: Use C(group/acme) or C(group/community.crypto.acme) in C(module_defaults) to set defaults for this module.
|
||||||
|
support: full
|
||||||
|
membership:
|
||||||
|
- community.crypto.acme
|
||||||
|
- acme
|
||||||
|
"""
|
||||||
|
|
||||||
|
FACTS = r"""
|
||||||
|
options: {}
|
||||||
|
attributes:
|
||||||
|
facts:
|
||||||
|
description: Action returns an C(ansible_facts) dictionary that will update existing host facts.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Should be used together with the standard fragment and the FACTS fragment
|
||||||
|
FACTS_MODULE = r"""
|
||||||
|
options: {}
|
||||||
|
attributes:
|
||||||
|
check_mode:
|
||||||
|
support: full
|
||||||
|
details:
|
||||||
|
- This action does not modify state.
|
||||||
|
diff_mode:
|
||||||
|
support: N/A
|
||||||
|
details:
|
||||||
|
- This action does not modify state.
|
||||||
|
facts:
|
||||||
|
support: full
|
||||||
|
"""
|
||||||
|
|
||||||
|
FILES = r"""
|
||||||
|
options: {}
|
||||||
|
attributes:
|
||||||
|
safe_file_operations:
|
||||||
|
description: Uses Ansible's strict file operation functions to ensure proper permissions and avoid data corruption.
|
||||||
|
"""
|
||||||
|
|
||||||
|
FLOW = r"""
|
||||||
|
options: {}
|
||||||
|
attributes:
|
||||||
|
action:
|
||||||
|
description: Indicates this has a corresponding action plugin so some parts of the options can be executed on the controller.
|
||||||
|
async:
|
||||||
|
description: Supports being used with the C(async) keyword.
|
||||||
|
"""
|
||||||
23
plugins/doc_fragments/_cryptography_dep.py
Normal file
23
plugins/doc_fragments/_cryptography_dep.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Copyright (c) 2025 Ansible project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this doc fragment is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleDocFragment:
|
||||||
|
"""
|
||||||
|
Doc fragments for cryptography requirements.
|
||||||
|
|
||||||
|
Must be kept in sync with plugins/module_utils/_cryptography_dep.py.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Corresponds to the plugins.module_utils._cryptography_dep.COLLECTION_MINIMUM_CRYPTOGRAPHY_VERSION constant
|
||||||
|
MINIMUM = r"""
|
||||||
|
requirements:
|
||||||
|
- cryptography >= 3.3
|
||||||
|
options: {}
|
||||||
|
"""
|
||||||
331
plugins/doc_fragments/_module_certificate.py
Normal file
331
plugins/doc_fragments/_module_certificate.py
Normal file
@@ -0,0 +1,331 @@
|
|||||||
|
# Copyright (c) 2016-2017, Yanis Guenane <yanis+ansible@guenane.org>
|
||||||
|
# Copyright (c) 2017, Markus Teufelberger <mteufelberger+ansible@mgit.at>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this doc fragment is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleDocFragment:
|
||||||
|
# Standard files documentation fragment
|
||||||
|
DOCUMENTATION = r"""
|
||||||
|
description:
|
||||||
|
- This module allows one to (re)generate OpenSSL certificates.
|
||||||
|
- It uses the cryptography python library to interact with OpenSSL.
|
||||||
|
attributes:
|
||||||
|
diff_mode:
|
||||||
|
support: full
|
||||||
|
idempotent:
|
||||||
|
support: partial
|
||||||
|
details:
|
||||||
|
- If relative timestamps are used and O(ignore_timestamps=false), the module is not idempotent.
|
||||||
|
- The option O(force=true) generally disables idempotency.
|
||||||
|
requirements:
|
||||||
|
- cryptography >= 3.3 (if using V(selfsigned) or V(ownca) provider)
|
||||||
|
options:
|
||||||
|
force:
|
||||||
|
description:
|
||||||
|
- Generate the certificate, even if it already exists.
|
||||||
|
type: bool
|
||||||
|
default: false
|
||||||
|
|
||||||
|
csr_path:
|
||||||
|
description:
|
||||||
|
- Path to the Certificate Signing Request (CSR) used to generate this certificate.
|
||||||
|
- This is mutually exclusive with O(csr_content).
|
||||||
|
type: path
|
||||||
|
csr_content:
|
||||||
|
description:
|
||||||
|
- Content of the Certificate Signing Request (CSR) used to generate this certificate.
|
||||||
|
- This is mutually exclusive with O(csr_path).
|
||||||
|
type: str
|
||||||
|
|
||||||
|
privatekey_path:
|
||||||
|
description:
|
||||||
|
- Path to the private key to use when signing the certificate.
|
||||||
|
- This is mutually exclusive with O(privatekey_content).
|
||||||
|
type: path
|
||||||
|
privatekey_content:
|
||||||
|
description:
|
||||||
|
- Content of the private key to use when signing the certificate.
|
||||||
|
- This is mutually exclusive with O(privatekey_path).
|
||||||
|
type: str
|
||||||
|
|
||||||
|
privatekey_passphrase:
|
||||||
|
description:
|
||||||
|
- The passphrase for the O(privatekey_path) resp. O(privatekey_content).
|
||||||
|
- This is required if the private key is password protected.
|
||||||
|
type: str
|
||||||
|
|
||||||
|
ignore_timestamps:
|
||||||
|
description:
|
||||||
|
- Whether the "not before" and "not after" timestamps should be ignored for idempotency checks.
|
||||||
|
- It is better to keep the default value V(true) when using relative timestamps (like V(+0s) for now).
|
||||||
|
type: bool
|
||||||
|
default: true
|
||||||
|
version_added: 2.0.0
|
||||||
|
|
||||||
|
select_crypto_backend:
|
||||||
|
description:
|
||||||
|
- Determines which crypto backend to use.
|
||||||
|
- The default choice is V(auto), which tries to use C(cryptography) if available.
|
||||||
|
- If set to V(cryptography), will try to use the L(cryptography,https://cryptography.io/) library.
|
||||||
|
- Note that with community.crypto 3.0.0, all values behave the same.
|
||||||
|
This option will be deprecated in a later version.
|
||||||
|
We recommend to not set it explicitly.
|
||||||
|
type: str
|
||||||
|
default: auto
|
||||||
|
choices: [auto, cryptography]
|
||||||
|
|
||||||
|
notes:
|
||||||
|
- All ASN.1 TIME values should be specified following the YYYYMMDDHHMMSSZ pattern.
|
||||||
|
- Date specified should be UTC. Minutes and seconds are mandatory.
|
||||||
|
- For security reason, when you use V(ownca) provider, you should NOT run M(community.crypto.x509_certificate) on a target
|
||||||
|
machine, but on a dedicated CA machine. It is recommended not to store the CA private key on the target machine. Once
|
||||||
|
signed, the certificate can be moved to the target machine.
|
||||||
|
seealso:
|
||||||
|
- module: community.crypto.openssl_csr
|
||||||
|
- module: community.crypto.openssl_csr_pipe
|
||||||
|
- module: community.crypto.openssl_dhparam
|
||||||
|
- module: community.crypto.openssl_pkcs12
|
||||||
|
- module: community.crypto.openssl_privatekey
|
||||||
|
- module: community.crypto.openssl_privatekey_pipe
|
||||||
|
- module: community.crypto.openssl_publickey
|
||||||
|
"""
|
||||||
|
|
||||||
|
BACKEND_ACME_DOCUMENTATION = r"""
|
||||||
|
description:
|
||||||
|
- This module allows one to (re)generate OpenSSL certificates.
|
||||||
|
requirements:
|
||||||
|
- acme-tiny >= 4.0.0 (if using the V(acme) provider)
|
||||||
|
options:
|
||||||
|
acme_accountkey_path:
|
||||||
|
description:
|
||||||
|
- The path to the accountkey for the V(acme) provider.
|
||||||
|
- This is only used by the V(acme) provider.
|
||||||
|
type: path
|
||||||
|
|
||||||
|
acme_challenge_path:
|
||||||
|
description:
|
||||||
|
- The path to the ACME challenge directory that is served on U(http://<HOST>:80/.well-known/acme-challenge/)
|
||||||
|
- This is only used by the V(acme) provider.
|
||||||
|
type: path
|
||||||
|
|
||||||
|
acme_chain:
|
||||||
|
description:
|
||||||
|
- Include the intermediate certificate to the generated certificate
|
||||||
|
- This is only used by the V(acme) provider.
|
||||||
|
- Note that this is only available for older versions of C(acme-tiny).
|
||||||
|
New versions include the chain automatically, and setting O(acme_chain) to V(true) results in an error.
|
||||||
|
type: bool
|
||||||
|
default: false
|
||||||
|
|
||||||
|
acme_directory:
|
||||||
|
description:
|
||||||
|
- "The ACME directory to use. You can use any directory that supports the ACME protocol, such as Let's Encrypt."
|
||||||
|
- "Let's Encrypt recommends using their staging server while developing jobs. U(https://letsencrypt.org/docs/staging-environment/)."
|
||||||
|
type: str
|
||||||
|
default: https://acme-v02.api.letsencrypt.org/directory
|
||||||
|
"""
|
||||||
|
|
||||||
|
BACKEND_OWNCA_DOCUMENTATION = r"""
|
||||||
|
description:
|
||||||
|
- The V(ownca) provider is intended for generating an OpenSSL certificate signed with your own
|
||||||
|
CA (Certificate Authority) certificate (self-signed certificate).
|
||||||
|
options:
|
||||||
|
ownca_path:
|
||||||
|
description:
|
||||||
|
- Remote absolute path of the CA (Certificate Authority) certificate.
|
||||||
|
- This is only used by the V(ownca) provider.
|
||||||
|
- This is mutually exclusive with O(ownca_content).
|
||||||
|
type: path
|
||||||
|
ownca_content:
|
||||||
|
description:
|
||||||
|
- Content of the CA (Certificate Authority) certificate.
|
||||||
|
- This is only used by the V(ownca) provider.
|
||||||
|
- This is mutually exclusive with O(ownca_path).
|
||||||
|
type: str
|
||||||
|
|
||||||
|
ownca_privatekey_path:
|
||||||
|
description:
|
||||||
|
- Path to the CA (Certificate Authority) private key to use when signing the certificate.
|
||||||
|
- This is only used by the V(ownca) provider.
|
||||||
|
- This is mutually exclusive with O(ownca_privatekey_content).
|
||||||
|
type: path
|
||||||
|
ownca_privatekey_content:
|
||||||
|
description:
|
||||||
|
- Content of the CA (Certificate Authority) private key to use when signing the certificate.
|
||||||
|
- This is only used by the V(ownca) provider.
|
||||||
|
- This is mutually exclusive with O(ownca_privatekey_path).
|
||||||
|
type: str
|
||||||
|
|
||||||
|
ownca_privatekey_passphrase:
|
||||||
|
description:
|
||||||
|
- The passphrase for the O(ownca_privatekey_path) resp. O(ownca_privatekey_content).
|
||||||
|
- This is only used by the V(ownca) provider.
|
||||||
|
type: str
|
||||||
|
|
||||||
|
ownca_digest:
|
||||||
|
description:
|
||||||
|
- The digest algorithm to be used for the V(ownca) certificate.
|
||||||
|
- This is only used by the V(ownca) provider.
|
||||||
|
type: str
|
||||||
|
default: sha256
|
||||||
|
|
||||||
|
ownca_version:
|
||||||
|
description:
|
||||||
|
- The version of the V(ownca) certificate.
|
||||||
|
- Nowadays it should almost always be V(3).
|
||||||
|
- This is only used by the V(ownca) provider.
|
||||||
|
type: int
|
||||||
|
default: 3
|
||||||
|
choices:
|
||||||
|
- 3
|
||||||
|
|
||||||
|
ownca_not_before:
|
||||||
|
description:
|
||||||
|
- The point in time the certificate is valid from.
|
||||||
|
- Time can be specified either as relative time or as absolute timestamp.
|
||||||
|
- Time will always be interpreted as UTC.
|
||||||
|
- Valid format is C([+-]timespec | ASN.1 TIME) where timespec can be an integer
|
||||||
|
+ C([w | d | h | m | s]) (for example V(+32w1d2h)).
|
||||||
|
- If this value is not specified, the certificate will start being valid from now.
|
||||||
|
- Note that this value is B(not used to determine whether an existing certificate should be regenerated).
|
||||||
|
This can be changed by setting the O(ignore_timestamps) option to V(false). Please note that you should
|
||||||
|
avoid relative timestamps when setting O(ignore_timestamps=false).
|
||||||
|
- This is only used by the V(ownca) provider.
|
||||||
|
type: str
|
||||||
|
default: +0s
|
||||||
|
|
||||||
|
ownca_not_after:
|
||||||
|
description:
|
||||||
|
- The point in time at which the certificate stops being valid.
|
||||||
|
- Time can be specified either as relative time or as absolute timestamp.
|
||||||
|
- Time will always be interpreted as UTC.
|
||||||
|
- Valid format is C([+-]timespec | ASN.1 TIME) where timespec can be an integer
|
||||||
|
+ C([w | d | h | m | s]) (for example V(+32w1d2h)).
|
||||||
|
- If this value is not specified, the certificate will stop being valid 10 years from now.
|
||||||
|
- Note that this value is B(not used to determine whether an existing certificate should be regenerated).
|
||||||
|
This can be changed by setting the O(ignore_timestamps) option to V(false). Please note that you should
|
||||||
|
avoid relative timestamps when setting O(ignore_timestamps=false).
|
||||||
|
- This is only used by the V(ownca) provider.
|
||||||
|
- On macOS 10.15 and onwards, TLS server certificates must have a validity period of 825 days or fewer.
|
||||||
|
Please see U(https://support.apple.com/en-us/HT210176) for more details.
|
||||||
|
type: str
|
||||||
|
default: +3650d
|
||||||
|
|
||||||
|
ownca_create_subject_key_identifier:
|
||||||
|
description:
|
||||||
|
- Whether to create the Subject Key Identifier (SKI) from the public key.
|
||||||
|
- A value of V(create_if_not_provided) (default) only creates a SKI when the CSR does not
|
||||||
|
provide one.
|
||||||
|
- A value of V(always_create) always creates a SKI. If the CSR provides one, that one is
|
||||||
|
ignored.
|
||||||
|
- A value of V(never_create) never creates a SKI. If the CSR provides one, that one is used.
|
||||||
|
- This is only used by the V(ownca) provider.
|
||||||
|
type: str
|
||||||
|
choices: [create_if_not_provided, always_create, never_create]
|
||||||
|
default: create_if_not_provided
|
||||||
|
|
||||||
|
ownca_create_authority_key_identifier:
|
||||||
|
description:
|
||||||
|
- Create a Authority Key Identifier from the CA's certificate. If the CSR provided
|
||||||
|
a authority key identifier, it is ignored.
|
||||||
|
- The Authority Key Identifier is generated from the CA certificate's Subject Key Identifier,
|
||||||
|
if available. If it is not available, the CA certificate's public key will be used.
|
||||||
|
- This is only used by the V(ownca) provider.
|
||||||
|
type: bool
|
||||||
|
default: true
|
||||||
|
"""
|
||||||
|
|
||||||
|
BACKEND_SELFSIGNED_DOCUMENTATION = r"""
|
||||||
|
notes:
|
||||||
|
- For the V(selfsigned) provider, O(csr_path) and O(csr_content) are optional. If not provided, a
|
||||||
|
certificate without any information (Subject, Subject Alternative Names, Key Usage, etc.) is created.
|
||||||
|
|
||||||
|
options:
|
||||||
|
# NOTE: descriptions in options are overwritten, not appended. For that reason, the texts provided
|
||||||
|
# here for csr_path and csr_content are not visible to the user. That's why this information is
|
||||||
|
# added to the notes (see above).
|
||||||
|
|
||||||
|
# csr_path:
|
||||||
|
# description:
|
||||||
|
# - This is optional for the V(selfsigned) provider. If not provided, a certificate
|
||||||
|
# without any information (Subject, Subject Alternative Names, Key Usage, etc.) is
|
||||||
|
# created.
|
||||||
|
|
||||||
|
# csr_content:
|
||||||
|
# description:
|
||||||
|
# - This is optional for the V(selfsigned) provider. If not provided, a certificate
|
||||||
|
# without any information (Subject, Subject Alternative Names, Key Usage, etc.) is
|
||||||
|
# created.
|
||||||
|
|
||||||
|
selfsigned_version:
|
||||||
|
description:
|
||||||
|
- Version of the V(selfsigned) certificate.
|
||||||
|
- Nowadays it should almost always be V(3).
|
||||||
|
- This is only used by the V(selfsigned) provider.
|
||||||
|
type: int
|
||||||
|
default: 3
|
||||||
|
choices:
|
||||||
|
- 3
|
||||||
|
|
||||||
|
selfsigned_digest:
|
||||||
|
description:
|
||||||
|
- Digest algorithm to be used when self-signing the certificate.
|
||||||
|
- This is only used by the V(selfsigned) provider.
|
||||||
|
type: str
|
||||||
|
default: sha256
|
||||||
|
|
||||||
|
selfsigned_not_before:
|
||||||
|
description:
|
||||||
|
- The point in time the certificate is valid from.
|
||||||
|
- Time can be specified either as relative time or as absolute timestamp.
|
||||||
|
- Time will always be interpreted as UTC.
|
||||||
|
- Valid format is C([+-]timespec | ASN.1 TIME) where timespec can be an integer
|
||||||
|
+ C([w | d | h | m | s]) (for example V(+32w1d2h)).
|
||||||
|
- If this value is not specified, the certificate will start being valid from now.
|
||||||
|
- Note that this value is B(not used to determine whether an existing certificate should be regenerated).
|
||||||
|
This can be changed by setting the O(ignore_timestamps) option to V(false). Please note that you should
|
||||||
|
avoid relative timestamps when setting O(ignore_timestamps=false).
|
||||||
|
- This is only used by the V(selfsigned) provider.
|
||||||
|
type: str
|
||||||
|
default: +0s
|
||||||
|
aliases:
|
||||||
|
- selfsigned_notBefore
|
||||||
|
|
||||||
|
selfsigned_not_after:
|
||||||
|
description:
|
||||||
|
- The point in time at which the certificate stops being valid.
|
||||||
|
- Time can be specified either as relative time or as absolute timestamp.
|
||||||
|
- Time will always be interpreted as UTC.
|
||||||
|
- Valid format is C([+-]timespec | ASN.1 TIME) where timespec can be an integer
|
||||||
|
+ C([w | d | h | m | s]) (for example V(+32w1d2h)).
|
||||||
|
- If this value is not specified, the certificate will stop being valid 10 years from now.
|
||||||
|
- Note that this value is B(not used to determine whether an existing certificate should be regenerated).
|
||||||
|
This can be changed by setting the O(ignore_timestamps) option to V(false). Please note that you should
|
||||||
|
avoid relative timestamps when setting O(ignore_timestamps=false).
|
||||||
|
- This is only used by the V(selfsigned) provider.
|
||||||
|
- On macOS 10.15 and onwards, TLS server certificates must have a validity period of 825 days or fewer.
|
||||||
|
Please see U(https://support.apple.com/en-us/HT210176) for more details.
|
||||||
|
type: str
|
||||||
|
default: +3650d
|
||||||
|
aliases:
|
||||||
|
- selfsigned_notAfter
|
||||||
|
|
||||||
|
selfsigned_create_subject_key_identifier:
|
||||||
|
description:
|
||||||
|
- Whether to create the Subject Key Identifier (SKI) from the public key.
|
||||||
|
- A value of V(create_if_not_provided) (default) only creates a SKI when the CSR does not
|
||||||
|
provide one.
|
||||||
|
- A value of V(always_create) always creates a SKI. If the CSR provides one, that one is
|
||||||
|
ignored.
|
||||||
|
- A value of V(never_create) never creates a SKI. If the CSR provides one, that one is used.
|
||||||
|
- This is only used by the V(selfsigned) provider.
|
||||||
|
type: str
|
||||||
|
choices: [create_if_not_provided, always_create, never_create]
|
||||||
|
default: create_if_not_provided
|
||||||
|
"""
|
||||||
343
plugins/doc_fragments/_module_csr.py
Normal file
343
plugins/doc_fragments/_module_csr.py
Normal file
@@ -0,0 +1,343 @@
|
|||||||
|
# Copyright (c) 2017, Yanis Guenane <yanis+ansible@guenane.org>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this doc fragment is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleDocFragment:
|
||||||
|
# Standard files documentation fragment
|
||||||
|
DOCUMENTATION = r"""
|
||||||
|
description:
|
||||||
|
- This module allows one to (re)generate OpenSSL certificate signing requests.
|
||||||
|
- This module supports the subjectAltName, keyUsage, extendedKeyUsage, basicConstraints and OCSP Must Staple extensions.
|
||||||
|
attributes:
|
||||||
|
diff_mode:
|
||||||
|
support: full
|
||||||
|
idempotent:
|
||||||
|
support: full
|
||||||
|
requirements:
|
||||||
|
- cryptography >= 3.3
|
||||||
|
options:
|
||||||
|
digest:
|
||||||
|
description:
|
||||||
|
- The digest used when signing the certificate signing request with the private key.
|
||||||
|
type: str
|
||||||
|
default: sha256
|
||||||
|
privatekey_path:
|
||||||
|
description:
|
||||||
|
- The path to the private key to use when signing the certificate signing request.
|
||||||
|
- Either O(privatekey_path) or O(privatekey_content) must be specified if O(state) is V(present), but not both.
|
||||||
|
type: path
|
||||||
|
privatekey_content:
|
||||||
|
description:
|
||||||
|
- The content of the private key to use when signing the certificate signing request.
|
||||||
|
- Either O(privatekey_path) or O(privatekey_content) must be specified if O(state) is V(present), but not both.
|
||||||
|
type: str
|
||||||
|
privatekey_passphrase:
|
||||||
|
description:
|
||||||
|
- The passphrase for the private key.
|
||||||
|
- This is required if the private key is password protected.
|
||||||
|
type: str
|
||||||
|
version:
|
||||||
|
description:
|
||||||
|
- The version of the certificate signing request.
|
||||||
|
- The only allowed value according to L(RFC 2986,https://tools.ietf.org/html/rfc2986#section-4.1) is 1.
|
||||||
|
- This option no longer accepts unsupported values since community.crypto 2.0.0.
|
||||||
|
type: int
|
||||||
|
default: 1
|
||||||
|
choices:
|
||||||
|
- 1
|
||||||
|
subject:
|
||||||
|
description:
|
||||||
|
- Key/value pairs that will be present in the subject name field of the certificate signing request.
|
||||||
|
- If you need to specify more than one value with the same key, use a list as value.
|
||||||
|
- If the order of the components is important, use O(subject_ordered).
|
||||||
|
- Mutually exclusive with O(subject_ordered).
|
||||||
|
type: dict
|
||||||
|
subject_ordered:
|
||||||
|
description:
|
||||||
|
- A list of dictionaries, where every dictionary must contain one key/value pair. This key/value pair will be present
|
||||||
|
in the subject name field of the certificate signing request.
|
||||||
|
- If you want to specify more than one value with the same key in a row, you can use a list as value.
|
||||||
|
- Mutually exclusive with O(subject), and any other subject field option, such as O(country_name), O(state_or_province_name),
|
||||||
|
O(locality_name), O(organization_name), O(organizational_unit_name), O(common_name), or O(email_address).
|
||||||
|
type: list
|
||||||
|
elements: dict
|
||||||
|
version_added: 2.0.0
|
||||||
|
country_name:
|
||||||
|
description:
|
||||||
|
- The countryName field of the certificate signing request subject.
|
||||||
|
type: str
|
||||||
|
aliases:
|
||||||
|
- C
|
||||||
|
- countryName
|
||||||
|
state_or_province_name:
|
||||||
|
description:
|
||||||
|
- The stateOrProvinceName field of the certificate signing request subject.
|
||||||
|
type: str
|
||||||
|
aliases:
|
||||||
|
- ST
|
||||||
|
- stateOrProvinceName
|
||||||
|
locality_name:
|
||||||
|
description:
|
||||||
|
- The localityName field of the certificate signing request subject.
|
||||||
|
type: str
|
||||||
|
aliases:
|
||||||
|
- L
|
||||||
|
- localityName
|
||||||
|
organization_name:
|
||||||
|
description:
|
||||||
|
- The organizationName field of the certificate signing request subject.
|
||||||
|
type: str
|
||||||
|
aliases:
|
||||||
|
- O
|
||||||
|
- organizationName
|
||||||
|
organizational_unit_name:
|
||||||
|
description:
|
||||||
|
- The organizationalUnitName field of the certificate signing request subject.
|
||||||
|
type: str
|
||||||
|
aliases:
|
||||||
|
- OU
|
||||||
|
- organizationalUnitName
|
||||||
|
common_name:
|
||||||
|
description:
|
||||||
|
- The commonName field of the certificate signing request subject.
|
||||||
|
type: str
|
||||||
|
aliases:
|
||||||
|
- CN
|
||||||
|
- commonName
|
||||||
|
email_address:
|
||||||
|
description:
|
||||||
|
- The emailAddress field of the certificate signing request subject.
|
||||||
|
type: str
|
||||||
|
aliases:
|
||||||
|
- E
|
||||||
|
- emailAddress
|
||||||
|
subject_alt_name:
|
||||||
|
description:
|
||||||
|
- Subject Alternative Name (SAN) extension to attach to the certificate signing request.
|
||||||
|
- Values must be prefixed by their options. (These are C(email), C(URI), C(DNS), C(RID), C(IP), C(dirName), C(otherName),
|
||||||
|
and the ones specific to your CA).
|
||||||
|
- Note that if no SAN is specified, but a common name, the common name will be added as a SAN except if O(use_common_name_for_san)
|
||||||
|
is set to V(false).
|
||||||
|
- More at U(https://tools.ietf.org/html/rfc5280#section-4.2.1.6).
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
aliases:
|
||||||
|
- subjectAltName
|
||||||
|
subject_alt_name_critical:
|
||||||
|
description:
|
||||||
|
- Should the subjectAltName extension be considered as critical.
|
||||||
|
type: bool
|
||||||
|
default: false
|
||||||
|
aliases:
|
||||||
|
- subjectAltName_critical
|
||||||
|
use_common_name_for_san:
|
||||||
|
description:
|
||||||
|
- If set to V(true), the module will fill the common name in for O(subject_alt_name) with C(DNS:) prefix if no SAN is
|
||||||
|
specified.
|
||||||
|
type: bool
|
||||||
|
default: true
|
||||||
|
aliases:
|
||||||
|
- useCommonNameForSAN
|
||||||
|
key_usage:
|
||||||
|
description:
|
||||||
|
- This defines the purpose (for example encipherment, signature, certificate signing) of the key contained in the certificate.
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
aliases:
|
||||||
|
- keyUsage
|
||||||
|
key_usage_critical:
|
||||||
|
description:
|
||||||
|
- Should the keyUsage extension be considered as critical.
|
||||||
|
type: bool
|
||||||
|
default: false
|
||||||
|
aliases:
|
||||||
|
- keyUsage_critical
|
||||||
|
extended_key_usage:
|
||||||
|
description:
|
||||||
|
- Additional restrictions (for example client authentication, server authentication) on the allowed purposes for which
|
||||||
|
the public key may be used.
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
aliases:
|
||||||
|
- extKeyUsage
|
||||||
|
- extendedKeyUsage
|
||||||
|
extended_key_usage_critical:
|
||||||
|
description:
|
||||||
|
- Should the extkeyUsage extension be considered as critical.
|
||||||
|
type: bool
|
||||||
|
default: false
|
||||||
|
aliases:
|
||||||
|
- extKeyUsage_critical
|
||||||
|
- extendedKeyUsage_critical
|
||||||
|
basic_constraints:
|
||||||
|
description:
|
||||||
|
- Indicates basic constraints, such as if the certificate is a CA.
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
aliases:
|
||||||
|
- basicConstraints
|
||||||
|
basic_constraints_critical:
|
||||||
|
description:
|
||||||
|
- Should the basicConstraints extension be considered as critical.
|
||||||
|
type: bool
|
||||||
|
default: false
|
||||||
|
aliases:
|
||||||
|
- basicConstraints_critical
|
||||||
|
ocsp_must_staple:
|
||||||
|
description:
|
||||||
|
- Indicates that the certificate should contain the OCSP Must Staple extension (U(https://tools.ietf.org/html/rfc7633)).
|
||||||
|
type: bool
|
||||||
|
default: false
|
||||||
|
aliases:
|
||||||
|
- ocspMustStaple
|
||||||
|
ocsp_must_staple_critical:
|
||||||
|
description:
|
||||||
|
- Should the OCSP Must Staple extension be considered as critical.
|
||||||
|
- Note that according to the RFC, this extension should not be marked as critical, as old clients not knowing about
|
||||||
|
OCSP Must Staple are required to reject such certificates (see U(https://tools.ietf.org/html/rfc7633#section-4)).
|
||||||
|
type: bool
|
||||||
|
default: false
|
||||||
|
aliases:
|
||||||
|
- ocspMustStaple_critical
|
||||||
|
name_constraints_permitted:
|
||||||
|
description:
|
||||||
|
- For CA certificates, this specifies a list of identifiers which describe subtrees of names that this CA is allowed
|
||||||
|
to issue certificates for.
|
||||||
|
- Values must be prefixed by their options. (That is, C(email), C(URI), C(DNS), C(RID), C(IP), C(dirName), C(otherName),
|
||||||
|
and the ones specific to your CA).
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
name_constraints_excluded:
|
||||||
|
description:
|
||||||
|
- For CA certificates, this specifies a list of identifiers which describe subtrees of names that this CA is B(not)
|
||||||
|
allowed to issue certificates for.
|
||||||
|
- Values must be prefixed by their options. (That is, C(email), C(URI), C(DNS), C(RID), C(IP), C(dirName), C(otherName),
|
||||||
|
and the ones specific to your CA).
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
name_constraints_critical:
|
||||||
|
description:
|
||||||
|
- Should the Name Constraints extension be considered as critical.
|
||||||
|
type: bool
|
||||||
|
default: false
|
||||||
|
select_crypto_backend:
|
||||||
|
description:
|
||||||
|
- Determines which crypto backend to use.
|
||||||
|
- The default choice is V(auto), which tries to use C(cryptography) if available.
|
||||||
|
- If set to V(cryptography), will try to use the L(cryptography,https://cryptography.io/) library.
|
||||||
|
- Note that with community.crypto 3.0.0, all values behave the same.
|
||||||
|
This option will be deprecated in a later version.
|
||||||
|
We recommend to not set it explicitly.
|
||||||
|
type: str
|
||||||
|
default: auto
|
||||||
|
choices: [auto, cryptography]
|
||||||
|
create_subject_key_identifier:
|
||||||
|
description:
|
||||||
|
- Create the Subject Key Identifier from the public key.
|
||||||
|
- Please note that commercial CAs can ignore the value, respectively use a value of their own choice instead. Specifying
|
||||||
|
this option is mostly useful for self-signed certificates or for own CAs.
|
||||||
|
type: bool
|
||||||
|
default: false
|
||||||
|
subject_key_identifier:
|
||||||
|
description:
|
||||||
|
- The subject key identifier as a hex string, where two bytes are separated by colons.
|
||||||
|
- 'Example: V(00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33).'
|
||||||
|
- Please note that commercial CAs ignore this value, respectively use a value of their own choice. Specifying this option
|
||||||
|
is mostly useful for self-signed certificates or for own CAs.
|
||||||
|
- Note that this option can only be used if O(create_subject_key_identifier) is V(false).
|
||||||
|
type: str
|
||||||
|
authority_key_identifier:
|
||||||
|
description:
|
||||||
|
- The authority key identifier as a hex string, where two bytes are separated by colons.
|
||||||
|
- 'Example: V(00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33).'
|
||||||
|
- Please note that commercial CAs ignore this value, respectively use a value of their own choice. Specifying this option
|
||||||
|
is mostly useful for self-signed certificates or for own CAs.
|
||||||
|
- The C(AuthorityKeyIdentifier) extension will only be added if at least one of O(authority_key_identifier), O(authority_cert_issuer)
|
||||||
|
and O(authority_cert_serial_number) is specified.
|
||||||
|
type: str
|
||||||
|
authority_cert_issuer:
|
||||||
|
description:
|
||||||
|
- Names that will be present in the authority cert issuer field of the certificate signing request.
|
||||||
|
- Values must be prefixed by their options. (That is, C(email), C(URI), C(DNS), C(RID), C(IP), C(dirName), C(otherName),
|
||||||
|
and the ones specific to your CA).
|
||||||
|
- 'Example: V(DNS:ca.example.org).'
|
||||||
|
- If specified, O(authority_cert_serial_number) must also be specified.
|
||||||
|
- Please note that commercial CAs ignore this value, respectively use a value of their own choice. Specifying this option
|
||||||
|
is mostly useful for self-signed certificates or for own CAs.
|
||||||
|
- The C(AuthorityKeyIdentifier) extension will only be added if at least one of O(authority_key_identifier), O(authority_cert_issuer)
|
||||||
|
and O(authority_cert_serial_number) is specified.
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
authority_cert_serial_number:
|
||||||
|
description:
|
||||||
|
- The authority cert serial number.
|
||||||
|
- If specified, O(authority_cert_issuer) must also be specified.
|
||||||
|
- Please note that commercial CAs ignore this value, respectively use a value of their own choice. Specifying this option
|
||||||
|
is mostly useful for self-signed certificates or for own CAs.
|
||||||
|
- The C(AuthorityKeyIdentifier) extension will only be added if at least one of O(authority_key_identifier), O(authority_cert_issuer)
|
||||||
|
and O(authority_cert_serial_number) is specified.
|
||||||
|
- This option accepts an B(integer). If you want to provide serial numbers as colon-separated hex strings, such as C(11:22:33),
|
||||||
|
you need to convert them to an integer with P(community.crypto.parse_serial#filter).
|
||||||
|
type: int
|
||||||
|
crl_distribution_points:
|
||||||
|
description:
|
||||||
|
- Allows to specify one or multiple CRL distribution points.
|
||||||
|
type: list
|
||||||
|
elements: dict
|
||||||
|
suboptions:
|
||||||
|
full_name:
|
||||||
|
description:
|
||||||
|
- Describes how the CRL can be retrieved.
|
||||||
|
- Mutually exclusive with O(crl_distribution_points[].relative_name).
|
||||||
|
- 'Example: V(URI:https://ca.example.com/revocations.crl).'
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
relative_name:
|
||||||
|
description:
|
||||||
|
- Describes how the CRL can be retrieved relative to the CRL issuer.
|
||||||
|
- Mutually exclusive with O(crl_distribution_points[].full_name).
|
||||||
|
- 'Example: V(/CN=example.com).'
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
crl_issuer:
|
||||||
|
description:
|
||||||
|
- Information about the issuer of the CRL.
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
reasons:
|
||||||
|
description:
|
||||||
|
- List of reasons that this distribution point can be used for when performing revocation checks.
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
choices:
|
||||||
|
- key_compromise
|
||||||
|
- ca_compromise
|
||||||
|
- affiliation_changed
|
||||||
|
- superseded
|
||||||
|
- cessation_of_operation
|
||||||
|
- certificate_hold
|
||||||
|
- privilege_withdrawn
|
||||||
|
- aa_compromise
|
||||||
|
version_added: 1.4.0
|
||||||
|
notes:
|
||||||
|
- If the certificate signing request already exists it will be checked whether subjectAltName, keyUsage, extendedKeyUsage
|
||||||
|
and basicConstraints only contain the requested values, whether OCSP Must Staple is as requested, and if the request was
|
||||||
|
signed by the given private key.
|
||||||
|
seealso:
|
||||||
|
- module: community.crypto.x509_certificate
|
||||||
|
- module: community.crypto.x509_certificate_pipe
|
||||||
|
- module: community.crypto.openssl_dhparam
|
||||||
|
- module: community.crypto.openssl_pkcs12
|
||||||
|
- module: community.crypto.openssl_privatekey
|
||||||
|
- module: community.crypto.openssl_privatekey_pipe
|
||||||
|
- module: community.crypto.openssl_publickey
|
||||||
|
- module: community.crypto.openssl_csr_info
|
||||||
|
- plugin: community.crypto.parse_serial
|
||||||
|
plugin_type: filter
|
||||||
|
"""
|
||||||
145
plugins/doc_fragments/_module_privatekey.py
Normal file
145
plugins/doc_fragments/_module_privatekey.py
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
# Copyright (c) 2016, Yanis Guenane <yanis+ansible@guenane.org>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this doc fragment is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleDocFragment:
|
||||||
|
# Standard files documentation fragment
|
||||||
|
DOCUMENTATION = r"""
|
||||||
|
description:
|
||||||
|
- One can generate L(RSA,https://en.wikipedia.org/wiki/RSA_%28cryptosystem%29), L(DSA,https://en.wikipedia.org/wiki/Digital_Signature_Algorithm),
|
||||||
|
L(ECC,https://en.wikipedia.org/wiki/Elliptic-curve_cryptography) or L(EdDSA,https://en.wikipedia.org/wiki/EdDSA) private
|
||||||
|
keys.
|
||||||
|
- Keys are generated in PEM format.
|
||||||
|
attributes:
|
||||||
|
diff_mode:
|
||||||
|
support: full
|
||||||
|
idempotent:
|
||||||
|
support: partial
|
||||||
|
details:
|
||||||
|
- The option O(regenerate=always) generally disables idempotency.
|
||||||
|
requirements:
|
||||||
|
- cryptography >= 3.3
|
||||||
|
options:
|
||||||
|
size:
|
||||||
|
description:
|
||||||
|
- Size (in bits) of the TLS/SSL key to generate.
|
||||||
|
type: int
|
||||||
|
default: 4096
|
||||||
|
type:
|
||||||
|
description:
|
||||||
|
- The algorithm used to generate the TLS/SSL private key.
|
||||||
|
type: str
|
||||||
|
default: RSA
|
||||||
|
choices: [DSA, ECC, Ed25519, Ed448, RSA, X25519, X448]
|
||||||
|
curve:
|
||||||
|
description:
|
||||||
|
- Note that not all curves are supported by all versions of C(cryptography).
|
||||||
|
- For maximal interoperability, V(secp384r1) or V(secp256r1) should be used.
|
||||||
|
- We use the curve names as defined in the L(IANA registry for TLS,https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8).
|
||||||
|
- Please note that all curves except V(secp224r1), V(secp256k1), V(secp256r1), V(secp384r1), and V(secp521r1) are discouraged
|
||||||
|
for new private keys.
|
||||||
|
type: str
|
||||||
|
choices:
|
||||||
|
- secp224r1
|
||||||
|
- secp256k1
|
||||||
|
- secp256r1
|
||||||
|
- secp384r1
|
||||||
|
- secp521r1
|
||||||
|
- secp192r1
|
||||||
|
- brainpoolP256r1
|
||||||
|
- brainpoolP384r1
|
||||||
|
- brainpoolP512r1
|
||||||
|
- sect163k1
|
||||||
|
- sect163r2
|
||||||
|
- sect233k1
|
||||||
|
- sect233r1
|
||||||
|
- sect283k1
|
||||||
|
- sect283r1
|
||||||
|
- sect409k1
|
||||||
|
- sect409r1
|
||||||
|
- sect571k1
|
||||||
|
- sect571r1
|
||||||
|
passphrase:
|
||||||
|
description:
|
||||||
|
- The passphrase for the private key.
|
||||||
|
type: str
|
||||||
|
cipher:
|
||||||
|
description:
|
||||||
|
- The cipher to encrypt the private key. This is only used when O(passphrase) is provided.
|
||||||
|
- Must be V(auto).
|
||||||
|
type: str
|
||||||
|
default: auto
|
||||||
|
select_crypto_backend:
|
||||||
|
description:
|
||||||
|
- Determines which crypto backend to use.
|
||||||
|
- The default choice is V(auto), which tries to use C(cryptography) if available.
|
||||||
|
- If set to V(cryptography), will try to use the L(cryptography,https://cryptography.io/) library.
|
||||||
|
- Note that with community.crypto 3.0.0, all values behave the same.
|
||||||
|
This option will be deprecated in a later version.
|
||||||
|
We recommend to not set it explicitly.
|
||||||
|
type: str
|
||||||
|
default: auto
|
||||||
|
choices: [auto, cryptography]
|
||||||
|
format:
|
||||||
|
description:
|
||||||
|
- Determines which format the private key is written in. By default, PKCS1 (traditional OpenSSL format) is used for
|
||||||
|
all keys which support it. Please note that not every key can be exported in any format.
|
||||||
|
- The value V(auto) selects a format based on the key format. The value V(auto_ignore) does the same, but for existing
|
||||||
|
private key files, it will not force a regenerate when its format is not the automatically selected one for generation.
|
||||||
|
- Note that if the format for an existing private key mismatches, the key is B(regenerated) by default. To change this
|
||||||
|
behavior, use the O(format_mismatch) option.
|
||||||
|
type: str
|
||||||
|
default: auto_ignore
|
||||||
|
choices: [pkcs1, pkcs8, raw, auto, auto_ignore]
|
||||||
|
format_mismatch:
|
||||||
|
description:
|
||||||
|
- Determines behavior of the module if the format of a private key does not match the expected format, but all other
|
||||||
|
parameters are as expected.
|
||||||
|
- If set to V(regenerate) (default), generates a new private key.
|
||||||
|
- If set to V(convert), the key will be converted to the new format instead.
|
||||||
|
type: str
|
||||||
|
default: regenerate
|
||||||
|
choices: [regenerate, convert]
|
||||||
|
regenerate:
|
||||||
|
description:
|
||||||
|
- Allows to configure in which situations the module is allowed to regenerate private keys. The module will always generate
|
||||||
|
a new key if the destination file does not exist.
|
||||||
|
- By default, the key will be regenerated when it does not match the module's options, except when the key cannot be
|
||||||
|
read or the passphrase does not match. Please note that this B(changed) for Ansible 2.10. For Ansible 2.9, the behavior
|
||||||
|
was as if V(full_idempotence) is specified.
|
||||||
|
- If set to V(never), the module will fail if the key cannot be read or the passphrase is not matching, and will never
|
||||||
|
regenerate an existing key.
|
||||||
|
- If set to V(fail), the module will fail if the key does not correspond to the module's options.
|
||||||
|
- If set to V(partial_idempotence), the key will be regenerated if it does not conform to the module's options. The
|
||||||
|
key is B(not) regenerated if it cannot be read (broken file), the key is protected by an unknown passphrase, or when
|
||||||
|
they key is not protected by a passphrase, but a passphrase is specified.
|
||||||
|
- If set to V(full_idempotence), the key will be regenerated if it does not conform to the module's options. This is
|
||||||
|
also the case if the key cannot be read (broken file), the key is protected by an unknown passphrase, or when they
|
||||||
|
key is not protected by a passphrase, but a passphrase is specified. Make sure you have a B(backup) when using this
|
||||||
|
option!
|
||||||
|
- If set to V(always), the module will always regenerate the key. This is equivalent to setting O(force) to V(true).
|
||||||
|
- Note that if O(format_mismatch) is set to V(convert) and everything matches except the format, the key will always
|
||||||
|
be converted, except if O(regenerate) is set to V(always).
|
||||||
|
type: str
|
||||||
|
choices:
|
||||||
|
- never
|
||||||
|
- fail
|
||||||
|
- partial_idempotence
|
||||||
|
- full_idempotence
|
||||||
|
- always
|
||||||
|
default: full_idempotence
|
||||||
|
seealso:
|
||||||
|
- module: community.crypto.x509_certificate
|
||||||
|
- module: community.crypto.x509_certificate_pipe
|
||||||
|
- module: community.crypto.openssl_csr
|
||||||
|
- module: community.crypto.openssl_csr_pipe
|
||||||
|
- module: community.crypto.openssl_dhparam
|
||||||
|
- module: community.crypto.openssl_pkcs12
|
||||||
|
- module: community.crypto.openssl_publickey
|
||||||
|
"""
|
||||||
51
plugins/doc_fragments/_module_privatekey_convert.py
Normal file
51
plugins/doc_fragments/_module_privatekey_convert.py
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
# Copyright (c) 2022, Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this doc fragment is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleDocFragment:
|
||||||
|
# Standard files documentation fragment
|
||||||
|
DOCUMENTATION = r"""
|
||||||
|
requirements:
|
||||||
|
- cryptography >= 3.3
|
||||||
|
attributes:
|
||||||
|
diff_mode:
|
||||||
|
support: none
|
||||||
|
idempotent:
|
||||||
|
support: full
|
||||||
|
options:
|
||||||
|
src_path:
|
||||||
|
description:
|
||||||
|
- Name of the file containing the OpenSSL private key to convert.
|
||||||
|
- Exactly one of O(src_path) or O(src_content) must be specified.
|
||||||
|
type: path
|
||||||
|
src_content:
|
||||||
|
description:
|
||||||
|
- The content of the file containing the OpenSSL private key to convert.
|
||||||
|
- Exactly one of O(src_path) or O(src_content) must be specified.
|
||||||
|
type: str
|
||||||
|
src_passphrase:
|
||||||
|
description:
|
||||||
|
- The passphrase for the private key to load.
|
||||||
|
type: str
|
||||||
|
dest_passphrase:
|
||||||
|
description:
|
||||||
|
- The passphrase for the private key to store.
|
||||||
|
type: str
|
||||||
|
format:
|
||||||
|
description:
|
||||||
|
- Determines which format the destination private key should be written in.
|
||||||
|
- Please note that not every key can be exported in any format, and that not every format supports encryption.
|
||||||
|
type: str
|
||||||
|
choices: [pkcs1, pkcs8, raw]
|
||||||
|
required: true
|
||||||
|
seealso:
|
||||||
|
- module: community.crypto.openssl_privatekey
|
||||||
|
- module: community.crypto.openssl_privatekey_pipe
|
||||||
|
- module: community.crypto.openssl_publickey
|
||||||
|
"""
|
||||||
32
plugins/doc_fragments/_name_encoding.py
Normal file
32
plugins/doc_fragments/_name_encoding.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# Copyright (c) 2022, Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this doc fragment is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleDocFragment:
|
||||||
|
DOCUMENTATION = r"""
|
||||||
|
options:
|
||||||
|
name_encoding:
|
||||||
|
description:
|
||||||
|
- How to encode names (DNS names, URIs, email addresses) in return values.
|
||||||
|
- V(ignore) will use the encoding returned by the backend.
|
||||||
|
- V(idna) will convert all labels of domain names to IDNA encoding. IDNA2008 will be preferred, and IDNA2003 will be
|
||||||
|
used if IDNA2008 encoding fails.
|
||||||
|
- V(unicode) will convert all labels of domain names to Unicode. IDNA2008 will be preferred, and IDNA2003 will be used
|
||||||
|
if IDNA2008 decoding fails.
|
||||||
|
- B(Note) that V(idna) and V(unicode) require the L(idna Python library,https://pypi.org/project/idna/) to be installed.
|
||||||
|
type: str
|
||||||
|
default: ignore
|
||||||
|
choices:
|
||||||
|
- ignore
|
||||||
|
- idna
|
||||||
|
- unicode
|
||||||
|
requirements:
|
||||||
|
- If O(name_encoding) is set to another value than V(ignore), the L(idna Python library,https://pypi.org/project/idna/)
|
||||||
|
needs to be installed.
|
||||||
|
"""
|
||||||
@@ -1,136 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Copyright: (c) 2016 Michael Gruener <michael.gruener@chaosmoon.net>
|
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
|
|
||||||
class ModuleDocFragment(object):
|
|
||||||
|
|
||||||
# Standard files documentation fragment
|
|
||||||
DOCUMENTATION = r'''
|
|
||||||
notes:
|
|
||||||
- "If a new enough version of the C(cryptography) library
|
|
||||||
is available (see Requirements for details), it will be used
|
|
||||||
instead of the C(openssl) binary. This can be explicitly disabled
|
|
||||||
or enabled with the C(select_crypto_backend) option. Note that using
|
|
||||||
the C(openssl) binary will be slower and less secure, as private key
|
|
||||||
contents always have to be stored on disk (see
|
|
||||||
C(account_key_content))."
|
|
||||||
- "Although the defaults are chosen so that the module can be used with
|
|
||||||
the L(Let's Encrypt,https://letsencrypt.org/) CA, the module can in
|
|
||||||
principle be used with any CA providing an ACME endpoint, such as
|
|
||||||
L(Buypass Go SSL,https://www.buypass.com/ssl/products/acme)."
|
|
||||||
- "So far, the ACME modules have only been tested by the developers against
|
|
||||||
Let's Encrypt (staging and production), Buypass (staging and production), ZeroSSL (production),
|
|
||||||
and L(Pebble testing server,https://github.com/letsencrypt/Pebble). We have got
|
|
||||||
community feedback that they also work with Sectigo ACME Service for InCommon.
|
|
||||||
If you experience problems with another ACME server, please
|
|
||||||
L(create an issue,https://github.com/ansible-collections/community.crypto/issues/new/choose)
|
|
||||||
to help us supporting it. Feedback that an ACME server not mentioned does work
|
|
||||||
is also appreciated."
|
|
||||||
requirements:
|
|
||||||
- either openssl or L(cryptography,https://cryptography.io/) >= 1.5
|
|
||||||
- ipaddress
|
|
||||||
options:
|
|
||||||
account_key_src:
|
|
||||||
description:
|
|
||||||
- "Path to a file containing the ACME account RSA or Elliptic Curve
|
|
||||||
key."
|
|
||||||
- "Private keys can be created with the
|
|
||||||
M(community.crypto.openssl_privatekey) or M(community.crypto.openssl_privatekey_pipe)
|
|
||||||
modules. If the requisite (cryptography) is not available,
|
|
||||||
keys can also be created directly with the C(openssl) command line tool:
|
|
||||||
RSA keys can be created with C(openssl genrsa ...). Elliptic curve keys
|
|
||||||
can be created with C(openssl ecparam -genkey ...). Any other tool creating
|
|
||||||
private keys in PEM format can be used as well."
|
|
||||||
- "Mutually exclusive with C(account_key_content)."
|
|
||||||
- "Required if C(account_key_content) is not used."
|
|
||||||
type: path
|
|
||||||
aliases: [ account_key ]
|
|
||||||
account_key_content:
|
|
||||||
description:
|
|
||||||
- "Content of the ACME account RSA or Elliptic Curve key."
|
|
||||||
- "Mutually exclusive with C(account_key_src)."
|
|
||||||
- "Required if C(account_key_src) is not used."
|
|
||||||
- "B(Warning:) the content will be written into a temporary file, which will
|
|
||||||
be deleted by Ansible when the module completes. Since this is an
|
|
||||||
important private key — it can be used to change the account key,
|
|
||||||
or to revoke your certificates without knowing their private keys
|
|
||||||
—, this might not be acceptable."
|
|
||||||
- "In case C(cryptography) is used, the content is not written into a
|
|
||||||
temporary file. It can still happen that it is written to disk by
|
|
||||||
Ansible in the process of moving the module with its argument to
|
|
||||||
the node where it is executed."
|
|
||||||
type: str
|
|
||||||
account_key_passphrase:
|
|
||||||
description:
|
|
||||||
- Phassphrase to use to decode the account key.
|
|
||||||
- "B(Note:) this is not supported by the C(openssl) backend, only by the C(cryptography) backend."
|
|
||||||
type: str
|
|
||||||
version_added: 1.6.0
|
|
||||||
account_uri:
|
|
||||||
description:
|
|
||||||
- "If specified, assumes that the account URI is as given. If the
|
|
||||||
account key does not match this account, or an account with this
|
|
||||||
URI does not exist, the module fails."
|
|
||||||
type: str
|
|
||||||
acme_version:
|
|
||||||
description:
|
|
||||||
- "The ACME version of the endpoint."
|
|
||||||
- "Must be C(1) for the classic Let's Encrypt and Buypass ACME endpoints,
|
|
||||||
or C(2) for standardized ACME v2 endpoints."
|
|
||||||
- "The value C(1) is deprecated since community.crypto 2.0.0 and will be
|
|
||||||
removed from community.crypto 3.0.0."
|
|
||||||
required: true
|
|
||||||
type: int
|
|
||||||
choices: [ 1, 2 ]
|
|
||||||
acme_directory:
|
|
||||||
description:
|
|
||||||
- "The ACME directory to use. This is the entry point URL to access
|
|
||||||
the ACME CA server API."
|
|
||||||
- "For safety reasons the default is set to the Let's Encrypt staging
|
|
||||||
server (for the ACME v1 protocol). This will create technically correct,
|
|
||||||
but untrusted certificates."
|
|
||||||
- "For Let's Encrypt, all staging endpoints can be found here:
|
|
||||||
U(https://letsencrypt.org/docs/staging-environment/). For Buypass, all
|
|
||||||
endpoints can be found here:
|
|
||||||
U(https://community.buypass.com/t/63d4ay/buypass-go-ssl-endpoints)"
|
|
||||||
- "For B(Let's Encrypt), the production directory URL for ACME v2 is
|
|
||||||
U(https://acme-v02.api.letsencrypt.org/directory)."
|
|
||||||
- "For B(Buypass), the production directory URL for ACME v2 and v1 is
|
|
||||||
U(https://api.buypass.com/acme/directory)."
|
|
||||||
- "For B(ZeroSSL), the production directory URL for ACME v2 is
|
|
||||||
U(https://acme.zerossl.com/v2/DV90)."
|
|
||||||
- The notes for this module contain a list of ACME services this module has
|
|
||||||
been tested against.
|
|
||||||
required: true
|
|
||||||
type: str
|
|
||||||
validate_certs:
|
|
||||||
description:
|
|
||||||
- Whether calls to the ACME directory will validate TLS certificates.
|
|
||||||
- "B(Warning:) Should B(only ever) be set to C(no) for testing purposes,
|
|
||||||
for example when testing against a local Pebble server."
|
|
||||||
type: bool
|
|
||||||
default: yes
|
|
||||||
select_crypto_backend:
|
|
||||||
description:
|
|
||||||
- Determines which crypto backend to use.
|
|
||||||
- The default choice is C(auto), which tries to use C(cryptography) if available, and falls back to
|
|
||||||
C(openssl).
|
|
||||||
- If set to C(openssl), will try to use the C(openssl) binary.
|
|
||||||
- If set to C(cryptography), will try to use the
|
|
||||||
L(cryptography,https://cryptography.io/) library.
|
|
||||||
type: str
|
|
||||||
default: auto
|
|
||||||
choices: [ auto, cryptography, openssl ]
|
|
||||||
request_timeout:
|
|
||||||
description:
|
|
||||||
- The time Ansible should wait for a response from the ACME API.
|
|
||||||
- This timeout is applied to all HTTP(S) requests (HEAD, GET, POST).
|
|
||||||
type: int
|
|
||||||
default: 10
|
|
||||||
version_added: 2.3.0
|
|
||||||
'''
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Copyright (c), Entrust Datacard Corporation, 2019
|
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
|
|
||||||
class ModuleDocFragment(object):
|
|
||||||
|
|
||||||
# Plugin options for Entrust Certificate Services (ECS) credentials
|
|
||||||
DOCUMENTATION = r'''
|
|
||||||
options:
|
|
||||||
entrust_api_user:
|
|
||||||
description:
|
|
||||||
- The username for authentication to the Entrust Certificate Services (ECS) API.
|
|
||||||
type: str
|
|
||||||
required: true
|
|
||||||
entrust_api_key:
|
|
||||||
description:
|
|
||||||
- The key (password) for authentication to the Entrust Certificate Services (ECS) API.
|
|
||||||
type: str
|
|
||||||
required: true
|
|
||||||
entrust_api_client_cert_path:
|
|
||||||
description:
|
|
||||||
- The path to the client certificate used to authenticate to the Entrust Certificate Services (ECS) API.
|
|
||||||
type: path
|
|
||||||
required: true
|
|
||||||
entrust_api_client_cert_key_path:
|
|
||||||
description:
|
|
||||||
- The path to the key for the client certificate used to authenticate to the Entrust Certificate Services (ECS) API.
|
|
||||||
type: path
|
|
||||||
required: true
|
|
||||||
entrust_api_specification_path:
|
|
||||||
description:
|
|
||||||
- The path to the specification file defining the Entrust Certificate Services (ECS) API configuration.
|
|
||||||
- You can use this to keep a local copy of the specification to avoid downloading it every time the module is used.
|
|
||||||
type: path
|
|
||||||
default: https://cloud.entrust.net/EntrustCloud/documentation/cms-api-2.1.0.yaml
|
|
||||||
requirements:
|
|
||||||
- "PyYAML >= 3.11"
|
|
||||||
'''
|
|
||||||
@@ -1,403 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Copyright: (c) 2016-2017, Yanis Guenane <yanis+ansible@guenane.org>
|
|
||||||
# Copyright: (c) 2017, Markus Teufelberger <mteufelberger+ansible@mgit.at>
|
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
|
|
||||||
class ModuleDocFragment(object):
|
|
||||||
|
|
||||||
# Standard files documentation fragment
|
|
||||||
DOCUMENTATION = r'''
|
|
||||||
description:
|
|
||||||
- This module allows one to (re)generate OpenSSL certificates.
|
|
||||||
- It uses the cryptography python library to interact with OpenSSL.
|
|
||||||
requirements:
|
|
||||||
- cryptography >= 1.6 (if using C(selfsigned) or C(ownca) provider)
|
|
||||||
options:
|
|
||||||
force:
|
|
||||||
description:
|
|
||||||
- Generate the certificate, even if it already exists.
|
|
||||||
type: bool
|
|
||||||
default: no
|
|
||||||
|
|
||||||
csr_path:
|
|
||||||
description:
|
|
||||||
- Path to the Certificate Signing Request (CSR) used to generate this certificate.
|
|
||||||
- This is mutually exclusive with I(csr_content).
|
|
||||||
type: path
|
|
||||||
csr_content:
|
|
||||||
description:
|
|
||||||
- Content of the Certificate Signing Request (CSR) used to generate this certificate.
|
|
||||||
- This is mutually exclusive with I(csr_path).
|
|
||||||
type: str
|
|
||||||
|
|
||||||
privatekey_path:
|
|
||||||
description:
|
|
||||||
- Path to the private key to use when signing the certificate.
|
|
||||||
- This is mutually exclusive with I(privatekey_content).
|
|
||||||
type: path
|
|
||||||
privatekey_content:
|
|
||||||
description:
|
|
||||||
- Path to the private key to use when signing the certificate.
|
|
||||||
- This is mutually exclusive with I(privatekey_path).
|
|
||||||
type: str
|
|
||||||
|
|
||||||
privatekey_passphrase:
|
|
||||||
description:
|
|
||||||
- The passphrase for the I(privatekey_path) resp. I(privatekey_content).
|
|
||||||
- This is required if the private key is password protected.
|
|
||||||
type: str
|
|
||||||
|
|
||||||
ignore_timestamps:
|
|
||||||
description:
|
|
||||||
- Whether the "not before" and "not after" timestamps should be ignored for idempotency checks.
|
|
||||||
- It is better to keep the default value C(true) when using relative timestamps (like C(+0s) for now).
|
|
||||||
type: bool
|
|
||||||
default: true
|
|
||||||
version_added: 2.0.0
|
|
||||||
|
|
||||||
select_crypto_backend:
|
|
||||||
description:
|
|
||||||
- Determines which crypto backend to use.
|
|
||||||
- The default choice is C(auto), which tries to use C(cryptography) if available.
|
|
||||||
- If set to C(cryptography), will try to use the L(cryptography,https://cryptography.io/) library.
|
|
||||||
type: str
|
|
||||||
default: auto
|
|
||||||
choices: [ auto, cryptography ]
|
|
||||||
|
|
||||||
notes:
|
|
||||||
- All ASN.1 TIME values should be specified following the YYYYMMDDHHMMSSZ pattern.
|
|
||||||
- Date specified should be UTC. Minutes and seconds are mandatory.
|
|
||||||
- For security reason, when you use C(ownca) provider, you should NOT run
|
|
||||||
M(community.crypto.x509_certificate) on a target machine, but on a dedicated CA machine. It
|
|
||||||
is recommended not to store the CA private key on the target machine. Once signed, the
|
|
||||||
certificate can be moved to the target machine.
|
|
||||||
seealso:
|
|
||||||
- module: community.crypto.openssl_csr
|
|
||||||
- module: community.crypto.openssl_csr_pipe
|
|
||||||
- module: community.crypto.openssl_dhparam
|
|
||||||
- module: community.crypto.openssl_pkcs12
|
|
||||||
- module: community.crypto.openssl_privatekey
|
|
||||||
- module: community.crypto.openssl_privatekey_pipe
|
|
||||||
- module: community.crypto.openssl_publickey
|
|
||||||
'''
|
|
||||||
|
|
||||||
BACKEND_ACME_DOCUMENTATION = r'''
|
|
||||||
description:
|
|
||||||
- This module allows one to (re)generate OpenSSL certificates.
|
|
||||||
requirements:
|
|
||||||
- acme-tiny >= 4.0.0 (if using the C(acme) provider)
|
|
||||||
options:
|
|
||||||
acme_accountkey_path:
|
|
||||||
description:
|
|
||||||
- The path to the accountkey for the C(acme) provider.
|
|
||||||
- This is only used by the C(acme) provider.
|
|
||||||
type: path
|
|
||||||
|
|
||||||
acme_challenge_path:
|
|
||||||
description:
|
|
||||||
- The path to the ACME challenge directory that is served on U(http://<HOST>:80/.well-known/acme-challenge/)
|
|
||||||
- This is only used by the C(acme) provider.
|
|
||||||
type: path
|
|
||||||
|
|
||||||
acme_chain:
|
|
||||||
description:
|
|
||||||
- Include the intermediate certificate to the generated certificate
|
|
||||||
- This is only used by the C(acme) provider.
|
|
||||||
- Note that this is only available for older versions of C(acme-tiny).
|
|
||||||
New versions include the chain automatically, and setting I(acme_chain) to C(yes) results in an error.
|
|
||||||
type: bool
|
|
||||||
default: no
|
|
||||||
|
|
||||||
acme_directory:
|
|
||||||
description:
|
|
||||||
- "The ACME directory to use. You can use any directory that supports the ACME protocol, such as Buypass or Let's Encrypt."
|
|
||||||
- "Let's Encrypt recommends using their staging server while developing jobs. U(https://letsencrypt.org/docs/staging-environment/)."
|
|
||||||
type: str
|
|
||||||
default: https://acme-v02.api.letsencrypt.org/directory
|
|
||||||
'''
|
|
||||||
|
|
||||||
BACKEND_ENTRUST_DOCUMENTATION = r'''
|
|
||||||
options:
|
|
||||||
entrust_cert_type:
|
|
||||||
description:
|
|
||||||
- Specify the type of certificate requested.
|
|
||||||
- This is only used by the C(entrust) provider.
|
|
||||||
type: str
|
|
||||||
default: STANDARD_SSL
|
|
||||||
choices: [ 'STANDARD_SSL', 'ADVANTAGE_SSL', 'UC_SSL', 'EV_SSL', 'WILDCARD_SSL', 'PRIVATE_SSL', 'PD_SSL', 'CDS_ENT_LITE', 'CDS_ENT_PRO', 'SMIME_ENT' ]
|
|
||||||
|
|
||||||
entrust_requester_email:
|
|
||||||
description:
|
|
||||||
- The email of the requester of the certificate (for tracking purposes).
|
|
||||||
- This is only used by the C(entrust) provider.
|
|
||||||
- This is required if the provider is C(entrust).
|
|
||||||
type: str
|
|
||||||
|
|
||||||
entrust_requester_name:
|
|
||||||
description:
|
|
||||||
- The name of the requester of the certificate (for tracking purposes).
|
|
||||||
- This is only used by the C(entrust) provider.
|
|
||||||
- This is required if the provider is C(entrust).
|
|
||||||
type: str
|
|
||||||
|
|
||||||
entrust_requester_phone:
|
|
||||||
description:
|
|
||||||
- The phone number of the requester of the certificate (for tracking purposes).
|
|
||||||
- This is only used by the C(entrust) provider.
|
|
||||||
- This is required if the provider is C(entrust).
|
|
||||||
type: str
|
|
||||||
|
|
||||||
entrust_api_user:
|
|
||||||
description:
|
|
||||||
- The username for authentication to the Entrust Certificate Services (ECS) API.
|
|
||||||
- This is only used by the C(entrust) provider.
|
|
||||||
- This is required if the provider is C(entrust).
|
|
||||||
type: str
|
|
||||||
|
|
||||||
entrust_api_key:
|
|
||||||
description:
|
|
||||||
- The key (password) for authentication to the Entrust Certificate Services (ECS) API.
|
|
||||||
- This is only used by the C(entrust) provider.
|
|
||||||
- This is required if the provider is C(entrust).
|
|
||||||
type: str
|
|
||||||
|
|
||||||
entrust_api_client_cert_path:
|
|
||||||
description:
|
|
||||||
- The path to the client certificate used to authenticate to the Entrust Certificate Services (ECS) API.
|
|
||||||
- This is only used by the C(entrust) provider.
|
|
||||||
- This is required if the provider is C(entrust).
|
|
||||||
type: path
|
|
||||||
|
|
||||||
entrust_api_client_cert_key_path:
|
|
||||||
description:
|
|
||||||
- The path to the private key of the client certificate used to authenticate to the Entrust Certificate Services (ECS) API.
|
|
||||||
- This is only used by the C(entrust) provider.
|
|
||||||
- This is required if the provider is C(entrust).
|
|
||||||
type: path
|
|
||||||
|
|
||||||
entrust_not_after:
|
|
||||||
description:
|
|
||||||
- The point in time at which the certificate stops being valid.
|
|
||||||
- Time can be specified either as relative time or as an absolute timestamp.
|
|
||||||
- A valid absolute time format is C(ASN.1 TIME) such as C(2019-06-18).
|
|
||||||
- A valid relative time format is C([+-]timespec) where timespec can be an integer + C([w | d | h | m | s]), such as C(+365d) or C(+32w1d2h)).
|
|
||||||
- Time will always be interpreted as UTC.
|
|
||||||
- Note that only the date (day, month, year) is supported for specifying the expiry date of the issued certificate.
|
|
||||||
- The full date-time is adjusted to EST (GMT -5:00) before issuance, which may result in a certificate with an expiration date one day
|
|
||||||
earlier than expected if a relative time is used.
|
|
||||||
- The minimum certificate lifetime is 90 days, and maximum is three years.
|
|
||||||
- If this value is not specified, the certificate will stop being valid 365 days the date of issue.
|
|
||||||
- This is only used by the C(entrust) provider.
|
|
||||||
- Please note that this value is B(not) covered by the I(ignore_timestamps) option.
|
|
||||||
type: str
|
|
||||||
default: +365d
|
|
||||||
|
|
||||||
entrust_api_specification_path:
|
|
||||||
description:
|
|
||||||
- The path to the specification file defining the Entrust Certificate Services (ECS) API configuration.
|
|
||||||
- You can use this to keep a local copy of the specification to avoid downloading it every time the module is used.
|
|
||||||
- This is only used by the C(entrust) provider.
|
|
||||||
type: path
|
|
||||||
default: https://cloud.entrust.net/EntrustCloud/documentation/cms-api-2.1.0.yaml
|
|
||||||
'''
|
|
||||||
|
|
||||||
BACKEND_OWNCA_DOCUMENTATION = r'''
|
|
||||||
description:
|
|
||||||
- The C(ownca) provider is intended for generating an OpenSSL certificate signed with your own
|
|
||||||
CA (Certificate Authority) certificate (self-signed certificate).
|
|
||||||
options:
|
|
||||||
ownca_path:
|
|
||||||
description:
|
|
||||||
- Remote absolute path of the CA (Certificate Authority) certificate.
|
|
||||||
- This is only used by the C(ownca) provider.
|
|
||||||
- This is mutually exclusive with I(ownca_content).
|
|
||||||
type: path
|
|
||||||
ownca_content:
|
|
||||||
description:
|
|
||||||
- Content of the CA (Certificate Authority) certificate.
|
|
||||||
- This is only used by the C(ownca) provider.
|
|
||||||
- This is mutually exclusive with I(ownca_path).
|
|
||||||
type: str
|
|
||||||
|
|
||||||
ownca_privatekey_path:
|
|
||||||
description:
|
|
||||||
- Path to the CA (Certificate Authority) private key to use when signing the certificate.
|
|
||||||
- This is only used by the C(ownca) provider.
|
|
||||||
- This is mutually exclusive with I(ownca_privatekey_content).
|
|
||||||
type: path
|
|
||||||
ownca_privatekey_content:
|
|
||||||
description:
|
|
||||||
- Content of the CA (Certificate Authority) private key to use when signing the certificate.
|
|
||||||
- This is only used by the C(ownca) provider.
|
|
||||||
- This is mutually exclusive with I(ownca_privatekey_path).
|
|
||||||
type: str
|
|
||||||
|
|
||||||
ownca_privatekey_passphrase:
|
|
||||||
description:
|
|
||||||
- The passphrase for the I(ownca_privatekey_path) resp. I(ownca_privatekey_content).
|
|
||||||
- This is only used by the C(ownca) provider.
|
|
||||||
type: str
|
|
||||||
|
|
||||||
ownca_digest:
|
|
||||||
description:
|
|
||||||
- The digest algorithm to be used for the C(ownca) certificate.
|
|
||||||
- This is only used by the C(ownca) provider.
|
|
||||||
type: str
|
|
||||||
default: sha256
|
|
||||||
|
|
||||||
ownca_version:
|
|
||||||
description:
|
|
||||||
- The version of the C(ownca) certificate.
|
|
||||||
- Nowadays it should almost always be C(3).
|
|
||||||
- This is only used by the C(ownca) provider.
|
|
||||||
type: int
|
|
||||||
default: 3
|
|
||||||
|
|
||||||
ownca_not_before:
|
|
||||||
description:
|
|
||||||
- The point in time the certificate is valid from.
|
|
||||||
- Time can be specified either as relative time or as absolute timestamp.
|
|
||||||
- Time will always be interpreted as UTC.
|
|
||||||
- Valid format is C([+-]timespec | ASN.1 TIME) where timespec can be an integer
|
|
||||||
+ C([w | d | h | m | s]) (for example C(+32w1d2h)).
|
|
||||||
- If this value is not specified, the certificate will start being valid from now.
|
|
||||||
- Note that this value is B(not used to determine whether an existing certificate should be regenerated).
|
|
||||||
This can be changed by setting the I(ignore_timestamps) option to C(false). Please note that you should
|
|
||||||
avoid relative timestamps when setting I(ignore_timestamps=false).
|
|
||||||
- This is only used by the C(ownca) provider.
|
|
||||||
type: str
|
|
||||||
default: +0s
|
|
||||||
|
|
||||||
ownca_not_after:
|
|
||||||
description:
|
|
||||||
- The point in time at which the certificate stops being valid.
|
|
||||||
- Time can be specified either as relative time or as absolute timestamp.
|
|
||||||
- Time will always be interpreted as UTC.
|
|
||||||
- Valid format is C([+-]timespec | ASN.1 TIME) where timespec can be an integer
|
|
||||||
+ C([w | d | h | m | s]) (for example C(+32w1d2h)).
|
|
||||||
- If this value is not specified, the certificate will stop being valid 10 years from now.
|
|
||||||
- Note that this value is B(not used to determine whether an existing certificate should be regenerated).
|
|
||||||
This can be changed by setting the I(ignore_timestamps) option to C(false). Please note that you should
|
|
||||||
avoid relative timestamps when setting I(ignore_timestamps=false).
|
|
||||||
- This is only used by the C(ownca) provider.
|
|
||||||
- On macOS 10.15 and onwards, TLS server certificates must have a validity period of 825 days or fewer.
|
|
||||||
Please see U(https://support.apple.com/en-us/HT210176) for more details.
|
|
||||||
type: str
|
|
||||||
default: +3650d
|
|
||||||
|
|
||||||
ownca_create_subject_key_identifier:
|
|
||||||
description:
|
|
||||||
- Whether to create the Subject Key Identifier (SKI) from the public key.
|
|
||||||
- A value of C(create_if_not_provided) (default) only creates a SKI when the CSR does not
|
|
||||||
provide one.
|
|
||||||
- A value of C(always_create) always creates a SKI. If the CSR provides one, that one is
|
|
||||||
ignored.
|
|
||||||
- A value of C(never_create) never creates a SKI. If the CSR provides one, that one is used.
|
|
||||||
- This is only used by the C(ownca) provider.
|
|
||||||
- Note that this is only supported if the C(cryptography) backend is used!
|
|
||||||
type: str
|
|
||||||
choices: [create_if_not_provided, always_create, never_create]
|
|
||||||
default: create_if_not_provided
|
|
||||||
|
|
||||||
ownca_create_authority_key_identifier:
|
|
||||||
description:
|
|
||||||
- Create a Authority Key Identifier from the CA's certificate. If the CSR provided
|
|
||||||
a authority key identifier, it is ignored.
|
|
||||||
- The Authority Key Identifier is generated from the CA certificate's Subject Key Identifier,
|
|
||||||
if available. If it is not available, the CA certificate's public key will be used.
|
|
||||||
- This is only used by the C(ownca) provider.
|
|
||||||
- Note that this is only supported if the C(cryptography) backend is used!
|
|
||||||
type: bool
|
|
||||||
default: yes
|
|
||||||
'''
|
|
||||||
|
|
||||||
BACKEND_SELFSIGNED_DOCUMENTATION = r'''
|
|
||||||
notes:
|
|
||||||
- For the C(selfsigned) provider, I(csr_path) and I(csr_content) are optional. If not provided, a
|
|
||||||
certificate without any information (Subject, Subject Alternative Names, Key Usage, etc.) is created.
|
|
||||||
|
|
||||||
options:
|
|
||||||
# NOTE: descriptions in options are overwritten, not appended. For that reason, the texts provided
|
|
||||||
# here for csr_path and csr_content are not visible to the user. That's why this information is
|
|
||||||
# added to the notes (see above).
|
|
||||||
|
|
||||||
# csr_path:
|
|
||||||
# description:
|
|
||||||
# - This is optional for the C(selfsigned) provider. If not provided, a certificate
|
|
||||||
# without any information (Subject, Subject Alternative Names, Key Usage, etc.) is
|
|
||||||
# created.
|
|
||||||
|
|
||||||
# csr_content:
|
|
||||||
# description:
|
|
||||||
# - This is optional for the C(selfsigned) provider. If not provided, a certificate
|
|
||||||
# without any information (Subject, Subject Alternative Names, Key Usage, etc.) is
|
|
||||||
# created.
|
|
||||||
|
|
||||||
selfsigned_version:
|
|
||||||
description:
|
|
||||||
- Version of the C(selfsigned) certificate.
|
|
||||||
- Nowadays it should almost always be C(3).
|
|
||||||
- This is only used by the C(selfsigned) provider.
|
|
||||||
type: int
|
|
||||||
default: 3
|
|
||||||
|
|
||||||
selfsigned_digest:
|
|
||||||
description:
|
|
||||||
- Digest algorithm to be used when self-signing the certificate.
|
|
||||||
- This is only used by the C(selfsigned) provider.
|
|
||||||
type: str
|
|
||||||
default: sha256
|
|
||||||
|
|
||||||
selfsigned_not_before:
|
|
||||||
description:
|
|
||||||
- The point in time the certificate is valid from.
|
|
||||||
- Time can be specified either as relative time or as absolute timestamp.
|
|
||||||
- Time will always be interpreted as UTC.
|
|
||||||
- Valid format is C([+-]timespec | ASN.1 TIME) where timespec can be an integer
|
|
||||||
+ C([w | d | h | m | s]) (for example C(+32w1d2h)).
|
|
||||||
- If this value is not specified, the certificate will start being valid from now.
|
|
||||||
- Note that this value is B(not used to determine whether an existing certificate should be regenerated).
|
|
||||||
This can be changed by setting the I(ignore_timestamps) option to C(false). Please note that you should
|
|
||||||
avoid relative timestamps when setting I(ignore_timestamps=false).
|
|
||||||
- This is only used by the C(selfsigned) provider.
|
|
||||||
type: str
|
|
||||||
default: +0s
|
|
||||||
aliases: [ selfsigned_notBefore ]
|
|
||||||
|
|
||||||
selfsigned_not_after:
|
|
||||||
description:
|
|
||||||
- The point in time at which the certificate stops being valid.
|
|
||||||
- Time can be specified either as relative time or as absolute timestamp.
|
|
||||||
- Time will always be interpreted as UTC.
|
|
||||||
- Valid format is C([+-]timespec | ASN.1 TIME) where timespec can be an integer
|
|
||||||
+ C([w | d | h | m | s]) (for example C(+32w1d2h)).
|
|
||||||
- If this value is not specified, the certificate will stop being valid 10 years from now.
|
|
||||||
- Note that this value is B(not used to determine whether an existing certificate should be regenerated).
|
|
||||||
This can be changed by setting the I(ignore_timestamps) option to C(false). Please note that you should
|
|
||||||
avoid relative timestamps when setting I(ignore_timestamps=false).
|
|
||||||
- This is only used by the C(selfsigned) provider.
|
|
||||||
- On macOS 10.15 and onwards, TLS server certificates must have a validity period of 825 days or fewer.
|
|
||||||
Please see U(https://support.apple.com/en-us/HT210176) for more details.
|
|
||||||
type: str
|
|
||||||
default: +3650d
|
|
||||||
aliases: [ selfsigned_notAfter ]
|
|
||||||
|
|
||||||
selfsigned_create_subject_key_identifier:
|
|
||||||
description:
|
|
||||||
- Whether to create the Subject Key Identifier (SKI) from the public key.
|
|
||||||
- A value of C(create_if_not_provided) (default) only creates a SKI when the CSR does not
|
|
||||||
provide one.
|
|
||||||
- A value of C(always_create) always creates a SKI. If the CSR provides one, that one is
|
|
||||||
ignored.
|
|
||||||
- A value of C(never_create) never creates a SKI. If the CSR provides one, that one is used.
|
|
||||||
- This is only used by the C(selfsigned) provider.
|
|
||||||
- Note that this is only supported if the C(cryptography) backend is used!
|
|
||||||
type: str
|
|
||||||
choices: [create_if_not_provided, always_create, never_create]
|
|
||||||
default: create_if_not_provided
|
|
||||||
'''
|
|
||||||
@@ -1,324 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Copyrigt: (c) 2017, Yanis Guenane <yanis+ansible@guenane.org>
|
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
|
|
||||||
class ModuleDocFragment(object):
|
|
||||||
|
|
||||||
# Standard files documentation fragment
|
|
||||||
DOCUMENTATION = r'''
|
|
||||||
description:
|
|
||||||
- This module allows one to (re)generate OpenSSL certificate signing requests.
|
|
||||||
- This module supports the subjectAltName, keyUsage, extendedKeyUsage, basicConstraints and OCSP Must Staple
|
|
||||||
extensions.
|
|
||||||
requirements:
|
|
||||||
- cryptography >= 1.3
|
|
||||||
options:
|
|
||||||
digest:
|
|
||||||
description:
|
|
||||||
- The digest used when signing the certificate signing request with the private key.
|
|
||||||
type: str
|
|
||||||
default: sha256
|
|
||||||
privatekey_path:
|
|
||||||
description:
|
|
||||||
- The path to the private key to use when signing the certificate signing request.
|
|
||||||
- Either I(privatekey_path) or I(privatekey_content) must be specified if I(state) is C(present), but not both.
|
|
||||||
type: path
|
|
||||||
privatekey_content:
|
|
||||||
description:
|
|
||||||
- The content of the private key to use when signing the certificate signing request.
|
|
||||||
- Either I(privatekey_path) or I(privatekey_content) must be specified if I(state) is C(present), but not both.
|
|
||||||
type: str
|
|
||||||
privatekey_passphrase:
|
|
||||||
description:
|
|
||||||
- The passphrase for the private key.
|
|
||||||
- This is required if the private key is password protected.
|
|
||||||
type: str
|
|
||||||
version:
|
|
||||||
description:
|
|
||||||
- The version of the certificate signing request.
|
|
||||||
- "The only allowed value according to L(RFC 2986,https://tools.ietf.org/html/rfc2986#section-4.1)
|
|
||||||
is 1."
|
|
||||||
- This option no longer accepts unsupported values since community.crypto 2.0.0.
|
|
||||||
type: int
|
|
||||||
default: 1
|
|
||||||
choices:
|
|
||||||
- 1
|
|
||||||
subject:
|
|
||||||
description:
|
|
||||||
- Key/value pairs that will be present in the subject name field of the certificate signing request.
|
|
||||||
- If you need to specify more than one value with the same key, use a list as value.
|
|
||||||
- If the order of the components is important, use I(subject_ordered).
|
|
||||||
- Mutually exclusive with I(subject_ordered).
|
|
||||||
type: dict
|
|
||||||
subject_ordered:
|
|
||||||
description:
|
|
||||||
- A list of dictionaries, where every dictionary must contain one key/value pair. This key/value pair
|
|
||||||
will be present in the subject name field of the certificate signing request.
|
|
||||||
- If you want to specify more than one value with the same key in a row, you can use a list as value.
|
|
||||||
- Mutually exclusive with I(subject), and any other subject field option, such as I(country_name),
|
|
||||||
I(state_or_province_name), I(locality_name), I(organization_name), I(organizational_unit_name),
|
|
||||||
I(common_name), or I(email_address).
|
|
||||||
type: list
|
|
||||||
elements: dict
|
|
||||||
version_added: 2.0.0
|
|
||||||
country_name:
|
|
||||||
description:
|
|
||||||
- The countryName field of the certificate signing request subject.
|
|
||||||
type: str
|
|
||||||
aliases: [ C, countryName ]
|
|
||||||
state_or_province_name:
|
|
||||||
description:
|
|
||||||
- The stateOrProvinceName field of the certificate signing request subject.
|
|
||||||
type: str
|
|
||||||
aliases: [ ST, stateOrProvinceName ]
|
|
||||||
locality_name:
|
|
||||||
description:
|
|
||||||
- The localityName field of the certificate signing request subject.
|
|
||||||
type: str
|
|
||||||
aliases: [ L, localityName ]
|
|
||||||
organization_name:
|
|
||||||
description:
|
|
||||||
- The organizationName field of the certificate signing request subject.
|
|
||||||
type: str
|
|
||||||
aliases: [ O, organizationName ]
|
|
||||||
organizational_unit_name:
|
|
||||||
description:
|
|
||||||
- The organizationalUnitName field of the certificate signing request subject.
|
|
||||||
type: str
|
|
||||||
aliases: [ OU, organizationalUnitName ]
|
|
||||||
common_name:
|
|
||||||
description:
|
|
||||||
- The commonName field of the certificate signing request subject.
|
|
||||||
type: str
|
|
||||||
aliases: [ CN, commonName ]
|
|
||||||
email_address:
|
|
||||||
description:
|
|
||||||
- The emailAddress field of the certificate signing request subject.
|
|
||||||
type: str
|
|
||||||
aliases: [ E, emailAddress ]
|
|
||||||
subject_alt_name:
|
|
||||||
description:
|
|
||||||
- Subject Alternative Name (SAN) extension to attach to the certificate signing request.
|
|
||||||
- Values must be prefixed by their options. (These are C(email), C(URI), C(DNS), C(RID), C(IP), C(dirName),
|
|
||||||
C(otherName), and the ones specific to your CA).
|
|
||||||
- Note that if no SAN is specified, but a common name, the common
|
|
||||||
name will be added as a SAN except if C(useCommonNameForSAN) is
|
|
||||||
set to I(false).
|
|
||||||
- More at U(https://tools.ietf.org/html/rfc5280#section-4.2.1.6).
|
|
||||||
type: list
|
|
||||||
elements: str
|
|
||||||
aliases: [ subjectAltName ]
|
|
||||||
subject_alt_name_critical:
|
|
||||||
description:
|
|
||||||
- Should the subjectAltName extension be considered as critical.
|
|
||||||
type: bool
|
|
||||||
default: false
|
|
||||||
aliases: [ subjectAltName_critical ]
|
|
||||||
use_common_name_for_san:
|
|
||||||
description:
|
|
||||||
- If set to C(yes), the module will fill the common name in for
|
|
||||||
C(subject_alt_name) with C(DNS:) prefix if no SAN is specified.
|
|
||||||
type: bool
|
|
||||||
default: yes
|
|
||||||
aliases: [ useCommonNameForSAN ]
|
|
||||||
key_usage:
|
|
||||||
description:
|
|
||||||
- This defines the purpose (for example encipherment, signature, certificate signing)
|
|
||||||
of the key contained in the certificate.
|
|
||||||
type: list
|
|
||||||
elements: str
|
|
||||||
aliases: [ keyUsage ]
|
|
||||||
key_usage_critical:
|
|
||||||
description:
|
|
||||||
- Should the keyUsage extension be considered as critical.
|
|
||||||
type: bool
|
|
||||||
default: false
|
|
||||||
aliases: [ keyUsage_critical ]
|
|
||||||
extended_key_usage:
|
|
||||||
description:
|
|
||||||
- Additional restrictions (for example client authentication, server authentication)
|
|
||||||
on the allowed purposes for which the public key may be used.
|
|
||||||
type: list
|
|
||||||
elements: str
|
|
||||||
aliases: [ extKeyUsage, extendedKeyUsage ]
|
|
||||||
extended_key_usage_critical:
|
|
||||||
description:
|
|
||||||
- Should the extkeyUsage extension be considered as critical.
|
|
||||||
type: bool
|
|
||||||
default: false
|
|
||||||
aliases: [ extKeyUsage_critical, extendedKeyUsage_critical ]
|
|
||||||
basic_constraints:
|
|
||||||
description:
|
|
||||||
- Indicates basic constraints, such as if the certificate is a CA.
|
|
||||||
type: list
|
|
||||||
elements: str
|
|
||||||
aliases: [ basicConstraints ]
|
|
||||||
basic_constraints_critical:
|
|
||||||
description:
|
|
||||||
- Should the basicConstraints extension be considered as critical.
|
|
||||||
type: bool
|
|
||||||
default: false
|
|
||||||
aliases: [ basicConstraints_critical ]
|
|
||||||
ocsp_must_staple:
|
|
||||||
description:
|
|
||||||
- Indicates that the certificate should contain the OCSP Must Staple
|
|
||||||
extension (U(https://tools.ietf.org/html/rfc7633)).
|
|
||||||
type: bool
|
|
||||||
default: false
|
|
||||||
aliases: [ ocspMustStaple ]
|
|
||||||
ocsp_must_staple_critical:
|
|
||||||
description:
|
|
||||||
- Should the OCSP Must Staple extension be considered as critical.
|
|
||||||
- Note that according to the RFC, this extension should not be marked
|
|
||||||
as critical, as old clients not knowing about OCSP Must Staple
|
|
||||||
are required to reject such certificates
|
|
||||||
(see U(https://tools.ietf.org/html/rfc7633#section-4)).
|
|
||||||
type: bool
|
|
||||||
default: false
|
|
||||||
aliases: [ ocspMustStaple_critical ]
|
|
||||||
name_constraints_permitted:
|
|
||||||
description:
|
|
||||||
- For CA certificates, this specifies a list of identifiers which describe
|
|
||||||
subtrees of names that this CA is allowed to issue certificates for.
|
|
||||||
- Values must be prefixed by their options. (i.e., C(email), C(URI), C(DNS), C(RID), C(IP), C(dirName),
|
|
||||||
C(otherName) and the ones specific to your CA).
|
|
||||||
type: list
|
|
||||||
elements: str
|
|
||||||
name_constraints_excluded:
|
|
||||||
description:
|
|
||||||
- For CA certificates, this specifies a list of identifiers which describe
|
|
||||||
subtrees of names that this CA is B(not) allowed to issue certificates for.
|
|
||||||
- Values must be prefixed by their options. (i.e., C(email), C(URI), C(DNS), C(RID), C(IP), C(dirName),
|
|
||||||
C(otherName) and the ones specific to your CA).
|
|
||||||
type: list
|
|
||||||
elements: str
|
|
||||||
name_constraints_critical:
|
|
||||||
description:
|
|
||||||
- Should the Name Constraints extension be considered as critical.
|
|
||||||
type: bool
|
|
||||||
default: false
|
|
||||||
select_crypto_backend:
|
|
||||||
description:
|
|
||||||
- Determines which crypto backend to use.
|
|
||||||
- The default choice is C(auto), which tries to use C(cryptography) if available.
|
|
||||||
- If set to C(cryptography), will try to use the L(cryptography,https://cryptography.io/) library.
|
|
||||||
type: str
|
|
||||||
default: auto
|
|
||||||
choices: [ auto, cryptography ]
|
|
||||||
create_subject_key_identifier:
|
|
||||||
description:
|
|
||||||
- Create the Subject Key Identifier from the public key.
|
|
||||||
- "Please note that commercial CAs can ignore the value, respectively use a value of
|
|
||||||
their own choice instead. Specifying this option is mostly useful for self-signed
|
|
||||||
certificates or for own CAs."
|
|
||||||
- Note that this is only supported if the C(cryptography) backend is used!
|
|
||||||
type: bool
|
|
||||||
default: no
|
|
||||||
subject_key_identifier:
|
|
||||||
description:
|
|
||||||
- The subject key identifier as a hex string, where two bytes are separated by colons.
|
|
||||||
- "Example: C(00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33)"
|
|
||||||
- "Please note that commercial CAs ignore this value, respectively use a value of their
|
|
||||||
own choice. Specifying this option is mostly useful for self-signed certificates
|
|
||||||
or for own CAs."
|
|
||||||
- Note that this option can only be used if I(create_subject_key_identifier) is C(no).
|
|
||||||
- Note that this is only supported if the C(cryptography) backend is used!
|
|
||||||
type: str
|
|
||||||
authority_key_identifier:
|
|
||||||
description:
|
|
||||||
- The authority key identifier as a hex string, where two bytes are separated by colons.
|
|
||||||
- "Example: C(00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33)"
|
|
||||||
- "Please note that commercial CAs ignore this value, respectively use a value of their
|
|
||||||
own choice. Specifying this option is mostly useful for self-signed certificates
|
|
||||||
or for own CAs."
|
|
||||||
- Note that this is only supported if the C(cryptography) backend is used!
|
|
||||||
- The C(AuthorityKeyIdentifier) extension will only be added if at least one of I(authority_key_identifier),
|
|
||||||
I(authority_cert_issuer) and I(authority_cert_serial_number) is specified.
|
|
||||||
type: str
|
|
||||||
authority_cert_issuer:
|
|
||||||
description:
|
|
||||||
- Names that will be present in the authority cert issuer field of the certificate signing request.
|
|
||||||
- Values must be prefixed by their options. (i.e., C(email), C(URI), C(DNS), C(RID), C(IP), C(dirName),
|
|
||||||
C(otherName) and the ones specific to your CA)
|
|
||||||
- "Example: C(DNS:ca.example.org)"
|
|
||||||
- If specified, I(authority_cert_serial_number) must also be specified.
|
|
||||||
- "Please note that commercial CAs ignore this value, respectively use a value of their
|
|
||||||
own choice. Specifying this option is mostly useful for self-signed certificates
|
|
||||||
or for own CAs."
|
|
||||||
- Note that this is only supported if the C(cryptography) backend is used!
|
|
||||||
- The C(AuthorityKeyIdentifier) extension will only be added if at least one of I(authority_key_identifier),
|
|
||||||
I(authority_cert_issuer) and I(authority_cert_serial_number) is specified.
|
|
||||||
type: list
|
|
||||||
elements: str
|
|
||||||
authority_cert_serial_number:
|
|
||||||
description:
|
|
||||||
- The authority cert serial number.
|
|
||||||
- If specified, I(authority_cert_issuer) must also be specified.
|
|
||||||
- Note that this is only supported if the C(cryptography) backend is used!
|
|
||||||
- "Please note that commercial CAs ignore this value, respectively use a value of their
|
|
||||||
own choice. Specifying this option is mostly useful for self-signed certificates
|
|
||||||
or for own CAs."
|
|
||||||
- The C(AuthorityKeyIdentifier) extension will only be added if at least one of I(authority_key_identifier),
|
|
||||||
I(authority_cert_issuer) and I(authority_cert_serial_number) is specified.
|
|
||||||
type: int
|
|
||||||
crl_distribution_points:
|
|
||||||
description:
|
|
||||||
- Allows to specify one or multiple CRL distribution points.
|
|
||||||
- Only supported by the C(cryptography) backend.
|
|
||||||
type: list
|
|
||||||
elements: dict
|
|
||||||
suboptions:
|
|
||||||
full_name:
|
|
||||||
description:
|
|
||||||
- Describes how the CRL can be retrieved.
|
|
||||||
- Mutually exclusive with I(relative_name).
|
|
||||||
- "Example: C(URI:https://ca.example.com/revocations.crl)."
|
|
||||||
type: list
|
|
||||||
elements: str
|
|
||||||
relative_name:
|
|
||||||
description:
|
|
||||||
- Describes how the CRL can be retrieved relative to the CRL issuer.
|
|
||||||
- Mutually exclusive with I(full_name).
|
|
||||||
- "Example: C(/CN=example.com)."
|
|
||||||
- Can only be used when cryptography >= 1.6 is installed.
|
|
||||||
type: list
|
|
||||||
elements: str
|
|
||||||
crl_issuer:
|
|
||||||
description:
|
|
||||||
- Information about the issuer of the CRL.
|
|
||||||
type: list
|
|
||||||
elements: str
|
|
||||||
reasons:
|
|
||||||
description:
|
|
||||||
- List of reasons that this distribution point can be used for when performing revocation checks.
|
|
||||||
type: list
|
|
||||||
elements: str
|
|
||||||
choices:
|
|
||||||
- key_compromise
|
|
||||||
- ca_compromise
|
|
||||||
- affiliation_changed
|
|
||||||
- superseded
|
|
||||||
- cessation_of_operation
|
|
||||||
- certificate_hold
|
|
||||||
- privilege_withdrawn
|
|
||||||
- aa_compromise
|
|
||||||
version_added: 1.4.0
|
|
||||||
notes:
|
|
||||||
- If the certificate signing request already exists it will be checked whether subjectAltName,
|
|
||||||
keyUsage, extendedKeyUsage and basicConstraints only contain the requested values, whether
|
|
||||||
OCSP Must Staple is as requested, and if the request was signed by the given private key.
|
|
||||||
seealso:
|
|
||||||
- module: community.crypto.x509_certificate
|
|
||||||
- module: community.crypto.x509_certificate_pipe
|
|
||||||
- module: community.crypto.openssl_dhparam
|
|
||||||
- module: community.crypto.openssl_pkcs12
|
|
||||||
- module: community.crypto.openssl_privatekey
|
|
||||||
- module: community.crypto.openssl_privatekey_pipe
|
|
||||||
- module: community.crypto.openssl_publickey
|
|
||||||
- module: community.crypto.openssl_csr_info
|
|
||||||
'''
|
|
||||||
@@ -1,150 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Copyright: (c) 2016, Yanis Guenane <yanis+ansible@guenane.org>
|
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
|
|
||||||
class ModuleDocFragment(object):
|
|
||||||
|
|
||||||
# Standard files documentation fragment
|
|
||||||
DOCUMENTATION = r'''
|
|
||||||
description:
|
|
||||||
- One can generate L(RSA,https://en.wikipedia.org/wiki/RSA_%28cryptosystem%29),
|
|
||||||
L(DSA,https://en.wikipedia.org/wiki/Digital_Signature_Algorithm),
|
|
||||||
L(ECC,https://en.wikipedia.org/wiki/Elliptic-curve_cryptography) or
|
|
||||||
L(EdDSA,https://en.wikipedia.org/wiki/EdDSA) private keys.
|
|
||||||
- Keys are generated in PEM format.
|
|
||||||
- "Please note that the module regenerates private keys if they do not match
|
|
||||||
the module's options. In particular, if you provide another passphrase
|
|
||||||
(or specify none), change the keysize, etc., the private key will be
|
|
||||||
regenerated. If you are concerned that this could B(overwrite your private key),
|
|
||||||
consider using the I(backup) option."
|
|
||||||
requirements:
|
|
||||||
- cryptography >= 1.2.3 (older versions might work as well)
|
|
||||||
options:
|
|
||||||
size:
|
|
||||||
description:
|
|
||||||
- Size (in bits) of the TLS/SSL key to generate.
|
|
||||||
type: int
|
|
||||||
default: 4096
|
|
||||||
type:
|
|
||||||
description:
|
|
||||||
- The algorithm used to generate the TLS/SSL private key.
|
|
||||||
- Note that C(ECC), C(X25519), C(X448), C(Ed25519) and C(Ed448) require the C(cryptography) backend.
|
|
||||||
C(X25519) needs cryptography 2.5 or newer, while C(X448), C(Ed25519) and C(Ed448) require
|
|
||||||
cryptography 2.6 or newer. For C(ECC), the minimal cryptography version required depends on the
|
|
||||||
I(curve) option.
|
|
||||||
type: str
|
|
||||||
default: RSA
|
|
||||||
choices: [ DSA, ECC, Ed25519, Ed448, RSA, X25519, X448 ]
|
|
||||||
curve:
|
|
||||||
description:
|
|
||||||
- Note that not all curves are supported by all versions of C(cryptography).
|
|
||||||
- For maximal interoperability, C(secp384r1) or C(secp256r1) should be used.
|
|
||||||
- We use the curve names as defined in the
|
|
||||||
L(IANA registry for TLS,https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8).
|
|
||||||
- Please note that all curves except C(secp224r1), C(secp256k1), C(secp256r1), C(secp384r1) and C(secp521r1)
|
|
||||||
are discouraged for new private keys.
|
|
||||||
type: str
|
|
||||||
choices:
|
|
||||||
- secp224r1
|
|
||||||
- secp256k1
|
|
||||||
- secp256r1
|
|
||||||
- secp384r1
|
|
||||||
- secp521r1
|
|
||||||
- secp192r1
|
|
||||||
- brainpoolP256r1
|
|
||||||
- brainpoolP384r1
|
|
||||||
- brainpoolP512r1
|
|
||||||
- sect163k1
|
|
||||||
- sect163r2
|
|
||||||
- sect233k1
|
|
||||||
- sect233r1
|
|
||||||
- sect283k1
|
|
||||||
- sect283r1
|
|
||||||
- sect409k1
|
|
||||||
- sect409r1
|
|
||||||
- sect571k1
|
|
||||||
- sect571r1
|
|
||||||
passphrase:
|
|
||||||
description:
|
|
||||||
- The passphrase for the private key.
|
|
||||||
type: str
|
|
||||||
cipher:
|
|
||||||
description:
|
|
||||||
- The cipher to encrypt the private key. Must be C(auto).
|
|
||||||
type: str
|
|
||||||
select_crypto_backend:
|
|
||||||
description:
|
|
||||||
- Determines which crypto backend to use.
|
|
||||||
- The default choice is C(auto), which tries to use C(cryptography) if available.
|
|
||||||
- If set to C(cryptography), will try to use the L(cryptography,https://cryptography.io/) library.
|
|
||||||
type: str
|
|
||||||
default: auto
|
|
||||||
choices: [ auto, cryptography ]
|
|
||||||
format:
|
|
||||||
description:
|
|
||||||
- Determines which format the private key is written in. By default, PKCS1 (traditional OpenSSL format)
|
|
||||||
is used for all keys which support it. Please note that not every key can be exported in any format.
|
|
||||||
- The value C(auto) selects a format based on the key format. The value C(auto_ignore) does the same,
|
|
||||||
but for existing private key files, it will not force a regenerate when its format is not the automatically
|
|
||||||
selected one for generation.
|
|
||||||
- Note that if the format for an existing private key mismatches, the key is B(regenerated) by default.
|
|
||||||
To change this behavior, use the I(format_mismatch) option.
|
|
||||||
type: str
|
|
||||||
default: auto_ignore
|
|
||||||
choices: [ pkcs1, pkcs8, raw, auto, auto_ignore ]
|
|
||||||
format_mismatch:
|
|
||||||
description:
|
|
||||||
- Determines behavior of the module if the format of a private key does not match the expected format, but all
|
|
||||||
other parameters are as expected.
|
|
||||||
- If set to C(regenerate) (default), generates a new private key.
|
|
||||||
- If set to C(convert), the key will be converted to the new format instead.
|
|
||||||
- Only supported by the C(cryptography) backend.
|
|
||||||
type: str
|
|
||||||
default: regenerate
|
|
||||||
choices: [ regenerate, convert ]
|
|
||||||
regenerate:
|
|
||||||
description:
|
|
||||||
- Allows to configure in which situations the module is allowed to regenerate private keys.
|
|
||||||
The module will always generate a new key if the destination file does not exist.
|
|
||||||
- By default, the key will be regenerated when it does not match the module's options,
|
|
||||||
except when the key cannot be read or the passphrase does not match. Please note that
|
|
||||||
this B(changed) for Ansible 2.10. For Ansible 2.9, the behavior was as if C(full_idempotence)
|
|
||||||
is specified.
|
|
||||||
- If set to C(never), the module will fail if the key cannot be read or the passphrase
|
|
||||||
is not matching, and will never regenerate an existing key.
|
|
||||||
- If set to C(fail), the module will fail if the key does not correspond to the module's
|
|
||||||
options.
|
|
||||||
- If set to C(partial_idempotence), the key will be regenerated if it does not conform to
|
|
||||||
the module's options. The key is B(not) regenerated if it cannot be read (broken file),
|
|
||||||
the key is protected by an unknown passphrase, or when they key is not protected by a
|
|
||||||
passphrase, but a passphrase is specified.
|
|
||||||
- If set to C(full_idempotence), the key will be regenerated if it does not conform to the
|
|
||||||
module's options. This is also the case if the key cannot be read (broken file), the key
|
|
||||||
is protected by an unknown passphrase, or when they key is not protected by a passphrase,
|
|
||||||
but a passphrase is specified. Make sure you have a B(backup) when using this option!
|
|
||||||
- If set to C(always), the module will always regenerate the key. This is equivalent to
|
|
||||||
setting I(force) to C(yes).
|
|
||||||
- Note that if I(format_mismatch) is set to C(convert) and everything matches except the
|
|
||||||
format, the key will always be converted, except if I(regenerate) is set to C(always).
|
|
||||||
type: str
|
|
||||||
choices:
|
|
||||||
- never
|
|
||||||
- fail
|
|
||||||
- partial_idempotence
|
|
||||||
- full_idempotence
|
|
||||||
- always
|
|
||||||
default: full_idempotence
|
|
||||||
seealso:
|
|
||||||
- module: community.crypto.x509_certificate
|
|
||||||
- module: community.crypto.x509_certificate_pipe
|
|
||||||
- module: community.crypto.openssl_csr
|
|
||||||
- module: community.crypto.openssl_csr_pipe
|
|
||||||
- module: community.crypto.openssl_dhparam
|
|
||||||
- module: community.crypto.openssl_pkcs12
|
|
||||||
- module: community.crypto.openssl_publickey
|
|
||||||
'''
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Copyright: (c) 2022, Felix Fontein <felix@fontein.de>
|
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
|
|
||||||
class ModuleDocFragment(object):
|
|
||||||
|
|
||||||
# Standard files documentation fragment
|
|
||||||
DOCUMENTATION = r'''
|
|
||||||
requirements:
|
|
||||||
- cryptography >= 1.2.3 (older versions might work as well)
|
|
||||||
options:
|
|
||||||
src_path:
|
|
||||||
description:
|
|
||||||
- Name of the file containing the OpenSSL private key to convert.
|
|
||||||
- Exactly one of I(src_path) or I(src_content) must be specified.
|
|
||||||
type: path
|
|
||||||
src_content:
|
|
||||||
description:
|
|
||||||
- The content of the file containing the OpenSSL private key to convert.
|
|
||||||
- Exactly one of I(src_path) or I(src_content) must be specified.
|
|
||||||
type: str
|
|
||||||
src_passphrase:
|
|
||||||
description:
|
|
||||||
- The passphrase for the private key to load.
|
|
||||||
type: str
|
|
||||||
dest_passphrase:
|
|
||||||
description:
|
|
||||||
- The passphrase for the private key to store.
|
|
||||||
type: str
|
|
||||||
format:
|
|
||||||
description:
|
|
||||||
- Determines which format the destination private key should be written in.
|
|
||||||
- Please note that not every key can be exported in any format, and that not every
|
|
||||||
format supports encryption.
|
|
||||||
type: str
|
|
||||||
choices: [ pkcs1, pkcs8, raw ]
|
|
||||||
required: true
|
|
||||||
seealso:
|
|
||||||
- module: community.crypto.openssl_privatekey
|
|
||||||
- module: community.crypto.openssl_privatekey_pipe
|
|
||||||
- module: community.crypto.openssl_publickey
|
|
||||||
'''
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Copyright: (c) 2022, Felix Fontein <felix@fontein.de>
|
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
|
|
||||||
class ModuleDocFragment(object):
|
|
||||||
DOCUMENTATION = r'''
|
|
||||||
options:
|
|
||||||
name_encoding:
|
|
||||||
description:
|
|
||||||
- How to encode names (DNS names, URIs, email addresses) in return values.
|
|
||||||
- C(ignore) will use the encoding returned by the backend.
|
|
||||||
- C(idna) will convert all labels of domain names to IDNA encoding.
|
|
||||||
IDNA2008 will be preferred, and IDNA2003 will be used if IDNA2008 encoding fails.
|
|
||||||
- C(unicode) will convert all labels of domain names to Unicode.
|
|
||||||
IDNA2008 will be preferred, and IDNA2003 will be used if IDNA2008 decoding fails.
|
|
||||||
- B(Note) that C(idna) and C(unicode) require the L(idna Python library,https://pypi.org/project/idna/) to be installed.
|
|
||||||
type: str
|
|
||||||
default: ignore
|
|
||||||
choices:
|
|
||||||
- ignore
|
|
||||||
- idna
|
|
||||||
- unicode
|
|
||||||
requirements:
|
|
||||||
- If I(name_encoding) is set to another value than C(ignore), the L(idna Python library,https://pypi.org/project/idna/) needs to be installed.
|
|
||||||
'''
|
|
||||||
177
plugins/filter/acme_dns_persist_record.py
Normal file
177
plugins/filter/acme_dns_persist_record.py
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
# Copyright (c) 2026, Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
DOCUMENTATION = r"""
|
||||||
|
name: acme_dns_persist_record
|
||||||
|
short_description: Craft a DNS record for ACME C(dns-persist-01) challenges
|
||||||
|
author: Felix Fontein (@felixfontein)
|
||||||
|
version_added: 3.2.0
|
||||||
|
description:
|
||||||
|
- Craft the content for a ACME C(dns-persist-01) DNS TXT record V(_validation-persist.<domain>).
|
||||||
|
- This filter conforms to the L(acme-dns-persist draft 01, https://www.ietf.org/archive/id/draft-ietf-acme-dns-persist-01.html).
|
||||||
|
Note that the supported draft version can change at any time,
|
||||||
|
and changes will only be considered breaking once the draft reached RFC status.
|
||||||
|
options:
|
||||||
|
_input:
|
||||||
|
description:
|
||||||
|
- The issuer domain name.
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
account_uri:
|
||||||
|
description:
|
||||||
|
- The ACME account URI.
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
policy:
|
||||||
|
description:
|
||||||
|
- The validation scope.
|
||||||
|
type: string
|
||||||
|
choices:
|
||||||
|
wildcard:
|
||||||
|
- If this value is present, the CA MAY consider this validation sufficient for issuing certificates
|
||||||
|
for the validated FQDN, for specific subdomains of the validated FQDN
|
||||||
|
(as covered by wildcard scope or specific subdomain validation rules),
|
||||||
|
and for wildcard certificates (for example V(*.example.com)). See
|
||||||
|
L(Section 5, https://www.ietf.org/archive/id/draft-ietf-acme-dns-persist-01.html#wildcard-certificate-validation)
|
||||||
|
and L(Section 6, https://www.ietf.org/archive/id/draft-ietf-acme-dns-persist-01.html#subdomain-certificate-validation)
|
||||||
|
of the L(acme-dns-persist draft 01, https://www.ietf.org/archive/id/draft-ietf-acme-dns-persist-01.html).
|
||||||
|
persist_until:
|
||||||
|
description:
|
||||||
|
- Until when the record is valid.
|
||||||
|
- Can be specified as a UNIX time stamp (integer), as a Python datetime object,
|
||||||
|
or as a relative time or absolute timestamp specified as a string.
|
||||||
|
- Times specified as strings will always be interpreted as UTC.
|
||||||
|
Valid format is C([+-]timespec | ASN.1 TIME) where timespec can be an integer
|
||||||
|
+ C([w | d | h | m | s]) (for example V(+32w1d2h)).
|
||||||
|
type: any
|
||||||
|
seealso:
|
||||||
|
- module: community.crypto.acme_certificate
|
||||||
|
- module: community.crypto.acme_certificate_order_create
|
||||||
|
- module: community.crypto.acme_certificate_order_validate
|
||||||
|
"""
|
||||||
|
|
||||||
|
EXAMPLES = r"""
|
||||||
|
---
|
||||||
|
- name: Create _validation-persist.<domain> TXT record contents
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: >-
|
||||||
|
{{
|
||||||
|
'letsencrypt.org' | community.crypto.acme_dns_persist_record(
|
||||||
|
account_uri='https://acme-v02.api.letsencrypt.org/acme/acct/1234',
|
||||||
|
policy='wildcard',
|
||||||
|
persist_until='+1w',
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
|
||||||
|
- name: Create _validation-persist.<domain> TXT record for example.com
|
||||||
|
community.dns.hetzner_dns_record_set:
|
||||||
|
prefix: _validation-persist
|
||||||
|
zone_name: example.com
|
||||||
|
value:
|
||||||
|
- >-
|
||||||
|
{{
|
||||||
|
'letsencrypt.org' | community.crypto.acme_dns_persist_record(
|
||||||
|
account_uri='https://acme-v02.api.letsencrypt.org/acme/acct/4321',
|
||||||
|
persist_until='20190331202428Z',
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
"""
|
||||||
|
|
||||||
|
RETURN = r"""
|
||||||
|
_value:
|
||||||
|
description:
|
||||||
|
- The content for the V(_validation-persist.<domain>) TXT record.
|
||||||
|
type: string
|
||||||
|
"""
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
import typing as t
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
from ansible.errors import AnsibleFilterError
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._caa import (
|
||||||
|
join_issue_value,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.basic import (
|
||||||
|
OpenSSLObjectError,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._time import (
|
||||||
|
get_epoch_seconds,
|
||||||
|
get_now_datetime,
|
||||||
|
get_relative_time_option,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def acme_dns_persist_record(
|
||||||
|
domain_issuer_name: t.Any,
|
||||||
|
*,
|
||||||
|
account_uri: t.Any,
|
||||||
|
policy: t.Any | None = None,
|
||||||
|
persist_until: t.Any | None = None,
|
||||||
|
) -> str:
|
||||||
|
if not isinstance(domain_issuer_name, str):
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
"The input for the community.crypto.acme_dns_persist_record filter"
|
||||||
|
f" must be a string; got {type(domain_issuer_name)} instead"
|
||||||
|
)
|
||||||
|
if not isinstance(account_uri, str):
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
"The account_uri parameter for the community.crypto.acme_dns_persist_record filter"
|
||||||
|
f" must be a string; got {type(account_uri)} instead"
|
||||||
|
)
|
||||||
|
valid_policies = ("wildcard",)
|
||||||
|
if policy is not None and policy not in valid_policies:
|
||||||
|
choices = ", ".join(f'"{vp}"' for vp in valid_policies)
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
"The policy parameter for the community.crypto.acme_dns_persist_record filter"
|
||||||
|
f" must be one of {choices}; got {policy!r} instead"
|
||||||
|
)
|
||||||
|
if persist_until is not None:
|
||||||
|
if isinstance(persist_until, str):
|
||||||
|
try:
|
||||||
|
persist_until = get_relative_time_option(
|
||||||
|
persist_until,
|
||||||
|
input_name="persist_until",
|
||||||
|
with_timezone=True,
|
||||||
|
now=get_now_datetime(with_timezone=True),
|
||||||
|
)
|
||||||
|
except OpenSSLObjectError as exc:
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
"Error parsing persist_until parameter for the community.crypto.acme_dns_persist_record filter:"
|
||||||
|
f" {exc}"
|
||||||
|
) from None
|
||||||
|
if isinstance(persist_until, int) and not isinstance(persist_until, bool):
|
||||||
|
pass
|
||||||
|
elif isinstance(persist_until, datetime.datetime):
|
||||||
|
persist_until = int(get_epoch_seconds(persist_until))
|
||||||
|
else:
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
"The persist_until parameter for the community.crypto.acme_dns_persist_record filter"
|
||||||
|
f" must be an integer, a string, or a datetime object; got {type(persist_until)} instead"
|
||||||
|
)
|
||||||
|
|
||||||
|
parts = [("accounturi", account_uri)]
|
||||||
|
if policy is not None:
|
||||||
|
parts.append(("policy", policy))
|
||||||
|
if persist_until is not None:
|
||||||
|
parts.append(("persistUntil", str(persist_until)))
|
||||||
|
try:
|
||||||
|
return join_issue_value(domain_issuer_name, parts)
|
||||||
|
except ValueError as exc:
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
"Error composing result for the community.crypto.acme_dns_persist_record filter:"
|
||||||
|
f" {exc}"
|
||||||
|
) from exc
|
||||||
|
|
||||||
|
|
||||||
|
class FilterModule:
|
||||||
|
"""Ansible jinja2 filters"""
|
||||||
|
|
||||||
|
def filters(self) -> dict[str, Callable]:
|
||||||
|
return {
|
||||||
|
"acme_dns_persist_record": acme_dns_persist_record,
|
||||||
|
}
|
||||||
163
plugins/filter/acme_dns_persist_record_parse.py
Normal file
163
plugins/filter/acme_dns_persist_record_parse.py
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
# Copyright (c) 2026, Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
DOCUMENTATION = r"""
|
||||||
|
name: acme_dns_persist_record_parse
|
||||||
|
short_description: Parse a DNS record for ACME C(dns-persist-01) challenges
|
||||||
|
author: Felix Fontein (@felixfontein)
|
||||||
|
version_added: 3.2.0
|
||||||
|
description:
|
||||||
|
- Parse the content for a ACME C(dns-persist-01) DNS TXT record V(_validation-persist.<domain>).
|
||||||
|
- This filter conforms to the L(acme-dns-persist draft 01, https://www.ietf.org/archive/id/draft-ietf-acme-dns-persist-01.html).
|
||||||
|
Note that the supported draft version can change at any time,
|
||||||
|
and changes will only be considered breaking once the draft reached RFC status.
|
||||||
|
options:
|
||||||
|
_input:
|
||||||
|
description:
|
||||||
|
- The DNS TXT record entry.
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
seealso:
|
||||||
|
- module: community.crypto.acme_certificate
|
||||||
|
- module: community.crypto.acme_certificate_order_create
|
||||||
|
- module: community.crypto.acme_certificate_order_validate
|
||||||
|
"""
|
||||||
|
|
||||||
|
EXAMPLES = r"""
|
||||||
|
---
|
||||||
|
- name: Create _validation-persist.<domain> TXT record contents
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "{{ record | community.crypto.acme_dns_persist_record_parse }}"
|
||||||
|
var:
|
||||||
|
record: >-
|
||||||
|
letsencrypt.org;
|
||||||
|
accounturi=https://acme-v02.api.letsencrypt.org/acme/acct/1234;
|
||||||
|
policy=wildcard;
|
||||||
|
persistUntil=1774813004
|
||||||
|
|
||||||
|
- name: Create _validation-persist.<domain> TXT record for example.com
|
||||||
|
community.dns.hetzner_dns_record_set:
|
||||||
|
prefix: _validation-persist
|
||||||
|
zone_name: example.com
|
||||||
|
value:
|
||||||
|
- >-
|
||||||
|
{{
|
||||||
|
'letsencrypt.org' | community.crypto.acme_dns_persist_record(
|
||||||
|
account_uri='https://acme-v02.api.letsencrypt.org/acme/acct/4321',
|
||||||
|
persist_until='20190331202428Z',
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
"""
|
||||||
|
|
||||||
|
RETURN = r"""
|
||||||
|
_value:
|
||||||
|
description:
|
||||||
|
- The content for the V(_validation-persist.<domain>) TXT record.
|
||||||
|
type: dictionary
|
||||||
|
contains:
|
||||||
|
issuer_domain_name:
|
||||||
|
type: string
|
||||||
|
description:
|
||||||
|
- The issuer domain name.
|
||||||
|
sample: letsencrypt.org
|
||||||
|
account_uri:
|
||||||
|
type: string
|
||||||
|
description:
|
||||||
|
- The ACME account URI.
|
||||||
|
policy:
|
||||||
|
description:
|
||||||
|
- The validation scope.
|
||||||
|
- Is V(null) if not present.
|
||||||
|
type: string
|
||||||
|
persist_until:
|
||||||
|
description:
|
||||||
|
- Until when the record is valid.
|
||||||
|
- This is a UNIX timestamp, that is the number of seconds since January 1st, 1970, in UTC.
|
||||||
|
- Is V(null) if V(persistUntil) is not present.
|
||||||
|
type: string
|
||||||
|
persist_until_str:
|
||||||
|
description:
|
||||||
|
- A ASN.1 string representation of RV(_value.persist_until).
|
||||||
|
- Is V(null) if V(persistUntil) is not present.
|
||||||
|
type: string
|
||||||
|
"""
|
||||||
|
|
||||||
|
import typing as t
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
from ansible.errors import AnsibleFilterError
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._caa import (
|
||||||
|
parse_issue_value,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._time import (
|
||||||
|
from_epoch_seconds,
|
||||||
|
)
|
||||||
|
|
||||||
|
TIMESTAMP_FORMAT = "%Y%m%d%H%M%SZ"
|
||||||
|
|
||||||
|
|
||||||
|
def acme_dns_persist_record_parse(
|
||||||
|
record_value: t.Any,
|
||||||
|
) -> dict[str, t.Any]:
|
||||||
|
if not isinstance(record_value, str):
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
"The input for the community.crypto.acme_dns_persist_record_parse filter"
|
||||||
|
f" must be a string; got {type(record_value)} instead"
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
domain_name, pairs = parse_issue_value(record_value)
|
||||||
|
except ValueError as exc:
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
"community.crypto.acme_dns_persist_record_parse filter could not parse"
|
||||||
|
f" value: {exc}"
|
||||||
|
) from exc
|
||||||
|
values = dict(pairs)
|
||||||
|
if domain_name is None:
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
"community.crypto.acme_dns_persist_record_parse filter: domain name not present"
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
account_uri = values.pop("accounturi")
|
||||||
|
except KeyError:
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
"community.crypto.acme_dns_persist_record_parse filter: cannot find account URI"
|
||||||
|
) from None
|
||||||
|
policy = values.pop("policy", None)
|
||||||
|
if policy is not None:
|
||||||
|
policy = policy.lower()
|
||||||
|
# TODO unknown policy
|
||||||
|
persist_until_v = values.pop("persistUntil", None)
|
||||||
|
persist_until: int | None = None
|
||||||
|
persist_until_str: str | None = None
|
||||||
|
if persist_until_v is not None:
|
||||||
|
try:
|
||||||
|
persist_until = int(persist_until_v)
|
||||||
|
except ValueError as exc:
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
f"community.crypto.acme_dns_persist_record_parse filter: error when parsing persistUntil: {exc}"
|
||||||
|
) from None
|
||||||
|
persist_until_str = from_epoch_seconds(
|
||||||
|
persist_until, with_timezone=True
|
||||||
|
).strftime(TIMESTAMP_FORMAT)
|
||||||
|
result: dict[str, t.Any] = {
|
||||||
|
"issuer_domain_name": domain_name,
|
||||||
|
"account_uri": account_uri,
|
||||||
|
"policy": policy,
|
||||||
|
"persist_until": persist_until,
|
||||||
|
"persist_until_str": persist_until_str,
|
||||||
|
}
|
||||||
|
# TODO values not empty
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
class FilterModule:
|
||||||
|
"""Ansible jinja2 filters"""
|
||||||
|
|
||||||
|
def filters(self) -> dict[str, Callable]:
|
||||||
|
return {
|
||||||
|
"acme_dns_persist_record_parse": acme_dns_persist_record_parse,
|
||||||
|
}
|
||||||
75
plugins/filter/gpg_fingerprint.py
Normal file
75
plugins/filter/gpg_fingerprint.py
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
# Copyright (c) 2023, Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
DOCUMENTATION = r"""
|
||||||
|
name: gpg_fingerprint
|
||||||
|
short_description: Retrieve a GPG fingerprint from a GPG public or private key
|
||||||
|
author: Felix Fontein (@felixfontein)
|
||||||
|
version_added: 2.15.0
|
||||||
|
description:
|
||||||
|
- Takes the content of a private or public GPG key as input and returns its fingerprint.
|
||||||
|
options:
|
||||||
|
_input:
|
||||||
|
description:
|
||||||
|
- The content of a GPG public or private key.
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
requirements:
|
||||||
|
- GnuPG (C(gpg) executable)
|
||||||
|
seealso:
|
||||||
|
- plugin: community.crypto.gpg_fingerprint
|
||||||
|
plugin_type: lookup
|
||||||
|
"""
|
||||||
|
|
||||||
|
EXAMPLES = r"""
|
||||||
|
---
|
||||||
|
- name: Show fingerprint of GPG public key
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "{{ lookup('file', '/path/to/public_key.gpg') | community.crypto.gpg_fingerprint }}"
|
||||||
|
"""
|
||||||
|
|
||||||
|
RETURN = r"""
|
||||||
|
_value:
|
||||||
|
description:
|
||||||
|
- The fingerprint of the provided public or private GPG key.
|
||||||
|
type: string
|
||||||
|
"""
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
from ansible.errors import AnsibleFilterError
|
||||||
|
from ansible.module_utils.common.text.converters import to_bytes
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._gnupg.cli import (
|
||||||
|
GPGError,
|
||||||
|
get_fingerprint_from_bytes,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.plugin_utils._gnupg import (
|
||||||
|
PluginGPGRunner,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def gpg_fingerprint(gpg_key_content: str | bytes) -> str:
|
||||||
|
if not isinstance(gpg_key_content, (str, bytes)):
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
f"The input for the community.crypto.gpg_fingerprint filter must be a string; got {type(gpg_key_content)} instead"
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
gpg = PluginGPGRunner()
|
||||||
|
return get_fingerprint_from_bytes(
|
||||||
|
gpg_runner=gpg, content=to_bytes(gpg_key_content)
|
||||||
|
)
|
||||||
|
except GPGError as exc:
|
||||||
|
raise AnsibleFilterError(str(exc)) from exc
|
||||||
|
|
||||||
|
|
||||||
|
class FilterModule:
|
||||||
|
"""Ansible jinja2 filters"""
|
||||||
|
|
||||||
|
def filters(self) -> dict[str, Callable]:
|
||||||
|
return {
|
||||||
|
"gpg_fingerprint": gpg_fingerprint,
|
||||||
|
}
|
||||||
328
plugins/filter/openssl_csr_info.py
Normal file
328
plugins/filter/openssl_csr_info.py
Normal file
@@ -0,0 +1,328 @@
|
|||||||
|
# Copyright (c) 2022, Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
DOCUMENTATION = r"""
|
||||||
|
name: openssl_csr_info
|
||||||
|
short_description: Retrieve information from OpenSSL Certificate Signing Requests (CSR)
|
||||||
|
version_added: 2.10.0
|
||||||
|
author:
|
||||||
|
- Felix Fontein (@felixfontein)
|
||||||
|
description:
|
||||||
|
- Provided an OpenSSL Certificate Signing Requests (CSR), retrieve information.
|
||||||
|
- This is a filter version of the M(community.crypto.openssl_csr_info) module.
|
||||||
|
options:
|
||||||
|
_input:
|
||||||
|
description:
|
||||||
|
- The content of the OpenSSL CSR.
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
extends_documentation_fragment:
|
||||||
|
- community.crypto._name_encoding
|
||||||
|
seealso:
|
||||||
|
- module: community.crypto.openssl_csr_info
|
||||||
|
- plugin: community.crypto.to_serial
|
||||||
|
plugin_type: filter
|
||||||
|
"""
|
||||||
|
|
||||||
|
EXAMPLES = r"""
|
||||||
|
---
|
||||||
|
- name: Show the Subject Alt Names of the CSR
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: >-
|
||||||
|
{{
|
||||||
|
(
|
||||||
|
lookup('ansible.builtin.file', '/path/to/cert.csr')
|
||||||
|
| community.crypto.openssl_csr_info
|
||||||
|
).subject_alt_name | join(', ')
|
||||||
|
}}
|
||||||
|
"""
|
||||||
|
|
||||||
|
RETURN = r"""
|
||||||
|
_value:
|
||||||
|
description:
|
||||||
|
- Information on the certificate.
|
||||||
|
type: dict
|
||||||
|
contains:
|
||||||
|
signature_valid:
|
||||||
|
description:
|
||||||
|
- Whether the CSR's signature is valid.
|
||||||
|
- In case the check returns V(false), the module will fail.
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
basic_constraints:
|
||||||
|
description: Entries in the C(basic_constraints) extension, or V(none) if extension is not present.
|
||||||
|
returned: success
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
sample: ['CA:TRUE', 'pathlen:1']
|
||||||
|
basic_constraints_critical:
|
||||||
|
description: Whether the C(basic_constraints) extension is critical.
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
extended_key_usage:
|
||||||
|
description: Entries in the C(extended_key_usage) extension, or V(none) if extension is not present.
|
||||||
|
returned: success
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
sample: [Biometric Info, DVCS, Time Stamping]
|
||||||
|
extended_key_usage_critical:
|
||||||
|
description: Whether the C(extended_key_usage) extension is critical.
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
extensions_by_oid:
|
||||||
|
description: Returns a dictionary for every extension OID.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
contains:
|
||||||
|
critical:
|
||||||
|
description: Whether the extension is critical.
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
value:
|
||||||
|
description:
|
||||||
|
- The Base64 encoded value (in DER format) of the extension.
|
||||||
|
- B(Note) that depending on the C(cryptography) version used, it is not possible to extract the ASN.1 content
|
||||||
|
of the extension, but only to provide the re-encoded content of the extension in case it was parsed by C(cryptography).
|
||||||
|
This should usually result in exactly the same value, except if the original extension value was malformed.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: "MAMCAQU="
|
||||||
|
sample: {"1.3.6.1.5.5.7.1.24": {"critical": false, "value": "MAMCAQU="}}
|
||||||
|
key_usage:
|
||||||
|
description: Entries in the C(key_usage) extension, or V(none) if extension is not present.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: [Key Agreement, Data Encipherment]
|
||||||
|
key_usage_critical:
|
||||||
|
description: Whether the C(key_usage) extension is critical.
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
subject_alt_name:
|
||||||
|
description:
|
||||||
|
- Entries in the C(subject_alt_name) extension, or V(none) if extension is not present.
|
||||||
|
- See O(name_encoding) for how IDNs are handled.
|
||||||
|
returned: success
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
sample: ["DNS:www.ansible.com", "IP:1.2.3.4"]
|
||||||
|
subject_alt_name_critical:
|
||||||
|
description: Whether the C(subject_alt_name) extension is critical.
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
ocsp_must_staple:
|
||||||
|
description: V(true) if the OCSP Must Staple extension is present, V(none) otherwise.
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
ocsp_must_staple_critical:
|
||||||
|
description: Whether the C(ocsp_must_staple) extension is critical.
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
name_constraints_permitted:
|
||||||
|
description: List of permitted subtrees to sign certificates for.
|
||||||
|
returned: success
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
sample: ['email:.somedomain.com']
|
||||||
|
name_constraints_excluded:
|
||||||
|
description:
|
||||||
|
- List of excluded subtrees the CA cannot sign certificates for.
|
||||||
|
- Is V(none) if extension is not present.
|
||||||
|
- See O(name_encoding) for how IDNs are handled.
|
||||||
|
returned: success
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
sample: ['email:.com']
|
||||||
|
name_constraints_critical:
|
||||||
|
description:
|
||||||
|
- Whether the C(name_constraints) extension is critical.
|
||||||
|
- Is V(none) if extension is not present.
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
subject:
|
||||||
|
description:
|
||||||
|
- The CSR's subject as a dictionary.
|
||||||
|
- Note that for repeated values, only the last one will be returned.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
sample: {"commonName": "www.example.com", "emailAddress": "test@example.com"}
|
||||||
|
subject_ordered:
|
||||||
|
description: The CSR's subject as an ordered list of tuples.
|
||||||
|
returned: success
|
||||||
|
type: list
|
||||||
|
elements: list
|
||||||
|
sample: [["commonName", "www.example.com"], ["emailAddress": "test@example.com"]]
|
||||||
|
public_key:
|
||||||
|
description: CSR's public key in PEM format.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8A..."
|
||||||
|
public_key_type:
|
||||||
|
description:
|
||||||
|
- The CSR's public key's type.
|
||||||
|
- One of V(RSA), V(DSA), V(ECC), V(Ed25519), V(X25519), V(Ed448), or V(X448).
|
||||||
|
- Will start with C(unknown) if the key type cannot be determined.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: RSA
|
||||||
|
public_key_data:
|
||||||
|
description:
|
||||||
|
- Public key data. Depends on the public key's type.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
contains:
|
||||||
|
size:
|
||||||
|
description:
|
||||||
|
- Bit size of modulus (RSA) or prime number (DSA).
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.public_key_type=RSA) or RV(_value.public_key_type=DSA)
|
||||||
|
modulus:
|
||||||
|
description:
|
||||||
|
- The RSA key's modulus.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.public_key_type=RSA)
|
||||||
|
exponent:
|
||||||
|
description:
|
||||||
|
- The RSA key's public exponent.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.public_key_type=RSA)
|
||||||
|
p:
|
||||||
|
description:
|
||||||
|
- The C(p) value for DSA.
|
||||||
|
- This is the prime modulus upon which arithmetic takes place.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.public_key_type=DSA)
|
||||||
|
q:
|
||||||
|
description:
|
||||||
|
- The C(q) value for DSA.
|
||||||
|
- This is a prime that divides C(p - 1), and at the same time the order of the subgroup of the multiplicative
|
||||||
|
group of the prime field used.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.public_key_type=DSA)
|
||||||
|
g:
|
||||||
|
description:
|
||||||
|
- The C(g) value for DSA.
|
||||||
|
- This is the element spanning the subgroup of the multiplicative group of the prime field used.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.public_key_type=DSA)
|
||||||
|
curve:
|
||||||
|
description:
|
||||||
|
- The curve's name for ECC.
|
||||||
|
type: str
|
||||||
|
returned: When RV(_value.public_key_type=ECC)
|
||||||
|
exponent_size:
|
||||||
|
description:
|
||||||
|
- The maximum number of bits of a private key. This is basically the bit size of the subgroup used.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.public_key_type=ECC)
|
||||||
|
x:
|
||||||
|
description:
|
||||||
|
- The C(x) coordinate for the public point on the elliptic curve.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.public_key_type=ECC)
|
||||||
|
y:
|
||||||
|
description:
|
||||||
|
- For RV(_value.public_key_type=ECC), this is the C(y) coordinate for the public point on the elliptic curve.
|
||||||
|
- For RV(_value.public_key_type=DSA), this is the publicly known group element whose discrete logarithm with respect
|
||||||
|
to C(g) is the private key.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.public_key_type=DSA) or RV(_value.public_key_type=ECC)
|
||||||
|
public_key_fingerprints:
|
||||||
|
description:
|
||||||
|
- Fingerprints of CSR's public key.
|
||||||
|
- For every hash algorithm available, the fingerprint is computed.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
sample: "{'sha256': 'd4:b3:aa:6d:c8:04:ce:4e:ba:f6:29:4d:92:a3:94:b0:c2:ff:bd:bf:33:63:11:43:34:0f:51:b0:95:09:2f:63',
|
||||||
|
'sha512': 'f7:07:4a:f0:b0:f0:e6:8b:95:5f:f9:e6:61:0a:32:68:f1..."
|
||||||
|
subject_key_identifier:
|
||||||
|
description:
|
||||||
|
- The CSR's subject key identifier.
|
||||||
|
- The identifier is returned in hexadecimal, with V(:) used to separate bytes.
|
||||||
|
- Is V(none) if the C(SubjectKeyIdentifier) extension is not present.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: '00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33'
|
||||||
|
authority_key_identifier:
|
||||||
|
description:
|
||||||
|
- The CSR's authority key identifier.
|
||||||
|
- The identifier is returned in hexadecimal, with V(:) used to separate bytes.
|
||||||
|
- Is V(none) if the C(AuthorityKeyIdentifier) extension is not present.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: '00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33'
|
||||||
|
authority_cert_issuer:
|
||||||
|
description:
|
||||||
|
- The CSR's authority cert issuer as a list of general names.
|
||||||
|
- Is V(none) if the C(AuthorityKeyIdentifier) extension is not present.
|
||||||
|
- See O(name_encoding) for how IDNs are handled.
|
||||||
|
returned: success
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
sample: ["DNS:www.ansible.com", "IP:1.2.3.4"]
|
||||||
|
authority_cert_serial_number:
|
||||||
|
description:
|
||||||
|
- The CSR's authority cert serial number.
|
||||||
|
- Is V(none) if the C(AuthorityKeyIdentifier) extension is not present.
|
||||||
|
- This return value is an B(integer). If you need the serial numbers as a colon-separated hex string, such as C(11:22:33),
|
||||||
|
you need to convert it to that form with P(community.crypto.to_serial#filter).
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
sample: 12345
|
||||||
|
"""
|
||||||
|
|
||||||
|
import typing as t
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
from ansible.errors import AnsibleFilterError
|
||||||
|
from ansible.module_utils.common.text.converters import to_bytes, to_text
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.basic import (
|
||||||
|
OpenSSLObjectError,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.module_backends.csr_info import (
|
||||||
|
get_csr_info,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.plugin_utils._filter_module import (
|
||||||
|
FilterModuleMock,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def openssl_csr_info_filter(
|
||||||
|
data: str | bytes, name_encoding: t.Literal["ignore", "idna", "unicode"] = "ignore"
|
||||||
|
) -> dict[str, t.Any]:
|
||||||
|
"""Extract information from X.509 PEM certificate."""
|
||||||
|
if not isinstance(data, (str, bytes)):
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
f"The community.crypto.openssl_csr_info input must be a text type, not {type(data)}"
|
||||||
|
)
|
||||||
|
if not isinstance(name_encoding, (str, bytes)):
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
f"The name_encoding option must be of a text type, not {type(name_encoding)}"
|
||||||
|
)
|
||||||
|
name_encoding = t.cast(
|
||||||
|
t.Literal["ignore", "idna", "unicode"], to_text(name_encoding)
|
||||||
|
)
|
||||||
|
if name_encoding not in ("ignore", "idna", "unicode"):
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
f'The name_encoding option must be one of the values "ignore", "idna", or "unicode", not "{name_encoding}"'
|
||||||
|
)
|
||||||
|
|
||||||
|
module = FilterModuleMock({"name_encoding": name_encoding})
|
||||||
|
try:
|
||||||
|
return get_csr_info(
|
||||||
|
module=module, content=to_bytes(data), validate_signature=True
|
||||||
|
)
|
||||||
|
except OpenSSLObjectError as exc:
|
||||||
|
raise AnsibleFilterError(str(exc)) from exc
|
||||||
|
|
||||||
|
|
||||||
|
class FilterModule:
|
||||||
|
"""Ansible jinja2 filters"""
|
||||||
|
|
||||||
|
def filters(self) -> dict[str, Callable]:
|
||||||
|
return {
|
||||||
|
"openssl_csr_info": openssl_csr_info_filter,
|
||||||
|
}
|
||||||
208
plugins/filter/openssl_privatekey_info.py
Normal file
208
plugins/filter/openssl_privatekey_info.py
Normal file
@@ -0,0 +1,208 @@
|
|||||||
|
# Copyright (c) 2022, Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
DOCUMENTATION = r"""
|
||||||
|
name: openssl_privatekey_info
|
||||||
|
short_description: Retrieve information from OpenSSL private keys
|
||||||
|
version_added: 2.10.0
|
||||||
|
author:
|
||||||
|
- Felix Fontein (@felixfontein)
|
||||||
|
description:
|
||||||
|
- Provided an OpenSSL private keys, retrieve information.
|
||||||
|
- This is a filter version of the M(community.crypto.openssl_privatekey_info) module.
|
||||||
|
options:
|
||||||
|
_input:
|
||||||
|
description:
|
||||||
|
- The content of the OpenSSL private key.
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
passphrase:
|
||||||
|
description:
|
||||||
|
- The passphrase for the private key.
|
||||||
|
type: str
|
||||||
|
return_private_key_data:
|
||||||
|
description:
|
||||||
|
- Whether to return private key data.
|
||||||
|
- Only set this to V(true) when you want private information about this key to be extracted.
|
||||||
|
- B(WARNING:) you have to make sure that private key data is not accidentally logged!
|
||||||
|
type: bool
|
||||||
|
default: false
|
||||||
|
extends_documentation_fragment:
|
||||||
|
- community.crypto._name_encoding
|
||||||
|
seealso:
|
||||||
|
- module: community.crypto.openssl_privatekey_info
|
||||||
|
"""
|
||||||
|
|
||||||
|
EXAMPLES = r"""
|
||||||
|
---
|
||||||
|
- name: Show the Subject Alt Names of the CSR
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: >-
|
||||||
|
{{
|
||||||
|
(
|
||||||
|
lookup('ansible.builtin.file', '/path/to/cert.csr')
|
||||||
|
| community.crypto.openssl_privatekey_info
|
||||||
|
).subject_alt_name | join(', ')
|
||||||
|
}}
|
||||||
|
"""
|
||||||
|
|
||||||
|
RETURN = r"""
|
||||||
|
_value:
|
||||||
|
description:
|
||||||
|
- Information on the certificate.
|
||||||
|
type: dict
|
||||||
|
contains:
|
||||||
|
public_key:
|
||||||
|
description: Private key's public key in PEM format.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8A..."
|
||||||
|
public_key_fingerprints:
|
||||||
|
description:
|
||||||
|
- Fingerprints of private key's public key.
|
||||||
|
- For every hash algorithm available, the fingerprint is computed.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
sample: "{'sha256': 'd4:b3:aa:6d:c8:04:ce:4e:ba:f6:29:4d:92:a3:94:b0:c2:ff:bd:bf:33:63:11:43:34:0f:51:b0:95:09:2f:63',
|
||||||
|
'sha512': 'f7:07:4a:f0:b0:f0:e6:8b:95:5f:f9:e6:61:0a:32:68:f1..."
|
||||||
|
type:
|
||||||
|
description:
|
||||||
|
- The key's type.
|
||||||
|
- One of V(RSA), V(DSA), V(ECC), V(Ed25519), V(X25519), V(Ed448), or V(X448).
|
||||||
|
- Will start with V(unknown) if the key type cannot be determined.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: RSA
|
||||||
|
public_data:
|
||||||
|
description:
|
||||||
|
- Public key data. Depends on key type.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
contains:
|
||||||
|
size:
|
||||||
|
description:
|
||||||
|
- Bit size of modulus (RSA) or prime number (DSA).
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.type=RSA) or RV(_value.type=DSA)
|
||||||
|
modulus:
|
||||||
|
description:
|
||||||
|
- The RSA key's modulus.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.type=RSA)
|
||||||
|
exponent:
|
||||||
|
description:
|
||||||
|
- The RSA key's public exponent.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.type=RSA)
|
||||||
|
p:
|
||||||
|
description:
|
||||||
|
- The C(p) value for DSA.
|
||||||
|
- This is the prime modulus upon which arithmetic takes place.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.type=DSA)
|
||||||
|
q:
|
||||||
|
description:
|
||||||
|
- The C(q) value for DSA.
|
||||||
|
- This is a prime that divides C(p - 1), and at the same time the order of the subgroup of the multiplicative
|
||||||
|
group of the prime field used.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.type=DSA)
|
||||||
|
g:
|
||||||
|
description:
|
||||||
|
- The C(g) value for DSA.
|
||||||
|
- This is the element spanning the subgroup of the multiplicative group of the prime field used.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.type=DSA)
|
||||||
|
curve:
|
||||||
|
description:
|
||||||
|
- The curve's name for ECC.
|
||||||
|
type: str
|
||||||
|
returned: When RV(_value.type=ECC)
|
||||||
|
exponent_size:
|
||||||
|
description:
|
||||||
|
- The maximum number of bits of a private key. This is basically the bit size of the subgroup used.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.type=ECC)
|
||||||
|
x:
|
||||||
|
description:
|
||||||
|
- The C(x) coordinate for the public point on the elliptic curve.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.type=ECC)
|
||||||
|
y:
|
||||||
|
description:
|
||||||
|
- For RV(_value.type=ECC), this is the C(y) coordinate for the public point on the elliptic curve.
|
||||||
|
- For RV(_value.type=DSA), this is the publicly known group element whose discrete logarithm with respect to C(g)
|
||||||
|
is the private key.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.type=DSA) or RV(_value.type=ECC)
|
||||||
|
private_data:
|
||||||
|
description:
|
||||||
|
- Private key data. Depends on key type.
|
||||||
|
returned: success and when O(return_private_key_data) is set to V(true)
|
||||||
|
type: dict
|
||||||
|
"""
|
||||||
|
|
||||||
|
import typing as t
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
from ansible.errors import AnsibleFilterError
|
||||||
|
from ansible.module_utils.common.text.converters import to_bytes, to_text
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.basic import (
|
||||||
|
OpenSSLObjectError,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.module_backends.privatekey_info import (
|
||||||
|
PrivateKeyParseError,
|
||||||
|
get_privatekey_info,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.plugin_utils._filter_module import (
|
||||||
|
FilterModuleMock,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def openssl_privatekey_info_filter(
|
||||||
|
data: str | bytes,
|
||||||
|
passphrase: str | bytes | None = None,
|
||||||
|
return_private_key_data: bool = False,
|
||||||
|
) -> dict[str, t.Any]:
|
||||||
|
"""Extract information from X.509 PEM certificate."""
|
||||||
|
if not isinstance(data, (str, bytes)):
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
f"The community.crypto.openssl_privatekey_info input must be a text type, not {type(data)}"
|
||||||
|
)
|
||||||
|
if passphrase is not None and not isinstance(passphrase, (str, bytes)):
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
f"The passphrase option must be a text type, not {type(passphrase)}"
|
||||||
|
)
|
||||||
|
if not isinstance(return_private_key_data, bool):
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
f"The return_private_key_data option must be a boolean, not {type(return_private_key_data)}"
|
||||||
|
)
|
||||||
|
|
||||||
|
module = FilterModuleMock({})
|
||||||
|
try:
|
||||||
|
result = get_privatekey_info(
|
||||||
|
module=module,
|
||||||
|
content=to_bytes(data),
|
||||||
|
passphrase=to_text(passphrase) if passphrase is not None else None,
|
||||||
|
return_private_key_data=return_private_key_data,
|
||||||
|
)
|
||||||
|
result.pop("can_parse_key", None)
|
||||||
|
result.pop("key_is_consistent", None)
|
||||||
|
return result
|
||||||
|
except PrivateKeyParseError as exc:
|
||||||
|
raise AnsibleFilterError(exc.error_message) from exc
|
||||||
|
except OpenSSLObjectError as exc:
|
||||||
|
raise AnsibleFilterError(str(exc)) from exc
|
||||||
|
|
||||||
|
|
||||||
|
class FilterModule:
|
||||||
|
"""Ansible jinja2 filters"""
|
||||||
|
|
||||||
|
def filters(self) -> dict[str, Callable]:
|
||||||
|
return {
|
||||||
|
"openssl_privatekey_info": openssl_privatekey_info_filter,
|
||||||
|
}
|
||||||
165
plugins/filter/openssl_publickey_info.py
Normal file
165
plugins/filter/openssl_publickey_info.py
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
# Copyright (c) 2022, Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
DOCUMENTATION = r"""
|
||||||
|
name: openssl_publickey_info
|
||||||
|
short_description: Retrieve information from OpenSSL public keys in PEM format
|
||||||
|
version_added: 2.10.0
|
||||||
|
author:
|
||||||
|
- Felix Fontein (@felixfontein)
|
||||||
|
description:
|
||||||
|
- Provided a public key in OpenSSL PEM format, retrieve information.
|
||||||
|
- This is a filter version of the M(community.crypto.openssl_publickey_info) module.
|
||||||
|
options:
|
||||||
|
_input:
|
||||||
|
description:
|
||||||
|
- The content of the OpenSSL PEM public key.
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
seealso:
|
||||||
|
- module: community.crypto.openssl_publickey_info
|
||||||
|
"""
|
||||||
|
|
||||||
|
EXAMPLES = r"""
|
||||||
|
---
|
||||||
|
- name: Show the type of a public key
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: >-
|
||||||
|
{{
|
||||||
|
(
|
||||||
|
lookup('ansible.builtin.file', '/path/to/public-key.pem')
|
||||||
|
| community.crypto.openssl_publickey_info
|
||||||
|
).type
|
||||||
|
}}
|
||||||
|
"""
|
||||||
|
|
||||||
|
RETURN = r"""
|
||||||
|
_value:
|
||||||
|
description:
|
||||||
|
- Information on the public key.
|
||||||
|
type: dict
|
||||||
|
contains:
|
||||||
|
fingerprints:
|
||||||
|
description:
|
||||||
|
- Fingerprints of public key.
|
||||||
|
- For every hash algorithm available, the fingerprint is computed.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
sample: "{'sha256': 'd4:b3:aa:6d:c8:04:ce:4e:ba:f6:29:4d:92:a3:94:b0:c2:ff:bd:bf:33:63:11:43:34:0f:51:b0:95:09:2f:63',
|
||||||
|
'sha512': 'f7:07:4a:f0:b0:f0:e6:8b:95:5f:f9:e6:61:0a:32:68:f1..."
|
||||||
|
type:
|
||||||
|
description:
|
||||||
|
- The key's type.
|
||||||
|
- One of V(RSA), V(DSA), V(ECC), V(Ed25519), V(X25519), V(Ed448), or V(X448).
|
||||||
|
- Will start with V(unknown) if the key type cannot be determined.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: RSA
|
||||||
|
public_data:
|
||||||
|
description:
|
||||||
|
- Public key data. Depends on key type.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
contains:
|
||||||
|
size:
|
||||||
|
description:
|
||||||
|
- Bit size of modulus (RSA) or prime number (DSA).
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.type=RSA) or RV(_value.type=DSA)
|
||||||
|
modulus:
|
||||||
|
description:
|
||||||
|
- The RSA key's modulus.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.type=RSA)
|
||||||
|
exponent:
|
||||||
|
description:
|
||||||
|
- The RSA key's public exponent.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.type=RSA)
|
||||||
|
p:
|
||||||
|
description:
|
||||||
|
- The C(p) value for DSA.
|
||||||
|
- This is the prime modulus upon which arithmetic takes place.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.type=DSA)
|
||||||
|
q:
|
||||||
|
description:
|
||||||
|
- The C(q) value for DSA.
|
||||||
|
- This is a prime that divides C(p - 1), and at the same time the order of the subgroup of the multiplicative
|
||||||
|
group of the prime field used.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.type=DSA)
|
||||||
|
g:
|
||||||
|
description:
|
||||||
|
- The C(g) value for DSA.
|
||||||
|
- This is the element spanning the subgroup of the multiplicative group of the prime field used.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.type=DSA)
|
||||||
|
curve:
|
||||||
|
description:
|
||||||
|
- The curve's name for ECC.
|
||||||
|
type: str
|
||||||
|
returned: When RV(_value.type=ECC)
|
||||||
|
exponent_size:
|
||||||
|
description:
|
||||||
|
- The maximum number of bits of a private key. This is basically the bit size of the subgroup used.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.type=ECC)
|
||||||
|
x:
|
||||||
|
description:
|
||||||
|
- The C(x) coordinate for the public point on the elliptic curve.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.type=ECC)
|
||||||
|
y:
|
||||||
|
description:
|
||||||
|
- For RV(_value.type=ECC), this is the C(y) coordinate for the public point on the elliptic curve.
|
||||||
|
- For RV(_value.type=DSA), this is the publicly known group element whose discrete logarithm with respect to C(g)
|
||||||
|
is the private key.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.type=DSA) or RV(_value.type=ECC)
|
||||||
|
"""
|
||||||
|
|
||||||
|
import typing as t
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
from ansible.errors import AnsibleFilterError
|
||||||
|
from ansible.module_utils.common.text.converters import to_bytes
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.basic import (
|
||||||
|
OpenSSLObjectError,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.module_backends.publickey_info import (
|
||||||
|
PublicKeyParseError,
|
||||||
|
get_publickey_info,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.plugin_utils._filter_module import (
|
||||||
|
FilterModuleMock,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def openssl_publickey_info_filter(data: str | bytes) -> dict[str, t.Any]:
|
||||||
|
"""Extract information from OpenSSL PEM public key."""
|
||||||
|
if not isinstance(data, (str, bytes)):
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
f"The community.crypto.openssl_publickey_info input must be a text type, not {type(data)}"
|
||||||
|
)
|
||||||
|
|
||||||
|
module = FilterModuleMock({})
|
||||||
|
try:
|
||||||
|
return get_publickey_info(module=module, content=to_bytes(data))
|
||||||
|
except PublicKeyParseError as exc:
|
||||||
|
raise AnsibleFilterError(exc.error_message) from exc
|
||||||
|
except OpenSSLObjectError as exc:
|
||||||
|
raise AnsibleFilterError(str(exc)) from exc
|
||||||
|
|
||||||
|
|
||||||
|
class FilterModule:
|
||||||
|
"""Ansible jinja2 filters"""
|
||||||
|
|
||||||
|
def filters(self) -> dict[str, Callable]:
|
||||||
|
return {
|
||||||
|
"openssl_publickey_info": openssl_publickey_info_filter,
|
||||||
|
}
|
||||||
68
plugins/filter/parse_serial.py
Normal file
68
plugins/filter/parse_serial.py
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
# Copyright (c) 2024, Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
DOCUMENTATION = r"""
|
||||||
|
name: parse_serial
|
||||||
|
short_description: Convert a serial number as a colon-separated list of hex numbers to an integer
|
||||||
|
author: Felix Fontein (@felixfontein)
|
||||||
|
version_added: 2.18.0
|
||||||
|
description:
|
||||||
|
- Parses a colon-separated list of hex numbers of the form C(00:11:22:33) and returns the corresponding integer.
|
||||||
|
options:
|
||||||
|
_input:
|
||||||
|
description:
|
||||||
|
- A serial number represented as a colon-separated list of hex numbers between 0 and 255.
|
||||||
|
- These numbers are interpreted as the byte presentation of an unsigned integer in network byte order. That is, C(01:00)
|
||||||
|
is interpreted as the integer 256.
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
seealso:
|
||||||
|
- plugin: community.crypto.to_serial
|
||||||
|
plugin_type: filter
|
||||||
|
"""
|
||||||
|
|
||||||
|
EXAMPLES = r"""
|
||||||
|
---
|
||||||
|
- name: Parse serial number
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "{{ '11:22:33' | community.crypto.parse_serial }}"
|
||||||
|
"""
|
||||||
|
|
||||||
|
RETURN = r"""
|
||||||
|
_value:
|
||||||
|
description:
|
||||||
|
- The serial number as an integer.
|
||||||
|
type: int
|
||||||
|
"""
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
from ansible.errors import AnsibleFilterError
|
||||||
|
from ansible.module_utils.common.text.converters import to_text
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._serial import (
|
||||||
|
parse_serial,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def parse_serial_filter(serial_str: str | bytes) -> int:
|
||||||
|
if not isinstance(serial_str, (str, bytes)):
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
f"The input for the community.crypto.parse_serial filter must be a string; got {type(serial_str)} instead"
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
return parse_serial(to_text(serial_str))
|
||||||
|
except ValueError as exc:
|
||||||
|
raise AnsibleFilterError(str(exc)) from exc
|
||||||
|
|
||||||
|
|
||||||
|
class FilterModule:
|
||||||
|
"""Ansible jinja2 filters"""
|
||||||
|
|
||||||
|
def filters(self) -> dict[str, Callable]:
|
||||||
|
return {
|
||||||
|
"parse_serial": parse_serial_filter,
|
||||||
|
}
|
||||||
66
plugins/filter/split_pem.py
Normal file
66
plugins/filter/split_pem.py
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
# Copyright (c) 2022, Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
DOCUMENTATION = r"""
|
||||||
|
name: split_pem
|
||||||
|
short_description: Split PEM file contents into multiple objects
|
||||||
|
version_added: 2.10.0
|
||||||
|
author:
|
||||||
|
- Felix Fontein (@felixfontein)
|
||||||
|
description:
|
||||||
|
- Split PEM file contents into multiple PEM objects. Comments or invalid parts are ignored.
|
||||||
|
options:
|
||||||
|
_input:
|
||||||
|
description:
|
||||||
|
- The PEM contents to split.
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
"""
|
||||||
|
|
||||||
|
EXAMPLES = r"""
|
||||||
|
---
|
||||||
|
- name: Print all CA certificates
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: '{{ item }}'
|
||||||
|
loop: >-
|
||||||
|
{{ lookup('ansible.builtin.file', '/path/to/ca-bundle.pem') | community.crypto.split_pem }}
|
||||||
|
"""
|
||||||
|
|
||||||
|
RETURN = r"""
|
||||||
|
_value:
|
||||||
|
description:
|
||||||
|
- A list of PEM file contents.
|
||||||
|
type: list
|
||||||
|
elements: string
|
||||||
|
"""
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
from ansible.errors import AnsibleFilterError
|
||||||
|
from ansible.module_utils.common.text.converters import to_text
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.pem import (
|
||||||
|
split_pem_list,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def split_pem_filter(data: str | bytes) -> list[str]:
|
||||||
|
"""Split PEM file."""
|
||||||
|
if not isinstance(data, (str, bytes)):
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
f"The community.crypto.split_pem input must be a text type, not {type(data)}"
|
||||||
|
)
|
||||||
|
|
||||||
|
return split_pem_list(to_text(data))
|
||||||
|
|
||||||
|
|
||||||
|
class FilterModule:
|
||||||
|
"""Ansible jinja2 filters"""
|
||||||
|
|
||||||
|
def filters(self) -> dict[str, Callable]:
|
||||||
|
return {
|
||||||
|
"split_pem": split_pem_filter,
|
||||||
|
}
|
||||||
69
plugins/filter/to_serial.py
Normal file
69
plugins/filter/to_serial.py
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
# Copyright (c) 2024, Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
DOCUMENTATION = r"""
|
||||||
|
name: to_serial
|
||||||
|
short_description: Convert an integer to a colon-separated list of hex numbers
|
||||||
|
author: Felix Fontein (@felixfontein)
|
||||||
|
version_added: 2.18.0
|
||||||
|
description:
|
||||||
|
- Converts an integer to a colon-separated list of hex numbers of the form C(00:11:22:33).
|
||||||
|
options:
|
||||||
|
_input:
|
||||||
|
description:
|
||||||
|
- The non-negative integer to convert.
|
||||||
|
type: int
|
||||||
|
required: true
|
||||||
|
seealso:
|
||||||
|
- plugin: community.crypto.to_serial
|
||||||
|
plugin_type: filter
|
||||||
|
"""
|
||||||
|
|
||||||
|
EXAMPLES = r"""
|
||||||
|
---
|
||||||
|
- name: Convert integer to serial number
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "{{ 1234567 | community.crypto.to_serial }}"
|
||||||
|
"""
|
||||||
|
|
||||||
|
RETURN = r"""
|
||||||
|
_value:
|
||||||
|
description:
|
||||||
|
- A colon-separated list of hexadecimal numbers.
|
||||||
|
- Letters are upper-case, and all numbers have exactly two digits.
|
||||||
|
- The string is never empty. The representation of C(0) is C("00").
|
||||||
|
type: string
|
||||||
|
"""
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
from ansible.errors import AnsibleFilterError
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._serial import to_serial
|
||||||
|
|
||||||
|
|
||||||
|
def to_serial_filter(serial_int: int) -> str:
|
||||||
|
if not isinstance(serial_int, int):
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
f"The input for the community.crypto.to_serial filter must be an integer; got {type(serial_int)} instead"
|
||||||
|
)
|
||||||
|
if serial_int < 0:
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
"The input for the community.crypto.to_serial filter must not be negative"
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
return to_serial(serial_int)
|
||||||
|
except ValueError as exc:
|
||||||
|
raise AnsibleFilterError(str(exc)) from exc
|
||||||
|
|
||||||
|
|
||||||
|
class FilterModule:
|
||||||
|
"""Ansible jinja2 filters"""
|
||||||
|
|
||||||
|
def filters(self) -> dict[str, Callable]:
|
||||||
|
return {
|
||||||
|
"to_serial": to_serial_filter,
|
||||||
|
}
|
||||||
360
plugins/filter/x509_certificate_info.py
Normal file
360
plugins/filter/x509_certificate_info.py
Normal file
@@ -0,0 +1,360 @@
|
|||||||
|
# Copyright (c) 2022, Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
DOCUMENTATION = r"""
|
||||||
|
name: x509_certificate_info
|
||||||
|
short_description: Retrieve information from X.509 certificates in PEM format
|
||||||
|
version_added: 2.10.0
|
||||||
|
author:
|
||||||
|
- Felix Fontein (@felixfontein)
|
||||||
|
description:
|
||||||
|
- Provided a X.509 certificate in PEM format, retrieve information.
|
||||||
|
- This is a filter version of the M(community.crypto.x509_certificate_info) module.
|
||||||
|
options:
|
||||||
|
_input:
|
||||||
|
description:
|
||||||
|
- The content of the X.509 certificate in PEM format.
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
extends_documentation_fragment:
|
||||||
|
- community.crypto._name_encoding
|
||||||
|
seealso:
|
||||||
|
- module: community.crypto.x509_certificate_info
|
||||||
|
- plugin: community.crypto.to_serial
|
||||||
|
plugin_type: filter
|
||||||
|
"""
|
||||||
|
|
||||||
|
EXAMPLES = r"""
|
||||||
|
---
|
||||||
|
- name: Show the Subject Alt Names of the certificate
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: >-
|
||||||
|
{{
|
||||||
|
(
|
||||||
|
lookup('ansible.builtin.file', '/path/to/cert.pem')
|
||||||
|
| community.crypto.x509_certificate_info
|
||||||
|
).subject_alt_name | join(', ')
|
||||||
|
}}
|
||||||
|
"""
|
||||||
|
|
||||||
|
RETURN = r"""
|
||||||
|
_value:
|
||||||
|
description:
|
||||||
|
- Information on the certificate.
|
||||||
|
type: dict
|
||||||
|
contains:
|
||||||
|
expired:
|
||||||
|
description: Whether the certificate is expired (in other words, C(notAfter) is in the past).
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
basic_constraints:
|
||||||
|
description: Entries in the C(basic_constraints) extension, or V(none) if extension is not present.
|
||||||
|
returned: success
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
sample: ["CA:TRUE", "pathlen:1"]
|
||||||
|
basic_constraints_critical:
|
||||||
|
description: Whether the C(basic_constraints) extension is critical.
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
extended_key_usage:
|
||||||
|
description: Entries in the C(extended_key_usage) extension, or V(none) if extension is not present.
|
||||||
|
returned: success
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
sample: [Biometric Info, DVCS, Time Stamping]
|
||||||
|
extended_key_usage_critical:
|
||||||
|
description: Whether the C(extended_key_usage) extension is critical.
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
extensions_by_oid:
|
||||||
|
description: Returns a dictionary for every extension OID.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
contains:
|
||||||
|
critical:
|
||||||
|
description: Whether the extension is critical.
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
value:
|
||||||
|
description:
|
||||||
|
- The Base64 encoded value (in DER format) of the extension.
|
||||||
|
- B(Note) that depending on the C(cryptography) version used, it is not possible to extract the ASN.1 content
|
||||||
|
of the extension, but only to provide the re-encoded content of the extension in case it was parsed by C(cryptography).
|
||||||
|
This should usually result in exactly the same value, except if the original extension value was malformed.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: "MAMCAQU="
|
||||||
|
sample: {"1.3.6.1.5.5.7.1.24": {"critical": false, "value": "MAMCAQU="}}
|
||||||
|
key_usage:
|
||||||
|
description: Entries in the C(key_usage) extension, or V(none) if extension is not present.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: [Key Agreement, Data Encipherment]
|
||||||
|
key_usage_critical:
|
||||||
|
description: Whether the C(key_usage) extension is critical.
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
subject_alt_name:
|
||||||
|
description:
|
||||||
|
- Entries in the C(subject_alt_name) extension, or V(none) if extension is not present.
|
||||||
|
- See O(name_encoding) for how IDNs are handled.
|
||||||
|
returned: success
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
sample: ["DNS:www.ansible.com", "IP:1.2.3.4"]
|
||||||
|
subject_alt_name_critical:
|
||||||
|
description: Whether the C(subject_alt_name) extension is critical.
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
ocsp_must_staple:
|
||||||
|
description: V(true) if the OCSP Must Staple extension is present, V(none) otherwise.
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
ocsp_must_staple_critical:
|
||||||
|
description: Whether the C(ocsp_must_staple) extension is critical.
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
issuer:
|
||||||
|
description:
|
||||||
|
- The certificate's issuer.
|
||||||
|
- Note that for repeated values, only the last one will be returned.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
sample: {"organizationName": "Ansible", "commonName": "ca.example.com"}
|
||||||
|
issuer_ordered:
|
||||||
|
description: The certificate's issuer as an ordered list of tuples.
|
||||||
|
returned: success
|
||||||
|
type: list
|
||||||
|
elements: list
|
||||||
|
sample: [["organizationName", "Ansible"], ["commonName": "ca.example.com"]]
|
||||||
|
subject:
|
||||||
|
description:
|
||||||
|
- The certificate's subject as a dictionary.
|
||||||
|
- Note that for repeated values, only the last one will be returned.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
sample: {"commonName": "www.example.com", "emailAddress": "test@example.com"}
|
||||||
|
subject_ordered:
|
||||||
|
description: The certificate's subject as an ordered list of tuples.
|
||||||
|
returned: success
|
||||||
|
type: list
|
||||||
|
elements: list
|
||||||
|
sample: [["commonName", "www.example.com"], ["emailAddress": "test@example.com"]]
|
||||||
|
not_after:
|
||||||
|
description: C(notAfter) date as ASN.1 TIME.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: '20190413202428Z'
|
||||||
|
not_before:
|
||||||
|
description: C(notBefore) date as ASN.1 TIME.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: '20190331202428Z'
|
||||||
|
public_key:
|
||||||
|
description: Certificate's public key in PEM format.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8A..."
|
||||||
|
public_key_type:
|
||||||
|
description:
|
||||||
|
- The certificate's public key's type.
|
||||||
|
- One of V(RSA), V(DSA), V(ECC), V(Ed25519), V(X25519), V(Ed448), or V(X448).
|
||||||
|
- Will start with V(unknown) if the key type cannot be determined.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: RSA
|
||||||
|
public_key_data:
|
||||||
|
description:
|
||||||
|
- Public key data. Depends on the public key's type.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
contains:
|
||||||
|
size:
|
||||||
|
description:
|
||||||
|
- Bit size of modulus (RSA) or prime number (DSA).
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.public_key_type=RSA) or RV(_value.public_key_type=DSA)
|
||||||
|
modulus:
|
||||||
|
description:
|
||||||
|
- The RSA key's modulus.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.public_key_type=RSA)
|
||||||
|
exponent:
|
||||||
|
description:
|
||||||
|
- The RSA key's public exponent.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.public_key_type=RSA)
|
||||||
|
p:
|
||||||
|
description:
|
||||||
|
- The C(p) value for DSA.
|
||||||
|
- This is the prime modulus upon which arithmetic takes place.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.public_key_type=DSA)
|
||||||
|
q:
|
||||||
|
description:
|
||||||
|
- The C(q) value for DSA.
|
||||||
|
- This is a prime that divides C(p - 1), and at the same time the order of the subgroup of the multiplicative
|
||||||
|
group of the prime field used.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.public_key_type=DSA)
|
||||||
|
g:
|
||||||
|
description:
|
||||||
|
- The C(g) value for DSA.
|
||||||
|
- This is the element spanning the subgroup of the multiplicative group of the prime field used.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.public_key_type=DSA)
|
||||||
|
curve:
|
||||||
|
description:
|
||||||
|
- The curve's name for ECC.
|
||||||
|
type: str
|
||||||
|
returned: When RV(_value.public_key_type=ECC)
|
||||||
|
exponent_size:
|
||||||
|
description:
|
||||||
|
- The maximum number of bits of a private key. This is basically the bit size of the subgroup used.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.public_key_type=ECC)
|
||||||
|
x:
|
||||||
|
description:
|
||||||
|
- The C(x) coordinate for the public point on the elliptic curve.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.public_key_type=ECC)
|
||||||
|
y:
|
||||||
|
description:
|
||||||
|
- For RV(_value.public_key_type=ECC), this is the C(y) coordinate for the public point on the elliptic curve.
|
||||||
|
- For RV(_value.public_key_type=DSA), this is the publicly known group element whose discrete logarithm with respect
|
||||||
|
to C(g) is the private key.
|
||||||
|
type: int
|
||||||
|
returned: When RV(_value.public_key_type=DSA) or RV(_value.public_key_type=ECC)
|
||||||
|
public_key_fingerprints:
|
||||||
|
description:
|
||||||
|
- Fingerprints of certificate's public key.
|
||||||
|
- For every hash algorithm available, the fingerprint is computed.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
sample: "{'sha256': 'd4:b3:aa:6d:c8:04:ce:4e:ba:f6:29:4d:92:a3:94:b0:c2:ff:bd:bf:33:63:11:43:34:0f:51:b0:95:09:2f:63',
|
||||||
|
'sha512': 'f7:07:4a:f0:b0:f0:e6:8b:95:5f:f9:e6:61:0a:32:68:f1..."
|
||||||
|
fingerprints:
|
||||||
|
description:
|
||||||
|
- Fingerprints of the DER-encoded form of the whole certificate.
|
||||||
|
- For every hash algorithm available, the fingerprint is computed.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
sample: "{'sha256': 'd4:b3:aa:6d:c8:04:ce:4e:ba:f6:29:4d:92:a3:94:b0:c2:ff:bd:bf:33:63:11:43:34:0f:51:b0:95:09:2f:63',
|
||||||
|
'sha512': 'f7:07:4a:f0:b0:f0:e6:8b:95:5f:f9:e6:61:0a:32:68:f1..."
|
||||||
|
signature_algorithm:
|
||||||
|
description: The signature algorithm used to sign the certificate.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: sha256WithRSAEncryption
|
||||||
|
serial_number:
|
||||||
|
description:
|
||||||
|
- The certificate's serial number.
|
||||||
|
- This return value is an B(integer). If you need the serial numbers as a colon-separated hex string, such as C(11:22:33),
|
||||||
|
you need to convert it to that form with P(community.crypto.to_serial#filter).
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
sample: 1234
|
||||||
|
version:
|
||||||
|
description: The certificate version.
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
sample: 3
|
||||||
|
subject_key_identifier:
|
||||||
|
description:
|
||||||
|
- The certificate's subject key identifier.
|
||||||
|
- The identifier is returned in hexadecimal, with V(:) used to separate bytes.
|
||||||
|
- Is V(none) if the C(SubjectKeyIdentifier) extension is not present.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: '00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33'
|
||||||
|
authority_key_identifier:
|
||||||
|
description:
|
||||||
|
- The certificate's authority key identifier.
|
||||||
|
- The identifier is returned in hexadecimal, with V(:) used to separate bytes.
|
||||||
|
- Is V(none) if the C(AuthorityKeyIdentifier) extension is not present.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: '00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33'
|
||||||
|
authority_cert_issuer:
|
||||||
|
description:
|
||||||
|
- The certificate's authority cert issuer as a list of general names.
|
||||||
|
- Is V(none) if the C(AuthorityKeyIdentifier) extension is not present.
|
||||||
|
- See O(name_encoding) for how IDNs are handled.
|
||||||
|
returned: success
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
sample: ["DNS:www.ansible.com", "IP:1.2.3.4"]
|
||||||
|
authority_cert_serial_number:
|
||||||
|
description:
|
||||||
|
- The certificate's authority cert serial number.
|
||||||
|
- Is V(none) if the C(AuthorityKeyIdentifier) extension is not present.
|
||||||
|
- This return value is an B(integer). If you need the serial numbers as a colon-separated hex string, such as C(11:22:33),
|
||||||
|
you need to convert it to that form with P(community.crypto.to_serial#filter).
|
||||||
|
returned: success
|
||||||
|
type: int
|
||||||
|
sample: 12345
|
||||||
|
ocsp_uri:
|
||||||
|
description: The OCSP responder URI, if included in the certificate. Will be V(none) if no OCSP responder URI is included.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
issuer_uri:
|
||||||
|
description: The Issuer URI, if included in the certificate. Will be V(none) if no issuer URI is included.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
"""
|
||||||
|
|
||||||
|
import typing as t
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
from ansible.errors import AnsibleFilterError
|
||||||
|
from ansible.module_utils.common.text.converters import to_bytes, to_text
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.basic import (
|
||||||
|
OpenSSLObjectError,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.module_backends.certificate_info import (
|
||||||
|
get_certificate_info,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.plugin_utils._filter_module import (
|
||||||
|
FilterModuleMock,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def x509_certificate_info_filter(
|
||||||
|
data: str | bytes, name_encoding: t.Literal["ignore", "idna", "unicode"] = "ignore"
|
||||||
|
) -> dict[str, t.Any]:
|
||||||
|
"""Extract information from X.509 PEM certificate."""
|
||||||
|
if not isinstance(data, (str, bytes)):
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
f"The community.crypto.x509_certificate_info input must be a text type, not {type(data)}"
|
||||||
|
)
|
||||||
|
if not isinstance(name_encoding, (str, bytes)):
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
f"The name_encoding option must be of a text type, not {type(name_encoding)}"
|
||||||
|
)
|
||||||
|
name_encoding = t.cast(
|
||||||
|
t.Literal["ignore", "idna", "unicode"], to_text(name_encoding)
|
||||||
|
)
|
||||||
|
if name_encoding not in ("ignore", "idna", "unicode"):
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
f'The name_encoding option must be one of the values "ignore", "idna", or "unicode", not "{name_encoding}"'
|
||||||
|
)
|
||||||
|
|
||||||
|
module = FilterModuleMock({"name_encoding": name_encoding})
|
||||||
|
try:
|
||||||
|
return get_certificate_info(module=module, content=to_bytes(data))
|
||||||
|
except OpenSSLObjectError as exc:
|
||||||
|
raise AnsibleFilterError(str(exc)) from exc
|
||||||
|
|
||||||
|
|
||||||
|
class FilterModule:
|
||||||
|
"""Ansible jinja2 filters"""
|
||||||
|
|
||||||
|
def filters(self) -> dict[str, Callable]:
|
||||||
|
return {
|
||||||
|
"x509_certificate_info": x509_certificate_info_filter,
|
||||||
|
}
|
||||||
227
plugins/filter/x509_crl_info.py
Normal file
227
plugins/filter/x509_crl_info.py
Normal file
@@ -0,0 +1,227 @@
|
|||||||
|
# Copyright (c) 2022, Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
DOCUMENTATION = r"""
|
||||||
|
name: x509_crl_info
|
||||||
|
short_description: Retrieve information from X.509 CRLs in PEM format
|
||||||
|
version_added: 2.10.0
|
||||||
|
author:
|
||||||
|
- Felix Fontein (@felixfontein)
|
||||||
|
description:
|
||||||
|
- Provided a X.509 crl in PEM format, retrieve information.
|
||||||
|
- This is a filter version of the M(community.crypto.x509_crl_info) module.
|
||||||
|
options:
|
||||||
|
_input:
|
||||||
|
description:
|
||||||
|
- The content of the X.509 CRL in PEM format.
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
list_revoked_certificates:
|
||||||
|
description:
|
||||||
|
- If set to V(false), the list of revoked certificates is not included in the result.
|
||||||
|
- This is useful when retrieving information on large CRL files. Enumerating all revoked certificates can take some
|
||||||
|
time, including serializing the result as JSON, sending it to the Ansible controller, and decoding it again.
|
||||||
|
type: bool
|
||||||
|
default: true
|
||||||
|
version_added: 1.7.0
|
||||||
|
extends_documentation_fragment:
|
||||||
|
- community.crypto._name_encoding
|
||||||
|
seealso:
|
||||||
|
- module: community.crypto.x509_crl_info
|
||||||
|
- plugin: community.crypto.to_serial
|
||||||
|
plugin_type: filter
|
||||||
|
"""
|
||||||
|
|
||||||
|
EXAMPLES = r"""
|
||||||
|
---
|
||||||
|
- name: Show the Organization Name of the CRL's subject
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: >-
|
||||||
|
{{
|
||||||
|
(
|
||||||
|
lookup('ansible.builtin.file', '/path/to/cert.pem')
|
||||||
|
| community.crypto.x509_crl_info
|
||||||
|
).issuer.organizationName
|
||||||
|
}}
|
||||||
|
"""
|
||||||
|
|
||||||
|
RETURN = r"""
|
||||||
|
_value:
|
||||||
|
description:
|
||||||
|
- Information on the CRL.
|
||||||
|
type: dict
|
||||||
|
contains:
|
||||||
|
format:
|
||||||
|
description:
|
||||||
|
- Whether the CRL is in PEM format (V(pem)) or in DER format (V(der)).
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: pem
|
||||||
|
choices:
|
||||||
|
- pem
|
||||||
|
- der
|
||||||
|
issuer:
|
||||||
|
description:
|
||||||
|
- The CRL's issuer.
|
||||||
|
- Note that for repeated values, only the last one will be returned.
|
||||||
|
- See O(name_encoding) for how IDNs are handled.
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
|
sample: {"organizationName": "Ansible", "commonName": "ca.example.com"}
|
||||||
|
issuer_ordered:
|
||||||
|
description: The CRL's issuer as an ordered list of tuples.
|
||||||
|
returned: success
|
||||||
|
type: list
|
||||||
|
elements: list
|
||||||
|
sample: [["organizationName", "Ansible"], ["commonName": "ca.example.com"]]
|
||||||
|
last_update:
|
||||||
|
description: The point in time from which this CRL can be trusted as ASN.1 TIME.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: '20190413202428Z'
|
||||||
|
next_update:
|
||||||
|
description: The point in time from which a new CRL will be issued and the client has to check for it as ASN.1 TIME.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: '20190413202428Z'
|
||||||
|
digest:
|
||||||
|
description: The signature algorithm used to sign the CRL.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
sample: sha256WithRSAEncryption
|
||||||
|
revoked_certificates:
|
||||||
|
description: List of certificates to be revoked.
|
||||||
|
returned: success if O(list_revoked_certificates=true)
|
||||||
|
type: list
|
||||||
|
elements: dict
|
||||||
|
contains:
|
||||||
|
serial_number:
|
||||||
|
description:
|
||||||
|
- Serial number of the certificate.
|
||||||
|
- This return value is an B(integer). If you need the serial numbers as a colon-separated hex string, such as
|
||||||
|
C(11:22:33), you need to convert it to that form with P(community.crypto.to_serial#filter).
|
||||||
|
type: int
|
||||||
|
sample: 1234
|
||||||
|
revocation_date:
|
||||||
|
description: The point in time the certificate was revoked as ASN.1 TIME.
|
||||||
|
type: str
|
||||||
|
sample: '20190413202428Z'
|
||||||
|
issuer:
|
||||||
|
description:
|
||||||
|
- The certificate's issuer.
|
||||||
|
- See O(name_encoding) for how IDNs are handled.
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
|
sample: ["DNS:ca.example.org"]
|
||||||
|
issuer_critical:
|
||||||
|
description: Whether the certificate issuer extension is critical.
|
||||||
|
type: bool
|
||||||
|
sample: false
|
||||||
|
reason:
|
||||||
|
description:
|
||||||
|
- The value for the revocation reason extension.
|
||||||
|
type: str
|
||||||
|
sample: key_compromise
|
||||||
|
choices:
|
||||||
|
- unspecified
|
||||||
|
- key_compromise
|
||||||
|
- ca_compromise
|
||||||
|
- affiliation_changed
|
||||||
|
- superseded
|
||||||
|
- cessation_of_operation
|
||||||
|
- certificate_hold
|
||||||
|
- privilege_withdrawn
|
||||||
|
- aa_compromise
|
||||||
|
- remove_from_crl
|
||||||
|
reason_critical:
|
||||||
|
description: Whether the revocation reason extension is critical.
|
||||||
|
type: bool
|
||||||
|
sample: false
|
||||||
|
invalidity_date:
|
||||||
|
description: |-
|
||||||
|
The point in time it was known/suspected that the private key was compromised
|
||||||
|
or that the certificate otherwise became invalid as ASN.1 TIME.
|
||||||
|
type: str
|
||||||
|
sample: '20190413202428Z'
|
||||||
|
invalidity_date_critical:
|
||||||
|
description: Whether the invalidity date extension is critical.
|
||||||
|
type: bool
|
||||||
|
sample: false
|
||||||
|
"""
|
||||||
|
|
||||||
|
import base64
|
||||||
|
import binascii
|
||||||
|
import typing as t
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
from ansible.errors import AnsibleFilterError
|
||||||
|
from ansible.module_utils.common.text.converters import to_bytes, to_text
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.basic import (
|
||||||
|
OpenSSLObjectError,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.module_backends.crl_info import (
|
||||||
|
get_crl_info,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.pem import (
|
||||||
|
identify_pem_format,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.plugin_utils._filter_module import (
|
||||||
|
FilterModuleMock,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def x509_crl_info_filter(
|
||||||
|
data: str | bytes,
|
||||||
|
name_encoding: t.Literal["ignore", "idna", "unicode"] = "ignore",
|
||||||
|
list_revoked_certificates: bool = True,
|
||||||
|
) -> dict[str, t.Any]:
|
||||||
|
"""Extract information from X.509 PEM certificate."""
|
||||||
|
if not isinstance(data, (str, bytes)):
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
f"The community.crypto.x509_crl_info input must be a text type, not {type(data)}"
|
||||||
|
)
|
||||||
|
if not isinstance(name_encoding, (str, bytes)):
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
f"The name_encoding option must be of a text type, not {type(name_encoding)}"
|
||||||
|
)
|
||||||
|
if not isinstance(list_revoked_certificates, bool):
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
f"The list_revoked_certificates option must be a boolean, not {type(list_revoked_certificates)}"
|
||||||
|
)
|
||||||
|
name_encoding = t.cast(
|
||||||
|
t.Literal["ignore", "idna", "unicode"], to_text(name_encoding)
|
||||||
|
)
|
||||||
|
if name_encoding not in ("ignore", "idna", "unicode"):
|
||||||
|
raise AnsibleFilterError(
|
||||||
|
f'The name_encoding option must be one of the values "ignore", "idna", or "unicode", not "{name_encoding}"'
|
||||||
|
)
|
||||||
|
|
||||||
|
data_bytes = to_bytes(data)
|
||||||
|
if not identify_pem_format(data_bytes):
|
||||||
|
try:
|
||||||
|
data_bytes = base64.b64decode(to_text(data_bytes))
|
||||||
|
except (binascii.Error, TypeError, ValueError, UnicodeEncodeError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
module = FilterModuleMock({"name_encoding": name_encoding})
|
||||||
|
try:
|
||||||
|
return get_crl_info(
|
||||||
|
module=module,
|
||||||
|
content=data_bytes,
|
||||||
|
list_revoked_certificates=list_revoked_certificates,
|
||||||
|
)
|
||||||
|
except OpenSSLObjectError as exc:
|
||||||
|
raise AnsibleFilterError(str(exc)) from exc
|
||||||
|
|
||||||
|
|
||||||
|
class FilterModule:
|
||||||
|
"""Ansible jinja2 filters"""
|
||||||
|
|
||||||
|
def filters(self) -> dict[str, Callable]:
|
||||||
|
return {
|
||||||
|
"x509_crl_info": x509_crl_info_filter,
|
||||||
|
}
|
||||||
83
plugins/lookup/gpg_fingerprint.py
Normal file
83
plugins/lookup/gpg_fingerprint.py
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
# Copyright (c) 2023, Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
DOCUMENTATION = r"""
|
||||||
|
name: gpg_fingerprint
|
||||||
|
short_description: Retrieve a GPG fingerprint from a GPG public or private key file
|
||||||
|
author: Felix Fontein (@felixfontein)
|
||||||
|
version_added: 2.15.0
|
||||||
|
description:
|
||||||
|
- Takes a list of filenames pointing to GPG public or private key files. Returns the fingerprints for each of these keys.
|
||||||
|
options:
|
||||||
|
_terms:
|
||||||
|
description:
|
||||||
|
- A path to a GPG public or private key.
|
||||||
|
type: list
|
||||||
|
elements: path
|
||||||
|
required: true
|
||||||
|
requirements:
|
||||||
|
- GnuPG (C(gpg) executable)
|
||||||
|
seealso:
|
||||||
|
- plugin: community.crypto.gpg_fingerprint
|
||||||
|
plugin_type: filter
|
||||||
|
"""
|
||||||
|
|
||||||
|
EXAMPLES = r"""
|
||||||
|
---
|
||||||
|
- name: Show fingerprint of GPG public key
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "{{ lookup('community.crypto.gpg_fingerprint', '/path/to/public_key.gpg') }}"
|
||||||
|
"""
|
||||||
|
|
||||||
|
RETURN = r"""
|
||||||
|
_value:
|
||||||
|
description:
|
||||||
|
- The fingerprints of the provided public or private GPG keys.
|
||||||
|
- The list has one entry for every path provided.
|
||||||
|
type: list
|
||||||
|
elements: string
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import typing as t
|
||||||
|
|
||||||
|
from ansible.errors import AnsibleLookupError
|
||||||
|
from ansible.module_utils.common.text.converters import to_text
|
||||||
|
from ansible.plugins.lookup import LookupBase
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._gnupg.cli import (
|
||||||
|
GPGError,
|
||||||
|
get_fingerprint_from_file,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.plugin_utils._gnupg import (
|
||||||
|
PluginGPGRunner,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class LookupModule(LookupBase):
|
||||||
|
def run(
|
||||||
|
self, terms: list[t.Any], variables: None = None, **kwargs: t.Any
|
||||||
|
) -> list[str]:
|
||||||
|
self.set_options(direct=kwargs)
|
||||||
|
if self._loader is None:
|
||||||
|
raise AssertionError(
|
||||||
|
"Contract violation: self._loader is None"
|
||||||
|
) # pragma: no cover
|
||||||
|
|
||||||
|
try:
|
||||||
|
gpg = PluginGPGRunner(cwd=self._loader.get_basedir())
|
||||||
|
result = []
|
||||||
|
for i, path in enumerate(terms):
|
||||||
|
if not isinstance(path, (str, bytes, os.PathLike)):
|
||||||
|
raise AnsibleLookupError(
|
||||||
|
f"Lookup parameter #{i} should be string or a path object, but got {type(path)}"
|
||||||
|
)
|
||||||
|
result.append(
|
||||||
|
get_fingerprint_from_file(gpg_runner=gpg, path=to_text(path))
|
||||||
|
)
|
||||||
|
return result
|
||||||
|
except GPGError as exc:
|
||||||
|
raise AnsibleLookupError(str(exc)) from exc
|
||||||
368
plugins/module_utils/_acme/account.py
Normal file
368
plugins/module_utils/_acme/account.py
Normal file
@@ -0,0 +1,368 @@
|
|||||||
|
# Copyright (c) 2016 Michael Gruener <michael.gruener@chaosmoon.net>
|
||||||
|
# Copyright (c) 2021 Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import typing as t
|
||||||
|
from collections.abc import Mapping
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.errors import (
|
||||||
|
ACMEProtocolException,
|
||||||
|
ModuleFailException,
|
||||||
|
)
|
||||||
|
|
||||||
|
if t.TYPE_CHECKING:
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.acme import ( # pragma: no cover
|
||||||
|
ACMEClient,
|
||||||
|
)
|
||||||
|
|
||||||
|
_JsonMapping = Mapping[str, t.Any]
|
||||||
|
else:
|
||||||
|
# Since we need to pass this to t.cast(), we need a version that doesn't break with Python 3.7 and 3.8
|
||||||
|
_JsonMapping = Mapping
|
||||||
|
|
||||||
|
|
||||||
|
class ACMEAccount:
|
||||||
|
"""
|
||||||
|
ACME account object. Allows to create new accounts, check for existence of accounts,
|
||||||
|
retrieve account data.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, *, client: ACMEClient) -> None:
|
||||||
|
# Set to true to enable logging of all signed requests
|
||||||
|
self._debug: bool = False
|
||||||
|
|
||||||
|
self.client = client
|
||||||
|
|
||||||
|
def _new_reg(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
contact: list[str] | None = None,
|
||||||
|
terms_agreed: bool = False,
|
||||||
|
allow_creation: bool = True,
|
||||||
|
external_account_binding: dict[str, t.Any] | None = None,
|
||||||
|
) -> tuple[bool, Mapping[str, t.Any] | None]:
|
||||||
|
"""
|
||||||
|
Registers a new ACME account. Returns a pair ``(created, data)``.
|
||||||
|
Here, ``created`` is ``True`` if the account was created and
|
||||||
|
``False`` if it already existed (e.g. it was not newly created),
|
||||||
|
or does not exist. In case the account was created or exists,
|
||||||
|
``data`` contains the account data; otherwise, it is ``None``.
|
||||||
|
|
||||||
|
If specified, ``external_account_binding`` should be a dictionary
|
||||||
|
with keys ``kid``, ``alg`` and ``key``
|
||||||
|
(https://tools.ietf.org/html/rfc8555#section-7.3.4).
|
||||||
|
|
||||||
|
https://tools.ietf.org/html/rfc8555#section-7.3
|
||||||
|
"""
|
||||||
|
contact = contact or []
|
||||||
|
|
||||||
|
if (
|
||||||
|
external_account_binding is not None
|
||||||
|
or self.client.directory["meta"].get("externalAccountRequired")
|
||||||
|
) and allow_creation:
|
||||||
|
# Some ACME servers such as ZeroSSL do not like it when you try to register an existing account
|
||||||
|
# and provide external_account_binding credentials. Thus we first send a request with allow_creation=False
|
||||||
|
# to see whether the account already exists.
|
||||||
|
|
||||||
|
# Unfortunately, for other ACME servers it's the other way around: (at least some) HARICA endpoints
|
||||||
|
# do not allow *any* access without external account data. That's why we catch errors and check
|
||||||
|
# for 'externalAccountRequired'.
|
||||||
|
try:
|
||||||
|
# Note that we pass contact here: ZeroSSL does not accept registration calls without contacts, even
|
||||||
|
# if onlyReturnExisting is set to true.
|
||||||
|
created, data = self._new_reg(contact=contact, allow_creation=False)
|
||||||
|
if data:
|
||||||
|
# An account already exists! Return data
|
||||||
|
return created, data
|
||||||
|
# An account does not yet exist. Try to create one next.
|
||||||
|
except ACMEProtocolException as exc:
|
||||||
|
if (
|
||||||
|
exc.error_type
|
||||||
|
!= "urn:ietf:params:acme:error:externalAccountRequired"
|
||||||
|
or external_account_binding is None
|
||||||
|
):
|
||||||
|
# Either another error happened, or we got 'externalAccountRequired' and external account data was not supplied
|
||||||
|
# => re-raise exception!
|
||||||
|
raise
|
||||||
|
# In this case, the server really wants external account data.
|
||||||
|
# The below code tries to create the account with external account data present.
|
||||||
|
|
||||||
|
new_reg: dict[str, t.Any] = {"contact": contact}
|
||||||
|
if not allow_creation:
|
||||||
|
# https://tools.ietf.org/html/rfc8555#section-7.3.1
|
||||||
|
new_reg["onlyReturnExisting"] = True
|
||||||
|
if terms_agreed:
|
||||||
|
new_reg["termsOfServiceAgreed"] = True
|
||||||
|
url = self.client.directory["newAccount"]
|
||||||
|
if external_account_binding is not None:
|
||||||
|
new_reg["externalAccountBinding"] = self.client.sign_request(
|
||||||
|
protected={
|
||||||
|
"alg": external_account_binding["alg"],
|
||||||
|
"kid": external_account_binding["kid"],
|
||||||
|
"url": url,
|
||||||
|
},
|
||||||
|
payload=self.client.account_jwk,
|
||||||
|
key_data=self.client.backend.create_mac_key(
|
||||||
|
alg=external_account_binding["alg"],
|
||||||
|
key=external_account_binding["key"],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
elif (
|
||||||
|
self.client.directory["meta"].get("externalAccountRequired")
|
||||||
|
and allow_creation
|
||||||
|
):
|
||||||
|
raise ModuleFailException(
|
||||||
|
"To create an account, an external account binding must be specified. Use the acme_account module with the external_account_binding option."
|
||||||
|
)
|
||||||
|
|
||||||
|
result, info = self.client.send_signed_request(
|
||||||
|
url, new_reg, fail_on_error=False
|
||||||
|
)
|
||||||
|
if not isinstance(result, Mapping):
|
||||||
|
raise ACMEProtocolException(
|
||||||
|
module=self.client.module,
|
||||||
|
msg="Invalid account creation reply from ACME server",
|
||||||
|
info=info,
|
||||||
|
content_json=result,
|
||||||
|
)
|
||||||
|
|
||||||
|
if info["status"] == 201:
|
||||||
|
# Account did not exist
|
||||||
|
if "location" in info:
|
||||||
|
self.client.set_account_uri(info["location"])
|
||||||
|
return True, t.cast(_JsonMapping, result)
|
||||||
|
if info["status"] == 200:
|
||||||
|
# Account did exist
|
||||||
|
if result.get("status") == "deactivated":
|
||||||
|
# A bug in Pebble (https://github.com/letsencrypt/pebble/issues/179) and
|
||||||
|
# Boulder (https://github.com/letsencrypt/boulder/issues/3971): this should
|
||||||
|
# not return a valid account object according to
|
||||||
|
# https://tools.ietf.org/html/rfc8555#section-7.3.6:
|
||||||
|
# "Once an account is deactivated, the server MUST NOT accept further
|
||||||
|
# requests authorized by that account's key."
|
||||||
|
if not allow_creation:
|
||||||
|
return False, None
|
||||||
|
raise ModuleFailException("Account is deactivated")
|
||||||
|
if "location" in info:
|
||||||
|
self.client.set_account_uri(info["location"])
|
||||||
|
return False, t.cast(_JsonMapping, result)
|
||||||
|
if (
|
||||||
|
info["status"] in (400, 404)
|
||||||
|
and result["type"] == "urn:ietf:params:acme:error:accountDoesNotExist"
|
||||||
|
and not allow_creation
|
||||||
|
):
|
||||||
|
# Account does not exist (and we did not try to create it)
|
||||||
|
# (According to RFC 8555, Section 7.3.1, the HTTP status code MUST be 400.
|
||||||
|
# Unfortunately Digicert does not care and sends 404 instead.)
|
||||||
|
return False, None
|
||||||
|
if (
|
||||||
|
info["status"] == 403
|
||||||
|
and result["type"] == "urn:ietf:params:acme:error:unauthorized"
|
||||||
|
and "deactivated" in (result.get("detail") or "")
|
||||||
|
):
|
||||||
|
# Account has been deactivated; currently works for Pebble; has not been
|
||||||
|
# implemented for Boulder (https://github.com/letsencrypt/boulder/issues/3971),
|
||||||
|
# might need adjustment in error detection.
|
||||||
|
if not allow_creation:
|
||||||
|
return False, None
|
||||||
|
raise ModuleFailException("Account is deactivated")
|
||||||
|
raise ACMEProtocolException(
|
||||||
|
module=self.client.module,
|
||||||
|
msg="Registering ACME account failed",
|
||||||
|
info=info,
|
||||||
|
content_json=result,
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_account_data(self) -> dict[str, t.Any] | None:
|
||||||
|
"""
|
||||||
|
Retrieve account information. Can only be called when the account
|
||||||
|
URI is already known (such as after calling setup_account).
|
||||||
|
Return None if the account was deactivated, or a dict otherwise.
|
||||||
|
"""
|
||||||
|
if self.client.account_uri is None:
|
||||||
|
raise ModuleFailException("Account URI unknown")
|
||||||
|
# try POST-as-GET first (draft-15 or newer)
|
||||||
|
data: dict[str, t.Any] | None = None
|
||||||
|
result, info = self.client.send_signed_request(
|
||||||
|
self.client.account_uri, data, fail_on_error=False
|
||||||
|
)
|
||||||
|
# check whether that failed with a malformed request error
|
||||||
|
if (
|
||||||
|
info["status"] >= 400
|
||||||
|
and isinstance(result, Mapping)
|
||||||
|
and result.get("type") == "urn:ietf:params:acme:error:malformed"
|
||||||
|
):
|
||||||
|
# retry as a regular POST (with no changed data) for pre-draft-15 ACME servers
|
||||||
|
data = {}
|
||||||
|
result, info = self.client.send_signed_request(
|
||||||
|
self.client.account_uri, data, fail_on_error=False
|
||||||
|
)
|
||||||
|
if not isinstance(result, dict):
|
||||||
|
raise ACMEProtocolException(
|
||||||
|
module=self.client.module,
|
||||||
|
msg="Invalid account data retrieved from ACME server",
|
||||||
|
info=info,
|
||||||
|
content_json=result,
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
info["status"] in (400, 403)
|
||||||
|
and result.get("type") == "urn:ietf:params:acme:error:unauthorized"
|
||||||
|
):
|
||||||
|
# Returned when account is deactivated
|
||||||
|
return None
|
||||||
|
if (
|
||||||
|
info["status"] in (400, 404)
|
||||||
|
and result.get("type") == "urn:ietf:params:acme:error:accountDoesNotExist"
|
||||||
|
):
|
||||||
|
# Returned when account does not exist
|
||||||
|
return None
|
||||||
|
if info["status"] < 200 or info["status"] >= 300:
|
||||||
|
raise ACMEProtocolException(
|
||||||
|
module=self.client.module,
|
||||||
|
msg="Error retrieving account data",
|
||||||
|
info=info,
|
||||||
|
content_json=result,
|
||||||
|
)
|
||||||
|
return result
|
||||||
|
|
||||||
|
@t.overload
|
||||||
|
def setup_account(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
contact: list[str] | None = None,
|
||||||
|
terms_agreed: bool = False,
|
||||||
|
allow_creation: t.Literal[True] = True,
|
||||||
|
remove_account_uri_if_not_exists: bool = False,
|
||||||
|
external_account_binding: dict[str, t.Any] | None = None,
|
||||||
|
) -> tuple[bool, Mapping[str, t.Any]]: ...
|
||||||
|
|
||||||
|
@t.overload
|
||||||
|
def setup_account(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
contact: list[str] | None = None,
|
||||||
|
terms_agreed: bool = False,
|
||||||
|
allow_creation: bool = True,
|
||||||
|
remove_account_uri_if_not_exists: bool = False,
|
||||||
|
external_account_binding: dict[str, t.Any] | None = None,
|
||||||
|
) -> tuple[bool, Mapping[str, t.Any] | None]: ...
|
||||||
|
|
||||||
|
def setup_account(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
contact: list[str] | None = None,
|
||||||
|
terms_agreed: bool = False,
|
||||||
|
allow_creation: bool = True,
|
||||||
|
remove_account_uri_if_not_exists: bool = False,
|
||||||
|
external_account_binding: dict[str, t.Any] | None = None,
|
||||||
|
) -> tuple[bool, Mapping[str, t.Any] | None]:
|
||||||
|
"""
|
||||||
|
Detect or create an account on the ACME server. For ACME v1,
|
||||||
|
as the only way (without knowing an account URI) to test if an
|
||||||
|
account exists is to try and create one with the provided account
|
||||||
|
key, this method will always result in an account being present
|
||||||
|
(except on error situations). For ACME v2, a new account will
|
||||||
|
only be created if ``allow_creation`` is set to True.
|
||||||
|
|
||||||
|
For ACME v2, ``check_mode`` is fully respected. For ACME v1, the
|
||||||
|
account might be created if it does not yet exist.
|
||||||
|
|
||||||
|
Return a pair ``(created, account_data)``. Here, ``created`` will
|
||||||
|
be ``True`` in case the account was created or would be created
|
||||||
|
(check mode). ``account_data`` will be the current account data,
|
||||||
|
or ``None`` if the account does not exist.
|
||||||
|
|
||||||
|
The account URI will be stored in ``client.account_uri``; if it is ``None``,
|
||||||
|
the account does not exist.
|
||||||
|
|
||||||
|
If specified, ``external_account_binding`` should be a dictionary
|
||||||
|
with keys ``kid``, ``alg`` and ``key``
|
||||||
|
(https://tools.ietf.org/html/rfc8555#section-7.3.4).
|
||||||
|
|
||||||
|
https://tools.ietf.org/html/rfc8555#section-7.3
|
||||||
|
"""
|
||||||
|
|
||||||
|
if self.client.account_uri is not None:
|
||||||
|
created = False
|
||||||
|
# Verify that the account key belongs to the URI.
|
||||||
|
# (If update_contact is True, this will be done below.)
|
||||||
|
account_data: Mapping[str, t.Any] | None = self.get_account_data()
|
||||||
|
if account_data is None:
|
||||||
|
if remove_account_uri_if_not_exists and not allow_creation:
|
||||||
|
self.client.account_uri = None
|
||||||
|
else:
|
||||||
|
raise ModuleFailException(
|
||||||
|
"Account is deactivated or does not exist!"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
created, account_data = self._new_reg(
|
||||||
|
contact=contact,
|
||||||
|
terms_agreed=terms_agreed,
|
||||||
|
allow_creation=allow_creation and not self.client.module.check_mode,
|
||||||
|
external_account_binding=external_account_binding,
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
self.client.module.check_mode
|
||||||
|
and self.client.account_uri is None
|
||||||
|
and allow_creation
|
||||||
|
):
|
||||||
|
created = True
|
||||||
|
account_data = {"contact": contact or []}
|
||||||
|
return created, account_data
|
||||||
|
|
||||||
|
def update_account(
|
||||||
|
self, *, account_data: dict[str, t.Any], contact: list[str] | None = None
|
||||||
|
) -> tuple[bool, Mapping[str, t.Any]]:
|
||||||
|
"""
|
||||||
|
Update an account on the ACME server. Check mode is fully respected.
|
||||||
|
|
||||||
|
The current account data must be provided as ``account_data``.
|
||||||
|
|
||||||
|
Return a pair ``(updated, account_data)``, where ``updated`` is
|
||||||
|
``True`` in case something changed (contact info updated) or
|
||||||
|
would be changed (check mode), and ``account_data`` the updated
|
||||||
|
account data.
|
||||||
|
|
||||||
|
https://tools.ietf.org/html/rfc8555#section-7.3.2
|
||||||
|
"""
|
||||||
|
if self.client.account_uri is None:
|
||||||
|
raise ModuleFailException("Cannot update account without account URI")
|
||||||
|
|
||||||
|
# Create request
|
||||||
|
update_request: dict[str, t.Any] = {}
|
||||||
|
if contact is not None and account_data.get("contact", []) != contact:
|
||||||
|
update_request["contact"] = list(contact)
|
||||||
|
|
||||||
|
# No change?
|
||||||
|
if not update_request:
|
||||||
|
return False, dict(account_data)
|
||||||
|
|
||||||
|
# Apply change
|
||||||
|
account_data_res: Mapping[str, t.Any]
|
||||||
|
if self.client.module.check_mode:
|
||||||
|
account_data_dict = dict(account_data)
|
||||||
|
account_data_dict.update(update_request)
|
||||||
|
account_data_res = account_data_dict
|
||||||
|
else:
|
||||||
|
raw_account_data, info = self.client.send_signed_request(
|
||||||
|
self.client.account_uri, update_request
|
||||||
|
)
|
||||||
|
if not isinstance(raw_account_data, Mapping):
|
||||||
|
raise ACMEProtocolException(
|
||||||
|
module=self.client.module,
|
||||||
|
msg="Invalid account updating reply from ACME server",
|
||||||
|
info=info,
|
||||||
|
content_json=account_data,
|
||||||
|
)
|
||||||
|
account_data_res = raw_account_data
|
||||||
|
|
||||||
|
return True, account_data_res
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ("ACMEAccount",)
|
||||||
816
plugins/module_utils/_acme/acme.py
Normal file
816
plugins/module_utils/_acme/acme.py
Normal file
@@ -0,0 +1,816 @@
|
|||||||
|
# Copyright (c) 2016 Michael Gruener <michael.gruener@chaosmoon.net>
|
||||||
|
# Copyright (c) 2021 Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import copy
|
||||||
|
import datetime
|
||||||
|
import json
|
||||||
|
import locale
|
||||||
|
import time
|
||||||
|
import typing as t
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import missing_required_lib
|
||||||
|
from ansible.module_utils.common.text.converters import to_bytes
|
||||||
|
from ansible.module_utils.urls import fetch_url
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.backend_cryptography import (
|
||||||
|
CRYPTOGRAPHY_ERROR,
|
||||||
|
CRYPTOGRAPHY_MINIMAL_VERSION,
|
||||||
|
CRYPTOGRAPHY_VERSION,
|
||||||
|
HAS_CURRENT_CRYPTOGRAPHY,
|
||||||
|
CryptographyBackend,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.backend_openssl_cli import (
|
||||||
|
OpenSSLCLIBackend,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.errors import (
|
||||||
|
ACMEProtocolException,
|
||||||
|
KeyParsingError,
|
||||||
|
ModuleFailException,
|
||||||
|
NetworkException,
|
||||||
|
format_http_status,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.utils import (
|
||||||
|
compute_cert_id,
|
||||||
|
nopad_b64,
|
||||||
|
parse_retry_after,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._argspec import (
|
||||||
|
ArgumentSpec,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._time import (
|
||||||
|
get_now_datetime,
|
||||||
|
)
|
||||||
|
|
||||||
|
if t.TYPE_CHECKING:
|
||||||
|
import http.client # pragma: no cover
|
||||||
|
import os # pragma: no cover
|
||||||
|
import urllib.error # pragma: no cover
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule # pragma: no cover
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.backends import ( # pragma: no cover
|
||||||
|
CertificateInformation,
|
||||||
|
CryptoBackend,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# -1 usually means connection problems
|
||||||
|
RETRY_STATUS_CODES = (-1, 408, 429, 502, 503, 504)
|
||||||
|
|
||||||
|
RETRY_COUNT = 20
|
||||||
|
|
||||||
|
|
||||||
|
def _decode_retry(
|
||||||
|
*,
|
||||||
|
module: AnsibleModule,
|
||||||
|
response: urllib.error.HTTPError | http.client.HTTPResponse | None,
|
||||||
|
info: dict[str, t.Any],
|
||||||
|
retry_count: int,
|
||||||
|
) -> bool:
|
||||||
|
if info["status"] not in RETRY_STATUS_CODES:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if retry_count >= RETRY_COUNT:
|
||||||
|
raise ACMEProtocolException(
|
||||||
|
module=module,
|
||||||
|
msg=f"Giving up after {RETRY_COUNT} retries",
|
||||||
|
info=info,
|
||||||
|
response=response,
|
||||||
|
)
|
||||||
|
|
||||||
|
# 429 and 503 should have a Retry-After header (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After)
|
||||||
|
now = get_now_datetime(with_timezone=True)
|
||||||
|
try:
|
||||||
|
then = parse_retry_after(
|
||||||
|
info.get("retry-after", "10"), relative_with_timezone=True, now=now
|
||||||
|
)
|
||||||
|
retry_after = (then - now).total_seconds()
|
||||||
|
retry_after = min(max(1, retry_after), 60)
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
retry_after = 10
|
||||||
|
module.log(
|
||||||
|
f"Retrieved a {format_http_status(info['status'])} HTTP status on {info['url']}, retrying in {retry_after} seconds"
|
||||||
|
)
|
||||||
|
|
||||||
|
time.sleep(retry_after)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def _assert_fetch_url_success(
|
||||||
|
*,
|
||||||
|
module: AnsibleModule,
|
||||||
|
response: urllib.error.HTTPError | http.client.HTTPResponse | None,
|
||||||
|
info: dict[str, t.Any],
|
||||||
|
allow_redirect: bool = False,
|
||||||
|
allow_client_error: bool = True,
|
||||||
|
allow_server_error: bool = True,
|
||||||
|
) -> None:
|
||||||
|
if info["status"] < 0:
|
||||||
|
raise NetworkException(msg=f"Failure downloading {info['url']}, {info['msg']}")
|
||||||
|
|
||||||
|
if (
|
||||||
|
(300 <= info["status"] < 400 and not allow_redirect)
|
||||||
|
or (400 <= info["status"] < 500 and not allow_client_error)
|
||||||
|
or (info["status"] >= 500 and not allow_server_error)
|
||||||
|
):
|
||||||
|
raise ACMEProtocolException(module=module, info=info, response=response)
|
||||||
|
|
||||||
|
|
||||||
|
def _is_failed(
|
||||||
|
*, info: dict[str, t.Any], expected_status_codes: t.Iterable[int] | None = None
|
||||||
|
) -> bool:
|
||||||
|
if info["status"] < 200 or info["status"] >= 400:
|
||||||
|
return True
|
||||||
|
return bool(
|
||||||
|
expected_status_codes is not None
|
||||||
|
and info["status"] not in expected_status_codes
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ACMEDirectory:
|
||||||
|
"""
|
||||||
|
The ACME server directory. Gives access to the available resources,
|
||||||
|
and allows to obtain a Replay-Nonce. The acme_directory URL
|
||||||
|
needs to support unauthenticated GET requests; ACME endpoints
|
||||||
|
requiring authentication are not supported.
|
||||||
|
https://tools.ietf.org/html/rfc8555#section-7.1.1
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, *, module: AnsibleModule, client: ACMEClient) -> None:
|
||||||
|
self.module = module
|
||||||
|
self.directory_root = module.params["acme_directory"]
|
||||||
|
self.version = module.params["acme_version"]
|
||||||
|
|
||||||
|
directory, info = client.get_request(self.directory_root, get_only=True)
|
||||||
|
if not isinstance(directory, dict):
|
||||||
|
raise ACMEProtocolException(
|
||||||
|
module=module,
|
||||||
|
msg=f"ACME directory is not a dictionary, but {type(directory)}",
|
||||||
|
info=info,
|
||||||
|
content_json=directory,
|
||||||
|
)
|
||||||
|
self.directory = directory
|
||||||
|
|
||||||
|
self.request_timeout = module.params["request_timeout"]
|
||||||
|
|
||||||
|
# Check whether self.version matches what we expect
|
||||||
|
if self.version == 2:
|
||||||
|
for key in ("newNonce", "newAccount", "newOrder"):
|
||||||
|
if key not in self.directory:
|
||||||
|
raise ModuleFailException(
|
||||||
|
"ACME directory does not seem to follow protocol ACME v2"
|
||||||
|
)
|
||||||
|
# Make sure that 'meta' is always available
|
||||||
|
if "meta" not in self.directory:
|
||||||
|
self.directory["meta"] = {}
|
||||||
|
|
||||||
|
def __getitem__(self, key: str) -> t.Any:
|
||||||
|
return self.directory[key]
|
||||||
|
|
||||||
|
def __contains__(self, key: str) -> bool:
|
||||||
|
return key in self.directory
|
||||||
|
|
||||||
|
def get(self, key: str, default_value: t.Any = None) -> t.Any:
|
||||||
|
return self.directory.get(key, default_value)
|
||||||
|
|
||||||
|
def get_nonce(self, resource: str | None = None) -> str:
|
||||||
|
url = self.directory["newNonce"]
|
||||||
|
if resource is not None:
|
||||||
|
url = resource
|
||||||
|
retry_count = 0
|
||||||
|
while True:
|
||||||
|
response, info = fetch_url(
|
||||||
|
self.module, url, method="HEAD", timeout=self.request_timeout
|
||||||
|
)
|
||||||
|
if _decode_retry(
|
||||||
|
module=self.module,
|
||||||
|
response=response,
|
||||||
|
info=info,
|
||||||
|
retry_count=retry_count,
|
||||||
|
):
|
||||||
|
retry_count += 1
|
||||||
|
continue
|
||||||
|
if info["status"] not in (200, 204):
|
||||||
|
raise NetworkException(
|
||||||
|
f"Failed to get replay-nonce, got status {format_http_status(info['status'])}"
|
||||||
|
)
|
||||||
|
if "replay-nonce" in info:
|
||||||
|
return info["replay-nonce"]
|
||||||
|
self.module.log(
|
||||||
|
f"HEAD to {url} did return status {format_http_status(info['status'])}, but no replay-nonce header!"
|
||||||
|
)
|
||||||
|
if retry_count >= 5:
|
||||||
|
raise ACMEProtocolException(
|
||||||
|
module=self.module,
|
||||||
|
msg="Was not able to obtain nonce, giving up after 5 retries",
|
||||||
|
info=info,
|
||||||
|
response=response,
|
||||||
|
)
|
||||||
|
retry_count += 1
|
||||||
|
|
||||||
|
def has_renewal_info_endpoint(self) -> bool:
|
||||||
|
return "renewalInfo" in self.directory
|
||||||
|
|
||||||
|
|
||||||
|
class ACMEClient:
|
||||||
|
"""
|
||||||
|
ACME client object. Handles the authorized communication with the
|
||||||
|
ACME server.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, *, module: AnsibleModule, backend: CryptoBackend) -> None:
|
||||||
|
# Set to true to enable logging of all signed requests
|
||||||
|
self._debug = False
|
||||||
|
|
||||||
|
self.module = module
|
||||||
|
self.backend = backend
|
||||||
|
self.version = module.params["acme_version"]
|
||||||
|
# account_key path and content are mutually exclusive
|
||||||
|
self.account_key_file = module.params.get("account_key_src")
|
||||||
|
self.account_key_content = module.params.get("account_key_content")
|
||||||
|
self.account_key_passphrase = module.params.get("account_key_passphrase")
|
||||||
|
|
||||||
|
# Grab account URI from module parameters.
|
||||||
|
# Make sure empty string is treated as None.
|
||||||
|
self.account_uri = module.params.get("account_uri") or None
|
||||||
|
|
||||||
|
self.request_timeout = module.params["request_timeout"]
|
||||||
|
|
||||||
|
self.account_key_data = None
|
||||||
|
self.account_jwk = None
|
||||||
|
self.account_jws_header = None
|
||||||
|
if self.account_key_file is not None or self.account_key_content is not None:
|
||||||
|
try:
|
||||||
|
self.account_key_data = self.parse_key(
|
||||||
|
key_file=self.account_key_file,
|
||||||
|
key_content=self.account_key_content,
|
||||||
|
passphrase=self.account_key_passphrase,
|
||||||
|
)
|
||||||
|
except KeyParsingError as e:
|
||||||
|
raise ModuleFailException(
|
||||||
|
f"Error while parsing account key: {e.msg}"
|
||||||
|
) from e
|
||||||
|
self.account_jwk = self.account_key_data["jwk"]
|
||||||
|
self.account_jws_header = {
|
||||||
|
"alg": self.account_key_data["alg"],
|
||||||
|
"jwk": self.account_jwk,
|
||||||
|
}
|
||||||
|
if self.account_uri:
|
||||||
|
# Make sure self.account_jws_header is updated
|
||||||
|
self.set_account_uri(self.account_uri)
|
||||||
|
|
||||||
|
self.directory = ACMEDirectory(module=module, client=self)
|
||||||
|
|
||||||
|
def set_account_uri(self, uri: str) -> None:
|
||||||
|
"""
|
||||||
|
Set account URI. For ACME v2, it needs to be used to sending signed
|
||||||
|
requests.
|
||||||
|
"""
|
||||||
|
self.account_uri = uri
|
||||||
|
if self.account_jws_header:
|
||||||
|
self.account_jws_header.pop("jwk", None)
|
||||||
|
self.account_jws_header["kid"] = self.account_uri
|
||||||
|
|
||||||
|
def parse_key(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
key_file: str | os.PathLike | None = None,
|
||||||
|
key_content: str | None = None,
|
||||||
|
passphrase: str | None = None,
|
||||||
|
) -> dict[str, t.Any]:
|
||||||
|
"""
|
||||||
|
Parses an RSA or Elliptic Curve key file in PEM format and returns key_data.
|
||||||
|
In case of an error, raises KeyParsingError.
|
||||||
|
"""
|
||||||
|
if key_file is None and key_content is None:
|
||||||
|
raise AssertionError(
|
||||||
|
"One of key_file and key_content must be specified!"
|
||||||
|
) # pragma: no cover
|
||||||
|
return self.backend.parse_key(
|
||||||
|
key_file=key_file, key_content=key_content, passphrase=passphrase
|
||||||
|
)
|
||||||
|
|
||||||
|
@t.overload
|
||||||
|
def sign_request(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
protected: dict[str, t.Any],
|
||||||
|
payload: dict[str, t.Any] | None,
|
||||||
|
key_data: dict[str, t.Any],
|
||||||
|
encode_payload: t.Literal[True] = True,
|
||||||
|
) -> dict[str, t.Any]: ...
|
||||||
|
|
||||||
|
@t.overload
|
||||||
|
def sign_request(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
protected: dict[str, t.Any],
|
||||||
|
payload: str | bytes | None,
|
||||||
|
key_data: dict[str, t.Any],
|
||||||
|
encode_payload: t.Literal[False],
|
||||||
|
) -> dict[str, t.Any]: ...
|
||||||
|
|
||||||
|
@t.overload
|
||||||
|
def sign_request(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
protected: dict[str, t.Any],
|
||||||
|
payload: str | bytes | dict[str, t.Any] | None,
|
||||||
|
key_data: dict[str, t.Any],
|
||||||
|
encode_payload: bool = True,
|
||||||
|
) -> dict[str, t.Any]: ...
|
||||||
|
|
||||||
|
def sign_request(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
protected: dict[str, t.Any],
|
||||||
|
payload: str | bytes | dict[str, t.Any] | None,
|
||||||
|
key_data: dict[str, t.Any],
|
||||||
|
encode_payload: bool = True,
|
||||||
|
) -> dict[str, t.Any]:
|
||||||
|
"""
|
||||||
|
Signs an ACME request.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
if payload is None:
|
||||||
|
# POST-as-GET
|
||||||
|
payload64 = ""
|
||||||
|
else:
|
||||||
|
# POST
|
||||||
|
if encode_payload:
|
||||||
|
payload = self.module.jsonify(payload).encode("utf8")
|
||||||
|
payload64 = nopad_b64(to_bytes(payload))
|
||||||
|
protected64 = nopad_b64(self.module.jsonify(protected).encode("utf8"))
|
||||||
|
except Exception as e:
|
||||||
|
raise ModuleFailException(
|
||||||
|
f"Failed to encode payload / headers as JSON: {e}"
|
||||||
|
) from e
|
||||||
|
|
||||||
|
return self.backend.sign(
|
||||||
|
payload64=payload64, protected64=protected64, key_data=key_data
|
||||||
|
)
|
||||||
|
|
||||||
|
def _log(self, msg: str, *, data: t.Any = None) -> None:
|
||||||
|
"""
|
||||||
|
Write arguments to acme.log when logging is enabled.
|
||||||
|
"""
|
||||||
|
if self._debug:
|
||||||
|
with open("acme.log", "ab") as f:
|
||||||
|
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%s")
|
||||||
|
f.write(f"[{timestamp}] {msg}\n".encode("utf-8"))
|
||||||
|
if data is not None:
|
||||||
|
f.write(
|
||||||
|
f"{json.dumps(data, indent=2, sort_keys=True)}\n\n".encode(
|
||||||
|
"utf-8"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
@t.overload
|
||||||
|
def send_signed_request(
|
||||||
|
self,
|
||||||
|
url: str,
|
||||||
|
payload: dict[str, t.Any] | None,
|
||||||
|
*,
|
||||||
|
key_data: dict[str, t.Any] | None = None,
|
||||||
|
jws_header: dict[str, t.Any] | None = None,
|
||||||
|
parse_json_result: t.Literal[True] = True,
|
||||||
|
encode_payload: t.Literal[True] = True,
|
||||||
|
fail_on_error: bool = True,
|
||||||
|
error_msg: str | None = None,
|
||||||
|
expected_status_codes: t.Iterable[int] | None = None,
|
||||||
|
) -> tuple[object | bytes, dict[str, t.Any]]: ...
|
||||||
|
|
||||||
|
@t.overload
|
||||||
|
def send_signed_request(
|
||||||
|
self,
|
||||||
|
url: str,
|
||||||
|
payload: str | bytes | None,
|
||||||
|
*,
|
||||||
|
key_data: dict[str, t.Any] | None = None,
|
||||||
|
jws_header: dict[str, t.Any] | None = None,
|
||||||
|
parse_json_result: t.Literal[True] = True,
|
||||||
|
encode_payload: t.Literal[False],
|
||||||
|
fail_on_error: bool = True,
|
||||||
|
error_msg: str | None = None,
|
||||||
|
expected_status_codes: t.Iterable[int] | None = None,
|
||||||
|
) -> tuple[object | bytes, dict[str, t.Any]]: ...
|
||||||
|
|
||||||
|
@t.overload
|
||||||
|
def send_signed_request(
|
||||||
|
self,
|
||||||
|
url: str,
|
||||||
|
payload: dict[str, t.Any] | None,
|
||||||
|
*,
|
||||||
|
key_data: dict[str, t.Any] | None = None,
|
||||||
|
jws_header: dict[str, t.Any] | None = None,
|
||||||
|
parse_json_result: t.Literal[False],
|
||||||
|
encode_payload: t.Literal[True] = True,
|
||||||
|
fail_on_error: bool = True,
|
||||||
|
error_msg: str | None = None,
|
||||||
|
expected_status_codes: t.Iterable[int] | None = None,
|
||||||
|
) -> tuple[bytes, dict[str, t.Any]]: ...
|
||||||
|
|
||||||
|
@t.overload
|
||||||
|
def send_signed_request(
|
||||||
|
self,
|
||||||
|
url: str,
|
||||||
|
payload: str | bytes | None,
|
||||||
|
*,
|
||||||
|
key_data: dict[str, t.Any] | None = None,
|
||||||
|
jws_header: dict[str, t.Any] | None = None,
|
||||||
|
parse_json_result: t.Literal[False],
|
||||||
|
encode_payload: t.Literal[False],
|
||||||
|
fail_on_error: bool = True,
|
||||||
|
error_msg: str | None = None,
|
||||||
|
expected_status_codes: t.Iterable[int] | None = None,
|
||||||
|
) -> tuple[bytes, dict[str, t.Any]]: ...
|
||||||
|
|
||||||
|
def send_signed_request(
|
||||||
|
self,
|
||||||
|
url: str,
|
||||||
|
payload: str | bytes | dict[str, t.Any] | None,
|
||||||
|
*,
|
||||||
|
key_data: dict[str, t.Any] | None = None,
|
||||||
|
jws_header: dict[str, t.Any] | None = None,
|
||||||
|
parse_json_result: bool = True,
|
||||||
|
encode_payload: bool = True,
|
||||||
|
fail_on_error: bool = True,
|
||||||
|
error_msg: str | None = None,
|
||||||
|
expected_status_codes: t.Iterable[int] | None = None,
|
||||||
|
) -> tuple[object | bytes, dict[str, t.Any]]:
|
||||||
|
"""
|
||||||
|
Sends a JWS signed HTTP POST request to the ACME server and returns
|
||||||
|
the response as dictionary (if parse_json_result is True) or in raw form
|
||||||
|
(if parse_json_result is False).
|
||||||
|
https://tools.ietf.org/html/rfc8555#section-6.2
|
||||||
|
|
||||||
|
If payload is None, a POST-as-GET is performed.
|
||||||
|
(https://tools.ietf.org/html/rfc8555#section-6.3)
|
||||||
|
"""
|
||||||
|
key_data = key_data or self.account_key_data
|
||||||
|
if key_data is None:
|
||||||
|
raise ModuleFailException("Missing key data")
|
||||||
|
jws_header = jws_header or self.account_jws_header
|
||||||
|
if jws_header is None:
|
||||||
|
raise ModuleFailException("Missing JWS header")
|
||||||
|
failed_tries = 0
|
||||||
|
while True:
|
||||||
|
protected = copy.deepcopy(jws_header)
|
||||||
|
protected["nonce"] = self.directory.get_nonce()
|
||||||
|
protected["url"] = url
|
||||||
|
|
||||||
|
self._log("URL", data=url)
|
||||||
|
self._log("protected", data=protected)
|
||||||
|
self._log("payload", data=payload)
|
||||||
|
data = self.sign_request(
|
||||||
|
protected=protected,
|
||||||
|
payload=payload,
|
||||||
|
key_data=key_data,
|
||||||
|
encode_payload=encode_payload,
|
||||||
|
)
|
||||||
|
self._log("signed request", data=data)
|
||||||
|
data_str = self.module.jsonify(data)
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Content-Type": "application/jose+json",
|
||||||
|
}
|
||||||
|
resp, info = fetch_url(
|
||||||
|
self.module,
|
||||||
|
url,
|
||||||
|
data=data_str,
|
||||||
|
headers=headers,
|
||||||
|
method="POST",
|
||||||
|
timeout=self.request_timeout,
|
||||||
|
)
|
||||||
|
if _decode_retry(
|
||||||
|
module=self.module, response=resp, info=info, retry_count=failed_tries
|
||||||
|
):
|
||||||
|
failed_tries += 1
|
||||||
|
continue
|
||||||
|
_assert_fetch_url_success(module=self.module, response=resp, info=info)
|
||||||
|
result: object | bytes = {}
|
||||||
|
|
||||||
|
try:
|
||||||
|
# In Python 2, reading from a closed response yields a TypeError.
|
||||||
|
# In Python 3, read() simply returns ''
|
||||||
|
if resp.closed:
|
||||||
|
raise TypeError
|
||||||
|
content = resp.read()
|
||||||
|
except (AttributeError, TypeError):
|
||||||
|
content = info.pop("body", None)
|
||||||
|
|
||||||
|
if content or not parse_json_result:
|
||||||
|
if (
|
||||||
|
parse_json_result
|
||||||
|
and info["content-type"].startswith("application/json")
|
||||||
|
) or 400 <= info["status"] < 600:
|
||||||
|
try:
|
||||||
|
decoded_result = self.module.from_json(content.decode("utf8"))
|
||||||
|
self._log("parsed result", data=decoded_result)
|
||||||
|
# In case of badNonce error, try again (up to 5 times)
|
||||||
|
# (https://tools.ietf.org/html/rfc8555#section-6.7)
|
||||||
|
if (
|
||||||
|
400 <= info["status"] < 600
|
||||||
|
and failed_tries <= 5
|
||||||
|
and isinstance(decoded_result, dict)
|
||||||
|
and decoded_result.get("type")
|
||||||
|
== "urn:ietf:params:acme:error:badNonce"
|
||||||
|
):
|
||||||
|
failed_tries += 1
|
||||||
|
continue
|
||||||
|
if parse_json_result:
|
||||||
|
result = decoded_result
|
||||||
|
else:
|
||||||
|
result = content
|
||||||
|
except ValueError as exc:
|
||||||
|
raise NetworkException(
|
||||||
|
f"Failed to parse the ACME response: {url} {content}"
|
||||||
|
) from exc
|
||||||
|
else:
|
||||||
|
result = content
|
||||||
|
|
||||||
|
if fail_on_error and _is_failed(
|
||||||
|
info=info, expected_status_codes=expected_status_codes
|
||||||
|
):
|
||||||
|
raise ACMEProtocolException(
|
||||||
|
module=self.module,
|
||||||
|
msg=error_msg,
|
||||||
|
info=info,
|
||||||
|
content=content,
|
||||||
|
content_json=result if parse_json_result else None,
|
||||||
|
)
|
||||||
|
return result, info
|
||||||
|
|
||||||
|
@t.overload
|
||||||
|
def get_request(
|
||||||
|
self,
|
||||||
|
uri: str,
|
||||||
|
*,
|
||||||
|
parse_json_result: t.Literal[True] = True,
|
||||||
|
headers: dict[str, str] | None = None,
|
||||||
|
get_only: bool = False,
|
||||||
|
fail_on_error: bool = True,
|
||||||
|
error_msg: str | None = None,
|
||||||
|
expected_status_codes: t.Iterable[int] | None = None,
|
||||||
|
) -> tuple[object, dict[str, t.Any]]: ...
|
||||||
|
|
||||||
|
@t.overload
|
||||||
|
def get_request(
|
||||||
|
self,
|
||||||
|
uri: str,
|
||||||
|
*,
|
||||||
|
parse_json_result: t.Literal[False],
|
||||||
|
headers: dict[str, str] | None = None,
|
||||||
|
get_only: bool = False,
|
||||||
|
fail_on_error: bool = True,
|
||||||
|
error_msg: str | None = None,
|
||||||
|
expected_status_codes: t.Iterable[int] | None = None,
|
||||||
|
) -> tuple[bytes, dict[str, t.Any]]: ...
|
||||||
|
|
||||||
|
def get_request(
|
||||||
|
self,
|
||||||
|
uri: str,
|
||||||
|
*,
|
||||||
|
parse_json_result: bool = True,
|
||||||
|
headers: dict[str, str] | None = None,
|
||||||
|
get_only: bool = False,
|
||||||
|
fail_on_error: bool = True,
|
||||||
|
error_msg: str | None = None,
|
||||||
|
expected_status_codes: t.Iterable[int] | None = None,
|
||||||
|
) -> tuple[object | bytes, dict[str, t.Any]]:
|
||||||
|
"""
|
||||||
|
Perform a GET-like request. Will try POST-as-GET for ACMEv2, with fallback
|
||||||
|
to GET if server replies with a status code of 405.
|
||||||
|
"""
|
||||||
|
if not get_only:
|
||||||
|
# Try POST-as-GET
|
||||||
|
content, info = self.send_signed_request(
|
||||||
|
uri, None, parse_json_result=False, fail_on_error=False
|
||||||
|
)
|
||||||
|
if info["status"] == 405:
|
||||||
|
# Instead, do unauthenticated GET
|
||||||
|
get_only = True
|
||||||
|
else:
|
||||||
|
# Do unauthenticated GET
|
||||||
|
get_only = True
|
||||||
|
|
||||||
|
if get_only:
|
||||||
|
# Perform unauthenticated GET
|
||||||
|
retry_count = 0
|
||||||
|
while True:
|
||||||
|
resp, info = fetch_url(
|
||||||
|
self.module,
|
||||||
|
uri,
|
||||||
|
method="GET",
|
||||||
|
headers=headers,
|
||||||
|
timeout=self.request_timeout,
|
||||||
|
)
|
||||||
|
if not _decode_retry(
|
||||||
|
module=self.module,
|
||||||
|
response=resp,
|
||||||
|
info=info,
|
||||||
|
retry_count=retry_count,
|
||||||
|
):
|
||||||
|
break
|
||||||
|
retry_count += 1
|
||||||
|
|
||||||
|
_assert_fetch_url_success(module=self.module, response=resp, info=info)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# In Python 2, reading from a closed response yields a TypeError.
|
||||||
|
# In Python 3, read() simply returns ''
|
||||||
|
if resp.closed:
|
||||||
|
raise TypeError
|
||||||
|
content = resp.read()
|
||||||
|
except (AttributeError, TypeError):
|
||||||
|
content = info.pop("body", None)
|
||||||
|
|
||||||
|
# Process result
|
||||||
|
parsed_json_result = False
|
||||||
|
result: object | bytes
|
||||||
|
if parse_json_result:
|
||||||
|
result = {}
|
||||||
|
if content:
|
||||||
|
if info["content-type"].startswith("application/json"):
|
||||||
|
try:
|
||||||
|
result = self.module.from_json(content.decode("utf8"))
|
||||||
|
parsed_json_result = True
|
||||||
|
except ValueError as exc:
|
||||||
|
raise NetworkException(
|
||||||
|
f"Failed to parse the ACME response: {uri} {content!r}"
|
||||||
|
) from exc
|
||||||
|
else:
|
||||||
|
result = content
|
||||||
|
else:
|
||||||
|
result = content
|
||||||
|
|
||||||
|
if fail_on_error and _is_failed(
|
||||||
|
info=info, expected_status_codes=expected_status_codes
|
||||||
|
):
|
||||||
|
raise ACMEProtocolException(
|
||||||
|
module=self.module,
|
||||||
|
msg=error_msg,
|
||||||
|
info=info,
|
||||||
|
content=content,
|
||||||
|
content_json=(
|
||||||
|
t.cast(dict[str, t.Any], result) if parsed_json_result else None
|
||||||
|
),
|
||||||
|
)
|
||||||
|
return result, info
|
||||||
|
|
||||||
|
def get_renewal_info(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
cert_id: str | None = None,
|
||||||
|
cert_info: CertificateInformation | None = None,
|
||||||
|
cert_filename: str | os.PathLike | None = None,
|
||||||
|
cert_content: str | bytes | None = None,
|
||||||
|
include_retry_after: bool = False,
|
||||||
|
retry_after_relative_with_timezone: bool = True,
|
||||||
|
) -> dict[str, t.Any]:
|
||||||
|
if not self.directory.has_renewal_info_endpoint():
|
||||||
|
raise ModuleFailException(
|
||||||
|
"The ACME endpoint does not support ACME Renewal Information retrieval"
|
||||||
|
)
|
||||||
|
|
||||||
|
if cert_id is None:
|
||||||
|
cert_id = compute_cert_id(
|
||||||
|
backend=self.backend,
|
||||||
|
cert_info=cert_info,
|
||||||
|
cert_filename=cert_filename,
|
||||||
|
cert_content=cert_content,
|
||||||
|
)
|
||||||
|
url = f"{self.directory.directory['renewalInfo'].rstrip('/')}/{cert_id}"
|
||||||
|
|
||||||
|
data, info = self.get_request(
|
||||||
|
url, parse_json_result=True, fail_on_error=True, get_only=True
|
||||||
|
)
|
||||||
|
if not isinstance(data, dict):
|
||||||
|
raise ACMEProtocolException(
|
||||||
|
module=self.module,
|
||||||
|
msg="Unexpected renewal information",
|
||||||
|
info=info,
|
||||||
|
content_json=data,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Include Retry-After header if asked for
|
||||||
|
if include_retry_after and "retry-after" in info:
|
||||||
|
try:
|
||||||
|
data["retryAfter"] = parse_retry_after(
|
||||||
|
info["retry-after"],
|
||||||
|
relative_with_timezone=retry_after_relative_with_timezone,
|
||||||
|
)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def create_default_argspec(
|
||||||
|
*,
|
||||||
|
with_account: bool = True,
|
||||||
|
require_account_key: bool = True,
|
||||||
|
with_certificate: bool = False,
|
||||||
|
) -> ArgumentSpec:
|
||||||
|
"""
|
||||||
|
Provides default argument spec for the options documented in the acme doc fragment.
|
||||||
|
"""
|
||||||
|
result = ArgumentSpec(
|
||||||
|
argument_spec={
|
||||||
|
"acme_directory": {"type": "str", "required": True},
|
||||||
|
"acme_version": {"type": "int", "choices": [2], "default": 2},
|
||||||
|
"validate_certs": {"type": "bool", "default": True},
|
||||||
|
"select_crypto_backend": {
|
||||||
|
"type": "str",
|
||||||
|
"default": "auto",
|
||||||
|
"choices": ["auto", "openssl", "cryptography"],
|
||||||
|
},
|
||||||
|
"request_timeout": {"type": "int", "default": 10},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if with_account:
|
||||||
|
result.update_argspec(
|
||||||
|
account_key_src={"type": "path", "aliases": ["account_key"]},
|
||||||
|
account_key_content={"type": "str", "no_log": True},
|
||||||
|
account_key_passphrase={"type": "str", "no_log": True},
|
||||||
|
account_uri={"type": "str"},
|
||||||
|
)
|
||||||
|
if require_account_key:
|
||||||
|
result.update(required_one_of=[["account_key_src", "account_key_content"]])
|
||||||
|
result.update(mutually_exclusive=[["account_key_src", "account_key_content"]])
|
||||||
|
if with_certificate:
|
||||||
|
result.update_argspec(
|
||||||
|
csr={"type": "path"},
|
||||||
|
csr_content={"type": "str"},
|
||||||
|
)
|
||||||
|
result.update(
|
||||||
|
required_one_of=[["csr", "csr_content"]],
|
||||||
|
mutually_exclusive=[["csr", "csr_content"]],
|
||||||
|
)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def create_backend(
|
||||||
|
module: AnsibleModule, *, needs_acme_v2: bool = True
|
||||||
|
) -> CryptoBackend:
|
||||||
|
backend = module.params["select_crypto_backend"]
|
||||||
|
|
||||||
|
# Backend autodetect
|
||||||
|
if backend == "auto":
|
||||||
|
backend = "cryptography" if HAS_CURRENT_CRYPTOGRAPHY else "openssl"
|
||||||
|
|
||||||
|
# Create backend object
|
||||||
|
module_backend: CryptoBackend
|
||||||
|
if backend == "cryptography":
|
||||||
|
if CRYPTOGRAPHY_ERROR is not None:
|
||||||
|
# Either we could not import cryptography at all, or there was an unexpected error
|
||||||
|
if CRYPTOGRAPHY_VERSION is None:
|
||||||
|
msg = missing_required_lib("cryptography")
|
||||||
|
else:
|
||||||
|
msg = f"Unexpected error while preparing cryptography: {CRYPTOGRAPHY_ERROR.splitlines()[-1]}"
|
||||||
|
module.fail_json(msg=msg, exception=CRYPTOGRAPHY_ERROR)
|
||||||
|
if not HAS_CURRENT_CRYPTOGRAPHY:
|
||||||
|
# We succeeded importing cryptography, but its version is too old.
|
||||||
|
mrl = missing_required_lib(
|
||||||
|
f"cryptography >= {CRYPTOGRAPHY_MINIMAL_VERSION}"
|
||||||
|
)
|
||||||
|
module.fail_json(
|
||||||
|
msg=f"Found cryptography, but only version {CRYPTOGRAPHY_VERSION}. {mrl}"
|
||||||
|
)
|
||||||
|
module.debug(
|
||||||
|
f"Using cryptography backend (library version {CRYPTOGRAPHY_VERSION})"
|
||||||
|
)
|
||||||
|
module_backend = CryptographyBackend(module=module)
|
||||||
|
elif backend == "openssl":
|
||||||
|
module.debug("Using OpenSSL binary backend")
|
||||||
|
module_backend = OpenSSLCLIBackend(module=module)
|
||||||
|
else:
|
||||||
|
module.fail_json(msg=f'Unknown crypto backend "{backend}"!')
|
||||||
|
|
||||||
|
# Check common module parameters
|
||||||
|
if not module.params["validate_certs"]:
|
||||||
|
module.warn(
|
||||||
|
"Disabling certificate validation for communications with ACME endpoint. "
|
||||||
|
"This should only be done for testing against a local ACME server for "
|
||||||
|
"development purposes, but *never* for production purposes."
|
||||||
|
)
|
||||||
|
|
||||||
|
# AnsibleModule() changes the locale, so change it back to C because we rely
|
||||||
|
# on datetime.datetime.strptime() when parsing certificate dates.
|
||||||
|
locale.setlocale(locale.LC_ALL, "C")
|
||||||
|
|
||||||
|
return module_backend
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = (
|
||||||
|
"ACMEClient",
|
||||||
|
"ACMEDirectory",
|
||||||
|
"create_backend",
|
||||||
|
"create_default_argspec",
|
||||||
|
)
|
||||||
546
plugins/module_utils/_acme/backend_cryptography.py
Normal file
546
plugins/module_utils/_acme/backend_cryptography.py
Normal file
@@ -0,0 +1,546 @@
|
|||||||
|
# Copyright (c) 2016 Michael Gruener <michael.gruener@chaosmoon.net>
|
||||||
|
# Copyright (c) 2021 Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import base64
|
||||||
|
import binascii
|
||||||
|
import os
|
||||||
|
import traceback
|
||||||
|
import typing as t
|
||||||
|
|
||||||
|
from ansible.module_utils.common.text.converters import to_bytes, to_text
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.backends import (
|
||||||
|
CertificateInformation,
|
||||||
|
CryptoBackend,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.certificates import (
|
||||||
|
ChainMatcher,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.errors import (
|
||||||
|
BackendException,
|
||||||
|
KeyParsingError,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.io import read_file
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.utils import (
|
||||||
|
nopad_b64,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.cryptography_support import (
|
||||||
|
CRYPTOGRAPHY_TIMEZONE,
|
||||||
|
cryptography_name_to_oid,
|
||||||
|
get_not_valid_after,
|
||||||
|
get_not_valid_before,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.math import (
|
||||||
|
convert_int_to_bytes,
|
||||||
|
convert_int_to_hex,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.pem import (
|
||||||
|
extract_first_pem,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.support import (
|
||||||
|
parse_name_field,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._time import (
|
||||||
|
add_or_remove_timezone,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._version import (
|
||||||
|
LooseVersion,
|
||||||
|
)
|
||||||
|
|
||||||
|
CRYPTOGRAPHY_MINIMAL_VERSION = "1.5"
|
||||||
|
|
||||||
|
CRYPTOGRAPHY_ERROR: None | str
|
||||||
|
try:
|
||||||
|
import cryptography
|
||||||
|
import cryptography.hazmat.backends
|
||||||
|
import cryptography.hazmat.primitives.asymmetric.ec
|
||||||
|
import cryptography.hazmat.primitives.asymmetric.padding
|
||||||
|
import cryptography.hazmat.primitives.asymmetric.rsa
|
||||||
|
import cryptography.hazmat.primitives.asymmetric.utils
|
||||||
|
import cryptography.hazmat.primitives.hashes
|
||||||
|
import cryptography.hazmat.primitives.hmac
|
||||||
|
import cryptography.hazmat.primitives.serialization
|
||||||
|
import cryptography.x509
|
||||||
|
import cryptography.x509.oid
|
||||||
|
except ImportError:
|
||||||
|
HAS_CURRENT_CRYPTOGRAPHY = False # pylint: disable=invalid-name
|
||||||
|
CRYPTOGRAPHY_VERSION = None # pylint: disable=invalid-name
|
||||||
|
CRYPTOGRAPHY_ERROR = traceback.format_exc() # pylint: disable=invalid-name
|
||||||
|
else:
|
||||||
|
CRYPTOGRAPHY_VERSION = cryptography.__version__ # pylint: disable=invalid-name
|
||||||
|
HAS_CURRENT_CRYPTOGRAPHY = LooseVersion(CRYPTOGRAPHY_VERSION) >= LooseVersion(
|
||||||
|
CRYPTOGRAPHY_MINIMAL_VERSION
|
||||||
|
)
|
||||||
|
CRYPTOGRAPHY_ERROR = None # pylint: disable=invalid-name
|
||||||
|
|
||||||
|
if t.TYPE_CHECKING:
|
||||||
|
import datetime # pragma: no cover
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule # pragma: no cover
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.certificates import ( # pragma: no cover
|
||||||
|
CertificateChain,
|
||||||
|
Criterium,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class CryptographyChainMatcher(ChainMatcher):
|
||||||
|
@staticmethod
|
||||||
|
def _parse_key_identifier(
|
||||||
|
*,
|
||||||
|
key_identifier: str | None,
|
||||||
|
name: str,
|
||||||
|
criterium_idx: int,
|
||||||
|
module: AnsibleModule,
|
||||||
|
) -> bytes | None:
|
||||||
|
if key_identifier:
|
||||||
|
try:
|
||||||
|
return binascii.unhexlify(key_identifier.replace(":", ""))
|
||||||
|
except Exception:
|
||||||
|
module.warn(
|
||||||
|
f"Criterium {criterium_idx} in select_chain has invalid {name} value. Ignoring criterium."
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
|
||||||
|
def __init__(self, *, criterium: Criterium, module: AnsibleModule) -> None:
|
||||||
|
self.criterium = criterium
|
||||||
|
self.test_certificates = criterium.test_certificates
|
||||||
|
self.subject: list[tuple[cryptography.x509.oid.ObjectIdentifier, str]] = []
|
||||||
|
self.issuer: list[tuple[cryptography.x509.oid.ObjectIdentifier, str]] = []
|
||||||
|
if criterium.subject:
|
||||||
|
self.subject = [
|
||||||
|
(cryptography_name_to_oid(k), to_text(v))
|
||||||
|
for k, v in parse_name_field(
|
||||||
|
criterium.subject, name_field_name="subject"
|
||||||
|
)
|
||||||
|
]
|
||||||
|
if criterium.issuer:
|
||||||
|
self.issuer = [
|
||||||
|
(cryptography_name_to_oid(k), to_text(v))
|
||||||
|
for k, v in parse_name_field(criterium.issuer, name_field_name="issuer")
|
||||||
|
]
|
||||||
|
self.subject_key_identifier = CryptographyChainMatcher._parse_key_identifier(
|
||||||
|
key_identifier=criterium.subject_key_identifier,
|
||||||
|
name="subject_key_identifier",
|
||||||
|
criterium_idx=criterium.index,
|
||||||
|
module=module,
|
||||||
|
)
|
||||||
|
self.authority_key_identifier = CryptographyChainMatcher._parse_key_identifier(
|
||||||
|
key_identifier=criterium.authority_key_identifier,
|
||||||
|
name="authority_key_identifier",
|
||||||
|
criterium_idx=criterium.index,
|
||||||
|
module=module,
|
||||||
|
)
|
||||||
|
self.module = module
|
||||||
|
|
||||||
|
def _match_subject(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
x509_subject: cryptography.x509.Name,
|
||||||
|
match_subject: list[tuple[cryptography.x509.oid.ObjectIdentifier, str]],
|
||||||
|
) -> bool:
|
||||||
|
for oid, value in match_subject:
|
||||||
|
found = False
|
||||||
|
for attribute in x509_subject:
|
||||||
|
if attribute.oid == oid and value == to_text(attribute.value):
|
||||||
|
found = True
|
||||||
|
break
|
||||||
|
if not found:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def match(self, *, certificate: CertificateChain) -> bool:
|
||||||
|
"""
|
||||||
|
Check whether an alternate chain matches the specified criterium.
|
||||||
|
"""
|
||||||
|
chain = certificate.chain
|
||||||
|
if self.test_certificates == "last":
|
||||||
|
chain = chain[-1:]
|
||||||
|
elif self.test_certificates == "first":
|
||||||
|
chain = chain[:1]
|
||||||
|
for cert in chain:
|
||||||
|
try:
|
||||||
|
x509 = cryptography.x509.load_pem_x509_certificate(to_bytes(cert))
|
||||||
|
matches = True
|
||||||
|
if not self._match_subject(
|
||||||
|
x509_subject=x509.subject, match_subject=self.subject
|
||||||
|
):
|
||||||
|
matches = False
|
||||||
|
if not self._match_subject(
|
||||||
|
x509_subject=x509.issuer, match_subject=self.issuer
|
||||||
|
):
|
||||||
|
matches = False
|
||||||
|
if self.subject_key_identifier:
|
||||||
|
try:
|
||||||
|
ext_ski = x509.extensions.get_extension_for_class(
|
||||||
|
cryptography.x509.SubjectKeyIdentifier
|
||||||
|
)
|
||||||
|
if self.subject_key_identifier != ext_ski.value.digest:
|
||||||
|
matches = False
|
||||||
|
except cryptography.x509.ExtensionNotFound:
|
||||||
|
matches = False
|
||||||
|
if self.authority_key_identifier:
|
||||||
|
try:
|
||||||
|
ext_aki = x509.extensions.get_extension_for_class(
|
||||||
|
cryptography.x509.AuthorityKeyIdentifier
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
self.authority_key_identifier
|
||||||
|
!= ext_aki.value.key_identifier
|
||||||
|
):
|
||||||
|
matches = False
|
||||||
|
except cryptography.x509.ExtensionNotFound:
|
||||||
|
matches = False
|
||||||
|
if matches:
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
self.module.warn(f"Error while loading certificate {cert}: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
class CryptographyBackend(CryptoBackend):
|
||||||
|
def __init__(self, *, module: AnsibleModule) -> None:
|
||||||
|
super().__init__(module=module, with_timezone=CRYPTOGRAPHY_TIMEZONE)
|
||||||
|
|
||||||
|
def parse_key(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
key_file: str | os.PathLike | None = None,
|
||||||
|
key_content: str | None = None,
|
||||||
|
passphrase: str | None = None,
|
||||||
|
) -> dict[str, t.Any]:
|
||||||
|
"""
|
||||||
|
Parses an RSA or Elliptic Curve key file in PEM format and returns key_data.
|
||||||
|
Raises KeyParsingError in case of errors.
|
||||||
|
"""
|
||||||
|
# If key_content is not given, read key_file
|
||||||
|
if key_content is None:
|
||||||
|
if key_file is None:
|
||||||
|
raise KeyParsingError(
|
||||||
|
"one of key_file and key_content must be specified"
|
||||||
|
)
|
||||||
|
b_key_content = read_file(key_file)
|
||||||
|
else:
|
||||||
|
b_key_content = to_bytes(key_content)
|
||||||
|
# Parse key
|
||||||
|
try:
|
||||||
|
key = cryptography.hazmat.primitives.serialization.load_pem_private_key(
|
||||||
|
b_key_content,
|
||||||
|
password=to_bytes(passphrase) if passphrase is not None else None,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
raise KeyParsingError(f"error while loading key: {e}") from e
|
||||||
|
if isinstance(key, cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey):
|
||||||
|
rsa_pk = key.public_key().public_numbers()
|
||||||
|
return {
|
||||||
|
"key_obj": key,
|
||||||
|
"type": "rsa",
|
||||||
|
"alg": "RS256",
|
||||||
|
"jwk": {
|
||||||
|
"kty": "RSA",
|
||||||
|
"e": nopad_b64(convert_int_to_bytes(rsa_pk.e)),
|
||||||
|
"n": nopad_b64(convert_int_to_bytes(rsa_pk.n)),
|
||||||
|
},
|
||||||
|
"hash": "sha256",
|
||||||
|
}
|
||||||
|
if isinstance(
|
||||||
|
key, cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey
|
||||||
|
):
|
||||||
|
ec_pk = key.public_key().public_numbers()
|
||||||
|
if ec_pk.curve.name == "secp256r1":
|
||||||
|
bits = 256
|
||||||
|
alg = "ES256"
|
||||||
|
hashalg = "sha256"
|
||||||
|
point_size = 32
|
||||||
|
curve = "P-256"
|
||||||
|
elif ec_pk.curve.name == "secp384r1":
|
||||||
|
bits = 384
|
||||||
|
alg = "ES384"
|
||||||
|
hashalg = "sha384"
|
||||||
|
point_size = 48
|
||||||
|
curve = "P-384"
|
||||||
|
elif ec_pk.curve.name == "secp521r1":
|
||||||
|
# Not yet supported on Let's Encrypt side, see
|
||||||
|
# https://github.com/letsencrypt/boulder/issues/2217
|
||||||
|
bits = 521
|
||||||
|
alg = "ES512"
|
||||||
|
hashalg = "sha512"
|
||||||
|
point_size = 66
|
||||||
|
curve = "P-521"
|
||||||
|
else:
|
||||||
|
raise KeyParsingError(f"unknown elliptic curve: {ec_pk.curve.name}")
|
||||||
|
num_bytes = (bits + 7) // 8
|
||||||
|
return {
|
||||||
|
"key_obj": key,
|
||||||
|
"type": "ec",
|
||||||
|
"alg": alg,
|
||||||
|
"jwk": {
|
||||||
|
"kty": "EC",
|
||||||
|
"crv": curve,
|
||||||
|
"x": nopad_b64(convert_int_to_bytes(ec_pk.x, count=num_bytes)),
|
||||||
|
"y": nopad_b64(convert_int_to_bytes(ec_pk.y, count=num_bytes)),
|
||||||
|
},
|
||||||
|
"hash": hashalg,
|
||||||
|
"point_size": point_size,
|
||||||
|
}
|
||||||
|
raise KeyParsingError(f'unknown key type "{type(key)}"')
|
||||||
|
|
||||||
|
def sign(
|
||||||
|
self, *, payload64: str, protected64: str, key_data: dict[str, t.Any]
|
||||||
|
) -> dict[str, t.Any]:
|
||||||
|
sign_payload = f"{protected64}.{payload64}".encode("utf8")
|
||||||
|
hashalg: type[cryptography.hazmat.primitives.hashes.HashAlgorithm]
|
||||||
|
if "mac_obj" in key_data:
|
||||||
|
mac = key_data["mac_obj"]()
|
||||||
|
mac.update(sign_payload)
|
||||||
|
signature = mac.finalize()
|
||||||
|
elif isinstance(
|
||||||
|
key_data["key_obj"],
|
||||||
|
cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey,
|
||||||
|
):
|
||||||
|
padding = cryptography.hazmat.primitives.asymmetric.padding.PKCS1v15()
|
||||||
|
hashalg = cryptography.hazmat.primitives.hashes.SHA256
|
||||||
|
signature = key_data["key_obj"].sign(sign_payload, padding, hashalg())
|
||||||
|
elif isinstance(
|
||||||
|
key_data["key_obj"],
|
||||||
|
cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey,
|
||||||
|
):
|
||||||
|
if key_data["hash"] == "sha256":
|
||||||
|
hashalg = cryptography.hazmat.primitives.hashes.SHA256
|
||||||
|
elif key_data["hash"] == "sha384":
|
||||||
|
hashalg = cryptography.hazmat.primitives.hashes.SHA384
|
||||||
|
elif key_data["hash"] == "sha512":
|
||||||
|
hashalg = cryptography.hazmat.primitives.hashes.SHA512
|
||||||
|
ecdsa = cryptography.hazmat.primitives.asymmetric.ec.ECDSA(hashalg())
|
||||||
|
r, s = cryptography.hazmat.primitives.asymmetric.utils.decode_dss_signature(
|
||||||
|
key_data["key_obj"].sign(sign_payload, ecdsa)
|
||||||
|
)
|
||||||
|
rr = convert_int_to_hex(r, digits=2 * key_data["point_size"])
|
||||||
|
ss = convert_int_to_hex(s, digits=2 * key_data["point_size"])
|
||||||
|
signature = binascii.unhexlify(rr) + binascii.unhexlify(ss)
|
||||||
|
else:
|
||||||
|
raise AssertionError("Can never be reached") # pragma: no cover
|
||||||
|
|
||||||
|
return {
|
||||||
|
"protected": protected64,
|
||||||
|
"payload": payload64,
|
||||||
|
"signature": nopad_b64(signature),
|
||||||
|
}
|
||||||
|
|
||||||
|
def create_mac_key(self, *, alg: str, key: str) -> dict[str, t.Any]:
|
||||||
|
"""Create a MAC key."""
|
||||||
|
hashalg: type[cryptography.hazmat.primitives.hashes.HashAlgorithm]
|
||||||
|
if alg == "HS256":
|
||||||
|
hashalg = cryptography.hazmat.primitives.hashes.SHA256
|
||||||
|
hashbytes = 32
|
||||||
|
elif alg == "HS384":
|
||||||
|
hashalg = cryptography.hazmat.primitives.hashes.SHA384
|
||||||
|
hashbytes = 48
|
||||||
|
elif alg == "HS512":
|
||||||
|
hashalg = cryptography.hazmat.primitives.hashes.SHA512
|
||||||
|
hashbytes = 64
|
||||||
|
else:
|
||||||
|
raise BackendException(
|
||||||
|
f"Unsupported MAC key algorithm for cryptography backend: {alg}"
|
||||||
|
)
|
||||||
|
key_bytes = base64.urlsafe_b64decode(key)
|
||||||
|
if len(key_bytes) < hashbytes:
|
||||||
|
raise BackendException(
|
||||||
|
f"{alg} key must be at least {hashbytes} bytes long (after Base64 decoding)"
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
"mac_obj": lambda: cryptography.hazmat.primitives.hmac.HMAC(
|
||||||
|
key_bytes, hashalg()
|
||||||
|
),
|
||||||
|
"type": "hmac",
|
||||||
|
"alg": alg,
|
||||||
|
"jwk": {
|
||||||
|
"kty": "oct",
|
||||||
|
"k": key,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_ordered_csr_identifiers(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
csr_filename: str | os.PathLike | None = None,
|
||||||
|
csr_content: str | bytes | None = None,
|
||||||
|
) -> list[tuple[str, str]]:
|
||||||
|
"""
|
||||||
|
Return a list of requested identifiers (CN and SANs) for the CSR.
|
||||||
|
Each identifier is a pair (type, identifier), where type is either
|
||||||
|
'dns' or 'ip'.
|
||||||
|
|
||||||
|
The list is deduplicated, and if a CNAME is present, it will be returned
|
||||||
|
as the first element in the result.
|
||||||
|
"""
|
||||||
|
if csr_content is None:
|
||||||
|
if csr_filename is None:
|
||||||
|
raise BackendException(
|
||||||
|
"One of csr_content and csr_filename has to be provided"
|
||||||
|
)
|
||||||
|
b_csr_content = read_file(csr_filename)
|
||||||
|
else:
|
||||||
|
b_csr_content = to_bytes(csr_content)
|
||||||
|
csr = cryptography.x509.load_pem_x509_csr(b_csr_content)
|
||||||
|
|
||||||
|
identifiers = set()
|
||||||
|
result = []
|
||||||
|
|
||||||
|
def add_identifier(identifier: tuple[str, str]) -> None:
|
||||||
|
if identifier in identifiers:
|
||||||
|
return
|
||||||
|
identifiers.add(identifier)
|
||||||
|
result.append(identifier)
|
||||||
|
|
||||||
|
for sub in csr.subject:
|
||||||
|
if sub.oid == cryptography.x509.oid.NameOID.COMMON_NAME:
|
||||||
|
add_identifier(("dns", t.cast(str, sub.value)))
|
||||||
|
for extension in csr.extensions:
|
||||||
|
if (
|
||||||
|
extension.oid
|
||||||
|
== cryptography.x509.oid.ExtensionOID.SUBJECT_ALTERNATIVE_NAME
|
||||||
|
):
|
||||||
|
for name in extension.value:
|
||||||
|
if isinstance(name, cryptography.x509.DNSName):
|
||||||
|
add_identifier(("dns", name.value))
|
||||||
|
elif isinstance(name, cryptography.x509.IPAddress):
|
||||||
|
add_identifier(("ip", name.value.compressed))
|
||||||
|
else:
|
||||||
|
raise BackendException(
|
||||||
|
f"Found unsupported SAN identifier {name}"
|
||||||
|
)
|
||||||
|
return result
|
||||||
|
|
||||||
|
def get_csr_identifiers(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
csr_filename: str | os.PathLike | None = None,
|
||||||
|
csr_content: str | bytes | bytes | None = None,
|
||||||
|
) -> set[tuple[str, str]]:
|
||||||
|
"""
|
||||||
|
Return a set of requested identifiers (CN and SANs) for the CSR.
|
||||||
|
Each identifier is a pair (type, identifier), where type is either
|
||||||
|
'dns' or 'ip'.
|
||||||
|
"""
|
||||||
|
return set(
|
||||||
|
self.get_ordered_csr_identifiers(
|
||||||
|
csr_filename=csr_filename, csr_content=csr_content
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_cert_days(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
cert_filename: str | os.PathLike | None = None,
|
||||||
|
cert_content: str | bytes | None = None,
|
||||||
|
now: datetime.datetime | None = None,
|
||||||
|
) -> int:
|
||||||
|
"""
|
||||||
|
Return the days the certificate in cert_filename remains valid and -1
|
||||||
|
if the file was not found. If cert_filename contains more than one
|
||||||
|
certificate, only the first one will be considered.
|
||||||
|
|
||||||
|
If now is not specified, datetime.datetime.now() is used.
|
||||||
|
"""
|
||||||
|
if cert_filename is not None:
|
||||||
|
cert_content = None
|
||||||
|
if os.path.exists(cert_filename):
|
||||||
|
cert_content = read_file(cert_filename)
|
||||||
|
else:
|
||||||
|
cert_content = to_bytes(cert_content)
|
||||||
|
|
||||||
|
if cert_content is None:
|
||||||
|
return -1
|
||||||
|
|
||||||
|
# Make sure we have at most one PEM. Otherwise cryptography 36.0.0 will barf.
|
||||||
|
b_cert_content = to_bytes(extract_first_pem(to_text(cert_content)) or "")
|
||||||
|
|
||||||
|
try:
|
||||||
|
cert = cryptography.x509.load_pem_x509_certificate(b_cert_content)
|
||||||
|
except Exception as e:
|
||||||
|
if cert_filename is None:
|
||||||
|
raise BackendException(f"Cannot parse certificate: {e}") from e
|
||||||
|
raise BackendException(
|
||||||
|
f"Cannot parse certificate {cert_filename}: {e}"
|
||||||
|
) from e
|
||||||
|
|
||||||
|
if now is None:
|
||||||
|
now = self.get_now()
|
||||||
|
else:
|
||||||
|
now = add_or_remove_timezone(now, with_timezone=CRYPTOGRAPHY_TIMEZONE)
|
||||||
|
return (get_not_valid_after(cert) - now).days
|
||||||
|
|
||||||
|
def create_chain_matcher(self, *, criterium: Criterium) -> ChainMatcher:
|
||||||
|
"""
|
||||||
|
Given a Criterium object, creates a ChainMatcher object.
|
||||||
|
"""
|
||||||
|
return CryptographyChainMatcher(criterium=criterium, module=self.module)
|
||||||
|
|
||||||
|
def get_cert_information(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
cert_filename: str | os.PathLike | None = None,
|
||||||
|
cert_content: str | bytes | None = None,
|
||||||
|
) -> CertificateInformation:
|
||||||
|
"""
|
||||||
|
Return some information on a X.509 certificate as a CertificateInformation object.
|
||||||
|
"""
|
||||||
|
if cert_filename is not None:
|
||||||
|
cert_content = read_file(cert_filename)
|
||||||
|
else:
|
||||||
|
cert_content = to_bytes(cert_content)
|
||||||
|
|
||||||
|
# Make sure we have at most one PEM. Otherwise cryptography 36.0.0 will barf.
|
||||||
|
b_cert_content = to_bytes(extract_first_pem(to_text(cert_content)) or "")
|
||||||
|
|
||||||
|
try:
|
||||||
|
cert = cryptography.x509.load_pem_x509_certificate(b_cert_content)
|
||||||
|
except Exception as e:
|
||||||
|
if cert_filename is None:
|
||||||
|
raise BackendException(f"Cannot parse certificate: {e}") from e
|
||||||
|
raise BackendException(
|
||||||
|
f"Cannot parse certificate {cert_filename}: {e}"
|
||||||
|
) from e
|
||||||
|
|
||||||
|
ski = None
|
||||||
|
try:
|
||||||
|
ext_ski = cert.extensions.get_extension_for_class(
|
||||||
|
cryptography.x509.SubjectKeyIdentifier
|
||||||
|
)
|
||||||
|
ski = ext_ski.value.digest
|
||||||
|
except cryptography.x509.ExtensionNotFound:
|
||||||
|
pass
|
||||||
|
|
||||||
|
aki = None
|
||||||
|
try:
|
||||||
|
ext_aki = cert.extensions.get_extension_for_class(
|
||||||
|
cryptography.x509.AuthorityKeyIdentifier
|
||||||
|
)
|
||||||
|
aki = ext_aki.value.key_identifier
|
||||||
|
except cryptography.x509.ExtensionNotFound:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return CertificateInformation(
|
||||||
|
not_valid_after=get_not_valid_after(cert),
|
||||||
|
not_valid_before=get_not_valid_before(cert),
|
||||||
|
serial_number=cert.serial_number,
|
||||||
|
subject_key_identifier=ski,
|
||||||
|
authority_key_identifier=aki,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = (
|
||||||
|
"CRYPTOGRAPHY_ERROR",
|
||||||
|
"CRYPTOGRAPHY_ERROR",
|
||||||
|
"CRYPTOGRAPHY_MINIMAL_VERSION",
|
||||||
|
"CRYPTOGRAPHY_VERSION",
|
||||||
|
"CryptographyBackend",
|
||||||
|
)
|
||||||
640
plugins/module_utils/_acme/backend_openssl_cli.py
Normal file
640
plugins/module_utils/_acme/backend_openssl_cli.py
Normal file
@@ -0,0 +1,640 @@
|
|||||||
|
# Copyright (c) 2016 Michael Gruener <michael.gruener@chaosmoon.net>
|
||||||
|
# Copyright (c) 2021 Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import base64
|
||||||
|
import binascii
|
||||||
|
import datetime
|
||||||
|
import ipaddress
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import tempfile
|
||||||
|
import traceback
|
||||||
|
import typing as t
|
||||||
|
|
||||||
|
from ansible.module_utils.common.text.converters import to_bytes, to_text
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.backends import (
|
||||||
|
CertificateInformation,
|
||||||
|
CryptoBackend,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.errors import (
|
||||||
|
BackendException,
|
||||||
|
KeyParsingError,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.utils import (
|
||||||
|
nopad_b64,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.math import (
|
||||||
|
convert_bytes_to_int,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._time import (
|
||||||
|
ensure_utc_timezone,
|
||||||
|
)
|
||||||
|
|
||||||
|
if t.TYPE_CHECKING:
|
||||||
|
from ansible.module_utils.basic import AnsibleModule # pragma: no cover
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.certificates import ( # pragma: no cover
|
||||||
|
Criterium,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
_OPENSSL_ENVIRONMENT_UPDATE = {
|
||||||
|
"LANG": "C",
|
||||||
|
"LC_ALL": "C",
|
||||||
|
"LC_MESSAGES": "C",
|
||||||
|
"LC_CTYPE": "C",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _extract_date(
|
||||||
|
out_text: str, *, name: str, cert_filename_suffix: str = ""
|
||||||
|
) -> datetime.datetime:
|
||||||
|
matcher = re.search(rf"\s+{name}\s*:\s+(.*)", out_text)
|
||||||
|
if matcher is None:
|
||||||
|
raise BackendException(f"No '{name}' date found{cert_filename_suffix}")
|
||||||
|
date_str = matcher.group(1)
|
||||||
|
try:
|
||||||
|
# For some reason Python's strptime() does not return any timezone information,
|
||||||
|
# even though the information is there and a supported timezone for all supported
|
||||||
|
# Python implementations (GMT). So we have to modify the datetime object by
|
||||||
|
# replacing it by UTC.
|
||||||
|
return ensure_utc_timezone(
|
||||||
|
datetime.datetime.strptime(date_str, "%b %d %H:%M:%S %Y %Z")
|
||||||
|
)
|
||||||
|
except ValueError as exc:
|
||||||
|
raise BackendException(
|
||||||
|
f"Failed to parse '{name}' date{cert_filename_suffix}: {exc}"
|
||||||
|
) from exc
|
||||||
|
|
||||||
|
|
||||||
|
def _decode_octets(octets_text: str) -> bytes:
|
||||||
|
return binascii.unhexlify(re.sub(r"(\s|:)", "", octets_text).encode("utf-8"))
|
||||||
|
|
||||||
|
|
||||||
|
@t.overload
|
||||||
|
def _extract_octets(
|
||||||
|
out_text: str,
|
||||||
|
*,
|
||||||
|
name: str,
|
||||||
|
required: t.Literal[False],
|
||||||
|
potential_prefixes: t.Iterable[str] | None = None,
|
||||||
|
) -> bytes | None: ...
|
||||||
|
|
||||||
|
|
||||||
|
@t.overload
|
||||||
|
def _extract_octets(
|
||||||
|
out_text: str,
|
||||||
|
*,
|
||||||
|
name: str,
|
||||||
|
required: t.Literal[True],
|
||||||
|
potential_prefixes: t.Iterable[str] | None = None,
|
||||||
|
) -> bytes: ...
|
||||||
|
|
||||||
|
|
||||||
|
def _extract_octets(
|
||||||
|
out_text: str,
|
||||||
|
*,
|
||||||
|
name: str,
|
||||||
|
required: bool = True,
|
||||||
|
potential_prefixes: t.Iterable[str] | None = None,
|
||||||
|
) -> bytes | None:
|
||||||
|
part = (
|
||||||
|
f"(?:{'|'.join(re.escape(pp) for pp in potential_prefixes)})"
|
||||||
|
if potential_prefixes
|
||||||
|
else ""
|
||||||
|
)
|
||||||
|
regexp = rf"\s+{name}:\s*\n\s+{part}([A-Fa-f0-9]{{2}}(?::[A-Fa-f0-9]{{2}})*)\s*\n"
|
||||||
|
match = re.search(regexp, out_text, re.MULTILINE | re.DOTALL)
|
||||||
|
if match is not None:
|
||||||
|
return _decode_octets(match.group(1))
|
||||||
|
if not required:
|
||||||
|
return None
|
||||||
|
raise BackendException(f"No '{name}' octet string found")
|
||||||
|
|
||||||
|
|
||||||
|
def _extract_rsa_key(out_text: str, *, key_file: str | None = None) -> dict[str, t.Any]:
|
||||||
|
matcher = re.search(
|
||||||
|
r"modulus:\n\s+(?:00:)?([a-f0-9\:\s]+?)\npublicExponent",
|
||||||
|
out_text,
|
||||||
|
re.MULTILINE | re.DOTALL,
|
||||||
|
)
|
||||||
|
if matcher is None:
|
||||||
|
raise KeyParsingError("cannot parse RSA key: modulus not found")
|
||||||
|
pub_hex = matcher.group(1)
|
||||||
|
|
||||||
|
matcher = re.search(
|
||||||
|
r"\npublicExponent: ([0-9]+)", out_text, re.MULTILINE | re.DOTALL
|
||||||
|
)
|
||||||
|
if matcher is None:
|
||||||
|
raise KeyParsingError("cannot parse RSA key: public exponent not found")
|
||||||
|
pub_exp = matcher.group(1)
|
||||||
|
pub_exp = f"{int(pub_exp):x}"
|
||||||
|
if len(pub_exp) % 2:
|
||||||
|
pub_exp = f"0{pub_exp}"
|
||||||
|
|
||||||
|
return {
|
||||||
|
"key_file": key_file,
|
||||||
|
"type": "rsa",
|
||||||
|
"alg": "RS256",
|
||||||
|
"jwk": {
|
||||||
|
"kty": "RSA",
|
||||||
|
"e": nopad_b64(binascii.unhexlify(pub_exp.encode("utf-8"))),
|
||||||
|
"n": nopad_b64(_decode_octets(pub_hex)),
|
||||||
|
},
|
||||||
|
"hash": "sha256",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _extract_ec_key(out_text: str, *, key_file: str | None = None) -> dict[str, t.Any]:
|
||||||
|
pub_data = re.search(
|
||||||
|
r"pub:\s*\n\s+04:([a-f0-9\:\s]+?)\nASN1 OID: (\S+)(?:\nNIST CURVE: (\S+))?",
|
||||||
|
out_text,
|
||||||
|
re.MULTILINE | re.DOTALL,
|
||||||
|
)
|
||||||
|
if pub_data is None:
|
||||||
|
raise KeyParsingError("cannot parse elliptic curve key")
|
||||||
|
pub_hex = _decode_octets(pub_data.group(1))
|
||||||
|
asn1_oid_curve = pub_data.group(2).lower()
|
||||||
|
nist_curve = pub_data.group(3).lower() if pub_data.group(3) else None
|
||||||
|
if asn1_oid_curve == "prime256v1" or nist_curve == "p-256":
|
||||||
|
bits = 256
|
||||||
|
alg = "ES256"
|
||||||
|
hashalg = "sha256"
|
||||||
|
point_size = 32
|
||||||
|
curve = "P-256"
|
||||||
|
elif asn1_oid_curve == "secp384r1" or nist_curve == "p-384":
|
||||||
|
bits = 384
|
||||||
|
alg = "ES384"
|
||||||
|
hashalg = "sha384"
|
||||||
|
point_size = 48
|
||||||
|
curve = "P-384"
|
||||||
|
elif asn1_oid_curve == "secp521r1" or nist_curve == "p-521":
|
||||||
|
# Not yet supported on Let's Encrypt side, see
|
||||||
|
# https://github.com/letsencrypt/boulder/issues/2217
|
||||||
|
bits = 521
|
||||||
|
alg = "ES512"
|
||||||
|
hashalg = "sha512"
|
||||||
|
point_size = 66
|
||||||
|
curve = "P-521"
|
||||||
|
else:
|
||||||
|
raise KeyParsingError(
|
||||||
|
f"unknown elliptic curve: {asn1_oid_curve} / {nist_curve}"
|
||||||
|
)
|
||||||
|
num_bytes = (bits + 7) // 8
|
||||||
|
if len(pub_hex) != 2 * num_bytes:
|
||||||
|
raise KeyParsingError(
|
||||||
|
f"bad elliptic curve point ({asn1_oid_curve} / {nist_curve})"
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
"key_file": key_file,
|
||||||
|
"type": "ec",
|
||||||
|
"alg": alg,
|
||||||
|
"jwk": {
|
||||||
|
"kty": "EC",
|
||||||
|
"crv": curve,
|
||||||
|
"x": nopad_b64(pub_hex[:num_bytes]),
|
||||||
|
"y": nopad_b64(pub_hex[num_bytes:]),
|
||||||
|
},
|
||||||
|
"hash": hashalg,
|
||||||
|
"point_size": point_size,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class OpenSSLCLIBackend(CryptoBackend):
|
||||||
|
def __init__(
|
||||||
|
self, *, module: AnsibleModule, openssl_binary: str | None = None
|
||||||
|
) -> None:
|
||||||
|
super().__init__(module=module, with_timezone=True)
|
||||||
|
if openssl_binary is None:
|
||||||
|
openssl_binary = module.get_bin_path("openssl", True)
|
||||||
|
self.openssl_binary = openssl_binary
|
||||||
|
|
||||||
|
def parse_key(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
key_file: str | os.PathLike | None = None,
|
||||||
|
key_content: str | None = None,
|
||||||
|
passphrase: str | None = None,
|
||||||
|
) -> dict[str, t.Any]:
|
||||||
|
"""
|
||||||
|
Parses an RSA or Elliptic Curve key file in PEM format and returns key_data.
|
||||||
|
Raises KeyParsingError in case of errors.
|
||||||
|
"""
|
||||||
|
if passphrase is not None:
|
||||||
|
raise KeyParsingError("openssl backend does not support key passphrases")
|
||||||
|
# If key_file is not given, but key_content, write that to a temporary file
|
||||||
|
if key_file is None:
|
||||||
|
if key_content is None:
|
||||||
|
raise KeyParsingError(
|
||||||
|
"one of key_file and key_content must be specified"
|
||||||
|
)
|
||||||
|
fd, tmpsrc = tempfile.mkstemp()
|
||||||
|
self.module.add_cleanup_file(tmpsrc) # Ansible will delete the file on exit
|
||||||
|
f = os.fdopen(fd, "wb")
|
||||||
|
try:
|
||||||
|
f.write(key_content.encode("utf-8"))
|
||||||
|
key_file = tmpsrc
|
||||||
|
except Exception as err:
|
||||||
|
try:
|
||||||
|
f.close()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
raise KeyParsingError(
|
||||||
|
f"failed to create temporary content file: {err}",
|
||||||
|
exception=traceback.format_exc(),
|
||||||
|
) from err
|
||||||
|
f.close()
|
||||||
|
# Parse key
|
||||||
|
account_key_type = None
|
||||||
|
with open(key_file, "r", encoding="utf-8") as fi:
|
||||||
|
for line in fi:
|
||||||
|
m = re.match(
|
||||||
|
r"^\s*-{5,}BEGIN\s+(EC|RSA)\s+PRIVATE\s+KEY-{5,}\s*$", line
|
||||||
|
)
|
||||||
|
if m is not None:
|
||||||
|
account_key_type = m.group(1).lower()
|
||||||
|
break
|
||||||
|
if account_key_type is None:
|
||||||
|
# This happens for example if openssl_privatekey created this key
|
||||||
|
# (as opposed to the OpenSSL binary). For now, we assume this is
|
||||||
|
# an RSA key.
|
||||||
|
# FIXME: add some kind of auto-detection
|
||||||
|
account_key_type = "rsa"
|
||||||
|
if account_key_type not in ("rsa", "ec"):
|
||||||
|
raise KeyParsingError(f'unknown key type "{account_key_type}"')
|
||||||
|
|
||||||
|
openssl_keydump_cmd = [
|
||||||
|
self.openssl_binary,
|
||||||
|
account_key_type,
|
||||||
|
"-in",
|
||||||
|
str(key_file),
|
||||||
|
"-noout",
|
||||||
|
"-text",
|
||||||
|
]
|
||||||
|
rc, out, stderr = self.module.run_command(
|
||||||
|
openssl_keydump_cmd,
|
||||||
|
check_rc=False,
|
||||||
|
environ_update=_OPENSSL_ENVIRONMENT_UPDATE,
|
||||||
|
)
|
||||||
|
if rc != 0:
|
||||||
|
raise BackendException(
|
||||||
|
f"Error while running {' '.join(openssl_keydump_cmd)}: {stderr}"
|
||||||
|
)
|
||||||
|
|
||||||
|
out_text = to_text(out, errors="surrogate_or_strict")
|
||||||
|
|
||||||
|
if account_key_type == "rsa":
|
||||||
|
return _extract_rsa_key(
|
||||||
|
out_text, key_file=str(key_file) if key_file is not None else None
|
||||||
|
)
|
||||||
|
if account_key_type == "ec":
|
||||||
|
return _extract_ec_key(
|
||||||
|
out_text, key_file=str(key_file) if key_file is not None else None
|
||||||
|
)
|
||||||
|
raise KeyParsingError(
|
||||||
|
f"Internal error: unexpected account_key_type = {account_key_type!r}"
|
||||||
|
)
|
||||||
|
|
||||||
|
def sign(
|
||||||
|
self, *, payload64: str, protected64: str, key_data: dict[str, t.Any]
|
||||||
|
) -> dict[str, t.Any]:
|
||||||
|
sign_payload = f"{protected64}.{payload64}".encode("utf8")
|
||||||
|
if key_data["type"] == "hmac":
|
||||||
|
hex_key = (
|
||||||
|
binascii.hexlify(base64.urlsafe_b64decode(key_data["jwk"]["k"]))
|
||||||
|
).decode("ascii")
|
||||||
|
cmd_postfix = [
|
||||||
|
"-mac",
|
||||||
|
"hmac",
|
||||||
|
"-macopt",
|
||||||
|
f"hexkey:{hex_key}",
|
||||||
|
"-binary",
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
cmd_postfix = ["-sign", key_data["key_file"]]
|
||||||
|
openssl_sign_cmd = [
|
||||||
|
self.openssl_binary,
|
||||||
|
"dgst",
|
||||||
|
f"-{key_data['hash']}",
|
||||||
|
] + cmd_postfix
|
||||||
|
|
||||||
|
out: bytes | str
|
||||||
|
|
||||||
|
rc, out, err = self.module.run_command(
|
||||||
|
openssl_sign_cmd,
|
||||||
|
data=sign_payload,
|
||||||
|
check_rc=False,
|
||||||
|
binary_data=True,
|
||||||
|
environ_update=_OPENSSL_ENVIRONMENT_UPDATE,
|
||||||
|
)
|
||||||
|
if rc != 0:
|
||||||
|
raise BackendException(
|
||||||
|
f"Error while running {' '.join(openssl_sign_cmd)}: {err}"
|
||||||
|
)
|
||||||
|
|
||||||
|
if key_data["type"] == "ec":
|
||||||
|
dummy, der_out, dummy2 = self.module.run_command(
|
||||||
|
[self.openssl_binary, "asn1parse", "-inform", "DER"],
|
||||||
|
data=out,
|
||||||
|
binary_data=True,
|
||||||
|
environ_update=_OPENSSL_ENVIRONMENT_UPDATE,
|
||||||
|
)
|
||||||
|
expected_len = 2 * key_data["point_size"]
|
||||||
|
sig = re.findall(
|
||||||
|
rf"prim:\s+INTEGER\s+:([0-9A-F]{{1,{expected_len}}})\n",
|
||||||
|
to_text(der_out, errors="surrogate_or_strict"),
|
||||||
|
)
|
||||||
|
if len(sig) != 2:
|
||||||
|
der_output = to_text(der_out, errors="surrogate_or_strict")
|
||||||
|
raise BackendException(
|
||||||
|
f"failed to generate Elliptic Curve signature; cannot parse DER output: {der_output}"
|
||||||
|
)
|
||||||
|
sig[0] = (expected_len - len(sig[0])) * "0" + sig[0]
|
||||||
|
sig[1] = (expected_len - len(sig[1])) * "0" + sig[1]
|
||||||
|
out = binascii.unhexlify(sig[0]) + binascii.unhexlify(sig[1])
|
||||||
|
|
||||||
|
return {
|
||||||
|
"protected": protected64,
|
||||||
|
"payload": payload64,
|
||||||
|
"signature": nopad_b64(to_bytes(out)),
|
||||||
|
}
|
||||||
|
|
||||||
|
def create_mac_key(self, *, alg: str, key: str) -> dict[str, t.Any]:
|
||||||
|
"""Create a MAC key."""
|
||||||
|
if alg == "HS256":
|
||||||
|
hashalg = "sha256"
|
||||||
|
hashbytes = 32
|
||||||
|
elif alg == "HS384":
|
||||||
|
hashalg = "sha384"
|
||||||
|
hashbytes = 48
|
||||||
|
elif alg == "HS512":
|
||||||
|
hashalg = "sha512"
|
||||||
|
hashbytes = 64
|
||||||
|
else:
|
||||||
|
raise BackendException(
|
||||||
|
f"Unsupported MAC key algorithm for OpenSSL backend: {alg}"
|
||||||
|
)
|
||||||
|
key_bytes = base64.urlsafe_b64decode(key)
|
||||||
|
if len(key_bytes) < hashbytes:
|
||||||
|
raise BackendException(
|
||||||
|
f"{alg} key must be at least {hashbytes} bytes long (after Base64 decoding)"
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
"type": "hmac",
|
||||||
|
"alg": alg,
|
||||||
|
"jwk": {
|
||||||
|
"kty": "oct",
|
||||||
|
"k": key,
|
||||||
|
},
|
||||||
|
"hash": hashalg,
|
||||||
|
}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _normalize_ip(ip: str) -> str:
|
||||||
|
try:
|
||||||
|
return ipaddress.ip_address(ip).compressed
|
||||||
|
except ValueError:
|
||||||
|
# We do not want to error out on something IPAddress() cannot parse
|
||||||
|
return ip
|
||||||
|
|
||||||
|
def get_ordered_csr_identifiers(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
csr_filename: str | os.PathLike | None = None,
|
||||||
|
csr_content: str | bytes | None = None,
|
||||||
|
) -> list[tuple[str, str]]:
|
||||||
|
"""
|
||||||
|
Return a list of requested identifiers (CN and SANs) for the CSR.
|
||||||
|
Each identifier is a pair (type, identifier), where type is either
|
||||||
|
'dns' or 'ip'.
|
||||||
|
|
||||||
|
The list is deduplicated, and if a CNAME is present, it will be returned
|
||||||
|
as the first element in the result.
|
||||||
|
"""
|
||||||
|
filename = csr_filename
|
||||||
|
data = None
|
||||||
|
if csr_content is not None:
|
||||||
|
filename = "/dev/stdin"
|
||||||
|
data = to_bytes(csr_content)
|
||||||
|
|
||||||
|
openssl_csr_cmd = [
|
||||||
|
self.openssl_binary,
|
||||||
|
"req",
|
||||||
|
"-in",
|
||||||
|
str(filename),
|
||||||
|
"-noout",
|
||||||
|
"-text",
|
||||||
|
]
|
||||||
|
rc, out, err = self.module.run_command(
|
||||||
|
openssl_csr_cmd,
|
||||||
|
data=data,
|
||||||
|
check_rc=False,
|
||||||
|
binary_data=True,
|
||||||
|
environ_update=_OPENSSL_ENVIRONMENT_UPDATE,
|
||||||
|
)
|
||||||
|
if rc != 0:
|
||||||
|
raise BackendException(
|
||||||
|
f"Error while running {' '.join(openssl_csr_cmd)}: {err}"
|
||||||
|
)
|
||||||
|
|
||||||
|
identifiers = set()
|
||||||
|
result = []
|
||||||
|
|
||||||
|
def add_identifier(identifier: tuple[str, str]) -> None:
|
||||||
|
if identifier in identifiers:
|
||||||
|
return
|
||||||
|
identifiers.add(identifier)
|
||||||
|
result.append(identifier)
|
||||||
|
|
||||||
|
common_name = re.search(
|
||||||
|
r"Subject:.* CN\s?=\s?([^\s,;/]+)",
|
||||||
|
to_text(out, errors="surrogate_or_strict"),
|
||||||
|
)
|
||||||
|
if common_name is not None:
|
||||||
|
add_identifier(("dns", common_name.group(1)))
|
||||||
|
subject_alt_names = re.search(
|
||||||
|
r"X509v3 Subject Alternative Name: (?:critical)?\n +([^\n]+)\n",
|
||||||
|
to_text(out, errors="surrogate_or_strict"),
|
||||||
|
re.MULTILINE | re.DOTALL,
|
||||||
|
)
|
||||||
|
if subject_alt_names is not None:
|
||||||
|
for san in subject_alt_names.group(1).split(", "):
|
||||||
|
if san.lower().startswith("dns:"):
|
||||||
|
add_identifier(("dns", san[4:]))
|
||||||
|
elif san.lower().startswith("ip:"):
|
||||||
|
add_identifier(("ip", self._normalize_ip(san[3:])))
|
||||||
|
elif san.lower().startswith("ip address:"):
|
||||||
|
add_identifier(("ip", self._normalize_ip(san[11:])))
|
||||||
|
else:
|
||||||
|
raise BackendException(f'Found unsupported SAN identifier "{san}"')
|
||||||
|
return result
|
||||||
|
|
||||||
|
def get_csr_identifiers(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
csr_filename: str | os.PathLike | None = None,
|
||||||
|
csr_content: str | bytes | None = None,
|
||||||
|
) -> set[tuple[str, str]]:
|
||||||
|
"""
|
||||||
|
Return a set of requested identifiers (CN and SANs) for the CSR.
|
||||||
|
Each identifier is a pair (type, identifier), where type is either
|
||||||
|
'dns' or 'ip'.
|
||||||
|
"""
|
||||||
|
return set(
|
||||||
|
self.get_ordered_csr_identifiers(
|
||||||
|
csr_filename=csr_filename, csr_content=csr_content
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_cert_days(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
cert_filename: str | os.PathLike | None = None,
|
||||||
|
cert_content: str | bytes | None = None,
|
||||||
|
now: datetime.datetime | None = None,
|
||||||
|
) -> int:
|
||||||
|
"""
|
||||||
|
Return the days the certificate in cert_filename remains valid and -1
|
||||||
|
if the file was not found. If cert_filename contains more than one
|
||||||
|
certificate, only the first one will be considered.
|
||||||
|
|
||||||
|
If now is not specified, datetime.datetime.now() is used.
|
||||||
|
"""
|
||||||
|
filename = cert_filename
|
||||||
|
data = None
|
||||||
|
if cert_content is not None:
|
||||||
|
filename = "/dev/stdin"
|
||||||
|
data = to_bytes(cert_content)
|
||||||
|
cert_filename_suffix = ""
|
||||||
|
elif cert_filename is not None:
|
||||||
|
if not os.path.exists(cert_filename):
|
||||||
|
return -1
|
||||||
|
cert_filename_suffix = f" in {cert_filename}"
|
||||||
|
else:
|
||||||
|
return -1
|
||||||
|
|
||||||
|
openssl_cert_cmd = [
|
||||||
|
self.openssl_binary,
|
||||||
|
"x509",
|
||||||
|
"-in",
|
||||||
|
str(filename),
|
||||||
|
"-noout",
|
||||||
|
"-text",
|
||||||
|
]
|
||||||
|
rc, out, err = self.module.run_command(
|
||||||
|
openssl_cert_cmd,
|
||||||
|
data=data,
|
||||||
|
check_rc=False,
|
||||||
|
binary_data=True,
|
||||||
|
environ_update=_OPENSSL_ENVIRONMENT_UPDATE,
|
||||||
|
)
|
||||||
|
if rc != 0:
|
||||||
|
raise BackendException(
|
||||||
|
f"Error while running {' '.join(openssl_cert_cmd)}: {err}"
|
||||||
|
)
|
||||||
|
|
||||||
|
out_text = to_text(out, errors="surrogate_or_strict")
|
||||||
|
not_after = _extract_date(
|
||||||
|
out_text, name="Not After", cert_filename_suffix=cert_filename_suffix
|
||||||
|
)
|
||||||
|
if now is None:
|
||||||
|
now = self.get_now()
|
||||||
|
else:
|
||||||
|
now = ensure_utc_timezone(now)
|
||||||
|
return (not_after - now).days
|
||||||
|
|
||||||
|
def create_chain_matcher(self, *, criterium: Criterium) -> t.NoReturn:
|
||||||
|
"""
|
||||||
|
Given a Criterium object, creates a ChainMatcher object.
|
||||||
|
"""
|
||||||
|
raise BackendException(
|
||||||
|
'Alternate chain matching can only be used with the "cryptography" backend.'
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_cert_information(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
cert_filename: str | os.PathLike | None = None,
|
||||||
|
cert_content: str | bytes | None = None,
|
||||||
|
) -> CertificateInformation:
|
||||||
|
"""
|
||||||
|
Return some information on a X.509 certificate as a CertificateInformation object.
|
||||||
|
"""
|
||||||
|
filename = cert_filename
|
||||||
|
data = None
|
||||||
|
if cert_filename is not None:
|
||||||
|
cert_filename_suffix = f" in {cert_filename}"
|
||||||
|
else:
|
||||||
|
filename = "/dev/stdin"
|
||||||
|
data = to_bytes(cert_content)
|
||||||
|
cert_filename_suffix = ""
|
||||||
|
|
||||||
|
openssl_cert_cmd = [
|
||||||
|
self.openssl_binary,
|
||||||
|
"x509",
|
||||||
|
"-in",
|
||||||
|
str(filename),
|
||||||
|
"-noout",
|
||||||
|
"-text",
|
||||||
|
]
|
||||||
|
rc, out, err = self.module.run_command(
|
||||||
|
openssl_cert_cmd,
|
||||||
|
data=data,
|
||||||
|
check_rc=False,
|
||||||
|
binary_data=True,
|
||||||
|
environ_update=_OPENSSL_ENVIRONMENT_UPDATE,
|
||||||
|
)
|
||||||
|
if rc != 0:
|
||||||
|
raise BackendException(
|
||||||
|
f"Error while running {' '.join(openssl_cert_cmd)}: {err}"
|
||||||
|
)
|
||||||
|
|
||||||
|
out_text = to_text(out, errors="surrogate_or_strict")
|
||||||
|
|
||||||
|
not_after = _extract_date(
|
||||||
|
out_text, name="Not After", cert_filename_suffix=cert_filename_suffix
|
||||||
|
)
|
||||||
|
not_before = _extract_date(
|
||||||
|
out_text, name="Not Before", cert_filename_suffix=cert_filename_suffix
|
||||||
|
)
|
||||||
|
|
||||||
|
sn = re.search(
|
||||||
|
r" Serial Number: ([0-9]+)",
|
||||||
|
to_text(out, errors="surrogate_or_strict"),
|
||||||
|
re.MULTILINE | re.DOTALL,
|
||||||
|
)
|
||||||
|
if sn:
|
||||||
|
serial = int(sn.group(1))
|
||||||
|
else:
|
||||||
|
serial = convert_bytes_to_int(
|
||||||
|
_extract_octets(out_text, name="Serial Number", required=True)
|
||||||
|
)
|
||||||
|
|
||||||
|
ski = _extract_octets(
|
||||||
|
out_text, name="X509v3 Subject Key Identifier", required=False
|
||||||
|
)
|
||||||
|
aki = _extract_octets(
|
||||||
|
out_text,
|
||||||
|
name="X509v3 Authority Key Identifier",
|
||||||
|
required=False,
|
||||||
|
potential_prefixes=["keyid:", ""],
|
||||||
|
)
|
||||||
|
|
||||||
|
return CertificateInformation(
|
||||||
|
not_valid_after=not_after,
|
||||||
|
not_valid_before=not_before,
|
||||||
|
serial_number=serial,
|
||||||
|
subject_key_identifier=ski,
|
||||||
|
authority_key_identifier=aki,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ("OpenSSLCLIBackend",)
|
||||||
242
plugins/module_utils/_acme/backends.py
Normal file
242
plugins/module_utils/_acme/backends.py
Normal file
@@ -0,0 +1,242 @@
|
|||||||
|
# Copyright (c) 2016 Michael Gruener <michael.gruener@chaosmoon.net>
|
||||||
|
# Copyright (c) 2021 Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import abc
|
||||||
|
import datetime
|
||||||
|
import re
|
||||||
|
import typing as t
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.errors import (
|
||||||
|
BackendException,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.basic import (
|
||||||
|
OpenSSLObjectError,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._time import (
|
||||||
|
UTC,
|
||||||
|
ensure_utc_timezone,
|
||||||
|
from_epoch_seconds,
|
||||||
|
get_epoch_seconds,
|
||||||
|
get_now_datetime,
|
||||||
|
get_relative_time_option,
|
||||||
|
remove_timezone,
|
||||||
|
)
|
||||||
|
|
||||||
|
if t.TYPE_CHECKING:
|
||||||
|
import os # pragma: no cover
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule # pragma: no cover
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.certificates import ( # pragma: no cover
|
||||||
|
ChainMatcher,
|
||||||
|
Criterium,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class CertificateInformation(t.NamedTuple):
|
||||||
|
not_valid_after: datetime.datetime
|
||||||
|
not_valid_before: datetime.datetime
|
||||||
|
serial_number: int
|
||||||
|
subject_key_identifier: bytes | None
|
||||||
|
authority_key_identifier: bytes | None
|
||||||
|
|
||||||
|
|
||||||
|
_FRACTIONAL_MATCHER = re.compile(
|
||||||
|
r"^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})(|\.\d+)(Z|[+-]\d{2}:?\d{2}.*)$"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _reduce_fractional_digits(timestamp_str: str) -> str:
|
||||||
|
"""
|
||||||
|
Given a RFC 3339 timestamp that includes too many digits for the fractional seconds part, reduces these to at most 6.
|
||||||
|
"""
|
||||||
|
# RFC 3339 (https://www.rfc-editor.org/info/rfc3339)
|
||||||
|
m = _FRACTIONAL_MATCHER.match(timestamp_str)
|
||||||
|
if not m:
|
||||||
|
raise BackendException(f"Cannot parse ISO 8601 timestamp {timestamp_str!r}")
|
||||||
|
timestamp, fractional, timezone = m.groups()
|
||||||
|
if len(fractional) > 7:
|
||||||
|
# Python does not support anything smaller than microseconds
|
||||||
|
# (Golang supports nanoseconds, Boulder often emits more fractional digits, which Python chokes on)
|
||||||
|
fractional = fractional[:7]
|
||||||
|
return f"{timestamp}{fractional}{timezone}"
|
||||||
|
|
||||||
|
|
||||||
|
def _parse_acme_timestamp(
|
||||||
|
timestamp_str: str, *, with_timezone: bool
|
||||||
|
) -> datetime.datetime:
|
||||||
|
"""
|
||||||
|
Parses a RFC 3339 timestamp.
|
||||||
|
"""
|
||||||
|
# RFC 3339 (https://www.rfc-editor.org/info/rfc3339)
|
||||||
|
timestamp_str = _reduce_fractional_digits(timestamp_str)
|
||||||
|
for time_format in (
|
||||||
|
"%Y-%m-%dT%H:%M:%SZ",
|
||||||
|
"%Y-%m-%dT%H:%M:%S.%fZ",
|
||||||
|
"%Y-%m-%dT%H:%M:%S%z",
|
||||||
|
"%Y-%m-%dT%H:%M:%S.%f%z",
|
||||||
|
):
|
||||||
|
try:
|
||||||
|
result = datetime.datetime.strptime(timestamp_str, time_format)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return (
|
||||||
|
ensure_utc_timezone(result)
|
||||||
|
if with_timezone
|
||||||
|
else remove_timezone(result)
|
||||||
|
)
|
||||||
|
raise BackendException(f"Cannot parse ISO 8601 timestamp {timestamp_str!r}")
|
||||||
|
|
||||||
|
|
||||||
|
class CryptoBackend(metaclass=abc.ABCMeta):
|
||||||
|
def __init__(self, *, module: AnsibleModule, with_timezone: bool = False) -> None:
|
||||||
|
self.module = module
|
||||||
|
self._with_timezone = with_timezone
|
||||||
|
|
||||||
|
def get_now(self) -> datetime.datetime:
|
||||||
|
return get_now_datetime(with_timezone=self._with_timezone)
|
||||||
|
|
||||||
|
def parse_acme_timestamp(self, timestamp_str: str) -> datetime.datetime:
|
||||||
|
# RFC 3339 (https://www.rfc-editor.org/info/rfc3339)
|
||||||
|
return _parse_acme_timestamp(timestamp_str, with_timezone=self._with_timezone)
|
||||||
|
|
||||||
|
def parse_module_parameter(self, *, value: str, name: str) -> datetime.datetime:
|
||||||
|
try:
|
||||||
|
result = get_relative_time_option(
|
||||||
|
value, input_name=name, with_timezone=self._with_timezone
|
||||||
|
)
|
||||||
|
if result is None:
|
||||||
|
raise BackendException(f"Invalid value for {name}: {value!r}")
|
||||||
|
return result
|
||||||
|
except OpenSSLObjectError as exc:
|
||||||
|
raise BackendException(str(exc)) from exc
|
||||||
|
|
||||||
|
def interpolate_timestamp(
|
||||||
|
self,
|
||||||
|
timestamp_start: datetime.datetime,
|
||||||
|
timestamp_end: datetime.datetime,
|
||||||
|
*,
|
||||||
|
percentage: float,
|
||||||
|
) -> datetime.datetime:
|
||||||
|
start = get_epoch_seconds(timestamp_start)
|
||||||
|
end = get_epoch_seconds(timestamp_end)
|
||||||
|
return from_epoch_seconds(
|
||||||
|
start + percentage * (end - start), with_timezone=self._with_timezone
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_utc_datetime(
|
||||||
|
self,
|
||||||
|
year: int,
|
||||||
|
month: int,
|
||||||
|
day: int,
|
||||||
|
hour: int = 0,
|
||||||
|
minute: int = 0,
|
||||||
|
second: int = 0,
|
||||||
|
microsecond: int = 0,
|
||||||
|
tzinfo: datetime.timezone | None = None,
|
||||||
|
) -> datetime.datetime:
|
||||||
|
has_tzinfo = tzinfo is not None
|
||||||
|
if self._with_timezone and not has_tzinfo:
|
||||||
|
tzinfo = UTC
|
||||||
|
result = datetime.datetime(
|
||||||
|
year, month, day, hour, minute, second, microsecond, tzinfo
|
||||||
|
)
|
||||||
|
if self._with_timezone and has_tzinfo:
|
||||||
|
result = ensure_utc_timezone(result)
|
||||||
|
return result
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def parse_key(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
key_file: str | os.PathLike | None = None,
|
||||||
|
key_content: str | None = None,
|
||||||
|
passphrase: str | None = None,
|
||||||
|
) -> dict[str, t.Any]:
|
||||||
|
"""
|
||||||
|
Parses an RSA or Elliptic Curve key file in PEM format and returns key_data.
|
||||||
|
Raises KeyParsingError in case of errors.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def sign(
|
||||||
|
self, *, payload64: str, protected64: str, key_data: dict[str, t.Any]
|
||||||
|
) -> dict[str, t.Any]:
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def create_mac_key(self, *, alg: str, key: str) -> dict[str, t.Any]:
|
||||||
|
"""Create a MAC key."""
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def get_ordered_csr_identifiers(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
csr_filename: str | os.PathLike | None = None,
|
||||||
|
csr_content: str | bytes | None = None,
|
||||||
|
) -> list[tuple[str, str]]:
|
||||||
|
"""
|
||||||
|
Return a list of requested identifiers (CN and SANs) for the CSR.
|
||||||
|
Each identifier is a pair (type, identifier), where type is either
|
||||||
|
'dns' or 'ip'.
|
||||||
|
|
||||||
|
The list is deduplicated, and if a CNAME is present, it will be returned
|
||||||
|
as the first element in the result.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def get_csr_identifiers(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
csr_filename: str | os.PathLike | None = None,
|
||||||
|
csr_content: str | bytes | None = None,
|
||||||
|
) -> set[tuple[str, str]]:
|
||||||
|
"""
|
||||||
|
Return a set of requested identifiers (CN and SANs) for the CSR.
|
||||||
|
Each identifier is a pair (type, identifier), where type is either
|
||||||
|
'dns' or 'ip'.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def get_cert_days(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
cert_filename: str | os.PathLike | None = None,
|
||||||
|
cert_content: str | bytes | None = None,
|
||||||
|
now: datetime.datetime | None = None,
|
||||||
|
) -> int:
|
||||||
|
"""
|
||||||
|
Return the days the certificate in cert_filename remains valid and -1
|
||||||
|
if the file was not found. If cert_filename contains more than one
|
||||||
|
certificate, only the first one will be considered.
|
||||||
|
|
||||||
|
If now is not specified, datetime.datetime.now() is used.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def create_chain_matcher(self, *, criterium: Criterium) -> ChainMatcher:
|
||||||
|
"""
|
||||||
|
Given a Criterium object, creates a ChainMatcher object.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def get_cert_information(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
cert_filename: str | os.PathLike | None = None,
|
||||||
|
cert_content: str | bytes | None = None,
|
||||||
|
) -> CertificateInformation:
|
||||||
|
"""
|
||||||
|
Return some information on a X.509 certificate as a CertificateInformation object.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ("CertificateInformation", "CryptoBackend")
|
||||||
434
plugins/module_utils/_acme/certificate.py
Normal file
434
plugins/module_utils/_acme/certificate.py
Normal file
@@ -0,0 +1,434 @@
|
|||||||
|
# Copyright (c) 2024 Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import os
|
||||||
|
import typing as t
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.account import (
|
||||||
|
ACMEAccount,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.acme import (
|
||||||
|
ACMEClient,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.certificates import (
|
||||||
|
CertificateChain,
|
||||||
|
Criterium,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.challenges import (
|
||||||
|
Authorization,
|
||||||
|
wait_for_validation,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.errors import (
|
||||||
|
ModuleFailException,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.io import (
|
||||||
|
write_file,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.orders import Order
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.utils import (
|
||||||
|
pem_to_der,
|
||||||
|
)
|
||||||
|
|
||||||
|
if t.TYPE_CHECKING:
|
||||||
|
from ansible.module_utils.basic import AnsibleModule # pragma: no cover
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.backends import ( # pragma: no cover
|
||||||
|
CryptoBackend,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.certificates import ( # pragma: no cover
|
||||||
|
ChainMatcher,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.challenges import ( # pragma: no cover
|
||||||
|
Challenge,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ACMECertificateClient:
|
||||||
|
"""
|
||||||
|
ACME v2 client class. Uses an ACME account object and a CSR to
|
||||||
|
start and validate ACME challenges and download the respective
|
||||||
|
certificates.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
module: AnsibleModule,
|
||||||
|
backend: CryptoBackend,
|
||||||
|
client: ACMEClient | None = None,
|
||||||
|
account: ACMEAccount | None = None,
|
||||||
|
) -> None:
|
||||||
|
self.module = module
|
||||||
|
self.version = module.params["acme_version"]
|
||||||
|
self.csr = module.params.get("csr")
|
||||||
|
self.csr_content = module.params.get("csr_content")
|
||||||
|
if client is None:
|
||||||
|
client = ACMEClient(module=module, backend=backend)
|
||||||
|
self.client = client
|
||||||
|
if account is None:
|
||||||
|
account = ACMEAccount(client=self.client)
|
||||||
|
self.account = account
|
||||||
|
self.order_uri = module.params.get("order_uri")
|
||||||
|
self.order_creation_error_strategy = module.params.get(
|
||||||
|
"order_creation_error_strategy", "auto"
|
||||||
|
)
|
||||||
|
self.order_creation_max_retries = module.params.get(
|
||||||
|
"order_creation_max_retries", 3
|
||||||
|
)
|
||||||
|
|
||||||
|
# Make sure account exists
|
||||||
|
dummy, account_data = self.account.setup_account(allow_creation=False)
|
||||||
|
if account_data is None:
|
||||||
|
raise ModuleFailException(msg="Account does not exist or is deactivated.")
|
||||||
|
|
||||||
|
if self.csr is not None and not os.path.exists(self.csr):
|
||||||
|
raise ModuleFailException(f"CSR {self.csr} not found")
|
||||||
|
|
||||||
|
# Extract list of identifiers from CSR
|
||||||
|
if self.csr is not None or self.csr_content is not None:
|
||||||
|
self.identifiers: list[tuple[str, str]] | None = (
|
||||||
|
self.client.backend.get_ordered_csr_identifiers(
|
||||||
|
csr_filename=self.csr, csr_content=self.csr_content
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.identifiers = None
|
||||||
|
|
||||||
|
def parse_select_chain(
|
||||||
|
self, select_chain: list[dict[str, t.Any]] | None
|
||||||
|
) -> list[ChainMatcher]:
|
||||||
|
select_chain_matcher = []
|
||||||
|
if select_chain:
|
||||||
|
for criterium_idx, criterium in enumerate(select_chain):
|
||||||
|
try:
|
||||||
|
select_chain_matcher.append(
|
||||||
|
self.client.backend.create_chain_matcher(
|
||||||
|
criterium=Criterium(
|
||||||
|
criterium=criterium, index=criterium_idx
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
except ValueError as exc:
|
||||||
|
self.module.warn(
|
||||||
|
f"Error while parsing criterium: {exc}. Ignoring criterium."
|
||||||
|
)
|
||||||
|
return select_chain_matcher
|
||||||
|
|
||||||
|
def load_order(self) -> Order:
|
||||||
|
if not self.order_uri:
|
||||||
|
raise ModuleFailException("The order URI has not been provided")
|
||||||
|
order = Order.from_url(client=self.client, url=self.order_uri)
|
||||||
|
order.load_authorizations(client=self.client)
|
||||||
|
return order
|
||||||
|
|
||||||
|
def create_order(
|
||||||
|
self, *, replaces_cert_id: str | None = None, profile: str | None = None
|
||||||
|
) -> Order:
|
||||||
|
"""
|
||||||
|
Create a new order.
|
||||||
|
"""
|
||||||
|
if self.identifiers is None:
|
||||||
|
raise ModuleFailException("No identifiers have been provided")
|
||||||
|
order = Order.create_with_error_handling(
|
||||||
|
client=self.client,
|
||||||
|
identifiers=self.identifiers,
|
||||||
|
error_strategy=self.order_creation_error_strategy,
|
||||||
|
error_max_retries=self.order_creation_max_retries,
|
||||||
|
replaces_cert_id=replaces_cert_id,
|
||||||
|
profile=profile,
|
||||||
|
message_callback=self.module.warn,
|
||||||
|
)
|
||||||
|
self.order_uri = order.url
|
||||||
|
order.load_authorizations(client=self.client)
|
||||||
|
return order
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _update_dns_data(
|
||||||
|
data_dns: dict[str, list[str]],
|
||||||
|
dns_challenge_type: str,
|
||||||
|
challenge_data: dict[str, t.Any],
|
||||||
|
) -> None:
|
||||||
|
dns_challenge = challenge_data.get(dns_challenge_type)
|
||||||
|
if dns_challenge:
|
||||||
|
values = data_dns.get(dns_challenge["record"])
|
||||||
|
if values is None:
|
||||||
|
values = []
|
||||||
|
data_dns[dns_challenge["record"]] = values
|
||||||
|
values.append(dns_challenge["resource_value"])
|
||||||
|
|
||||||
|
def get_challenges_data(
|
||||||
|
self, order: Order
|
||||||
|
) -> tuple[list[dict[str, t.Any]], dict[str, list[str]], dict[str, list[str]]]:
|
||||||
|
"""
|
||||||
|
Get challenge details.
|
||||||
|
|
||||||
|
Return a tuple of generic challenge details, and specialized DNS challenge details.
|
||||||
|
"""
|
||||||
|
data: list[dict[str, t.Any]] = []
|
||||||
|
data_dns: dict[str, list[str]] = {}
|
||||||
|
data_dns_account: dict[str, list[str]] = {}
|
||||||
|
dns_challenge_type = "dns-01"
|
||||||
|
dns_account_challenge_type = "dns-account-01"
|
||||||
|
for authz in order.authorizations.values():
|
||||||
|
# Skip valid authentications: their challenges are already valid
|
||||||
|
# and do not need to be returned
|
||||||
|
if authz.status == "valid":
|
||||||
|
continue
|
||||||
|
challenge_data = authz.get_challenge_data(client=self.client)
|
||||||
|
data.append(
|
||||||
|
{
|
||||||
|
"identifier": authz.identifier,
|
||||||
|
"identifier_type": authz.identifier_type,
|
||||||
|
"challenges": challenge_data,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
self._update_dns_data(data_dns, dns_challenge_type, challenge_data)
|
||||||
|
self._update_dns_data(
|
||||||
|
data_dns_account, dns_account_challenge_type, challenge_data
|
||||||
|
)
|
||||||
|
return data, data_dns, data_dns_account
|
||||||
|
|
||||||
|
def check_that_authorizations_can_be_used(self, order: Order) -> None:
|
||||||
|
bad_authzs = []
|
||||||
|
for authz in order.authorizations.values():
|
||||||
|
if authz.status not in ("valid", "pending"):
|
||||||
|
error_details = authz.get_error_details()
|
||||||
|
error = f"; {error_details}" if error_details else ""
|
||||||
|
bad_authzs.append(
|
||||||
|
f"{authz.combined_identifier} (status={authz.status!r}{error})"
|
||||||
|
)
|
||||||
|
if bad_authzs:
|
||||||
|
bad_authzs_str = ", ".join(sorted(bad_authzs))
|
||||||
|
raise ModuleFailException(
|
||||||
|
f"Some of the authorizations for the order are in a bad state, so the order can no longer be satisfied: {bad_authzs_str}",
|
||||||
|
)
|
||||||
|
|
||||||
|
def collect_invalid_authzs(self, order: Order) -> list[Authorization]:
|
||||||
|
return [
|
||||||
|
authz
|
||||||
|
for authz in order.authorizations.values()
|
||||||
|
if authz.status == "invalid"
|
||||||
|
]
|
||||||
|
|
||||||
|
def collect_pending_authzs(self, order: Order) -> list[Authorization]:
|
||||||
|
return [
|
||||||
|
authz
|
||||||
|
for authz in order.authorizations.values()
|
||||||
|
if authz.status == "pending"
|
||||||
|
]
|
||||||
|
|
||||||
|
def call_validate(
|
||||||
|
self,
|
||||||
|
pending_authzs: list[Authorization],
|
||||||
|
*,
|
||||||
|
get_challenge: Callable[[Authorization], str],
|
||||||
|
wait: bool = True,
|
||||||
|
) -> list[tuple[Authorization, str, Challenge | None]]:
|
||||||
|
authzs_with_challenges_to_wait_for = []
|
||||||
|
for authz in pending_authzs:
|
||||||
|
challenge_type = get_challenge(authz)
|
||||||
|
authz.call_validate(
|
||||||
|
client=self.client, challenge_type=challenge_type, wait=wait
|
||||||
|
)
|
||||||
|
authzs_with_challenges_to_wait_for.append(
|
||||||
|
(
|
||||||
|
authz,
|
||||||
|
challenge_type,
|
||||||
|
authz.find_challenge(challenge_type=challenge_type),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return authzs_with_challenges_to_wait_for
|
||||||
|
|
||||||
|
def wait_for_validation(self, authzs_to_wait_for: list[Authorization]) -> None:
|
||||||
|
wait_for_validation(authzs=authzs_to_wait_for, client=self.client)
|
||||||
|
|
||||||
|
def _download_alternate_chains(
|
||||||
|
self, cert: CertificateChain
|
||||||
|
) -> list[CertificateChain]:
|
||||||
|
alternate_chains = []
|
||||||
|
for alternate in cert.alternates:
|
||||||
|
try:
|
||||||
|
alt_cert = CertificateChain.download(client=self.client, url=alternate)
|
||||||
|
except ModuleFailException as e:
|
||||||
|
self.module.warn(
|
||||||
|
f"Error while downloading alternative certificate {alternate}: {e}"
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
if alt_cert.cert is not None:
|
||||||
|
alternate_chains.append(alt_cert)
|
||||||
|
else:
|
||||||
|
self.module.warn(
|
||||||
|
f"Error while downloading alternative certificate {alternate}: no certificate found"
|
||||||
|
)
|
||||||
|
return alternate_chains
|
||||||
|
|
||||||
|
@t.overload
|
||||||
|
def download_certificate(
|
||||||
|
self, order: Order, *, download_all_chains: t.Literal[True] = True
|
||||||
|
) -> tuple[CertificateChain, list[CertificateChain]]: ...
|
||||||
|
|
||||||
|
@t.overload
|
||||||
|
def download_certificate(
|
||||||
|
self, order: Order, *, download_all_chains: t.Literal[False]
|
||||||
|
) -> tuple[CertificateChain, None]: ...
|
||||||
|
|
||||||
|
@t.overload
|
||||||
|
def download_certificate(
|
||||||
|
self, order: Order, *, download_all_chains: bool = True
|
||||||
|
) -> tuple[CertificateChain, list[CertificateChain] | None]: ...
|
||||||
|
|
||||||
|
def download_certificate(
|
||||||
|
self, order: Order, *, download_all_chains: bool = True
|
||||||
|
) -> tuple[CertificateChain, list[CertificateChain] | None]:
|
||||||
|
"""
|
||||||
|
Download certificate from a valid oder.
|
||||||
|
"""
|
||||||
|
if order.status != "valid":
|
||||||
|
raise ModuleFailException(
|
||||||
|
f"The order must be valid, but has state {order.status!r}!"
|
||||||
|
)
|
||||||
|
|
||||||
|
if not order.certificate_uri:
|
||||||
|
raise ModuleFailException(
|
||||||
|
f"Order's crtificate URL {order.certificate_uri!r} is empty!"
|
||||||
|
)
|
||||||
|
|
||||||
|
cert = CertificateChain.download(client=self.client, url=order.certificate_uri)
|
||||||
|
if cert.cert is None:
|
||||||
|
raise ModuleFailException(
|
||||||
|
f"Certificate at {order.certificate_uri} is empty!"
|
||||||
|
)
|
||||||
|
|
||||||
|
alternate_chains = None
|
||||||
|
if download_all_chains:
|
||||||
|
alternate_chains = self._download_alternate_chains(cert)
|
||||||
|
|
||||||
|
return cert, alternate_chains
|
||||||
|
|
||||||
|
@t.overload
|
||||||
|
def get_certificate(
|
||||||
|
self, order: Order, *, download_all_chains: t.Literal[True] = True
|
||||||
|
) -> tuple[CertificateChain, list[CertificateChain] | None]: ...
|
||||||
|
|
||||||
|
@t.overload
|
||||||
|
def get_certificate(
|
||||||
|
self, order: Order, *, download_all_chains: t.Literal[False]
|
||||||
|
) -> tuple[CertificateChain, list[CertificateChain] | None]: ...
|
||||||
|
|
||||||
|
@t.overload
|
||||||
|
def get_certificate(
|
||||||
|
self, order: Order, *, download_all_chains: bool = True
|
||||||
|
) -> tuple[CertificateChain, list[CertificateChain] | None]: ...
|
||||||
|
|
||||||
|
def get_certificate(
|
||||||
|
self, order: Order, *, download_all_chains: bool = True
|
||||||
|
) -> tuple[CertificateChain, list[CertificateChain] | None]:
|
||||||
|
"""
|
||||||
|
Request a new certificate and downloads it, and optionally all certificate chains.
|
||||||
|
First verifies whether all authorizations are valid; if not, aborts with an error.
|
||||||
|
"""
|
||||||
|
if self.csr is None and self.csr_content is None:
|
||||||
|
raise ModuleFailException("No CSR has been provided")
|
||||||
|
for authz in order.authorizations.values():
|
||||||
|
if authz.status != "valid":
|
||||||
|
authz.raise_error(
|
||||||
|
error_msg=f'Status is {authz.status!r} and not "valid"',
|
||||||
|
module=self.module,
|
||||||
|
)
|
||||||
|
|
||||||
|
order.finalize(
|
||||||
|
client=self.client,
|
||||||
|
csr_der=pem_to_der(pem_filename=self.csr, pem_content=self.csr_content),
|
||||||
|
)
|
||||||
|
|
||||||
|
return self.download_certificate(order, download_all_chains=download_all_chains)
|
||||||
|
|
||||||
|
def find_matching_chain(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
chains: list[CertificateChain],
|
||||||
|
select_chain_matcher: t.Iterable[ChainMatcher],
|
||||||
|
) -> CertificateChain | None:
|
||||||
|
for criterium_idx, matcher in enumerate(select_chain_matcher):
|
||||||
|
for chain in chains:
|
||||||
|
if matcher.match(certificate=chain):
|
||||||
|
self.module.debug(
|
||||||
|
f"Found matching chain for criterium {criterium_idx}"
|
||||||
|
)
|
||||||
|
return chain
|
||||||
|
return None
|
||||||
|
|
||||||
|
def write_cert_chain(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
cert: CertificateChain,
|
||||||
|
cert_dest: str | os.PathLike | None = None,
|
||||||
|
fullchain_dest: str | os.PathLike | None = None,
|
||||||
|
chain_dest: str | os.PathLike | None = None,
|
||||||
|
) -> bool:
|
||||||
|
changed = False
|
||||||
|
if cert.cert is None:
|
||||||
|
raise ValueError("Certificate is not present")
|
||||||
|
|
||||||
|
if cert_dest and write_file(
|
||||||
|
module=self.module, dest=cert_dest, content=cert.cert.encode("utf8")
|
||||||
|
):
|
||||||
|
changed = True
|
||||||
|
|
||||||
|
if fullchain_dest and write_file(
|
||||||
|
module=self.module,
|
||||||
|
dest=fullchain_dest,
|
||||||
|
content=(cert.cert + "\n".join(cert.chain)).encode("utf8"),
|
||||||
|
):
|
||||||
|
changed = True
|
||||||
|
|
||||||
|
if chain_dest and write_file(
|
||||||
|
module=self.module,
|
||||||
|
dest=chain_dest,
|
||||||
|
content=("\n".join(cert.chain)).encode("utf8"),
|
||||||
|
):
|
||||||
|
changed = True
|
||||||
|
|
||||||
|
return changed
|
||||||
|
|
||||||
|
def deactivate_authzs(self, order: Order) -> None:
|
||||||
|
"""
|
||||||
|
Deactivates all valid authz's. Does not raise exceptions.
|
||||||
|
https://community.letsencrypt.org/t/authorization-deactivation/19860/2
|
||||||
|
https://tools.ietf.org/html/rfc8555#section-7.5.2
|
||||||
|
"""
|
||||||
|
if len(order.authorization_uris) > len(order.authorizations):
|
||||||
|
for authz_uri in order.authorization_uris:
|
||||||
|
authz = None
|
||||||
|
try:
|
||||||
|
authz = Authorization.deactivate_url(
|
||||||
|
client=self.client, url=authz_uri
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
# ignore errors
|
||||||
|
pass
|
||||||
|
if authz is None or not authz.is_in_final_state(allow_valid=False):
|
||||||
|
self.module.warn(
|
||||||
|
warning=f"Could not deactivate authz object {authz_uri}."
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
for authz in order.authorizations.values():
|
||||||
|
try:
|
||||||
|
authz.deactivate(client=self.client)
|
||||||
|
except Exception:
|
||||||
|
# ignore errors
|
||||||
|
pass
|
||||||
|
if not authz.is_in_final_state(allow_valid=False):
|
||||||
|
self.module.warn(
|
||||||
|
warning=f"Could not deactivate authz object {authz.url}."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ("ACMECertificateClient",)
|
||||||
131
plugins/module_utils/_acme/certificates.py
Normal file
131
plugins/module_utils/_acme/certificates.py
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
# Copyright (c) 2016 Michael Gruener <michael.gruener@chaosmoon.net>
|
||||||
|
# Copyright (c) 2021 Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import abc
|
||||||
|
import typing as t
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.errors import (
|
||||||
|
ModuleFailException,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.utils import (
|
||||||
|
der_to_pem,
|
||||||
|
process_links,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.pem import (
|
||||||
|
split_pem_list,
|
||||||
|
)
|
||||||
|
|
||||||
|
if t.TYPE_CHECKING:
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.acme import ( # pragma: no cover
|
||||||
|
ACMEClient,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
_CertificateChain = t.TypeVar("_CertificateChain", bound="CertificateChain")
|
||||||
|
|
||||||
|
|
||||||
|
class CertificateChain:
|
||||||
|
"""
|
||||||
|
Download and parse the certificate chain.
|
||||||
|
https://tools.ietf.org/html/rfc8555#section-7.4.2
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, url: str):
|
||||||
|
self.url = url
|
||||||
|
self.cert: str | None = None
|
||||||
|
self.chain: list[str] = []
|
||||||
|
self.alternates: list[str] = []
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def download(
|
||||||
|
cls: type[_CertificateChain], *, client: ACMEClient, url: str
|
||||||
|
) -> _CertificateChain:
|
||||||
|
content, info = client.get_request(
|
||||||
|
url,
|
||||||
|
parse_json_result=False,
|
||||||
|
headers={"Accept": "application/pem-certificate-chain"},
|
||||||
|
)
|
||||||
|
|
||||||
|
if not content or not info["content-type"].startswith(
|
||||||
|
"application/pem-certificate-chain"
|
||||||
|
):
|
||||||
|
raise ModuleFailException(
|
||||||
|
f"Cannot download certificate chain from {url}, as content type is not application/pem-certificate-chain: {content!r} (headers: {info})"
|
||||||
|
)
|
||||||
|
|
||||||
|
result = cls(url)
|
||||||
|
|
||||||
|
# Parse data
|
||||||
|
certs = split_pem_list(content.decode("utf-8"), keep_inbetween=True)
|
||||||
|
if certs:
|
||||||
|
result.cert = certs[0]
|
||||||
|
result.chain = certs[1:]
|
||||||
|
|
||||||
|
process_links(
|
||||||
|
info=info,
|
||||||
|
callback=lambda link, relation: result._process_links( # pylint: disable=protected-access
|
||||||
|
client=client, link=link, relation=relation
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
if result.cert is None:
|
||||||
|
raise ModuleFailException(
|
||||||
|
f"Failed to parse certificate chain download from {url}: {content!r} (headers: {info})"
|
||||||
|
)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
def _process_links(self, *, client: ACMEClient, link: str, relation: str) -> None:
|
||||||
|
if relation == "up":
|
||||||
|
# Process link-up headers if there was no chain in reply
|
||||||
|
if not self.chain:
|
||||||
|
chain_result, chain_info = client.get_request(
|
||||||
|
link, parse_json_result=False
|
||||||
|
)
|
||||||
|
if chain_info["status"] in [200, 201]:
|
||||||
|
self.chain.append(der_to_pem(chain_result))
|
||||||
|
elif relation == "alternate":
|
||||||
|
self.alternates.append(link)
|
||||||
|
|
||||||
|
def to_json(self) -> dict[str, bytes]:
|
||||||
|
if self.cert is None:
|
||||||
|
raise ValueError("Has no certificate")
|
||||||
|
cert = self.cert.encode("utf8")
|
||||||
|
chain = ("\n".join(self.chain)).encode("utf8")
|
||||||
|
return {
|
||||||
|
"cert": cert,
|
||||||
|
"chain": chain,
|
||||||
|
"full_chain": cert + chain,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Criterium:
|
||||||
|
def __init__(self, *, criterium: dict[str, t.Any], index: int):
|
||||||
|
self.index = index
|
||||||
|
self.test_certificates: t.Literal["first", "last", "all"] = criterium[
|
||||||
|
"test_certificates"
|
||||||
|
]
|
||||||
|
self.subject: dict[str, t.Any] | None = criterium["subject"]
|
||||||
|
self.issuer: dict[str, t.Any] | None = criterium["issuer"]
|
||||||
|
self.subject_key_identifier: str | None = criterium["subject_key_identifier"]
|
||||||
|
self.authority_key_identifier: str | None = criterium[
|
||||||
|
"authority_key_identifier"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class ChainMatcher(metaclass=abc.ABCMeta):
|
||||||
|
@abc.abstractmethod
|
||||||
|
def match(self, *, certificate: CertificateChain) -> bool:
|
||||||
|
"""
|
||||||
|
Check whether a certificate chain (CertificateChain instance) matches.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ("CertificateChain", "ChainMatcher", "Criterium")
|
||||||
503
plugins/module_utils/_acme/challenges.py
Normal file
503
plugins/module_utils/_acme/challenges.py
Normal file
@@ -0,0 +1,503 @@
|
|||||||
|
# Copyright (c) 2016 Michael Gruener <michael.gruener@chaosmoon.net>
|
||||||
|
# Copyright (c) 2021 Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import base64
|
||||||
|
import hashlib
|
||||||
|
import ipaddress
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
import time
|
||||||
|
import typing as t
|
||||||
|
|
||||||
|
from ansible.module_utils.common.text.converters import to_bytes
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.errors import (
|
||||||
|
ACMEProtocolException,
|
||||||
|
ModuleFailException,
|
||||||
|
format_error_problem,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.utils import (
|
||||||
|
nopad_b64,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._caa import (
|
||||||
|
_check_domain_name,
|
||||||
|
)
|
||||||
|
|
||||||
|
if t.TYPE_CHECKING:
|
||||||
|
from ansible.module_utils.basic import AnsibleModule # pragma: no cover
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.acme import ( # pragma: no cover
|
||||||
|
ACMEClient,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def create_key_authorization(*, client: ACMEClient, token: str) -> str:
|
||||||
|
"""
|
||||||
|
Returns the key authorization for the given token
|
||||||
|
https://tools.ietf.org/html/rfc8555#section-8.1
|
||||||
|
"""
|
||||||
|
accountkey_json = json.dumps(
|
||||||
|
client.account_jwk, sort_keys=True, separators=(",", ":")
|
||||||
|
)
|
||||||
|
thumbprint = nopad_b64(hashlib.sha256(accountkey_json.encode("utf8")).digest())
|
||||||
|
return f"{token}.{thumbprint}"
|
||||||
|
|
||||||
|
|
||||||
|
def combine_identifier(*, identifier_type: str, identifier: str) -> str:
|
||||||
|
return f"{identifier_type}:{identifier}"
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_combined_identifier(identifier: str) -> str:
|
||||||
|
identifier_type, identifier = split_identifier(identifier)
|
||||||
|
# Normalize DNS names and IPs
|
||||||
|
identifier = identifier.lower()
|
||||||
|
return combine_identifier(identifier_type=identifier_type, identifier=identifier)
|
||||||
|
|
||||||
|
|
||||||
|
def split_identifier(identifier: str) -> tuple[str, str]:
|
||||||
|
parts = identifier.split(":", 1)
|
||||||
|
if len(parts) != 2:
|
||||||
|
raise ModuleFailException(
|
||||||
|
f'Identifier "{identifier}" is not of the form <type>:<identifier>'
|
||||||
|
)
|
||||||
|
return parts[0], parts[1]
|
||||||
|
|
||||||
|
|
||||||
|
_Challenge = t.TypeVar("_Challenge", bound="Challenge")
|
||||||
|
|
||||||
|
|
||||||
|
class Challenge:
|
||||||
|
def __init__(self, *, data: dict[str, t.Any], url: str) -> None:
|
||||||
|
self.data = data
|
||||||
|
|
||||||
|
self.type: str = data["type"]
|
||||||
|
self.url = url
|
||||||
|
self.status: str = data["status"]
|
||||||
|
self.token: str | None = data.get("token")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(
|
||||||
|
cls: type[_Challenge],
|
||||||
|
*,
|
||||||
|
client: ACMEClient,
|
||||||
|
data: dict[str, t.Any],
|
||||||
|
url: str | None = None,
|
||||||
|
) -> _Challenge:
|
||||||
|
return cls(data=data, url=url or data["url"])
|
||||||
|
|
||||||
|
def call_validate(self, client: ACMEClient) -> None:
|
||||||
|
challenge_response: dict[str, t.Any] = {}
|
||||||
|
client.send_signed_request(
|
||||||
|
self.url,
|
||||||
|
challenge_response,
|
||||||
|
error_msg="Failed to validate challenge",
|
||||||
|
expected_status_codes=[200, 202],
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_json(self) -> dict[str, t.Any]:
|
||||||
|
return self.data.copy()
|
||||||
|
|
||||||
|
def get_validation_data(
|
||||||
|
self, *, client: ACMEClient, identifier_type: str, identifier: str
|
||||||
|
) -> dict[str, t.Any] | None:
|
||||||
|
if self.type == "dns-persist-01":
|
||||||
|
# https://www.ietf.org/archive/id/draft-ietf-acme-dns-persist-01.html#section-3.1
|
||||||
|
account_uri = self.data.get("accounturi")
|
||||||
|
issuer_domain_names = self.data.get("issuer-domain-names")
|
||||||
|
if account_uri is None:
|
||||||
|
# In version 00 of the draft, accounturi isn't present.
|
||||||
|
# Since that's what Pebble currently implements,
|
||||||
|
# let's fake the value if we have it.
|
||||||
|
# (https://www.ietf.org/archive/id/draft-ietf-acme-dns-persist-00.html#section-6)
|
||||||
|
account_uri = client.account_uri
|
||||||
|
if (
|
||||||
|
not isinstance(account_uri, str)
|
||||||
|
or not isinstance(issuer_domain_names, list)
|
||||||
|
or not all(isinstance(idn, str) for idn in issuer_domain_names)
|
||||||
|
):
|
||||||
|
return None
|
||||||
|
if not (1 <= len(issuer_domain_names) <= 10):
|
||||||
|
client.module.warn(
|
||||||
|
f"The dns-persist-01 challenge for DNS:{identifier} has {len(issuer_domain_names)}"
|
||||||
|
" issuer domain names, which is not in [1, 10]. Ignoring malformed challenge."
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
for idn in issuer_domain_names:
|
||||||
|
try:
|
||||||
|
_check_domain_name(idn)
|
||||||
|
if idn != idn.lower() or len(idn) > 253:
|
||||||
|
raise ValueError()
|
||||||
|
except ValueError:
|
||||||
|
client.module.warn(
|
||||||
|
f"The dns-persist-01 challenge for DNS:{identifier} has an invalid"
|
||||||
|
f" issuer domain name {idn!r}. Ignoring malformed challenge."
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
return {
|
||||||
|
"account_uri": account_uri,
|
||||||
|
"issuer_domain_names": issuer_domain_names,
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.token is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
token = re.sub(r"[^A-Za-z0-9_\-]", "_", self.token)
|
||||||
|
key_authorization = create_key_authorization(client=client, token=token)
|
||||||
|
|
||||||
|
if self.type == "http-01":
|
||||||
|
# https://tools.ietf.org/html/rfc8555#section-8.3
|
||||||
|
return {
|
||||||
|
"resource": f".well-known/acme-challenge/{token}",
|
||||||
|
"resource_value": key_authorization,
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.type == "dns-01":
|
||||||
|
if identifier_type != "dns":
|
||||||
|
return None
|
||||||
|
# https://tools.ietf.org/html/rfc8555#section-8.4
|
||||||
|
resource = "_acme-challenge"
|
||||||
|
value = nopad_b64(hashlib.sha256(to_bytes(key_authorization)).digest())
|
||||||
|
record = f"{resource}.{identifier[2:] if identifier.startswith('*.') else identifier}"
|
||||||
|
return {
|
||||||
|
"resource": resource,
|
||||||
|
"resource_value": value,
|
||||||
|
"record": record,
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.type == "dns-account-01":
|
||||||
|
if identifier_type != "dns" or client.account_uri is None:
|
||||||
|
return None
|
||||||
|
# https://datatracker.ietf.org/doc/html/draft-ietf-acme-dns-account-label-02#section-3.2
|
||||||
|
prefix = (
|
||||||
|
base64.b32encode(
|
||||||
|
hashlib.sha256(client.account_uri.encode("utf8")).digest()[:10]
|
||||||
|
)
|
||||||
|
.decode("ascii")
|
||||||
|
.lower()
|
||||||
|
)
|
||||||
|
resource = f"_{prefix}._acme-challenge"
|
||||||
|
value = nopad_b64(hashlib.sha256(to_bytes(key_authorization)).digest())
|
||||||
|
record = f"{resource}.{identifier[2:] if identifier.startswith('*.') else identifier}"
|
||||||
|
return {
|
||||||
|
"resource": resource,
|
||||||
|
"resource_value": value,
|
||||||
|
"record": record,
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.type == "tls-alpn-01":
|
||||||
|
# https://www.rfc-editor.org/rfc/rfc8737.html#section-3
|
||||||
|
if identifier_type == "ip":
|
||||||
|
# IPv4/IPv6 address: use reverse mapping (RFC1034, RFC3596)
|
||||||
|
resource = ipaddress.ip_address(identifier).reverse_pointer
|
||||||
|
if not resource.endswith("."):
|
||||||
|
resource += "."
|
||||||
|
else:
|
||||||
|
resource = identifier
|
||||||
|
b_value = base64.b64encode(
|
||||||
|
hashlib.sha256(to_bytes(key_authorization)).digest()
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
"resource": resource,
|
||||||
|
"resource_original": combine_identifier(
|
||||||
|
identifier_type=identifier_type, identifier=identifier
|
||||||
|
),
|
||||||
|
"resource_value": b_value,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Unknown challenge type: ignore
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
_Authorization = t.TypeVar("_Authorization", bound="Authorization")
|
||||||
|
|
||||||
|
|
||||||
|
class Authorization:
|
||||||
|
def __init__(self, *, url: str) -> None:
|
||||||
|
self.url = url
|
||||||
|
|
||||||
|
self.data: dict[str, t.Any] | None = None
|
||||||
|
self.challenges: list[Challenge] = []
|
||||||
|
self.status: str | None = None
|
||||||
|
self.identifier_type: str | None = None
|
||||||
|
self.identifier: str | None = None
|
||||||
|
|
||||||
|
def _setup(self, *, client: ACMEClient, data: dict[str, t.Any]) -> None:
|
||||||
|
data["uri"] = self.url
|
||||||
|
self.data = data
|
||||||
|
# While 'challenges' is a required field, apparently not every CA cares
|
||||||
|
# (https://github.com/ansible-collections/community.crypto/issues/824)
|
||||||
|
if data.get("challenges"):
|
||||||
|
self.challenges = [
|
||||||
|
Challenge.from_json(client=client, data=challenge)
|
||||||
|
for challenge in data["challenges"]
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
self.challenges = []
|
||||||
|
self.status = data["status"]
|
||||||
|
self.identifier = data["identifier"]["value"]
|
||||||
|
self.identifier_type = data["identifier"]["type"]
|
||||||
|
if data.get("wildcard", False):
|
||||||
|
self.identifier = f"*.{self.identifier}"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(
|
||||||
|
cls: type[_Authorization],
|
||||||
|
*,
|
||||||
|
client: ACMEClient,
|
||||||
|
data: dict[str, t.Any],
|
||||||
|
url: str,
|
||||||
|
) -> _Authorization:
|
||||||
|
result = cls(url=url)
|
||||||
|
result._setup(client=client, data=data)
|
||||||
|
return result
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_url(
|
||||||
|
cls: type[_Authorization], *, client: ACMEClient, url: str
|
||||||
|
) -> _Authorization:
|
||||||
|
result = cls(url=url)
|
||||||
|
result.refresh(client=client)
|
||||||
|
return result
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def create(
|
||||||
|
cls: type[_Authorization],
|
||||||
|
*,
|
||||||
|
client: ACMEClient,
|
||||||
|
identifier_type: str,
|
||||||
|
identifier: str,
|
||||||
|
) -> _Authorization:
|
||||||
|
"""
|
||||||
|
Create a new authorization for the given identifier.
|
||||||
|
Return the authorization object of the new authorization
|
||||||
|
https://tools.ietf.org/html/draft-ietf-acme-acme-02#section-6.4
|
||||||
|
"""
|
||||||
|
new_authz = {
|
||||||
|
"identifier": {
|
||||||
|
"type": identifier_type,
|
||||||
|
"value": identifier,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if "newAuthz" not in client.directory.directory:
|
||||||
|
raise ACMEProtocolException(
|
||||||
|
module=client.module,
|
||||||
|
msg="ACME endpoint does not support pre-authorization",
|
||||||
|
)
|
||||||
|
url = client.directory["newAuthz"]
|
||||||
|
|
||||||
|
result, info = client.send_signed_request(
|
||||||
|
url,
|
||||||
|
new_authz,
|
||||||
|
error_msg="Failed to request challenges",
|
||||||
|
expected_status_codes=[200, 201],
|
||||||
|
)
|
||||||
|
if not isinstance(result, dict):
|
||||||
|
raise ACMEProtocolException(
|
||||||
|
module=client.module,
|
||||||
|
msg="Unexpected authorization creation result",
|
||||||
|
content_json=result,
|
||||||
|
)
|
||||||
|
return cls.from_json(client=client, data=result, url=info["location"])
|
||||||
|
|
||||||
|
@property
|
||||||
|
def combined_identifier(self) -> str:
|
||||||
|
if self.identifier_type is None or self.identifier is None:
|
||||||
|
raise ValueError("Data not present")
|
||||||
|
return combine_identifier(
|
||||||
|
identifier_type=self.identifier_type, identifier=self.identifier
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_json(self) -> dict[str, t.Any]:
|
||||||
|
if self.data is None:
|
||||||
|
raise ValueError("Data not present")
|
||||||
|
return self.data.copy()
|
||||||
|
|
||||||
|
def refresh(self, *, client: ACMEClient) -> bool:
|
||||||
|
result, info = client.get_request(self.url)
|
||||||
|
if not isinstance(result, dict):
|
||||||
|
raise ACMEProtocolException(
|
||||||
|
module=client.module,
|
||||||
|
msg="Unexpected authorization data",
|
||||||
|
info=info,
|
||||||
|
content_json=result,
|
||||||
|
)
|
||||||
|
changed = self.data != result
|
||||||
|
self._setup(client=client, data=result)
|
||||||
|
return changed
|
||||||
|
|
||||||
|
def get_challenge_data(self, *, client: ACMEClient) -> dict[str, t.Any]:
|
||||||
|
"""
|
||||||
|
Returns a dict with the data for all proposed (and supported) challenges
|
||||||
|
of the given authorization.
|
||||||
|
"""
|
||||||
|
if self.identifier_type is None or self.identifier is None:
|
||||||
|
raise ValueError("Data not present")
|
||||||
|
data = {}
|
||||||
|
for challenge in self.challenges:
|
||||||
|
validation_data = challenge.get_validation_data(
|
||||||
|
client=client,
|
||||||
|
identifier_type=self.identifier_type,
|
||||||
|
identifier=self.identifier,
|
||||||
|
)
|
||||||
|
if validation_data is not None:
|
||||||
|
data[challenge.type] = validation_data
|
||||||
|
return data
|
||||||
|
|
||||||
|
def get_error_details(self) -> str | None:
|
||||||
|
error_details = []
|
||||||
|
for challenge in self.challenges:
|
||||||
|
if challenge.status == "invalid":
|
||||||
|
msg = f"Challenge {challenge.type}"
|
||||||
|
if "error" in challenge.data:
|
||||||
|
problem = format_error_problem(
|
||||||
|
challenge.data["error"],
|
||||||
|
subproblem_prefix=f"{challenge.type}.",
|
||||||
|
)
|
||||||
|
msg = f"{msg}: {problem}"
|
||||||
|
error_details.append(msg)
|
||||||
|
return "; ".join(error_details) if error_details else None
|
||||||
|
|
||||||
|
def raise_error(self, *, error_msg: str, module: AnsibleModule) -> t.NoReturn:
|
||||||
|
"""
|
||||||
|
Aborts with a specific error for a challenge.
|
||||||
|
"""
|
||||||
|
error_details = self.get_error_details()
|
||||||
|
error_details_str = f" {error_details}" if error_details else ""
|
||||||
|
raise ACMEProtocolException(
|
||||||
|
module=module,
|
||||||
|
msg=f"Failed to validate challenge for {self.combined_identifier}: {error_msg}.{error_details_str}",
|
||||||
|
extras={
|
||||||
|
"identifier": self.combined_identifier,
|
||||||
|
"authorization": self.data,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
def find_challenge(self, *, challenge_type: str) -> Challenge | None:
|
||||||
|
for challenge in self.challenges:
|
||||||
|
if challenge_type == challenge.type:
|
||||||
|
return challenge
|
||||||
|
return None
|
||||||
|
|
||||||
|
def wait_for_validation(self, *, client: ACMEClient) -> bool:
|
||||||
|
while True:
|
||||||
|
self.refresh(client=client)
|
||||||
|
if self.status in ["valid", "invalid", "revoked"]:
|
||||||
|
break
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
if self.status == "invalid":
|
||||||
|
self.raise_error(error_msg='Status is "invalid"', module=client.module)
|
||||||
|
|
||||||
|
return self.status == "valid"
|
||||||
|
|
||||||
|
def call_validate(
|
||||||
|
self, *, client: ACMEClient, challenge_type: str, wait: bool = True
|
||||||
|
) -> bool:
|
||||||
|
"""
|
||||||
|
Validate the authorization provided in the auth dict. Returns True
|
||||||
|
when the validation was successful and False when it was not.
|
||||||
|
"""
|
||||||
|
challenge = self.find_challenge(challenge_type=challenge_type)
|
||||||
|
if challenge is None:
|
||||||
|
raise ModuleFailException(
|
||||||
|
f'Found no challenge of type "{challenge_type}" for identifier {self.combined_identifier}!'
|
||||||
|
)
|
||||||
|
|
||||||
|
challenge.call_validate(client)
|
||||||
|
|
||||||
|
if not wait:
|
||||||
|
return self.status == "valid"
|
||||||
|
return self.wait_for_validation(client=client)
|
||||||
|
|
||||||
|
def can_deactivate(self) -> bool:
|
||||||
|
"""
|
||||||
|
Deactivates this authorization.
|
||||||
|
https://community.letsencrypt.org/t/authorization-deactivation/19860/2
|
||||||
|
https://tools.ietf.org/html/rfc8555#section-7.5.2
|
||||||
|
"""
|
||||||
|
return self.status in ("valid", "pending")
|
||||||
|
|
||||||
|
def is_in_final_state(self, *, allow_valid: bool = True) -> bool:
|
||||||
|
if allow_valid and self.status == "valid":
|
||||||
|
return True
|
||||||
|
return self.status in ("invalid", "revoked", "deactivated", "expired")
|
||||||
|
|
||||||
|
def deactivate(self, *, client: ACMEClient) -> bool | None:
|
||||||
|
"""
|
||||||
|
Deactivates this authorization.
|
||||||
|
https://community.letsencrypt.org/t/authorization-deactivation/19860/2
|
||||||
|
https://tools.ietf.org/html/rfc8555#section-7.5.2
|
||||||
|
"""
|
||||||
|
if not self.can_deactivate():
|
||||||
|
return None
|
||||||
|
authz_deactivate = {"status": "deactivated"}
|
||||||
|
result, info = client.send_signed_request(
|
||||||
|
self.url, authz_deactivate, fail_on_error=False
|
||||||
|
)
|
||||||
|
if 200 <= info["status"] < 300 and isinstance(result, dict):
|
||||||
|
self._setup(client=client, data=result)
|
||||||
|
return self.status == "deactivated"
|
||||||
|
return False
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def deactivate_url(
|
||||||
|
cls: type[_Authorization], *, client: ACMEClient, url: str
|
||||||
|
) -> _Authorization:
|
||||||
|
"""
|
||||||
|
Deactivates this authorization.
|
||||||
|
https://community.letsencrypt.org/t/authorization-deactivation/19860/2
|
||||||
|
https://tools.ietf.org/html/rfc8555#section-7.5.2
|
||||||
|
"""
|
||||||
|
authz = cls(url=url)
|
||||||
|
authz_deactivate = {"status": "deactivated"}
|
||||||
|
result, _info = client.send_signed_request(
|
||||||
|
url, authz_deactivate, fail_on_error=True
|
||||||
|
)
|
||||||
|
if not isinstance(result, dict):
|
||||||
|
raise ACMEProtocolException(
|
||||||
|
module=client.module,
|
||||||
|
msg="Unexpected challenge deactivation result",
|
||||||
|
content_json=result,
|
||||||
|
)
|
||||||
|
authz._setup(client=client, data=result)
|
||||||
|
return authz
|
||||||
|
|
||||||
|
|
||||||
|
def wait_for_validation(
|
||||||
|
*, authzs: t.Iterable[Authorization], client: ACMEClient
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Wait until a list of authz is valid. Fail if at least one of them is invalid or revoked.
|
||||||
|
"""
|
||||||
|
while authzs:
|
||||||
|
authzs_next = []
|
||||||
|
for authz in authzs:
|
||||||
|
authz.refresh(client=client)
|
||||||
|
if authz.status in ["valid", "invalid", "revoked"]:
|
||||||
|
if authz.status != "valid":
|
||||||
|
authz.raise_error(
|
||||||
|
error_msg='Status is not "valid"', module=client.module
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
authzs_next.append(authz)
|
||||||
|
if authzs_next:
|
||||||
|
time.sleep(2)
|
||||||
|
authzs = authzs_next
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = (
|
||||||
|
"Authorization",
|
||||||
|
"Challenge",
|
||||||
|
"combine_identifier",
|
||||||
|
"create_key_authorization",
|
||||||
|
"normalize_combined_identifier",
|
||||||
|
"split_identifier",
|
||||||
|
"wait_for_validation",
|
||||||
|
)
|
||||||
194
plugins/module_utils/_acme/errors.py
Normal file
194
plugins/module_utils/_acme/errors.py
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
# Copyright (c) 2016 Michael Gruener <michael.gruener@chaosmoon.net>
|
||||||
|
# Copyright (c) 2021 Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import typing as t
|
||||||
|
from http.client import responses as http_responses
|
||||||
|
|
||||||
|
from ansible.module_utils.common.text.converters import to_text
|
||||||
|
|
||||||
|
if t.TYPE_CHECKING:
|
||||||
|
import http.client # pragma: no cover
|
||||||
|
import urllib.error # pragma: no cover
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule # pragma: no cover
|
||||||
|
|
||||||
|
|
||||||
|
def format_http_status(status_code: int) -> str:
|
||||||
|
expl = http_responses.get(status_code)
|
||||||
|
if not expl:
|
||||||
|
return str(status_code)
|
||||||
|
return f"{status_code} {expl}"
|
||||||
|
|
||||||
|
|
||||||
|
def format_error_problem(
|
||||||
|
problem: dict[str, t.Any], *, subproblem_prefix: str = ""
|
||||||
|
) -> str:
|
||||||
|
error_type = problem.get(
|
||||||
|
"type", "about:blank"
|
||||||
|
) # https://www.rfc-editor.org/rfc/rfc7807#section-3.1
|
||||||
|
if "title" in problem:
|
||||||
|
msg = f'Error "{problem["title"]}" ({error_type})'
|
||||||
|
else:
|
||||||
|
msg = f"Error {error_type}"
|
||||||
|
if "detail" in problem:
|
||||||
|
msg += f': "{problem["detail"]}"'
|
||||||
|
subproblems = problem.get("subproblems")
|
||||||
|
if subproblems is not None:
|
||||||
|
msg = f"{msg} Subproblems:"
|
||||||
|
for index, subproblem in enumerate(subproblems):
|
||||||
|
index_str = f"{subproblem_prefix}{index}"
|
||||||
|
subproblem_str = format_error_problem(
|
||||||
|
subproblem, subproblem_prefix=f"{index_str}."
|
||||||
|
)
|
||||||
|
msg = f"{msg}\n({index_str}) {subproblem_str}"
|
||||||
|
return msg
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleFailException(Exception):
|
||||||
|
"""
|
||||||
|
If raised, module.fail_json() will be called with the given parameters after cleanup.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, msg: str, **args: t.Any) -> None:
|
||||||
|
super().__init__(self, msg)
|
||||||
|
self.msg = msg
|
||||||
|
self.module_fail_args = args
|
||||||
|
|
||||||
|
def do_fail(self, *, module: AnsibleModule, **arguments: t.Any) -> t.NoReturn:
|
||||||
|
module.fail_json(msg=self.msg, other=self.module_fail_args, **arguments)
|
||||||
|
|
||||||
|
|
||||||
|
class ACMEProtocolException(ModuleFailException):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
module: AnsibleModule,
|
||||||
|
msg: str | None = None,
|
||||||
|
info: dict[str, t.Any] | None = None,
|
||||||
|
response: urllib.error.HTTPError | http.client.HTTPResponse | None = None,
|
||||||
|
content: bytes | None = None,
|
||||||
|
content_json: object | bytes | None = None,
|
||||||
|
extras: dict[str, t.Any] | None = None,
|
||||||
|
) -> None:
|
||||||
|
# Try to get hold of content, if response is given and content is not provided
|
||||||
|
if content is None and content_json is None and response is not None:
|
||||||
|
try:
|
||||||
|
# In Python 2, reading from a closed response yields a TypeError.
|
||||||
|
# In Python 3, read() simply returns ''
|
||||||
|
if response.closed:
|
||||||
|
raise TypeError
|
||||||
|
content = response.read()
|
||||||
|
except (AttributeError, TypeError):
|
||||||
|
if info is not None:
|
||||||
|
content = info.pop("body", None)
|
||||||
|
|
||||||
|
# Make sure that content_json is None or a dictionary
|
||||||
|
content_json_json: dict[str, t.Any] | None = None
|
||||||
|
if content_json is not None and not isinstance(content_json, dict):
|
||||||
|
if content is None and isinstance(content_json, bytes):
|
||||||
|
content = content_json
|
||||||
|
content_json = None
|
||||||
|
elif content_json is not None:
|
||||||
|
content_json_json = content_json.copy()
|
||||||
|
|
||||||
|
# Try to get hold of JSON decoded content, when content is given and JSON not provided
|
||||||
|
if content_json_json is None and content is not None and module is not None:
|
||||||
|
try:
|
||||||
|
cjj = module.from_json(to_text(content))
|
||||||
|
if isinstance(cjj, dict):
|
||||||
|
content_json_json = cjj
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
extras = extras or {}
|
||||||
|
error_code = None
|
||||||
|
error_type = None
|
||||||
|
|
||||||
|
if msg is None:
|
||||||
|
msg = "ACME request failed"
|
||||||
|
add_msg = ""
|
||||||
|
|
||||||
|
if info is not None:
|
||||||
|
url = info["url"]
|
||||||
|
code = info["status"]
|
||||||
|
extras["http_url"] = url
|
||||||
|
extras["http_status"] = code
|
||||||
|
error_code = code
|
||||||
|
if (
|
||||||
|
code is not None
|
||||||
|
and code >= 400
|
||||||
|
and content_json_json is not None
|
||||||
|
and "type" in content_json_json
|
||||||
|
):
|
||||||
|
error_type = content_json_json["type"]
|
||||||
|
if (
|
||||||
|
"status" in content_json_json
|
||||||
|
and content_json_json["status"] != code
|
||||||
|
):
|
||||||
|
code_msg = f"status {content_json_json['status']} (HTTP status: {format_http_status(code)})"
|
||||||
|
else:
|
||||||
|
code_msg = f"status {format_http_status(code)}"
|
||||||
|
if code == -1 and info.get("msg"):
|
||||||
|
code_msg = f"error: {info['msg']}"
|
||||||
|
subproblems = content_json_json.pop("subproblems", None)
|
||||||
|
add_msg = f" {format_error_problem(content_json_json)}."
|
||||||
|
extras["problem"] = content_json_json
|
||||||
|
extras["subproblems"] = subproblems or []
|
||||||
|
if subproblems is not None:
|
||||||
|
add_msg = f"{add_msg} Subproblems:"
|
||||||
|
for index, problem in enumerate(subproblems):
|
||||||
|
problem = format_error_problem(
|
||||||
|
problem, subproblem_prefix=f"{index}."
|
||||||
|
)
|
||||||
|
add_msg = f"{add_msg}\n({index}) {problem}."
|
||||||
|
else:
|
||||||
|
code_msg = f"HTTP status {format_http_status(code)}"
|
||||||
|
if code == -1 and info.get("msg"):
|
||||||
|
code_msg = f"error: {info['msg']}"
|
||||||
|
if content_json_json is not None:
|
||||||
|
add_msg = f" The JSON error result: {content_json_json}"
|
||||||
|
elif content is not None:
|
||||||
|
add_msg = f" The raw error result: {to_text(content)}"
|
||||||
|
msg = f"{msg} for {url} with {code_msg}"
|
||||||
|
elif content_json_json is not None:
|
||||||
|
add_msg = f" The JSON result: {content_json_json}"
|
||||||
|
elif content is not None:
|
||||||
|
add_msg = f" The raw result: {to_text(content)}"
|
||||||
|
|
||||||
|
super().__init__(f"{msg}.{add_msg}", **extras)
|
||||||
|
self.problem: dict[str, t.Any] = {}
|
||||||
|
self.subproblems: list[dict[str, t.Any]] = []
|
||||||
|
self.error_code = error_code
|
||||||
|
self.error_type = error_type
|
||||||
|
for k, v in extras.items():
|
||||||
|
setattr(self, k, v)
|
||||||
|
|
||||||
|
|
||||||
|
class BackendException(ModuleFailException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class NetworkException(ModuleFailException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class KeyParsingError(ModuleFailException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = (
|
||||||
|
"ACMEProtocolException",
|
||||||
|
"BackendException",
|
||||||
|
"KeyParsingError",
|
||||||
|
"ModuleFailException",
|
||||||
|
"NetworkException",
|
||||||
|
"format_error_problem",
|
||||||
|
"format_http_status",
|
||||||
|
)
|
||||||
101
plugins/module_utils/_acme/io.py
Normal file
101
plugins/module_utils/_acme/io.py
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
# Copyright (c) 2013, Romeo Theriault <romeot () hawaii.edu>
|
||||||
|
# Copyright (c) 2016 Michael Gruener <michael.gruener@chaosmoon.net>
|
||||||
|
# Copyright (c) 2021 Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
import traceback
|
||||||
|
import typing as t
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.errors import (
|
||||||
|
ModuleFailException,
|
||||||
|
)
|
||||||
|
|
||||||
|
if t.TYPE_CHECKING:
|
||||||
|
from ansible.module_utils.basic import AnsibleModule # pragma: no cover
|
||||||
|
|
||||||
|
|
||||||
|
def read_file(fn: str | os.PathLike) -> bytes:
|
||||||
|
try:
|
||||||
|
with open(fn, "rb") as f:
|
||||||
|
return f.read()
|
||||||
|
except Exception as e:
|
||||||
|
raise ModuleFailException(f'Error while reading file "{fn}": {e}') from e
|
||||||
|
|
||||||
|
|
||||||
|
# This function was adapted from an earlier version of https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/uri.py
|
||||||
|
def write_file(
|
||||||
|
*, module: AnsibleModule, dest: str | os.PathLike[str], content: bytes
|
||||||
|
) -> bool:
|
||||||
|
"""
|
||||||
|
Write content to destination file dest, only if the content
|
||||||
|
has changed.
|
||||||
|
"""
|
||||||
|
changed = False
|
||||||
|
# create a tempfile
|
||||||
|
fd, tmpsrc = tempfile.mkstemp(text=False)
|
||||||
|
f = os.fdopen(fd, "wb")
|
||||||
|
try:
|
||||||
|
f.write(content)
|
||||||
|
except Exception as err:
|
||||||
|
try:
|
||||||
|
f.close()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
os.remove(tmpsrc)
|
||||||
|
raise ModuleFailException(
|
||||||
|
f"failed to create temporary content file: {err}",
|
||||||
|
exception=traceback.format_exc(),
|
||||||
|
) from err
|
||||||
|
f.close()
|
||||||
|
checksum_src = None
|
||||||
|
checksum_dest = None
|
||||||
|
# raise an error if there is no tmpsrc file
|
||||||
|
if not os.path.exists(tmpsrc):
|
||||||
|
try:
|
||||||
|
os.remove(tmpsrc)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
raise ModuleFailException(f"Source {tmpsrc} does not exist")
|
||||||
|
if not os.access(tmpsrc, os.R_OK):
|
||||||
|
os.remove(tmpsrc)
|
||||||
|
raise ModuleFailException(f"Source {tmpsrc} not readable")
|
||||||
|
checksum_src = module.sha1(tmpsrc)
|
||||||
|
# check if there is no dest file
|
||||||
|
if os.path.exists(dest):
|
||||||
|
# raise an error if copy has no permission on dest
|
||||||
|
if not os.access(dest, os.W_OK):
|
||||||
|
os.remove(tmpsrc)
|
||||||
|
raise ModuleFailException(f"Destination {dest} not writable")
|
||||||
|
if not os.access(dest, os.R_OK):
|
||||||
|
os.remove(tmpsrc)
|
||||||
|
raise ModuleFailException(f"Destination {dest} not readable")
|
||||||
|
checksum_dest = module.sha1(str(dest))
|
||||||
|
else:
|
||||||
|
dirname = os.path.dirname(dest) or "."
|
||||||
|
if not os.access(dirname, os.W_OK):
|
||||||
|
os.remove(tmpsrc)
|
||||||
|
raise ModuleFailException(f"Destination dir {dirname} not writable")
|
||||||
|
if checksum_src != checksum_dest:
|
||||||
|
try:
|
||||||
|
shutil.copyfile(tmpsrc, dest)
|
||||||
|
changed = True
|
||||||
|
except Exception as err:
|
||||||
|
os.remove(tmpsrc)
|
||||||
|
raise ModuleFailException(
|
||||||
|
f"failed to copy {tmpsrc} to {dest}: {err}",
|
||||||
|
exception=traceback.format_exc(),
|
||||||
|
) from err
|
||||||
|
os.remove(tmpsrc)
|
||||||
|
return changed
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ("read_file", "write_file")
|
||||||
244
plugins/module_utils/_acme/orders.py
Normal file
244
plugins/module_utils/_acme/orders.py
Normal file
@@ -0,0 +1,244 @@
|
|||||||
|
# Copyright (c) 2016 Michael Gruener <michael.gruener@chaosmoon.net>
|
||||||
|
# Copyright (c) 2021 Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import time
|
||||||
|
import typing as t
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.challenges import (
|
||||||
|
Authorization,
|
||||||
|
normalize_combined_identifier,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.errors import (
|
||||||
|
ACMEProtocolException,
|
||||||
|
ModuleFailException,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.utils import (
|
||||||
|
nopad_b64,
|
||||||
|
)
|
||||||
|
|
||||||
|
if t.TYPE_CHECKING:
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.acme import ( # pragma: no cover
|
||||||
|
ACMEClient,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
_Order = t.TypeVar("_Order", bound="Order")
|
||||||
|
|
||||||
|
|
||||||
|
class Order:
|
||||||
|
def __init__(self, *, url: str) -> None:
|
||||||
|
self.url = url
|
||||||
|
|
||||||
|
self.data: dict[str, t.Any] | None = None
|
||||||
|
|
||||||
|
self.status: str | None = None
|
||||||
|
self.identifiers: list[tuple[str, str]] = []
|
||||||
|
self.replaces_cert_id: str | None = None
|
||||||
|
self.finalize_uri: str | None = None
|
||||||
|
self.certificate_uri: str | None = None
|
||||||
|
self.authorization_uris: list[str] = []
|
||||||
|
self.authorizations: dict[str, Authorization] = {}
|
||||||
|
|
||||||
|
def _setup(self, *, client: ACMEClient, data: dict[str, t.Any]) -> None:
|
||||||
|
self.data = data
|
||||||
|
|
||||||
|
self.status = data["status"]
|
||||||
|
self.identifiers = []
|
||||||
|
for identifier in data["identifiers"]:
|
||||||
|
self.identifiers.append((identifier["type"], identifier["value"]))
|
||||||
|
self.replaces_cert_id = data.get("replaces")
|
||||||
|
self.finalize_uri = data.get("finalize")
|
||||||
|
self.certificate_uri = data.get("certificate")
|
||||||
|
self.authorization_uris = data["authorizations"]
|
||||||
|
self.authorizations = {}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_json(
|
||||||
|
cls: type[_Order], *, client: ACMEClient, data: dict[str, t.Any], url: str
|
||||||
|
) -> _Order:
|
||||||
|
result = cls(url=url)
|
||||||
|
result._setup(client=client, data=data)
|
||||||
|
return result
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_url(cls: type[_Order], *, client: ACMEClient, url: str) -> _Order:
|
||||||
|
result = cls(url=url)
|
||||||
|
result.refresh(client=client)
|
||||||
|
return result
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def create(
|
||||||
|
cls: type[_Order],
|
||||||
|
*,
|
||||||
|
client: ACMEClient,
|
||||||
|
identifiers: list[tuple[str, str]],
|
||||||
|
replaces_cert_id: str | None = None,
|
||||||
|
profile: str | None = None,
|
||||||
|
) -> _Order:
|
||||||
|
"""
|
||||||
|
Start a new certificate order (ACME v2 protocol).
|
||||||
|
https://tools.ietf.org/html/rfc8555#section-7.4
|
||||||
|
"""
|
||||||
|
acme_identifiers = []
|
||||||
|
for identifier_type, identifier in identifiers:
|
||||||
|
acme_identifiers.append(
|
||||||
|
{
|
||||||
|
"type": identifier_type,
|
||||||
|
"value": identifier,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
new_order: dict[str, t.Any] = {"identifiers": acme_identifiers}
|
||||||
|
if replaces_cert_id is not None:
|
||||||
|
new_order["replaces"] = replaces_cert_id
|
||||||
|
if profile is not None:
|
||||||
|
new_order["profile"] = profile
|
||||||
|
result, info = client.send_signed_request(
|
||||||
|
client.directory["newOrder"],
|
||||||
|
new_order,
|
||||||
|
error_msg="Failed to start new order",
|
||||||
|
expected_status_codes=[201],
|
||||||
|
)
|
||||||
|
if not isinstance(result, dict):
|
||||||
|
raise ACMEProtocolException(
|
||||||
|
module=client.module,
|
||||||
|
msg="Unexpected new order response",
|
||||||
|
content_json=result,
|
||||||
|
)
|
||||||
|
return cls.from_json(client=client, data=result, url=info["location"])
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def create_with_error_handling(
|
||||||
|
cls: type[_Order],
|
||||||
|
*,
|
||||||
|
client: ACMEClient,
|
||||||
|
identifiers: list[tuple[str, str]],
|
||||||
|
error_strategy: t.Literal[
|
||||||
|
"auto", "fail", "always", "retry_without_replaces_cert_id"
|
||||||
|
] = "auto",
|
||||||
|
error_max_retries: int = 3,
|
||||||
|
replaces_cert_id: str | None = None,
|
||||||
|
profile: str | None = None,
|
||||||
|
message_callback: Callable[[str], None] | None = None,
|
||||||
|
) -> _Order:
|
||||||
|
"""
|
||||||
|
error_strategy can be one of the following strings:
|
||||||
|
|
||||||
|
* ``fail``: simply fail. (Same behavior as ``Order.create()``.)
|
||||||
|
* ``retry_without_replaces_cert_id``: if ``replaces_cert_id`` is not ``None``, set it to ``None`` and retry.
|
||||||
|
The only exception is an error of type ``urn:ietf:params:acme:error:alreadyReplaced``, that indicates that
|
||||||
|
the certificate was already replaced.
|
||||||
|
* ``auto``: try to be clever. Right now this is identical to ``retry_without_replaces_cert_id``, but that can
|
||||||
|
change at any time in the future.
|
||||||
|
* ``always``: always retry until ``error_max_retries`` has been reached.
|
||||||
|
"""
|
||||||
|
tries = 0
|
||||||
|
while True:
|
||||||
|
tries += 1
|
||||||
|
try:
|
||||||
|
return cls.create(
|
||||||
|
client=client,
|
||||||
|
identifiers=identifiers,
|
||||||
|
replaces_cert_id=replaces_cert_id,
|
||||||
|
profile=profile,
|
||||||
|
)
|
||||||
|
except ACMEProtocolException as exc:
|
||||||
|
if tries <= error_max_retries + 1 and error_strategy != "fail":
|
||||||
|
if error_strategy == "always":
|
||||||
|
continue
|
||||||
|
|
||||||
|
if (
|
||||||
|
error_strategy in ("auto", "retry_without_replaces_cert_id")
|
||||||
|
and replaces_cert_id is not None
|
||||||
|
and not (
|
||||||
|
exc.error_code == 409
|
||||||
|
and exc.error_type
|
||||||
|
== "urn:ietf:params:acme:error:alreadyReplaced"
|
||||||
|
)
|
||||||
|
):
|
||||||
|
if message_callback:
|
||||||
|
message_callback(
|
||||||
|
f"Stop passing `replaces={replaces_cert_id}` due to error {exc.error_code} {exc.error_type} when creating ACME order"
|
||||||
|
)
|
||||||
|
replaces_cert_id = None
|
||||||
|
continue
|
||||||
|
|
||||||
|
raise
|
||||||
|
|
||||||
|
def refresh(self, *, client: ACMEClient) -> bool:
|
||||||
|
result, info = client.get_request(self.url)
|
||||||
|
if not isinstance(result, dict):
|
||||||
|
raise ACMEProtocolException(
|
||||||
|
module=client.module,
|
||||||
|
msg="Unexpected authorization data",
|
||||||
|
info=info,
|
||||||
|
content_json=result,
|
||||||
|
)
|
||||||
|
changed = self.data != result
|
||||||
|
self._setup(client=client, data=result)
|
||||||
|
return changed
|
||||||
|
|
||||||
|
def load_authorizations(self, *, client: ACMEClient) -> None:
|
||||||
|
for auth_uri in self.authorization_uris:
|
||||||
|
authz = Authorization.from_url(client=client, url=auth_uri)
|
||||||
|
self.authorizations[
|
||||||
|
normalize_combined_identifier(authz.combined_identifier)
|
||||||
|
] = authz
|
||||||
|
|
||||||
|
def wait_for_finalization(self, *, client: ACMEClient) -> None:
|
||||||
|
while True:
|
||||||
|
self.refresh(client=client)
|
||||||
|
if self.status in ["valid", "invalid", "pending", "ready"]:
|
||||||
|
break
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
if self.status != "valid":
|
||||||
|
raise ACMEProtocolException(
|
||||||
|
module=client.module,
|
||||||
|
msg=f'Failed to wait for order to complete; got status "{self.status}"',
|
||||||
|
content_json=self.data,
|
||||||
|
)
|
||||||
|
|
||||||
|
def finalize(
|
||||||
|
self, *, client: ACMEClient, csr_der: bytes, wait: bool = True
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Create a new certificate based on the csr.
|
||||||
|
Return the certificate object as dict
|
||||||
|
https://tools.ietf.org/html/rfc8555#section-7.4
|
||||||
|
"""
|
||||||
|
if self.finalize_uri is None:
|
||||||
|
raise ModuleFailException("finalize_uri must be set")
|
||||||
|
new_cert = {
|
||||||
|
"csr": nopad_b64(csr_der),
|
||||||
|
}
|
||||||
|
result, info = client.send_signed_request(
|
||||||
|
self.finalize_uri,
|
||||||
|
new_cert,
|
||||||
|
error_msg="Failed to finalizing order",
|
||||||
|
expected_status_codes=[200],
|
||||||
|
)
|
||||||
|
# It is not clear from the RFC whether the finalize call returns the order object or not.
|
||||||
|
# Instead of using the result, we call self.refresh(client) below.
|
||||||
|
|
||||||
|
if wait:
|
||||||
|
self.wait_for_finalization(client=client)
|
||||||
|
else:
|
||||||
|
self.refresh(client=client)
|
||||||
|
if self.status not in ["procesing", "valid", "invalid"]:
|
||||||
|
raise ACMEProtocolException(
|
||||||
|
module=client.module,
|
||||||
|
msg=f'Failed to finalize order; got status "{self.status}"',
|
||||||
|
info=info,
|
||||||
|
content_json=result,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ("Order",)
|
||||||
173
plugins/module_utils/_acme/utils.py
Normal file
173
plugins/module_utils/_acme/utils.py
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
# Copyright (c) 2016 Michael Gruener <michael.gruener@chaosmoon.net>
|
||||||
|
# Copyright (c) 2021 Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import base64
|
||||||
|
import datetime
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import textwrap
|
||||||
|
import traceback
|
||||||
|
import typing as t
|
||||||
|
from collections.abc import Callable
|
||||||
|
from urllib.parse import unquote
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.errors import (
|
||||||
|
ModuleFailException,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto.math import (
|
||||||
|
convert_int_to_bytes,
|
||||||
|
)
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._time import (
|
||||||
|
get_now_datetime,
|
||||||
|
)
|
||||||
|
|
||||||
|
if t.TYPE_CHECKING:
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._acme.backends import ( # pragma: no cover
|
||||||
|
CertificateInformation,
|
||||||
|
CryptoBackend,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def nopad_b64(data: bytes) -> str:
|
||||||
|
return base64.urlsafe_b64encode(data).decode("utf8").replace("=", "")
|
||||||
|
|
||||||
|
|
||||||
|
def der_to_pem(der_cert: bytes) -> str:
|
||||||
|
"""
|
||||||
|
Convert the DER format certificate in der_cert to a PEM format certificate and return it.
|
||||||
|
"""
|
||||||
|
content = "\n".join(textwrap.wrap(base64.b64encode(der_cert).decode("utf8"), 64))
|
||||||
|
return f"-----BEGIN CERTIFICATE-----\n{content}\n-----END CERTIFICATE-----\n"
|
||||||
|
|
||||||
|
|
||||||
|
def pem_to_der(
|
||||||
|
*, pem_filename: str | os.PathLike | None = None, pem_content: str | None = None
|
||||||
|
) -> bytes:
|
||||||
|
"""
|
||||||
|
Load PEM file, or use PEM file's content, and convert to DER.
|
||||||
|
|
||||||
|
If PEM contains multiple entities, the first entity will be used.
|
||||||
|
"""
|
||||||
|
certificate_lines = []
|
||||||
|
if pem_content is not None:
|
||||||
|
lines = pem_content.splitlines()
|
||||||
|
elif pem_filename is not None:
|
||||||
|
try:
|
||||||
|
with open(pem_filename, "r", encoding="utf-8") as f:
|
||||||
|
lines = list(f)
|
||||||
|
except Exception as err:
|
||||||
|
raise ModuleFailException(
|
||||||
|
f"cannot load PEM file {pem_filename}: {err}",
|
||||||
|
exception=traceback.format_exc(),
|
||||||
|
) from err
|
||||||
|
else:
|
||||||
|
raise ModuleFailException(
|
||||||
|
"One of pem_filename and pem_content must be provided"
|
||||||
|
)
|
||||||
|
header_line_count = 0
|
||||||
|
for line in lines:
|
||||||
|
if line.startswith("-----"):
|
||||||
|
header_line_count += 1
|
||||||
|
if header_line_count == 2:
|
||||||
|
# If certificate file contains other certs appended
|
||||||
|
# (like intermediate certificates), ignore these.
|
||||||
|
break
|
||||||
|
continue
|
||||||
|
certificate_lines.append(line.strip())
|
||||||
|
return base64.b64decode("".join(certificate_lines))
|
||||||
|
|
||||||
|
|
||||||
|
def process_links(
|
||||||
|
*, info: dict[str, t.Any], callback: Callable[[str, str], None]
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Process link header, calls callback for every link header with the URL and relation as options.
|
||||||
|
|
||||||
|
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link
|
||||||
|
"""
|
||||||
|
if "link" in info:
|
||||||
|
link = info["link"]
|
||||||
|
for url, relation in re.findall(r'<([^>]+)>;\s*rel="(\w+)"', link):
|
||||||
|
callback(unquote(url), relation)
|
||||||
|
|
||||||
|
|
||||||
|
def parse_retry_after(
|
||||||
|
value: str,
|
||||||
|
*,
|
||||||
|
relative_with_timezone: bool = True,
|
||||||
|
now: datetime.datetime | None = None,
|
||||||
|
) -> datetime.datetime:
|
||||||
|
"""
|
||||||
|
Parse the value of a Retry-After header and return a timestamp.
|
||||||
|
|
||||||
|
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
|
||||||
|
"""
|
||||||
|
# First try a number of seconds
|
||||||
|
try:
|
||||||
|
delta = datetime.timedelta(seconds=int(value))
|
||||||
|
if now is None:
|
||||||
|
now = get_now_datetime(with_timezone=relative_with_timezone)
|
||||||
|
return now + delta
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
return datetime.datetime.strptime(value, "%a, %d %b %Y %H:%M:%S GMT")
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
raise ValueError(f"Cannot parse Retry-After header value {repr(value)}")
|
||||||
|
|
||||||
|
|
||||||
|
def compute_cert_id(
|
||||||
|
*,
|
||||||
|
backend: CryptoBackend,
|
||||||
|
cert_info: CertificateInformation | None = None,
|
||||||
|
cert_filename: str | os.PathLike | None = None,
|
||||||
|
cert_content: str | bytes | None = None,
|
||||||
|
none_if_required_information_is_missing: bool = False,
|
||||||
|
) -> str | None:
|
||||||
|
# Obtain certificate info if not provided
|
||||||
|
if cert_info is None:
|
||||||
|
cert_info = backend.get_cert_information(
|
||||||
|
cert_filename=cert_filename, cert_content=cert_content
|
||||||
|
)
|
||||||
|
|
||||||
|
# Convert Authority Key Identifier to string
|
||||||
|
if cert_info.authority_key_identifier is None:
|
||||||
|
if none_if_required_information_is_missing:
|
||||||
|
return None
|
||||||
|
raise ModuleFailException(
|
||||||
|
"Certificate has no Authority Key Identifier extension"
|
||||||
|
)
|
||||||
|
aki = (
|
||||||
|
(base64.urlsafe_b64encode(cert_info.authority_key_identifier))
|
||||||
|
.decode("ascii")
|
||||||
|
.replace("=", "")
|
||||||
|
)
|
||||||
|
|
||||||
|
# Convert serial number to string
|
||||||
|
serial_bytes = convert_int_to_bytes(cert_info.serial_number)
|
||||||
|
if ord(serial_bytes[:1]) >= 128:
|
||||||
|
serial_bytes = b"\x00" + serial_bytes
|
||||||
|
serial = (base64.urlsafe_b64encode(serial_bytes)).decode("ascii").replace("=", "")
|
||||||
|
|
||||||
|
# Compose cert ID
|
||||||
|
return f"{aki}.{serial}"
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = (
|
||||||
|
"compute_cert_id",
|
||||||
|
"der_to_pem",
|
||||||
|
"nopad_b64",
|
||||||
|
"parse_retry_after",
|
||||||
|
"pem_to_der",
|
||||||
|
"process_links",
|
||||||
|
)
|
||||||
203
plugins/module_utils/_argspec.py
Normal file
203
plugins/module_utils/_argspec.py
Normal file
@@ -0,0 +1,203 @@
|
|||||||
|
# Copyright (c) 2020, Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import typing as t
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
|
if t.TYPE_CHECKING:
|
||||||
|
import datetime # pragma: no cover
|
||||||
|
from collections.abc import Callable, Mapping, Sequence # pragma: no cover
|
||||||
|
|
||||||
|
_T = t.TypeVar("_T") # pragma: no cover
|
||||||
|
|
||||||
|
ArgSpecType = t.Literal[ # pragma: no cover
|
||||||
|
"bits",
|
||||||
|
"bool",
|
||||||
|
"bytes",
|
||||||
|
"dict",
|
||||||
|
"float",
|
||||||
|
"int",
|
||||||
|
"json",
|
||||||
|
"jsonarg",
|
||||||
|
"list",
|
||||||
|
"path",
|
||||||
|
"raw",
|
||||||
|
"sid",
|
||||||
|
"str",
|
||||||
|
]
|
||||||
|
MutuallyExclusiveT = t.Union[ # pragma: no cover # noqa: UP007
|
||||||
|
Sequence[str], Sequence[Sequence[str]]
|
||||||
|
]
|
||||||
|
MutuallyExclusiveMutT = list[Sequence[str]] # pragma: no cover
|
||||||
|
RequiredTogetherT = Sequence[Sequence[str]] # pragma: no cover
|
||||||
|
RequiredTogetherMutT = list[Sequence[str]] # pragma: no cover
|
||||||
|
RequiredOneOfT = Sequence[Sequence[str]] # pragma: no cover
|
||||||
|
RequiredOneOfMutT = list[Sequence[str]] # pragma: no cover
|
||||||
|
RequiredIfT = Sequence[ # pragma: no cover
|
||||||
|
t.Union[ # noqa: UP007
|
||||||
|
list[object],
|
||||||
|
tuple[str, object, Sequence[str]],
|
||||||
|
tuple[str, object, Sequence[str], bool],
|
||||||
|
]
|
||||||
|
]
|
||||||
|
RequiredIfMutT = list[ # pragma: no cover
|
||||||
|
t.Union[ # noqa: UP007
|
||||||
|
list[object],
|
||||||
|
tuple[str, object, Sequence[str]],
|
||||||
|
tuple[str, object, Sequence[str], bool],
|
||||||
|
]
|
||||||
|
]
|
||||||
|
RequiredByT = Mapping[str, Sequence[str]] # pragma: no cover
|
||||||
|
RequiredByMutT = dict[str, Sequence[str]] # pragma: no cover
|
||||||
|
|
||||||
|
class DeprecatedAlias(t.TypedDict): # pragma: no cover
|
||||||
|
name: str
|
||||||
|
date: t.NotRequired[datetime.date | str]
|
||||||
|
version: t.NotRequired[str]
|
||||||
|
collection_name: str
|
||||||
|
|
||||||
|
class OneArgumentSpecT(t.TypedDict): # pragma: no cover
|
||||||
|
type: t.NotRequired[ArgSpecType | Callable[[object], object]]
|
||||||
|
elements: t.NotRequired[ArgSpecType]
|
||||||
|
default: t.NotRequired[object]
|
||||||
|
# For fallback elements, the first element of the sequence has to be a callable, the others sequences or dicts.
|
||||||
|
# Unfortunately there is no way to specify this in a generic way...
|
||||||
|
fallback: t.NotRequired[
|
||||||
|
Sequence[
|
||||||
|
Callable[[object], object] | Sequence[object] | Mapping[str, object]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
choices: t.NotRequired[Sequence[object]]
|
||||||
|
context: t.NotRequired[Mapping[object, object]]
|
||||||
|
required: t.NotRequired[bool]
|
||||||
|
no_log: t.NotRequired[bool]
|
||||||
|
aliases: t.NotRequired[Sequence[str]]
|
||||||
|
apply_defaults: t.NotRequired[bool]
|
||||||
|
removed_in_version: t.NotRequired[str]
|
||||||
|
removed_at_date: t.NotRequired[datetime.date | str]
|
||||||
|
removed_from_collection: t.NotRequired[str]
|
||||||
|
options: t.NotRequired[Mapping[str, OneArgumentSpecT]] # recursive!
|
||||||
|
deprecated_aliases: t.NotRequired[Sequence[DeprecatedAlias]]
|
||||||
|
|
||||||
|
mutually_exclusive: t.NotRequired[MutuallyExclusiveT]
|
||||||
|
required_together: t.NotRequired[RequiredTogetherT]
|
||||||
|
required_one_of: t.NotRequired[RequiredOneOfT]
|
||||||
|
required_if: t.NotRequired[RequiredIfT]
|
||||||
|
required_by: t.NotRequired[RequiredByT]
|
||||||
|
|
||||||
|
ArgumentSpecT = Mapping[str, OneArgumentSpecT] # pragma: no cover
|
||||||
|
ArgumentSpecMutT = dict[str, OneArgumentSpecT] # pragma: no cover
|
||||||
|
|
||||||
|
|
||||||
|
class ArgumentSpec:
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
argument_spec: ArgumentSpecT | None = None,
|
||||||
|
*,
|
||||||
|
required_together: RequiredTogetherT | None = None,
|
||||||
|
required_if: RequiredIfT | None = None,
|
||||||
|
required_one_of: RequiredOneOfT | None = None,
|
||||||
|
mutually_exclusive: MutuallyExclusiveT | None = None,
|
||||||
|
required_by: RequiredByT | None = None,
|
||||||
|
) -> None:
|
||||||
|
self.argument_spec: ArgumentSpecMutT = {}
|
||||||
|
self.required_together: RequiredTogetherMutT = []
|
||||||
|
self.required_if: RequiredIfMutT = []
|
||||||
|
self.required_one_of: RequiredOneOfMutT = []
|
||||||
|
self.mutually_exclusive: MutuallyExclusiveMutT = []
|
||||||
|
self.required_by: RequiredByMutT = {}
|
||||||
|
if argument_spec:
|
||||||
|
self.argument_spec.update(argument_spec)
|
||||||
|
if required_together:
|
||||||
|
self.required_together.extend(required_together)
|
||||||
|
if required_if:
|
||||||
|
self.required_if.extend(required_if)
|
||||||
|
if required_one_of:
|
||||||
|
self.required_one_of.extend(required_one_of)
|
||||||
|
if mutually_exclusive:
|
||||||
|
if all(isinstance(me, str) for me in mutually_exclusive):
|
||||||
|
# mutually_exclusive is a Sequence[str]
|
||||||
|
self.mutually_exclusive.append(mutually_exclusive) # type: ignore
|
||||||
|
else:
|
||||||
|
self.mutually_exclusive.extend(mutually_exclusive)
|
||||||
|
if required_by:
|
||||||
|
self.required_by.update(required_by)
|
||||||
|
|
||||||
|
def update_argspec(self, **kwargs: t.Any) -> t.Self:
|
||||||
|
self.argument_spec.update(kwargs)
|
||||||
|
return self
|
||||||
|
|
||||||
|
def update(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
required_together: RequiredTogetherT | None = None,
|
||||||
|
required_if: RequiredIfT | None = None,
|
||||||
|
required_one_of: RequiredOneOfT | None = None,
|
||||||
|
mutually_exclusive: MutuallyExclusiveT | None = None,
|
||||||
|
required_by: RequiredByT | None = None,
|
||||||
|
) -> t.Self:
|
||||||
|
if mutually_exclusive:
|
||||||
|
self.mutually_exclusive.extend(mutually_exclusive)
|
||||||
|
if required_together:
|
||||||
|
self.required_together.extend(required_together)
|
||||||
|
if required_one_of:
|
||||||
|
self.required_one_of.extend(required_one_of)
|
||||||
|
if required_if:
|
||||||
|
self.required_if.extend(required_if)
|
||||||
|
if required_by:
|
||||||
|
for k, v in required_by.items():
|
||||||
|
if k in self.required_by:
|
||||||
|
v = list(self.required_by[k]) + list(v)
|
||||||
|
self.required_by[k] = v
|
||||||
|
return self
|
||||||
|
|
||||||
|
def merge(self, other: t.Self) -> t.Self:
|
||||||
|
self.update_argspec(**other.argument_spec)
|
||||||
|
self.update(
|
||||||
|
mutually_exclusive=other.mutually_exclusive,
|
||||||
|
required_together=other.required_together,
|
||||||
|
required_one_of=other.required_one_of,
|
||||||
|
required_if=other.required_if,
|
||||||
|
required_by=other.required_by,
|
||||||
|
)
|
||||||
|
return self
|
||||||
|
|
||||||
|
def create_ansible_module_helper(
|
||||||
|
self, clazz: type[_T], args: tuple, **kwargs: t.Any
|
||||||
|
) -> _T:
|
||||||
|
for forbidden_name in (
|
||||||
|
"argument_spec",
|
||||||
|
"mutually_exclusive",
|
||||||
|
"required_together",
|
||||||
|
"required_one_of",
|
||||||
|
"required_if",
|
||||||
|
"required_by",
|
||||||
|
):
|
||||||
|
if forbidden_name in kwargs:
|
||||||
|
raise ValueError(
|
||||||
|
f"You must not provide a {forbidden_name} keyword parameter to create_ansible_module_helper()"
|
||||||
|
)
|
||||||
|
instance = clazz( # type: ignore
|
||||||
|
*args,
|
||||||
|
argument_spec=self.argument_spec,
|
||||||
|
mutually_exclusive=self.mutually_exclusive,
|
||||||
|
required_together=self.required_together,
|
||||||
|
required_one_of=self.required_one_of,
|
||||||
|
required_if=self.required_if,
|
||||||
|
required_by=self.required_by,
|
||||||
|
**kwargs,
|
||||||
|
)
|
||||||
|
return instance
|
||||||
|
|
||||||
|
def create_ansible_module(self, **kwargs: t.Any) -> AnsibleModule:
|
||||||
|
return self.create_ansible_module_helper(AnsibleModule, (), **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ("ArgumentSpec",)
|
||||||
98
plugins/module_utils/_caa.py
Normal file
98
plugins/module_utils/_caa.py
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
# Copyright (c) 2020, Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
_VALUE_RE = re.compile("^[\x21-\x3a\x3c-\x7e]*$")
|
||||||
|
_LABEL_RE = re.compile("^[0-9a-zA-Z][0-9a-zA-Z-]*$")
|
||||||
|
|
||||||
|
|
||||||
|
def _check_value(value: str) -> None:
|
||||||
|
if not _VALUE_RE.match(value):
|
||||||
|
raise ValueError(f"Invalid value {value!r}")
|
||||||
|
|
||||||
|
|
||||||
|
def _check_label(label: str, what: str) -> None:
|
||||||
|
if not _LABEL_RE.match(label):
|
||||||
|
raise ValueError(f"Invalid {what} {label!r}")
|
||||||
|
|
||||||
|
|
||||||
|
def _check_domain_name(value: str) -> None:
|
||||||
|
for p in value.split("."):
|
||||||
|
_check_label(p, "label")
|
||||||
|
|
||||||
|
|
||||||
|
def parse_issue_value(
|
||||||
|
value: str, *, check_for_duplicates: bool = True, strict: bool = True
|
||||||
|
) -> tuple[str | None, list[tuple[str, str]]]:
|
||||||
|
"""
|
||||||
|
Given a CAA issue property, parses it according to the syntax defined in RFC 8659.
|
||||||
|
|
||||||
|
More precisely, see https://www.rfc-editor.org/rfc/rfc8659.html#section-4.2.
|
||||||
|
|
||||||
|
If ``check_for_duplicates == True``, duplicate tags are reported as an error.
|
||||||
|
If ``strict == True``, invalid characters are reported as an error.
|
||||||
|
"""
|
||||||
|
parts = [v.strip(" \t") for v in value.split(";")]
|
||||||
|
if len(parts) > 1 and not parts[-1]:
|
||||||
|
del parts[-1]
|
||||||
|
domain_name = parts[0] or None
|
||||||
|
if domain_name is not None and strict:
|
||||||
|
_check_domain_name(domain_name)
|
||||||
|
pairs = []
|
||||||
|
previous_tags: set[str] = set()
|
||||||
|
for part in parts[1:]:
|
||||||
|
pieces = part.split("=", 1)
|
||||||
|
if len(pieces) != 2:
|
||||||
|
raise ValueError(f"{part!r} is not of the form tag=value")
|
||||||
|
tag, value = pieces[0].rstrip(" \t"), pieces[1].lstrip(" \t")
|
||||||
|
if strict:
|
||||||
|
_check_label(tag, "tag")
|
||||||
|
_check_value(value)
|
||||||
|
pairs.append((tag, value))
|
||||||
|
if check_for_duplicates:
|
||||||
|
if tag in previous_tags:
|
||||||
|
raise ValueError(f"Tag {tag!r} appears multiple times")
|
||||||
|
previous_tags.add(tag)
|
||||||
|
return domain_name, pairs
|
||||||
|
|
||||||
|
|
||||||
|
def join_issue_value(
|
||||||
|
domain_name: str | None,
|
||||||
|
pairs: list[tuple[str, str]],
|
||||||
|
*,
|
||||||
|
check_for_duplicates: bool = True,
|
||||||
|
strict: bool = True,
|
||||||
|
) -> str:
|
||||||
|
"""
|
||||||
|
Given a domain name and a list of tag-value pairs, joins them according
|
||||||
|
to the syntax defined in RFC 8659.
|
||||||
|
|
||||||
|
More precisely, see https://www.rfc-editor.org/rfc/rfc8659.html#section-4.2.
|
||||||
|
|
||||||
|
If ``check_for_duplicates == True``, duplicate tags are reported as an error.
|
||||||
|
If ``strict == True``, invalid characters are reported as an error.
|
||||||
|
"""
|
||||||
|
if domain_name is not None and strict:
|
||||||
|
_check_domain_name(domain_name)
|
||||||
|
parts = [domain_name or ""]
|
||||||
|
previous_tags: set[str] = set()
|
||||||
|
for tag, value in pairs:
|
||||||
|
if strict:
|
||||||
|
_check_label(tag, "tag")
|
||||||
|
_check_value(value)
|
||||||
|
parts.append(f"{tag}={value}")
|
||||||
|
if check_for_duplicates:
|
||||||
|
if tag in previous_tags:
|
||||||
|
raise ValueError(f"Tag {tag!r} appears multiple times")
|
||||||
|
previous_tags.add(tag)
|
||||||
|
return "; ".join(parts)
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ("parse_issue_value",)
|
||||||
175
plugins/module_utils/_crypto/_asn1.py
Normal file
175
plugins/module_utils/_crypto/_asn1.py
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
# Copyright (c) 2020, Jordan Borean <jborean93@gmail.com>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import enum
|
||||||
|
import re
|
||||||
|
|
||||||
|
from ansible.module_utils.common.text.converters import to_bytes
|
||||||
|
|
||||||
|
# An ASN.1 serialized as a string in the OpenSSL format:
|
||||||
|
# [modifier,]type[:value]
|
||||||
|
#
|
||||||
|
# 'modifier':
|
||||||
|
# The modifier can be 'IMPLICIT:<tag_number><tag_class>,' or 'EXPLICIT:<tag_number><tag_class>' where IMPLICIT
|
||||||
|
# changes the tag of the universal value to encode and EXPLICIT prefixes its tag to the existing universal value.
|
||||||
|
# The tag_number must be set while the tag_class can be 'U', 'A', 'P', or 'C" for 'Universal', 'Application',
|
||||||
|
# 'Private', or 'Context Specific' with C being the default.
|
||||||
|
#
|
||||||
|
# 'type':
|
||||||
|
# The underlying ASN.1 type of the value specified. Currently only the following have been implemented:
|
||||||
|
# UTF8: The value must be a UTF-8 encoded string.
|
||||||
|
#
|
||||||
|
# 'value':
|
||||||
|
# The value to encode, the format of this value depends on the <type> specified.
|
||||||
|
ASN1_STRING_REGEX = re.compile(
|
||||||
|
r"^((?P<tag_type>IMPLICIT|EXPLICIT):(?P<tag_number>\d+)(?P<tag_class>U|A|P|C)?,)?"
|
||||||
|
r"(?P<value_type>[\w\d]+):(?P<value>.*)"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TagClass(enum.Enum):
|
||||||
|
UNIVERSAL = 0
|
||||||
|
APPLICATION = 1
|
||||||
|
CONTEXT_SPECIFIC = 2
|
||||||
|
PRIVATE = 3
|
||||||
|
|
||||||
|
|
||||||
|
# Universal tag numbers that can be encoded.
|
||||||
|
class TagNumber(enum.Enum):
|
||||||
|
UTF8_STRING = 12
|
||||||
|
|
||||||
|
|
||||||
|
def _pack_octet_integer(value: int) -> bytes:
|
||||||
|
"""Packs an integer value into 1 or multiple octets."""
|
||||||
|
# NOTE: This is *NOT* the same as packing an ASN.1 INTEGER like value.
|
||||||
|
octets = bytearray()
|
||||||
|
|
||||||
|
# Continue to shift the number by 7 bits and pack into an octet until the
|
||||||
|
# value is fully packed.
|
||||||
|
while value:
|
||||||
|
octet_value = value & 0b01111111
|
||||||
|
|
||||||
|
# First round (last octet) must have the MSB set.
|
||||||
|
if len(octets):
|
||||||
|
octet_value |= 0b10000000
|
||||||
|
|
||||||
|
octets.append(octet_value)
|
||||||
|
value >>= 7
|
||||||
|
|
||||||
|
# Reverse to ensure the higher order octets are first.
|
||||||
|
octets.reverse()
|
||||||
|
return bytes(octets)
|
||||||
|
|
||||||
|
|
||||||
|
def serialize_asn1_string_as_der(value: str) -> bytes:
|
||||||
|
"""Deserializes an ASN.1 string to a DER encoded byte string."""
|
||||||
|
asn1_match = ASN1_STRING_REGEX.match(value)
|
||||||
|
if not asn1_match:
|
||||||
|
raise ValueError(
|
||||||
|
"The ASN.1 serialized string must be in the format [modifier,]type[:value]"
|
||||||
|
)
|
||||||
|
|
||||||
|
tag_type = asn1_match.group("tag_type")
|
||||||
|
tag_number = asn1_match.group("tag_number")
|
||||||
|
tag_class = asn1_match.group("tag_class") or "C"
|
||||||
|
value_type = asn1_match.group("value_type")
|
||||||
|
asn1_value = asn1_match.group("value")
|
||||||
|
|
||||||
|
if value_type != "UTF8":
|
||||||
|
raise ValueError(
|
||||||
|
f'The ASN.1 serialized string is not a known type "{value_type}", only UTF8 types are supported'
|
||||||
|
)
|
||||||
|
|
||||||
|
b_value = to_bytes(asn1_value, encoding="utf-8", errors="surrogate_or_strict")
|
||||||
|
|
||||||
|
# We should only do a universal type tag if not IMPLICITLY tagged or the tag class is not universal.
|
||||||
|
if not tag_type or (tag_type == "EXPLICIT" and tag_class != "U"):
|
||||||
|
b_value = pack_asn1(
|
||||||
|
tag_class=TagClass.UNIVERSAL,
|
||||||
|
constructed=False,
|
||||||
|
tag_number=TagNumber.UTF8_STRING,
|
||||||
|
b_data=b_value,
|
||||||
|
)
|
||||||
|
|
||||||
|
if tag_type:
|
||||||
|
tag_class_enum = {
|
||||||
|
"U": TagClass.UNIVERSAL,
|
||||||
|
"A": TagClass.APPLICATION,
|
||||||
|
"P": TagClass.PRIVATE,
|
||||||
|
"C": TagClass.CONTEXT_SPECIFIC,
|
||||||
|
}[tag_class]
|
||||||
|
|
||||||
|
# When adding support for more types this should be looked into further. For now it works with UTF8Strings.
|
||||||
|
constructed = tag_type == "EXPLICIT" and tag_class_enum != TagClass.UNIVERSAL
|
||||||
|
b_value = pack_asn1(
|
||||||
|
tag_class=tag_class_enum,
|
||||||
|
constructed=constructed,
|
||||||
|
tag_number=int(tag_number),
|
||||||
|
b_data=b_value,
|
||||||
|
)
|
||||||
|
|
||||||
|
return b_value
|
||||||
|
|
||||||
|
|
||||||
|
def pack_asn1(
|
||||||
|
*,
|
||||||
|
tag_class: TagClass,
|
||||||
|
constructed: bool,
|
||||||
|
tag_number: TagNumber | int,
|
||||||
|
b_data: bytes,
|
||||||
|
) -> bytes:
|
||||||
|
"""Pack the value into an ASN.1 data structure.
|
||||||
|
|
||||||
|
The structure for an ASN.1 element is
|
||||||
|
|
||||||
|
| Identifier Octet(s) | Length Octet(s) | Data Octet(s) |
|
||||||
|
"""
|
||||||
|
b_asn1_data = bytearray()
|
||||||
|
|
||||||
|
# Bit 8 and 7 denotes the class.
|
||||||
|
identifier_octets = tag_class.value << 6
|
||||||
|
# Bit 6 denotes whether the value is primitive or constructed.
|
||||||
|
identifier_octets |= (1 if constructed else 0) << 5
|
||||||
|
|
||||||
|
# Bits 5-1 contain the tag number, if it cannot be encoded in these 5 bits
|
||||||
|
# then they are set and another octet(s) is used to denote the tag number.
|
||||||
|
if isinstance(tag_number, TagNumber):
|
||||||
|
tag_number = tag_number.value
|
||||||
|
if tag_number < 31:
|
||||||
|
identifier_octets |= tag_number
|
||||||
|
b_asn1_data.append(identifier_octets)
|
||||||
|
else:
|
||||||
|
identifier_octets |= 31
|
||||||
|
b_asn1_data.append(identifier_octets)
|
||||||
|
b_asn1_data.extend(_pack_octet_integer(tag_number))
|
||||||
|
|
||||||
|
length = len(b_data)
|
||||||
|
|
||||||
|
# If the length can be encoded in 7 bits only 1 octet is required.
|
||||||
|
if length < 128:
|
||||||
|
b_asn1_data.append(length)
|
||||||
|
|
||||||
|
else:
|
||||||
|
# Otherwise the length must be encoded across multiple octets
|
||||||
|
length_octets = bytearray()
|
||||||
|
while length:
|
||||||
|
length_octets.append(length & 0b11111111)
|
||||||
|
length >>= 8
|
||||||
|
|
||||||
|
length_octets.reverse() # Reverse to make the higher octets first.
|
||||||
|
|
||||||
|
# The first length octet must have the MSB set alongside the number of
|
||||||
|
# octets the length was encoded in.
|
||||||
|
b_asn1_data.append(len(length_octets) | 0b10000000)
|
||||||
|
b_asn1_data.extend(length_octets)
|
||||||
|
|
||||||
|
return bytes(b_asn1_data) + b_data
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ("TagClass", "TagNumber", "pack_asn1", "serialize_asn1_string_as_der")
|
||||||
@@ -1,7 +1,20 @@
|
|||||||
|
# This code is part of Ansible, but is an independent component.
|
||||||
|
# This particular file snippet, and this file snippet only, is licensed under the
|
||||||
|
# Apache 2.0 License. Modules you write using this snippet, which is embedded
|
||||||
|
# dynamically by Ansible, still belong to the author of the module, and may assign
|
||||||
|
# their own license to the complete work.
|
||||||
|
|
||||||
|
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
# This excerpt is dual licensed under the terms of the Apache License, Version
|
# This excerpt is dual licensed under the terms of the Apache License, Version
|
||||||
# 2.0, and the BSD License. See the LICENSE file at
|
# 2.0, and the BSD License. See the LICENSE file at
|
||||||
# https://github.com/pyca/cryptography/blob/master/LICENSE for complete details.
|
# https://github.com/pyca/cryptography/blob/master/LICENSE for complete details.
|
||||||
#
|
#
|
||||||
|
# The Apache 2.0 license has been included as LICENSES/Apache-2.0.txt in this collection.
|
||||||
|
# The BSD License license has been included as LICENSES/BSD-3-Clause.txt in this collection.
|
||||||
|
# SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause
|
||||||
|
#
|
||||||
# Adapted from cryptography's hazmat/backends/openssl/decode_asn1.py
|
# Adapted from cryptography's hazmat/backends/openssl/decode_asn1.py
|
||||||
#
|
#
|
||||||
# Copyright (c) 2015, 2016 Paul Kehrer (@reaperhulk)
|
# Copyright (c) 2015, 2016 Paul Kehrer (@reaperhulk)
|
||||||
@@ -16,15 +29,16 @@
|
|||||||
# pyca/cryptography@3057f91ea9a05fb593825006d87a391286a4d828
|
# pyca/cryptography@3057f91ea9a05fb593825006d87a391286a4d828
|
||||||
# pyca/cryptography@d607dd7e5bc5c08854ec0c9baff70ba4a35be36f
|
# pyca/cryptography@d607dd7e5bc5c08854ec0c9baff70ba4a35be36f
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import annotations
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
|
import typing as t
|
||||||
|
|
||||||
# WARNING: this function no longer works with cryptography 35.0.0 and newer!
|
# WARNING: this function no longer works with cryptography 35.0.0 and newer!
|
||||||
# It must **ONLY** be used in compatibility code for older
|
# It must **ONLY** be used in compatibility code for older
|
||||||
# cryptography versions!
|
# cryptography versions!
|
||||||
|
|
||||||
def obj2txt(openssl_lib, openssl_ffi, obj):
|
|
||||||
|
def obj2txt(openssl_lib: t.Any, openssl_ffi: t.Any, obj: t.Any) -> str:
|
||||||
# Set to 80 on the recommendation of
|
# Set to 80 on the recommendation of
|
||||||
# https://www.openssl.org/docs/crypto/OBJ_nid2ln.html#return_values
|
# https://www.openssl.org/docs/crypto/OBJ_nid2ln.html#return_values
|
||||||
#
|
#
|
||||||
@@ -44,4 +58,8 @@ def obj2txt(openssl_lib, openssl_ffi, obj):
|
|||||||
buf_len = res + 1
|
buf_len = res + 1
|
||||||
buf = openssl_ffi.new("char[]", buf_len)
|
buf = openssl_ffi.new("char[]", buf_len)
|
||||||
res = openssl_lib.OBJ_obj2txt(buf, buf_len, obj, 1)
|
res = openssl_lib.OBJ_obj2txt(buf, buf_len, obj, 1)
|
||||||
return openssl_ffi.buffer(buf, res)[:].decode()
|
bytes_str: bytes = openssl_ffi.buffer(buf, res)[:]
|
||||||
|
return bytes_str.decode()
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ("obj2txt",)
|
||||||
37
plugins/module_utils/_crypto/_objects.py
Normal file
37
plugins/module_utils/_crypto/_objects.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# Copyright (c) 2019, Felix Fontein <felix@fontein.de>
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
|
||||||
|
# Do not use this from other collections or standalone plugins/modules!
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from ansible_collections.community.crypto.plugins.module_utils._crypto._objects_data import (
|
||||||
|
OID_MAP,
|
||||||
|
)
|
||||||
|
|
||||||
|
OID_LOOKUP: dict[str, str] = {}
|
||||||
|
NORMALIZE_NAMES: dict[str, str] = {}
|
||||||
|
NORMALIZE_NAMES_SHORT: dict[str, str] = {}
|
||||||
|
|
||||||
|
for dotted, names in OID_MAP.items():
|
||||||
|
for name in names:
|
||||||
|
if name in NORMALIZE_NAMES and OID_LOOKUP[name] != dotted:
|
||||||
|
raise AssertionError( # pragma: no cover
|
||||||
|
f'Name collision during setup: "{name}" for OIDs {dotted} and {OID_LOOKUP[name]}'
|
||||||
|
)
|
||||||
|
NORMALIZE_NAMES[name] = names[0]
|
||||||
|
NORMALIZE_NAMES_SHORT[name] = names[-1]
|
||||||
|
OID_LOOKUP[name] = dotted
|
||||||
|
for alias, original in [("userID", "userId")]:
|
||||||
|
if alias in NORMALIZE_NAMES:
|
||||||
|
raise AssertionError( # pragma: no cover
|
||||||
|
f'Name collision during adding aliases: "{alias}" (alias for "{original}") is already mapped to OID {OID_LOOKUP[alias]}'
|
||||||
|
)
|
||||||
|
NORMALIZE_NAMES[alias] = original
|
||||||
|
NORMALIZE_NAMES_SHORT[alias] = NORMALIZE_NAMES_SHORT[original]
|
||||||
|
OID_LOOKUP[alias] = OID_LOOKUP[original]
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ("NORMALIZE_NAMES", "NORMALIZE_NAMES_SHORT", "OID_LOOKUP")
|
||||||
1179
plugins/module_utils/_crypto/_objects_data.py
Normal file
1179
plugins/module_utils/_crypto/_objects_data.py
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user