2

再会!ObjectHandle我正在尝试基于来自客户端通过发布请求的十六进制字符串创建公钥。

我正在根据文档进行操作,但它返回给我CKR_ATTRIBUTE_TYPE_INVALID例外。

完整的例外消息:Net.Pkcs11Interop.Common.Pkcs11Exception: 'Method C_CreateObject returned CKR_ATTRIBUTE_VALUE_INVALID'

内部异常为空

你能帮我弄清楚我做错了什么吗?

这是我的代码:

using (Pkcs11 pkcs11 = new Pkcs11(Settings.RutokenEcpDllDefaultPath, AppType.MultiThreaded))
{
    Slot slot = GetSlot(pkcs11);

    // This public key comes from client
    // But i put it here to show value. Maybe value is a reason. I'm not sure, 
    // but i hope you will help me

    var hexString = "1c:ec:2d:4a:b3:51:51:07:f7:c4:f6:d9:09:a3:06:73:c2:06:42:7f:b2:11:fd:be:ad:12:5c:22:b9:df:cb:e5:08:7c:7c:48:a6:af:92:67:d3:56:63:29:0c:9e:1a:4a:0e:d1:08:d8:7a:28:61:bd:da:ed:be:aa:49:84:f2:64";
    hexString = hexString.Replace(":", string.Empty);
    var publicKeyValue = ConvertUtils.HexStringToBytes(hexString);

    using (Session session = slot.OpenSession(SessionType.ReadWrite))
    {
        session.Login(CKU.CKU_USER, Settings.TokenPin);
        List<ObjectAttribute> objectAttributes = new List<ObjectAttribute>();
        objectAttributes.Add(new ObjectAttribute(CKA.CKA_CLASS, CKO.CKO_PUBLIC_KEY));
        objectAttributes.Add(new ObjectAttribute(CKA.CKA_KEY_TYPE, CKK.CKK_GOSTR3410));
        objectAttributes.Add(new ObjectAttribute(CKA.CKA_LABEL, "Verification Key"));
        objectAttributes.Add(new ObjectAttribute(CKA.CKA_VERIFY, true));
        objectAttributes.Add(new ObjectAttribute(CKA.CKA_VALUE, publicKeyValue));
        objectAttributes.Add(new ObjectAttribute(CKA.CKA_TOKEN, true));
        objectAttributes.Add(new ObjectAttribute(CKA.CKA_PRIVATE, false));
        objectAttributes.Add(new ObjectAttribute(CKA.CKA_GOSTR3410_PARAMS, new byte[] { 0x06, 0x07, 0x2a, 0x85, 0x03, 0x02, 0x02, 0x23, 0x00 }));

        // Create object
        ObjectHandle objectHandle = session.CreateObject(objectAttributes);

    }
}
4

2 回答 2

0

通过返回CKR_ATTRIBUTE_VALUE_INVALID您的 PKCS#11 库告诉您您的模板为有效属性指定了无效值。

不幸的是,PKCS#11 API 没有提供导致错误的属性的详细信息,但是许多 PKCS#11 库支持某种内部日志记录机制,这可能会揭示错误的真正原因。启用日志记录所需的确切步骤应包含在 PKCS#11 库供应商提供的文档中。

于 2018-10-15T19:04:10.267 回答
0

GOST 公钥无法导入到 ruToken - 请参阅框中的文档说明。

只是改变

objectAttributes.Add(new ObjectAttribute(CKA.CKA_TOKEN, **true**));

objectAttributes.Add(new ObjectAttribute(CKA.CKA_TOKEN, **false**));

作为令牌对象的公钥只能作为C_GenerateKeyPair调用的结果“创建”。

于 2018-11-06T11:14:26.670 回答