IPsec入門

佐塚 秀人(久留米工業大学)

 

本日の内容

 

1.  IPsecの基本概念

2.  Linuxでのフリー実装FreeS/WANのインストールと設定

 

1. IPsecの基本概念

1.1 IPsecの概要

IPsecはIPパケットを、パケット単位で暗号化、認証するセキュリティプロトコル

・次期TCP/IPプロトコルIPv6では標準で実装される(IPv4でも利用可)

・3つのプロトコルよりなる

- ESP(Encapsulating Security Payload)

IPパケットのデータを暗号化し、盗聴、改竄、偽造を防ぐ

- AH(Authentication Header)

IPパケットに認証ヘッダを付加し、改竄、偽造をされていないことを保証する

- IKE(Internet Key Exchange)

通信相手の認証を行い、ESPやAHで用いる秘密情報(鍵)の交換を行う

HOST-HOST間だけでなくROUTER-ROUTER間の通信路をセキュア化

VPNの容易に実現(典型的用途)

 

1.2 階層モデルとセキュリティプロトコル

表1にネットワーク階層と各種セキュリティプロトコルに位置付けを簡単にまとめる。IPsecはネットワーク層のセキュリティレベルを高め、SSL, SSHはトランスポート層のセキュリティレベルを高めるよう働く。

1 ネットワーク階層とセキュリティプロトコル

アプリケーション層(HTTP,SMTP,POP,...)

S/MIME

トランスポート層(TCP,UDP)

SSL, SSH

ネットワーク層(IP)

IPsec

データリンク層

 

物理層

 

IPレベルのセキュリティプロトコルであるIPsecと、TCPレベルのセキュリティプロトコルのSSL, SSHなどとを比較する。

SSLやSSHはTCPストリームの暗号化を行い。アプリケーションごとの通信路の暗号化に適している。

IPsecはIPパケット単位の認証、暗号化を行うため、IP通信網全体のセキュリティを高めることができる。上位のアプリケーションは意識することなく使える。

SSLやSSHが偽造パケット等によるTCPストリームの切断については無力だが、IPsecではパケットごとの認証を行っているので、このような攻撃に対しても有効である。

SSLやSSHはアプリケーションごとで対応ができるが、IPsecは多くの場合OSのカーネルへの組み込みが必要になる。

 

1.3 暗号化手法・鍵の管理

IPsecでは、同時に多数の通信相手と異なった設定の暗号通信をしなくてはならない。

SAD(Security Association Database)

通信相手ごとの設定情報(通信プロトコル,アルゴリズム、鍵)のデータベース(表)

SPI(Security Parameters Index)

SADエントリにつけられたID(32ビット整数)

 

1.4 ESP(Encapsulated Security Payload)プロトコル

IPパケットを暗号化しIPパケットとして転送するプロトコル。IPパケットデータはペイロード部分に暗号化され挿入される(図1)。ESPは送り先を記述したIPヘッダが付加されネットワーク上を転送される。

Security Parameters Index (SPI)

Sequence Number

Payload Data (variable)

 

Padding

 

Payload Length

Next Header

Authentication Data (variable)

図1 ESPプロトコル

1.5 AH(Authentication Header)プロトコル

ESPではデータは暗号化され、ペイロード部に挿入されるが、AHでは平文としてそのまま送られる。AHはIPヘッダとペイロードの間に挿入される。AHは図2のようになっている。

Next Header

Payload Length

RESERVED

Security Parameters Index (SPI)

Squence Number

Authentication Data (variable)

図2 AHプロトコル

AHではペイロード部は暗号化されないため、完全性と認証のみを提供する。AHは市民が暗号を用いることができない国のために提供されている(フランスなど)。

 

1.6 IKE(Internet Key Excange)プロトコルによる自動鍵交換

ノード間の認証、ESPやAHで用いる、暗号・認証アルゴリズムのネゴシエーション、秘密鍵の交換はIKEを用いて行われる。IKEはUDPにより実装され、デーモンとして実現することができる。

Phase 1:ノード間に暗号通信路を確保し、ノード間の認証を行う。

Phase 2:AHやESPで使う秘密鍵やアルゴリズムをネゴシエーションする。

 

Phase 1

1往復目:IKE通信路の暗号アルゴリズムを選ぶ

2往復目:Diffee-Hellman公開暗号アルゴリズムにより鍵交換(IKE通信用の鍵)をする

3往復目:通信相手の認証を行う

・あらかじめ決めた文字列(pre-shared secret)

X.509/SPKI/PGPなどに基づく証明書

Phase 2

Phase 1で確立した秘密の通信路を使いESP,AHで用いる暗号アルゴリズムや秘密鍵を交換する。交換された情報は、両端ノードのSADエントリとして登録され、ESP,AHで利用される。

 

1.7 IPsecのモード

パケット転送モード

(1) トランスポート・モード

元のIPパケットのペイロード部だけを取り出して、ESPのペイロード部またはAHのペイロード部に乗せる方式。ただし、HOST-TO-HOSTでの利用に限られる

(2) トンネル・モード

元にIPパケットのIPヘッダ部も含めて送る方式。IPsecの相手先ノードで完全に元のパケットに復元できるため、通信経路の一部をIPsec化することが可能(IPトンネリング)。トンネルモードを使えばVPNが容易に実現可能。IPsecのメインの用途はVPNである。

暗号化・認証の手段

状況に応じて、パケットの暗号化方式(ESPを用いる)・認証方式(AHの場合)を選択し、IKEで自動的にネゴシエーションすることができる。暗号化方式では、DESと無暗号化が標準で組み込まれている必要があり、認証方式(ハッシュアルゴリズム)は確かHMAC-MD5が標準で組み込まれている必要がある。

相互認証の方式

IPsecは主にVPNで用いられるので、SSLやメールのように認証の手段はそれほど重要でない場合が多い(認証局等を必要としない)。

IPsecではIKEで相互認証を行う。

pre-shared key方式

RSA公開鍵暗号

X.509

 

2. LinuxへのFreeS/WANのインストールと設定

The Linux FreeS/WAN Project

2.1 FreeS/WANについて

John Gilmoreらによって1996年から始まったプロジェクト

Linux上でのIPsec(ESP, AH, IKE)の実装

GNU Public Licenceに従って配布(フリーソフトウェア)

・現在のバージョン freeswan-1.9

・カーネルバージョン2.0, 2.2, 2.4 で動作

WEBサイト: http://www.freeswan.org/

 

2.2 FreeS/WANの概要

FreeS/WANパッケージ

KLIPS     ESP, AHの実装    -- カーネルに実装

Pluto     IKEの実装        -- daemonとして実装(UDP 500番ポート)

・コントロールプログラム:/usr/local/sbin/ipsec  -- 詳細はmanに

・起動スクリプト:/etc/rc.d/init.d/ipsec -- RedHatはmakeで自動インストール

FreeS/WAN運用

VPN運用(サブネットのプライベートネットワークの接続)

・外部からの接続(ダイアルアップ等で外部から接続:Road Warrior)

HOST-HOST間の接続

 

2.3 インストールの手順

(1) カーネルソース,カーネルパッケージの入手

RedHat系の場合:kernel-2.2.XX-YYY.src.rpm

(2) カーネルソースの展開,パッチ当て

RedHat, Vine, Kondara等は、配布されているカーネルに、ディストリビューション・オリジナルのパッチが施してあるの注意。

RPM対策

a. FreeS/WANインストール用SPECファイルを作成し、rpmパッケージを作成

b. 一般的なカーネルソースに自分でパッチを当ててFreeS/WANを入れたカーネルを作成

c. rpmパッケージを利用しパッチまで当て、後は手動でFreeS/WANを入れる

FreeS/WANは単純なカーネルパッチの形式になっていなので、aはrpmパッケージ作成の経験がいる(途中まで作業をしたがくじけている)。bは作業量的に面倒、適切なパッチを当てないと動作しない場合も多い(別の意味でエキスパート向き)。cは現実的だがやや邪道。

(3) FreeS/WANの導入

★一般的導入

[1] FreeS/WANを入れず設定(make depまでやらないと導入できない)

$ make menuconfig で設定

$ make dep

[2] FreeS/WANのソースを展開

Makefileの中のlinuxカーネルのソースパスを設定(標準は/usr/src/linux)

[3] コンパイル・インストール

スーパーユーザになって一気にコンパイルとインストール

$ cd ($FREESWAN_TOP)

$ su

# make oldgo  # 特に何も設定を変更しない場合(実はこれで十分)

または make mgo    # make menuconfigが呼ばれる

make xgo    # make xconfig

make ogo    # make config

これだけで必要なツールのコンパイルとインストール、カーネルのコンパイルが行われる(かなり強引)。個別にやりたい場合はMakefileを読むこと。

[4] カーネルのインストール

# make kinstall          # FreeS/WAN対応カーネルのインストール

# vi /etc/lilo.conf      # liloの設定

# /sbin/lilo             # liloの実行

[5] 再起動(とりあえず設定は不要)

以下のようめメッセージが起動時に出力されればOK

Starting FreeS/WAN IPsec 1.9...

KLIPS startup, FreeS/WAN version: 1.9

initialising PF_KEY domain sockets.

initialisation of device: ipsec0

initialisation of device: ipsec1

initialisation of device: ipsec2

initialisation of device: ipsec3

 

RedHatLinuxへの簡単な導入法(邪道版)

[1] ソースパッケージの入手と展開

# rpm -ivh kernel-2.2.18-XXX.src.rpm

/usr/src/redhat/SOURCE 以下にソース、パッチ等が展開される

/usr/src/redhat/SPECSにkernel.specが置かれる

[2] FreeS/WANソースの展開

# cd /usr/src/redhat/BUILD/linux

# tar xvzf $ANYWHARE/freeswan-1.9.tar.gz

Makefileの中のカーネルソースの場所を/usr/src/redhat/BUILD/linuxに修正する

[3] SPECファイル(kernel.spec)の修正

/usr/src/redhat/SPECSの下のkernel.specのバージョン番号等を修正

本格的に書き換えを行えばパッケージを完全に作成可能であるが、FreeS/WANの導入にやや癖があるので今回はキャンセル(Kondara MNU/Linuxでは独自にパッチを作成していた)。

[4] パッチを当てる

# cd /usr/src/redhat/SPECS

# rpm -bp kernel.spec

[5] カーネルの設定

とりあえずカーネルの設定を行う。/usr/src/redhat/SOURCS以下に展開された既に設定された.configファイルをコピーしてから設定を開始したほうがよい。

# cd /usr/src/redhat/BUILD/linux

# cp ../../SOURCS/kernel-2.2-i686-XXX-YYY.config .config

# make menuconfig

# make dep

[6] FreeS/WANの導入・コンパイル・インストール・テスト

FreeS/WANの導入は一般的なインストールと同じ

# cd /usr/src/redhat/BUILD/linux/freeswan-1.9

# make oldgo

# make kinstall

# vi /etc/lilo.conf

# /sbin/lilo

# /sbin/reboot

注意:カーネルのリリース・バージョンのつけ方に注意

 

2.4 設定とテスト

設定ファイル

/etc/ipsec.conf     -- 設定ファイル

/etc/ipsec.secret   -- 秘密鍵設定ファイル

鍵の交換・認証の方式

(1) マニュアル方式

Plutoは用いない

・手動で暗号鍵を設定

・実験以外では勧められない

(2) 自動鍵交換方式

pre-shared key認証方式(PSA)

RSA

ネットワークの構成

(1) GATEWAY-TO-GATEWAY                   -- VPN(トンネリング)

     Sunset==========West------------------East=========Sunrise
           local net       untrusted net       local net

(2) GATEWAY-TO-HOST(dynamic addressing)  -- Road Warrior

                                           telecommuter's PC or
       corporate LAN                       traveller's laptop
     Sunset==========West------------------East
           local net       untrusted net

(3) HOST-TO-HOST

                     West------------------East
                           untrusted net

トンネルモード            type=tunnel    (1),(2),(3)で利用可

トランスポートモード      type=transport (3)でしか利用できない

 

2.5 ipsec.confの構成

※詳細はhttp://www.freeswan.org/freeswan_trees/freeswan-1.9/doc/config.html

※具体的な例は$FREESWAN_TOP/doc/examplesを参照

ipsec.confは2点間の実験ならば自分側(left)、相手側(right)はまったく同じ内容でよい

(1) config setup部      基本設定

(2) conn %default部     接続方式のデフォルト設定

(3) conn部              各接続ごとの設定

 

2.6 RSA認証鍵の生成と設定

conn %defaultの設定

authby=rsasig

鍵の生成

$ ipsec rsakeysig sigkey 鍵長 > keyfile

秘密鍵格納

/etc/ipsec.secretに格納

:RSA {

    keyfileの中身

}

公開鍵の設定

生成したkeyfileの中のpubkey=..の部分の公開鍵をipsec.confのleftrsasigkyと相手側の公開鍵を同じくrightrsasigkeyに設定。

公開鍵はDNSに登録し運用することも可能

 

ipsec.conf examples:

# sample connections

# This file is RCSID $Id: examples,v 1.5 1999/12/13 02:38:16 henry Exp $

 

 

 

# basic configuration

config setup

            # THIS SETTING MUST BE CORRECT or almost nothing will work.

            interfaces="ipsec0=eth1 ipsec1=ppp0"

            # Debug-logging controls:  "none" for (almost) none, "all" for lots.

            klipsdebug=none

            plutodebug=none

            # Manual connections to be started at startup.

            manualstart="test1 test2"

            # Auto connections to be loaded into Pluto at startup.

            plutoload="samplehth samplefire"

            # Auto connections to be started at startup.

            plutostart=samplefire

 

 

 

# defaults for subsequent connection descriptions

conn %default

            # How persistent to be in (re)keying negotiations (0 means very).

            keyingtries=0

            # Parameters for manual-keying testing (DON'T USE OPERATIONALLY).

            spi=0x200

            esp=3des-md5-96

            espenckey=0x01234567_89abcdef_02468ace_13579bdf_12345678_9abcdef0

            espauthkey=0x12345678_9abcdef0_2468ace0_13579bdf

            # key lifetime (before automatic rekeying)

            keylife=8h

 

 

 

# sample connection

conn sample

            # Left security gateway and subnet behind it.

            left=10.0.0.1

            leftsubnet=172.16.0.0/24

            # Right security gateway and subnet behind it.

            right=10.12.12.1

            rightsubnet=192.168.0.0/24

            # Authorize this connection, but don't actually start it, at startup.

            auto=add

 

# sample tunnel (manually or automatically keyed)

# Here we just use ESP for both encryption and authentication, which is

# the simplest and often the best method.

conn sample

            # left security gateway (public-network address)

            left=10.0.0.1

            # next hop to reach right

            leftnexthop=10.44.55.66

            # subnet behind left (omit if left end of the tunnel is just the s.g.)

            leftsubnet=172.16.0.0/24

            # right s.g., subnet behind it, and next hop to reach left

            right=10.12.12.1

            rightnexthop=10.88.77.66

            rightsubnet=192.168.0.0/24

            # (manual) SPI number

            spi=0x200

            # (manual) encryption/authentication algorithm and parameters to it

            esp=3des-md5-96

            espenckey=[192 bits]

            espauthkey=[128 bits]

 

# In the remaining examples, deviations from the sample-tunnel configuration

# are marked with ###.

 

# sample host-to-host tunnel (no subnets)

# Here we assume (for purposes of illustration) that the hosts talk directly

# to each other, so we don't need next-hop settings.

conn samplehth

            ### left host (public-network address)

            left=10.0.0.1

            ### next hop to reach right

            leftnexthop=

            ### right host

            right=10.12.12.1

            ### next hop to reach left

            rightnexthop=

            ### (manual) SPI number

            spi=0x300

            # (manual) encryption/authentication algorithm and parameters to it

            esp=3des-md5-96

            espenckey=[192 bits]

            espauthkey=[128 bits]

 

# sample hybrid tunnel, with a host on one end and a subnet (behind a

# security gateway) on the other

# This case is also sometimes called "road warrior".

conn samplehyb

            ### left host (public-network address)

            left=10.0.0.1

            # next hop to reach right

            leftnexthop=10.44.55.66

            # subnet behind left

            leftsubnet=172.16.0.0/24

            ### right host, and next hop to reach left

            right=10.12.12.1

            rightnexthop=10.88.77.66

            ### (manual) SPI number

            spi=0x400

            # (manual) encryption/authentication algorithm and parameters to it

            esp=3des-md5-96

            espenckey=[192 bits]

            espauthkey=[128 bits]

 

# sample firewall-penetrating tunnel

# Here we assume that firewalling is being done on the left side.

conn samplefire

            # left security gateway (public-network address)

            left=10.0.0.1

            # next hop to reach right

            leftnexthop=10.44.55.66

            # subnet behind left (omit if left end of the tunnel is just the s.g.)

            leftsubnet=172.16.0.0/24

            ### left is firewalling for its subnet

            leftfirewall=yes

            # right s.g., subnet behind it, and next hop to reach left

            right=10.12.12.1

            rightnexthop=10.88.77.66

            rightsubnet=192.168.0.0/24

            ### (manual) SPI number

            spi=0x500

            # (manual) encryption/authentication algorithm and parameters to it

            esp=3des-md5-96

            espenckey=[192 bits]

            espauthkey=[128 bits]

 

# sample transport-mode connection (which can only be host-to-host)

# Here we use the whole nine yards, with encryption done by ESP and

# authentication by AH; this perhaps is slightly preferable for transport

# mode, where the IP headers are exposed.

conn sampletm

            ### transport mode rather than tunnel

            type=transport

            ### left host (public-network address)

            left=10.0.0.1

            # next hop to reach right

            leftnexthop=10.44.55.66

            ### right host, and next hop to reach left

            right=10.12.12.1

            rightnexthop=10.88.77.66

            ### (manual) SPI number

            spi=0x600

            ### (manual) encryption algorithm and parameters to it

            esp=3des

            espenckey=[192 bits]

            ### (manual) authentication algorithm and parameters to it

            ah=hmac-md5

            ahkey=[128 bits]

            ### (auto) authentication control

            auth=ah

 

# sample description with keys split out into a separate section

# Normally the key section would go in a separate file, with tighter

# permissions set on it.

conn samplesep

            # left security gateway (public-network address)

            left=10.0.0.1

            # next hop to reach right

            leftnexthop=10.44.55.66

            # subnet behind left (omit if left end of the tunnel is just the s.g.)

            leftsubnet=172.16.0.0/24

            # right s.g., subnet behind it, and next hop to reach left

            right=10.12.12.1

            rightnexthop=10.88.77.66

            rightsubnet=192.168.0.0/24

            ### (manual) SPI number

            spi=0x700

            # (manual) encryption/authentication algorithm and parameters to it

            esp=3des-md5-96

            also=samplesep-keys

 

# keys for the previous section

# Normally this would go in a separate file, picked up using an include line,

# to allow keeping the keys confidential.

conn samplesep-keys

            espenckey=[192 bits]

            espauthkey=[128 bits]

 

3. IPsecの今後と現状について

既に多くのルータ製品に実装されている(Cisco, YAMAHA,)。現在のIPv4ネットワークではアドレス資源の関係で、NATやIP Masquradeが多用されており、IPsecとの相性がよくない点が問題であるが、IPv6では標準で実装されるようになること、IPアドレス制限が実質的になくなることから、広く用いられる可能性は大きい。

LinuxのFreeS/WAN以外にもOpenBSD上の実装、IPv6のプロジェクトのKAMEも有名である。FreeS/WANはまだ機能が不足しているところもあるようだが(X.509対応?)、実用上十分な性能・安定性をもっているようである。日本のLinuxコミュニティではまだそれほど使われているようではないが、今後広まる可能性は大である。