def test_create_rsa_signature(self): global private_rsa global public_rsa data = 'The quick brown fox jumps over the lazy dog'.encode('utf-8') signature, method = pycrypto.create_rsa_signature(private_rsa, data) # Verify format of returned values. self.assertNotEqual(None, signature) self.assertEqual(None, tuf.formats.NAME_SCHEMA.check_match(method), FORMAT_ERROR_MSG) self.assertEqual('RSASSA-PSS', method) # Check for improperly formatted arguments. self.assertRaises(tuf.FormatError, pycrypto.create_rsa_signature, 123, data) self.assertRaises(TypeError, pycrypto.create_rsa_signature, '', data) # Check for invalid 'data'. pycrypto.create_rsa_signature(private_rsa, '') # create_rsa_signature should reject non-string data. self.assertRaises(tuf.FormatError, pycrypto.create_rsa_signature, private_rsa, 123) # Check for missing private key. self.assertRaises(tuf.CryptoError, pycrypto.create_rsa_signature, public_rsa, data)
def test_create_rsa_signature(self): global private_rsa global public_rsa data = 'The quick brown fox jumps over the lazy dog'.encode('utf-8') signature, method = pycrypto.create_rsa_signature(private_rsa, data) # Verify format of returned values. self.assertNotEqual(None, signature) self.assertEqual(None, tuf.formats.NAME_SCHEMA.check_match(method), FORMAT_ERROR_MSG) self.assertEqual('RSASSA-PSS', method) # Check for improperly formatted arguments. self.assertRaises(tuf.FormatError, pycrypto.create_rsa_signature, 123, data) self.assertRaises(TypeError, pycrypto.create_rsa_signature, '', data) # Check for invalid 'data'. self.assertRaises(tuf.FormatError, pycrypto.create_rsa_signature, private_rsa, '') # create_rsa_signature should reject non-string data. self.assertRaises(tuf.FormatError, pycrypto.create_rsa_signature, private_rsa, 123) # Check for missing private key. self.assertRaises(tuf.CryptoError, pycrypto.create_rsa_signature, public_rsa, data)
def test_verify_rsa_signature(self): global public_rsa global private_rsa data = 'The quick brown fox jumps over the lazy dog'.encode('utf-8') signature, method = pycrypto.create_rsa_signature(private_rsa, data) valid_signature = pycrypto.verify_rsa_signature( signature, method, public_rsa, data) self.assertEqual(True, valid_signature) # Check for improperly formatted arguments. self.assertRaises(tuf.FormatError, pycrypto.verify_rsa_signature, signature, 123, public_rsa, data) self.assertRaises(tuf.FormatError, pycrypto.verify_rsa_signature, signature, method, 123, data) self.assertRaises(tuf.FormatError, pycrypto.verify_rsa_signature, 123, method, public_rsa, data) self.assertRaises(tuf.UnknownMethodError, pycrypto.verify_rsa_signature, signature, 'invalid_method', public_rsa, data) # Check for invalid signature and data. # Verify_rsa_signature should reject non-string data. self.assertRaises(tuf.FormatError, pycrypto.verify_rsa_signature, signature, method, public_rsa, 123) self.assertEqual( False, pycrypto.verify_rsa_signature(signature, method, public_rsa, b'mismatched data')) mismatched_signature, method = pycrypto.create_rsa_signature( private_rsa, b'mismatched data') self.assertEqual( False, pycrypto.verify_rsa_signature(mismatched_signature, method, public_rsa, data)) # Verify that a valid public key is needed. self.assertRaises(tuf.CryptoError, pycrypto.verify_rsa_signature, signature, method, 'bad_public_key', data)
def test_verify_rsa_signature(self): global public_rsa global private_rsa data = 'The quick brown fox jumps over the lazy dog'.encode('utf-8') signature, method = pycrypto.create_rsa_signature(private_rsa, data) valid_signature = pycrypto.verify_rsa_signature(signature, method, public_rsa, data) self.assertEqual(True, valid_signature) # Check for improperly formatted arguments. self.assertRaises(tuf.FormatError, pycrypto.verify_rsa_signature, signature, 123, public_rsa, data) self.assertRaises(tuf.FormatError, pycrypto.verify_rsa_signature, signature, method, 123, data) self.assertRaises(tuf.FormatError, pycrypto.verify_rsa_signature, 123, method, public_rsa, data) self.assertRaises(tuf.UnknownMethodError, pycrypto.verify_rsa_signature, signature, 'invalid_method', public_rsa, data) # Check for invalid signature and data. # Verify_rsa_signature should reject non-string data. self.assertRaises(tuf.FormatError, pycrypto.verify_rsa_signature, signature, method, public_rsa, 123) self.assertEqual(False, pycrypto.verify_rsa_signature(signature, method, public_rsa, b'mismatched data')) mismatched_signature, method = pycrypto.create_rsa_signature(private_rsa, b'mismatched data') self.assertEqual(False, pycrypto.verify_rsa_signature(mismatched_signature, method, public_rsa, data))