blob: 363eac639af52d1f3d16ecc23747fd77907ae180 (
plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
#!/bin/sh
#
# ifup-ipsec
#
# Brings up ipsec interfaces
#
# Configuration parameters
#
# SRC = source address. Not required.
# DST = destination address
# SRCNET = source net (for tunneling)
# DSTNET = destination network (for tunneling)
#
# Manual keying:
#
# AH_PROTO{_IN,_OUT} = protocol to use for AH (defaults to HMAC-MD5)
# ESP_PROTO{_IN,_OUT} = protocol to use for ESP (defaults to 3DES)
# KEY_AH{_IN,_OUT} = AH key
# KEY_ESP{_IN,_OUT} = ESP key
# SPI[1..4] = SPIs to use
#
# _IN and _OUT specifiers are for using different keys or protocols for inccoming
# and outgoing packets. If neither _IN or _OUT variants are set, the same keys
# or protocols will be used for both.
#
# Automatic keying:
#
# IKE_METHOD=PSK|X509|RSA
# PSK = preshared keys (shared secret)
# X509 = X.509 certificates
# RSA = RSA host keys in DNS (not yet implemented)
# GSSAPI = GSSAPI authentication
# IKE_PSK = preshared key for this connection
# IKE_CERTFILE = our certificate file name for X509 IKE
# IKE_PEER_CERTFILE = peer public cert filename for X509 IKE
# IKE_DNSSEC = retrieve peer public certs from DNS
# (otherwise uses certificate information sent over IKE)
# IKE_RSA_KEY = RSA key for RSA IKE
#
if [ -n "$KEY_AH" -o -n "$KEY_ESP" ]; then
KEYING=manual
fi
if [ -z "$KEY_AH_IN" -a -n "$KEY_AH" ]; then
KEY_AH_IN=$KEY_AH
fi
if [ -z "$KEY_AH_OUT" -a -n "$KEY_AH" ]; then
KEY_AH_OUT=$KEY_AH
fi
if [ -z "$KEY_ESP_IN" -a -n "$KEY_ESP" ]; then
KEY_ESP_IN=$KEY_ESP
fi
if [ -z "$KEY_ESP_OUT" -a -n "$KEY_ESP" ]; then
KEY_ESP_OUT=$KEY_ESP
fi
if [ -n "$IKE_PSK" ]; then
KEYING=automatic
IKE_METHOD=PSK
fi
if [ -n "$IKE_CERTFILE" ]; then
KEYING=automatic
IKE_METHOD=X509
fi
if [ -n "$IKE_PEER_CERTFILE" ]; then
KEYING=automatic
IKE_METHOD=X509
fi
if [ -n "$IKE_DNSSEC" ]; then
KEYING=automatic
IKE_METHOD=X509
fi
if [ -n "$RSA_KEY" ]; then
KEYING=automatic
IKE_METHOD=RSA
fi
if [ -n "$SRCNET" -o -n "$DSTNET" ]; then
MODE=tunnel
else
MODE=host
fi
[ -z "$KEYING" ] && KEYING=manual
if [ "$KEYING" = "manual" ]; then
# Get source address
if [ -n "$SRC" ]; then
SRC=`ip -o route get to $DST | sed "s|.*src \([^ ]*\).*|\1|"`
fi
[ -z "$AH_PROTO" ] && AH_PROTO=hmac-md5
[ -z "$ESP_PROTO" ] && ESP_PROTO=3des-cbc
if [ "$MODE" = "host" ]; then
/sbin/setkey -c << EOF
deleteall $SRC $DST ah;
deleteall $DST $SRC ah;
deleteall $SRC $DST esp;
deleteall $DST $SRC esp;
spddelete $SRC $DST any -P out;
spddelete $DST $SRC any -P in;
# ESP
${KEY_ESP_IN:+add $DST $SRC esp $SPI3 -E ${ESP_PROTO_IN:-$ESP_PROTO} $KEY_ESP_IN;}
${KEY_ESP_OUT:+add $SRC $DST esp $SPI4 -E ${ESP_PROTO_OUT:-$ESP_PROTO} $KEY_ESP_OUT;}
# AH
${KEY_AH_IN:+add $DST $SRC ah $SPI1 -A ${AH_PROTO_IN:-$AH_PROTO} $KEY_AH_IN;}
${KEY_AH_OUT:+add $SRC $DST ah $SPI2 -A ${AH_PROTO_OUT:-$AH_PROTO} $KEY_AH_OUT;}
spdadd $SRC $DST any -P out ipsec
${KEY_ESP_OUT:+esp/transport//require}
${KEY_AH_OUT:+ah/transport//require}
;
spdadd $DST $SRC any -P in ipsec
${KEY_ESP_IN:+esp/transport//require}
${KEY_AH_IN:+ah/transport//require}
;
EOF
else
[ -n "$SRCNET" ] && SRCNET="$SRC/32"
[ -n "$DSTNET" ] && DSTNET="$DST/32"
/sbin/setkey -c << EOF
deleteall $SRC $DST ah;
deleteall $DST $SRC ah;
deleteall $SRC $DST esp;
deleteall $DST $SRC esp;
spddelete $SRCNET $DSTNET any -P out;
spddelete $DSTNET $SRCNET any -P in;
# ESP
${KEY_ESP_IN:+add $DST $SRC esp $SPI3 -m tunnel -E ${ESP_PROTO_IN:-$ESP_PROTO} $KEY_ESP_IN;}
${KEY_ESP_OUT:+add $SRC $DST esp $SPI4 -m tunnel -E ${ESP_PROTO_OUT:-$ESP_PROTO} $KEY_ESP_OUT;}
# AH
${KEY_AH_IN:+add $DST $SRC ah $SPI1 -m tunnel -A ${AH_PROTO_IN:-$AH_PROTO} $KEY_AH_IN;}
${KEY_AH_OUT:+add $SRC $DST ah $SPI2 -m tunnel -A ${AH_PROTO_OUT:-$AH_PROTO} $KEY_AH_OUT;}
spdadd $SRCNET $DSTNET any -P out ipsec
${KEY_ESP_OUT:+esp/tunnel/$SRC-$DEST/require}
${KEY_AH_OUT:+ah/tunnel/$SRC-$DEST/require}
;
spdadd $DSTNET $SRCNET any -P in ipsec
${KEY_ESP_IN:+esp/tunnel/$DEST-$SRC/require}
${KEY_AH_IN:+ah/tunnel/$DEST-$SRC/require}
;
EOF
fi
fi
if [ "$KEYING" = "automatic" ]; then
if [ "$MODE" = "host" ]; then
/sbin/setkey -c << EOF
spddelete $SRC $DST any -P out;
spddelete $DST $SRC any -P in;
spdadd $SRC $DST any -P out ipsec
${KEY_ESP_OUT:+esp/transport//require}
${KEY_AH_OUT:+ah/transport//require}
;
spdadd $DST $SRC any -P in ipsec
${KEY_ESP_IN:+esp/transport//require}
${KEY_AH_IN:+ah/transport//require}
;
EOF
else
[ -n "$SRCNET" ] && SRCNET="$SRC/32"
[ -n "$DSTNET" ] && DSTNET="$DST/32"
/sbin/setkey -c << EOF
spddelete $SRCNET $DSTNET any -P out;
spddelete $DSTNET $SRCNET any -P in;
spdadd $SRCNET $DSTNET any -P out ipsec
${KEY_ESP_OUT:+esp/tunnel/$SRC-$DEST/require}
${KEY_AH_OUT:+ah/tunnel/$SRC-$DEST/require}
;
spdadd $DSTNET $SRCNET any -P in ipsec
${KEY_ESP_IN:+esp/tunnel/$DEST-$SRC/require}
${KEY_AH_IN:+ah/tunnel/$DEST-$SRC/require}
;
EOF
fi
if [ "$IKE_METHOD" = "PSK" ]; then
tmpfile=`mktemp /etc/racoon/psk.XXXXXX`
grep -v "^$DST" /etc/racoon/psk.txt > $tmpfile
echo "$DST $IKE_PSK" >> $tmpfile
mv -f $tmpfile /etc/racoon/psk.txt
fi
if [ ! -f /etc/racoon/$DST.conf -o /etc/racoon/$DST.conf -ot $1 ] ; then
cat > /etc/racoon/$DST.conf << EOF
remote $DST
{
exchange_mode agressive, main;
EOF
case "$IKE_METHOD" in
PSK)
cat >> /etc/racoon/$DST.conf << EOF
my_identifier address;
proposal {
encryption_algorithm $ESP_PROTO;
hash_alogirtihm $AH_PROTO;
authentication_method pre_shared_key;
dh_group 2 ;
}
}
EOF
;;
X509)
cat >> /etc/racoon/$DST.conf << EOF
my_identifier asn1dn;
peers_identifier asn1dn;
certificate_type x509 "$IKE_CERTFILE.public" "$IKE_CERTFILE.private";
EOF
if [ -n "$IKE_DNSSEC" ]; then
echo " peers_certfile dnssec;" >> /etc/racoon/$DST.conf
fi
if [ -n "$IKE_PEER_CERTFILE" ]; then
echo " peers_certfile $IKE_PEER_CERTFILE;" >> /etc/racoon/$DST.conf
fi
cat >> /etc/racoon/$DST.conf << EOF
proposal {
encryption_algorithm $ESP_PROTO;
hash_algorithm $AH_PROTO;
authentication_method rsasig;
dh_group 2;
}
}
EOF
;;
RSA)
# not supported yet, only in freeswan
;;
GSSAPI)
cat >> /etc/racoon/$DST.conf << EOF
my_identifier address;
proposal {
encryption_algorithm $ESP_PROTO;
hash_alogirtihm $AH_PROTO;
authentication_method gssapi_krb;
dh_group 2 ;
}
}
EOF
esac
racoontmp=`mktemp /etc/racoon/racoon.XXXXXX`
grep -v "^include $DST.conf" /etc/racoon/racoon.conf >> $racoontmp
echo "include $DST.conf" >> $racoontmp
mv -f $racoontmp /etc/racoon/racoon.conf
pidof -x /usr/sbin/racoon > /dev/null 2>&1 && killall -HUP /usr/sbin/racoon
fi
pidof -x /usr/sbin/racoon || /usr/sbin/racoon
fi
|