このブログはURLが変更になりました

新しいブログはこちら→ https://matsuu.hatenablog.com/

オレオレWaveサーバを構築する方法

先日参加したWaveプロトコル勉強会でオレオレWaveサーバーを立ち上げ、sandboxと接続するところまでできました。その方法を紹介します。

いきなり結論

ここに掲載している手順は、ほぼ次のURLにかかれている手順の抄訳です。
http://www.24100.net/2009/11/federate-google-wave-sandbox-with-your-own-fedone-server/

オレオレWaveサーバは準備できますが、Google WaveのようなWebインタフェースが使えるわけではありません。別途Waveクライアントを用意する必要があります。
wave-protocolにテキストベースのテスト用Waveクライアントがついてきますのでそれで動作確認ができます。
google wave clientで検索するといくつかWaveクライアントが出てきますが、動作未確認です。
Windows(Cygwin)でも一応サーバが立ち上がるところまでいけますが、勉強会ではうまく接続できないなどトラブりました。方法を確立できる方は是非。

必要なもの

事前準備

まずSunの Java SDKか、Open Java SDKと、Mercurialをインストールしましょう。
Gentooなら、

# emerge sun-jdk
# emerge mercurial

Ubuntuなら、

$ sudo apt-get install sun-java6-jdk sun-java6-fonts
$ sudo apt-get install mercurial

続いてOpenfireをインストールします。
Gentooなら、

# emerge openfire
# cp -a /opt/openfire/conf/openfire.xml.sample /opt/openfire/conf/openfire.xml
# vi /opt/openfire/conf/openfire.xml
# /etc/init.d/openfire start

Ubuntuなら、

$ wget http://www.igniterealtime.org/downloadServlet?filename=openfire/openfire_3.6.4_all.deb
$ sudo dpkg -i openfire_3.6.4_all.deb

http://<あなたのドメイン>:9090/ でウィザードに従い設定します。

  • Server Setting > Domain でドメイン名を設定、私の場合は matsuu.org
  • Database Settings は Embedded Database を選択
  • Profile Settings は Default のまま
  • Administrator Account は メールアドレスとパスワードを登録

一通り設定したら、一旦openfireを再起動する必要があります。

# /etc/init.d/openfire restart

再起動できたら、 http://<あなたのドメイン>:9090/ でusernameにadmin、passwordに先ほど設定したパスワードを入力します。

ログインできたら、Server Settings > External Components > Service EnabledでEnabledを選択し、Default shared secretに適当な文字列を設定します。ここで設定したDefault shared secretは後ほど使用します。

続いて、Server Settings > Security Settings > Server Connection SecurityでCustomを選択し、Server DialbackはAvailable、TLS methodはOptionalを選択します。Accept self-signed certificatesにもチェックを入れます。Server Connection SecurityがOptionalに戻りますが気にする必要はありません。

Server Settings > Compression Settings > Server Compression PolicyでAvailableを選択します。

Server Settings > File Transfer SettingsでDisabledを選択します。

Server Settings > Registration & LoginでInband Account Registration、Change Password、Anonymous LoginでDisabledを選択します。

Server Manager > System PropertiesでフォームのProperty Nameにxmpp.pubsub.enabled、Property Valueにfalseを入力します。

Group Chat > Group Chat Settingsでconference domeinを削除します。

wave-protocolの取得

wave-protocolを取得、構築します。

$ hg clone https://wave-protocol.googlecode.com/hg/ wave-protocol
$ cd wave-protocol
$ ant

DNSの設定

XMPPサーバのAレコードとSRVレコードを登録します。私はwave.matsuu.orgなのでこんな感じ。

# vi /etc/bind/pri/matsuu.org.zone
wave                    IN A            206.125.172.114
_xmpp-server._tcp       IN SRV  10      0       5269    wave
_xmpp-server._tcp.wave  IN SRV  10      0       5269    wave

# /etc/init.d/named restart

ちゃんと設定できてるか確認します。

$ dig +short -t SRV _xmpp-server._tcp.matsuu.org
10 0 5269 wave.matsuu.org.
$ dig +short -t SRV _xmpp-server._tcp.wave.matsuu.org
10 0 5269 wave.matsuu.org.

証明書の作成

StartSSLXMPP用にドメイン認証を行います。
2048ビット長で証明書を作成します。CSRも作成しておきます。

$ openssl genrsa 2048 | openssl pkcs8 -topk8 -nocrypt -out wave.matsuu.org.key
...
Common Name (eg, YOUR name) []:wave.matsuu.org
...
$ openssl req -new -nodes -sha1 -days 365 -key wave.matsuu.org.key -out wave.matsuu.org.csr

(注意:以降は私の記憶が曖昧です。嘘が含まれているかもしれません)

StartSSLのサインアップ

  • https://www.startssl.com/?app=12 にアクセスし、Sign-upを選択(Express Laneでも可能だそうです)
  • すべての項目を埋めて次へ
  • 入力したメールアドレスにAuthentication Codeが届くので、Authentication Codeを入力して次へ
  • 途中で証明書をブラウザにインストールする作業が入ります。必ずインストールしましょう

証明書に署名してもらう

  • Validation WizardからDomain Name Validationを選択します。
  • あなたのドメイン名を入力します。
  • verification codeを送る画面になるので、有効なメールアドレスを選択します
  • 届いたメールにかかれたverification codeを入力して最後まで進めます
  • Certificate Wizardを選択します
  • XMPP(Jabber) SSL/TLS Certificateを選択します
  • Generate Private KeyはSkipで飛ばします
  • 先ほど生成したcsr(wave.matsuu.org.csr)の中身をStartSSL画面上のテキストフィールドに張り付けます
  • サブドメイン名にwaveと入力します
  • Tool BoxのRetrieve Certificateで署名された証明書を取得します

証明書のインストール

まずStartSSLの証明書を取得します。 http://www.startssl.com/certs/ からsub.class1.server.ca.pemをダウンロードします。
wave-protocolを展開したディレクトリに各ファイルを設置します。

  • wave.matsuu.org.key
  • wave.matsuu.org.crt
  • sub.class1.server.ca.pem

FedOneで証明書を使用するための設定

run-config.shを作成します

$ cp run-config.sh.example run-config.sh
$ vi run-config.sh
(以下のように編集)
WAVE_SERVER_DOMAIN_NAME=wave.matsuu.org

WAVE_SERVER_HOSTNAME=wave.matsuu.org

XMPP_SERVER_SECRET=(openfireのDefault shared secretの値を設定)

WAVESERVER_DISABLE_SIGNER_VERIFICATION=false

CERTIFICATE_FILENAME_LIST=${WAVE_SERVER_DOMAIN_NAME}.crt,sub.class1.server.ca.pem

証明書をJavaのkeystoreへ

StartSSLの証明書をJavaのkeystoreに格納します。cacertsの場所はシステムによって異なります。Gentooなら次のようになります。

# keytool -importcert -storetype jks -keystore /etc/java-config-2/current-system-vm/jre/lib/security/cacerts -file sub.class1.server.ca.pem

パスワード入力のプロンプトが出た場合は「changeit」と入力します。

Waveサーバ(FedOne)を動かす

さて動かしてみましょう。

$ ./run-server.sh

Javaのエラーが表示されなければ成功ですね。

コンソールクライアントからつないでみる

./run-client-console.sh matsuu

接続できたらwaveを作ってみましょう。

/new
/open 0

適当にメッセージを入力してみてください。また、複数箇所から接続してみてください。
ヘルプは/helpで確認できます。