Skip to content

Commit

Permalink
Auth: ssh_sign, add type hints; #6600
Browse files Browse the repository at this point in the history
Follow-up from this PR: #6497
  • Loading branch information
rdimaio authored and bari12 committed Apr 26, 2024
1 parent 876f736 commit 25ab761
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/rucio/common/utils.py
Expand Up @@ -1271,22 +1271,21 @@ def detect_client_location():
'longitude': longitude}


def ssh_sign(private_key, message):
def ssh_sign(private_key: str, message: str) -> str:
"""
Sign a string message using the private key.
:param private_key: The SSH RSA private key as a string.
:param message: The message to sign as a string.
:return: Base64 encoded signature as a string.
"""
if isinstance(message, str):
message = message.encode()
encoded_message = message.encode()
if not EXTRA_MODULES['paramiko']:
raise MissingModuleException('The paramiko module is not installed or faulty.')
sio_private_key = StringIO(private_key)
priv_k = RSAKey.from_private_key(sio_private_key)
sio_private_key.close()
signature_stream = priv_k.sign_ssh_data(message)
signature_stream = priv_k.sign_ssh_data(encoded_message)
signature_stream.rewind()
base64_encoded = base64.b64encode(signature_stream.get_remainder())
base64_encoded = base64_encoded.decode()
Expand Down

0 comments on commit 25ab761

Please sign in to comment.