Communicating with HSM python



我正在尝试通过此脚本与远程计算机建立连接。该脚本正在尝试打开会话的远程计算机上运行,我认为作不正确。我正在尝试通过智能卡访问包含密钥库的库opt/PTK/lib/libcryptoki.so中的插槽零(即 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

对我来说非常有效。在连接方面。

import subprocess
proc = subprocess.Popen(("ssh", "remoteuser@host", "echo", "1"), 
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()

最新更新