Debian Codegraph @

c/include/proton/sasl.h

raw
1 #ifndef PROTON_SASL_H
2 #define PROTON_SASL_H 1
3
4 /*
5 *
6 * Licensed to the Apache Software Foundation (ASF) under one
7 * or more contributor license agreements. See the NOTICE file
8 * distributed with this work for additional information
9 * regarding copyright ownership. The ASF licenses this file
10 * to you under the Apache License, Version 2.0 (the
11 * "License"); you may not use this file except in compliance
12 * with the License. You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an
18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 * KIND, either express or implied. See the License for the
20 * specific language governing permissions and limitations
21 * under the License.
22 *
23 */
24
25 #include <proton/import_export.h>
26 #include <proton/type_compat.h>
27 #include <proton/types.h>
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 /**
34 * @file
35 *
36 * @copybrief sasl
37 *
38 * @addtogroup sasl
39 * @{
40 */
41
42 /**
43 * The SASL layer is responsible for establishing an authenticated
44 * and/or encrypted tunnel over which AMQP frames are passed between
45 * peers. The peer acting as the SASL Client must provide
46 * authentication credentials. The peer acting as the SASL Server must
47 * provide authentication against the received credentials.
48 */
49 typedef struct pn_sasl_t pn_sasl_t;
50
51 /**
52 * The result of the SASL negotiation.
53 */
54 typedef enum {
55 PN_SASL_NONE = -1, /** negotiation not completed */
56 PN_SASL_OK = 0, /** authentication succeeded */
57 PN_SASL_AUTH = 1, /** failed due to bad credentials */
58 PN_SASL_SYS = 2, /** failed due to a system error */
59 PN_SASL_PERM = 3, /** failed due to unrecoverable error */
60 PN_SASL_TEMP = 4 /** failed due to transient error */
61 } pn_sasl_outcome_t;
62
63 /**
64 * Construct an Authentication and Security Layer object.
65 *
66 * This will return the SASL layer object for the supplied transport
67 * object. If there is currently no SASL layer one will be created.
68 *
69 * On the client side of an AMQP connection this will have the effect
70 * of ensuring that the AMQP SASL layer is used for that connection.
71 *
72 * @note For incoming connections you must call pn_transport_set_server()
73 * before pn_sasl() in order to set up a server SASL configuration.
74 *
75 * @return an object representing the SASL layer.
76 */
77 PN_EXTERN pn_sasl_t *pn_sasl(pn_transport_t *transport);
78
79 /**
80 * Do we support extended SASL negotiation
81 *
82 * Do we support extended SASL negotiation?
83 * All implementations of Proton support ANONYMOUS and EXTERNAL on both
84 * client and server sides and PLAIN on the client side.
85 *
86 * Extended SASL implementations use an external library (Cyrus SASL)
87 * to support other mechanisms beyond these basic ones.
88 *
89 * @return true if we support extended SASL negotiation, false if we only support basic negotiation.
90 */
91 PN_EXTERN bool pn_sasl_extended(void);
92
93 /**
94 * **Deprecated** - Do not use. There is no correct way to use this
95 * API.
96 *
97 * Set the outcome of SASL negotiation
98 *
99 * Used by the server to set the result of the negotiation process.
100 */
101 PN_EXTERN void pn_sasl_done(pn_sasl_t *sasl, pn_sasl_outcome_t outcome);
102
103 /**
104 * Retrieve the outcome of SASL negotiation.
105 */
106 PN_EXTERN pn_sasl_outcome_t pn_sasl_outcome(pn_sasl_t *sasl);
107
108 /**
109 * Retrieve the authenticated user
110 *
111 * This is usually used at the the server end to find the name of the authenticated user.
112 * On the client it will merely return whatever user was passed in to the
113 * pn_transport_set_user_password() API.
114 *
115 * If pn_sasl_outcome() returns a value other than PN_SASL_OK, then there will be no user to return.
116 * The returned value is only reliable after the PN_TRANSPORT_AUTHENTICATED event has been received.
117 *
118 * @param[in] sasl the sasl layer
119 *
120 * @return
121 * If the SASL layer was not negotiated then 0 is returned
122 * If the ANONYMOUS mechanism is used then the user will be "anonymous"
123 * Otherwise a string containing the user is returned.
124 */
125 PN_EXTERN const char *pn_sasl_get_user(pn_sasl_t *sasl);
126
127 /**
128 * Retrieve the authorization id
129 *
130 * This is usually used at the the server end to find the name of the requested authorization id.
131 * On the client it will merely return whatever was passed in to the
132 * pn_transport_set_authorization() API.
133 *
134 * If pn_sasl_outcome() returns a value other than PN_SASL_OK, then there will be no user to return.
135 * The returned value is only reliable after the PN_TRANSPORT_AUTHENTICATED event has been received.
136 *
137 * @param[in] sasl the sasl layer
138 *
139 * @return
140 * If the SASL layer was not negotiated then 0 is returned
141 * If the ANONYMOUS mechanism is used then 0 is returned
142 * If no authorization id was requested then 0 is returned
143 * Otherwise a string containing the requested authorization id is returned.
144 */
145 PN_EXTERN const char *pn_sasl_get_authorization(pn_sasl_t *sasl);
146
147 /**
148 * Return the selected SASL mechanism
149 *
150 * The returned value is only reliable after the PN_TRANSPORT_AUTHENTICATED event has been received.
151 *
152 * @param[in] sasl the SASL layer
153 *
154 * @return The authentication mechanism selected by the SASL layer
155 */
156 PN_EXTERN const char *pn_sasl_get_mech(pn_sasl_t *sasl);
157
158 /**
159 * SASL mechanisms that are to be considered for authentication
160 *
161 * This can be used on either the client or the server to restrict the SASL
162 * mechanisms that may be used to the mechanisms on the list.
163 *
164 * @note By default the GSSAPI and GSS-SPNEGO mechanisms are not enabled for clients. This is because
165 * these mechanisms have the problematic behaviour of 'capturing' the client whenever they are installed
166 * so that they will be used by the client if offered by the server even if the client can't successfully
167 * authenticate this way. This can lead to some very hard to debug failures.
168 *
169 * @note The GSSAPI or GSS-SPNEGO mechanisms need to be explicitly enabled if they are required (together
170 * with any other required mechanisms).
171 *
172 * @param[in] sasl the SASL layer
173 * @param[in] mechs space separated list of mechanisms that are allowed for authentication
174 */
175 PN_EXTERN void pn_sasl_allowed_mechs(pn_sasl_t *sasl, const char *mechs);
176
177 /**
178 * Boolean to allow use of clear text authentication mechanisms
179 *
180 * By default the SASL layer is configured not to allow mechanisms that disclose
181 * the clear text of the password over an unencrypted AMQP connection. This specifically
182 * will disallow the use of the PLAIN mechanism without using SSL encryption.
183 *
184 * This default is to avoid disclosing password information accidentally over an
185 * insecure network.
186 *
187 * If you actually wish to use a clear text password unencrypted then you can use this
188 * API to set allow_insecure_mechs to true.
189 *
190 * @param[in] sasl the SASL layer
191 * @param[in] insecure set this to true to allow unencrypted PLAIN authentication.
192 *
193 */
194 PN_EXTERN void pn_sasl_set_allow_insecure_mechs(pn_sasl_t *sasl, bool insecure);
195
196 /**
197 * Return the current value for allow_insecure_mechs
198 *
199 * @param[in] sasl the SASL layer
200 */
201 PN_EXTERN bool pn_sasl_get_allow_insecure_mechs(pn_sasl_t *sasl);
202
203 /**
204 * Set the sasl configuration name
205 *
206 * This is used to construct the SASL configuration filename. In the current implementation
207 * it ".conf" is added to the name and the file is looked for in the configuration directory.
208 *
209 * If not set it will default to "proton-server" for a sasl server and "proton-client"
210 * for a client.
211 *
212 * @param[in] sasl the SASL layer
213 * @param[in] name the configuration name
214 */
215 PN_EXTERN void pn_sasl_config_name(pn_sasl_t *sasl, const char *name);
216
217 /**
218 * Set the sasl configuration path
219 *
220 * This is used to tell SASL where to look for the configuration file.
221 * In the current implementation it can be a colon separated list of directories.
222 *
223 * The environment variable PN_SASL_CONFIG_PATH can also be used to set this path,
224 * but if both methods are used then this pn_sasl_config_path() will take precedence.
225 *
226 * If not set the underlying implementation default will be used.
227 * for a client.
228 *
229 * @param[in] sasl the SASL layer
230 * @param[in] path the configuration path
231 */
232 PN_EXTERN void pn_sasl_config_path(pn_sasl_t *sasl, const char *path);
233
234 /**
235 * @}
236 */
237
238 #ifdef __cplusplus
239 }
240 #endif
241
242 #endif /* sasl.h */