Changes between Initial Version and Version 1 of Realisations/2006-2007/Projet/IpsecImplementation


Ignore:
Timestamp:
Apr 28, 2007, 12:37:30 PM (18 years ago)
Author:
alladoum
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Realisations/2006-2007/Projet/IpsecImplementation

    v1 v1  
     1[wiki:Groupe1Entreprise2 Entreprise2] : ListeTutoriaux : IpsecImplementation
     2----
     3= '''''Configuration d'un flux IPSec en mode Transport sous FreeBSD''''' =
     4
     5== Configuration d'IPSec ==
     6Cet exemple a été écrit pour la création d'un flux IPSec en mode Transport entre [wiki:Entreprise2Client1 CLIENT1.ENT2](10.40.0.13) et [wiki:Entreprise2Serveur1 SERVEUR1.ENT2] (10.40.0.9). [[BR]]
     7
     8=== Vérifiez les options ===
     9Les options
     10{{{
     11options  IPSEC
     12options  IPSEC_ESP
     13options  IPSEC_DEBUG (optionnel mais fortement recommandé)
     14}}}
     15 doivent être installées sur le noyau que vous exécutez, sinon [http://www.freebsdebutant.org/index.php?page=configuration_noyau recompilez votre noyau].
     16   * Installez IPSec-tools et Racoon ( votre bonheur se trouve dans les /usr/ports/security)
     17=== Configurez IPSec pour FreeBSD ===
     18[[BR]]
     19   * Créer le fichier /etc/ipsec.conf :
     20{{{
     21$ cat > /etc/ipsec.conf << EOF
     22# Definition des SA + Cles
     23# Rappel :
     24# 3des-cbc,cle de 192 bits (24o)
     25# hmac-md5,cle de 128 bits(16o)
     26flush;
     27
     28## de client1 vers serveur1
     29add 10.40.0.13 10.40.0.9 ah  1000 -m transport -A hmac-md5 "1234567890123456";
     30add 10.40.0.13 10.40.0.9 esp 1001 -m transport -E 3des-cbc "123456789012345678901234";
     31
     32## de serveur1 vers client1
     33add 10.40.0.9 10.40.0.13 ah  2000 -m transport -A hmac-md5 "1234567890123456";
     34add 10.40.0.9 10.40.0.13 esp  2001 -m transport -E 3des-cbc "123456789012345678901234";
     35
     36# Definition des SPD
     37spdflush;
     38spdadd 10.40.0.13 10.40.0.9 any -P out ipsec
     39esp/transport/10.40.0.13-10.40.0.9/use
     40ah/transport/10.40.0.13-10.40.0.9/use;
     41# politique en entree
     42spdadd 10.40.0.9 10.40.0.13 any -P in ipsec
     43ah/transport/10.40.0.9-10.40.0.13/use
     44esp/transport/10.40.0.9-10.40.0.13/use;
     45EOF
     46}}}
     47   * Puis entrez
     48{{{
     49$ setkey -v -f /etc/ipsec.conf
     50}}}
     51   * Maintenant, si vous entrez
     52{{{
     53$ setkey -D -P
     54}}}
     55la création des SA et SP devraient vous produire un affichage à peu près similaire à
     56{{{
     57[root@SERVEUR1 ~]# setkey -P -D
     5810.40.0.13[any] 10.40.0.9[any] any
     59        in ipsec
     60        ah/transport/10.40.0.13-10.40.0.9/use
     61        esp/transport/10.40.0.13-10.40.0.9/use
     62        created: Apr 20 18:10:44 2007  lastused: Apr 20 18:10:44 2007
     63        lifetime: 0(s) validtime: 0(s)
     64        spid=16393 seq=1 pid=7761
     65        refcnt=1
     6610.40.0.9[any] 10.40.0.13[any] any
     67        out ipsec
     68        ah/transport/10.40.0.9-10.40.0.13/use
     69        esp/transport/10.40.0.9-10.40.0.13/use
     70        created: Apr 20 18:10:44 2007  lastused: Apr 20 18:10:44 2007
     71        lifetime: 0(s) validtime: 0(s)
     72        spid=16392 seq=0 pid=7761
     73        refcnt=1
     74}}}
     75   * Pour automatiser cette procédure au démarrage de la machine, éditez dans /etc/rc.conf en ajoutant :
     76{{{
     77ipsec_enable="YES"
     78ipsec_file="/etc/ipsec.conf"
     79}}}
     80   * '''Votre démon IPSec sera actif avec les bons paramètres dès le prochain démarrage'''
     81[[BR]]
     82
     83=== Configurer Racoon ===
     84[[BR]]
     85
     86   * Créer psk.txt initiant l'échange de clé partagé
     87{{{
     88$ cat > psk.txt << EOF
     8910.40.0.9       mot_de_passe_t3$T
     90EOF
     91}}}
     92L'adresse IP est celle de la cible (ici Serveur1), suivi du mot de passe.
     93   * Créer racoon.conf. Vous pouvez vous inspirer de l'exemple fourni par défaut avec Racoon, ou bien utiliser (en le modifiant) celui-ci:
     94{{{
     95$ cat > racoon.conf << EOF
     96#  $File: /home/chris/PRes/Postes_Rackables/ipsec_client1/racoon.conf $
     97#  $MD5: 2922df40b60a8f1eb7116f90a485f84a $
     98#  $By Christophe Alladoum <christophe[dot]alladoum[at]gmail[dot]com>$
     99#  $Last-Modified: Fri Apr 20 18:28:11 2007$
     100
     101#
     102# Configuration de RACOON cote client
     103#
     104
     105path include "/chemin/absolu/vers/ce/repertoire" ;
     106
     107path pre_shared_key "/chemin/absolu/vers/psk.txt" ;
     108# path pre_shared_key "/root/ipsec_client1/psk.txt" ;
     109# path certificate "/usr/local/etc/cert" ;
     110
     111# "log" indique le niveau de debug
     112# choix : notify, debug, debug2
     113# log debug;
     114
     115padding
     116{
     117        maximum_length 20;      # maximum padding length.
     118        randomize off;          # enable randomize length.
     119        strict_check off;       # enable strict check.
     120        exclusive_tail off;     # extract last one octet.
     121}
     122
     123# Interfaces a ecouter (IPv4 et/ou v6)
     124# Si aucune, ecoute sur toutes les interfaces de la machine
     125listen
     126{
     127        # pour le client IPv4
     128        isakmp 10.40.0.13 [500];
     129        # pour le client IPv6
     130        # isakmp ::1 [7000];
     131}
     132
     133# Temporisateurs d echange de cle
     134timer
     135{
     136        counter 5;              # maximum trying count to send.
     137        interval 20 sec;        # maximum interval to resend.
     138        persend 1;              # the number of packets per a send.
     139
     140        # Temps max. pour chaque phase
     141        phase1 2 min;
     142        phase2 4 min;
     143}
     144
     145# Cas du client1
     146remote 10.40.0.9
     147{
     148        exchange_mode aggressive,main;
     149        doi ipsec_doi;
     150        situation identity_only;
     151
     152        nonce_size 16;
     153        lifetime time 60 min;   # sec,min,hour
     154        initial_contact on;
     155        support_proxy on;
     156        proposal_check obey;    # obey, strict or claim
     157
     158        proposal {
     159                encryption_algorithm blowfish;
     160                hash_algorithm sha1;
     161                authentication_method pre_shared_key ;
     162                dh_group 5 ;
     163        }
     164}
     165
     166# Cas du client1
     167sainfo anonymous
     168{
     169        pfs_group 5;
     170        lifetime time 48 hour;
     171        encryption_algorithm 3des, cast128, blowfish 448, des;
     172        authentication_algorithm hmac_md5, hmac_sha1;
     173        compression_algorithm deflate ;
     174}
     175EOF
     176}}}
     177   * A présent, lancez:
     178{{{
     179$ /usr/local/sbin/racoon -l /var/log/racoon.log -f /chemin/vers/racoon.conf
     180}}}
     181Un fichier de log (utile pour le debug) sera crée à l'adresse /var/log/racoon.log
     182   * ''' Votre Racoon est lancé  !! '''
     183=== Vérifier le fonctionnement ===
     184Via le monitoring, vous devriez observer des échanges similaires aux suivants.
     185{{{
     186Capturing on dc3
     187[...]
     188Echange de cle avec ISAKMP
     189904.714799    10.40.0.9 -> 10.40.0.13   ISAKMP Aggressive
     190904.715327    10.40.0.9 -> 10.40.0.13   ISAKMP Aggressive
     191904.715883    10.40.0.9 -> 10.40.0.13   ISAKMP Aggressive
     192[...]
     193Communication Securisee via IPSec/ESP
     1941 0.000000 10.40.0.9  10.40.0.13 ESP ESP (SPI=0x000007d1)
     1952 0.000588 10.40.0.9  10.40.0.13 ESP ESP (SPI=0x000007d1)
     1963 0.000711 10.40.0.13 10.40.0.9  TCP 61738 > 10987 [ACK] Seq=0 Ack=0 Win=17879 Len=1424 TSV=2005181 TSER=751670683
     1974 0.001238 10.40.0.13 10.40.0.9  TCP [TCP Out-Of-Order] 61738 > 10987 [ACK] Seq=0 Ack=0 Win=17879 Len=1424 TSV=2005181 TSER=751670683
     1985 0.001792 10.40.0.13 10.40.0.9  TCP [TCP Out-Of-Order] 61738 > 10987 [ACK] Seq=0 Ack=0 Win=17879 Len=1424 TSV=2005181 TSER=751670683
     1996 0.002747 10.40.0.13 10.40.0.9  TCP 61738 > 10987 [ACK] Seq=1424 Ack=1399 Win=17691 Len=1424 TSV=2005183 TSER=751670687
     2007 0.002864 10.40.0.9  10.40.0.13 ESP ESP (SPI=0x000007d1)
     2018 0.003315 10.40.0.13 10.40.0.9  TCP [TCP Out-Of-Order] 61738 > 10987 [ACK] Seq=1424 Ack=1399 Win=17691 Len=1424 TSV=2005183 TSER=751670687
     202
     203Authentication Header
     204
     205Data (1424 bytes)
     206
     2070000  01 56 07 d2 b2 50 99 a6 fc 4c 1d bb 2a 88 d9 09   .V...P...L..*...
     2080010  e5 05 ad fa c1 4b 62 a5 7b c6 dd d2 ee 4e d7 c7   .....Kb.{....N..
     2090020  a8 95 6b da b3 ec 28 5c f4 5a 99 08 0a dd 39 20   ..k...(\.Z....9
     2100030  c0 ef 9c 7c 6b dc 66 e1 b0 c0 a5 bb 9f bc 4e 99   ...|k.f.......N.
     2110040  bc f3 38 70 d4 8f 1c f8 fe 8d 4c 8a 94 97 b4 b6   ..8p......L.....
     2120050  12 1f a1 1b 57 ac 28 97 1a 67 0e e7 aa b8 3a 1b   ....W.(..g....:.
     2130060  4e 8b 19 6c 80 48 77 aa 80 c5 05 46 74 37 2d 5a   N..l.Hw....Ft7-Z
     2140070  b3 94 73 9a 13 b7 bf 81 65 11 d8 16 e8 88 e2 5f   ..s.....e......_
     2150080  6f dc c6 7d fc a7 77 e7 f4 39 12 b3 e9 17 52 b6   o..}..w..9....R.
     216[...]
     217}}}
     218[[BR]]
     219Vous pouvez télécharger un exemple de trames échangées entre les stations [wiki:Entreprise2Client1 CLIENT1.ENT2] et [wiki:Entreprise2Serveur1 SERVEUR1.ENT2] via ce
     220[http://projet.reseau.free.fr/data/AS65004/trace_ipsec lien]. A noter que la trace pèse env. 14Mo (10 000 paquets capturés).
     221Pour voir les échanges, vous devrez ouvrir cette trace avec un outil, comme Wireshark.
     222----
     223Pour plus d'infos, se référer aux '''man de Setkey , Racoon  , IPSec'''
     224[[BR]]
     225Références:
     226   * http://www.onlamp.com/pub/a/bsd/2001/12/10/ipsec.html
     227   * http://www.onlamp.com/pub/a/bsd/2002/12/26/FreeBSD_Basics.html
     228----