Progetto

Generale

Profilo

Actions

UsoDiOpenPGPCard » Cronologia » Versione 7

« Precedente | Versione 7/31 (diff) | Successivo »
Elena Grandi, 19-10-2016 12:31


Uso di OpenPGP Card

L'OpenPGP Card è una smartcard sulla quale si possono salvare in modo sicuro ed usare le sottochiavi segrete usate da GnuPG per crittografia, firma ed anche autenticazione; ne esistono versioni tradizionali, oppure implementate in un dispositivo USB. In ogni caso si possono caricare nuove chiavi sulla scheda, ma non si possono estrarre (per via software) quelle salvate ed è la scheda stessa ad effettuare le operazioni crittografiche.

L'obiettivo che si vuole ottenere è di non avere materiale crittografico segreto sui computer, in modo che un attaccante remoto non possa impossessarsene, mantenendo comunque la comodità di poter usare le chiavi sulla stessa macchina di uso comune. Per farlo si dovrà avere una chiave principale di lunga durata conservata offline ed usata solo saltuariamente per operazioni di gestione della chiave stessa (creazione di nuove sottochiavi, modifica delle scadenze, firma di altre chiavi per la Web Of Trust) e delle sottochiavi da usare quotidianamente, conservate sulla card.

Ll'OpenPGP Card permette di caricare tre sottochiavi con finalità di crittografia, firma ed autenticazione: le prime due si usano normalmente tramite GnuPG, la terza può essere usata per l'autenticazione ssh tramite gpg-agent.

prerequisiti

Tutte le versioni di GnuPG supportano l'uso di base delle OpenPGP Card, ma per meglio sfruttarne le capacità è meglio usare la versione 2.1 (modern), specialmente in fase di creazione della chiave e delle sue sottochiavi.

Nel caso si voglia usare poi la Card per autenticazione ssh con versioni precedenti di GnuPG è necessario installare anche gpg-agent (in 2.1 usato di default).

Per il supporto della Card è poi necessario installare PC/SC Lite.

Sotto distribuzioni debian o derivate (che già preinstallano gnupg e openssh-client) i pacchetti da installare sono quindi:

apt install pcscd gnupg-agent

creazione della chiave

Innanzitutto bisogna creare una chiave principale che verrà associata alla nostra identità; questa dovrà essere da almeno 4096 bit per garantirle sufficiente longevità, dato che la sua sostituzione comporta un nuovo ingresso nella Web of Trust.

Ovviamente, se si ha già una chiave gpg da 4096 bit si può saltare questo passaggio ed usare quella.

Innanzitutto, configurare gpg per l'uso di SHA2 aggiungendo le seguenti righe a ~/.gnupg/gpg.conf:

personal-digest-preferences SHA256
cert-digest-algo SHA256
default-preference-list SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed

Quindi generare una nuova chiave: notare l'uso di gpg versione 2.1 e la dimensione a 4096 bit (per il resto si sono accettate le scelte di default oppure inseriti i propri dati).

$ gpg --full-gen-key 
gpg (GnuPG) 2.1.15; Copyright (C) 2016 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)
Your selection? 1
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 4096
Requested keysize is 4096 bits
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) 
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: Random User
Email address: random@example.org
Comment: 
You selected this USER-ID:
    "Random User <random@example.org>" 

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.
gpg: key 3E0EE5BAC50DF7C1 marked as ultimately trusted
gpg: directory '/home/random/.gnupg/openpgp-revocs.d' created
gpg: revocation certificate stored as '/home/valhalla/.gnupg/openpgp-revocs.d/19DB75A75734ABBEDB1124163E0EE5BAC50DF7C1.rev'
public and secret key created and signed.

pub   rsa4096 2016-10-19 [SC]
      19DB75A75734ABBEDB1124163E0EE5BAC50DF7C1
      19DB75A75734ABBEDB1124163E0EE5BAC50DF7C1
uid                      Random User <random@example.org>
sub   rsa4096 2016-10-19 [E]

creazione delle sottochiavi

Questo è il punto in cui è particolarmente importante l'uso di GnuPG 2.1, che rende molto più semplice la creazione di una chiave per l'autenticazione.

Molte delle OpenPGP Card disponibili sul mercato supportano chiavi al massimo a 2048 bit: questo non è un grosso problema dato che al momento sono considerate ancora ragionevolmente sicure, ed una loro eventuale sostituzione in futuro non è particolarmente onerosa (oltre ovviamente alla necessità di usare una Card o un dispositivo diverso).

Per generare le sottochiavi necessarie, si entra in modalità di modifica con l'opzione --expert che abilita la creazione di chiavi di autenticazione.

$ gpg --expert --edit-key 3E0EE5BAC50DF7C1
gpg (GnuPG) 2.1.15; Copyright (C) 2016 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  rsa4096/3E0EE5BAC50DF7C1
     created: 2016-10-19  expires: never       usage: SC  
     trust: ultimate      validity: ultimate
ssb  rsa4096/F303978FEBB6E995
     created: 2016-10-19  expires: never       usage: E   
[ultimate] (1). Random User <random@example.org>

Quindi si crea prima una normale sottochiave di firma (opzione 4)

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? 4
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
      <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) 1y
Key expires at Thu 19 Oct 2017 12:15:49 CEST
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  rsa4096/3E0EE5BAC50DF7C1
     created: 2016-10-19  expires: never       usage: SC  
     trust: ultimate      validity: ultimate
ssb  rsa4096/F303978FEBB6E995
     created: 2016-10-19  expires: never       usage: E   
ssb  rsa2048/40A2ADF0FE9E4620
     created: 2016-10-19  expires: 2017-10-19  usage: S   
[ultimate] (1). Random User <random@example.org>

Una normale sottochiave per la crittografia (opzione 6)

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? 6
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
      <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) 1y
Key expires at Thu 19 Oct 2017 12:18:16 CEST
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  rsa4096/3E0EE5BAC50DF7C1
     created: 2016-10-19  expires: never       usage: SC  
     trust: ultimate      validity: ultimate
ssb  rsa4096/F303978FEBB6E995
     created: 2016-10-19  expires: never       usage: E   
ssb  rsa2048/40A2ADF0FE9E4620
     created: 2016-10-19  expires: 2017-10-19  usage: S   
ssb  rsa2048/ED9BBD7B3BFF900F
     created: 2016-10-19  expires: 2017-10-19  usage: E   
[ultimate] (1). Random User <random@example.org>

Ed infine una sottochiave per l'autenticazione, selezionando l'opzione 8, togliendo le capacità di firma e crittografia e mettendo quella di autenticazione.

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
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
      <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) 1y
Key expires at Thu 19 Oct 2017 12:24:56 CEST
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  rsa4096/3E0EE5BAC50DF7C1
     created: 2016-10-19  expires: never       usage: SC  
     trust: ultimate      validity: ultimate
ssb  rsa4096/F303978FEBB6E995
     created: 2016-10-19  expires: never       usage: E   
ssb  rsa2048/40A2ADF0FE9E4620
     created: 2016-10-19  expires: 2017-10-19  usage: S   
ssb  rsa2048/ED9BBD7B3BFF900F
     created: 2016-10-19  expires: 2017-10-19  usage: E   
ssb  rsa2048/5F89B668295AE797
     created: 2016-10-19  expires: 2017-10-19  usage: A   
[ultimate] (1). Random User <random@example.org>

Si può quindi uscire dalla modalità di modifica chiave, salvando le modifiche.

gpg> save

salvataggio su supporto esterno

spostamento delle chiavi sulla Card

configurazione di ssh

configurazione su una nuova macchina

configurazione su una nuova macchina, con versioni precedenti di gpg

Aggiornato da Elena Grandi oltre 7 anni fa · 7 revisions