与 HSM 通信 python

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()