简体   繁体   English

SunPKCS11 在没有 CKO_CERTIFICATE 的情况下针对 HSM 的使用

[英]SunPKCS11 usage against HSM without CKO_CERTIFICATE

My problem concern the usage of an hsm with Java (openjdk 11.0.12).我的问题涉及 hsm 与 Java (openjdk 11.0.12) 的使用。 Hsm should be use for signature purpose, by SHA512 RSA algorithm. Hsm 应该用于签名目的,通过 SHA512 RSA 算法。 I could be wrong in a lot of the following sentences, I'm totally newbie with HSM & co, so I apologize in advance.我可能在以下很多句子中都错了,我完全是 HSM & co 的新手,所以我提前道歉。

For what I've understand there are three kinds of approaches:据我所知,有三种方法:

1- Using SUNPKCS11 provider 1- 使用 SUNPKCS11 提供程序

2- Using vendor lib (hsm is shipped with a couple of jar, in my case nCipher is shipped with nCipherKM.jar, which should be vendor provider.) 2- 使用供应商库(hsm 附带几个 jar,在我的情况下 nCipher 附带 nCipherKM.jar,它应该是供应商提供者。)

3- openssl (we have some software in c already doing this, I prefer to avoid) 3- openssl(我们在 c 中有一些软件已经这样做了,我宁愿避免)

The usage of vendor lib it's really easy, at least until the Get info call, which send an Unknown Parameter to HardServer, causing an unmarshable exception.供应商库的使用真的很简单,至少在 Get info 调用之前,它向 HardServer 发送一个未知参数,导致不可编组的异常。 This is difficult to debug, communication protocol isn't documented.这很难调试,没有记录通信协议。 Right now I've put this solution aside.现在我已经把这个解决方案放在一边。

In any case I prefer the SUNPKCS11 solution, it doesn't work out of the box for me, but it was simple to debug and analyze.无论如何,我更喜欢 SUNPKCS11 解决方案,它对我来说不是开箱即用的,但是调试和分析很简单。 And should be a standard.并且应该是一个标准。

In this case i'm using European DSS library to interface with PKCS11Provider, making things a little simpler for me to configure and implement.在这种情况下,我使用欧洲 DSS 库与 PKCS11Provider 进行交互,这让我的配置和实现变得更简单一些。

The problem occurs during SunPKCS11 (vanilla) initialization.问题发生在 SunPKCS11(vanilla)初始化期间。

At some point it calls a method "P11Keystore.mapLabels()" that match, according to code and Oracle documentation, all private key handlers (CKA_PRIVATE_KEY) coming from that slot with certificate handlers (CKO_CERTIFICATE), looking for matching between cka_id, in order to build a software in memory keystore with aliases map containing the CKA_LABEL attributes.在某些时候,它调用一个方法“P11Keystore.mapLabels()”,根据代码和 Oracle 文档,该方法匹配来自该插槽的所有私钥处理程序 (CKA_PRIVATE_KEY) 和证书处理程序 (CKO_CERTIFICATE),按顺序查找 cka_id 之间的匹配使用包含 CKA_LABEL 属性的别名映射在内存密钥库中构建软件。 (Private key is unextractable so access is read only https://docs.oracle.com/javase/8/docs/technotes/guides/security/p11guide.html#KeyStoreRestrictions ) (私钥不可提取,因此访问权限为只读https://docs.oracle.com/javase/8/docs/technotes/guides/security/p11guide.html#KeyStoreRestrictions

In signature initialization this private key entry is used to fetch from HSM (by some key attributes that I don't have) the private key handler.在签名初始化中,此私钥条目用于从 HSM(通过我没有的一些关键属性)获取私钥处理程序。

The problem is that my hsm nCipher doesn't expose any object for CKO_CERTIFICATE, so the match returns 0 result and my software keystore is empty.问题是我的 hsm nCipher 没有为 CKO_CERTIFICATE 公开任何对象,所以匹配返回 0 结果并且我的软件密钥库是空的。

When I try to extract the private key handler from keystore I obtain nothing and I cannot initialize Signature object.当我尝试从密钥库中提取私钥处理程序时,我什么也得不到,也无法初始化 Signature 对象。

My predecessor manually wrapped the private key attributes inside a local jks, and rewrote a new provider in order to load certificate from file and not from HSM/PKCS11.我的前任手动将私钥属性包装在本地 jks 中,并重写了一个新的提供程序,以便从文件而不是从 HSM/PKCS11 加载证书。

I dislike this solution, I don't want my application to have configuration depending on HSM certificate.. it's HSM certificate job to handle those keys, not mine.我不喜欢这个解决方案,我不希望我的应用程序根据 HSM 证书进行配置..处理这些密钥是 HSM 证书工作,而不是我的。

Instead, I wrote another provider to fetch and use directly the private key handler, from CKA_PRIVATE_KEY, using a preconfigured CKA_LABEL, bypassing the certificate match.相反,我编写了另一个提供程序来直接从 CKA_PRIVATE_KEY 获取和使用私钥处理程序,使用预配置的 CKA_LABEL,绕过证书匹配。 And it works.它有效。

However I dislike this solution too, it means more maintenance costs for a standard protocol, and the jar must be signed each time, which for me is a nuisance.但是我也不喜欢这个解决方案,这意味着标准协议的维护成本更高,并且每次都必须对 jar 进行签名,这对我来说很麻烦。

I have the feeling that I am approaching the problem from the wrong side, maybe because I'm a noob in the matter.我有一种感觉,我是从错误的方面解决问题的,也许是因为我在这件事上是个菜鸟。

Explanation are over, so here my questions: 1- Am I wrong to claim that CKO_CERTIFICATE is a prerequisite for SunPKCS11?解释已经结束,所以我的问题是: 1- 声称 CKO_CERTIFICATE 是 SunPKCS11 的先决条件我错了吗? 1- Could/Should HSM expose CKO_CERTIFICATE object without malevolent side effects? 1- HSM 可以/应该在没有恶意副作用的情况下公开 CKO_CERTIFICATE 对象吗? 2- Is this missing object a limitation of nCipher HSM or, probably, a configuration missing during installation? 2- 这个丢失的对象是 nCipher HSM 的限制,还是可能是安装过程中丢失的配置? (It works even without so it's a java prerequisite more than an HSM missing) 3- If the CKO_CERTIFICATE cannot be installed and exposed: Is it ok to implement our own provider to obtain the workaround, or could exist a better way to get it working? (即使没有它也能工作,所以它是一个 Java 先决条件,而不是缺少 HSM) 3-如果 CKO_CERTIFICATE 无法安装和公开:是否可以实现我们自己的提供程序以获得解决方法,或者可以存在更好的方法来让它工作?

Sorry for my English, I'm not a native one.对不起我的英语,我不是本地人。 Thanks to those who have come to read up to here and who will answer.感谢那些来到这里阅读并回答的人。

..almost a month later.. ..将近一个月后..

I've finished my application, now I know a lot more about the argument, it works with following modes:我已经完成了我的申请,现在我对这个论点有了更多的了解,它适用于以下模式:

  1. Standard SunPKCS11 against a Docker SoftHSM2 image.针对 Docker SoftHSM2 映像的标准 SunPKCS11。 HSM contains CKO_CERTIFICATE PUBLIC_KEY and PRIVATE_KEY, on the same slot, with same CKA_ID.All works fine and flawless. HSM 包含 CKO_CERTIFICATE PUBLIC_KEY 和 PRIVATE_KEY,位于同一个插槽上,具有相同的 CKA_ID。一切正常且完美无缺。
  2. Custom PKCS11 extension, I have to copy/paste almost every class from java security package (because is Java 11~17 with sun.* packages), just to alter a couple of lines in Certificate retrieving logic, dropping CKO_CERTIFICTE request and loading it by file (crt/p12).自定义 PKCS11 扩展,我必须从 Java 安全包中复制/粘贴几乎每个类(因为是带有 sun.* 包的 Java 11~17),只是为了更改证书检索逻辑中的几行,删除 CKO_CERTIFICTE 请求并通过以下方式加载它文件 (crt/p12)。
  3. P12, containing all information, used as mocked version for local use only. P12,包含所有信息,用作仅供本地使用的模拟版本。

I've tried to extend Bouncy Castle Fips provider, instead of SunPKCS11, without any luck.我试图扩展 Bouncy Castle Fips 提供程序,而不是 SunPKCS11,但没有任何运气。

In the end I think is not possible to accomplish what I need for, the problem is in the server configuration, which is not solvable from a client software.最后,我认为不可能完成我所需要的,问题在于服务器配置,这是无法通过客户端软件解决的。 Anyway I'll fix server configuration, adopting the first working case, dropping custom PKCS11 solution, keeping it just for academic purpose.无论如何,我将修复服务器配置,采用第一个工作案例,删除自定义 PKCS11 解决方案,仅用于学术目的。

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

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