Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR #2004/42c0475d backport][stable-7] setup_sshkey: drop a dep on Crypto #2005

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,5 @@ git+https://github.com/ansible-community/pytest-ansible-units.git ; python_versi
netaddr
# Sometimes needed where we don't have features we need in modules
awscli
# Used for comparing SSH Public keys to the Amazon fingerprints
# pycrypto is EoL using pycryptodome for now
pycryptodome
# Used by ec2_win_password
# Used for comparing SSH Public keys to the Amazon fingerprints and ec2_win_password
cryptography
3 changes: 1 addition & 2 deletions tests/integration/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ virtualenv
# Sometimes needed where we don't have features we need in modules
awscli
# Used for comparing SSH Public keys to the Amazon fingerprints
# pycrypto is EoL using pycryptodome for now
pycryptodome
cryptography
# Used by ec2_asg_scheduled_action
python-dateutil
22 changes: 10 additions & 12 deletions tests/integration/targets/setup_sshkey/files/ec2-fingerprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,26 @@
(but without needing the OpenSSL CLI)
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

__metaclass__ = type

import hashlib
import sys

from Crypto.PublicKey import RSA
from cryptography.hazmat.primitives import serialization

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()
with open(ssh_public_key, "rb") as key_file:
public_key = serialization.load_ssh_public_key(
key_file.read(),
)
pub_der = public_key.public_bytes(
encoding=serialization.Encoding.DER,
format=serialization.PublicFormat.SubjectPublicKeyInfo,
)
md5digest = hashlib.md5(pub_der).hexdigest()
# Format the md5sum into the normal format
pairs = zip(md5digest[::2], md5digest[1::2])
md5string = ":".join(["".join(pair) for pair in pairs])
Expand Down
Loading