Skip to content

Commit 47365e7

Browse files
committed
add support for CKA_MODIFIABLE and CKA_DESTROYABLE attributes
1 parent a841fa7 commit 47365e7

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

PyKCS11/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,8 @@ def isBool(self, type):
13951395
CKA_HAS_RESET,
13961396
CKA_LOCAL,
13971397
CKA_MODIFIABLE,
1398+
CKA_COPYABLE,
1399+
CKA_DESTROYABLE,
13981400
CKA_NEVER_EXTRACTABLE,
13991401
CKA_PRIVATE,
14001402
CKA_RESET_ON_INIT,

src/ck_attribute_smart.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@
102102
case CKA_HAS_RESET:
103103
case CKA_LOCAL:
104104
case CKA_MODIFIABLE:
105+
case CKA_COPYABLE:
106+
case CKA_DESTROYABLE:
105107
case CKA_NEVER_EXTRACTABLE:
106108
case CKA_PRIVATE:
107109
case CKA_RESET_ON_INIT:

src/opensc/pkcs11.h

+2
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,8 @@ typedef unsigned long ck_attribute_type_t;
429429
#define CKA_ALWAYS_SENSITIVE (0x165)
430430
#define CKA_KEY_GEN_MECHANISM (0x166)
431431
#define CKA_MODIFIABLE (0x170)
432+
#define CKA_COPYABLE (0x171)
433+
#define CKA_DESTROYABLE (0x172)
432434
#define CKA_ECDSA_PARAMS (0x180)
433435
#define CKA_EC_PARAMS (0x180)
434436
#define CKA_EC_POINT (0x181)

test/test_objects.py

+35
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,41 @@ def test_objects(self):
9393
template = [(PyKCS11.CKA_HW_FEATURE_TYPE, PyKCS11.CKH_USER_INTERFACE)]
9494
o = self.session.findObjects(template)
9595

96+
def test_BoolAttributes(self):
97+
# dictionary of attributes expected to be bool and their expected values
98+
boolAttributes = {
99+
PyKCS11.CKA_TOKEN : PyKCS11.CK_FALSE,
100+
PyKCS11.CKA_PRIVATE : PyKCS11.CK_FALSE,
101+
# The attributes below are defaulted to CK_TRUE
102+
# ( according to the PKCS#11 standard )
103+
PyKCS11.CKA_MODIFIABLE : PyKCS11.CK_TRUE,
104+
PyKCS11.CKA_COPYABLE : PyKCS11.CK_TRUE,
105+
PyKCS11.CKA_DESTROYABLE : PyKCS11.CK_TRUE,
106+
}
107+
108+
CkoDataTemplate = [
109+
(PyKCS11.CKA_CLASS, PyKCS11.CKO_DATA),
110+
(PyKCS11.CKA_TOKEN, PyKCS11.CK_FALSE),
111+
(PyKCS11.CKA_PRIVATE, PyKCS11.CK_FALSE),
112+
(PyKCS11.CKA_LABEL, "TestData"),
113+
]
114+
115+
# create a CKO_DATA object
116+
ckoData = self.session.createObject(CkoDataTemplate)
117+
self.assertIsNotNone(ckoData)
118+
119+
attrValues = self.session.getAttributeValue(
120+
ckoData, list(boolAttributes.keys())
121+
)
122+
123+
# check that attributes are of bool type
124+
# and have expected values
125+
for i, attr in enumerate(boolAttributes):
126+
self.assertIsInstance(attrValues[i], bool)
127+
self.assertEqual(attrValues[i], boolAttributes[attr])
128+
129+
# clean up
130+
self.session.destroyObject(ckoData)
96131

97132
class TestGetSetAttributeValues(unittest.TestCase):
98133

0 commit comments

Comments
 (0)