ircd-hybridをssl通信で通信内容暗号化

■ 目的
ircは通信内容が平文で流れるので、パケット解析ツールなどを使えば簡単に盗聴されてしまう。
通信内容をsslで暗号化して、セキュリティ向上をはかる。
ircd-hybridでのssl設定がどうしても見つからなかったため、stoneで、規定ポートへのパケットをsslで暗号化してircに転送する設定を行う。
また、バックグラウンドで走らせるため、起動スクリプトも作成する。

■ 必要パッケージ
・openssl
・openssl-devel
・stone
cvs(stoneがインストールされていない場合)

■ openssl/openssl-develのインストール

[root@example ~]# yum install openssl openssl-devel

■ stoneのインストール

# cvsにログイン(パスワードなし)
[root@example tmp]# cvs -d :pserver:anonymous@cvs.sourceforge.jp:/cvsroot/stone login

# チェックアウト
[root@example tmp]# cvs -d :pserver:anonymous@cvs.sourceforge.jp:/cvsroot/stone co stone

# コンパイル
[root@example tmp]# cd stone
[root@example stone]# make linux-ssl

# 実行ファイルをパスが通ってる場所にコピー
[root@example stone]# cp -v stone /usr/local/bin/

# stoneのテスト
# ircへの通信を6668経由で6667に接続するように設定。
# ircクライアントから6668に接続できるかテスト。
[root@example tmp]# stone localhost:6667 6668

# ssl証明書を作成
[root@example tmp]# cd /etc/pki/tls/certs/
[root@example certs]# make stone.pem

# stoneのテスト
# ircクライアントの通信を6668経由で暗号化して6667に接続するように設定。
# ircクライアントからssl経由で6668に接続できるかテスト。
[root@example certs]# stone localhost:6667 6668/ssl

■ 設定ファイルの作成

 # ircssl通信用設定ファイルを格納するディレクトリを作成
[root@example ~]# mkdir /etc/ircd-ssl
# 設定ファイルを新規作成
[root@example ~]# vi /etc/ircd-ssl/ircd-ssl.conf
# ircdのポート番号
IRCD_PORT=6667
# sslとして動作させるポート番号
IRCD_SSL_PORT=6668

■ 起動スクリプトの作成
本来は/etc/init.d/functionsに定義されている関数を使用してプロセスの管理を行うべきかと思うが、今回はめんどいので割愛。
また、例外処理も入れてない。

# 起動スクリプトを新規作成
[root@example ~]# vi /etc/init.d/ircd-ssl

#!/bin/bash
PATH=${PATH}:/usr/local/bin
prog=ircd-ssl
desc="ircd-hybrid(SSL)"
pidf=/var/run/${prog}.pid

# 設定を読み込む
[ -f /etc/${prog}/${prog}.conf ] && . /etc/${prog}/${prog}.conf

function clean() {
[ -e $pidf ] && rm -f $pidf
}

function start() {
echo "$desc 開始"
stone localhost:$IRCD_PORT $IRCD_SSL_PORT/ssl &
echo $! > $pidf
}

function stop() {
echo "$desc 停止"
[ -e $pidf ] && kill -9 `cat $pidf`
clean
}

case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: $prog {start|stop|restart}" >&2
;;
esac

# 実行権限追加
[root@example ~]# chmod +x /etc/init.d/ircd-ssl

■ 起動テスト

# ircdを起動する
[root@example ~]# /etc/init.d/ircd start

# ircd-sslを起動する
[root@example ~]# /etc/init.d/ircd-ssl start
# 起動確認
[root@example ~]# ps aux | grep 6668

# ircd-sslを停止する
[root@example ~]# /etc/init.d/ircd-ssl stop
# 停止確認
[root@example ~]# ps aux | grep 6668

# ircd-sslを再起動する
[root@example ~]# /etc/init.d/ircd-ssl restart
# 起動確認
[root@example ~]# ps aux | grep 6668

■ iptablesの設定
ircdのポートを閉じて、6668のポートを開放。
設定ファイル:/etc/sysconfig/iptables


# -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 6667 -j ACCEPT

  • A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 6668 -j ACCEPT