Qpid Proton C API 0.40.0
 
Loading...
Searching...
No Matches
sasl_plugin.h
1#ifndef PROTON_SASL_PLUGIN_H
2#define PROTON_SASL_PLUGIN_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/annotations.h>
26#include <proton/import_export.h>
27#include <proton/logger.h>
28#include <proton/type_compat.h>
29#include <proton/types.h>
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
37/*
38 Internal SASL authenticator interface: These are the entry points to a SASL implementations
39
40 Free up all data structures allocated by the SASL implementation
41 void free(pn_transport_t *transport);
42
43 Return space separated list of supported mechanisms (client and server)
44 If the returned string is dynamically allocated by the SASL implemetation
45 it must stay valid until the free entry point is called.
46 const char *list_mechanisms(pn_transport_t *transport);
47
48 Initialise for either client or server (can't call both for a
49 given transport/connection):
50 bool init_server(pn_transport_t *transport);
51 bool init_client(pn_transport_t *transport);
52
53 Writing:
54 void prepare_write(pn_transport_t *transport);
55
56 Reading:
57 Server side (process server SASL messages):
58 void process_init(pn_transport_t *transport, const char *mechanism, const pn_bytes_t *recv);
59 void process_response(pn_transport_t *transport, const pn_bytes_t *recv);
60
61 Client side (process client SASL messages)
62 bool process_mechanisms(pn_transport_t *transport, const char *mechs);
63 void process_challenge(pn_transport_t *transport, const pn_bytes_t *recv);
64 void process_outcome(pn_transport_t *transport);
65
66 Security layer interface (active after SASL succeeds)
67 bool can_encrypt(pn_transport_t *transport);
68 ssize_t max_encrypt_size(pn_transport_t *transport);
69 ssize_t encode(pn_transport_t *transport, pn_bytes_t in, pn_bytes_t *out);
70 ssize_t decode(pn_transport_t *transport, pn_bytes_t in, pn_bytes_t *out);
71*/
72
73typedef struct pnx_sasl_implementation
74{
75 void (*free)(pn_transport_t *transport);
76
77 const char* (*list_mechanisms)(pn_transport_t *transport);
78
79 bool (*init_server)(pn_transport_t *transport);
80 bool (*init_client)(pn_transport_t *transport);
81
82 void (*prepare_write)(pn_transport_t *transport);
83
84 void (*process_init)(pn_transport_t *transport, const char *mechanism, const pn_bytes_t *recv);
85 void (*process_response)(pn_transport_t *transport, const pn_bytes_t *recv);
86
87 bool (*process_mechanisms)(pn_transport_t *transport, const char *mechs);
88 void (*process_challenge)(pn_transport_t *transport, const pn_bytes_t *recv);
89 void (*process_outcome)(pn_transport_t *transport, const pn_bytes_t *recv);
90
91 bool (*can_encrypt)(pn_transport_t *transport);
92 ssize_t (*max_encrypt_size)(pn_transport_t *transport);
93 ssize_t (*encode)(pn_transport_t *transport, pn_bytes_t in, pn_bytes_t *out);
94 ssize_t (*decode)(pn_transport_t *transport, pn_bytes_t in, pn_bytes_t *out);
95
96} pnx_sasl_implementation;
97
98/* Shared SASL API used by the actual SASL authenticators */
99enum pnx_sasl_state {
100 SASL_NONE,
101 SASL_POSTED_INIT,
102 SASL_POSTED_MECHANISMS,
103 SASL_POSTED_RESPONSE,
104 SASL_POSTED_CHALLENGE,
105 SASL_RECVED_SUCCESS,
106 SASL_RECVED_FAILURE,
107 SASL_POSTED_OUTCOME,
108 SASL_ERROR
109};
110
111/* APIs used by sasl implementations */
112PN_EXTERN void pnx_sasl_logf(pn_transport_t *transport, pn_log_level_t level, PN_PRINTF_FORMAT const char *format, ...)
113 PN_PRINTF_FORMAT_ATTR(3, 4);
114PN_EXTERN void pnx_sasl_error(pn_transport_t *transport, const char* err, const char* condition_name);
115
116PN_EXTERN void *pnx_sasl_get_context(pn_transport_t *transport);
117PN_EXTERN void pnx_sasl_set_context(pn_transport_t *transport, void *context);
118
119PN_EXTERN bool pnx_sasl_is_client(pn_transport_t *transport);
120PN_EXTERN bool pnx_sasl_is_mechanism_included(pn_transport_t *transport, pn_bytes_t s);
121PN_EXTERN bool pnx_sasl_is_transport_encrypted(pn_transport_t *transport);
122PN_EXTERN bool pnx_sasl_get_allow_insecure_mechanisms(pn_transport_t *transport);
123PN_EXTERN bool pnx_sasl_get_authentication_required(pn_transport_t *transport);
124PN_EXTERN const char *pnx_sasl_get_external_username(pn_transport_t *transport);
125PN_EXTERN int pnx_sasl_get_external_ssf(pn_transport_t *transport);
126
127PN_EXTERN const char *pnx_sasl_get_username(pn_transport_t *transport);
128PN_EXTERN const char *pnx_sasl_get_password(pn_transport_t *transport);
129PN_EXTERN const char *pnx_sasl_get_authorization(pn_transport_t *transport);
130PN_EXTERN void pnx_sasl_clear_password(pn_transport_t *transport);
131PN_EXTERN const char *pnx_sasl_get_remote_fqdn(pn_transport_t *transport);
132PN_EXTERN const char *pnx_sasl_get_selected_mechanism(pn_transport_t *transport);
133
134PN_EXTERN void pnx_sasl_set_bytes_out(pn_transport_t *transport, pn_bytes_t bytes);
135PN_EXTERN void pnx_sasl_set_desired_state(pn_transport_t *transport, enum pnx_sasl_state desired_state);
136PN_EXTERN void pnx_sasl_set_selected_mechanism(pn_transport_t *transport, const char *mechanism);
137PN_EXTERN void pnx_sasl_set_local_hostname(pn_transport_t * transport, const char * fqdn);
138PN_EXTERN void pnx_sasl_set_succeeded(pn_transport_t *transport, const char *username, const char *authzid);
139PN_EXTERN void pnx_sasl_set_failed(pn_transport_t *transport);
140
141PN_EXTERN void pnx_sasl_set_implementation(pn_transport_t *transport, const pnx_sasl_implementation *impl, void *context);
142PN_EXTERN void pnx_sasl_set_default_implementation(const pnx_sasl_implementation *impl);
143
146#ifdef __cplusplus
147}
148#endif
149
150#endif /* sasl_plugin.h */
A const byte buffer.
Definition types.h:223
pn_log_level_t
Definitions for different severities of log messages Note that these are exclusive bits so that you c...
Definition logger.h:110
struct pn_transport_t pn_transport_t
A network channel supporting an AMQP connection.
Definition types.h:450
Facility for logging messages.
AMQP and API data types.