简体   繁体   English

Sun PKCS#11包装器如何调试CKR_TEMPLATE_INCONSISTENT

[英]Sun PKCS#11 Wrapper how to debug CKR_TEMPLATE_INCONSISTENT

Is there any way how to debug what is causing Sun PKCS#11 wrapper exception?: 有什么方法可以调试导致Sun PKCS#11包装异常的原因:

sun.security.pkcs11.wrapper.PKCS11Exception: CKR_TEMPLATE_INCONSISTENT

I would like to know which attribute of PKCS#11 object is inconsistent and fix it. 我想知道PKCS#11对象的哪个属性不一致并进行修复。

It is quite tricky to find exactly what attribute is missing or provided incorrectly. 准确查找缺少或提供不正确的属性是非常棘手的。 The only way you could fix this is by trial and error. 解决此问题的唯一方法是反复试验。 Since this exception is thrown by the token, it wouldn't be logged, which makes it much difficult to solve. 由于此异常是由令牌抛出的,因此不会被记录下来,这使得解决起来非常困难。

I would recommend first to better understand what type of token you are dealing with. 我建议首先更好地了解您正在处理的令牌类型。 This will give you a better idea of what type of object template it would expect. 这将使您更好地了解期望的对象模板类型。

For example, if the token only allows you to create sensitive keys, if you set the attribute value as false , the token would complain. 例如,如果令牌仅允许您创建sensitive密钥,则如果将属性值设置为false ,则令牌会抱怨。 So you have to try a combination of attributes and see if it succeeds in creating the object. 因此,您必须尝试组合属性,并查看其是否成功创建了对象。

Another thing you could do is, if, the token comes with its own sdk or tools, that can interact with the token and create objects, create a test object using their sdk/tool, and then use the PKCS#11 interface to extract the object and see what template it has. 您可以做的另一件事是,如果令牌随附其自己的sdk或工具,它们可以与令牌交互并创建对象,使用其sdk / tool创建测试对象,然后使用PKCS#11接口提取对象并查看其具有的模板。 You could use this as a base template. 您可以将其用作基本模板。

If it doesn't you can try to create an object starting with a minimal template, with required values, like: 如果不是,则可以尝试以最小的模板开始创建具有所需值的对象,例如:

  • Id (some random value) ID(一些随机值)
  • Label (alias name) 标签(别名)
  • Token (true recommended) 令牌(真推荐)
  • Sensitive (true recommended) 敏感(真推荐)
  • Algorithm/Mechanism (CKM_RSA_PKCS_KEY_PAIR_GEN / CKM_AES_KEY_GEN) 算法/机制(CKM_RSA_PKCS_KEY_PAIR_GEN / CKM_AES_KEY_GEN)
  • Key Type (CKK_RSA / CKK_AES) 密钥类型(CKK_RSA / CKK_AES)
  • Value Length (optional) 值长度(可选)
  • Class (optional) 类(可选)

You can use a pkcs11 logging wrapper. 您可以使用pkcs11日志记录包装器。 For instance: https://github.com/Pkcs11Interop/pkcs11-logger 例如: https : //github.com/Pkcs11Interop/pkcs11-logger

You'll need some environment variables: 您将需要一些环境变量:

  • PKCS11_LOGGER_LIBRARY_PATH -> path to the real pkcs11 library PKCS11_LOGGER_LIBRARY_PATH->实际pkcs11库的路径
  • PKCS11_LOGGER_LOG_FILE_PATH -> path to the log file PKCS11_LOGGER_LOG_FILE_PATH->日志文件的路径
  • PKCS11_LOGGER_FLAGS -> flags (take a look at pkcs11-logger README.md PKCS11_LOGGER_FLAGS->标志(看看pkcs11-logger README.md

file) 文件)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM