gpg module¶
GpgKey
¶
The GPG keys held in one key file on the target host.
Commands:
gpg --with-colons <src>
Returns:
list[GpgKeyInfo]
Raises:
CommandNotFoundError, HostConnectionError, ValueError
Examples:
Examples can be found in examples/modules/gpg/gpg_gpg_key.py.
GpgKeyDetails
¶
One key's full metadata from the executing user's keychain, or None.
Commands:
gpg --list-keys --with-colons -- <keyid> 2>/dev/null || true
Returns:
GpgKeyMetadata | None
Raises:
HostConnectionError, ValueError
Examples:
Examples can be found in examples/modules/gpg/gpg_gpg_key_details.py.
GpgKeyInfo
¶
Attributes:
| Name | Type | Description |
|---|---|---|
id |
The key id (the last 16 hex digits of the fingerprint), the identity a colon-record listing names the key under. |
|
validity |
GPG's validity letter for the key ( |
|
length |
The key length in bits (e.g. 4096). |
|
fingerprint |
The full fingerprint, when a |
|
uid_hash |
The hash of the user id, when a |
|
uid |
The user id string (name, comment and email), when a
|
|
subkeys |
The key's subkeys as further |
GpgKeyMetadata
¶
Attributes:
| Name | Type | Description |
|---|---|---|
id |
The primary key's id (the last 16 hex digits of the fingerprint). |
|
fingerprint |
The primary key's full fingerprint; |
|
validity |
GPG's validity letter for the key ( |
|
length |
The primary key's length in bits (e.g. 4096). |
|
algo |
The public-key algorithm number as a string ( |
|
created |
The creation date as a raw epoch-seconds string (e.g.
|
|
capabilities |
The key's capability letters (e.g. |
|
expires |
The expiration date as a raw epoch-seconds string; absent when the key never expires (an empty colon field). |
|
uids |
Every user id string attached to the key, in listing order;
|
|
subkeys |
The key's subkeys as |
GpgKeyTrust
¶
Attributes:
| Name | Type | Description |
|---|---|---|
fingerprint |
The full fingerprint of the key the ownertrust assignment names. |
|
ownertrust |
The raw numeric trust value exactly as the export line prints it (1-6; 5 and 6 both mean ultimate). |
|
level |
The trust level name for |
GpgKeyring
¶
Attributes:
| Name | Type | Description |
|---|---|---|
path |
The keyring file's path, exactly as the |
|
format |
The file's extension lowercased ( |
|
keys |
The keys the file holds, as |
GpgKeyrings
¶
The GPG keyring files found under given directories, with their keys.
Commands:
find "<directories>" -type f \( -name '*.gpg' -o -name '*.kbx' \) 2>/dev/null -exec sh -c 'echo "KEYRING:$1"; gpg --list-keys --with-colons --keyring "$1" --no-default-keyring 2>/dev/null || true' _ {} \; ; find "<directories>" -type f -name '*.asc' 2>/dev/null -exec sh -c 'echo "KEYRING:$1"; gpg --with-colons "$1" 2>/dev/null || true' _ {} \;
Returns:
list[GpgKeyring]
Raises:
CommandNotFoundError, HostConnectionError, ValueError
Examples:
Examples can be found in examples/modules/gpg/gpg_gpg_keyrings.py.
GpgKeys
¶
The public GPG keys in the executing user's keychain, or one keyring file.
Commands:
gpg --list-keys --with-colons
Returns:
list[GpgKeyInfo]
Raises:
CommandNotFoundError, HostConnectionError
Examples:
Examples can be found in examples/modules/gpg/gpg_gpg_keys.py.
GpgSecretKeys
¶
The secret GPG keys in the executing user's keychain, or one keyring file.
Commands:
gpg --list-secret-keys --with-colons
Returns:
list[GpgKeyInfo]
Raises:
CommandNotFoundError, HostConnectionError
Examples:
Examples can be found in examples/modules/gpg/gpg_gpg_secret_keys.py.
GpgTrust
¶
The ownertrust assignments in the executing user's trust database.
Commands:
gpg --batch --export-ownertrust 2>/dev/null || true
Returns:
list[GpgKeyTrust]
Raises:
HostConnectionError
Examples:
Examples can be found in examples/modules/gpg/gpg_gpg_trust.py.
GpgVerification
¶
Attributes:
| Name | Type | Description |
|---|---|---|
valid |
True only when gpg reported a good signature ( |
|
status |
The deciding status line lowercased ( |
|
keyid |
The signing key's id as the status line names it; absent
when |
|
signer |
The signing key's user id string; present only for
|
GpgVerify
¶
The outcome of verifying a signature on the target host, read-only.
Commands:
gpg --batch --status-fd 1 --verify <signature> [<file>] 2>/dev/null || true
Returns:
GpgVerification
Raises:
HostConnectionError, ValueError
Examples:
Examples can be found in examples/modules/gpg/gpg_gpg_verify.py.
dearmor
async
¶
Convert an ASCII-armored GPG key file to binary format on the target host.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
OpContext
|
Execution context for the operation. |
required |
src
|
str
|
Path of the ASCII-armored key file on the target host. |
required |
dest
|
str
|
Path of the binary key file to write on the target host; its parent directory is created when missing. |
required |
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Yields:
| Name | Type | Description |
|---|---|---|
Command |
AsyncGenerator[Command]
|
The dearmor command, always (the operation is stateless). |
Raises:
ValueError
Examples:
Examples can be found in examples/modules/gpg/gpg_dearmor.py.
delete_key
async
¶
delete_key(
ctx: OpContext,
keyid: str,
secret: bool = False,
**kwargs: Any,
) -> AsyncGenerator[Command]
Delete a GPG key from the executing user's keychain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
OpContext
|
Execution context for the operation. |
required |
keyid
|
str
|
The key id, long id or fingerprint to delete ( |
required |
secret
|
bool
|
Whether to delete the secret and public
key ( |
False
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Yields:
| Name | Type | Description |
|---|---|---|
Command |
AsyncGenerator[Command]
|
Generated gpg key-deletion commands. |
Raises:
CommandNotFoundError, HostConnectionError, ValueError
Examples:
Examples can be found in examples/modules/gpg/gpg_delete_key.py.
export_key
async
¶
export_key(
ctx: OpContext,
keyid: str,
dest: str,
armor: bool = False,
secret: bool = False,
**kwargs: Any,
) -> AsyncGenerator[Command]
Export a GPG key from the executing user's keychain to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
OpContext
|
Execution context for the operation. |
required |
keyid
|
str
|
The key id, long id or fingerprint to export
( |
required |
dest
|
str
|
Path of the export file to write on the target host; its parent directory is created when missing. |
required |
armor
|
bool
|
Whether to write ASCII-armored output
( |
False
|
secret
|
bool
|
Whether to export the secret key
( |
False
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Yields:
| Name | Type | Description |
|---|---|---|
Command |
AsyncGenerator[Command]
|
The export command, always (the operation is stateless). |
Raises:
ValueError
Examples:
Examples can be found in examples/modules/gpg/gpg_export_key.py.
gen_key
async
¶
gen_key(
ctx: OpContext,
real_name: str,
email: str,
algo: str = "rsa",
length: int = 4096,
expire: str = "never",
**kwargs: Any,
) -> AsyncGenerator[Command]
Generate a GPG key in the executing user's keychain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
OpContext
|
Execution context for the operation. |
required |
real_name
|
str
|
The key user id's real name (the |
required |
email
|
str
|
The key user id's email address (the |
required |
algo
|
str
|
The key algorithm (the |
'rsa'
|
length
|
int
|
The key length in bits (the |
4096
|
expire
|
str
|
The key's expiry (the |
'never'
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Yields:
| Name | Type | Description |
|---|---|---|
Command |
AsyncGenerator[Command]
|
Generated gpg key-generation commands. |
Raises:
CommandNotFoundError, HostConnectionError, ValueError
Examples:
Examples can be found in examples/modules/gpg/gpg_gen_key.py.
import_key
async
¶
import_key(
ctx: OpContext,
src: IO[Any],
keyid: str | None = None,
secret: bool = False,
**kwargs: Any,
) -> AsyncGenerator[Command]
Import a GPG key stream into the executing user's keychain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
OpContext
|
Execution context for the operation. |
required |
src
|
IO[Any]
|
The key content as a seekable IO-like object on the
control machine (an |
required |
keyid
|
str | None
|
The key id or fingerprint ( |
None
|
secret
|
bool
|
Whether |
False
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Yields:
| Name | Type | Description |
|---|---|---|
Command |
AsyncGenerator[Command]
|
Generated gpg import commands. |
Raises:
CommandNotFoundError, HostConnectionError, ValueError
Examples:
Examples can be found in examples/modules/gpg/gpg_import_key.py.
key
async
¶
key(
ctx: OpContext,
src: IO[Any] | None = None,
dest: str | None = None,
keyid: str | list[str] | tuple[str, ...] | None = None,
present: bool = True,
working_dirs: list[str] | tuple[str, ...] | None = None,
dearmor: bool = True,
**kwargs: Any,
) -> AsyncGenerator[Command]
Install or remove GPG keyring files on the target host.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
OpContext
|
Execution context for the operation. |
required |
src
|
IO[Any] | None
|
The key content as a seekable IO-like
object on the control machine (an |
None
|
dest
|
str | None
|
The keyring file path on the target
host. Required for installation; for removal it names the one
keyring to act on (the whole file without |
None
|
keyid
|
str | list[str] | tuple[str, ...] | None
|
Key id(s)
or fingerprint(s) ( |
None
|
present
|
bool
|
Whether the key/keyring should be present (True) or absent (False). Defaults to True. |
True
|
working_dirs
|
list[str] | tuple[str, ...] | None
|
Directories to scan for keyrings when removing by |
None
|
dearmor
|
bool
|
Whether to convert ASCII-armored key content to binary form on install (the content is sniffed, not the file extension); False copies the stream verbatim. Defaults to True. |
True
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Yields:
| Name | Type | Description |
|---|---|---|
Command |
AsyncGenerator[Command]
|
Generated gpg keyring commands. |
Raises:
CommandNotFoundError, HostConnectionError, ValueError
Examples:
Examples can be found in examples/modules/gpg/gpg_key.py.
refresh_keys
async
¶
refresh_keys(
ctx: OpContext,
keyids: str | list[str] | tuple[str, ...] | None = None,
**kwargs: Any,
) -> AsyncGenerator[Command]
Refresh GPG keys from the keyservers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
OpContext
|
Execution context for the operation. |
required |
keyids
|
str | list[str] | tuple[str, ...] | None
|
The key
id(s) or fingerprint(s) to refresh ( |
None
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Yields:
| Name | Type | Description |
|---|---|---|
Command |
AsyncGenerator[Command]
|
The refresh command, always (the operation is stateless). |
Raises:
None
Examples:
Examples can be found in examples/modules/gpg/gpg_refresh_keys.py.
trust
async
¶
Set one key's ownertrust in the executing user's trust database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
OpContext
|
Execution context for the operation. |
required |
fingerprint
|
str
|
The full fingerprint of the key whose ownertrust is set. |
required |
level
|
str
|
The trust level: |
required |
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Yields:
| Name | Type | Description |
|---|---|---|
Command |
AsyncGenerator[Command]
|
Generated gpg ownertrust commands. |
Raises:
HostConnectionError, ValueError
Examples:
Examples can be found in examples/modules/gpg/gpg_trust.py.