LoginSignup
7
10

More than 5 years have passed since last update.

Windowsでoathtoolを使ってOTP(TOTP)認証/2段階認証をする

Last updated at Posted at 2018-05-25

PCだけで認証したいけど、oathtoolはWindowsには対応してない

PC単体で2段階認証ができればいいのに、できればCUIで、と思った人は私以外にも絶対いると思う。調べてみたところ、MacOSX/Linuxではoath-toolkitというパッケージに含まれるoathtoolコマンドで2段階認証ができるらしい

  • Linuxの場合は

-- RHEL系

sudo yum install oathtool

-- Debian/Ubuntu系

sudo apt-get install oathtool

  • Mac OS Xの場合

brew install oath-toolkit

でインストールすれば使えるのに、Windowsだとそれがない(UWPでUbuntuやFedoraを入れればできなくもないけれど)、GUIのアプリだとWinAuthなどがありますが、GUIなのでバッチに組み込んで使ったり、コマンドラインで使うのが難しい
CUIのパッケージがあればいいのにと思って…調べてみたのですけどないのですよ

見つけたものは古かった

実は検索してみたところ、古いバージョンのものはあった。
oathtool-1.10.0-cygwin.rar
このパッケージは以下のサイトで見つけたものの、バージョンが古くbase32が使えないなど、現行の二段階認証やMFAには使えない。
http://rubli.info/t-blog/2011/09/03/generating-oath-otps-on-windows-with-oathtool/

無いなら作るしかない、ビルドするしかないじゃないか!!

というわけで、MacOSX/Linuxに存在するoathtoolをWindows用にCygwinでビルドしてみました。
使い方は適当なフォルダに展開して、コマンドラインで実行してください
このツールがあれば、WindowsだけでgithubやGoogle、AWSの2段階認証やMFAができます

  • ビルド元のソース

※ビルドには Windows7 64bit環境でCygwin 2.10.0-1 x86_64を使っています。

http://download.savannah.nongnu.org/releases/oath-toolkit/
http://download.savannah.nongnu.org/releases/oath-toolkit/oath-toolkit-2.6.2.tar.gz
http://download.savannah.nongnu.org/releases/oath-toolkit/oath-toolkit-2.6.2.tar.gz.sig

ビルドについては、cygportを用いて、Daisuke Fujimura さんの
https://github.com/fd00/yacp/tree/master/oath-toolkit
を利用して生成させていただきました。

  • cygportを使ったビルド
git clone https://github.com/fd00/yacp/tree/master/oath-toolkit
ls oath-toolkit-2.6.2-1bl1.cygport
oath-toolkit-2.6.2-1bl1.cygport

cygport oath-toolkit-2.6.2-1bl1 fetch
cygport oath-toolkit-2.6.2-1bl1 prep
cygport oath-toolkit-2.6.2-1bl1 compile
cygport oath-toolkit-2.6.2-1bl1 check
cygport oath-toolkit-2.6.2-1bl1 install
cygport oath-toolkit-2.6.2-1bl1 package
  • ビルドバイナリの依存調査(Windowsの標準DLL以外のCygwinランタイムのみ抽出)
$ ldd /usr/bin/oathtool.exe
     cygoath-0.dll => /usr/bin/cygoath-0.dll (0x5aa680000)
     cygwin1.dll => /usr/bin/cygwin1.dll (0x180040000)
名前   : oathtool-2.6.2-x86_64.zip
サイズ : 1209138バイト (1180 KiB)
SHA256 : 9AFDB8F9DA1211E4D2553153BFB0952EBE78F1E56391468C4248980CF5278542

※64bitバイナリなので注意!!

  • アーカイブファイルの内容

含まれるファイルは以下の通りです。oathtool.exe,cygwin1.dll,cygoath-0.dllの3つのファイルが1つのフォルダに入っていれば動作します。

cygoath-0.dll
cygwin1.dll
NEWS
oathtool.exe
README
version.xml
COPYING

コマンドラインで実行した場合のヘルプは以下の通り

oathtool 2.6.2

Generate and validate OATH one-time passwords.

Usage: oathtool [OPTIONS]... [KEY [OTP]]...

  -h, --help                    Print help and exit
  -V, --version                 Print version and exit
      --hotp                    use event-based HOTP mode  (default=on)
      --totp[=STRING]           use time-variant TOTP mode  (possible
                                  values="sha1", "sha256", "sha512"
                                  default=`sha1')
  -b, --base32                  use base32 encoding of KEY instead of hex
                                  (default=off)
  -c, --counter=COUNTER         HOTP counter value
  -s, --time-step-size=DURATION TOTP time-step duration  (default=`30s')
  -S, --start-time=TIME         when to start counting time steps for TOTP
                                  (default=`1970-01-01 00:00:00 UTC')
  -N, --now=TIME                use this time as current time for TOTP
                                  (default=`now')
  -d, --digits=DIGITS           number of digits in one-time password
  -w, --window=WIDTH            window of counter values to test when
                                  validating OTPs
  -v, --verbose                 explain what is being done  (default=off)

Report bugs to: oath-toolkit-help@nongnu.org
oathtool home page: <http://www.nongnu.org/oath-toolkit/>
General help using GNU software: <http://www.gnu.org/gethelp/>

実際の使い方は、MacやLinuxの使い方と変わらないので、代表的な使い方だけ

oathtool.exe --totp --base32 "認証用のBASE32のコード"

以上、まぁ、だれかの役に立つかもしれないので公開しておきます。

7
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
10