mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
Enable integration tests for the crypto/ namespace (#26684)
Crypto namespace contains the openssl modules. It has no integration testing as of now. This commits aims to add integration tests for the crypto namespace. This will make it easier to spot breaking changes in the future. This tests currently apply to: * openssl_privatekey * openssl_publickey * openssl_csr
This commit is contained in:
committed by
John R Barker
parent
b3e8fa72ce
commit
8b22c45a45
@@ -35,15 +35,12 @@ class OpenSSLObjectError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def get_fingerprint(path, passphrase):
|
||||
def get_fingerprint(path, passphrase=None):
|
||||
"""Generate the fingerprint of the public key. """
|
||||
|
||||
fingerprint = {}
|
||||
|
||||
privatekey = crypto.load_privatekey(crypto.FILETYPE_PEM,
|
||||
open(path, 'rb').read(),
|
||||
passphrase)
|
||||
|
||||
privatekey = load_privatekey(path, passphrase)
|
||||
try:
|
||||
publickey = crypto.dump_publickey(crypto.FILETYPE_ASN1, privatekey)
|
||||
for algo in hashlib.algorithms:
|
||||
@@ -63,10 +60,14 @@ def load_privatekey(path, passphrase=None):
|
||||
"""Load the specified OpenSSL private key."""
|
||||
|
||||
try:
|
||||
privatekey_content = open(path, 'rb').read()
|
||||
privatekey = crypto.load_privatekey(crypto.FILETYPE_PEM,
|
||||
privatekey_content,
|
||||
passphrase)
|
||||
if passphrase:
|
||||
privatekey = crypto.load_privatekey(crypto.FILETYPE_PEM,
|
||||
open(path, 'rb').read(),
|
||||
passphrase)
|
||||
else:
|
||||
privatekey = crypto.load_privatekey(crypto.FILETYPE_PEM,
|
||||
open(path, 'rb').read())
|
||||
|
||||
return privatekey
|
||||
except (IOError, OSError) as exc:
|
||||
raise OpenSSLObjectError(exc)
|
||||
|
||||
Reference in New Issue
Block a user