1/* GIO - GLib Input, Output and Streaming Library
2 *
3 * Copyright © 2010 Red Hat, Inc.
4 * Copyright © 2015 Collabora, Ltd.
5 *
6 * SPDX-License-Identifier: LGPL-2.1-or-later
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General
19 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef __G_DTLS_CONNECTION_H__
23#define __G_DTLS_CONNECTION_H__
24
25#if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
26#error "Only <gio/gio.h> can be included directly."
27#endif
28
29#include <gio/gdatagrambased.h>
30
31G_BEGIN_DECLS
32
33#define G_TYPE_DTLS_CONNECTION (g_dtls_connection_get_type ())
34#define G_DTLS_CONNECTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), G_TYPE_DTLS_CONNECTION, GDtlsConnection))
35#define G_IS_DTLS_CONNECTION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), G_TYPE_DTLS_CONNECTION))
36#define G_DTLS_CONNECTION_GET_INTERFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), G_TYPE_DTLS_CONNECTION, GDtlsConnectionInterface))
37
38typedef struct _GDtlsConnectionInterface GDtlsConnectionInterface;
39
40/**
41 * GDtlsConnectionInterface:
42 * @g_iface: The parent interface.
43 * @accept_certificate: Check whether to accept a certificate.
44 * @handshake: Perform a handshake operation.
45 * @handshake_async: Start an asynchronous handshake operation.
46 * @handshake_finish: Finish an asynchronous handshake operation.
47 * @shutdown: Shut down one or both directions of the connection.
48 * @shutdown_async: Start an asynchronous shutdown operation.
49 * @shutdown_finish: Finish an asynchronous shutdown operation.
50 * @set_advertised_protocols: Set APLN protocol list (Since: 2.60)
51 * @get_negotiated_protocol: Get ALPN-negotiated protocol (Since: 2.60)
52 * @get_binding_data: Retrieve TLS channel binding data (Since: 2.66)
53 *
54 * Virtual method table for a #GDtlsConnection implementation.
55 *
56 * Since: 2.48
57 */
58struct _GDtlsConnectionInterface
59{
60 GTypeInterface g_iface;
61
62 /* signals */
63 gboolean (*accept_certificate) (GDtlsConnection *connection,
64 GTlsCertificate *peer_cert,
65 GTlsCertificateFlags errors);
66
67 /* methods */
68 gboolean (*handshake) (GDtlsConnection *conn,
69 GCancellable *cancellable,
70 GError **error);
71
72 void (*handshake_async) (GDtlsConnection *conn,
73 int io_priority,
74 GCancellable *cancellable,
75 GAsyncReadyCallback callback,
76 gpointer user_data);
77 gboolean (*handshake_finish) (GDtlsConnection *conn,
78 GAsyncResult *result,
79 GError **error);
80
81 gboolean (*shutdown) (GDtlsConnection *conn,
82 gboolean shutdown_read,
83 gboolean shutdown_write,
84 GCancellable *cancellable,
85 GError **error);
86
87 void (*shutdown_async) (GDtlsConnection *conn,
88 gboolean shutdown_read,
89 gboolean shutdown_write,
90 int io_priority,
91 GCancellable *cancellable,
92 GAsyncReadyCallback callback,
93 gpointer user_data);
94 gboolean (*shutdown_finish) (GDtlsConnection *conn,
95 GAsyncResult *result,
96 GError **error);
97
98 void (*set_advertised_protocols) (GDtlsConnection *conn,
99 const gchar * const *protocols);
100 const gchar *(*get_negotiated_protocol) (GDtlsConnection *conn);
101
102G_GNUC_BEGIN_IGNORE_DEPRECATIONS
103 gboolean (*get_binding_data) (GDtlsConnection *conn,
104 GTlsChannelBindingType type,
105 GByteArray *data,
106 GError **error);
107G_GNUC_END_IGNORE_DEPRECATIONS
108};
109
110GIO_AVAILABLE_IN_2_48
111GType g_dtls_connection_get_type (void) G_GNUC_CONST;
112
113GIO_AVAILABLE_IN_2_48
114void g_dtls_connection_set_database (GDtlsConnection *conn,
115 GTlsDatabase *database);
116GIO_AVAILABLE_IN_2_48
117GTlsDatabase *g_dtls_connection_get_database (GDtlsConnection *conn);
118
119GIO_AVAILABLE_IN_2_48
120void g_dtls_connection_set_certificate (GDtlsConnection *conn,
121 GTlsCertificate *certificate);
122GIO_AVAILABLE_IN_2_48
123GTlsCertificate *g_dtls_connection_get_certificate (GDtlsConnection *conn);
124
125GIO_AVAILABLE_IN_2_48
126void g_dtls_connection_set_interaction (GDtlsConnection *conn,
127 GTlsInteraction *interaction);
128GIO_AVAILABLE_IN_2_48
129GTlsInteraction *g_dtls_connection_get_interaction (GDtlsConnection *conn);
130
131GIO_AVAILABLE_IN_2_48
132GTlsCertificate *g_dtls_connection_get_peer_certificate (GDtlsConnection *conn);
133GIO_AVAILABLE_IN_2_48
134GTlsCertificateFlags g_dtls_connection_get_peer_certificate_errors (GDtlsConnection *conn);
135
136GIO_AVAILABLE_IN_2_48
137void g_dtls_connection_set_require_close_notify (GDtlsConnection *conn,
138 gboolean require_close_notify);
139GIO_AVAILABLE_IN_2_48
140gboolean g_dtls_connection_get_require_close_notify (GDtlsConnection *conn);
141
142G_GNUC_BEGIN_IGNORE_DEPRECATIONS
143GIO_DEPRECATED_IN_2_60
144void g_dtls_connection_set_rehandshake_mode (GDtlsConnection *conn,
145 GTlsRehandshakeMode mode);
146GIO_DEPRECATED_IN_2_60
147GTlsRehandshakeMode g_dtls_connection_get_rehandshake_mode (GDtlsConnection *conn);
148G_GNUC_END_IGNORE_DEPRECATIONS
149
150GIO_AVAILABLE_IN_2_48
151gboolean g_dtls_connection_handshake (GDtlsConnection *conn,
152 GCancellable *cancellable,
153 GError **error);
154
155GIO_AVAILABLE_IN_2_48
156void g_dtls_connection_handshake_async (GDtlsConnection *conn,
157 int io_priority,
158 GCancellable *cancellable,
159 GAsyncReadyCallback callback,
160 gpointer user_data);
161GIO_AVAILABLE_IN_2_48
162gboolean g_dtls_connection_handshake_finish (GDtlsConnection *conn,
163 GAsyncResult *result,
164 GError **error);
165
166GIO_AVAILABLE_IN_2_48
167gboolean g_dtls_connection_shutdown (GDtlsConnection *conn,
168 gboolean shutdown_read,
169 gboolean shutdown_write,
170 GCancellable *cancellable,
171 GError **error);
172
173GIO_AVAILABLE_IN_2_48
174void g_dtls_connection_shutdown_async (GDtlsConnection *conn,
175 gboolean shutdown_read,
176 gboolean shutdown_write,
177 int io_priority,
178 GCancellable *cancellable,
179 GAsyncReadyCallback callback,
180 gpointer user_data);
181GIO_AVAILABLE_IN_2_48
182gboolean g_dtls_connection_shutdown_finish (GDtlsConnection *conn,
183 GAsyncResult *result,
184 GError **error);
185
186GIO_AVAILABLE_IN_2_48
187gboolean g_dtls_connection_close (GDtlsConnection *conn,
188 GCancellable *cancellable,
189 GError **error);
190
191GIO_AVAILABLE_IN_2_48
192void g_dtls_connection_close_async (GDtlsConnection *conn,
193 int io_priority,
194 GCancellable *cancellable,
195 GAsyncReadyCallback callback,
196 gpointer user_data);
197GIO_AVAILABLE_IN_2_48
198gboolean g_dtls_connection_close_finish (GDtlsConnection *conn,
199 GAsyncResult *result,
200 GError **error);
201
202/*< protected >*/
203GIO_AVAILABLE_IN_2_48
204gboolean g_dtls_connection_emit_accept_certificate (GDtlsConnection *conn,
205 GTlsCertificate *peer_cert,
206 GTlsCertificateFlags errors);
207GIO_AVAILABLE_IN_2_60
208void g_dtls_connection_set_advertised_protocols (GDtlsConnection *conn,
209 const gchar * const *protocols);
210
211GIO_AVAILABLE_IN_2_60
212const gchar * g_dtls_connection_get_negotiated_protocol (GDtlsConnection *conn);
213
214G_GNUC_BEGIN_IGNORE_DEPRECATIONS
215GIO_AVAILABLE_IN_2_66
216gboolean g_dtls_connection_get_channel_binding_data (GDtlsConnection *conn,
217 GTlsChannelBindingType type,
218 GByteArray *data,
219 GError **error);
220G_GNUC_END_IGNORE_DEPRECATIONS
221
222GIO_AVAILABLE_IN_2_70
223GTlsProtocolVersion g_dtls_connection_get_protocol_version (GDtlsConnection *conn);
224
225GIO_AVAILABLE_IN_2_70
226gchar * g_dtls_connection_get_ciphersuite_name (GDtlsConnection *conn);
227
228G_END_DECLS
229
230#endif /* __G_DTLS_CONNECTION_H__ */
231