R.A. Epigonos et al.

[google] oathtool で 2 段階認証のシークレットキーから確認コードを生成

google の 2 段階認証を設定した。しかしガラケーでiphoneとかandroidを持っていないのでGoogle Authenticatorを使えない、海外にいるので携帯で確認コードを受け取れない、さらに海外ローミング契約してない、そもそも携帯圏外だし、バックアップ確認コードも手元にない。そこでどうすんだという話。Google の 2 段階認証は rfc6238 に技術仕様が公開されている。rfc6238 を実装したプログラムが oath-toolkit に含まれる oathtool。oathtool を使って、確認コードを生成しよう。大事なのはシークレットキー(秘密鍵)さえあれば確認コードを手元の計算機で生成できるということ。

oathtool をインストール

# apt-get install oathtool
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  liboath0
The following NEW packages will be installed:
  liboath0 oathtool
0 upgraded, 2 newly installed, 0 to remove and 1 not upgraded.
Need to get 90.9 kB of archives.
After this operation, 205 kB of additional disk space will be used.
Do you want to continue [Y/n]? Y
Get:1 http://ftp.jp.debian.org/debian/ wheezy/main liboath0 amd64 1.12.4-1 [44.6 kB]
Get:2 http://ftp.jp.debian.org/debian/ wheezy/main oathtool amd64 1.12.4-1 [46.3 kB]
Fetched 90.9 kB in 0s (273 kB/s)
Selecting previously unselected package liboath0.
(Reading database ... 151790 files and directories currently installed.)
Unpacking liboath0 (from .../liboath0_1.12.4-1_amd64.deb) ...
Selecting previously unselected package oathtool.
Unpacking oathtool (from .../oathtool_1.12.4-1_amd64.deb) ...
Processing triggers for man-db ...
Setting up liboath0 (1.12.4-1) ...
Setting up oathtool (1.12.4-1) ...

Google 2 段階認証の確認コードを生成するために必要な情報は、時間ベースのワンタイムパスワード (--totp)、有効期間はある時間 (--now "2000-01-01 00:00:00 UTC") から 30 秒間 (--time-step-size 30s)、base32 でエンコードされた 16 文字のキー (--base32 "JBSWY3DPEHPK3PXP")、である。キーは Google の 2 段階認証プロセスの設定ページで「シークレットキー」と呼ばれているもの。QR コードか base32 文字列 (16 文字) で入手できる。生成された 6 桁の数字が確認コード。

$ oathtool -v --totp --now "2000-01-01 00:00:00 UTC" --time-step-size 30s --base32 "JBSWY3DPEHPK3PXP"
Hex secret: 48656c6c6f21deadbeef
Base32 secret: JBSWY3DPEHPK3PXP
Digits: 6
Window size: 2
Step size (seconds): 30
Start time: 1970-01-01 00:00:00 UTC (0)
Current time: 2000-01-01 00:00:00 UTC (946684800)
Counter: 0x1E18240 (31556160)

050144

"X OAM SKW OXF SDW WQT" のようにキーに空白が含まれる場合は削除して "XOAMSKWOXFSDWWQT" のようにする。

$ oathtool -v --totp --now "2000-01-01 00:00:00 UTC" --time-step-size 30s --base32 `echo "X OAM SKW OXF SDW WQT" | tr -d ' '`
Hex secret: bb80c92aceb9643b5a13
Base32 secret: XOAMSKWOXFSDWWQT
Digits: 6
Window size: 2
Step size (seconds): 30
Start time: 1970-01-01 00:00:00 UTC (0)
Current time: 2000-01-01 00:00:00 UTC (946684800)
Counter: 0x1E18240 (31556160)

615689

oathtool のデフォルト設定と重複するオプションを省けば、通常の使い方は以下 (シークレットキーが JBSWY3DPEHPK3PXP の場合)。

$ oathtool -v --totp --base32 JBSWY3DPEHPK3PXP
R2: The prover and verifier MUST either share the same secret or the
    knowledge of a secret transformation to generate a shared secret.

R2: 認証される側と認証する側は同じ秘密鍵を共有するかあるいは
    共有秘密鍵を生成する安全な変換方法を共有しなければいけません。

リファレンス

  1. google-authenticator - Two-step verification - Google Project Hosting
  2. RFC 6238 - TOTP: Time-Based One-Time Password Algorithm
  3. Google Authenticator - Wikipedia
  4. security - Google Authenticator implementation in Python - Stack Overflow
  5. Google Authenticator for multi-factor authentication [LWN.net]
  6. OATH Toolkit
  7. OATHTOOL
  8. zaitcev: Seeking Google Authenticator for Linux
  9. Google 認証システムのインストール - Google アカウント ヘルプ
  10. macosx: oathtool totp google 2 factor authentication
  11. KeyUriFormat - google-authenticator - The format of URIs containing encoded keys - Two-step verification - Google Project Hosting
  12. http://blog dot jamesdotcuff dot net: cli java based google-authenticator desktop client direct from your shell
  13. Time-based One-time Password Algorithm - Wikipedia, the free encyclopedia

ソーシャルブックマーク

  1. はてなブックマーク
  2. Google Bookmarks
  3. del.icio.us

ChangeLog

  1. Posted: 2010-09-13T05:30:46+09:00
  2. Modified: 2010-09-13T05:30:46+09:00
  3. Generated: 2023-08-27T23:09:14+09:00