Added a bunch of well known IKEv1 vendor IDs to database
[strongswan.git] / src / libcharon / sa / tasks / ike_vendor_v1.c
1 /*
2 * Copyright (C) 2009 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "ike_vendor_v1.h"
17
18 #include <daemon.h>
19 #include <encoding/payloads/vendor_id_payload.h>
20
21 typedef struct private_ike_vendor_v1_t private_ike_vendor_v1_t;
22
23 /**
24 * Private data of an ike_vendor_v1_t object.
25 */
26 struct private_ike_vendor_v1_t {
27
28 /**
29 * Public ike_vendor_v1_t interface.
30 */
31 ike_vendor_v1_t public;
32
33 /**
34 * Associated IKE_SA
35 */
36 ike_sa_t *ike_sa;
37
38 /**
39 * Are we the inititator of this task
40 */
41 bool initiator;
42 };
43
44 /**
45 * IKEv1 Vendor ID database
46 */
47 static struct {
48 /* Description */
49 char *desc;
50 /* extension flag negotiated with vendor ID, if any */
51 ike_extension_t extension;
52 /* send yourself? */
53 bool send;
54 /* length of vendor ID string */
55 int len;
56 /* vendor ID string */
57 char *id;
58 } vendor_ids[] = {
59
60 /* strongSwan MD5("strongSwan") */
61 { "strongSwan", EXT_STRONGSWAN, FALSE, 16,
62 "\x88\x2f\xe5\x6d\x6f\xd2\x0d\xbc\x22\x51\x61\x3b\x2e\xbe\x5b\xeb"},
63
64 /* XAuth, MD5("draft-ietf-ipsra-isakmp-xauth-06.txt") */
65 { "XAuth", EXT_XAUTH, TRUE, 8,
66 "\x09\x00\x26\x89\xdf\xd6\xb7\x12"},
67
68 /* NAT-Traversal, MD5("RFC 3947") */
69 { "NAT-T (RFC 3947)", EXT_NATT, TRUE, 16,
70 "\x4a\x13\x1c\x81\x07\x03\x58\x45\x5c\x57\x28\xf2\x0e\x95\x45\x2f"},
71
72 /* draft-ietf-ipsec-dpd-00 */
73 { "DPD", 0, FALSE, 16,
74 "\xaf\xca\xd7\x13\x68\xa1\xf1\xc9\x6b\x86\x96\xfc\x77\x57\x01\x00"},
75
76 { "draft-stenberg-ipsec-nat-traversal-01", 0, FALSE, 16,
77 "\x27\xba\xb5\xdc\x01\xea\x07\x60\xea\x4e\x31\x90\xac\x27\xc0\xd0"},
78
79 { "draft-stenberg-ipsec-nat-traversal-02", 0, FALSE, 16,
80 "\x61\x05\xc4\x22\xe7\x68\x47\xe4\x3f\x96\x84\x80\x12\x92\xae\xcd"},
81
82 { "draft-ietf-ipsec-nat-t-ike-00", 0, FALSE, 16,
83 "\x44\x85\x15\x2d\x18\xb6\xbb\xcd\x0b\xe8\xa8\x46\x95\x79\xdd\xcc"},
84
85 { "draft-ietf-ipsec-nat-t-ike-02", 0, FALSE, 16,
86 "\xcd\x60\x46\x43\x35\xdf\x21\xf8\x7c\xfd\xb2\xfc\x68\xb6\xa4\x48"},
87
88 { "draft-ietf-ipsec-nat-t-ike-02", 0, FALSE, 16,
89 "\x90\xcb\x80\x91\x3e\xbb\x69\x6e\x08\x63\x81\xb5\xec\x42\x7b\x1f"},
90
91 { "draft-ietf-ipsec-nat-t-ike-03", 0, FALSE, 16,
92 "\x7d\x94\x19\xa6\x53\x10\xca\x6f\x2c\x17\x9d\x92\x15\x52\x9d\x56"},
93
94 { "Cisco Unity", 0, FALSE, 16,
95 "\x12\xf5\xf2\x8c\x45\x71\x68\xa9\x70\x2d\x9f\xe2\x74\xcc\x01\x00"},
96 };
97
98 METHOD(task_t, build, status_t,
99 private_ike_vendor_v1_t *this, message_t *message)
100 {
101 vendor_id_payload_t *vid_payload;
102 bool strongswan;
103 int i;
104
105 strongswan = lib->settings->get_bool(lib->settings,
106 "charon.send_vendor_id", FALSE);
107 for (i = 0; i < countof(vendor_ids); i++)
108 {
109 if (vendor_ids[i].send ||
110 (vendor_ids[i].extension == EXT_STRONGSWAN && strongswan))
111 {
112 vid_payload = vendor_id_payload_create_data(VENDOR_ID_V1,
113 chunk_clone(chunk_create(vendor_ids[i].id, vendor_ids[i].len)));
114 message->add_payload(message, &vid_payload->payload_interface);
115 }
116 }
117 return this->initiator ? NEED_MORE : SUCCESS;
118 }
119
120 METHOD(task_t, process, status_t,
121 private_ike_vendor_v1_t *this, message_t *message)
122 {
123 enumerator_t *enumerator;
124 payload_t *payload;
125 int i;
126
127 enumerator = message->create_payload_enumerator(message);
128 while (enumerator->enumerate(enumerator, &payload))
129 {
130 if (payload->get_type(payload) == VENDOR_ID_V1)
131 {
132 vendor_id_payload_t *vid;
133 bool found = FALSE;
134 chunk_t data;
135
136 vid = (vendor_id_payload_t*)payload;
137 data = vid->get_data(vid);
138
139 for (i = 0; i < countof(vendor_ids); i++)
140 {
141 if (chunk_equals(data, chunk_create(vendor_ids[i].id,
142 vendor_ids[i].len)))
143 {
144 DBG1(DBG_IKE, "received %s vendor id", vendor_ids[i].desc);
145 if (vendor_ids[i].extension)
146 {
147 this->ike_sa->enable_extension(this->ike_sa,
148 vendor_ids[i].extension);
149 }
150 found = TRUE;
151 }
152 }
153 if (!found)
154 {
155 DBG1(DBG_ENC, "received unknown vendor id: %#B", &data);
156 }
157 }
158 }
159 enumerator->destroy(enumerator);
160
161 return this->initiator ? SUCCESS : NEED_MORE;
162 }
163
164 METHOD(task_t, migrate, void,
165 private_ike_vendor_v1_t *this, ike_sa_t *ike_sa)
166 {
167 this->ike_sa = ike_sa;
168 }
169
170 METHOD(task_t, get_type, task_type_t,
171 private_ike_vendor_v1_t *this)
172 {
173 return TASK_VENDOR_V1;
174 }
175
176 METHOD(task_t, destroy, void,
177 private_ike_vendor_v1_t *this)
178 {
179 free(this);
180 }
181
182 /**
183 * See header
184 */
185 ike_vendor_v1_t *ike_vendor_v1_create(ike_sa_t *ike_sa, bool initiator)
186 {
187 private_ike_vendor_v1_t *this;
188
189 INIT(this,
190 .public = {
191 .task = {
192 .build = _build,
193 .process = _process,
194 .migrate = _migrate,
195 .get_type = _get_type,
196 .destroy = _destroy,
197 },
198 },
199 .initiator = initiator,
200 .ike_sa = ike_sa,
201 );
202
203 return &this->public;
204 }