我有多个用于签名和加密的子密钥。这是我的公钥和私钥列表。
jeremy@localhost ~
$ gpg -k
/home/jeremy/.gnupg/pubring.gpg
-------------------------------
pub 4096R/35E40FA7 2015-04-14
uid keybase.io/jeremytwfortune <[email protected]>
uid Jeremy Fortune <[email protected]>
uid Jeremy Fortune <[email protected]>
sub 2048R/73671EAD 2015-04-14 [expires: 2023-04-12]
sub 2048R/0690427C 2015-04-14 [expires: 2023-04-12]
sub 4096R/AEE9FB5F 2015-12-06 [expires: 2025-12-03]
sub 4096R/757D1A1D 2015-12-06 [expires: 2025-12-03]
sub 2112R/9B5BAC36 2015-12-06 [expires: 2025-12-03]
sub 4096R/5A8F548A 2015-12-06 [expires: 2025-12-03]
jeremy@localhost ~
$ gpg -K
/home/jeremy/.gnupg/secring.gpg
-------------------------------
sec 4096R/35E40FA7 2015-04-14
uid keybase.io/jeremytwfortune <[email protected]>
ssb 2048R/73671EAD 2015-04-14
ssb 2048R/0690427C 2015-04-14
当我给自己加密消息时,会使用最新的加密密钥 (9b5bac36)。这似乎没问题,因为它是一个子密钥,但在解密时,gpg 仍然只寻找该私钥。它甚至不会尝试使用 0690427c。
jeremy@localhost ~
$ echo -e "\nAn encrypted message." | gpg -vver 35e40fa7 | gpg -vvd
gpg: using subkey 9B5BAC36 instead of primary key 35E40FA7
gpg: using PGP trust model
gpg: key 35E40FA7: accepted as trusted key
gpg: checking the trustdb
gpg: 1 keys cached (11 signatures)
gpg: 1 keys processed (0 validity counts cleared)
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
gpg: This key belongs to us
gpg: reading from `[stdin]'
gpg: writing to stdout
gpg: RSA/AES256 encrypted for: "9B5BAC36 keybase.io/jeremytwfortune <[email protected]>"
:pubkey enc packet: version 3, algo 1, keyid 743409AA9B5BAC36
data: [2111 bits]
gpg: public key is 9B5BAC36
:encrypted data packet:
length: 76
mdc_method: 2
gpg: using subkey 9B5BAC36 instead of primary key 35E40FA7
gpg: encrypted with 2112-bit RSA key, ID 9B5BAC36, created 2015-12-06
"keybase.io/jeremytwfortune <[email protected]>"
gpg: decryption failed: secret key not available
当我撤销较新的加密密钥时,一切都按预期进行。
jeremy@localhost ~
$ gpg -k
/home/jeremy/.gnupg/pubring.gpg
-------------------------------
pub 4096R/35E40FA7 2015-04-14
uid keybase.io/jeremytwfortune <[email protected]>
uid Jeremy Fortune <[email protected]>
uid Jeremy Fortune <[email protected]>
sub 2048R/73671EAD 2015-04-14 [expires: 2023-04-12]
sub 2048R/0690427C 2015-04-14 [expires: 2023-04-12]
sub 4096R/AEE9FB5F 2015-12-06 [expires: 2025-12-03]
sub 4096R/5A8F548A 2015-12-06 [expires: 2025-12-03]
jeremy@localhost ~
$ echo -e "\nAn encrypted message." | gpg -vver 35e40fa7 | gpg -vvd
gpg: using subkey 0690427C instead of primary key 35E40FA7
gpg: using PGP trust model
gpg: key 35E40FA7: accepted as trusted key
gpg: This key belongs to us
gpg: reading from `[stdin]'
gpg: writing to stdout
gpg: RSA/AES256 encrypted for: "0690427C keybase.io/jeremytwfortune <[email protected]>"
:pubkey enc packet: version 3, algo 1, keyid 60A3F13E0690427C
data: [2045 bits]
gpg: public key is 0690427C
gpg: no secret subkey for public subkey AEE9FB5F - ignoring
gpg: no secret subkey for public subkey 5A8F548A - ignoring
gpg: using subkey 0690427C instead of primary key 35E40FA7
You need a passphrase to unlock the secret key for
user: "keybase.io/jeremytwfortune <[email protected]>"
gpg: using subkey 0690427C instead of primary key 35E40FA7
2048-bit RSA key, ID 0690427C, created 2015-04-14 (main key ID 35E40FA7)
gpg: gpg-agent is not available in this session
gpg: public key encrypted data: good DEK
:encrypted data packet:
length: 76
mdc_method: 2
gpg: encrypted with 2048-bit RSA key, ID 0690427C, created 2015-04-14
"keybase.io/jeremytwfortune <[email protected]>"
gpg: AES256 encrypted data
:compressed packet: algo=1
:literal data packet:
mode b (62), created 1458172973, name="",
raw data: 23 bytes
gpg: original file name=''
An encrypted message.
gpg: decryption okay
但当然,这是因为它现在使用 0690427c 加密。我真的只能有一个加密子密钥吗?如果不行,我是否必须在每台机器上保留所有秘密子密钥?
答案1
OpenPGP(包括 GnuPG)的实现将默认选择最新的有效加密(子)密钥并使用它进行加密。在 OpenPGP 中,无法定义给定子密钥以某种方式绑定到给定计算机或用户 ID,也无法强制对所有有效加密密钥执行加密。
人们可以很好地手动使用所选的密钥 ID 作为接收者,选择用于 GnuPG 加密的密钥,但后跟!
。例如,假设有一个较旧的加密子密钥DEADBEEF
,并且您想要覆盖使用另一个较新的加密子密钥的默认设置:
gpg --recipient DEADBEEF! --encrypt
如果!
省略,GnuPG 会将密钥 ID 解析为主密钥,并再次选择最新匹配的子密钥。使用相同的方法,您可以强制使用主密钥(如果它具有加密功能集)。
如果要在不同的计算机上使用不同的密钥进行加密,则必须使用不同的主密钥。这是 OpenPGP 的主要缺点之一。