安裝gmssl:
Download (GmSSL-master.zip), uncompress it and go to the source code folder. On Linux and OS X, run the following commands:
https://github.com/guanzhi/GmSSL.git
$ ./config
$ make
$ sudo make install
PATH=$HOME/work/gmbrowser/usr/local/gmssl/bin:$PATH
LD_LIBRARY_PATH=$HOME/work/gmbrowser/usr/local/gmssl/lib:$LD_LIBRARY_PATH
配置
mkdir certs clr newcerts private
touch index.txt
echo “01” > serial
創建的子目錄及文件的含義:
certs:存放已頒發的證書;
newcerts:存放CA指令生成的新證書;
private:存放私鑰;
crl:存放已吊銷的整數;
index.txt:penSSL定義的已簽發證書的文本數據庫文件,這個文件通常在初始化的時候是空的;
serial:證書簽發時使用的序列號參考文件,該文件的序列號是以16進制格式進行存放的,該文件必須提供並且包含一個有效的序列號。
----------------------------------------------------------------------------------------------------------
國密根證書:
gmssl ecparam -genkey -name sm2p256v1 -out private/root-key1.pem
gmssl req -x509 -sm3 -days 365 -key private/rootkey.pem -out newcerts/rootcert.pem
----------------------------------------------------------------------------------------------------------
國密二級證書:
gmssl ecparam -genkey -name sm2p256v1 -out private/ca-key.pem
gmssl req -new -sm3 -key private/ca-key.pem -out ca-csr.pem
cd ..
gmssl ca -md sm3 -extensions v3_ca -in demoCA/ca-csr.pem -out demoCA/newcerts/ca-cert.pem -days 365 -cert demoCA/newcerts/root-cert1.pem -keyfile demoCA/private/root-key1.pem
----------------------------------------------------------------------------------------------------------
用戶證書:
gmssl ecparam -genkey -name sm2p256v1 -out private/user1key.pem
gmssl req -new -sm3 -key private/user1key.pem -out user1csr.pem
cd ..
gmssl ca -in demoCA/user1csr.pem -out demoCA/newcerts/user1cert.pem -days 365 -cert demoCA/newcerts/rootcert.pem -keyfile demoCA/private/rootkey.pem
在簽名二級證書和用戶證書時,兩者的區別:
key usage擴展為Digital Signature, Non-Repudiation, Key Encipherment (e0),證書可以用來加密和簽名
key usage擴展為Digital Signature, Non-Repudiation,沒有加密功能,只能用來簽名。
gmssl 命令中的-md -batch的作用還未找到。
----------------------------------------------------------------------------------------------------------
查看國密證書:
gmssl x509 -text -in newcerts/sub-cacert.pem -noout
----------------------------------------------------------------------------------------------------------
國密證書合成pfx:
gmssl pkcs12 -export -out your_pfx_certificate.pfx -inkey clientguomikey.key -in clientguomi.crt
----------------------------------------------------------------------------------------------------------
遇到問題:
failed to update database
TXT_DB error number 2
原因:
This thing happens when certificates share common data. You cannot have two
certificates that look otherwise the same.
措施:
刪除demoCA下的index.txt,並再touch下