Progetto

Generale

Profilo

UsoDiOpenPGPCard » Cronologia » Versione 8

Elena Grandi, 19-10-2016 13:50

1 1 Elena Grandi
h1. Uso di OpenPGP Card
2
3 2 Elena Grandi
L'"OpenPGP Card":https://en.wikipedia.org/wiki/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.
4 1 Elena Grandi
5 2 Elena Grandi
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.
6
7
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.
8
9 3 Elena Grandi
h2. prerequisiti
10
11 2 Elena Grandi
Tutte le versioni di "GnuPG":https://gnupg.org/ 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.
12 1 Elena Grandi
13 3 Elena Grandi
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).
14
15
Per il supporto della Card è poi necessario installare "PC/SC Lite":http://pcsclite.alioth.debian.org/.
16
17
Sotto distribuzioni debian o derivate (che già preinstallano @gnupg@ e @openssh-client@) i pacchetti da installare sono quindi:
18
19
<pre>
20
apt install pcscd gnupg-agent
21
</pre>
22 2 Elena Grandi
23
h2. creazione della chiave
24
25 4 Elena Grandi
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.
26
27
Ovviamente, se si ha già una chiave gpg da 4096 bit si può saltare questo passaggio ed usare quella.
28
29
Innanzitutto, configurare gpg per l'uso di SHA2 aggiungendo le seguenti righe a @~/.gnupg/gpg.conf@:
30
31
<pre>
32
personal-digest-preferences SHA256
33
cert-digest-algo SHA256
34
default-preference-list SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed
35
</pre>
36
37
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).
38
39
<pre>
40
$ gpg --full-gen-key 
41
gpg (GnuPG) 2.1.15; Copyright (C) 2016 Free Software Foundation, Inc.
42
This is free software: you are free to change and redistribute it.
43
There is NO WARRANTY, to the extent permitted by law.
44
45
Please select what kind of key you want:
46
   (1) RSA and RSA (default)
47
   (2) DSA and Elgamal
48
   (3) DSA (sign only)
49
   (4) RSA (sign only)
50
Your selection? 1
51
RSA keys may be between 1024 and 4096 bits long.
52
What keysize do you want? (2048) 4096
53
Requested keysize is 4096 bits
54
Please specify how long the key should be valid.
55
         0 = key does not expire
56
      <n>  = key expires in n days
57
      <n>w = key expires in n weeks
58
      <n>m = key expires in n months
59
      <n>y = key expires in n years
60
Key is valid for? (0) 
61
Key does not expire at all
62
Is this correct? (y/N) y
63
64
GnuPG needs to construct a user ID to identify your key.
65
66
Real name: Random User
67
Email address: random@example.org
68
Comment: 
69
You selected this USER-ID:
70
    "Random User <random@example.org>"
71
72
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o
73
We need to generate a lot of random bytes. It is a good idea to perform
74
some other action (type on the keyboard, move the mouse, utilize the
75
disks) during the prime generation; this gives the random number
76
generator a better chance to gain enough entropy.
77
gpg: key 3E0EE5BAC50DF7C1 marked as ultimately trusted
78
gpg: directory '/home/random/.gnupg/openpgp-revocs.d' created
79
gpg: revocation certificate stored as '/home/valhalla/.gnupg/openpgp-revocs.d/19DB75A75734ABBEDB1124163E0EE5BAC50DF7C1.rev'
80
public and secret key created and signed.
81
82
pub   rsa4096 2016-10-19 [SC]
83
      19DB75A75734ABBEDB1124163E0EE5BAC50DF7C1
84
      19DB75A75734ABBEDB1124163E0EE5BAC50DF7C1
85
uid                      Random User <random@example.org>
86
sub   rsa4096 2016-10-19 [E]
87
</pre>
88
89 2 Elena Grandi
h2. creazione delle sottochiavi
90
91 5 Elena Grandi
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.
92
93
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).
94
95
Per generare le sottochiavi necessarie, si entra in modalità di modifica con l'opzione @--expert@ che abilita la creazione di chiavi di autenticazione.
96
97
<pre>
98
$ gpg --expert --edit-key 3E0EE5BAC50DF7C1
99
gpg (GnuPG) 2.1.15; Copyright (C) 2016 Free Software Foundation, Inc.
100
This is free software: you are free to change and redistribute it.
101
There is NO WARRANTY, to the extent permitted by law.
102
103
Secret key is available.
104
105
sec  rsa4096/3E0EE5BAC50DF7C1
106
     created: 2016-10-19  expires: never       usage: SC  
107
     trust: ultimate      validity: ultimate
108
ssb  rsa4096/F303978FEBB6E995
109
     created: 2016-10-19  expires: never       usage: E   
110
[ultimate] (1). Random User <random@example.org>
111
</pre>
112
113
Quindi si crea prima una normale sottochiave di firma (opzione 4)
114
115
<pre>
116
gpg> addkey 
117
Please select what kind of key you want:
118
   (3) DSA (sign only)
119
   (4) RSA (sign only)
120
   (5) Elgamal (encrypt only)
121
   (6) RSA (encrypt only)
122
   (7) DSA (set your own capabilities)
123
   (8) RSA (set your own capabilities)
124
  (10) ECC (sign only)
125
  (11) ECC (set your own capabilities)
126
  (12) ECC (encrypt only)
127
  (13) Existing key
128
Your selection? 4
129
RSA keys may be between 1024 and 4096 bits long.
130
What keysize do you want? (2048) 
131
Requested keysize is 2048 bits
132
Please specify how long the key should be valid.
133
         0 = key does not expire
134
      <n>  = key expires in n days
135
      <n>w = key expires in n weeks
136
      <n>m = key expires in n months
137
      <n>y = key expires in n years
138
Key is valid for? (0) 1y
139
Key expires at Thu 19 Oct 2017 12:15:49 CEST
140
Is this correct? (y/N) y
141
Really create? (y/N) y
142
We need to generate a lot of random bytes. It is a good idea to perform
143
some other action (type on the keyboard, move the mouse, utilize the
144
disks) during the prime generation; this gives the random number
145
generator a better chance to gain enough entropy.
146
147
sec  rsa4096/3E0EE5BAC50DF7C1
148
     created: 2016-10-19  expires: never       usage: SC  
149
     trust: ultimate      validity: ultimate
150
ssb  rsa4096/F303978FEBB6E995
151
     created: 2016-10-19  expires: never       usage: E   
152
ssb  rsa2048/40A2ADF0FE9E4620
153
     created: 2016-10-19  expires: 2017-10-19  usage: S   
154
[ultimate] (1). Random User <random@example.org>
155
156
</pre>
157
158
Una normale sottochiave per la crittografia (opzione 6)
159
160
<pre>
161
gpg> addkey 
162
Please select what kind of key you want:
163
   (3) DSA (sign only)
164
   (4) RSA (sign only)
165
   (5) Elgamal (encrypt only)
166
   (6) RSA (encrypt only)
167
   (7) DSA (set your own capabilities)
168
   (8) RSA (set your own capabilities)
169
  (10) ECC (sign only)
170
  (11) ECC (set your own capabilities)
171
  (12) ECC (encrypt only)
172
  (13) Existing key
173
Your selection? 6
174
RSA keys may be between 1024 and 4096 bits long.
175
What keysize do you want? (2048) 
176
Requested keysize is 2048 bits
177
Please specify how long the key should be valid.
178
         0 = key does not expire
179
      <n>  = key expires in n days
180
      <n>w = key expires in n weeks
181
      <n>m = key expires in n months
182
      <n>y = key expires in n years
183
Key is valid for? (0) 1y
184
Key expires at Thu 19 Oct 2017 12:18:16 CEST
185
Is this correct? (y/N) y
186
Really create? (y/N) y
187
We need to generate a lot of random bytes. It is a good idea to perform
188
some other action (type on the keyboard, move the mouse, utilize the
189
disks) during the prime generation; this gives the random number
190
generator a better chance to gain enough entropy.
191
192
sec  rsa4096/3E0EE5BAC50DF7C1
193
     created: 2016-10-19  expires: never       usage: SC  
194
     trust: ultimate      validity: ultimate
195
ssb  rsa4096/F303978FEBB6E995
196
     created: 2016-10-19  expires: never       usage: E   
197
ssb  rsa2048/40A2ADF0FE9E4620
198
     created: 2016-10-19  expires: 2017-10-19  usage: S   
199
ssb  rsa2048/ED9BBD7B3BFF900F
200
     created: 2016-10-19  expires: 2017-10-19  usage: E   
201
[ultimate] (1). Random User <random@example.org>
202
</pre>
203
204
Ed infine una sottochiave per l'autenticazione, selezionando l'opzione 8, togliendo le capacità di firma e crittografia e mettendo quella di autenticazione.
205
206
<pre>
207
gpg> addkey 
208
Please select what kind of key you want:
209
   (3) DSA (sign only)
210
   (4) RSA (sign only)
211
   (5) Elgamal (encrypt only)
212
   (6) RSA (encrypt only)
213
   (7) DSA (set your own capabilities)
214
   (8) RSA (set your own capabilities)
215
  (10) ECC (sign only)
216
  (11) ECC (set your own capabilities)
217
  (12) ECC (encrypt only)
218
  (13) Existing key
219
Your selection? 8
220
221
Possible actions for a RSA key: Sign Encrypt Authenticate 
222
Current allowed actions: Sign Encrypt 
223
224
   (S) Toggle the sign capability
225
   (E) Toggle the encrypt capability
226
   (A) Toggle the authenticate capability
227
   (Q) Finished
228
229
Your selection? s
230
231
Possible actions for a RSA key: Sign Encrypt Authenticate 
232
Current allowed actions: Encrypt 
233
234
   (S) Toggle the sign capability
235
   (E) Toggle the encrypt capability
236
   (A) Toggle the authenticate capability
237
   (Q) Finished
238
239
Your selection? e
240
241
Possible actions for a RSA key: Sign Encrypt Authenticate 
242
Current allowed actions: 
243
244
   (S) Toggle the sign capability
245
   (E) Toggle the encrypt capability
246
   (A) Toggle the authenticate capability
247
   (Q) Finished
248
249
Your selection? a
250
251
Possible actions for a RSA key: Sign Encrypt Authenticate 
252
Current allowed actions: Authenticate 
253
254
   (S) Toggle the sign capability
255
   (E) Toggle the encrypt capability
256
   (A) Toggle the authenticate capability
257
   (Q) Finished
258
259
Your selection? q
260
RSA keys may be between 1024 and 4096 bits long.
261
What keysize do you want? (2048) 
262
Requested keysize is 2048 bits
263
Please specify how long the key should be valid.
264
         0 = key does not expire
265
      <n>  = key expires in n days
266
      <n>w = key expires in n weeks
267
      <n>m = key expires in n months
268
      <n>y = key expires in n years
269
Key is valid for? (0) 1y
270
Key expires at Thu 19 Oct 2017 12:24:56 CEST
271
Is this correct? (y/N) y
272
Really create? (y/N) y
273
We need to generate a lot of random bytes. It is a good idea to perform
274
some other action (type on the keyboard, move the mouse, utilize the
275
disks) during the prime generation; this gives the random number
276
generator a better chance to gain enough entropy.
277
278
sec  rsa4096/3E0EE5BAC50DF7C1
279
     created: 2016-10-19  expires: never       usage: SC  
280
     trust: ultimate      validity: ultimate
281
ssb  rsa4096/F303978FEBB6E995
282
     created: 2016-10-19  expires: never       usage: E   
283
ssb  rsa2048/40A2ADF0FE9E4620
284
     created: 2016-10-19  expires: 2017-10-19  usage: S   
285
ssb  rsa2048/ED9BBD7B3BFF900F
286
     created: 2016-10-19  expires: 2017-10-19  usage: E   
287
ssb  rsa2048/5F89B668295AE797
288
     created: 2016-10-19  expires: 2017-10-19  usage: A   
289
[ultimate] (1). Random User <random@example.org>
290
</pre>
291
292
Si può quindi uscire dalla modalità di modifica chiave, salvando le modifiche.
293
294
<pre>
295
gpg> save
296
</pre>
297
298 7 Elena Grandi
h2. salvataggio su supporto esterno
299
300 8 Elena Grandi
A questo punto la chiave è ancora gestita nel modo tradizionale, su hard disk. Questo è il momento di salvarne un backup e di farne una copia su chiavetta USB da usare in futuro per le modifiche della chiave.
301
302
303
304 2 Elena Grandi
h2. spostamento delle chiavi sulla Card
305
306
h2. configurazione di ssh
307 6 Elena Grandi
308
h2. configurazione su una nuova macchina
309
310
h2. configurazione su una nuova macchina, con versioni precedenti di gpg