-
resources:
- Anatomy of GPG
- TODO TOFU vs WebOfTrust
- deep understanding: https://www.reddit.com/r/GnuPG/comments/vjas2e/proper_key_management/
- GPG和HTTPS,Crypto,SSH等都使用非对称加密,但GPG是一整套key管理的加解密protocol
- GPGPrimayKey对应Identity,Subkey对应同一个identity不同功能或devices
- 理解GPGSubkeyCapability区别是正确使用的前提.有的可以混用有的不可以
- GPGExpire是owner设置来提醒非owner需要更新,不代表失效.Revoke才是失效
- Use-GPGKey-For-SSH-Auth
- GPG-security-technical-best-practices
- Keyserver-url是GPGPubKey的一部分,optional设置,可以设置成真正的keyserver或者自己host最新key的地址
- GPG文件存储细节-Keygrip是GnuPG实现细节,Fingerprint是OpenPGP标准,KeyID是fingerprint的后一部分
-
Usage
gpg --list-secret-keys --with-keygrip --fingerprintgpg --export -a SavoryBillion | save encryption_key.pubgpg --export-secret-subkeys -a "78F8 26FF 13FC C70A 5DC3 47DA 9A48 A782 EF82 61F3" | save -f encryption_keygpg --recipient <KeyID> --encrypt <data file>gpg --decrypt <encrypted file>pub key is self-containedgpg --clearsignoutputs text, easier for readinggpg --verify <signature file>again which pub key should be used to verify is self-contained-
Backup and Recover primary/sub keys
gpg --export-secret-keys <KeyID>- of both primary and all sub keys
- equivalently, mv/rm the
private-keys.d/keygrip.keyfile directly
gpg --export-secret-subkeys <KeyID>- of only sub keys
gpg --delete-secret-keys <KeyID>gpg --edit-key, select thendelkeywill delete the pub/secret pair
-
Config and apply
~/.gnupg/gpg.conf- restart agent to apply:
gpg-connect-agent /bye
-
Expiration and
--edit-keyfunctionalitygpg --edit-key <KeyID>- use
key <index>to select primary/sub key, starting from 0 - use
expireto set expiration again - use
delkeyto delete pub and private pair of a specified (sub)key only
- use
-
Add Subkey
gpg --edit-key <KeyID>thenaddkey
-
Set capabilities
gpg --edit-key <KeyID>thenkey <index>thenchange-usage
-
原理相关 - 和其他常见 Public-Key Cryptography 加密方式比较
id:: 65d1d74d-719b-4dd1-a8b0-89dc1ecbb1fc- comparison to CryptoCurrencies: btc and eth use a different curve,
secp256k1, for no specific advantage, likely historical reason - comparison to ssh
id:: 65d0c75a-4e66-479f-9f47-221cf0b4c92e
- Key Formats: GPG and SSH keys are stored in different formats. GPG uses its own format, which is compatible with the OpenPGP standard, while SSH keys are stored in a format that is specific to SSH. Purpose and Functionality: GPG provides a suite of encryption technologies for emails and files, including key management systems and access to public key directories. SSH keys are specifically designed for secure access to remote servers and don’t natively support document signing or encryption in the way GPG does.
- comparison to https TLS
- also a chain of trust: rootCA → intermediateCA → server certificates
- also uses Public-Key Cryptography: signatures and verifications
- comparison
- comparison to CryptoCurrencies: btc and eth use a different curve,
-
InfoSec best practices
- cryptographic algorithm: use ED25519. No <3k RSA, no NIST
- revocation cert
- digest: no SHA1, prefer SHA512
- primary + sub keys, with primary offline
-
understand one-primary+multi-sub v.s. multi-primary keys
-
Examples for using multiple primary keys: You don’t want to mix up your private and professional keys You need some key not connected with your “real life” identity, eg. when prosecuted by the authorities
-
Examples for using subkeys: You want to use multiple keys for multiple devices (so you won’t have to revoke your computer’s key if you lose your mobile) You want to switch keys regularly (eg., every some years) without losing your reputation in the Web of Trust
- multiple signing subkeys or encrypting subkeys?
- only the latest encrypting subkey is used?
-
- https://incenp.org/notes/2015/using-an-offline-gnupg-master-key.html
- https://wiki.debian.org/Subkeys
- https://amann.dev/blog/2020/offline_gpg/
-
- different keys for sign/encryption
- disable AEAD
- generate with care
$ gpg --full-generate-key --expert
-
Fungible and Non-Fungible key capabilities
- Sign and Authenticate (e.g. ssh ).
- 默认用最后一个add的pub sign key来sign,没法指定别的。
- 但无论是哪一个sign/auth都代表同一个primaryKey所代表的identity 所以无所谓,可以每个设备一个,丢了revoke
- Encrypt and Certify: non-fungible.
- encrypt: 哪一个subkey加密,谁解密,丢了sub, primary也没法帮忙揭秘
- 所以最好多设备share一个不然电脑加密手机没法解密
- certify: 只有primary certify subs没有grand-children
- 强行默认用最后一个add的pub encrypt key来encrypt, 没法用别的
- encrypt: 哪一个subkey加密,谁解密,丢了sub, primary也没法帮忙揭秘
- When create a primary key, only “Certify” capability is a must.
- Sign and Authenticate (e.g. ssh ).
-
Expired v.s. Revoked
- expire means “needs update” (from keyserver or somewhere)
- owner can extend expiration even AFTER expiried
- revoked means “no longer used” (for can-be-specified reason/comments)
- expire means “needs update” (from keyserver or somewhere)
-
Keyserver and How to find a (pub) key on the Internet
gpg --import sss/sb_240922.pgppreferred-keyserver-urlcan be any URL to download your key file. Its a public key attribute.honor-keyserver-urlwill try the above attribute first- therefore, one can visit the URL as long as they have your pub key with that attribute set
- You can choose to include info on how to find your pub key in signatures:
- the entire pub key (too long)
- the keyserver-url (best)
- keyID, user, email, etc. (avoid)
-
GPG public and private keys files/formats explained
- keyID vs fingerprint
- fingerprint is the only unique id. keyID (0xAAAAA…) is the last 4 4-hex groups of the fingerprint
- Fingerprint vs keygrip
- fingerprint is a OpenPGP standard while keygrip is GnuPG internal structure. it’s used as private key file names
- they are both hashes (a.k.a. digests) of public key information. Fingerprint contains algo while keygrip does not
gpg --list-keys <KeyID>public key info output explained: collapsed:: true-
pub ed25519 2024-02-18 [SC] [expires: 2027-02-17] E9438CCFA834E1F65390F82FDF89B1399C3332A1 uid test1 <test1@test.com> sub cv25519 2024-02-18 [E] [expires: 2027-02-17] pub ed25519 2024-02-18 [SC] [expires: 2027-02-17]: This line indicates you have an Ed25519 public key, generated on February 18, 2024. The[SC]flags mean this key is used for Signing (S) and Certification (C) of other keys. The key has an expiration date set to February 17, 2027.E9438CCFA834E1F65390F82FDF89B1399C3332A1: This is the fingerprint of your Ed25519 public key. The fingerprint is a shorter way to uniquely identify the key.uid test1 <test1@test.com>: This is the user ID associated with the key, including a name and email address. It’s used to identify the owner of the key.sub cv25519 2024-02-18 [E] [expires: 2027-02-17]: This line indicates a subkey used for Encryption (E). It’s based on the Curve25519 (cv25519) elliptic curve, generated on the same date as the primary key and also expiring on February 17, 2027.
-
- gpg private keys are stored under
~/.gnupg/private-keys-v1.d, and in plain text format storing- There’ll be two private keys by default, one for master key, one for encryption sub key
- if it’s password protected, then the part will be further encrypted
- gpg pulic keys can be exported by
gpg --armor --export <KeyID> > mypublickey.ascit’s base64 encoded ASCII containing meta data and public points of all keys and subkeys
- keyID vs fingerprint
- ((65d5b602-aa1c-47a9-adbb-fdaaf28bff1b))