2 #include "xauth_request.h"
6 #include <encoding/payloads/cp_payload.h>
8 typedef struct private_xauth_request_t private_xauth_request_t
;
11 XAUTH_STATUS_FAIL
= 0,
16 * Private members of a xauth_request_t task.
18 struct private_xauth_request_t
{
21 * Public methods and task_t interface.
23 xauth_request_t
public;
31 * Are we the initiator?
41 * list of attributes requested and its handler, entry_t
43 linked_list_t
*requested
;
56 * The current state of the task
64 * The status of the XAuth request
70 * Entry for a requested attribute and the requesting handler
73 /** attribute requested */
74 configuration_attribute_type_t type
;
75 /** handler requesting this attribute */
76 attribute_handler_t
*handler
;
79 METHOD(task_t
, build_i
, status_t
,
80 private_xauth_request_t
*this, message_t
*message
)
83 chunk_t chunk
= chunk_empty
;
88 cp
= cp_payload_create_type(CONFIGURATION_V1
, CFG_REQUEST
);
89 cp
->add_attribute(cp
, configuration_attribute_create_chunk(
90 CONFIGURATION_ATTRIBUTE_V1
, XAUTH_USER_NAME
, chunk
));
91 cp
->add_attribute(cp
, configuration_attribute_create_chunk(
92 CONFIGURATION_ATTRIBUTE_V1
, XAUTH_USER_PASSWORD
, chunk
));
94 case TASK_XAUTH_PASS_DONE
:
95 cp
= cp_payload_create_type(CONFIGURATION_V1
, CFG_SET
);
96 cp
->add_attribute(cp
, configuration_attribute_create_value(
98 (this->status
== FAILED ? XAUTH_STATUS_FAIL
: XAUTH_STATUS_OK
)));
104 /* Add the payloads into the message */
105 message
->add_payload(message
, (payload_t
*)cp
);
111 METHOD(task_t
, process_r
, status_t
,
112 private_xauth_request_t
*this, message_t
*message
)
117 METHOD(task_t
, build_r
, status_t
,
118 private_xauth_request_t
*this, message_t
*message
)
123 METHOD(task_t
, process_i
, status_t
,
124 private_xauth_request_t
*this, message_t
*message
)
126 cp_payload_t
*cp_payload
;
127 enumerator_t
*enumerator
;
128 configuration_attribute_t
*ca
;
129 chunk_t status_chunk
= chunk_empty
;
131 cp_payload
= (cp_payload_t
*)message
->get_payload(message
, CONFIGURATION_V1
);
132 enumerator
= cp_payload
->create_attribute_enumerator(cp_payload
);
133 while (enumerator
->enumerate(enumerator
, &ca
))
135 switch(ca
->get_type(ca
))
137 case XAUTH_USER_NAME
:
138 this->user_name
= ca
->get_chunk(ca
);
140 case XAUTH_USER_PASSWORD
:
141 this->user_pass
= ca
->get_chunk(ca
);
144 status_chunk
= ca
->get_chunk(ca
);
147 DBG3(DBG_IKE
, "Unknown config attribute type %d, ignored", ca
->get_type(ca
));
150 enumerator
->destroy(enumerator
);
154 case TASK_XAUTH_INIT
:
156 if(cp_payload
->get_type(cp_payload
) != CFG_REPLY
)
158 DBG1(DBG_IKE
, "ERROR: ConfigMode payload is not a reply");
162 this->state
= TASK_XAUTH_PASS_DONE
;
163 if((this->user_name
.len
== 0) || (this->user_pass
.len
== 0))
165 DBG1(DBG_IKE
, "ERROR: Did not get user name or user pass, aborting");
166 this->status
= FAILED
;
167 /* We should close out the XAuth negotiation cleanly by sending a "failed" message */
171 /* TODO-IKEv1: Do actual user/pass verification */
172 // if(!chunk_compare(this->user_name, this->user_pass))
174 // this->status = FAILED;
175 // DBG1(DBG_IKE, "ERROR: user/pass verification failure");
176 /* We should close out the XAuth negotiation cleanly by sending a "failed" message */
180 this->status
= SUCCESS
;
182 case TASK_XAUTH_PASS_DONE
:
183 if(cp_payload
->get_type(cp_payload
) != CFG_ACK
)
185 DBG1(DBG_IKE
, "ERROR: ConfigMode payload is not a status ack");
188 if(status_chunk
.len
!= 0)
190 DBG1(DBG_IKE
, "Status payload of an ack had data, hmm....");
193 DBG1(DBG_IKE
, "Done with XAUTH!!!");
199 METHOD(task_t
, get_type
, task_type_t
,
200 private_xauth_request_t
*this)
202 return TASK_XAUTH_REQUEST
;
205 METHOD(task_t
, migrate
, void,
206 private_xauth_request_t
*this, ike_sa_t
*ike_sa
)
208 DESTROY_IF(this->virtual_ip
);
210 this->ike_sa
= ike_sa
;
211 this->virtual_ip
= NULL
;
212 this->requested
->destroy_function(this->requested
, free
);
213 this->requested
= linked_list_create();
216 METHOD(task_t
, destroy
, void,
217 private_xauth_request_t
*this)
219 DESTROY_IF(this->virtual_ip
);
220 this->requested
->destroy_function(this->requested
, free
);
224 METHOD(task_t
, swap_initiator
, void,
225 private_xauth_request_t
*this)
229 this->public.task
.build
= _build_r
;
230 this->public.task
.process
= _process_r
;
231 this->initiator
= FALSE
;
235 this->public.task
.build
= _build_i
;
236 this->public.task
.process
= _process_i
;
237 this->initiator
= TRUE
;
242 * Described in header.
244 xauth_request_t
*xauth_request_create(ike_sa_t
*ike_sa
, bool initiator
)
246 private_xauth_request_t
*this;
251 .get_type
= _get_type
,
254 .swap_initiator
= _swap_initiator
,
257 .initiator
= initiator
,
259 .requested
= linked_list_create(),
260 .user_name
= chunk_empty
,
261 .user_pass
= chunk_empty
,
262 .state
= TASK_XAUTH_INIT
,
267 this->public.task
.build
= _build_i
;
268 this->public.task
.process
= _process_i
;
272 this->public.task
.build
= _build_r
;
273 this->public.task
.process
= _process_r
;
276 return &this->public;