Mac 使用 softhsm

发布于:2025-09-07 ⋅ 阅读:(14) ⋅ 点赞:(0)

Mac 使用 softhsm

卸载

由于 brew 安装 softhsm 使用的是 boringssl,java 使用通过 JSP 调用 softhsm 会报如下的错误。

Assertion failed: (ret == 0), function digest_final, file boringssl_crypto_digests.m, line 41.

我们需要卸载已安装的 softhsm(如果是通过 brew 安装的话)。

brew unistall softhsm

注意: 我们 jar 程序会引用 /opt/homebrew/lib/softhsm/libsofthsm2.so,卸载后此路径会失效,所以需要重新链接。

安装必要依赖

brew install automake libtool pkg-config cppunit openssl

编译 softhsm

请在本地合理安排位置,将 https://github.com/softhsm/SoftHSMv2 进行 clone,分支默认 develop 即可。

git clone git@github.com:softhsm/SoftHSMv2.git
cd SoftHSMv2
./autogen.sh
./configure --with-openssl=$(brew --prefix openssl)
make
sudo make install

注意:自行编译后,所需依赖位置: /usr/local/lib/softhsm/libsofthsm2.so

(可选)链接

注意: 我们 jar 程序会引用 /opt/homebrew/lib/softhsm/libsofthsm2.so,卸载后此路径会失效,所以需要重新链接。

ln -s [源文件或目录] [目标文件或目录]

mkdir -p /opt/homebrew/lib/softhsm/
ln -s /usr/local/lib/softhsm /opt/homebrew/lib

生成 slot

softhsm2-util --init-token --slot 0 --label test --pin 123456 --so-pin 123456

在 java 上使用 JSP 以 PKCS11 协议加载 softhsm。

--
name = SoftHSM
library = /opt/homebrew/lib/softhsm/libsofthsm2.so
slot = {SLOT}
attributes(generate, *, *) = {
    CKA_TOKEN = true
}
attributes(generate, CKO_CERTIFICATE, *) = {
    CKA_PRIVATE = false
}
attributes(generate, CKO_PUBLIC_KEY, *) = {
    CKA_PRIVATE = false
}
destroyTokenAfterLogout = false
cleaner.shortInterval = 2000
cleaner.longInterval = 60000

ref

  • https://gist.github.com/mkontani/5b683ffe9508bda0c6c96ee50938225f
  • Install SoftHSM and Access it via Java Program
  • https://github.com/parallaxsecond/rust-cryptoki/issues/191
    Assertion failed: (ret == 0), function digest_final, file boringssl_crypto_digests.m, line 41.

网站公告

今日签到

点亮在社区的每一天
去签到