| 1 | # Copyright New York University and the in-toto contributors |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| 4 | """ |
| 5 | <Program Name> |
| 6 | _signer.py |
| 7 | |
| 8 | <Author> |
| 9 | Pradyumna Krishna <[email protected]> |
| 10 | |
| 11 | <Started> |
| 12 | Jan 26, 2023 |
| 13 | |
| 14 | <Copyright> |
| 15 | See LICENSE for licensing information. |
| 16 | |
| 17 | <Purpose> |
| 18 | Provides in-toto flavored GPGSigner, GPGSignature and GPGKey. |
| 19 | |
| 20 | """ |
| 21 | |
| 22 | from dataclassesscip-python python python-stdlib 3.11 dataclasses/__init__: import dataclassscip-python python python-stdlib 3.11 dataclasses/dataclass(). |
| 23 | from typingscip-python python python-stdlib 3.11 typing/__init__: import Anyscip-python python python-stdlib 3.11 typing/Any., Dictscip-python python python-stdlib 3.11 typing/Dict., Listscip-python python python-stdlib 3.11 typing/List., Optionalscip-python python python-stdlib 3.11 typing/Optional. |
| 24 | |
| 25 | import securesystemslib.gpg.exceptionsscip-python python securesystemslib 1.4.0 `securesystemslib.gpg.exceptions`/__init__: as gpg_exceptions |
| 26 | import securesystemslib.gpg.functionsscip-python python securesystemslib 1.4.0 `securesystemslib.gpg.functions`/__init__: as gpg |
| 27 | from securesystemslibscip-python python securesystemslib 1.4.0 securesystemslib/__init__: import exceptionsscip-python python securesystemslib 1.4.0 `securesystemslib.exceptions`/__init__: |
| 28 | from securesystemslib.signerscip-python python securesystemslib 1.4.0 `securesystemslib.signer`/__init__: import Key, SecretsHandler, Signature, Signer |
| 29 | |
| 30 | |
| 31 | class GPGSignaturescip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#(Signature): |
| 32 | """A container class containing information about a gpg signature. |
| 33 | Besides the signature, it also contains other meta information |
| 34 | needed to uniquely identify the key used to generate the signature. |
| 35 | |
| 36 | Attributes: |
| 37 | keyid: HEX string used as a unique identifier of the key. |
| 38 | signature: HEX string representing the signature. |
| 39 | other_headers: HEX representation of additional GPG headers. |
| 40 | """ |
| 41 | |
| 42 | def __init__scip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#__init__().( |
| 43 | selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#__init__().(self), |
| 44 | keyidscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#__init__().(keyid): strscip-python python python-stdlib 3.11 builtins/str#, |
| 45 | signaturescip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#__init__().(signature): strscip-python python python-stdlib 3.11 builtins/str#, |
| 46 | other_headersscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#__init__().(other_headers): strscip-python python python-stdlib 3.11 builtins/str#, |
| 47 | ): |
| 48 | superscip-python python python-stdlib 3.11 builtins/super#().__init__(keyidscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#__init__().(keyid), signaturescip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#__init__().(signature)) |
| 49 | selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#__init__().(self).other_headersscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#other_headers. = other_headersscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#__init__().(other_headers) |
| 50 | |
| 51 | @classmethodscip-python python python-stdlib 3.11 builtins/classmethod# |
| 52 | def from_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#from_dict().(clsscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#from_dict().(cls), signature_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#from_dict().(signature_dict): Dictscip-python python python-stdlib 3.11 typing/Dict.) -> "GPGSignaturescip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#": |
| 53 | """Creates a ``GPGSignature`` object from its JSON/dict |
| 54 | representation. |
| 55 | |
| 56 | Arguments: |
| 57 | signature_dict: Dict containing valid "keyid", "signature" and |
| 58 | "other_fields" fields. |
| 59 | Raises: |
| 60 | KeyError: If any of the "keyid", "sig" or "other_headers" fields |
| 61 | are missing from the signature_dict. |
| 62 | Returns: |
| 63 | ``GPGSignature`` instance. |
| 64 | """ |
| 65 | |
| 66 | return clsscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#from_dict().(cls)( |
| 67 | signature_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#from_dict().(signature_dict)["keyid"], |
| 68 | signature_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#from_dict().(signature_dict)["signature"], |
| 69 | signature_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#from_dict().(signature_dict)["other_headers"], |
| 70 | ) |
| 71 | |
| 72 | def to_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#to_dict().(selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#to_dict().(self)) -> Dictscip-python python python-stdlib 3.11 typing/Dict.: |
| 73 | """Returns the JSON-serializable dictionary representation of self.""" |
| 74 | return { |
| 75 | "keyid": selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#to_dict().(self).keyid, |
| 76 | "signature": selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#to_dict().(self).signature, |
| 77 | "other_headers": selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#to_dict().(self).other_headersscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#other_headers., |
| 78 | } |
| 79 | |
| 80 | |
| 81 | class GPGSignerscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#(Signer): |
| 82 | """A in-toto gpg implementation of the ``Signer`` interface. |
| 83 | Provides a sign method to generate a cryptographic signature with gpg, using |
| 84 | an RSA, DSA or EdDSA private key identified by the keyid on the instance. |
| 85 | |
| 86 | Arguments: |
| 87 | keyid: The keyid of the gpg signing keyid. If not passed the default |
| 88 | key in the keyring is used. |
| 89 | homedir: Path to the gpg keyring. If not passed the default keyring |
| 90 | is used. |
| 91 | """ |
| 92 | |
| 93 | def __init__scip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#__init__().( |
| 94 | selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#__init__().(self), keyidscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#__init__().(keyid): Optionalscip-python python python-stdlib 3.11 typing/Optional.[strscip-python python python-stdlib 3.11 builtins/str#] = None, homedirscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#__init__().(homedir): Optionalscip-python python python-stdlib 3.11 typing/Optional.[strscip-python python python-stdlib 3.11 builtins/str#] = None |
| 95 | ): |
| 96 | selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#__init__().(self).keyidscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#keyid. = keyidscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#__init__().(keyid) |
| 97 | selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#__init__().(self).homedirscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#homedir. = homedirscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#__init__().(homedir) |
| 98 | |
| 99 | @classmethodscip-python python python-stdlib 3.11 builtins/classmethod# |
| 100 | def from_priv_key_uriscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#from_priv_key_uri().( |
| 101 | clsscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#from_priv_key_uri().(cls), |
| 102 | priv_key_uriscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#from_priv_key_uri().(priv_key_uri): strscip-python python python-stdlib 3.11 builtins/str#, |
| 103 | public_keyscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#from_priv_key_uri().(public_key): Key, |
| 104 | secrets_handlerscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#from_priv_key_uri().(secrets_handler): Optionalscip-python python python-stdlib 3.11 typing/Optional.[SecretsHandler] = None, |
| 105 | ) -> "GPGSignerscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#": |
| 106 | raise NotImplementedErrorscip-python python python-stdlib 3.11 builtins/NotImplementedError#( |
| 107 | "Incompatible with private key URIs" |
| 108 | ) # pragma: no cover |
| 109 | |
| 110 | def signscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#sign().(selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#sign().(self), payloadscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#sign().(payload): bytesscip-python python python-stdlib 3.11 builtins/bytes#) -> GPGSignaturescip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#: |
| 111 | """Signs a given payload by the key assigned to the ``GPGSigner`` |
| 112 | instance. Calls the gpg command line utility to sign the passed content |
| 113 | with the key identified by the passed keyid from the gpg keyring at the |
| 114 | passed homedir. |
| 115 | |
| 116 | Arguments: |
| 117 | payload: The bytes to be signed. |
| 118 | Raises: |
| 119 | securesystemslib.exceptions.FormatError: |
| 120 | If the keyid was passed and does not match |
| 121 | securesystemslib.formats.KEYID_SCHEMA. |
| 122 | ValueError: the gpg command failed to create a valid signature. |
| 123 | OSError: the gpg command is not present or non-executable. |
| 124 | securesystemslib.exceptions.UnsupportedLibraryError: the gpg command is |
| 125 | not available, or the cryptography library is not installed. |
| 126 | securesystemslib.gpg.exceptions.CommandError: the gpg command returned a |
| 127 | non-zero exit code. |
| 128 | securesystemslib.gpg.exceptions.KeyNotFoundError: the used gpg version is |
| 129 | not fully supported and no public key can be found for short keyid. |
| 130 | Returns: |
| 131 | Returns a ``GPGSignature`` class instance. |
| 132 | """ |
| 133 | |
| 134 | sig_dict = gpg.create_signature(payloadscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#sign().(payload), selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#sign().(self).keyidscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#keyid., selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#sign().(self).homedirscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSigner#homedir.) |
| 135 | return GPGSignaturescip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#(**sig_dict) |
| 136 | |
| 137 | |
| 138 | @dataclassscip-python python python-stdlib 3.11 dataclasses/dataclass(). |
| 139 | class GPGKeyscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#(Key): |
| 140 | """A container class representing public key portion of a GPG key. |
| 141 | Provides a verify method to verify a cryptographic signature with a |
| 142 | gpg-style rsa, dsa or ecdsa public key on the instance. |
| 143 | |
| 144 | Attributes: |
| 145 | type: Key type, e.g. "rsa", "dsa" or "ecdsa". |
| 146 | method: GPG Key Scheme, For example: |
| 147 | "pgp+rsa-pkcsv1.5", "pgp+dsa-fips-180-2", and "pgp+eddsa-ed25519". |
| 148 | hashes: list of GPG Hash Algorithms, e.g. "pgp+SHA2". |
| 149 | keyval: Opaque key content. |
| 150 | keyid: Key identifier that is unique within the metadata it is used in. |
| 151 | Keyid is not verified to be the hash of a specific representation |
| 152 | of the key. |
| 153 | creation_time: Unix timestamp when GPG key was created. |
| 154 | validity_period: Validity of the GPG Keys in days. |
| 155 | subkeys: A dictionary containing keyid and GPG subkey. |
| 156 | """ |
| 157 | |
| 158 | typescip-python python python-stdlib 3.11 builtins/type#: strscip-python python python-stdlib 3.11 builtins/str# |
| 159 | methodscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#method.: strscip-python python python-stdlib 3.11 builtins/str# |
| 160 | hashesscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#hashes.: Listscip-python python python-stdlib 3.11 typing/List.[strscip-python python python-stdlib 3.11 builtins/str#] |
| 161 | keyvalscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#keyval.: Dictscip-python python python-stdlib 3.11 typing/Dict.[strscip-python python python-stdlib 3.11 builtins/str#, strscip-python python python-stdlib 3.11 builtins/str#] |
| 162 | keyidscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#keyid.: strscip-python python python-stdlib 3.11 builtins/str# |
| 163 | creation_timescip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#creation_time.: Optionalscip-python python python-stdlib 3.11 typing/Optional.[intscip-python python python-stdlib 3.11 builtins/int#] = None |
| 164 | validity_periodscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#validity_period.: Optionalscip-python python python-stdlib 3.11 typing/Optional.[intscip-python python python-stdlib 3.11 builtins/int#] = None |
| 165 | subkeysscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#subkeys.: Optionalscip-python python python-stdlib 3.11 typing/Optional.[Dictscip-python python python-stdlib 3.11 typing/Dict.[strscip-python python python-stdlib 3.11 builtins/str#, "GPGKeyscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#"]] = None |
| 166 | |
| 167 | @classmethodscip-python python python-stdlib 3.11 builtins/classmethod# |
| 168 | def from_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_dict().(clsscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_dict().(cls), keyidscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_dict().(keyid): strscip-python python python-stdlib 3.11 builtins/str#, key_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_dict().(key_dict): Dictscip-python python python-stdlib 3.11 typing/Dict.[strscip-python python python-stdlib 3.11 builtins/str#, Anyscip-python python python-stdlib 3.11 typing/Any.]): |
| 169 | """Creates ``GPGKey`` object from its json/dict representation. |
| 170 | Raises: |
| 171 | KeyError, TypeError: Invalid arguments. |
| 172 | """ |
| 173 | subkeys_dict = key_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_dict().(key_dict).getscip-python python python-stdlib 3.11 builtins/dict#get().("subkeys") |
| 174 | |
| 175 | gpg_subkeys = None |
| 176 | if subkeys_dict: |
| 177 | gpg_subkeys = { |
| 178 | _keyid: GPGKeyscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#.from_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_dict().(_keyid, subkey_dict) |
| 179 | for (_keyid, subkey_dict) in subkeys_dict.items() |
| 180 | } |
| 181 | |
| 182 | return clsscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_dict().(cls)( |
| 183 | key_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_dict().(key_dict)["type"], |
| 184 | key_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_dict().(key_dict)["method"], |
| 185 | key_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_dict().(key_dict)["hashes"], |
| 186 | key_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_dict().(key_dict)["keyval"], |
| 187 | keyidscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_dict().(keyid), |
| 188 | key_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_dict().(key_dict).getscip-python python python-stdlib 3.11 builtins/dict#get().("creation_time"), |
| 189 | key_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_dict().(key_dict).getscip-python python python-stdlib 3.11 builtins/dict#get().("validity_period"), |
| 190 | gpg_subkeys, |
| 191 | ) |
| 192 | |
| 193 | @classmethodscip-python python python-stdlib 3.11 builtins/classmethod# |
| 194 | def from_legacy_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_legacy_dict().(clsscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_legacy_dict().(cls), key_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_legacy_dict().(key_dict): Dictscip-python python python-stdlib 3.11 typing/Dict.[strscip-python python python-stdlib 3.11 builtins/str#, Anyscip-python python python-stdlib 3.11 typing/Any.]): |
| 195 | """Create GPGKey from legacy dictionary representation.""" |
| 196 | |
| 197 | keyid = key_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_legacy_dict().(key_dict)["keyid"] |
| 198 | return clsscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_legacy_dict().(cls).from_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_dict().(keyid, key_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_legacy_dict().(key_dict)) |
| 199 | |
| 200 | def to_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#to_dict().(selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#to_dict().(self)): |
| 201 | """Returns the dictionary representation of self.""" |
| 202 | |
| 203 | key_dict = { |
| 204 | "method": selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#to_dict().(self).methodscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#method., |
| 205 | "type": selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#to_dict().(self).typescip-python python python-stdlib 3.11 builtins/type#, |
| 206 | "hashes": selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#to_dict().(self).hashesscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#hashes., |
| 207 | "keyid": selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#to_dict().(self).keyidscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#keyid., |
| 208 | "keyval": selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#to_dict().(self).keyvalscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#keyval., |
| 209 | } |
| 210 | |
| 211 | if selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#to_dict().(self).creation_timescip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#creation_time.: |
| 212 | key_dict["creation_time"] = selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#to_dict().(self).creation_timescip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#creation_time. |
| 213 | if selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#to_dict().(self).validity_periodscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#validity_period.: |
| 214 | key_dict["validity_period"] = selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#to_dict().(self).validity_periodscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#validity_period. |
| 215 | if selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#to_dict().(self).subkeysscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#subkeys.: |
| 216 | subkeys_dict = { |
| 217 | keyid: subkey.to_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#to_dict().() |
| 218 | for (keyid, subkey) in selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#to_dict().(self).subkeysscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#subkeys..itemsscip-python python python-stdlib 3.11 builtins/dict#items().() |
| 219 | } |
| 220 | key_dict["subkeys"] = subkeys_dict |
| 221 | |
| 222 | return key_dict |
| 223 | |
| 224 | @classmethodscip-python python python-stdlib 3.11 builtins/classmethod# |
| 225 | def from_keyringscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_keyring().(clsscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_keyring().(cls), keyidscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_keyring().(keyid), homedirscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_keyring().(homedir)=None): |
| 226 | """Creates ``GPGKey`` object from GnuPG Keyring.""" |
| 227 | |
| 228 | pubkey_dict = gpg.export_pubkey(keyidscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_keyring().(keyid), homedirscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_keyring().(homedir)) |
| 229 | return clsscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_keyring().(cls).from_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_dict().(keyidscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#from_keyring().(keyid), pubkey_dict) |
| 230 | |
| 231 | def verify_signaturescip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#verify_signature().(selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#verify_signature().(self), signaturescip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#verify_signature().(signature): GPGSignaturescip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#, datascip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#verify_signature().(data): bytesscip-python python python-stdlib 3.11 builtins/bytes#) -> None: |
| 232 | """Verifies a given payload by the key assigned to the GPGKey |
| 233 | instance. |
| 234 | |
| 235 | Arguments: |
| 236 | signature: A ``GPGSignature`` class instance. |
| 237 | data: The bytes to be verified. |
| 238 | """ |
| 239 | |
| 240 | try: |
| 241 | if not gpg.verify_signature( |
| 242 | signaturescip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#verify_signature().(signature).to_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGSignature#to_dict().(), selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#verify_signature().(self).to_dictscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#to_dict().(), datascip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#verify_signature().(data) |
| 243 | ): |
| 244 | raise exceptionsscip-python python securesystemslib 1.4.0 `securesystemslib.exceptions`/__init__:.UnverifiedSignatureError( |
| 245 | f"Failed to verify signature by {selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#verify_signature().(self).keyidscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#keyid.}" |
| 246 | ) |
| 247 | except ( |
| 248 | exceptionsscip-python python securesystemslib 1.4.0 `securesystemslib.exceptions`/__init__:.FormatError, |
| 249 | exceptionsscip-python python securesystemslib 1.4.0 `securesystemslib.exceptions`/__init__:.UnsupportedLibraryError, |
| 250 | gpg_exceptions.KeyExpirationError, |
| 251 | ) as e: |
| 252 | raise exceptionsscip-python python securesystemslib 1.4.0 `securesystemslib.exceptions`/__init__:.VerificationError( |
| 253 | f"Unknown failure to verify signature by {selfscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#verify_signature().(self).keyidscip-python python in-toto 2.0.0 `in_toto.models._signer`/GPGKey#keyid.}" |
| 254 | ) from e |