Generazione di chiavi OpenPGP con backup#

(Nitrokey Start - Linux)

The following instructions explain the generation of OpenPGP keys and how to copy them to the Nitrokey. This method has the advantage of providing a backup of the keys in case of losing or breaking the Nitrokey. The instructions are based on the command line interface of GnuPG. Thus, you need to have GnuPG installed on your system. The newest GnuPG version for Windows can be found here and the newest version for MacOS can be found here. Users of Linux systems please install GnuPG with help of the package manager.

Generazione di chiavi#

All’inizio, è necessario generare una chiave a livello locale. Puoi decidere quali attributi chiave usare e - cosa più importante - puoi esportare la chiave e tenerla da qualche parte per salvarla nel caso tu abbia bisogno di ripristinarla.

Chiave principale e sottochiave di crittografia#

Possiamo usare il comando gpg --full-generate-key --expert per iniziare una generazione guidata della chiave con tutte le opzioni possibili. Si può scegliere il tipo di chiave (di solito RSA (1) o ECC (9)), la lunghezza della chiave e altri attributi. Il seguente output è solo un semplice esempio, puoi scegliere altri valori.

> gpg --full-generate-key --expert
gpg (GnuPG) 2.2.10; Copyright (C) 2018 Free Software Foundation, Inc.
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 (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
   (7) DSA (set your own capabilities)
   (8) RSA (set your own capabilities)
   (9) ECC and ECC
  (10) ECC (sign only)
  (11) ECC (set your own capabilities)
  (13) Existing key
Your selection? 1
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048)
Requested keysize is 2048 bits
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want for the subkey? (2048)
Requested keysize is 2048 bits
Please specify how long the key should be valid.
         0 = key does not expire
        = key expires in n days
      w = key expires in n weeks
      m = key expires in n months
      y = key expires in n years
Key is valid for? (0)
Key does not expire at all
Is this correct? (y/N) y

GnuPG needs to construct a user ID to identify your key.

Real name: Jane Doe
Email address: jane@example.com
Comment:
You selected this USER-ID:
    "Jane Doe "

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
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.
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: key 0EFFB0704391497C marked as ultimately trusted
gpg: revocation certificate stored as '/home/nitrokey//.gnupg/openpgp-revocs.d/9D12C91F6FC4CD6E10A1727A0EFFB0704391497C.rev'
public and secret key created and signed.

pub   rsa2048 2018-09-17 [SC]
      9D12C91F6FC4CD6E10A1727A0EFFB0704391497C
uid                      Jane Doe
sub   rsa2048 2018-09-17 [E]

Nota

Per informazioni sugli algoritmi supportati, consultare le FAQ di .

Sottochiave di autenticazione#

Ora avete una chiave principale con la capacità di firmare e certificare (segnata come [SC]) e una sottochiave per la crittografia (segnata come [E]). È necessario avere un’altra sottochiave per i casi in cui è necessaria l’autenticazione. Questa sottochiave viene generata nel prossimo passo. Scrivi gpg --edit-key --expert keyID per iniziare il processo, mentre «keyID» è o l’id della chiave o l’indirizzo email usato durante la generazione della chiave.

> gpg --edit-key --expert jane@example.com
gpg (GnuPG) 2.2.10; Copyright (C) 2018 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Secret key is available.

sec  rsa2048/0EFFB0704391497C
     created: 2018-09-17  expires: never       usage: SC
     trust: ultimate      validity: ultimate
ssb  rsa2048/A9A814C210F16700
     created: 2018-09-17  expires: never       usage: E
[ultimate] (1). Jane Doe

gpg>

Ora siete nella modalità interattiva di GnuPG e potete aggiungere una chiave semplicemente digitando addkey. Dovete scegliere la chiave che volete usare. È fondamentale scegliere «set your own capabilities», perché vogliamo avere la capacità «authenticate» che altrimenti non è disponibile. Alterniamo la firma e la crittografia digitando s e e e attiviamo l’autenticazione digitando a.

gpg> addkey
Please select what kind of key you want:
   (3) DSA (sign only)
   (4) RSA (sign only)
   (5) Elgamal (encrypt only)
   (6) RSA (encrypt only)
   (7) DSA (set your own capabilities)
   (8) RSA (set your own capabilities)
  (10) ECC (sign only)
  (11) ECC (set your own capabilities)
  (12) ECC (encrypt only)
  (13) Existing key
Your selection? 8

Possible actions for a RSA key: Sign Encrypt Authenticate
Current allowed actions: Sign Encrypt

   (S) Toggle the sign capability
   (E) Toggle the encrypt capability
   (A) Toggle the authenticate capability
   (Q) Finished

Your selection? s

Possible actions for a RSA key: Sign Encrypt Authenticate
Current allowed actions: Encrypt

   (S) Toggle the sign capability
   (E) Toggle the encrypt capability
   (A) Toggle the authenticate capability
   (Q) Finished

Your selection? e

Possible actions for a RSA key: Sign Encrypt Authenticate
Current allowed actions:

   (S) Toggle the sign capability
   (E) Toggle the encrypt capability
   (A) Toggle the authenticate capability
   (Q) Finished

Your selection? a

Possible actions for a RSA key: Sign Encrypt Authenticate
Current allowed actions: Authenticate

   (S) Toggle the sign capability
   (E) Toggle the encrypt capability
   (A) Toggle the authenticate capability
   (Q) Finished

Your selection? q

Usciamo con q. Dopodiché dobbiamo rispondere alle stesse domande di prima. Infine, abbiamo un set di chiavi pronto per l’uso che possiamo importare nel nostro dispositivo.

RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048)
Requested keysize is 2048 bits
Please specify how long the key should be valid.
         0 = key does not expire
        = key expires in n days
      w = key expires in n weeks
      m = key expires in n months
      y = key expires in n years
Key is valid for? (0)
Key does not expire at all
Is this correct? (y/N) y
Really create? (y/N) y
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.

sec  rsa2048/0EFFB0704391497C
     created: 2018-09-17  expires: never       usage: SC
     trust: ultimate      validity: ultimate
ssb  rsa2048/A9A814C210F16700
     created: 2018-09-17  expires: never       usage: E
ssb  rsa2048/61F186B8B0BBD5D5
     created: 2018-09-17  expires: never       usage: A
[ultimate] (1). Jane Doe

gpg> quit
Save changes? (y/N) y

Ora è un buon momento per fare il backup della vostra chiave. Per favore tenete questo backup molto sicuro. È una buona pratica non avere mai questa chiave su un normale computer che abbia una connessione a internet, in modo che la chiave non venga mai compromessa. Puoi creare un backup con qualcosa come:

> gpg --export-secret-keys jane@example.com > sec-key.asc

Importazione chiave#

Avete una chiave principale e due sottochiavi che possono essere importate nella vostra Nitrokey. Prima di procedere assicuratevi di avere davvero un backup della chiave, se ne avete bisogno. Il comando keytocard usato nei prossimi passi cancellerà la vostra chiave dal vostro disco!

Iniziamo il processo accedendo nuovamente all’interfaccia interattiva di GnuPG con gpg --edit-key --expert keyID, mentre keyID è l’id della chiave o l’indirizzo email usato durante la generazione della chiave.

> gpg --edit-key --expert jane@example.com
gpg (GnuPG) 2.2.10; Copyright (C) 2018 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Secret key is available.

sec  rsa2048/0EFFB0704391497C
     created: 2018-09-17  expires: never       usage: SC
     trust: ultimate      validity: ultimate
ssb  rsa2048/A9A814C210F16700
     created: 2018-09-17  expires: never       usage: E
ssb  rsa2048/61F186B8B0BBD5D5
     created: 2018-09-17  expires: never       usage: A
[ultimate] (1). Jane Doe

gpg> keytocard
Really move the primary key? (y/N) y
Please select where to store the key:
   (1) Signature key
   (3) Authentication key
Your selection? 1

sec  rsa2048/0EFFB0704391497C
     created: 2018-09-17  expires: never       usage: SC
     trust: ultimate      validity: ultimate
ssb  rsa2048/A9A814C210F16700
     created: 2018-09-17  expires: never       usage: E
ssb  rsa2048/61F186B8B0BBD5D5
     created: 2018-09-17  expires: never       usage: A
[ultimate] (1). Jane Doe

Abbiamo appena importato la chiave principale nella scheda. Ora procediamo con le due sottochiavi. Digitiamo key 1 per selezionare la sottochiave di crittografia e digitiamo keytocard nuovamente e selezioniamo lo slot da utilizzare.

gpg> key 1

sec  rsa2048/0EFFB0704391497C
     created: 2018-09-17  expires: never       usage: SC
     trust: ultimate      validity: ultimate
ssb* rsa2048/A9A814C210F16700
     created: 2018-09-17  expires: never       usage: E
ssb  rsa2048/61F186B8B0BBD5D5
     created: 2018-09-17  expires: never       usage: A
[ultimate] (1). Jane Doe

gpg> keytocard
Please select where to store the key:
   (2) Encryption key
Your selection? 2

sec  rsa2048/0EFFB0704391497C
     created: 2018-09-17  expires: never       usage: SC
     trust: ultimate      validity: ultimate
ssb* rsa2048/A9A814C210F16700
     created: 2018-09-17  expires: never       usage: E
ssb  rsa2048/61F186B8B0BBD5D5
     created: 2018-09-17  expires: never       usage: A
[ultimate] (1). Jane Doe

Ora deselezioniamo la prima chiave con key 1 e selezioniamo la seconda sottochiave con key 2 e spostiamo anche questa con keytocard. Dopodiché usciamo e salviamo le modifiche.

gpg> key 1

sec  rsa2048/0EFFB0704391497C
     created: 2018-09-17  expires: never       usage: SC
     trust: ultimate      validity: ultimate
ssb  rsa2048/A9A814C210F16700
     created: 2018-09-17  expires: never       usage: E
ssb  rsa2048/61F186B8B0BBD5D5
     created: 2018-09-17  expires: never       usage: A
[ultimate] (1). Jane Doe

gpg> key 2

sec  rsa2048/0EFFB0704391497C
     created: 2018-09-17  expires: never       usage: SC
     trust: ultimate      validity: ultimate
ssb  rsa2048/A9A814C210F16700
     created: 2018-09-17  expires: never       usage: E
ssb* rsa2048/61F186B8B0BBD5D5
     created: 2018-09-17  expires: never       usage: A
[ultimate] (1). Jane Doe

gpg> keytocard
Please select where to store the key:
   (3) Authentication key
Your selection? 3

sec  rsa2048/0EFFB0704391497C
     created: 2018-09-17  expires: never       usage: SC
     trust: ultimate      validity: ultimate
ssb  rsa2048/A9A814C210F16700
     created: 2018-09-17  expires: never       usage: E
ssb* rsa2048/61F186B8B0BBD5D5
     created: 2018-09-17  expires: never       usage: A
[ultimate] (1). Jane Doe

gpg> quit
Save changes? (y/N) y

Le tue chiavi sono ora spostate nella Nitrokey e quindi assicurate nell’hardware. Congratulazioni!

Esportazione della chiave pubblica e uso del Keyserver#

Anche se puoi iniziare a usare la tua Nitrokey subito dopo aver generato le chiavi sul tuo sistema, devi importare la tua chiave pubblica su ogni sistema su cui vuoi usare la Nitrokey. Quindi per essere preparati avete due opzioni: O salvi la chiave pubblica dove vuoi e la usi su un altro sistema o salvi la chiave pubblica su una pagina web/keyserver.

Generare un file di chiave pubblica#

Per ottenere un semplice file della vostra chiave pubblica, potete semplicemente usare gpg --armor --export keyID > pubkey.asc. Usa l’impronta digitale come «keyID» (guarda gpg -K per ottenerlo) o usa semplicemente il tuo indirizzo email come identificatore.

Potete portare questo file con voi o inviarlo a chiunque vogliate. Questo file non è affatto segreto. Se vuoi usare la Nitrokey su un altro sistema, prima importa questa chiave pubblica tramite gpg --import pubkey.asc e poi digita gpg --card-status in modo che il sistema sappia dove cercare questa chiave. Questo è tutto.

Caricare la chiave pubblica#

Se non volete portare con voi un keyfile pubblico, potete caricarlo su keyserver. Puoi farlo digitando gpg --keyserver search.keyserver.net --send-key keyID. Se stai usando un’altra macchina puoi semplicemente importarlo usando gpg --keyserver search.keyserver.net --recv-key keyID.

Un’altra possibilità è quella di cambiare l’impostazione dell’URL sulla vostra scheda. Avviate di nuovo gpg --card-edit e prima impostate l’URL dove si trova la chiave (ad esempio sul keyserver o sulla vostra pagina web ecc.) tramite il comando url. D’ora in poi potrete importare la chiave su un altro sistema usando semplicemente il comando fetch all’interno del gpg --card-edit environment.