iBook G4をOpenVPNサーバにしてみる/その1

OpenVPNで構築する超簡単VPN入門―Windows/Mac OS X/Linux対応

OpenVPNで構築する超簡単VPN入門―Windows/Mac OS X/Linux対応

これを見ながらやってみます。


が、いきなり「Mac OSXはクライアントのみ利用可能です」との説明があり、盛大にコーヒーを吹きこぼす。えーうそー。そんなはずねーべなー。
と思ってGoogleすると

OpenVPN Server on Mac

なるページを発見。参考にさせてもらってレッツトライ。

MacportsXcodeをインストール

OSX 10.5.6をクリーンインストールしたiBook G4にMacportsをインストール。
コンパイルに必要なXcodeLeopardのDVDからインストール。

OpenVPNをインストール

$ sudo port selfupdate
$ sudo port install openvpn2

としてOpenVPNをインストール。/opt/local/sbin/openvpn2 などが出来上がる。

証明書作成準備

$ sudo mkdir /etc/openvpn/
$ sudo cp -r /opt/local/share/doc/openvpn2/easy-rsa /etc/openvpn/
$ cd /etc/openvpn/easy-rsa

リリカルnano派の私は

$ sudo nano vars

として設定ファイルの末尾を以下の通り編集。

export KEY_COUNTRY=JP
export KEY_PROVINCE=Saitama
export KEY_CITY=Kawagoe
export KEY_ORG="自分の組織名"
export KEY_EMAIL="自分のメールアドレス"

rootになる

ここからrootの実行権限が必要となるので、一時的にrootになっておく。

  1. 「アプリケーション>ユーティリティ>ディレクトリユーティリティ」を起動。
  2. 鍵アイコンをクリックしてパスワードを入力し、ロックを解除する。
  3. メニューバーから「編集>ルートユーザを有効にする」をクリックし、rootのパスワードを設定。

varsに実行権限を設定。

$ su -
# cd /etc/openvpn/easy-rsa/
# chmod +x vars

認証局証明書の作成

# . ./vars
# ./clean-all
# ./build-ca
Generating a 1024 bit RSA private key
..................++++++
.........................................++++++
writing new private key to 'ca.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [JP]: <ENTER入力>
State or Province Name (full name) [Saitama]: <ENTER入力>
Locality Name (eg, city) [Kawagoe]: <ENTER入力>
Organization Name (eg, company) [自分の組織名]: <ENTER入力>
Organizational Unit Name (eg, section) []: <ENTER入力>
Common Name (eg, your name or your server's hostname) []:OPEN_VPN
Email Address [自分のメール]: <ENTER入力>

Common Nameだけ入力。

サーバー証明書の作成

# ./build-key-server server
Generating a 1024 bit RSA private key
..........................................................................++++++
...............................................++++++
writing new private key to 'server.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [JP]: <ENTER入力>
State or Province Name (full name) [Saitama]: <ENTER入力>
Locality Name (eg, city) [Kawagoe]: <ENTER入力>
Organization Name (eg, company) [自分の組織名]: <ENTER入力>
Organizational Unit Name (eg, section) []: <ENTER入力>
Common Name (eg, your name or your server's hostname) []:VPN_SERVER
Email Address [自分のメールアドレス]: <ENTER入力>

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []: <ENTER入力>
An optional company name []: <ENTER入力>
Using configuration from /etc/openvpn/easy-rsa/openssl.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
(あれこれ情報が表示される)
Certificate is to be certified until Jan 31 14:18:53 2019 GMT (3650 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

Common Nameだけ入力。あとはEnterとy。

DHパラメータの作成

# ./build-dh
Generating DH parameters, 1024 bit long safe prime, generator 2
This is going to take a long time
..+....(延々)

クライアント証明書の作成

接続するクライアントの数だけ作る。

# ./build-key-pass client1
Generating a 1024 bit RSA private key
......................++++++
......++++++
writing new private key to 'client1.key'
Enter PEM pass phrase: (パスワード)<ENTER>
Verifying - Enter PEM pass phrase: (パスワード)<ENTER>
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [JP]: <ENTER>
State or Province Name (full name) [Saitama]: <ENTER>
Locality Name (eg, city) [Kawagoe]: <ENTER>
Organization Name (eg, company) [自分の組織]: <ENTER>
Organizational Unit Name (eg, section) []: <ENTER>
Common Name (eg, your name or your server's hostname) []:client1<ENTER>
Email Address [自分のメール]: <ENTER>

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []: (VPNクライアント起動時パスワード)<ENTER>
An optional company name []:<ENTER>
Using configuration from /etc/openvpn/easy-rsa/openssl.cnf
DEBUG[load_index]: unique_subject = "yes"
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
(いろいろ情報が表示される)
Sign the certificate? [y/n]:y<ENTER>


1 out of 1 certificate requests certified, commit? [y/n]y<ENTER>
Write out database with 1 new entries
Data Base Updated

パスワードとCommon Nameの設定を行った。

一般人に戻る

ディレクトリユーティリティを使って、rootユーザを無効化しておく。

キーファイルの確認

認証局、サーバー、クライアント(client1,client2)を作成した状態。

$ sudo ls /etc/openvpn/easy-rsa/keys/
01.pem			client1.key		index.txt.attr.old
02.pem			client2.crt		index.txt.old
03.pem			client2.csr		serial
ca.crt			client2.key		serial.old
ca.key			dh1024.pem		server.crt
client1.crt		index.txt		server.csr
client1.csr		index.txt.attr		server.key

server.crt, client1.crt, client1.keyをクライアント側とするMacBookにコピー。

とりあえずここまで。