14ee75afd32c86ee834b4164a5b8dee1c8651e56
[strongswan.git] / src / libcharon / sa / tasks / xauth_request.c
1
2 #include "xauth_request.h"
3
4 #include <daemon.h>
5 #include <hydra.h>
6 #include <encoding/payloads/cp_payload.h>
7
8 typedef struct private_xauth_request_t private_xauth_request_t;
9
10 /**
11 * Private members of a xauth_request_t task.
12 */
13 struct private_xauth_request_t {
14
15 /**
16 * Public methods and task_t interface.
17 */
18 xauth_request_t public;
19
20 /**
21 * Assigned IKE_SA.
22 */
23 ike_sa_t *ike_sa;
24
25 /**
26 * Are we the initiator?
27 */
28 bool initiator;
29
30 /**
31 * virtual ip
32 */
33 host_t *virtual_ip;
34
35 /**
36 * list of attributes requested and its handler, entry_t
37 */
38 linked_list_t *requested;
39 };
40
41 /**
42 * Entry for a requested attribute and the requesting handler
43 */
44 typedef struct {
45 /** attribute requested */
46 configuration_attribute_type_t type;
47 /** handler requesting this attribute */
48 attribute_handler_t *handler;
49 } entry_t;
50
51 /**
52 * Scan for configuration payloads and attributes
53 */
54 static void process_payloads(private_xauth_request_t *this, message_t *message)
55 {
56 }
57
58 METHOD(task_t, build_i, status_t,
59 private_xauth_request_t *this, message_t *message)
60 {
61 cp_payload_t *cp;
62 chunk_t chunk = chunk_empty;
63
64 DBG1(DBG_IKE, "BUILDING XAUTH REQUEST PACKET");
65 /* TODO1: Create ATTR payload */
66 cp = cp_payload_create(CONFIGURATION_V1);
67 cp->add_attribute(cp, configuration_attribute_create_chunk(
68 CONFIGURATION_ATTRIBUTE_V1, XAUTH_USER_NAME, chunk));
69 cp->add_attribute(cp, configuration_attribute_create_chunk(
70 CONFIGURATION_ATTRIBUTE_V1, XAUTH_USER_PASSWORD, chunk));
71 message->add_payload(message, (payload_t *)cp);
72
73 return NEED_MORE;
74 }
75
76 METHOD(task_t, process_r, status_t,
77 private_xauth_request_t *this, message_t *message)
78 {
79 return NEED_MORE;
80 }
81
82 METHOD(task_t, build_r, status_t,
83 private_xauth_request_t *this, message_t *message)
84 {
85 return NEED_MORE;
86 }
87
88 METHOD(task_t, process_i, status_t,
89 private_xauth_request_t *this, message_t *message)
90 {
91 return NEED_MORE;
92 }
93
94 METHOD(task_t, get_type, task_type_t,
95 private_xauth_request_t *this)
96 {
97 return TASK_XAUTH_REQUEST;
98 }
99
100 METHOD(task_t, migrate, void,
101 private_xauth_request_t *this, ike_sa_t *ike_sa)
102 {
103 DESTROY_IF(this->virtual_ip);
104
105 this->ike_sa = ike_sa;
106 this->virtual_ip = NULL;
107 this->requested->destroy_function(this->requested, free);
108 this->requested = linked_list_create();
109 }
110
111 METHOD(task_t, destroy, void,
112 private_xauth_request_t *this)
113 {
114 DESTROY_IF(this->virtual_ip);
115 this->requested->destroy_function(this->requested, free);
116 free(this);
117 }
118
119 /*
120 * Described in header.
121 */
122 xauth_request_t *xauth_request_create(ike_sa_t *ike_sa, bool initiator)
123 {
124 private_xauth_request_t *this;
125
126 INIT(this,
127 .public = {
128 .task = {
129 .get_type = _get_type,
130 .migrate = _migrate,
131 .destroy = _destroy,
132 },
133 },
134 .initiator = initiator,
135 .ike_sa = ike_sa,
136 .requested = linked_list_create(),
137 );
138
139 if (initiator)
140 {
141 this->public.task.build = _build_i;
142 this->public.task.process = _process_i;
143 }
144 else
145 {
146 this->public.task.build = _build_r;
147 this->public.task.process = _process_r;
148 }
149
150 return &this->public;
151 }