Bringing up TLS connections working.
[radsecproxy.git] / lib / include / radsec / radsec-impl.h
1 /** @file libradsec-impl.h
2     @brief Libraray internal header file for libradsec.  */
3
4 /* See the file COPYING for licensing information.  */
5
6 #include <freeradius/libradius.h>
7 #include <event2/util.h>
8 #if defined(RS_ENABLE_TLS)
9 #include <openssl/ssl.h>
10 #endif
11
12 /* Constants.  */
13 #define RS_HEADER_LEN 4
14
15 /* Data types.  */
16 enum rs_cred_type {
17     RS_CRED_NONE = 0,
18     RS_CRED_TLS_PSK_RSA,        /* RFC 4279.  */
19 };
20 typedef unsigned int rs_cred_type_t;
21
22 struct rs_packet;
23
24 struct rs_credentials {
25     enum rs_cred_type type;
26     char *identity;
27     char *secret;
28 };
29
30 struct rs_error {
31     int code;
32     char *msg;
33     char buf[1024];
34 };
35
36 struct rs_peer {
37     struct rs_connection *conn;
38     struct rs_realm *realm;
39     struct evutil_addrinfo *addr;
40     int fd;                     /* Socket.  */
41     char is_connecting;         /* FIXME: replace with a single state member */
42     char is_connected;          /* FIXME: replace with a single state member */
43     char *secret;
44     int timeout;                /* client only */
45     int tries;                  /* client only */
46     struct rs_peer *next;
47 };
48
49 struct rs_realm {
50     char *name;
51     enum rs_conn_type type;
52     char *cacertfile;
53     char *cacertpath;
54     char *certfile;
55     char *certkeyfile;
56     struct rs_peer *peers;
57     struct rs_realm *next;
58 };
59
60 struct rs_context {
61     struct rs_realm *realms;
62     struct rs_alloc_scheme alloc_scheme;
63     struct rs_error *err;
64     fr_randctx fr_randctx;
65 };
66
67 struct rs_connection {
68     struct rs_context *ctx;
69     struct event_base *evb;
70     struct bufferevent *bev;
71     enum rs_conn_type type;
72     struct rs_credentials transport_credentials;
73     struct rs_conn_callbacks callbacks;
74     void *user_data;
75     struct rs_peer *peers;
76     struct rs_peer *active_peer;
77     struct rs_error *err;
78     int nextid;
79     int user_dispatch_flag : 1; /* User does the dispatching.  */
80 #if defined(RS_ENABLE_TLS)
81     SSL_CTX *tls_ctx;
82     SSL *tls_ssl;
83 #endif
84 };
85
86 struct rs_packet {
87     struct rs_connection *conn;
88     char hdr_read_flag;
89     uint8_t hdr[4];
90     RADIUS_PACKET *rpkt;
91     struct rs_packet *original;
92 };
93
94 struct rs_attr {
95     struct rs_packet *pkt;
96     VALUE_PAIR *vp;
97 };
98
99 /* Nonpublic functions.  */
100 struct rs_error *_rs_resolv(struct evutil_addrinfo **addr,
101                             rs_conn_type_t type, const char *hostname,
102                             const char *service);
103 struct rs_peer *_rs_peer_create(struct rs_context *ctx,
104                                 struct rs_peer **rootp);
105 struct rs_error *_rs_err_create(unsigned int code, const char *file,
106                                 int line, const char *fmt, ...);
107 int _rs_err_conn_push_err(struct rs_connection *conn,
108                           struct rs_error *err);
109
110
111 /* Convenience macros.  */
112 #define rs_calloc(h, nmemb, size) \
113     (h->alloc_scheme.calloc ? h->alloc_scheme.calloc : calloc)(nmemb, size)
114 #define rs_malloc(h, size) \
115     (h->alloc_scheme.malloc ? h->alloc_scheme.malloc : malloc)(size)
116 #define rs_free(h, ptr) \
117     (h->alloc_scheme.free ? h->alloc_scheme.free : free)(ptr)
118 #define rs_realloc(h, realloc, ptr, size) \
119     (h->alloc_scheme.realloc ? h->alloc_scheme.realloc : realloc)(ptr, size)
120
121 /* Local Variables: */
122 /* c-file-style: "stroustrup" */
123 /* End: */