Генериране на ключове OpenPGP с резервно копие¶
Compatible Nitrokeys |
|||||||
|---|---|---|---|---|---|---|---|
✓ active |
⨯ inactive |
⨯ inactive |
✓ active |
⨯ inactive |
✓ active |
✓ active |
⨯ inactive |
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.
Генериране на ключове¶
At first, you need to generate a key locally. You can decide, which key attributes to use and - most importantly - you can export the key and keep it somewhere safe in case you need to restore the key.
Основен ключ и подключ за криптиране¶
Можем да използваме командата gpg --full-generate-key --expert, за да стартираме насочено генериране на ключове с всички възможни опции. Можете да изберете типа на ключа (обикновено RSA (1) или ECC (9)), дължината на ключа и други атрибути. Следващият изход е само прост пример, можете да изберете други стойности.
> 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]
Note
For information regarding the supported algorithms, refer to the FAQ of the respective Nitrokey model.
Подключ за удостоверяване¶
You now have a main key with the capability to sign and certify (marked as [SC]) and a subkey for encryption (marked as [E]). It is necessary to have another subkey for use cases in which authentication is needed. This subkey is generated in the next step. Type in gpg --edit-key --expert keyID to start the process, whereas keyID
is either the ID of the key or the email address used during key generation.
> 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>
Сега сте в интерактивния режим на GnuPG и можете да добавите ключ, като просто напишете addkey. Трябва да изберете ключа, който искате да използвате. Изключително важно е да изберете „задаване на собствени възможности“, защото искаме да разполагаме с възможността „удостоверяване“, която иначе не е налична. Превключваме подписването и криптирането, като въвеждаме s и e и активираме удостоверяването, като въведем 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
Приключваме с 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
= 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
Сега е моментът да направите резервно копие на ключа си. Моля, пазете това резервно копие на много сигурно място. Най-добрата практика е този ключ никога да не се съхранява на обикновен компютър, който има връзка с интернет, за да не бъде компрометиран. Можете да създадете резервно копие с нещо подобно:
> gpg --export-secret-keys jane@example.com > sec-key.asc
Optionally user can chose to export an ‚encrypted backup‘ of the secret key ,to avoid accidental leakage of secret key (This is not a foolproof method or replacement for offline computers but should still provide good security against leakage).
> gpg --export-secret-keys --armor jane@example.com | gpg --symmetric --cipher-algo AES256 -o sec-key.gpg
При изпълнение на горната команда ще се покаже подкана за въвеждане на парола. Трябва да съхранявате тази парола на сигурно място за успешното декриптиране на вашия частен ключ.
В Linux може да се използва следната команда за сигурно изтриване и изтриване на некриптираното резервно копие на ключа от диска.
> shred -u sec-key.asc
Ключов внос¶
Имате основен ключ и два подключени ключа, които могат да бъдат импортирани в ключа Nitrokey. Преди да продължите, моля, уверете се, че наистина разполагате с резервно копие на ключа, ако имате нужда от такова. Командата keytocard, използвана в следващите стъпки, ще изтрие вашия ключ от диска!
We start the process by accessing the interactive interface of GnuPG again with gpg --edit-key --expert keyID, whereas keyID is either the ID of the key or the email address used during key generation.
> 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
Току-що импортирахме основния ключ в картата. Сега продължаваме с двата подключа. Въвеждаме key 1, за да изберем подключ за криптиране, и въвеждаме keytocard отново и избираме слота за използване.
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
Сега премахваме избора на първия ключ с key 1 и избираме втория подключ с key 2 и го преместваме също с keytocard. След това излизаме от системата и запазваме промените.
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
Ключовете ви вече са преместени в Nitrokey и по този начин са защитени хардуерно. Поздравления!
Експортиране на публичен ключ и използване на Keyserver¶
Въпреки че можете да започнете да използвате своя Nitrokey веднага след генерирането на ключовете във вашата система, трябва да импортирате публичния си ключ във всяка система, в която искате да използвате Nitrokey. За да сте подготвени, имате две възможности: Или записвате публичния ключ, където пожелаете, и го използвате в друга система, или записвате публичния ключ в уеб страница/ключов сървър.
Генериране на файл с публичен ключ¶
To get a simple file of your public key, you can just use gpg --armor --export keyID > pubkey.asc. Use either the fingerprint as keyID (look at gpg -K to get it) or just use your email address as an identifier.
You can carry this file with you or send it to anyone who you like. This file is not secret at all. If you want to use the Nitrokey on another system, you first import this public key via gpg --import pubkey.asc
and then types gpg --card-status so that the system knows where to look for this key. That’s all.
Качване на публичния ключ¶
If you don’t want to carry a public key file, you can upload it to keyserver. For the common SKS federated keyservers, for example, keyserver.ubuntu.com. Type gpg --keyserver keyserver.ubuntu.com --send-key keyID. If you are using another machine, you can just import it by using gpg --keyserver keyserver.ubuntu.com --recv-key keyID.
You can also use keys.openpgp.org. The recommended way is to do this by gpg --export your_address@example.net. If you are using another machine, you can just import it by using gpg --auto-key-locate hkps://keys.openpgp.org.
Another possibility is to change the URL setting on your card. Start gpg --card-edit again and first set the URL where the key is situated (e.g. on the keyserver or on your webpage etc.) via the url
command. From now on you can import the key on another system by just using the fetch command within the gpg --card-edit environment.