forked from ansible-collections/amazon.aws
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ec2_key : Fix tests (ansible-collections#427)
ec2_key : Fix tests SUMMARY The Zuul nodes don't have OpenSSL installed on them, this breaks the generation of the fingerprints ISSUE TYPE Bugfix Pull Request COMPONENT NAME ec2_key ADDITIONAL INFORMATION https://dashboard.zuul.ansible.com/t/ansible/build/d79dcec2e3024558800bba5fd6917505/log/job-output.txt "stderr": "/bin/sh: line 1: openssl: command not found" Depends-on: ansible-collections#460 Reviewed-by: Alina Buzachis <None> Reviewed-by: None <None>
- Loading branch information
Showing
5 changed files
with
69 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Needed by the ec2_key integration tests (generating EC2 format fingerprint) | ||
openssl [test platform:rpm] | ||
gcc [test platform:rpm] | ||
python3-devel [test platform:rpm] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
tests/integration/targets/setup_sshkey/files/ec2-fingerprint.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env python | ||
""" | ||
Reads an OpenSSH Public key and spits out the 'AWS' MD5 sum | ||
The equivalent of | ||
ssh-keygen -f id_rsa.pub -e -m PKCS8 | openssl pkey -pubin -outform DER | openssl md5 -c | cut -f 2 -d ' ' | ||
(but without needing the OpenSSL CLI) | ||
""" | ||
|
||
from __future__ import absolute_import, division, print_function | ||
__metaclass__ = type | ||
|
||
import hashlib | ||
import sys | ||
from Crypto.PublicKey import RSA | ||
|
||
if len(sys.argv) == 0: | ||
ssh_public_key = "id_rsa.pub" | ||
else: | ||
ssh_public_key = sys.argv[1] | ||
|
||
with open(ssh_public_key, 'r') as key_fh: | ||
data = key_fh.read() | ||
|
||
# Convert from SSH format to DER format | ||
public_key = RSA.importKey(data).exportKey('DER') | ||
md5digest = hashlib.md5(public_key).hexdigest() | ||
# Format the md5sum into the normal format | ||
pairs = zip(md5digest[::2], md5digest[1::2]) | ||
md5string = ":".join(["".join(pair) for pair in pairs]) | ||
|
||
print(md5string) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters