与HSM python通信

2024-05-04 08:47:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过这个脚本与远程计算机建立连接。脚本正在试图打开会话的远程计算机上运行,我认为我做得不对。我试图访问库opt/PTK/lib/libcryptoki.so中的插槽0,该库通过智能卡(即00000010300000A2)包含密钥库,但是可用的插槽返回零。在

正确的脚本

#!/usr/bin/python
from PyKCS11.LowLevel import *

a = CPKCS11Lib()
info = CK_INFO()
slotInfo = CK_SLOT_INFO()
lib='/opt/PTK/lib/libcryptoki.so'
slotList = ckintlist()

print("Load of " + lib + ": " + str(a.Load(lib, 1)))
a.C_Initialize()
print("C_GetInfo:", hex(a.C_GetInfo(info)))
print("Library manufacturerID:", info.GetManufacturerID())

del info

print("C_GetSlotList(NULL): " + hex(a.C_GetSlotList(0, slotList)))
print("\tAvailable Slots: " + str(len(slotList)))

输出

ctstat ProtectToolkit C Status Utility 4.3.0 Copyright (c) Safenet, Inc. 2009-2013 ShowAllSlots:4 slots, 4 with tokens Slot ID 0 Description : ProtectServer K5E:00045 Manufacturer : SafeNet Inc. Hardware Version : 65.00 Firmware Version : 3.20 Token for Slot ID 0 Label : CKM Manufacturer : SafeNet Inc. Model : K5E:PL25 Serial Number : 502152:00045 Hardware Version : 65.00 Firmware Version : 3.20


Tags: info脚本远程soversionlib计算机ck