Skip to content

Commit

Permalink
Remove pubkey arg from spx_keys.create_signature
Browse files Browse the repository at this point in the history
To create a signature the public key is not required.
  • Loading branch information
lukpueh committed Jun 18, 2019
1 parent 335199d commit a67a6b3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 25 deletions.
6 changes: 2 additions & 4 deletions securesystemslib/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,11 +798,9 @@ def create_signature(key_dict, data):
public, private, data, scheme)

elif keytype == 'spx':
public = binascii.unhexlify(public.encode('utf-8'))
private = binascii.unhexlify(private.encode('utf-8'))
sig, scheme = securesystemslib.spx_keys.create_signature(public,
private, data.encode('utf-8'), scheme)

sig, scheme = securesystemslib.spx_keys.create_signature(private,
data.encode('utf-8'), scheme)

elif keytype == 'ecdsa-sha2-nistp256':
sig, scheme = securesystemslib.ecdsa_keys.create_signature(
Expand Down
13 changes: 3 additions & 10 deletions securesystemslib/spx_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def generate_public_and_private():



def create_signature(public_key, private_key, data, scheme):
def create_signature(private_key, data, scheme):
"""
<Purpose>
Return a (signature, scheme) tuple, where the signature scheme is 'spx'
Expand All @@ -125,22 +125,19 @@ def create_signature(public_key, private_key, data, scheme):
>>> data = b'The quick brown fox jumps over the lazy dog'
>>> scheme = 'spx'
>>> signature, scheme = \
create_signature(public, private, data, scheme)
create_signature(private, data, scheme)
>>> SPX_SIG_BYTES_SCHEMA.matches(signature)
True
>>> scheme == 'spx'
True
>>> signature, scheme = \
create_signature(public, private, data, scheme)
create_signature(private, data, scheme)
>>> SPX_SIG_BYTES_SCHEMA.matches(signature)
True
>>> scheme == 'spx'
True
<Arguments>
public:
The spx public key, a simple byte string
private:
The spx private key, a simple byte string
Expand All @@ -163,13 +160,9 @@ def create_signature(public_key, private_key, data, scheme):
A signature dictionary conformat to 'securesystemslib.format.SIGNATURE_SCHEMA'.
"""
# Validate arguments
SPX_PUBLIC_BYTES_SCHEMA.check_match(public_key)
SPX_PRIVATE_BYTES_SCHEMA.check_match(private_key)
securesystemslib.formats.SPX_SIG_SCHEMA.check_match(scheme)

# Signing the 'data' object requires a seed and public key.
# spx.signing.SigningKey.sign() generates the signature.
public = public_key
private = private_key

signature = None
Expand Down
17 changes: 6 additions & 11 deletions tests/test_spx_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ def test_generate_public_and_private(self):


def test_create_signature(self):
global public
global private
data = b'The quick brown fox jumps over the lazy dog'
scheme = 'spx'
signature, scheme = securesystemslib.spx_keys.create_signature(public,
signature, scheme = securesystemslib.spx_keys.create_signature(
private, data, scheme)

# Verify format of returned values.
Expand All @@ -70,16 +69,12 @@ def test_create_signature(self):

# Check for improperly formatted argument.
self.assertRaises(securesystemslib.exceptions.FormatError,
securesystemslib.spx_keys.create_signature, 123, private, data,
scheme)

self.assertRaises(securesystemslib.exceptions.FormatError,
securesystemslib.spx_keys.create_signature, public, 123, data,
securesystemslib.spx_keys.create_signature, 123, data,
scheme)

# Check for invalid 'data'.
self.assertRaises(securesystemslib.exceptions.CryptoError,
securesystemslib.spx_keys.create_signature, public, private, 123,
securesystemslib.spx_keys.create_signature, private, 123,
scheme)


Expand All @@ -88,8 +83,8 @@ def test_verify_signature(self):
global private
data = b'The quick brown fox jumps over the lazy dog'
scheme = 'spx'
signature, scheme = securesystemslib.spx_keys.create_signature(public,
private, data, scheme)
signature, scheme = securesystemslib.spx_keys.create_signature(private,
data, scheme)

valid_signature = securesystemslib.spx_keys.verify_signature(public,
scheme, signature, data)
Expand Down Expand Up @@ -132,7 +127,7 @@ def test_verify_signature(self):

# Generated signature created with different data.
new_signature, scheme = securesystemslib.spx_keys.create_signature(
public, private, b'mismatched data', scheme)
private, b'mismatched data', scheme)

self.assertEqual(False, securesystemslib.spx_keys.verify_signature(
public, scheme, new_signature, data))
Expand Down

0 comments on commit a67a6b3

Please sign in to comment.