Skip to content

Commit eeabc68

Browse files
authored
Merge pull request #11 from kommendorkapten/correct_key_id
2 parents e905b27 + ca60489 commit eeabc68

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

securesystemslib/signer/_azure_signer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def __init__(self, az_key_uri: str, public_key: Key):
8585
"Key %s has unsupported key type or unsupported elliptic curve"
8686
)
8787
raise e
88+
self.public_key = public_key
8889

8990
@staticmethod
9091
def _get_key_vault_key(
@@ -270,4 +271,4 @@ def sign(self, payload: bytes) -> Signature:
270271
# pyca/cryptography
271272
dss_sig_value = encode_dss_signature(r, s).hex()
272273

273-
return Signature(response.key_id, dss_sig_value)
274+
return Signature(self.public_key.keyid, dss_sig_value)

tests/check_azure_signer.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""
2+
This module confirms that signing using Azure KMS keys works.
3+
4+
The purpose is to do a smoke test, not to exhaustively test every possible
5+
key and environment combination.
6+
7+
For Azure, the requirements to successfully test are:
8+
* Azure authentication details have to be available in the environment
9+
* The key defined in the test has to be available to the authenticated user
10+
11+
NOTE: the filename is purposefully check_ rather than test_ so that tests are
12+
only run when explicitly invoked.
13+
"""
14+
15+
import unittest
16+
17+
from securesystemslib.exceptions import UnverifiedSignatureError
18+
from securesystemslib.signer import AzureSigner, Key, Signer
19+
20+
21+
class TestAzureKeys(unittest.TestCase):
22+
"""Test that KMS keys can be used to sign."""
23+
24+
azure_pubkey = Key.from_dict(
25+
"8b4af6aec66518bc66718474aa15c8becd3286e8e2b958c497a60a828d591d04",
26+
{
27+
"keytype": "ecdsa",
28+
"scheme": "ecdsa-sha2-nistp256",
29+
"keyval": {
30+
"public": "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE95qxD+/kX6oCace7hrfChtz2IYGK\nHNBmUwtf3wXH0VEdLPWVoFgGITonvA7vxqYrF8ZzAeeZYNyEBbod7SEeaw==\n-----END PUBLIC KEY-----\n"
31+
},
32+
},
33+
)
34+
azure_id = "azurekms://fsn-vault-1.vault.azure.net/keys/ec-key-1/b1089bbf068742d483970282f02090de"
35+
36+
def test_azure_sign(self):
37+
"""Test that Azure KMS key works for signing
38+
39+
Note that this test requires valid credentials available.
40+
"""
41+
42+
data = "data".encode("utf-8")
43+
44+
signer = Signer.from_priv_key_uri(self.azure_id, self.azure_pubkey)
45+
sig = signer.sign(data)
46+
47+
print(sig.signature)
48+
49+
self.azure_pubkey.verify_signature(sig, data)
50+
with self.assertRaises(UnverifiedSignatureError):
51+
self.azure_pubkey.verify_signature(sig, b"NOT DATA")
52+
53+
def test_azure_import(self):
54+
"""Test that Azure KMS key works for signing
55+
56+
Note that this test requires valid credentials available.
57+
"""
58+
59+
uri, pubkey = AzureSigner.import_("fsn-vault-1", "ec-key-1")
60+
61+
self.assertEqual(pubkey, self.azure_pubkey)
62+
self.assertEqual(uri, self.azure_id)
63+
64+
65+
if __name__ == "__main__":
66+
unittest.main(verbosity=1, buffer=True)

0 commit comments

Comments
 (0)