バックアップ付きOpenPGP鍵生成#

(Nitrokey Pro 2 - macOS)

以下の説明では、OpenPGPキーの生成とNitrokeyへのコピー方法を説明します。この方法は、Nitrokeyを紛失したり壊したりした場合に、鍵のバックアップが取れるという利点があります。説明は、GnuPGのコマンドライン・インターフェースに基づいています。そのため、お使いのシステムにGnuPGがインストールされている必要があります。Windows用の最新のGnuPGバージョンは`こちら<https://www.gpg4win.org/>`_、MacOS用の最新バージョンは`こちら<https://gpgtools.org/>`_でご覧いただけます。Linuxシステムのユーザは、パッケージマネージャの助けを借りてGnuPGをインストールしてください。

キー・ジェネレーション#

まず最初に、ローカルで鍵を生成する必要があります。どのような鍵の属性を使用するかを決めることができ、最も重要なことは、鍵をエクスポートしてどこかに保存し、鍵を復元する必要がある場合に備えることができることです。

メインキーと暗号化サブキー#

コマンド 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]

注釈

対応アルゴリズムについては、`のfaqをご参照ください。<../faq.html>`_

認証用サブキー#

これで、署名と認証の機能を持つメインキー([SC]と表示)と、暗号化のためのサブキー([E]と表示)ができました。認証が必要なユースケースでは、別のサブキーが必要になります。このサブキーは次のステップで生成します。``gpg --edit-key --expert keyID``と入力して処理を開始します。"keyID "には、鍵のIDまたは鍵生成時に使用したメールアドレスを指定します。

> 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``と入力するだけで、キーを追加することができます。使用するキーを選択する必要があります。set your own capabilities "を選択することは非常に重要です。なぜなら、他の方法では利用できない "authenticate "機能を利用したいからです。``s``と``<xid="330"></x>``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

キーインポート#

メインキーと2つのサブキーがありますが、これらはNitrokeyにインポートすることができます。先に進む前に、必要に応じてキーのバックアップが本当にあるかどうか確認してください。次のステップで使用する``keytocard``コマンドは、ディスクからキーを 削除 します!

まず、``gpg --edit-key --expert keyID``で再びGnuPGの対話型インターフェースにアクセスし、``keyID``には、鍵のIDか、鍵の生成時に使用したメールアドレスを指定します。

> 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

メインキーをカードに取り込んだところです。次に、2つのサブキーを入力します。``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``で最初のキーを選択解除し、<xid="79"></x>`key 2``で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に移され、こうしてハードウェアで固定されました。おめでとうございます。

公開鍵のエクスポートと鍵サーバの利用#

お使いのシステムで鍵を生成した後、すぐにNitrokeyを使い始めることができますが、Nitrokeyを使用したいすべてのシステムで公開鍵をインポートする必要があります。そのための準備として、2つの選択肢があります。公開鍵を好きな場所に保存して別のシステムで使用するか、Webページ/鍵サーバに公開鍵を保存するかです。

公開鍵ファイルの生成#

公開鍵のシンプルなファイルを取得するには、``gpg --armor --export keyID > pubkey.asc``を使用すればよいでしょう。フィンガープリントを "keyID "として使用するか(``gpg -K``を参照してください)、メールアドレスを識別子として使用してください。

このファイルを持ち歩いたり、好きな人に送ったりすることができます。このファイルは全く秘密ではありません。別のシステムでNitrokeyを使いたい場合は、まず``gpg --import pubkey.asc``を介してこの公開鍵をインポートし、次に``gpg --card-status``をタイプして、システムがこの鍵をどこで探すかを知るようにします。以上です。

公開鍵のアップロード#

公開鍵ファイルを持ち歩きたくない場合は、keyserverにアップロードすることができます。これは、``gpg --keyserver search.keyserver.net --send-key keyID``と入力することで行うことができます。別のマシンを使っている場合は、``gpg --keyserver search.keyserver.net --recv-key keyID``を使ってインポートすることができます。

もう一つの可能性は、カードのURL設定を変更することです。``gpg --card-edit``を再度起動し、最初に``url``コマンドを使用して、キーが置かれているURLを設定します(例:キーサーバーや自分のウェブページなど)。今後は、``gpg --card-edit environment``コマンドの中で``fetch``コマンドを使用するだけで、別のシステムにキーをインポートすることができます。