前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Windows 通过命令行安装根证书

Windows 通过命令行安装根证书

作者头像
战神伽罗
发布2020-06-29 10:52:08
5K0
发布2020-06-29 10:52:08
举报

证书链的原理:

根证书自签名,而其他证书的公钥使用根证书的公钥验证,验证通过的则子证书有效,子证书则可以发行下一个分支。

有的时候我们需要在用户机器上将自制的 CA 证书安装到“受信任的根证书颁发机构”下,这样就能使用该 CA 颁发自签名的证书了,以便后续完成一些安全相关的操作。

工具

在命令行安装证书需要用到证书管理器 certmgr.exe,这个二进制可执行文件在 Win10 中 大概 这个路径下,C:\Program Files (x86)\Windows Kits\8.1\bin\x86\certmgr.exe,建议把这个二进制打在程序的发布包中,或者让程序从网络上拉取到本地。

certmgr.exe

可以通过该工具实现证书的管理操作:

D:\>certmgr.exe /?
Usage: CertMgr [options][-s [-r <location>][SourceStoreName]
                        [-s [-r <location>][DestinationStoreName]
Options:
 -add               Add certificates/CRLs/CTLs to a storeFile or a system store
 -del               Delete certificates/CRLs/CTLs from a storeFile or
                    a system store
 -put               Put an encoded certificate/CRL/CTL from a storeFile or
                    a system store to a file.  The file will be saved in X.509
                    format. -7 can be used to save the file in PKCS #7 format
 -s                 Indicate the store is a system store
 -r    <location>   The system store location
                        <currentUser|localMachine> Default to 'currentUser'
 -c                 Certificates in the store
 -crl               Certificates revocation lists(CRLs) in the store
 -ctl               Certificates trust lists(CTLs) in the store
 -v                 Verbose display of the certificates/CRLs/CTLs
 -all               All certificates/CRLs/CTLs in the store
 -n    <name>       Common name of the certificate
 -sha1 <thumbPrint> The sha1 hash of the certificate/CRLs/CTLs
 -7                 Save the destination store in PKCS #7 format
 -e    <encode>     Certificate/CRL/CTL encoding type.
                    Default to X509_ASN_ENCODING
 -f    <flag>       CertStore open flags.  Meaningful only if -y is set
 -y    <provider>   CertStore provider name

我们的目标是将 CA 证书导入到“受信任的根证书颁发机构”下,可以通过如下命令参数实现:certmgr.exe /c /add ca.crt /s root

导入之前可以通过 certmgr.exe /all /s root 来查询是否已经导入过。

结论

  • certmgr.exe 需要自己分发到确定的路径下再调用
  • 作为用户不要轻易安装来历不明的证书
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 证书链的原理:
  • 工具
  • certmgr.exe
  • 结论
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档