- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
与 Gemalto 网络 HSM 斗争了一段时间,是时候寻求一些专家帮助了。我试图从一个已知的公钥和一个存储在 HSM 上的私钥派生出一个 ECDH1 key ,并不断将 HSM 发送到某种 panic 模式,这需要我在每次调用派生 key 时它再次开始说话之前重置它功能如下。有人有任何指示吗?
static string PKCSLibraryPath = @"C:\Program Files (x86)\SafeNet\Protect Toolkit 5\Protect Toolkit C SDK\bin\hsm\cryptoki.dll";
static Pkcs11 pkc = new Pkcs11(PKCSLibraryPath, AppType.SingleThreaded);
public string HSM_Interaction(int SlotNumber, string KeyLabel, string Pubkey, string GUID)
{
List<Slot> slots = pkc.GetSlotList(SlotsType.WithTokenPresent);
string pass = "1111";
//convert putblic key to byte array
byte[] data = Get_pub_Key(Pubkey);
//convert password to byte array
byte[] password = Encoding.ASCII.GetBytes(pass);
//select correct HSM slot
Slot S = slots[SlotNumber];
using (Session Sesh = S.OpenSession(SessionType.ReadWrite))
{
Sesh.Login(CKU.CKU_USER, password);
List<CKM> Mechs = S.GetMechanismList();
ObjectHandle oPrivKeyObjectHandle;
//setup search criteria for token
List<ObjectAttribute> objectAttributes = new List<ObjectAttribute>();
objectAttributes.Add(new ObjectAttribute(CKA.CKA_CLASS, CKO.CKO_PRIVATE_KEY));
objectAttributes.Add(new ObjectAttribute(CKA.CKA_KEY_TYPE, CKK.CKK_EC));
objectAttributes.Add(new ObjectAttribute(CKA.CKA_LABEL, KeyLabel));
Sesh.FindObjectsInit(objectAttributes);
List<ObjectHandle> oObjCollection = Sesh.FindObjects(1);
Sesh.FindObjectsFinal();
if (oObjCollection.Count > 0)
{
oPrivKeyObjectHandle = oObjCollection[0];
//set template for generated key
var shared_secret_template = new List<ObjectAttribute>
{
new ObjectAttribute(CKA.CKA_CLASS, CKO.CKO_SECRET_KEY),
new ObjectAttribute(CKA.CKA_KEY_TYPE, CKK.CKK_GENERIC_SECRET),
new ObjectAttribute(CKA.CKA_SENSITIVE, false),
new ObjectAttribute(CKA.CKA_EXTRACTABLE, true),
new ObjectAttribute(CKA.CKA_VALUE_LEN, (ulong)32)
};
var deriveAttributes = new List<ObjectAttribute>
{
new ObjectAttribute(CKA.CKA_TOKEN, false),
new ObjectAttribute(CKA.CKA_CLASS, CKO.CKO_SECRET_KEY),
new ObjectAttribute(CKA.CKA_KEY_TYPE, CKK.CKK_GENERIC_SECRET),
new ObjectAttribute(CKA.CKA_SENSITIVE, false),
new ObjectAttribute(CKA.CKA_EXTRACTABLE, true),
new ObjectAttribute(CKA.CKA_ENCRYPT, true),
new ObjectAttribute(CKA.CKA_DECRYPT, true),
new ObjectAttribute(CKA.CKA_WRAP, true),
new ObjectAttribute(CKA.CKA_UNWRAP, true),
new ObjectAttribute(CKA.CKA_VALUE_LEN, (ulong)32)
};
try
{
//generate derived key
byte[] sd = null;
CkEcdh1DeriveParams par = new CkEcdh1DeriveParams((ulong)CKD.CKD_NULL, sd, data);
par.ToMarshalableStructure();
Mechanism m = new Mechanism(CKM.CKM_ECDH1_DERIVE, par);
Sesh.DeriveKey(m, oPrivKeyObjectHandle, deriveAttributes);
ObjectHandle SSOH = new ObjectHandle();
Sesh.GetAttributeValue(SSOH,deriveAttributes);
}
catch (Exception ex)
{
string error = ex.Message;
}
finally
{
Sesh.Logout();
}
}
}
return "";
}
private byte[] Get_SHA256(string text)
{
byte[] bytes = Encoding.UTF8.GetBytes(text);
SHA256Managed hashstring = new SHA256Managed();
byte[] hash = hashstring.ComputeHash(bytes);
string hashString = string.Empty;
foreach (byte x in hash)
{
hashString += String.Format("{0:x2}", x);
}
return hash;
}
private byte[] Get_pub_Key(string text)
{
byte[] Bytes = new byte[65];
int startpos = 0;
for (int i = 0; i < (text.Length / 2); i++)
{
byte b = Convert.ToByte(text.Substring(startpos, 2), 16);
Bytes[i] = b;
startpos += 2;
}
return Bytes;
}
}
Net.Pkcs11Interop.Common.Pkcs11Exception: 'Method C_DeriveKey returned 2147484548'
Mar 21 07:59:10 hsm1 kernel: ERR: viper0: _do_smachine: hsm kernel crashed
Mar 21 07:59:10 hsm1 kernel: ERR: viper0: _do_smachine: device error
Mar 21 07:59:10 hsm1 kernel: NOTE: viper0: HSM is being shut down, discarding pending requests...
Mar 21 07:59:10 hsm1 kernel: NOTE: viper0: DMA buffers: 0000
Mar 21 07:59:10 hsm1 kernel: NOTE: viper0: HSM commands: 0001
Mar 21 07:59:10 hsm1 kernel: NOTE: viper0: Callback requests: 0000
Mar 21 07:59:10 hsm1 etnetserver[990]: MDV2_SendReceiveCmd(): MD_SendReceive()
error: Internal error - unknown error
最佳答案
您得到的异常表示低级 PKCS#11 函数 C_DeriveKey
返回供应商特定错误 0x80000384
( 2147484548
dec) 称为 CKR_SMS_ERROR
.您需要讨论设备供应商提供的文档或联系供应商支持,以更好地了解如何处理或避免此特定错误。
这个确切的错误 was also discussed in an older question它是由在多线程环境中错误使用 PKCS#11 API 引起的。
关于pkcs#11 - PCKS11interop 和 Safenet Network HSM 的 ECDH1_DERIVE 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49383728/
我正在使用 Microsoft.Office.Interop.Outlook 提取电子邮件附件: var MAPI = new Application().GetNamespace("MAPI");
突然得到一个 System.invalidcastexception: unable to cast COM object of type 'system._object' to interface
我正在尝试在兼容的渲染目标上使用 Gdi 和 Direct 2D 来渲染位图。我使用 D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_GDI_COMPATIBLE 选项创建
完整错误: Could not load file or assembly 'Interop.Microsoft.Office.Interop.Word' or one of its dependen
我正在尝试寻找一种使用 Office.Interop.Outlook COM 对象连接到其他邮箱的方法。目前我正在执行以下操作(在添加 COM 对象之后): var app = new Microso
我有一个用 C# 编写的应用程序,该应用程序当前向 LDAP 进行身份验证。我们希望扩展功能以支持 IBM 的 Tivoli Access Manager,它由一个策略服务器和一个 LDAP 服务器(
在 Visual Studio 中将 interop.excel 引用添加到我的 C# winform 后,我无法再“编辑并继续”...... 错误提示“正在修改“方法” ' 包含嵌入式互操作类型/成
我正在尝试创建 Excel 文件的 Worksheet 数组,但找不到正确的转换。 这是代码: Excel.Application app = new Excel.Application(); Exc
我正在使用 C# Interop 从工作表中获取一些值,但出现以下错误: Non-invocable member 'Microsoft.Office.Interop.Excel.Range.End'
我在 MVC 桌面应用程序中使用 Nuget 包 System.Data.SQLite。当我尝试清理解决方案时出现错误。我收到的错误消息是:无法删除文件“...bin\Debug\x64\SQLite
序列化异常:程序集“Microsoft.Office.Interop.Excel,Version=11.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e
我正在通过命令行将 magento 2.1.8 升级到 2.3.3,当我运行 composer update 命令时它显示以下错误。 包 container-interop/container-int
我正在尝试从 C# 控制台应用程序中的 Excel 中捕获一些数据。 我得到了错误 Unable to cast COM object of type 'microsoft.Office.Intero
我收到一个错误: Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' to inte
我刚刚下载了 MS Visual Studio 2010 解决方案并收到该错误。 Error 1 Assembly 'Microsoft.Office.Interop.Word, Version=15
我尝试为 socket.io 编写一个绑定(bind)。 我在使用函数(底部示例代码中的 next())时遇到问题,该函数要么不带参数,要么带有错误对象( Js.Exn.raiseError("ERR
在 C++/CLI 中,是否可以固定不包含元素的数组? 例如 array^ bytes = gcnew array(0); pin_ptr pin = &bytes[0]; //。您可以回退到 GCH
我目前正在从事一个项目,该项目包含几种不同的“编程”语言,每种语言都有自己的命名约定。应该始终使用相同的命名约定,还是应该在每种语言中使用不同的名称以具有原生外观(即不与框架的其余部分冲突)? 例如,
我是Clojure和Java的新手。 为了访问Clojure中的Java字段,您可以执行以下操作: Classname/staticField 就是一样的 (. Classname staticFie
我想提取word文档中的项目符号信息。我想要这样的东西:假设下面的文字在 word 文档中: 启动汽车的步骤: 开门 坐在里面 关上门 插入 key 等等 然后我想要我的文本文件如下: 启动汽车的步骤
我是一名优秀的程序员,十分优秀!