エリプティックカーブ(ECC)のサポート

Compatible Nitrokeys

3A/C/Mini

Passkey

HSM 2

Pro 2

FIDO2

Storage 2

Start

U2F

active

inactive

active

active

inactive

active

inactive

inactive

RSA-2048はますます安全ではなくなっていく

ドイツ連邦情報セキュリティ局(Bundesamt für Sicherheit in der Informationstechnik、BSI)は、セキュリティ上の理由から、2048ビットの長さのRSA鍵を2022年以降`に使用することを推奨しなくなりました <https://www.bsi.bund.de/SharedDocs/Downloads/EN/BSI/Publications/TechGuidelines/TG02102/BSI-TR-02102-1.pdf?_blob=publicationFile&v=10>`__ 。つまり、近い将来、より長い鍵が使われるようになることが予想されます。使用期間を5年と仮定すると、すでに長い鍵を生成する必要があります。しかし、3072ビットや4096ビットの長いRSA鍵では速度が著しく低下します。このため、新しいNitrokey Storage 2およびPro 2(および統合されたOpenPGP Cardバージョン3.3)では、`楕円曲線暗号(ECC)<https://en.wikipedia.org/wiki/Elliptic-curve_cryptography>`__ による暗号化をサポートしています。この方法は、小さいECCキーでも長いRSAキーと同様に安全で、しかもかなり高速であると考えられています。

楕円曲線暗号の基礎知識

RSA とは対照的に、楕円曲線暗号にはさまざまな形式 (いわゆる曲線) があります。特に、NISTの曲線の開発には、`NSAが<https://www.schneier.com/essays/archives/2007/11/did_nsa_put_a_secret.html>`_関与しています。曲線にバックドアの証拠がなくても、特定の曲線を使用すると信頼性に疑問が生じます。幸い、新しいNitrokey Storage 2とPro 2は、NISTとBrainpoolという2種類の曲線をサポートしています。以下では、Brainpool曲線を使用します。`この記事<https://arstechnica.com/information-technology/2013/10/a-relatively-easy-to-understand-primer-on-elliptic-curve-cryptography/>`_は、楕円曲線暗号の一般的な理解を得るための良い入口となります。

システム要件

楕円曲線に基づく鍵を作成するには、Nitrokey Storage 2 / Pro 2とGnuPGバージョン2.1.17以上が必要です。

You can read Nitrokey's OpenPGP Card version via gpg2 --card-status:

> gpg2 --card-status
Reader ...........: 20A0:...
Application ID ...: D276...
Version ..........: 3.3
...

The Version field represents the version of the OpenPGP Card integrated in the Nitrokey — in this case it is 3.3 as needed for Elliptic-curve cryptography. OpenPGP Card version 2.2 doesn't support ECC.

インストールされているGnuPGのバージョンについては、gpg2  --version で知ることができます。最低でもバージョン2.1.16が必要です。Windows用のGnuPGの最新版は`こちら<https://www.gpg4win.org/>`__ 、MacOS用の最新版は`こちら<https://gpgtools.org/>`__ にあります。GNU/Linux ディストリビューションの Ubuntu (18.04 以降)、Debian (Stretch 以降)、Arch Linux、Fedora (Release 26 以降)、openSUSE Tumbleweed には、GnuPG の適切なバージョンが含まれています。この記事の最後に、古いバージョンのUbuntuでGnuPGを手動でアップデートする方法を紹介しています。

重要

GnuPG 2.0は現在も使用されていますが、2017年にサポートが終了しています。すべての通信相手は、ECCによるメールの暗号化にGnuPG 2.1以降を使用する必要があり、そうしないと非互換性の問題が発生する可能性があります。したがって、この問題を回避できることが確実な場合にのみECCを使用する必要があります。

Nitrokey Storage 2 / Pro 2の鍵生成について

Once these requirements are fulfilled, you can get started. (Warning: existing keys will be overwritten in the process!) You now have two options. The first option is to create the key directly on the Nitrokey Storage 2 / Pro 2. The benefit here is that the key will never be outside the device and as such can never be read out. The second option is to import a previously locally generated key. The advantage in this case is that you can securely store a backup of the key, which can then be restored in case the Nitrokey is lost. Only the first option is described below. In order to create a key with backup, you can access the following instructions and use this general information to transfer the key to the Nitrokey.

GnuPGにはすでに「generate」コマンドがあり、これを使ってデバイス上で簡単に鍵を作成することができます。しかし、鍵の種類を直接選択することはまだできませんので、まず鍵を準備する必要があります。これには以下のコマンドを使用します。

> gpg-connect-agent "SCD SETATTR KEY-ATTR --force 1 19 brainpoolP256r1" /bye
> gpg-connect-agent "SCD SETATTR KEY-ATTR --force 2 18 brainpoolP256r1" /bye
> gpg-connect-agent "SCD SETATTR KEY-ATTR --force 3 19 brainpoolP256r1" /bye

また、次のセクションで説明するように、他の曲線を選択することもできます。

ここで、gpg2 --card-edit と入力すると、「鍵の属性」のところに、rsa2048ではなく、brainpoolP256r1があることがわかります。

> gpg2 --card-edit
Reader ...........: 20A0:4109:0000000000000:0
Application ID ...: D276000124010303000500005F100000
Version ..........: 3.3
Manufacturer .....: ZeitControl
Serial number ....: 00005F10
Name of cardholder: [not set]
Language prefs ...: [not set]
Sex ..............: unspecified
URL of public key : [not set]
Login data .......: [not set]
Signature PIN ....: forced
Key attributes ...: brainpoolP256r1 brainpoolP256r1 brainpoolP256r1
Max. PIN lengths .: 64 64 64
PIN retry counter : 3 0 3
Signature counter : 0
Signature key ....: [none]
Encryption key....: [none]
Authentication key: [none]
General key info..: [none]

そして、キーを作成します。

gpg/card> admin
Admin commands are allowed

gpg/card> generate
Make off-card backup of encryption key? (Y/n) n
Please note that the factory settings of the PINs are
PIN = '123456' Admin PIN = '12345678'
You should change them using the command --change-pin
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: Jane Doe
Email address: jane.doe@example.org
Comment:
You selected this USER-ID:
"Jane Doe <jane.doe@example.org>"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
gpg: key 7F8C68E1B084E169 marked as ultimately trusted
gpg: revocation certificate stored as '/home/jane/.gnupg/openpgp-revocs.d/F8C00BC1636A7D7604A31A877F8C68E1B084E169.rev'
public and secret key created and signed.

Nitrokeyは、RSA鍵の代わりに楕円曲線暗号を採用したので、通常通り使用することができます。

カーブ

上記の手順では、Brainpool曲線を選択しました。また、NISTの曲線を使用することもできます。設定は以下のようにして行います。

> gpg-connect-agent "SCD SETATTR KEY-ATTR --force 1 19 nistp256" /bye
> gpg-connect-agent "SCD SETATTR KEY-ATTR --force 2 18 nistp256" /bye
> gpg-connect-agent "SCD SETATTR KEY-ATTR --force 3 19 nistp256" /bye

UbuntuにおけるGnuPGのアップデート

The following steps are needed only if you are running a Ubuntu version older than 18.04. You can install GnuPG 2.1.18 on such system with the commands below. This involves newer Debian packages, which is the easiest option. This approach has been tested successfully on Ubuntu 17.10 and propbably works on 16.04 as well. However, the occurence of problems during usage can't be excluded.

$ mkdir gnupg_tmp
$ cd gnupg_tmp
$ wget http://ftp.debian.org/debian/pool/main/g/gnupg2/gnupg_2.1.18-8~deb9u1_amd64.deb
$ wget http://ftp.debian.org/debian/pool/main/g/gnupg2/dirmngr_2.1.18-8~deb9u1_amd64.deb
$ wget http://ftp.debian.org/debian/pool/main/g/gnupg2/gnupg-agent_2.1.18-8~deb9u1_amd64.deb
$ wget http://ftp.debian.org/debian/pool/main/g/gnupg2/scdaemon_2.1.18-8~deb9u1_amd64.deb
$ sudo dpkg -i *
$ cd ..
$ rm -rf gnupg_tmp

インストールを元に戻したい場合は、以下のコマンドを実行する必要があります。

$ sudo dpkg --remove --force-depends gnupg dirmngr gnupg-agent scdaemon
  # (removes manually installed packages)
$ sudo apt-get install gnupg dirmngr gnupg-agent scdaemon
  # (installs the appropriate packages from regular package repositories)