Skip to content

Commit 37089c5

Browse files
author
Lukas Pühringer
authored
Merge pull request #775 from lukpueh/rm-gpg-schema-check
Remove schema checks in securesystemslib.gpg
2 parents 1004c45 + 7d4c336 commit 37089c5

File tree

9 files changed

+42
-129
lines changed

9 files changed

+42
-129
lines changed

securesystemslib/gpg/common.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import logging
2424
import struct
2525

26-
from securesystemslib import formats
2726
from securesystemslib.gpg import util as gpg_util
2827
from securesystemslib.gpg.constants import (
2928
FULL_KEYID_SUBPACKET,
29+
GPG_HASH_ALGORITHM_STRING,
3030
KEY_EXPIRATION_SUBPACKET,
3131
PACKET_TYPE_PRIMARY_KEY,
3232
PACKET_TYPE_SIGNATURE,
@@ -93,7 +93,7 @@ def parse_pubkey_payload(data):
9393
None.
9494
9595
<Returns>
96-
A public key in the format securesystemslib.formats.GPG_PUBKEY_SCHEMA
96+
A public key dict.
9797
9898
"""
9999
if not data:
@@ -145,7 +145,7 @@ def parse_pubkey_payload(data):
145145
return {
146146
"method": keyinfo["method"],
147147
"type": keyinfo["type"],
148-
"hashes": [formats.GPG_HASH_ALGORITHM_STRING],
148+
"hashes": [GPG_HASH_ALGORITHM_STRING],
149149
"creation_time": time_of_creation[0],
150150
"keyid": keyinfo["keyid"],
151151
"keyval": {"private": "", "public": key_params},
@@ -333,7 +333,7 @@ def _assign_certified_key_info(bundle):
333333
None.
334334
335335
<Returns>
336-
A public key in the format securesystemslib.formats.GPG_PUBKEY_SCHEMA.
336+
A public key dict.
337337
338338
"""
339339
# Create handler shortcut
@@ -476,8 +476,7 @@ def _get_verified_subkeys(bundle):
476476
None.
477477
478478
<Returns>
479-
A dictionary of public keys in the format
480-
securesystemslib.formats.GPG_PUBKEY_SCHEMA, with keyids as dict keys.
479+
A dict of public keys dicts with keyids as dict keys.
481480
482481
"""
483482
# Create handler shortcut
@@ -601,19 +600,14 @@ def get_pubkey_bundle(data, keyid):
601600
If no master key or subkeys could be found that matches the passed
602601
keyid.
603602
604-
securesystemslib.exceptions.FormatError
605-
If the passed keyid does not match
606-
securesystemslib.formats.KEYID_SCHEMA
607603
608604
<Side Effects>
609605
None.
610606
611607
<Returns>
612-
A public key in the format securesystemslib.formats.GPG_PUBKEY_SCHEMA with
613-
optional subkeys.
608+
A public key dict with optional subkeys.
614609
615610
"""
616-
formats.KEYID_SCHEMA.check_match(keyid)
617611
if not data:
618612
raise KeyNotFoundError(
619613
"Could not find gpg key '{}' in empty exported key " # pylint: disable=consider-using-f-string
@@ -703,9 +697,7 @@ def parse_signature_packet( # pylint: disable=too-many-locals,too-many-branches
703697
None.
704698
705699
<Returns>
706-
A signature dictionary matching
707-
securesystemslib.formats.GPG_SIGNATURE_SCHEMA with the following special
708-
characteristics:
700+
A signature dict with the following special characteristics:
709701
- The "keyid" field is an empty string if it cannot be determined
710702
- The "short_keyid" is not added if it cannot be determined
711703
- At least one of non-empty "keyid" or "short_keyid" are part of the

securesystemslib/gpg/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,5 @@ def gpg_export_pubkey_command(homearg: str, keyid: str) -> List[str]:
131131
PRIMARY_USERID_SUBPACKET = 0x19
132132
# See section 5.2.3.28. (Issuer Fingerprint) of rfc4880bis-06
133133
FULL_KEYID_SUBPACKET = 0x21
134+
135+
GPG_HASH_ALGORITHM_STRING = "pgp+SHA2"

securesystemslib/gpg/dsa.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
CRYPTO = False
2929

3030
# pylint: disable=wrong-import-position
31-
from securesystemslib import exceptions, formats
31+
from securesystemslib import exceptions
3232
from securesystemslib.gpg import util as gpg_util
3333
from securesystemslib.gpg.exceptions import PacketParsingError
3434

@@ -43,13 +43,9 @@ def create_pubkey(pubkey_info):
4343
4444
<Arguments>
4545
pubkey_info:
46-
The DSA pubkey info dictionary as specified by
47-
securesystemslib.formats.GPG_DSA_PUBKEY_SCHEMA
46+
The DSA pubkey dict.
4847
4948
<Exceptions>
50-
securesystemslib.exceptions.FormatError if
51-
pubkey_info does not match securesystemslib.formats.GPG_DSA_PUBKEY_SCHEMA
52-
5349
securesystemslib.exceptions.UnsupportedLibraryError if
5450
the cryptography module is not available
5551
@@ -61,8 +57,6 @@ def create_pubkey(pubkey_info):
6157
if not CRYPTO: # pragma: no cover
6258
raise exceptions.UnsupportedLibraryError(NO_CRYPTO_MSG)
6359

64-
formats.GPG_DSA_PUBKEY_SCHEMA.check_match(pubkey_info)
65-
6660
y = int(pubkey_info["keyval"]["public"]["y"], 16)
6761
g = int(pubkey_info["keyval"]["public"]["g"], 16)
6862
p = int(pubkey_info["keyval"]["public"]["p"], 16)
@@ -93,8 +87,7 @@ def get_pubkey_params(data):
9387
None.
9488
9589
<Returns>
96-
The parsed DSA public key in the format
97-
securesystemslib.formats.GPG_DSA_PUBKEY_SCHEMA.
90+
A DSA public key dict.
9891
9992
"""
10093
ptr = 0
@@ -190,12 +183,10 @@ def verify_signature(signature_object, pubkey_info, content, hash_algorithm_id):
190183
191184
<Arguments>
192185
signature_object:
193-
A signature dictionary as specified by
194-
securesystemslib.formats.GPG_SIGNATURE_SCHEMA
186+
A signature dict.
195187
196188
pubkey_info:
197-
The DSA public key info dictionary as specified by
198-
securesystemslib.formats.GPG_DSA_PUBKEY_SCHEMA
189+
The DSA public key dict.
199190
200191
hash_algorithm_id:
201192
one of SHA1, SHA256, SHA512 (see securesystemslib.gpg.constants)
@@ -207,10 +198,6 @@ def verify_signature(signature_object, pubkey_info, content, hash_algorithm_id):
207198
The signed bytes against which the signature is verified
208199
209200
<Exceptions>
210-
securesystemslib.exceptions.FormatError if:
211-
signature_object does not match securesystemslib.formats.GPG_SIGNATURE_SCHEMA
212-
pubkey_info does not match securesystemslib.formats.GPG_DSA_PUBKEY_SCHEMA
213-
214201
securesystemslib.exceptions.UnsupportedLibraryError if:
215202
the cryptography module is not available
216203
@@ -225,9 +212,6 @@ def verify_signature(signature_object, pubkey_info, content, hash_algorithm_id):
225212
if not CRYPTO: # pragma: no cover
226213
raise exceptions.UnsupportedLibraryError(NO_CRYPTO_MSG)
227214

228-
formats.GPG_SIGNATURE_SCHEMA.check_match(signature_object)
229-
formats.GPG_DSA_PUBKEY_SCHEMA.check_match(pubkey_info)
230-
231215
hasher = gpg_util.get_hashing_class(hash_algorithm_id)
232216

233217
pubkey_object = create_pubkey(pubkey_info)

securesystemslib/gpg/eddsa.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import binascii
2121

22-
from securesystemslib import exceptions, formats
22+
from securesystemslib import exceptions
2323
from securesystemslib.gpg import util as gpg_util
2424
from securesystemslib.gpg.exceptions import PacketParsingError
2525

@@ -65,8 +65,7 @@ def get_pubkey_params(data):
6565
6666
<Returns>
6767
A dictionary with an element "q" that holds the ascii hex representation
68-
of the MPI of an EC point representing an EdDSA public key that conforms
69-
with securesystemslib.formats.GPG_ED25519_PUBKEY_SCHEMA.
68+
of the MPI of an EC point representing an EdDSA public key.
7069
7170
"""
7271
ptr = 0
@@ -163,12 +162,9 @@ def create_pubkey(pubkey_info):
163162
164163
<Arguments>
165164
pubkey_info:
166-
The ED25519 public key dictionary as specified by
167-
securesystemslib.formats.GPG_ED25519_PUBKEY_SCHEMA
165+
The ED25519 public key dict.
168166
169167
<Exceptions>
170-
securesystemslib.exceptions.FormatError if
171-
pubkey_info does not match securesystemslib.formats.GPG_DSA_PUBKEY_SCHEMA
172168
173169
securesystemslib.exceptions.UnsupportedLibraryError if
174170
the cryptography module is unavailable
@@ -181,8 +177,6 @@ def create_pubkey(pubkey_info):
181177
if not CRYPTO: # pragma: no cover
182178
raise exceptions.UnsupportedLibraryError(NO_CRYPTO_MSG)
183179

184-
formats.GPG_ED25519_PUBKEY_SCHEMA.check_match(pubkey_info)
185-
186180
public_bytes = binascii.unhexlify(pubkey_info["keyval"]["public"]["q"])
187181
public_key = pyca_ed25519.Ed25519PublicKey.from_public_bytes(public_bytes)
188182

@@ -197,12 +191,10 @@ def verify_signature(signature_object, pubkey_info, content, hash_algorithm_id):
197191
198192
<Arguments>
199193
signature_object:
200-
A signature dictionary as specified by
201-
securesystemslib.formats.GPG_SIGNATURE_SCHEMA
194+
A signature dict.
202195
203196
pubkey_info:
204-
The DSA public key info dictionary as specified by
205-
securesystemslib.formats.GPG_ED25519_PUBKEY_SCHEMA
197+
A DSA public key dict.
206198
207199
hash_algorithm_id:
208200
one of SHA1, SHA256, SHA512 (see securesystemslib.gpg.constants)
@@ -214,10 +206,6 @@ def verify_signature(signature_object, pubkey_info, content, hash_algorithm_id):
214206
The signed bytes against which the signature is verified
215207
216208
<Exceptions>
217-
securesystemslib.exceptions.FormatError if:
218-
signature_object does not match securesystemslib.formats.GPG_SIGNATURE_SCHEMA
219-
pubkey_info does not match securesystemslib.formats.GPG_ED25519_PUBKEY_SCHEMA
220-
221209
securesystemslib.exceptions.UnsupportedLibraryError if:
222210
the cryptography module is unavailable
223211
@@ -232,9 +220,6 @@ def verify_signature(signature_object, pubkey_info, content, hash_algorithm_id):
232220
if not CRYPTO: # pragma: no cover
233221
raise exceptions.UnsupportedLibraryError(NO_CRYPTO_MSG)
234222

235-
formats.GPG_SIGNATURE_SCHEMA.check_match(signature_object)
236-
formats.GPG_ED25519_PUBKEY_SCHEMA.check_match(pubkey_info)
237-
238223
hasher = gpg_util.get_hashing_class(hash_algorithm_id)
239224

240225
pubkey_object = create_pubkey(pubkey_info)

securesystemslib/gpg/functions.py

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import subprocess # nosec
2121
import time
2222

23-
from securesystemslib import exceptions, formats
23+
from securesystemslib import exceptions
2424
from securesystemslib.gpg.common import (
2525
get_pubkey_bundle,
2626
parse_signature_packet,
@@ -73,9 +73,6 @@ def create_signature(content, keyid=None, homedir=None, timeout=GPG_TIMEOUT):
7373
gpg command timeout in seconds. Default is 10.
7474
7575
<Exceptions>
76-
securesystemslib.exceptions.FormatError:
77-
If the keyid was passed and does not match
78-
securesystemslib.formats.KEYID_SCHEMA
7976
8077
ValueError:
8178
If the gpg command failed to create a valid signature.
@@ -98,8 +95,7 @@ def create_signature(content, keyid=None, homedir=None, timeout=GPG_TIMEOUT):
9895
None.
9996
10097
<Returns>
101-
The created signature in the format:
102-
securesystemslib.formats.GPG_SIGNATURE_SCHEMA.
98+
A signature dict.
10399
104100
"""
105101
if not have_gpg(): # pragma: no cover
@@ -110,7 +106,6 @@ def create_signature(content, keyid=None, homedir=None, timeout=GPG_TIMEOUT):
110106

111107
keyarg = ""
112108
if keyid:
113-
formats.KEYID_SCHEMA.check_match(keyid)
114109
keyarg = (
115110
"--local-user {}".format( # pylint: disable=consider-using-f-string
116111
keyid
@@ -211,12 +206,10 @@ def verify_signature(signature_object, pubkey_info, content):
211206
212207
<Arguments>
213208
signature_object:
214-
A signature object in the format:
215-
securesystemslib.formats.GPG_SIGNATURE_SCHEMA
209+
A signature dict.
216210
217211
pubkey_info:
218-
A public key object in the format:
219-
securesystemslib.formats.GPG_PUBKEY_SCHEMA
212+
A public key dict.
220213
221214
content:
222215
The content to be verified. (bytes)
@@ -238,9 +231,6 @@ def verify_signature(signature_object, pubkey_info, content):
238231
if not CRYPTO: # pragma: no cover
239232
raise exceptions.UnsupportedLibraryError(NO_CRYPTO_MSG)
240233

241-
formats.GPG_PUBKEY_SCHEMA.check_match(pubkey_info)
242-
formats.GPG_SIGNATURE_SCHEMA.check_match(signature_object)
243-
244234
handler = SIGNATURE_HANDLERS[pubkey_info["type"]]
245235
sig_keyid = signature_object["keyid"]
246236

@@ -270,13 +260,12 @@ def export_pubkey(keyid, homedir=None, timeout=GPG_TIMEOUT):
270260
"""Exports a public key from a GnuPG keyring.
271261
272262
Arguments:
273-
keyid: An OpenPGP keyid in KEYID_SCHEMA format.
263+
keyid: An OpenPGP keyid..
274264
homedir (optional): A path to the GnuPG home directory. If not set the
275265
default GnuPG home directory is used.
276266
timeout (optional): gpg command timeout in seconds. Default is 10.
277267
278268
Raises:
279-
ValueError: Keyid is not a string.
280269
UnsupportedLibraryError: The gpg command or pyca/cryptography are not
281270
available.
282271
KeyNotFoundError: No key or subkey was found for that keyid.
@@ -285,7 +274,7 @@ def export_pubkey(keyid, homedir=None, timeout=GPG_TIMEOUT):
285274
Calls system gpg command in a subprocess.
286275
287276
Returns:
288-
An OpenPGP public key object in GPG_PUBKEY_SCHEMA format.
277+
An OpenPGP public key dict.
289278
290279
"""
291280
if not have_gpg(): # pragma: no cover
@@ -294,14 +283,6 @@ def export_pubkey(keyid, homedir=None, timeout=GPG_TIMEOUT):
294283
if not CRYPTO: # pragma: no cover
295284
raise exceptions.UnsupportedLibraryError(NO_CRYPTO_MSG)
296285

297-
if not formats.KEYID_SCHEMA.matches(keyid):
298-
# FIXME: probably needs smarter parsing of what a valid keyid is so as to
299-
# not export more than one pubkey packet.
300-
raise ValueError(
301-
"we need to export an individual key. Please provide a " # pylint: disable=consider-using-f-string
302-
" valid keyid! Keyid was '{}'.".format(keyid)
303-
)
304-
305286
homearg = ""
306287
if homedir:
307288
homearg = (
@@ -330,7 +311,7 @@ def export_pubkeys(keyids, homedir=None, timeout=GPG_TIMEOUT):
330311
"""Exports multiple public keys from a GnuPG keyring.
331312
332313
Arguments:
333-
keyids: A list of OpenPGP keyids in KEYID_SCHEMA format.
314+
keyids: A list of OpenPGP keyids.
334315
homedir (optional): A path to the GnuPG home directory. If not set the
335316
default GnuPG home directory is used.
336317
timeout (optional): gpg command timeout in seconds. Default is 10.
@@ -346,7 +327,7 @@ def export_pubkeys(keyids, homedir=None, timeout=GPG_TIMEOUT):
346327
Calls system gpg command in a subprocess.
347328
348329
Returns:
349-
A dict of OpenPGP public key objects in GPG_PUBKEY_SCHEMA format as values,
330+
A dict of OpenPGP public key dicts as values,
350331
and their keyids as dict keys.
351332
352333

0 commit comments

Comments
 (0)