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)
45TDSRET tds_ssl_init(TDSSOCKET *tds, bool full);
46void tds_ssl_deinit(TDSCONNECTION *conn);
47
48# ifdef HAVE_GNUTLS
49
50static inline int
51tds_ssl_pending(TDSCONNECTION *conn)
52{
53 return gnutls_record_check_pending((gnutls_session_t) conn->tls_session);
54}
55
56static inline int
57tds_ssl_read(TDSCONNECTION *conn, unsigned char *buf, int buflen)
58{
59 return gnutls_record_recv((gnutls_session_t) conn->tls_session, buf, buflen);
60}
61
62static inline int
63tds_ssl_write(TDSCONNECTION *conn, const unsigned char *buf, int buflen)
64{
65 return gnutls_record_send((gnutls_session_t) conn->tls_session, buf, buflen);
66}
67# else
68
69/* compatibility for LibreSSL 2.7 */
70#ifdef LIBRESSL_VERSION_NUMBER
71#define TLS_ST_OK SSL_ST_OK
72#endif
73
74static inline int
75tds_ssl_pending(TDSCONNECTION *conn)
76{
77 return SSL_pending((SSL *) conn->tls_session);
78}
79
80static inline int
81tds_ssl_read(TDSCONNECTION *conn, unsigned char *buf, int buflen)
82{
83 return SSL_read((SSL *) conn->tls_session, buf, buflen);
84}
85
86static inline int
87tds_ssl_write(TDSCONNECTION *conn, const unsigned char *buf, int buflen)
88{
89 return SSL_write((SSL *) conn->tls_session, buf, buflen);
90}
91# endif
92#else
93static inline TDSRET
94tds_ssl_init(TDSSOCKET *tds TDS_UNUSED, bool full TDS_UNUSED)
95{
96 return TDS_FAIL;
97}
98
99static inline void
100tds_ssl_deinit(TDSCONNECTION *conn TDS_UNUSED)
101{
102}
103
104static inline int
105tds_ssl_pending(TDSCONNECTION *conn TDS_UNUSED)
106{
107 return 0;
108}
109
110static inline int
111tds_ssl_read(TDSCONNECTION *conn TDS_UNUSED, unsigned char *buf TDS_UNUSED, int buflen TDS_UNUSED)
112{
113 return -1;
114}
115
116static inline int
117tds_ssl_write(TDSCONNECTION *conn TDS_UNUSED, const unsigned char *buf TDS_UNUSED, int buflen TDS_UNUSED)
118{
119 return -1;
120}
121#endif
122
123#include <freetds/popvis.h>
124
125#endif /* _tdsguard_hpUeh3TzYOzN1FtT39tMHz_ */