Featured image of post canokey硬件密钥openpgp配置随笔

canokey硬件密钥openpgp配置随笔

一.windows环境配置

在windows里面一般使用GnuPG作为openpgp实践,我这里使用GnuPG官方推荐使用的Gpg4win作为实现下载地址为

https://gpg4win.org/download.html

安装也很简单直接一直下一步就行。

这里有个很坑的点,就是需要执行以下命令否则git无法识别到你装的gunpg(地址换成你自己的)

1
git config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe"

二.生成你的主密钥

我这里建议使用命令行生成,使用ui生成的话疑似主密钥不会被加密,输入以下命令开始生成

1
 gpg --full-gen-key

然后就会进去交互式命令行页面

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
gpg (GnuPG) 2.4.5; Copyright (C) 2024 g10 Code GmbH
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Please select what kind of key you want:
   (1) RSA and RSA
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
   (9) ECC (sign and encrypt) *default*
  (10) ECC (sign only)
  (14) Existing key from card
Your selection?

这里我个人建议使用rsa算法所以输入1

1
2
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (3072)

这里需要输入密钥长度我个人建议4096

1
2
3
4
5
6
7
Please specify how long the key should be valid.
         0 = key does not expire
      <n>  = key expires in n days
      <n>w = key expires in n weeks
      <n>m = key expires in n months
      <n>y = key expires in n years
Key is valid for? (0)

这里为有效期,0代表不设置有效期,这里请根据需要填写

1
Is this correct? (y/N)

这里是确定信息是否正确这里输入y

1
2
3
Real name: 
Email address: 
Comment: 

这三个分别是名称,邮箱,备注,这里建议和git的邮箱和用户名一致

1
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit?

这里直接输入o

1
2
3
4
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.

显示这个就代表正在生成密钥,建议这个时候快速晃动鼠标,否则可能导致熵池太小,期间会让你输入密码

三.生成签名子密钥

首先使用 gpg --list-secret-keys --keyid-format=long 命令查看用户的id

1
2
3
4
sec   rsa4096/1875E40E3C815509 2024-05-13 [SC]
      5C520F18444882BBFAE578FF1875E40E3C815509
uid                 [ultimate] cangkuai (test) <****>
ssb   rsa4096/24E8A4015EB581E1 2024-05-13 [E]

比如我这里是5C520F18444882BBFAE578FF1875E40E3C815509

使用gpg --expert --edit-key 用户ID 进入编辑页面

使用addkey 命令新建密钥,这里操作和生成主密钥一模一样我就不再赘述了,只是第一步选算法的时候选择(4) RSA (sign only)

生成完成后一定要输入quit来退出否则不保存

四.导入canokey

首先我科普一下canokey符合openpgp智能卡标准,所以他只支持以下功能的子密钥各一个

Signature key(签名)
Encryption key(加密)
Authentication key(身份验证,这个几乎用不到)

在安装Gpg4win的时候自带了一个gui界面叫Kleopatra可以在桌面快捷方式里找到

首先插入canokey,然后切换到智能卡页面,点击重新加载(如果已经加载成功跳过这步) 图片1 在证书页面双击你生成的密钥,点击导出就可以获取你的公钥

在证书页面双击你生成的密钥出现的页面上点击更多详情就可以看到主密钥和子密钥

图片2

五.参考文章

https://blog.moe233.net/posts/18974f8b

https://timberkito.com/?p=141

Licensed under CC BY-NC-SA 4.0
使用 Hugo 构建
主题 StackJimmy 设计
© 2021 ckappblog.com 版权所有
蜀ICP备2021015106号
川公网安备 51010602001393号