embedded ipsec vpn implementation für low-end embedded systeme “tag der entwickler” – 7. juli...
TRANSCRIPT
embedded IPsec
VPN Implementation fürlow-end embedded Systeme
“Tag der Entwickler” – 7. Juli 2004 – M,O,C, München Christian Scheurer 1
„D&E - Tag der Entwickler“ - M,O,C München, 07. Juli 2004
2
• Hintergrund, Motivation und Ziele
• Design und Implementation
• Testen
• Ergebnisse
Übersicht
3
Hintergrund
• 2003: Sicherheit für vernetzte Systeme: Passwort
• 2004: Zahlreiche Angebote zum Thema Fernwartung über GSM
• 200x: Vernetzt über öffentliche Netze
4
Motivation
• Offene IPsec Implementation ausgelegt für low-end embedded Systeme
• Interoperabilität mit andern IPsec Systemen
5
Vorbereitung: Verständnis
• IPsec verstehen– Literatur
• Big Book of IPsec RFCs(Peter Loshin, Morgan Kaufmann 2000)
• Netzsicherheit(Günter Schäfer, dpunkt Verlag 2003)
• Praktische Tests- Linux Kernel 2.6- FreeS/WAN (jetzt OpenS/WAN, StrongS/WAN)
6
Vorbereitung: Arbeitsplatz
• Entwicklungsumgebung
– PC mit Keil uVision IDE und Sniffer
– VMware Workstation (oder PC) mit FreeS/WAN und Linux Kernel 2.6 IPsec
– C167-Board
– 10Mbit Ethernet Hub
7
Design
3DES CBC encrypt3DES CBC decrypt
HMAC-MD5HMAC-SHA1
AH encapsulate
AH check
ESP decapsulate
ESP encapsulate
SAD lookupSPD lookupSPD lookup
IPsec Output
IPsec Input
cs8900 outputcs8900 input
IP input
IP output
IPsec I/O
SAD
ESP
AH
Cryptolibrary
SPD
IPsecDeviceDriver
TCP/IPStack
cs8900NetworkDriver
embedded IPsecModule
8
Implementation der Module
Reihenfolge Implementation:1.) Anbindung an TCP/IP Stack2.) Konfigurationsdatenbanken3.) Crypto Funktionen4.) AH Protokoll5.) ESP Protokoll6.) AntiReplay, ...
9
ipsecdev / ipsec Module
3DES CBC encrypt3DES CBC decrypt
HMAC-MD5HMAC-SHA1
AH encapsulate
AH check
ESP decapsulate
ESP encapsulate
SAD lookupSPD lookupSPD lookup
IPsec Output
IPsec Input
cs8900 outputcs8900 input
IP input
IP output
IPsec I/O
SAD
ESP
AH
Cryptolibrary
SPD
IPsecDeviceDriver
TCP/IPStack
cs8900NetworkDriver „ipsecdev“
10
lwIP TCP/IP Stack
TCP/IP Stack
CS8900 Driver Device Driver
I P Layer
cs8900_ input() cs8900_output()
ip_ input() ip_output()
input output
Ethernet
lwIP – a light weight TCP/IP Stack
11
IPsec Integration
TrafficInterception
I Pseclibrary
Device Driver
I P Layer
I Psec Driveripsecdev_ input() ipsecdev_output()
cs8900_ input() cs8900_output()
ip_ input() ip_output()
input output
ipse
c_in
put(
)
ipse
c_ou
tput
()
Ethernet
IPsec LibraryIPsec Driver
12
IPsec Datenbank Module
3DES CBC encrypt3DES CBC decrypt
HMAC-MD5HMAC-SHA1
AH encapsulate
AH check
ESP decapsulate
ESP encapsulate
SAD lookupSPD lookupSPD lookup
IPsec Output
IPsec Input
cs8900 outputcs8900 input
IP input
IP output
IPsec I/O
SAD
ESP
AH
Cryptolibrary
SPD
IPsecDeviceDriver
TCP/IPStack
cs8900NetworkDriver SPD und SAD
13
Security Policy Database
• Welche Pakete werden verarbeitet?– DISCARD
– BYPASS
– APPLY
14
Security Policy Database
Beispiel einer SPD Konfiguration
15
Security Association Database
• Wie werden Pakete verarbeitet?– Tunnel oder Transport Mode – AH oder ESP – Algorithmen und Keys– Security Parameter Index
16
Security Association Database
Beispiel einer SAD Konfiguration
17
Outbound Processing
Datenfluss beiOutbound Processing
SPDlookup
encapsulateIPsec packet
device driveroutput
BYPASS
DISCARD
audi
tabl
e ev
ents
ipsecdev_output()
cs8900_output()
IP output
APPLYip_output()SA
18
AH / ESP / Crypto - Module
3DES CBC encrypt3DES CBC decrypt
HMAC-MD5HMAC-SHA1
AH encapsulate
AH check
ESP decapsulate
ESP encapsulate
SAD lookupSPD lookupSPD lookup
IPsec Output
IPsec Input
cs8900 outputcs8900 input
IP input
IP output
IPsec I/O
SAD
ESP
AH
Cryptolibrary
SPD
IPsecDeviceDriver
TCP/IPStack
cs8900NetworkDriver AH und ESP
19
Crypto - Library
• Crypto Funktionen von OpenSSL– DES, 3DES– HMAC-MD5-96, HMAC-SHA1-96
• Für MCU optimierte Versionen– Dmitry Basko‘s DES
• http://www.dbasko.com – Graham Cole‘s MD5
• http://www.programmersheaven.com/zone5/cat27/index.htm
20
Authentication Header
unencrypted IP packet
IP header IP payloadfree headroom
free tailroom
one contiguous block of RAM
authenticated IP packetfree headroom
free tailroomIC
V
Nex
t hea
der,
Leng
th,
SP
I,S
eq N
r
deca
psul
atio
n
new
IPhe
ader
encapsulation
AH in IP packet (tunnel mode)
AHheader
AH payload
21
Encapsulating Security Payload
unencrypted IP packet
IP header IP payloadfree headroom
free tailroom
one contiguous block of RAM
encrypted and padded IP packetfree headroom
free tailroomIVS
PI
Seq
Nr.
ICV
Pad
ding
,P
add.
Len
,ne
xt H
eade
r
decr
yptio
n /
deca
psul
atio
n
new
IPhe
ader
encryption /encapsulation
ESP in IP packet (tunnel mode)
ESPheader
ESP payload
22
Speicherverwaltung
free memoryspace
free memoryspace
lengthpayload
p bufhe ade r
pbufdata space
IP header
TCP header
payload
len gth
next
free memoryspace
free memoryspace
lengthpayload
pbufhe ade r
pbufdata space
le n gth
next
IPsec header
outer I P header
inner packet
padding & ICV
23
Testen
• Test-Konzept
IPsec ModuleImplementation
Functional Test
Structural Test
Sample Application
Automated TestScripts
embedded IPsecRelease Version
1.
2.
3.
24
Structural Tests
• Structural TestsTST sa_test_sad_lookup() : SUCCESS : TST sa_test_sad_get_spi(): SUCCESS : TST sa_test_spd_flush() : NOT IMPL. : TST sa_test_sad_flush() : NOT IMPL. :
TST test_esp_decapsulate : SUCCESS : TST test_esp_encapsulate : SUCCESS :
MSG main : structural testing finished:MSG main : o 100.00% correct (92 of 92 tests passed)MSG main : o 82.61% complete (19 of 23 functions implemented)
25
Functional Tests
• Functional Tests
IP layer
IPsec driver
Network Driver
Transport Layer
Application Layer
IP layer
IPsec driver
Network Driver
Transport Layer
Application LayerInject applicationdata: e.g webpage
Compare withexpected result
Inject IPsecpackets
Compare withexpected result
Bottom
-up Test
Top-dow
n Test
26
Ergebnisse: Grösse
• Grösse
05'000
10'00015'00020'00025'00030'00035'00040'000
size
[by
tes]
IPSE
CIP
SECD
EV AH ESP SA D
ESM
D5
SHA1
UTI
L
RAMROMCode
Protokolle und DBtotal 18kB
Crypto Library aufOpenSSL Basistotal 90kB
27
Ergebnisse: Performance
• Performance
0
200
400
600
800
1000
1200
64 128 256 512 768 1024 1280Payload size [bytes]
Roun
d-tr
ip ti
me
[ms]
non-IPsecAH HMAC-MD5AH HMAC-SHA1ESP 3DESESP 3DES HMAC-MD5ESP 3DES HMAC-SHA1
64 BytesOhne: 5 mS
AH-MD5: 19 mSESP-3DES: 60 mS
512 BytesOhne: 8 mS
AH-MD5: 38 mSESP-3DES: 351 mS
1280 BytesOhne: 13 mS
AH-MD5: 165 mSESP-3DES: 851 mS
28
Einsatzgebiete
• Einsatzgebiete– Vernetzte Sensoren– Gebührenzähler
Protokoll Round-Trip Time[1024 Bytes] Durchsatz Anwendung
AH-MD5 60 mS ca. 25 kB/s DatenESP-3DES 685 mS ca. 2.5 kB/s HTMLESP-3DES-MD5 733 mS ca. 2 kB/s Email
29
Interoperabilität
• InteroperabilitätAus Linux Kernel 2.6.7 (./net/ipv4/esp4.c): .. esph = (struct ip_esp_hdr*)skb->data; iph = skb->nh.iph; /* Get ivec. This can be wrong, check against another impls. */ if (esp->conf.ivlen) crypto_cipher_set_iv(esp->conf.tfm, esph->enc_data, crypto_tfm_alg_ivsize(esp->conf.tfm)); {
u8 nexthdr[2]; ...
30
16-Bit Demo
Demo
31
Versuchs-Aufbau
16-Bit (Infineon C167)
8-Bit (ATMEL AVR)
Laptop (grau)
Laptop (schwarz)
Hub
192.168.1.21
192.168.1.20
192.168.1.5192.168.1.3
192.168.1.4