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

Auth: ssh_sign, remove isinstance(message, str) check and add type hints #6647

Merged
merged 2 commits into from Apr 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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