Skip to content

Commit 7f62768

Browse files
author
Grant Sowards
committed
pkcs11/_pkcs11.pyx: add support for protected authentication
1 parent c2b9c1f commit 7f62768

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

pkcs11/_pkcs11.pyx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class Slot(types.Slot):
225225
class Token(types.Token):
226226
"""Extend Token with implementation."""
227227

228-
def open(self, rw=False, user_pin=None, so_pin=None):
228+
def open(self, rw=False, user_pin=None, so_pin=None, p_auth=False):
229229
cdef CK_SESSION_HANDLE handle
230230
cdef CK_FLAGS flags = CKF_SERIAL_SESSION
231231
cdef CK_USER_TYPE user_type
@@ -235,6 +235,13 @@ class Token(types.Token):
235235

236236
if user_pin is not None and so_pin is not None:
237237
raise ArgumentsBad("Set either `user_pin` or `so_pin`")
238+
elif user_pin is not None and use_pap:
239+
raise ArgumentsBad("Set either `user_pin` or `p_auth`")
240+
elif so_pin is not None and use_pap:
241+
raise ArgumentsBad("Set either `so_pin` or `p_auth`")
242+
elif p_auth:
243+
pin = None
244+
user_type = CKU_USER
238245
elif user_pin is not None:
239246
pin = user_pin.encode('utf-8')
240247
user_type = CKU_USER
@@ -247,7 +254,12 @@ class Token(types.Token):
247254

248255
assertRV(_funclist.C_OpenSession(self.slot.slot_id, flags, NULL, NULL, &handle))
249256

250-
if pin is not None:
257+
if p_auth:
258+
if self.flags & TokenFlag.PROTECTED_AUTHENTICATION_PATH:
259+
assertRV(_funclist.C_Login(handle, user_type, NULL, < CK_ULONG > 0))
260+
else:
261+
raise ArgumentsBad('Protected authentication is not supported by loaded module')
262+
elif pin is not None:
251263
assertRV(_funclist.C_Login(handle, user_type, pin, <CK_ULONG> len(pin)))
252264

253265
return Session(self, handle, rw=rw, user_type=user_type)

0 commit comments

Comments
 (0)