NetBSD上でYubiKey 5 NFCの各機能を使ってみる (1)

この記事は、NetBSD Advent Calendar 2025の17日目の記事です。

はじめに

以前、YubiKey 5 NFCを日本国内の代理店から購入したのですが、その直後にそのYubiKey 5 NFCのファームウェアには脆弱性が見付かってしまいました。 しかも、FIDO credentialsの登録数が十分ではなく、あまり活用できない常態でした。 今回は、YubiKeyの公式オンラインストアからファームウェアバージョン5.7.4のものを購入しました。 これは既存の脆弱性はないようですし、FIDO credentialsの登録可能数も十分のようです。

YubiKey 5 NFCはいろいろな機能があるようです。製品紹介のページの表を見ると、 以下の9つの機能があるようです。ただ、YubiKeyの提供する機能と1:1と言う訳ではないような気もします。 各機能をNetBSD/amd64-currentから使ってみたいと思います。

  1. WebAuthn
  2. FIDO (CTAP 1, 2, 2.1)
  3. Universal Second Factor (U2F)
  4. Smart Card / PIV
  5. Yubico OTP
  6. OATH - HOTP (Event)
  7. OATH - TOTP (Time)
  8. OpenPGP
  9. Secure Static Password

NetBSDでYubiKeyを管理するツールをインストールする

YubiKey Managerのページには、QTで書かれたGUIツールと、CLIのツールの2つが紹介されています。 pkgsrcにはいずれも収録されているのですが、今回はCLIツールであるykmanコマンドの方を使ってみます。 以下のようにインストールすれば良いでしょう。 今回はPython 3.14ベースで使ってみます。 ちなみに、NetBSDで正常に使えるのは、py314-yubikey-manager-5.8.0nb1以降のバージョンです。

# /usr/pkgsrc/security/py-yubikey-manager
# make install

ところが、これだけでは全てのYubiKey 5 NFCの機能を使うことができません。 py314-yubikey-manager-5.8.0nb1は、機能ごとにpcscd(8)経由かuhid(4)経由でYubiKey 5 NFCにアクセスします。 uhid(4)は追加のソフトウェアは不要 えすが、pcscd(8)経由でアクセスするには、以下のように実行する必要があります。

; ccidパッケージがpcscd(8)経由でSmart Cardとしてアクセスするのに必要です。
# /usr/pkgsrc/security/ccid
# make install
; その上で、pcscd(8)を起動させておく必要があります。
# cp /usr/pkg/share/examples/rc.d/pcscd /etc/rc.d
# echo "psccd=YES" >> /etc/rc.conf
# service pcscd start

ここまで実施すれば、YubiKey 5 NFCの機能にアクセスすることはできるように見えます。 現時点で全ての動作を確認してはいないので、必要になったら追加のセットアップを考えたいと思います。

YubiKey 5 NFCの情報を取得する

yumanコマンドは、複数のPythonインタープリターで動くものを共存できるように、alternative frameworkでPythonインタープリターのバージョン番号付きのコマンド名にするようになっています。 Python 3.14ベースの場合には、ykmanコマンドはykman-3.14という名前になっているはずです。

何のオプションも指定せずにykmanコマンドを実行すると、使えるオプションとサブコマンドを表示させることができます。 以下のように表示されるので、一通り情報を表示させてみます。

Usage: ykman-3.14 [OPTIONS] COMMAND [ARGS]...

  Configure your YubiKey via the command line.

  Examples:

    List connected YubiKeys, only output serial number:
    $ ykman list --serials

    Show information about YubiKey with serial number 123456:
    $ ykman --device 123456 info

Options:
  -d, --device SERIAL             specify which YubiKey to interact with by
                                  serial number
  -r, --reader NAME               specify a YubiKey by smart card reader name
                                  (can't be used with --device or list)
  -t, --scp-ca FILENAME           specify the CA to use to verify the SCP11
                                  card key (CA-KLCC)
  -s, --scp CRED                  specify private key and certificate chain
                                  for secure messaging, can be used multiple
                                  times to provide key and certificates in
                                  multiple files (private key, certificates in
                                  leaf-last order), OR SCP03 keys in hex
                                  separated by colon (:) K-ENC:K-MAC[:K-DEK]
  -p, --scp-password PASSWORD     specify a password required to access the
                                  --scp file, if needed
  -l, --log-level [error|warning|info|debug|traffic]
                                  enable logging at given verbosity level
  --log-file FILE                 write log to FILE instead of printing to
                                  stderr (requires --log-level)
  --diagnose                      show diagnostics information useful for
                                  troubleshooting
  -v, --version                   show version information about the app
  --full-help                     show --help output, including hidden
                                  commands
  -h, --help                      show this message and exit

Commands:
  info     show general information
  list     list connected YubiKeys
  script   run a python script
  config   configure the YubiKey, enable or disable applications
  fido     manage the FIDO applications
  hsmauth  manage the YubiHSM Auth application
  oath     manage the OATH application
  openpgp  manage the OpenPGP application
  otp      manage the YubiOTP application
  piv      manage the PIV application

これによると、infoで全体の情報を表示させ、fido、hsmauth、oath、openpgp、otp、pivという6つのサブコマンドで機能を管理できるようです。

$ ykman-3.14 info
Device type: YubiKey 5 NFC
Serial number: XXXXXXXX
Firmware version: 5.7.4
Form factor: Keychain (USB-A)
Enabled USB interfaces: OTP, FIDO, CCID
NFC transport is enabled

Applications    USB     NFC
Yubico OTP      Enabled Enabled
FIDO U2F        Enabled Enabled
FIDO2           Enabled Enabled
OATH            Enabled Enabled
PIV             Enabled Enabled
OpenPGP         Enabled Enabled
YubiHSM Auth    Enabled Enabled

ここで見ると、FIDO U2FとFIDO2は別々の機能になっているようです。 できることも違ったはずなので、当然かもしれません。

6つのサブコマンドでinfoコマンドを実行した結果を掲載したいと思います。

$ ykman-3.14 fido info
AAGUID:                       XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
PIN:                          8 attempt(s) remaining
Minimum PIN length:           4
Always Require UV:            Off
Credential storage remaining: 97
$ ykman-3.14 hsmauth info
YubiHSM Auth version:             5.7.4
Management key retries remaining: 8/8
$ ykman-3.14 oath info
OATH version:        5.7.4
Password protection: disabled
$ ykman-3.14 openpgp info
OpenPGP version:            3.4
Application version:        5.7.4
PIN tries remaining:        3
Reset code tries remaining: 0
Admin PIN tries remaining:  3
Require PIN for signature:  Once
KDF enabled:                False
$ ykman-3.14 otp info
Slot 1: programmed
Slot 2: empty
$ ykman-3.14 piv info
PIV version:              5.7.4
PIN tries remaining:      3/3
PUK tries remaining:      3/3
Management key algorithm: AES192
WARNING: Using default PIN!
WARNING: Using default PUK!
WARNING: Using default Management key!
CHUID: No data available
CCC:   No data available

このYubiKey 5 NFCは、実は既にFirefox経由でPINの設定と3つのFIDO credentialsを登録済みになっています。 今日はここまでにして、次回はfidoサブコマンドで管理できる機能を使ってみたいと思います。

0 件のコメント:

コメントを投稿

注: コメントを投稿できるのは、このブログのメンバーだけです。

NetBSD上でYubiKey 5 NFCの各機能を使ってみる (1)

この記事は、 NetBSD Advent Calendar 2025 の17日目の記事です。 はじめに 以前、YubiKey 5 NFCを日本国内の代理店から購入したのですが、その直後にそのYubiKey 5 NFCのファームウェアには脆弱性が見付かってしまい...