aboutsummaryrefslogtreecommitdiff
path: root/unit-tests.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2016-11-21 23:36:36 -0500
committerRob Austein <sra@hactrn.net>2016-11-21 23:36:36 -0500
commit15efcdb3e2ebe20c35818447537728c9de2f089f (patch)
tree3dffa84f8e69254043ad088350e13c6010a16382 /unit-tests.py
parent834924b3e4d827f6db03d307a88e23bf95dc4624 (diff)
Whack attribute code with a club until it works with PKCS #11.
PKCS #11 supports zero-length attributes (eg, CKA_LABEL) so hack of using zero length attribute as NIL value won't work, instead we use a slightly more portable version of the hack PKCS #11 uses (PKCS #11 stuffs -1 into a CK_ULONG, we stuff 0xFFFFFFFF into a uint32_t). ks_attribute.c code was trying too hard and tripping over its own socks. Instead of trying to maintain attributes[] in place during modification, we now perform the minimum necessary change then re-scan the block. This is (very slightly) slower but more robust, both because the scan code has better error checking and because it's the scan code that we want to be sure is happy before committing a change. Rename hal_rpc_pkey_attribute_t to hal_pkey_attribute_t.
Diffstat (limited to 'unit-tests.py')
-rw-r--r--unit-tests.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/unit-tests.py b/unit-tests.py
index 8ae9c74..a8779c5 100644
--- a/unit-tests.py
+++ b/unit-tests.py
@@ -594,6 +594,70 @@ class TestPKeyAttribute(TestCaseLoggedIn):
self.load_and_fill(HAL_KEY_FLAG_TOKEN, n_attrs = 4, n_fill = 512) # [16, 1024]
+class TestPKeyAttributeP11(TestCaseLoggedIn):
+ """
+ Attribute creation/lookup/deletion tests based on a PKCS #11 trace.
+ """
+
+ def setUp(self):
+ der = PreloadedKey.db[HAL_KEY_TYPE_EC_PRIVATE, HAL_CURVE_P256].der
+ self.k = hsm.pkey_load(HAL_KEY_TYPE_EC_PRIVATE, HAL_CURVE_P256, der, HAL_KEY_FLAG_TOKEN)
+ self.addCleanup(self.k.delete)
+ super(TestPKeyAttributeP11, self).setUp()
+
+ def test_set_many_attributes(self):
+ self.k.set_attributes({
+ 0x001 : "\x01",
+ 0x108 : "\x01",
+ 0x105 : "\x00",
+ 0x002 : "\x01",
+ 0x107 : "\x00",
+ 0x102 : "\x45\x43\x2d\x50\x32\x35\x36",
+ 0x003 : "\x45\x43\x2d\x50\x32\x35\x36",
+ 0x162 : "\x00",
+ 0x103 : "\x01",
+ 0x000 : "\x03\x00\x00\x00",
+ 0x100 : "\x03\x00\x00\x00",
+ 0x101 : "",
+ 0x109 : "\x00",
+ 0x10c : "\x00",
+ 0x110 : "",
+ 0x111 : "",
+ 0x163 : "\x00",
+ 0x166 : "\xff\xff\xff\xff",
+ 0x170 : "\x01",
+ 0x210 : "\x00",
+ 0x163 : "\x01",
+ 0x166 : "\x40\x10\x00\x00",
+ 0x180 : "\x06\x08\x2a\x86\x48\xce\x3d\x03\x01\x07" })
+
+ def test_set_many_attributes_with_deletions(self):
+ self.k.set_attributes({
+ 0x001 : "\x01",
+ 0x108 : "\x01",
+ 0x105 : "\x00",
+ 0x002 : "\x01",
+ 0x107 : "\x00",
+ 0x102 : "\x45\x43\x2d\x50\x32\x35\x36",
+ 0x003 : "\x45\x43\x2d\x50\x32\x35\x36",
+ 0x162 : "\x00",
+ 0x103 : "\x01",
+ 0x000 : "\x03\x00\x00\x00",
+ 0x100 : "\x03\x00\x00\x00",
+ 0x101 : None,
+ 0x109 : "\x00",
+ 0x10c : "\x00",
+ 0x110 : None,
+ 0x111 : None,
+ 0x163 : "\x00",
+ 0x166 : "\xff\xff\xff\xff",
+ 0x170 : "\x01",
+ 0x210 : "\x00",
+ 0x163 : "\x01",
+ 0x166 : "\x40\x10\x00\x00",
+ 0x180 : "\x06\x08\x2a\x86\x48\xce\x3d\x03\x01\x07" })
+
+
class TestPKeyAttributeWriteSpeedToken(TestCaseLoggedIn):
"""
Attribute speed tests.