IKEv1 XAuth: Added plugin support for XAuth, which allows us to have plugins to talk...
[strongswan.git] / src / libcharon / sa / authenticators / xauth / xauth_method.h
1 /*
2 * Copyright (C) 2006 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 /**
17 * @defgroup xauth_method xauth_method
18 * @{ @ingroup xauth
19 */
20
21 #ifndef XAUTH_METHOD_H_
22 #define XAUTH_METHOD_H_
23
24 typedef struct xauth_method_t xauth_method_t;
25 typedef enum xauth_role_t xauth_role_t;
26
27 #include <library.h>
28 #include <plugins/plugin.h>
29 #include <utils/identification.h>
30 #include <encoding/payloads/cp_payload.h>
31 #include <xauth/xauth.h>
32
33 /**
34 * Role of an xauth_method, SERVER or PEER (client)
35 */
36 enum xauth_role_t {
37 XAUTH_SERVER,
38 XAUTH_PEER,
39 };
40 /**
41 * enum names for xauth_role_t.
42 */
43 extern enum_name_t *xauth_role_names;
44
45 /**
46 * Interface of an XAuth method for server and client side.
47 *
48 * An XAuth method initiates an XAuth exchange and processes requests and
49 * responses. An XAuth method may need multiple exchanges before succeeding, and
50 * the xauth_authentication may use multiple XAuth methods to authenticate a peer.
51 * To accomplish these requirements, all XAuth methods have their own
52 * implementation while the xauth_authenticatior uses one or more of these
53 * XAuth methods. Sending of XAUTH(STATUS) message is not the job
54 * of the method, the xauth_authenticator does this.
55 */
56 struct xauth_method_t {
57
58 /**
59 * Initiate the XAuth exchange.
60 *
61 * initiate() is only useable for server implementations, as clients only
62 * reply to server requests.
63 * A cp_payload is created in "out" if result is NEED_MORE.
64 *
65 * @param out cp_payload to send to the client
66 * @return
67 * - NEED_MORE, if an other exchange is required
68 * - FAILED, if unable to create XAuth request payload
69 */
70 status_t (*initiate) (xauth_method_t *this, cp_payload_t **out);
71
72 /**
73 * Process a received XAuth message.
74 *
75 * A cp_payload is created in "out" if result is NEED_MORE.
76 *
77 * @param in cp_payload response received
78 * @param out created cp_payload to send
79 * @return
80 * - NEED_MORE, if an other exchange is required
81 * - FAILED, if XAuth method failed
82 * - SUCCESS, if XAuth method succeeded
83 */
84 status_t (*process) (xauth_method_t *this, cp_payload_t *in,
85 cp_payload_t **out);
86
87 /**
88 * Get the XAuth type implemented in this method.
89 *
90 * @param vendor pointer receiving vendor identifier for type, 0 for none
91 * @return type of the XAuth method
92 */
93 xauth_type_t (*get_type) (xauth_method_t *this, u_int32_t *vendor);
94
95 /**
96 * Destroys a eap_method_t object.
97 */
98 void (*destroy) (xauth_method_t *this);
99 };
100
101 /**
102 * Constructor definition for a pluggable XAuth method.
103 *
104 * Each XAuth module must define a constructor function which will return
105 * an initialized object with the methods defined in xauth_method_t.
106 * Constructors for server and peers are identical, to support both roles
107 * of a XAuth method, a plugin needs register two constructors in the
108 * xauth_manager_t.
109 * The passed identites are of type ID_EAP and valid only during the
110 * constructor invocation.
111 *
112 * @param server ID of the server to use for credential lookup
113 * @param peer ID of the peer to use for credential lookup
114 * @return implementation of the eap_method_t interface
115 */
116 typedef xauth_method_t *(*xauth_constructor_t)(identification_t *server,
117 identification_t *peer);
118
119 /**
120 * Helper function to (un-)register XAuth methods from plugin features.
121 *
122 * This function is a plugin_feature_callback_t and can be used with the
123 * PLUGIN_CALLBACK macro to register a XAuth method constructor.
124 *
125 * @param plugin plugin registering the XAuth method constructor
126 * @param feature associated plugin feature
127 * @param reg TRUE to register, FALSE to unregister.
128 * @param data data passed to callback, an xauth_constructor_t
129 */
130 bool xauth_method_register(plugin_t *plugin, plugin_feature_t *feature,
131 bool reg, void *data);
132
133 #endif /** XAUTH_METHOD_H_ @}*/