WordpressのログインにMixiのOpenIDを使用する設定

Wordpress MUのログインにMixiのOpenIDを使えないかと調査したメモ。(記事のタイトルとしては「Lampp環境でcurlのhttps通信をする方法」の方が適切だなと後で思った。)

環境はCentOS5.4, Lampp 1.7.1, wordpress mu 2.8.6

OpenIDについてはwikipediaで。OpenIDを使った処理手順は

  1. WordpressでOpenIDを発行するサイトを指定(ここではmixiとする)
  2. mixiのサイトに飛ばされ、mixiのユーザーIDとパスワードでログイン
  3. OpenIDの認証画面が表示され、「許可」をするとwordpressに戻る
  4. wordpress側ではOpenIDで処理をする

OpenIDを使うプラグインはopenidがあるので試しにインストールしてみた。この時点のバージョンは3.3.3

管理画面のプラグインでインストールすると、fatal errorが出る場合は、ここを参考にしながら、ファイル内のget_user_metaをget_usermetaに置換する。

次はサーバー(プラグイン)がhttpsでmixi.jpと通信するための証明書をインストールする。下記サイトを参考に。

cURL に HTTPS でアクセスできるように証明書を追加する

mixi OpenIDのサンプルコードをPHP OpenID Libraryで動かしてみた

実行したコマンドは

# cd /opt/lampp/share/curl/
# cat mixi.jp.crt >> crul-ca-bundle.crt

でも動かない。curlでのhttps接続が失敗するみたいなので、curl単独のコマンドを実行してみる。

# /opt/lampp/bin/curl https://mixi.jp/

これは下記エラーで失敗する。

curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). The default
bundle is named curl-ca-bundle.crt; you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.

次は証明書を指定して実行してみる。

# /opt/lampp/bin/curl --cacert /opt/lampp/share/curl/mixi.jp.crt https://mixi.jp/

これも失敗するので、証明書が有効でないみたい(形式が違うのか?)。

何となくCentOSにインストールされていたcurlで実行してみると

# curl https://mixi.jp/

なんと成功する!なぜ?メジャーな認証局の証明書を使うようになったのかな?でもLamppで失敗してたのは謎。

何はともあれ、使われた証明書を検索

# find /usr/ -name "libcurl.so*" -type f|head -n 1|xargs strings|grep ca-bundle.crt

パスが出力されるので、これをコピー

# cp /etc/pki/tls/certs/ca-bundle.crt /opt/lampp/share/curl/

あとは前のをバックアップして、curl-ca-bundle.crtにrenameすれば

# /opt/lampp/bin/curl https://mixi.jp/

が成功するはず。

これでwordpressのログイン画面からでもOpenID認証ができるようになったけど、このプラグインでは思ったような処理が実現できないので自作しそう。

OpenID2.0の仕様を勉強しないといけない予感。