1/* GIO - GLib Input, Output and Streaming Library
2 *
3 * Copyright (C) 2010 Red Hat, Inc.
4 *
5 * SPDX-License-Identifier: LGPL-2.1-or-later
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General
18 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef __G_TLS_CONNECTION_H__
22#define __G_TLS_CONNECTION_H__
23
24#if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
25#error "Only <gio/gio.h> can be included directly."
26#endif
27
28#include <gio/giostream.h>
29
30G_BEGIN_DECLS
31
32#define G_TYPE_TLS_CONNECTION (g_tls_connection_get_type ())
33#define G_TLS_CONNECTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), G_TYPE_TLS_CONNECTION, GTlsConnection))
34#define G_TLS_CONNECTION_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_TLS_CONNECTION, GTlsConnectionClass))
35#define G_IS_TLS_CONNECTION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), G_TYPE_TLS_CONNECTION))
36#define G_IS_TLS_CONNECTION_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_TLS_CONNECTION))
37#define G_TLS_CONNECTION_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), G_TYPE_TLS_CONNECTION, GTlsConnectionClass))
38
39typedef struct _GTlsConnectionClass GTlsConnectionClass;
40typedef struct _GTlsConnectionPrivate GTlsConnectionPrivate;
41
42struct _GTlsConnection {
43 GIOStream parent_instance;
44
45 GTlsConnectionPrivate *priv;
46};
47
48/**
49 * GTlsConnectionClass:
50 * @parent_class: The parent class.
51 * @accept_certificate: Check whether to accept a certificate.
52 * @handshake: Perform a handshake operation.
53 * @handshake_async: Start an asynchronous handshake operation.
54 * @handshake_finish: Finish an asynchronous handshake operation.
55 * @get_binding_data: Retrieve TLS channel binding data (Since: 2.66)
56 * @get_negotiated_protocol: Get ALPN-negotiated protocol (Since: 2.70)
57 *
58 * The class structure for the #GTlsConnection type.
59 *
60 * Since: 2.28
61 */
62struct _GTlsConnectionClass
63{
64 GIOStreamClass parent_class;
65
66 /* signals */
67 gboolean ( *accept_certificate) (GTlsConnection *connection,
68 GTlsCertificate *peer_cert,
69 GTlsCertificateFlags errors);
70
71 /* methods */
72 gboolean ( *handshake ) (GTlsConnection *conn,
73 GCancellable *cancellable,
74 GError **error);
75
76 void ( *handshake_async ) (GTlsConnection *conn,
77 int io_priority,
78 GCancellable *cancellable,
79 GAsyncReadyCallback callback,
80 gpointer user_data);
81 gboolean ( *handshake_finish ) (GTlsConnection *conn,
82 GAsyncResult *result,
83 GError **error);
84
85G_GNUC_BEGIN_IGNORE_DEPRECATIONS
86 gboolean ( *get_binding_data) (GTlsConnection *conn,
87 GTlsChannelBindingType type,
88 GByteArray *data,
89 GError **error);
90G_GNUC_END_IGNORE_DEPRECATIONS
91
92 const gchar *(*get_negotiated_protocol) (GTlsConnection *conn);
93
94 /*< private >*/
95 /* Padding for future expansion */
96 gpointer padding[6];
97};
98
99GIO_AVAILABLE_IN_ALL
100GType g_tls_connection_get_type (void) G_GNUC_CONST;
101
102GIO_DEPRECATED
103void g_tls_connection_set_use_system_certdb (GTlsConnection *conn,
104 gboolean use_system_certdb);
105GIO_DEPRECATED
106gboolean g_tls_connection_get_use_system_certdb (GTlsConnection *conn);
107
108GIO_AVAILABLE_IN_ALL
109void g_tls_connection_set_database (GTlsConnection *conn,
110 GTlsDatabase *database);
111GIO_AVAILABLE_IN_ALL
112GTlsDatabase * g_tls_connection_get_database (GTlsConnection *conn);
113
114GIO_AVAILABLE_IN_ALL
115void g_tls_connection_set_certificate (GTlsConnection *conn,
116 GTlsCertificate *certificate);
117GIO_AVAILABLE_IN_ALL
118GTlsCertificate *g_tls_connection_get_certificate (GTlsConnection *conn);
119
120GIO_AVAILABLE_IN_ALL
121void g_tls_connection_set_interaction (GTlsConnection *conn,
122 GTlsInteraction *interaction);
123GIO_AVAILABLE_IN_ALL
124GTlsInteraction * g_tls_connection_get_interaction (GTlsConnection *conn);
125
126GIO_AVAILABLE_IN_ALL
127GTlsCertificate *g_tls_connection_get_peer_certificate (GTlsConnection *conn);
128GIO_AVAILABLE_IN_ALL
129GTlsCertificateFlags g_tls_connection_get_peer_certificate_errors (GTlsConnection *conn);
130
131GIO_AVAILABLE_IN_ALL
132void g_tls_connection_set_require_close_notify (GTlsConnection *conn,
133 gboolean require_close_notify);
134GIO_AVAILABLE_IN_ALL
135gboolean g_tls_connection_get_require_close_notify (GTlsConnection *conn);
136
137G_GNUC_BEGIN_IGNORE_DEPRECATIONS
138GIO_DEPRECATED_IN_2_60
139void g_tls_connection_set_rehandshake_mode (GTlsConnection *conn,
140 GTlsRehandshakeMode mode);
141GIO_DEPRECATED_IN_2_60
142GTlsRehandshakeMode g_tls_connection_get_rehandshake_mode (GTlsConnection *conn);
143G_GNUC_END_IGNORE_DEPRECATIONS
144
145GIO_AVAILABLE_IN_2_60
146void g_tls_connection_set_advertised_protocols (GTlsConnection *conn,
147 const gchar * const *protocols);
148
149GIO_AVAILABLE_IN_2_60
150const gchar * g_tls_connection_get_negotiated_protocol (GTlsConnection *conn);
151
152G_GNUC_BEGIN_IGNORE_DEPRECATIONS
153GIO_AVAILABLE_IN_2_66
154gboolean g_tls_connection_get_channel_binding_data (GTlsConnection *conn,
155 GTlsChannelBindingType type,
156 GByteArray *data,
157 GError **error);
158G_GNUC_END_IGNORE_DEPRECATIONS
159
160GIO_AVAILABLE_IN_ALL
161gboolean g_tls_connection_handshake (GTlsConnection *conn,
162 GCancellable *cancellable,
163 GError **error);
164
165GIO_AVAILABLE_IN_ALL
166void g_tls_connection_handshake_async (GTlsConnection *conn,
167 int io_priority,
168 GCancellable *cancellable,
169 GAsyncReadyCallback callback,
170 gpointer user_data);
171GIO_AVAILABLE_IN_ALL
172gboolean g_tls_connection_handshake_finish (GTlsConnection *conn,
173 GAsyncResult *result,
174 GError **error);
175
176GIO_AVAILABLE_IN_2_70
177GTlsProtocolVersion g_tls_connection_get_protocol_version (GTlsConnection *conn);
178
179GIO_AVAILABLE_IN_2_70
180gchar * g_tls_connection_get_ciphersuite_name (GTlsConnection *conn);
181
182/**
183 * G_TLS_ERROR:
184 *
185 * Error domain for TLS. Errors in this domain will be from the
186 * #GTlsError enumeration. See #GError for more information on error
187 * domains.
188 */
189#define G_TLS_ERROR (g_tls_error_quark ())
190GIO_AVAILABLE_IN_ALL
191GQuark g_tls_error_quark (void);
192
193/**
194 * G_TLS_CHANNEL_BINDING_ERROR:
195 *
196 * Error domain for TLS channel binding. Errors in this domain will be from the
197 * #GTlsChannelBindingError enumeration. See #GError for more information on error
198 * domains.
199 *
200 * Since: 2.66
201 */
202#define G_TLS_CHANNEL_BINDING_ERROR (g_tls_channel_binding_error_quark ())
203GIO_AVAILABLE_IN_2_66
204GQuark g_tls_channel_binding_error_quark (void);
205
206/*< protected >*/
207GIO_AVAILABLE_IN_ALL
208gboolean g_tls_connection_emit_accept_certificate (GTlsConnection *conn,
209 GTlsCertificate *peer_cert,
210 GTlsCertificateFlags errors);
211
212G_END_DECLS
213
214#endif /* __G_TLS_CONNECTION_H__ */
215