Softhsm2的安装和使用

windows版本安装:

win下有两种方式:一种是msi安装方式,一种是压缩包方式。

方法很简单,详情请参照Github地址

SoftHSM2 for Windows
====================

SoftHSM is an implementation of a cryptographic store accessible through 
a PKCS#11 interface. You can use it to explore PKCS#11 without having 
a Hardware Security Module. It is being developed as a part of the OpenDNSSEC 
project:

  https://www.opendnssec.org/softhsm/

This package includes both 32-bit and 64-bit build of SoftHSM 2.5.0 statically 
linked to OpenSSL 1.1.1. Latest version of SoftHSM2 for Windows can be 
downloaded from:

  https://github.com/disig/SoftHSM2-for-Windows

SoftHSM2 searches for its configuration file in the following locations:

  1. Path specified by SOFTHSM2_CONF environment variable
  2. User specific path %HOMEDRIVE%%HOMEPATH%\softhsm2.conf
  3. File softhsm2.conf in the current working directory

Following modifications of environment variables are required before using 
portable (not installed from MSI) version extracted in C:\SoftHSM2\ directory:

  set SOFTHSM2_CONF=C:\SoftHSM2\etc\softhsm2.conf
  set PATH=%PATH%;C:\SoftHSM2\lib\

First token can be initialized with PKCS#11 function C_InitToken or with 
the following command:

  softhsm2-util.exe --init-token --slot 0 --label "My token 1"

不要忘记配置环境变量SOFTHSM2_CONF,使用的时候,找到softhsm2-util.exe。在命令行中运行。

Ubuntu版本安装

该版本的下载地址为:此处

安装过程如下:

需要一些依赖包automake、autoconf、libtool安装

主要代码如下:

curl -OL http://ftpmirror.gnu.org/automake/automake-1.14.tar.gz 
tar -xzf automake-1.14.tar.gz 
cd automake-1.14 
./configure && make && sudo make install   

curl -OL http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz 
tar -xzf libtool-2.4.2.tar.gz 
cd libtool-2.4.2 
./configure && make && sudo make install

automake安装比较复杂一点儿

curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-2.69.tar.gz 
tar -xzf autoconf-2.69.tar.gz 
cd autoconf-2.69 
./configure && make && sudo make install   

可能出现的问题:

help2man :dan't get '--help' info from automake-1.14

Try '-no-discard-stderr' if option ouyputs to stderr

Makefile:3707:recipe for target 'doc/automake-1.14.1'failed

make:***[doc/qutomake-1.14.1]Error 255

解决方法:

在Makefile   3707行处加上,-no-discard-stderr 如下面代码所示

doc/aclocal-$(APIVERSION).1: $(aclocal_script) lib/Automake/Config.pm
                $(update_mans) aclocal-$(APIVERSION)
        doc/automake-$(APIVERSION).1: $(automake_script) lib/Automake/Config.pm
                $(update_mans) automake-$(APIVERSION) --no-discard-stderr

运行make&&sudo make install  进行编译。

提醒(千万不能用configure)

下面步入主题进行softhsm安装

1.下载安装包:

wget https://dist.opendnssec.org/source/softhsm-2.3.0.tar.gz

2.解压缩

tar -xzf softhsm-2.3.0.tar.gz

3.

./configure

可能会提示一些问题:

例如:configure:error:OpenSSL library has no GOST support

这个问题的解决方法很简单:

./configure --disable-gost
sudo make install

4.

sudo apt-get install openssl

然后安装:

sudo apt-get install libssl-dev

安装这个可能是由于版本号,不符合产生问题。

下列软件包有未满足的依赖关系:
libssl-dev : 依赖: libssl1.0.0 (= 1.0.1f-1ubuntu2.18) 但是 1.0.1f-1ubuntu9.8 正要被安装
              推荐: libssl-doc 但是它将不会被安装
E: 无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系。

解决方法如下:


原因:
    已安装的libssl1.0.0版本太高, 无法支持

-----(查看当前libssl-dev版本情况)

richer@ubuntu1804:~$ dpkg -l *libssl*
期望状态=未知(u)/安装(i)/删除(r)/清除(p)/保持(h)
| 状态=未安装(n)/已安装(i)/仅存配置(c)/仅解压缩(U)/配置失败(F)/不完全安装(H)/触发器等待(W)/触发器未决(T)
|/ 错误?=(无)/须重装(R) (状态,错误:大写=故障)
||/ 名称           版本         架构:       描述
+++-==============-============-============-=================================
ii  libssl1.0.0:am 1.0.1f-1ubun amd64        Secure Sockets Layer toolkit - sh


=============解决方案(注意选项)============

1.( 安装aptitude )使用aptitude软件包管理器
    

richer@ubuntu1804:~$ sudo apt-get install aptitude
2. 使用aptitude安装 libssl-dev包, 采用建议的解决方案(将libssl1.0.0版本降级)

richer@ubuntu1804:~$ sudo aptitude install libssl-dev
下列“新”软件包将被安装。         
  libssl-dev{b} libssl-doc{a} 
0 个软件包被升级,新安装 2 个, 0 个将被删除, 同时 74 个将不升级。
需要获取 2,036 kB 的存档。 解包后将要使用 7,819 kB。
下列软件包存在未满足的依赖关系:
libssl-dev : 依赖: libssl1.0.0 (= 1.0.1f-1ubuntu2.18) 但是 1.0.1f-1ubuntu9.8 已安装。
下列动作将解决这些依赖关系:

     保持 下列软件包于其当前版本:
1)     libssl-dev [未安装的]      

是否接受该解决方案?[Y/n/q/?] n
下列动作将解决这些依赖关系:

     降级 下列软件包:                                                          
1)     libssl1.0.0 [1.0.1f-1ubuntu9.8 (now) -> 1.0.1f-1ubuntu2.18 (trusty-securi

是否接受该解决方案?[Y/n/q/?] y
下列软件包将被“降级”:
  libssl1.0.0 
下列“新”软件包将被安装。
  libssl-dev libssl-doc{a} 
0 个软件包被升级,新安装 2 个, 1 个被降级, 0 个将被删除, 同时 74 个将不升级。
需要获取 2,866 kB 的存档。 解包后将要使用 7,783 kB。
您要继续吗?[Y/n/?] y

5.make

6.sudo make install

7.配置文件:

export SOFTHSM2_CONF=/etc/softhsm2.conf

然后进行初始化token

softhsm2-util --init-token --slot 0 --label "My token 1"

但是这时会出现问题:

ERROR:Could not initialize the PKCS#11 library/module:/usr/local/lib/softhsm/libsofthsm2.so

ERROR:Please check log files for additional information

原因可能是:

在将令牌初始化为非root用户时,我们总是尝试访问默认的/etc/softhsm/softhsm2.conf,它指向暂存在/var/lib/softhsm/tokens下的令牌,该令牌的所有权/权限被限制为root及其相关组使用。
修改/var/lib/softhsm/tokens的所有权/权限并不能解决问题,因为我们不能访问/etc/softhsm/softhsm2.conf。

解决方案:

cd $HOME
mkdir -p $HOME/lib/softhsm/tokens
cd $HOME/lib/softhsm/
echo "directories.tokendir = $PWD/tokens" > softhsm2.conf
export SOFTHSM2_CONF=$HOME/lib/softhsm/softhsm2.conf

$ softhsm2-util --init-token --slot 0 --label "test" --so-pin 5462 --pin 8764329

最后会祝成功!!!!!!!!!!!!!

猜你喜欢

转载自blog.csdn.net/zhuiyunzhugang/article/details/112146837