【问题标题】:PKCS11 Python FindObjects in available slots可用插槽中的 PKCS11 Python FindObjects
【发布时间】:2016-07-21 21:02:04
【问题描述】:

我用 python 编写了一个从 Cryptoki 库获取信息的脚本。从那里我可以(仅)进行低级 API 调用,例如:

  1. C_getInfo
  2. C_GetSlotList
  3. C_SlotInfo
  4. C_OpenSession
  5. C_GetTokenInfo
  6. C_Logout
  7. C_CloseSession
  8. C_Initialize

这里有几个关于它们的实现的例子

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

for x in range(len(slotList)):
    print("\tC_SlotInfo(): " + hex(a.C_GetSlotInfo(slotList[x], slotInfo)))
    print("\t\tSlot N." + str(x) + ": ID=" + str(slotList[x]) + ", name='" + slotInfo.GetSlotDescription() + "'")
    print("\tC_OpenSession(): " + hex(a.C_OpenSession(slotList[x], CKF_SERIAL_SESSION | CKF_RW_SESSION, session)))
    print("\t\tSession:" + str(session))
    #print("\tMechList:" + hex(a.C_GetMechanismList(0, slotList[x])))
    print("\tC_GetTokenInfo(): " + hex(a.C_GetTokenInfo(slotList[x], tokenInfo)))
    print("\t\tTokenInfo: Label=" + tokenInfo.GetLabel() + ", ManufacturerID=" + tokenInfo.GetManufacturerID())
    print("\t\tTokenInfo: flags=" + hex(tokenInfo.flags) + ", Model=" + tokenInfo.GetModel())

    print("\tC_Login(): " + hex(a.C_Login(session, CKU_USER, pin)))
    print("\t\tSessionInfo: state=" + hex(sessionInfo.state) + ", flags=" + hex(sessionInfo.flags))

问题

我似乎无法弄清楚在插槽列表中查找对象需要什么 api 调用。我有类似print("Finding objects: " + hex(a.C_FindObjects(slotList[x], CKA_CLASS, CKO_CERTIFICATE)))

我不确定要传递哪些参数,或者它的结构是否正确。 我正在使用这个文档LowLevel API pkcs11

最终我试图提取特定的全能智能卡令牌..使用它的私钥和证书来签名和验证数据..

【问题讨论】:

    标签: python-3.x encryption cryptography pkcs#11


    【解决方案1】:
    SearchResult = PyKCS11.LowLevel.ckobjlist(10)
    SearchTemplate = PyKCS11.LowLevel.ckattrlist(0)
    print "C_FindObjectsInit: " + hex(a.C_FindObjectsInit(session,SearchTemplate))
    print "C_FindObjects: " + hex(a.C_FindObjects(session, SearchResult))
    print "C_FindObjectsFinal: " + hex(a.C_FindObjectsFinal(session))
    

    首先,您必须创建一个结果变量并使用它来搜索对象列表。我通过了 10,因为我知道列表中只有少数对象和标记。您可以构造一个模板变量来搜索每个对象的特定属性,例如是否为 Private、Modifiable、Key Type、Encrypt 等。然后您必须调用 (a.C_FindObjectsInit(session,SearchTemplate)) 以通过模板规范初始化会话中的搜索。使用 LowLevel API 可能会令人困惑,几乎没有文档。希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-29
      • 1970-01-01
      • 1970-01-01
      • 2018-02-25
      • 2021-02-06
      • 2021-07-17
      • 1970-01-01
      相关资源
      最近更新 更多