pkcs#11 内存错误 - 常见原因可能是什么?
我收到使用 cryptoki 库的 C_Encrypt
调用的 CKR_DEVICE_MEMORY
错误代码。
根据 PKCS#11 规范,CKR_DEVICE_MEMORY
表示令牌没有足够的内存来执行请求的功能。
什么情况下,我们的token内存会完全满呢?
HSM 已连续 7 天 24x7 工作,主要在白天通过 2 个并行会话加密和解密文件。我在过去 7 天内没有调用 C_Finalize
。所以 cryptoki 库从初始化起就一直在其内存空间中工作(请参阅有关此的相关文章)。
我可以从我的应用程序、调试日志中看到我正在分配、正在解除分配的任何内容,因此我的应用程序代码中没有内存泄漏。
更新1:有一个
I am getting the CKR_DEVICE_MEMORY
error code for C_Encrypt
call using cryptoki library.
From the PKCS#11 spec, CKR_DEVICE_MEMORY
means The token doesnot have sufficient memory to perform the requested function.
Under what circumstances, do we get the token's memory completely full?
The HSM has been working 24x7 for 7 days continuously mostly encrypting and decrypting files during the day time with 2 parallel sessions. I haven't called C_Finalize
in the last 7 days. so cryptoki library has been working in its memory space from the point it has been initialised(see a related post on this).
I can see from my applications, debug log, what ever, i am allocating, i am deallocating so there is no memory leak from my application code.
UPDATE 1: There is a related detailed discussion on how i can call C_Finalize
in Application_End
of the ASP.NET. The main reason i couldn't use this because after recycling/timeout, the ASP.net threads access a single session resulting in CKR_OPERATION_ACTIVE error. In my case multiple applications are accessing the HSM via a webservice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
让我们分别考虑 HSM 和主机(运行 Cryptoki 库)的内存。如果 HSM 设备内存不足,则正确实现的 Cryptoki 库应返回 CKR_DEVICE_MEMORY;如果 Cryptoki 库无法为其内部结构分配主机内存,则应返回 CKR_HOST_MEMORY(如果它实现为共享库,则进程无法分配内存) 。因此,如果您的 pkcs11 库正确实现,那么 CKR_DEVICE_MEMORY 意味着设备 (HSM) 内存不足。
造成此类错误的原因有很多。我们不能考虑所有分支。可以仅限制某些问题。回答您的问题时,Cryptoki 库中内存问题的三个主要常见原因:
这些估计只是为了说明此类库中内存的一般问题。
Let’s consider the memory of HSM and host computer (which Cryptoki library runs on) separately. Correctly implemented Cryptoki library should return CKR_DEVICE_MEMORY if HSM device suffers from the lack of memory and CKR_HOST_MEMORY if Cryptoki library can’t allocate host computer memory for its internal structures (if it is implemented as a shared library then the process can’t allocate memory). So if your pkcs11 library is implemented correctly then CKR_DEVICE_MEMORY means insufficient device (HSM) memory literally.
There are a lot of reasons of such bugs. We can’t consider all branches. It’s possible to restrict some issues only. Answering your question there are three main common reasons of problems with memory in Cryptoki library:
These estimates are only to illustrate general issues with memory in such libraries.
您此处提到您没有关闭会话。如果这是真的,那么这很可能就是
CKR_DEVICE_MEMORY
的原因。You mention here that you are not closing your sessions. If that is true, that is most probably the cause of the
CKR_DEVICE_MEMORY
s.我也有这个问题,年份是 2020 :S
.Net Framework + Rest Api 这对组合这次遇到了这个问题。
我使用 HSM 进行解密方法。我有一个登录方式的交互频道,我们需要进行性能测试。该服务有一个来自 Pkcs11 的实例
,这是 Decrypt 方法。
公共字节[]解密(字节[]加密的TextByteArray)
{
当我尝试使用 Postman runner 进行性能测试时,一个线程没有问题。
如果我增加线程数,就会出现这些错误。
第一个错误:CKR_OPERATION_ACTIVE
下一个错误:CKR_DEVICE_MEMORY
我尝试了这些方法。
-对于每个请求关闭会话。并且还为新请求打开了会话。但没有成功。出现了同样的错误。 (当然请求和响应时间增加了)
-对于每个请求都关闭了连接。并且还为新请求打开了新连接。出现了同样的错误。 (当然请求和响应时间增加了)
有人帮助我吗? :)
I have also this problem and year is 2020 :S
.Net Framework + Rest Api couple have this problem this time.
I'm using HSM for decrypt method. I have a login method interactive channel, and we need to make performance test. The service has an instance from Pkcs11
And this is the Decrypt method.
public byte[] Decrypt(byte[] encryptedTextByteArray)
{
When I try to make performance test using Postman runner, there is no problem for one thread.
If I increase thread count, It appears these errors.
First error: CKR_OPERATION_ACTIVE
Next error: CKR_DEVICE_MEMORY
I tried these methods.
-For every request closed session. And also opened session for new request. But not succeeed. The same errors appeared. (Of course request and response time increased)
-For evey request closed the conenction. And also opened new connection for new request. The same errors appeared. (Of course request and response time increased)
Anyone helps me? :)