2 * Copyright (C) 2009 Martin Willi
3 * Hochschule fuer Technik Rapperswil
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>.
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
16 #include "ike_vendor.h"
19 #include <encoding/payloads/vendor_id_payload.h>
21 typedef struct private_ike_vendor_t private_ike_vendor_t
;
24 * Private data of an ike_vendor_t object.
26 struct private_ike_vendor_t
{
29 * Public ike_vendor_t interface.
39 * Are we the inititator of this task
45 * Vendor ID database entry
50 /* extension flag negotiated with vendor ID, if any */
51 ike_extension_t extension
;
52 /* length of vendor ID string, 0 for NULL terminated */
54 /* vendor ID string */
59 * Get the data of a vendor ID as a chunk
61 static chunk_t
get_vid_data(vid_data_t
*data
)
63 return chunk_create(data
->id
, data
->len
?: strlen(data
->id
));
67 * IKEv2 Vendor ID database entry
69 static vid_data_t vids
[] = {
70 /* strongSwan MD5("strongSwan") */
71 { "strongSwan", EXT_STRONGSWAN
, 16,
72 "\x88\x2f\xe5\x6d\x6f\xd2\x0d\xbc\x22\x51\x61\x3b\x2e\xbe\x5b\xeb"},
73 { "Cisco Delete Reason", 0, 0,
74 "CISCO-DELETE-REASON" },
75 { "Cisco Copyright (c) 2009", 0, 0,
76 "CISCO(COPYRIGHT)&Copyright (c) 2009 Cisco Systems, Inc." },
79 METHOD(task_t
, build
, status_t
,
80 private_ike_vendor_t
*this, message_t
*message
)
82 vendor_id_payload_t
*vid
;
86 strongswan
= lib
->settings
->get_bool(lib
->settings
,
87 "%s.send_vendor_id", FALSE
, charon
->name
);
88 for (i
= 0; i
< countof(vids
); i
++)
90 if (vids
[i
].extension
== EXT_STRONGSWAN
&& strongswan
)
92 DBG2(DBG_IKE
, "sending %s vendor ID", vids
[i
].desc
);
93 vid
= vendor_id_payload_create_data(VENDOR_ID
,
94 chunk_clone(get_vid_data(&vids
[i
])));
95 message
->add_payload(message
, &vid
->payload_interface
);
99 return this->initiator
? NEED_MORE
: SUCCESS
;
102 METHOD(task_t
, process
, status_t
,
103 private_ike_vendor_t
*this, message_t
*message
)
105 enumerator_t
*enumerator
;
109 enumerator
= message
->create_payload_enumerator(message
);
110 while (enumerator
->enumerate(enumerator
, &payload
))
112 if (payload
->get_type(payload
) == VENDOR_ID
)
114 vendor_id_payload_t
*vid
;
118 vid
= (vendor_id_payload_t
*)payload
;
119 data
= vid
->get_data(vid
);
121 for (i
= 0; i
< countof(vids
); i
++)
123 if (chunk_equals(get_vid_data(&vids
[i
]), data
))
125 DBG1(DBG_IKE
, "received %s vendor ID", vids
[i
].desc
);
126 if (vids
[i
].extension
)
128 this->ike_sa
->enable_extension(this->ike_sa
,
137 DBG1(DBG_ENC
, "received unknown vendor ID: %#B", &data
);
141 enumerator
->destroy(enumerator
);
143 return this->initiator
? SUCCESS
: NEED_MORE
;
146 METHOD(task_t
, migrate
, void,
147 private_ike_vendor_t
*this, ike_sa_t
*ike_sa
)
149 this->ike_sa
= ike_sa
;
152 METHOD(task_t
, get_type
, task_type_t
,
153 private_ike_vendor_t
*this)
155 return TASK_IKE_VENDOR
;
158 METHOD(task_t
, destroy
, void,
159 private_ike_vendor_t
*this)
167 ike_vendor_t
*ike_vendor_create(ike_sa_t
*ike_sa
, bool initiator
)
169 private_ike_vendor_t
*this;
177 .get_type
= _get_type
,
181 .initiator
= initiator
,
185 return &this->public;