与HSM python通信

时间:2016-07-07 12:40:24

标签: python smartcard pkcs#11 hsm

我正在尝试通过此脚本与远程计算机建立连接。该脚本正在尝试打开会话的远程计算机上运行,​​我相信我做错了。我正在尝试通过智能卡访问包含密钥库的库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

1 个答案:

答案 0 :(得分:0)

这对我来说很有效。在连接方面。

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