-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try again to generate EC2 key fingerprints
- Loading branch information
Showing
3 changed files
with
63 additions
and
21 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
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