Last-modified: 2016-10-17 (月) 14:40:02
StrongSwan/インストール

概要

VPNサーバー(IKEv2)としてStrongSwanをインストールします。

手順(インストール)

  1. インストール
    1. Debianの場合
      Everything is expanded.Everything is shortened.
        1
        2
        3
      
       
      -
      !
      
      apt-get install strongswan
      # EAPで認証するなら必要
      apt-get install libcharon-extra-plugins
    2. Ubuntuの場合
      Everything is expanded.Everything is shortened.
        1
        2
      
      -
      !
      
      # 確実に使わないプラグインが分かっている場合は省いてもOK
      apt-get install strongswan strongswan-plugin-af-alg strongswan-plugin-agent strongswan-plugin-certexpire strongswan-plugin-coupling strongswan-plugin-curl strongswan-plugin-dhcp strongswan-plugin-duplicheck strongswan-plugin-eap-aka strongswan-plugin-eap-aka-3gpp2 strongswan-plugin-eap-dynamic strongswan-plugin-eap-gtc strongswan-plugin-eap-mschapv2 strongswan-plugin-eap-peap strongswan-plugin-eap-radius strongswan-plugin-eap-tls strongswan-plugin-eap-ttls strongswan-plugin-error-notify strongswan-plugin-farp strongswan-plugin-fips-prf strongswan-plugin-gcrypt strongswan-plugin-gmp strongswan-plugin-ipseckey strongswan-plugin-kernel-libipsec strongswan-plugin-ldap strongswan-plugin-led strongswan-plugin-load-tester strongswan-plugin-lookip strongswan-plugin-ntru strongswan-plugin-pgp strongswan-plugin-pkcs11 strongswan-plugin-pubkey strongswan-plugin-radattr strongswan-plugin-sshkey strongswan-plugin-systime-fix strongswan-plugin-whitelist strongswan-plugin-xauth-eap strongswan-plugin-xauth-generic strongswan-plugin-xauth-noauth strongswan-plugin-xauth-pam
  2. sysctl設定
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
      5
      6
      7
      8
      9
    
     
     
     
     
     
     
     
     
     
    
    echo "net.ipv4.ip_forward = 1" |  tee -a /etc/sysctl.conf
    echo "net.ipv4.conf.all.accept_redirects = 0" |  tee -a /etc/sysctl.conf
    echo "net.ipv4.conf.all.send_redirects = 0" |  tee -a /etc/sysctl.conf
    echo "net.ipv4.conf.default.rp_filter = 0" |  tee -a /etc/sysctl.conf
    echo "net.ipv4.conf.default.accept_source_route = 0" |  tee -a /etc/sysctl.conf
    echo "net.ipv4.conf.default.send_redirects = 0" |  tee -a /etc/sysctl.conf
    echo "net.ipv4.icmp_ignore_bogus_error_responses = 1" |  tee -a /etc/sysctl.conf
     
    sysctl -p
  3. iptables設定
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
      5
      6
    
    -
    !
    -
    !
     
     
    
    # /etc/network/if-pre-up.d/iptablesなど、iptables用のスクリプトに、ポート設定とNAT設定を追加
     
    # 例
    iptables -A INPUT -p udp --dport 500 -m state --state NEW -j ACCEPT # IKEv2
    iptables -A INPUT -p udp --dport 4500 -m state --state NEW -j ACCEPT # IPsec NAT traversal
    iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
  4. ルーターなどのNAT設定
    UDP500(IKEv2), UDP4500(IPsec NAT traversal)を通して完了です。

証明書作成

OpenSSLで作成したほうが良いですが、簡単のためipsecコマンドで作成します。
例としてPrivateCAの証明書(ECDSA), サーバー証明書(ECDSA), クライアント証明書(ECDSA1通, RSA1通)を作成します。

EAP-MSCHAPv2認証

Windows, OSX, iOS, Androidで接続可能な設定です。

  1. /etc/ipsec.conf
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
    
     
    -
    !
     
    -
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    |
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    |
    !
    -
    !
    -
    !
     
     
     
     
     
    
    config setup
        # ログレベル(<subsystem> <loglevel>, ...)
        charondebug="ike 2, knl 2, cfg 2, net 2, esp 2, dmn 2,  mgr 2"
     
    # デフォルト設定
    conn %default
        # IKE SAの有効期間
        ikelifetime=60m
        # 鍵の有効期間
        keylife=20m
        # リキー猶予
        rekeymargin=3m
        # 接続リトライ回数
        keyingtries=1
        # 鍵交換プロトコル
        keyexchange=ikev2
        # IKE SAで使う暗号化,認証アルゴリズムのリスト
        ike=aes256-sha256-modp1024,aes256-sha256-modp2048
        # ESPで使う暗号化,認証アルゴリズムのリスト
        esp=aes256-sha256-modp1024,aes256-sha256-modp2048
        # DPDポリシー
        dpdaction=clear
        # DPD検出時間 
        dpddelay=300s
        # EAP ID
        eap_identity=%any
        # IKEフラグメント(WindowsクライアントはIKEv2フラグメント非対応)
        fragmentation=yes
        # --- left設定 ---
        # IP 
        left=%defaultroute
        # ID 
        leftid=strongswan2310.cloudapp.net
        # 認証方式
        leftauth=pubkey
        # 証明書送信ポリシー
        leftsendcert=always
        # サブネット
        leftsubnet=10.0.0.0/24
        # 証明書(ECDSAなのはIPフラグメント防止策)
        leftcert=server.crt
        # 自動NAT
        leftfirewall=yes
        # --- right設定 ---
        # IP
        right=%any
        # 認証方式
        rightauth=eap-mschapv2
        # 配布DNSサーバーIP
        rightdns=8.8.8.8
     
    conn mobile
        rightid=%any
        rightsourceip=10.6.0.0/24
        auto=add
  2. /etc/ipsec.secret
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
    
     
    -
    |
    !
    
     : ECDSA server.key
    # EAP-MACHAPv2認証のユーザー名(<ユーザー名> : EAP "<パスワード>")
    # 例.
    bar : EAP "foo"
  3. 再起動
    Everything is expanded.Everything is shortened.
      1
    
     
    
    ipsec restart

EAP-TLS認証

Windows, OSX, iOS, Androidで接続可能な設定です。

  1. /etc/ipsec.conf
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
    
     
    -
    !
     
    -
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    |
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    !
    -
    |
    !
    -
    !
    -
    !
     
     
     
     
     
    
    config setup
        # ログレベル(<subsystem> <loglevel>, ...)
        charondebug="ike 2, knl 2, cfg 2, net 2, esp 2, dmn 2,  mgr 2"
     
    # デフォルト設定
    conn %default
        # IKE SAの有効期間
        ikelifetime=60m
        # 鍵の有効期間
        keylife=20m
        # リキー猶予
        rekeymargin=3m
        # 接続リトライ回数
        keyingtries=1
        # 鍵交換プロトコル
        keyexchange=ikev2
        # IKE SAで使う暗号化,認証アルゴリズムのリスト
        ike=aes256-sha256-modp1024,aes256-sha256-modp2048
        # ESPで使う暗号化,認証アルゴリズムのリスト
        esp=aes256-sha256-modp1024,aes256-sha256-modp2048
        # DPDポリシー
        dpdaction=clear
        # DPD検出時間 
        dpddelay=300s
        # EAP ID
        eap_identity=%any
        # IKEフラグメント(WindowsクライアントはIKEv2フラグメント非対応)
        fragmentation=yes
        # --- left設定 ---
        # IP 
        left=%defaultroute
        # ID 
        leftid=strongswan2310.cloudapp.net
        # 認証方式
        leftauth=pubkey
        # 証明書送信ポリシー
        leftsendcert=always
        # サブネット
        leftsubnet=10.0.0.0/24
        # 証明書(ECDSAなのはIPフラグメント防止策)
        leftcert=server.crt
        # 自動NAT
        leftfirewall=yes
        # --- right設定 ---
        # IP
        right=%any
        # 認証方式
        rightauth=eap-tls
        # 配布DNSサーバーIP
        rightdns=8.8.8.8
     
    conn mobile
        rightid=%any
        rightsourceip=10.6.0.0/24
        auto=add
  2. /etc/ipsec.secret
    Everything is expanded.Everything is shortened.
      1
    
     
    
     : ECDSA server.key
  3. 設定再読み込み
    Everything is expanded.Everything is shortened.
      1
    
     
    
    ipsec restart

クライアント証明書の失効

検証時の環境

参考