FreeTDS API: include/freetds/tls.h Source File

FreeTDS API

Loading...
Searching...
No Matches
tls.h
1/* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2 * Copyright (C) 2015 Frediano Ziglio
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 */
19
20#ifndef _tdsguard_hpUeh3TzYOzN1FtT39tMHz_
21#define _tdsguard_hpUeh3TzYOzN1FtT39tMHz_
22
23#ifndef _tdsguard_hfOrWb5znoUCWdBPoNQvqN_
24#error tds.h must be included before tls.h
25#endif
26
27#ifdef HAVE_GNUTLS
28# if defined(_THREAD_SAFE) && defined(TDS_HAVE_PTHREAD_MUTEX)
29# include <freetds/thread.h>
30# ifndef GNUTLS_USE_NETTLE
31# include <gcrypt.h>
32# endif
33# endif
34# include <gnutls/gnutls.h>
35# include <gnutls/x509.h>
36#elif defined(HAVE_OPENSSL)
37# include <openssl/ssl.h>
38# include <openssl/x509v3.h>
39# include <openssl/err.h>
40#endif
41
42#include <freetds/pushvis.h>
43
44#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
45
46/*
47 * Common definitions
48 */
49TDSRET tds_ssl_init(TDSSOCKET *tds, bool full);
50void tds_ssl_deinit(TDSCONNECTION *conn);
51size_t tds_ssl_get_cb(TDSCONNECTION * conn, void *cb, size_t cblen);
52
53# ifdef HAVE_GNUTLS
54/*
55 * GnuTLS definitions
56 */
57static inline int
58tds_ssl_pending(TDSCONNECTION *conn)
59{
60 return gnutls_record_check_pending((gnutls_session_t) conn->tls_session);
61}
62
63static inline int
64tds_ssl_read(TDSCONNECTION *conn, unsigned char *buf, int buflen)
65{
66 return gnutls_record_recv((gnutls_session_t) conn->tls_session, buf, buflen);
67}
68
69static inline int
70tds_ssl_write(TDSCONNECTION *conn, const unsigned char *buf, int buflen)
71{
72 return gnutls_record_send((gnutls_session_t) conn->tls_session, buf, buflen);
73}
74
75# else
76/*
77 * OpenSSL definitions
78 */
79
80/* compatibility for LibreSSL 2.7 */
81#ifdef LIBRESSL_VERSION_NUMBER
82#define TLS_ST_OK SSL_ST_OK
83#endif
84
85static inline int
86tds_ssl_pending(TDSCONNECTION *conn)
87{
88 return SSL_pending((SSL *) conn->tls_session);
89}
90
91static inline int
92tds_ssl_read(TDSCONNECTION *conn, unsigned char *buf, int buflen)
93{
94 return SSL_read((SSL *) conn->tls_session, buf, buflen);
95}
96
97static inline int
98tds_ssl_write(TDSCONNECTION *conn, const unsigned char *buf, int buflen)
99{
100 return SSL_write((SSL *) conn->tls_session, buf, buflen);
101}
102# endif
103
104#else
105/*
106 * Definitions if TLS is not enabled
107 */
108static inline TDSRET
109tds_ssl_init(TDSSOCKET *tds TDS_UNUSED, bool full TDS_UNUSED)
110{
111 return TDS_FAIL;
112}
113
114static inline void
115tds_ssl_deinit(TDSCONNECTION *conn TDS_UNUSED)
116{
117}
118
119static inline int
120tds_ssl_pending(TDSCONNECTION *conn TDS_UNUSED)
121{
122 return 0;
123}
124
125static inline int
126tds_ssl_read(TDSCONNECTION *conn TDS_UNUSED, unsigned char *buf TDS_UNUSED, int buflen TDS_UNUSED)
127{
128 return -1;
129}
130
131static inline int
132tds_ssl_write(TDSCONNECTION *conn TDS_UNUSED, const unsigned char *buf TDS_UNUSED, int buflen TDS_UNUSED)
133{
134 return -1;
135}
136
137static inline size_t
138tds_ssl_get_cb(TDSCONNECTION *conn TDS_UNUSED, void *cb TDS_UNUSED, size_t cblen TDS_UNUSED)
139{
140 return 0;
141}
142#endif
143
144#include <freetds/popvis.h>
145
146#endif /* _tdsguard_hpUeh3TzYOzN1FtT39tMHz_ */
tds_connection
Definition tds.h:1088
tds_socket
Information for a server connection.
Definition tds.h:1174