-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for passphrase to be an awaitable
This commit expands the passphrase argument in SSHClientConnectionOptions and SSHServerConnectionOptions to accept an awaitable, in addition to the callable which was previously added. Options evaluation is still done in a separate executor thread to avoid blocking the asyncio event loop, but it's now possible to pass in an awaitable which will run as a task in the event loop to determine the passphrase to use if you need to do "blocking" async operations to determine this value.
- Loading branch information
Showing
4 changed files
with
86 additions
and
30 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright (c) 2013-2023 by Ron Frederick <[email protected]> and others. | ||
# Copyright (c) 2013-2024 by Ron Frederick <[email protected]> and others. | ||
# | ||
# This program and the accompanying materials are made available under | ||
# the terms of the Eclipse Public License v2.0 which accompanies this | ||
|
@@ -20,7 +20,9 @@ | |
|
||
"""SSH asymmetric encryption handlers""" | ||
|
||
import asyncio | ||
import binascii | ||
import inspect | ||
import os | ||
import re | ||
import time | ||
|
@@ -3472,7 +3474,8 @@ def load_keypairs( | |
keylist: KeyPairListArg, passphrase: Optional[BytesOrStr] = None, | ||
certlist: CertListArg = (), skip_public: bool = False, | ||
ignore_encrypted: bool = False, | ||
unsafe_skip_rsa_key_validation: Optional[bool] = None) -> \ | ||
unsafe_skip_rsa_key_validation: Optional[bool] = None, | ||
loop: Optional[asyncio.AbstractEventLoop] = None) -> \ | ||
Sequence[SSHKeyPair]: | ||
"""Load SSH private keys and optional matching certificates | ||
|
@@ -3521,6 +3524,10 @@ def load_keypairs( | |
else: | ||
resolved_passphrase = passphrase | ||
|
||
if loop and inspect.isawaitable(resolved_passphrase): | ||
resolved_passphrase = asyncio.run_coroutine_threadsafe( | ||
resolved_passphrase, loop).result() | ||
|
||
priv_keys = read_private_key_list(keylist, resolved_passphrase, | ||
unsafe_skip_rsa_key_validation) | ||
|
||
|
@@ -3559,6 +3566,10 @@ def load_keypairs( | |
else: | ||
resolved_passphrase = passphrase | ||
|
||
if loop and inspect.isawaitable(resolved_passphrase): | ||
resolved_passphrase = asyncio.run_coroutine_threadsafe( | ||
resolved_passphrase, loop).result() | ||
|
||
if allow_certs: | ||
key, certs_to_load = read_private_key_and_certs( | ||
key_to_load, resolved_passphrase, | ||
|
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
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