OpenPGP-nøglegenerering med sikkerhedskopiering#

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.

Nøglegenerering#

Først skal du generere en nøgle lokalt. Du kan selv bestemme, hvilke nøgleattributter du vil bruge, og - vigtigst af alt - du kan eksportere nøglen og gemme den et sted, hvis du har brug for at gendanne nøglen.

Hovednøgle og krypteringsundernøgle#

Vi kan bruge kommandoen gpg --full-generate-key --expert til at starte en guidet nøglegenerering med alle mulige indstillinger. Du kan vælge nøgletype (normalt RSA (1) eller ECC (9)), nøglens længde og andre attributter. Det følgende output er blot et simpelt eksempel, du kan vælge andre værdier.

> 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]

Bemærk

For information om de understøttede algoritmer henvises til faq.

Undernøgle til autentificering#

Du har nu en hovednøgle med mulighed for at underskrive og certificere (markeret som [SC]) og en undernøgle til kryptering (markeret som [E]). Det er nødvendigt at have endnu en undernøgle til anvendelsestilfælde, hvor der er behov for autentificering. Denne undernøgle genereres i det næste trin. Indtast gpg --edit-key --expert keyID for at starte processen, mens »keyID« enten er id’et for nøglen eller den e-mail-adresse, der blev anvendt under genereringen af nøglen.

> 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>

Nu er du i GnuPG’s interaktive tilstand, og du kan tilføje en nøgle ved blot at skrive addkey. Du skal vælge den nøgle, du ønsker at bruge. Det er afgørende at vælge »set your own capabilities«, fordi vi ønsker at have »authenticate«-funktionen, som ellers ikke er tilgængelig. Vi skifter mellem sign og encrypt ved at skrive s og e, og vi aktiverer autentificering ved at skrive a<x>.

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

Vi afslutter med q. Herefter skal vi besvare de samme spørgsmål som før. Endelig har vi et nøgle sæt klar til brug, som vi kan importere til vores enhed.

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

Nu er det et godt tidspunkt at tage backup af din nøgle. Opbevar venligst denne sikkerhedskopi meget sikkert. Det er den bedste praksis aldrig at have denne nøgle på en almindelig computer med forbindelse til internettet, så nøglen aldrig bliver kompromitteret. Du kan oprette en sikkerhedskopi med noget som f.eks:

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

Nøgle Import#

Du har en hovednøgle og to undernøgler, som kan importeres til din Nitrokey. Før du fortsætter, skal du sikre dig, at du virkelig har en sikkerhedskopi af nøglen, hvis du har brug for en. Kommandoen keytocard, der bruges i de næste trin, vil slette din nøgle fra din disk!

Vi starter processen ved at få adgang til GnuPG’s interaktive grænseflade igen med gpg --edit-key --expert keyID, mens keyID enten er id’et for nøglen eller den e-mail-adresse, der blev brugt under genereringen af nøglen.

> 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

Vi har lige importeret hovednøglen til kortet. Nu fortsætter vi med de to undernøgler. Vi skriver key 1 for at vælge krypteringsundernøglen og skriver keytocard igen og vælger den slot, der skal bruges.

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

Nu fravælger vi den første nøgle med key 1 og markerer den anden undernøgle med key 2 og flytter den også med keytocard. Herefter afslutter vi og gemmer ændringerne.

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

Dine nøgler er nu flyttet til Nitrokey og dermed sikret i hardware. Tillykke med det!

Eksport af offentlig nøgle og brug af nøgleserver#

Selv om du kan begynde at bruge din Nitrokey med det samme, når du har genereret nøglerne på dit system, skal du importere din offentlige nøgle på alle de systemer, du vil bruge Nitrokey på. Så for at være forberedt har du to muligheder: Du kan enten gemme den offentlige nøgle hvor som helst og bruge den på et andet system, eller du gemmer den offentlige nøgle på en webside/nøgleserver.

Generering af en fil med en offentlig nøgle#

Hvis du vil have en simpel fil med din offentlige nøgle, kan du blot bruge gpg --armor --export keyID > pubkey.asc. Brug enten fingeraftrykket som »keyID« (se gpg -K for at få det) eller brug bare din e-mail-adresse som identifikator.

Du kan have denne fil med dig eller sende den til hvem du vil. Denne fil er slet ikke hemmelig. Hvis du vil bruge Nitrokey på et andet system, skal du først importere denne offentlige nøgle via gpg --import pubkey.asc og derefter skrive gpg --card-status, så systemet ved, hvor det skal lede efter denne nøgle. Det er det hele.

Upload af den offentlige nøgle#

Hvis du ikke ønsker at have en offentlig nøglefil med dig, kan du uploade den til keyserver. Det kan du gøre ved at skrive gpg --keyserver search.keyserver.net --send-key keyID. Hvis du bruger en anden maskine, kan du bare importere den ved at bruge gpg --keyserver search.keyserver.net --recv-key keyID.

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.