-->

FIDO-U2F絡みのメモ2

二段階認証セキュリティキー(U2F)対応の認証ページを作るための私的メモ。Pythonならお手軽スタンドアローンU2Fサーバになる。と思いきや色々入れるハメに。

環境

FIDO U2F Security Key
API
https://github.com/Yubico/python-u2flib-server
サーバ
windows7+cygwin/pyhton2.7
クライアント
chrome51

導入

API先の情報のまま
$ git clone https://github.com/Yubico/python-u2flib-server.git

$ cd python-u2flib-server
$ git submodule init
$ git submodule update
 
$ python setup.py sdist
 
$ python examples/u2f_server.py

うまく行けばスタンドアロンでU2Fサーバになる。

[20/Jun/2016 13:31:44] Starting server on http://localhost:8081
ImportError: .. cryptography
$ pip install cryptography
問題が起きた例
UnicodeDecodeError: 'ascii' codec can't decode ..

$ vim /usr/lib/python2.7/site-packages/sitecustomize.py

## 設定を追記
import sys
sys.setdefaultencoding('utf-8')
.. ffi.h: No such file ..

apt-cyg install libffi-devel

.. openssl/opensslv.h: No such file ..

apt-cyg install openssl-devel

Successfully installed cryptography idna pyasn1 enum34 ipaddress cffi pycparser
ImportError: .. webob.dec
$ pip install webob
Successfully installed webob

流れ

APIの説明のように、ざっくり以下のような流れ。

メモ1のPHP-APIにあるu2f-api.jsを使ってWebデモを作った方が確かに楽そうだ。

Registration
GET /enroll
{
 "authenticateRequests": [],
 "registerRequests": [
  {
   "challenge": "9s80ruHc",
   "version": "U2F_V2",
   "appId": "http://localhost:8081"
  }
 ]
POST /bind
data={"clientData":"eyJvcmln"}
Authentication
GET /sign
{
 "authenticateRequests": [
  {
   "challenge": "EHuxwx0A",
   "version": "U2F_V2", 
   "keyHandle": "bxXoPvBA",
   "appId": "http://localhost:8081"
  }
 ]
}
POST /verify
data={"clientData":"eyJvcmln"}