]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libtls/tls_socket.h
Update copyright headers after acquisition by secunet
[thirdparty/strongswan.git] / src / libtls / tls_socket.h
1 /*
2 * Copyright (C) 2010 Martin Willi
3 *
4 * Copyright (C) secunet Security Networks AG
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 /**
18 * @defgroup tls_socket tls_socket
19 * @{ @ingroup libtls
20 */
21
22 #ifndef TLS_SOCKET_H_
23 #define TLS_SOCKET_H_
24
25 #include "tls.h"
26
27 typedef struct tls_socket_t tls_socket_t;
28
29 /**
30 * TLS secured socket.
31 *
32 * Wraps a blocking (socket) file descriptor for a reliable transport into a
33 * TLS secured socket. TLS negotiation happens on demand, certificates and
34 * private keys are fetched from any registered credential set.
35 */
36 struct tls_socket_t {
37
38 /**
39 * Read data from secured socket.
40 *
41 * This call is blocking, you may use select() on the underlying socket to
42 * wait for data. If "block" is FALSE and no application data is available,
43 * the function returns -1 and sets errno to EWOULDBLOCK.
44 *
45 * @param buf buffer to write received data to
46 * @param len size of buffer
47 * @param block TRUE to block this call, FALSE to fail if it would block
48 * @return number of bytes read, 0 on EOF, -1 on error
49 */
50 ssize_t (*read)(tls_socket_t *this, void *buf, size_t len, bool block);
51
52 /**
53 * Write data over the secured socket.
54 *
55 * @param buf data to send
56 * @param len number of bytes to write from buf
57 * @return number of bytes written, -1 on error
58 */
59 ssize_t (*write)(tls_socket_t *this, void *buf, size_t len);
60
61 /**
62 * Read/write plain data from file descriptor.
63 *
64 * This call is blocking, but a thread cancellation point. Data is
65 * exchanged until one of the sockets gets closed or an error occurs.
66 *
67 * @param rfd file descriptor to read plain data from
68 * @param wfd file descriptor to write plain data to
69 * @return TRUE if data exchanged successfully
70 */
71 bool (*splice)(tls_socket_t *this, int rfd, int wfd);
72
73 /**
74 * Get the underlying file descriptor passed to the constructor.
75 *
76 * @return file descriptor
77 */
78 int (*get_fd)(tls_socket_t *this);
79
80 /**
81 * Return the server identity.
82 *
83 * @return server identity
84 */
85 identification_t* (*get_server_id)(tls_socket_t *this);
86
87 /**
88 * Return the peer identity.
89 *
90 * @return peer identity
91 */
92 identification_t* (*get_peer_id)(tls_socket_t *this);
93
94 /**
95 * Destroy a tls_socket_t.
96 */
97 void (*destroy)(tls_socket_t *this);
98 };
99
100 /**
101 * Create a tls_socket instance.
102 *
103 * Use TLS_UNSPEC to default to the configured min/max version.
104 *
105 * @param is_server TRUE to act as TLS server
106 * @param server server identity
107 * @param peer client identity, NULL for no client authentication
108 * @param fd socket to read/write from
109 * @param cache session cache to use, or NULL
110 * @param min_version minimum TLS version to negotiate or TLS_UNSPEC
111 * @param max_version maximum TLS version to negotiate or TLS_UNSPEC
112 * @param flags flags controlling the TLS stack
113 * @return TLS socket wrapper
114 */
115 tls_socket_t *tls_socket_create(bool is_server, identification_t *server,
116 identification_t *peer, int fd,
117 tls_cache_t *cache, tls_version_t min_version,
118 tls_version_t max_version, tls_flag_t flags);
119
120 #endif /** TLS_SOCKET_H_ @}*/