# Memo GPG ## Vocabulaire * **Primary key vs. subkey** - A PGP key certificate may contain other information in addition to the key itself. A subkey is a key that is stored as a sub-component of another key. The primary key is the top level key. It is often referred to elsewhere as the master key. * **Public key** - This post is working with the published version of the key certificate. Therefore, only public keys are described (the ones that encrypt and verify signatures). Your local version of your key also includes the associated private keys (for decryption and signature creation), to define the key pair. * **Key certificate** - Part of the challenge of understanding gpg key management documentation is the flexibility in the definition of the word ‘key’. It can refer to a specific private or public key, or to a particular key pair, or to the OpenPGP ‘certificate’ that defines a suite of information associated with a key or set of keys. I will use the term “key/public key” and “key certificate” to distinguish between the possible interpretations. Key pairs and private keys will not come up here. We will be focusing on the key certificate. * **Key ID** - A hexadecimal string that identifies a key (usually the primary key). * **fingerprint** - sert à identifier de manière unique une clef. L'idée étant que, plusieurs personnes pouvant générer une clef avec un même uid, il faut pouvoir déterminer si on a la bonne clef publique en comparant son empreinte. **Note:** Les 8 derniers caractères du fingerprint correspondent à l'identifiant pub de la clé. Cette méthode d’identification des clés n’est plus fiable, il est facile de générer une clé avec une empreinte différente mais dont les 8 derniers caractères sont choisis. Fingerprint: 0D69 E11F 12BD BA07 7B37 26AB 4E1F 799A A4FF 2279 Long key ID: 4E1F 799A A4FF 2279 Short key ID: A4FF 2279 * **UID, or User ID** - The name and email of the user is stored in one or more UID entries, stored under the Primary key. * **Certification vs. signing** - ‘Signing’ is an action against arbitrary data. ‘Certification’ is the signing of another key. Ironically, the act of certifying a key is universally called “key signing”. Just embrace the contradiction. * **Key packet** - ‘Packet’ is the term used by RFC4880 to identify a component of the message/certificate format. Messages and keys certificates are made up of packets and subpackets of various types. * **Trust, Validity, and the Web of Trust** - gpg uses a model of ‘trust’ of users (defined locally-only using the ‘trust’ edit command) and reported ‘validity’ of keys (defined by key signatures/certificates). The combination creates a “Web of Trust”, starting with locally-defined trust statements about users, and passing through multiple levels of key-signature-defined validity links to other keys. Gpg uses the web of trust to determine if a key is acceptable for use without warning the user. There is a writeup in the GNU Privacy Handbook that covers the concepts well enough if you have the terms straight. Documentation often uses the word ‘trust’ for both ‘trust’ and ‘validity’. I mention all of this only to note that this document is concerned with ‘validity’. ## Générer une paire de clés GPG manuellement gpg --full-gen-key --expert ### Génération auto d'une primary_key avec en paramètres: durée 1 an, RSA 4096, servant uniquement à certifier gpg --quick-gen-key 'Thomas vlp ' rsa4096 cert 1y ### Gérération sous-clef servant à signer uniquement sur les même paramètres gpg --quick-addkey ID_KEY_primary_key rsa4096 sign 1y ### Génération sous-clef servant uniquement à encrypter sur les même paramètres gpg --quick-addkey ID_KEY_primary_key rsa4096 encr 1y ## Clef par default: ajouter dans gpg.conf default-key ID_KEY no-greeting personal-digest-preferences SHA512 personal-cipher-preferences AES256 AES cert-digest-algo SHA512 default-preference-list SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed s2k-cipher-algo AES256 s2k-digest-algo SHA512 s2k-mode 3 s2k-count 65011712 si non spécifié, la clef par default est la première affiché par gpg -K ## Générer certif de révocation gpg --output revocation.asc --gen-revoke thomas@vlp.fr ## Lister les clés publiques gpg -k ## Lister les clés privées gpg -K ## Récupérer les (si subkey) fingerprints de la clé gpg --fingerprint ID_KEY ## Exporter une clé publique dans un fichier gpg -a --export ID_KEY > pub_key.key ## Importer une clé publique depuis un fichier gpg --import pub_key.key ## Exporter une clé privée dans un fichier gpg -a --export-secret-key > primary_key.key -a laisse la clef dans un format lisible ## Exporter sub-key privée dans un fichier gpg -a --export-secret-subkeys > secret_subkeys.gpg ## Importer une clé privée depuis un fichier gpg --import --allow-secret-key-import primary_key.key ## Signer un fichier ### Signer fichier text gpg --clearsign fichier ### Signer binairies (signature à part) gpg --detach-sign fichier ## Chiffrer et signer un fichier gpg -s -a -e fichier_à_signer -s signe -a laisse en format lisible (sinon binairie) -e chiffre ## Déchiffrer un fichier gpg -r ID_KEY -d fichier_à_chiffrer ## Vérifier la signature séparée gpg --verify fichier_signature fichier_signé ## Vérifier la signature incluse gpg --verify fichier_signé ## Supprimer une clé privée : gpg --delete-secret-keys ID_KEY gpg --delete-key ID_KEY ## Informations plus poussées sur une paire de clé gpg --edit-key ID_KEY export mode: --expert ### Afficher options help ## Changer la passphrase d'une clé privée gpg --edit-key ID_KEY passwd save ## Symetric encryption: gpg -c -o out.gpg --cipher-algo AES256 -s in.gpg ## Install outil gestion gpg card/yubi key like sudo apt install scdaemon pcscd pcsc-tools ## Afficher info card gpg --card-status ## Lister/modifier les info gpg --card-edit >admin >help ## Transférer clef sur card gpg --edit-key ID_KEY #séclection key1 aka subkey1 car key0 = primary_key (absente car offline cf bonne pratiques) >key1 #envoie key1 et répondre à la question sur nature de la key: S ou E >keytocard #déselectionne key1 (! e pas oublier) >key1 #sélectionne key2 >key2 >keytocard >key2 >save ## Utiliser notre card + subkey sur nouvelle machine #se connecter sur la nouvelle machine qui à déjà import notre clef public gpg --card-edit fetch ## Error There is no assurance this key belongs to the named user gpg --edit-key ID_KEY > trust ## Bonne pratique Required: 2 gpg card + 1 yubi key like 1. créer une primary key pour certifier 2. créer une sub key pour signer, une subkey pour chiffrer et une sub key pour auth 3. créer certif de revoc 4. exporter la primary key et les sub keys 5. mettre la primary key sur une gpg card > backup offline 6. mettre les subkey sur une gpg card > backup offline 7. supprimer les clefs (il faut réimporter la clef primaire pour supprimer les clef secondaires avec) 8. importer uniquement les subkeys 9. mettre les subkey sur la yubi key like 10. stocker les cards en un lieu sur > cf étapes 5 & 6