1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2010 Red Hat, Inc.
5 * SPDX-License-Identifier: LGPL-2.1-or-later
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.
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.
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/>.
21 #ifndef __G_TLS_CONNECTION_H__
22 #define __G_TLS_CONNECTION_H__
24 #if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
25 #error "Only <gio/gio.h> can be included directly."
28 #include <gio/giostream.h>
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))
39 typedef struct _GTlsConnectionClass GTlsConnectionClass;
40 typedef struct _GTlsConnectionPrivate GTlsConnectionPrivate;
42 struct _GTlsConnection {
43 GIOStream parent_instance;
45 GTlsConnectionPrivate *priv;
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)
58 * The class structure for the #GTlsConnection type.
62 struct _GTlsConnectionClass
64 GIOStreamClass parent_class;
67 gboolean ( *accept_certificate) (GTlsConnection *connection,
68 GTlsCertificate *peer_cert,
69 GTlsCertificateFlags errors);
72 gboolean ( *handshake ) (GTlsConnection *conn,
73 GCancellable *cancellable,
76 void ( *handshake_async ) (GTlsConnection *conn,
78 GCancellable *cancellable,
79 GAsyncReadyCallback callback,
81 gboolean ( *handshake_finish ) (GTlsConnection *conn,
85 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
86 gboolean ( *get_binding_data) (GTlsConnection *conn,
87 GTlsChannelBindingType type,
90 G_GNUC_END_IGNORE_DEPRECATIONS
92 const gchar *(*get_negotiated_protocol) (GTlsConnection *conn);
95 /* Padding for future expansion */
100 GType g_tls_connection_get_type (void) G_GNUC_CONST;
103 void g_tls_connection_set_use_system_certdb (GTlsConnection *conn,
104 gboolean use_system_certdb);
106 gboolean g_tls_connection_get_use_system_certdb (GTlsConnection *conn);
109 void g_tls_connection_set_database (GTlsConnection *conn,
110 GTlsDatabase *database);
112 GTlsDatabase * g_tls_connection_get_database (GTlsConnection *conn);
115 void g_tls_connection_set_certificate (GTlsConnection *conn,
116 GTlsCertificate *certificate);
118 GTlsCertificate *g_tls_connection_get_certificate (GTlsConnection *conn);
121 void g_tls_connection_set_interaction (GTlsConnection *conn,
122 GTlsInteraction *interaction);
124 GTlsInteraction * g_tls_connection_get_interaction (GTlsConnection *conn);
127 GTlsCertificate *g_tls_connection_get_peer_certificate (GTlsConnection *conn);
129 GTlsCertificateFlags g_tls_connection_get_peer_certificate_errors (GTlsConnection *conn);
132 void g_tls_connection_set_require_close_notify (GTlsConnection *conn,
133 gboolean require_close_notify);
135 gboolean g_tls_connection_get_require_close_notify (GTlsConnection *conn);
137 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
138 GIO_DEPRECATED_IN_2_60
139 void g_tls_connection_set_rehandshake_mode (GTlsConnection *conn,
140 GTlsRehandshakeMode mode);
141 GIO_DEPRECATED_IN_2_60
142 GTlsRehandshakeMode g_tls_connection_get_rehandshake_mode (GTlsConnection *conn);
143 G_GNUC_END_IGNORE_DEPRECATIONS
145 GIO_AVAILABLE_IN_2_60
146 void g_tls_connection_set_advertised_protocols (GTlsConnection *conn,
147 const gchar * const *protocols);
149 GIO_AVAILABLE_IN_2_60
150 const gchar * g_tls_connection_get_negotiated_protocol (GTlsConnection *conn);
152 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
153 GIO_AVAILABLE_IN_2_66
154 gboolean g_tls_connection_get_channel_binding_data (GTlsConnection *conn,
155 GTlsChannelBindingType type,
158 G_GNUC_END_IGNORE_DEPRECATIONS
161 gboolean g_tls_connection_handshake (GTlsConnection *conn,
162 GCancellable *cancellable,
166 void g_tls_connection_handshake_async (GTlsConnection *conn,
168 GCancellable *cancellable,
169 GAsyncReadyCallback callback,
172 gboolean g_tls_connection_handshake_finish (GTlsConnection *conn,
173 GAsyncResult *result,
176 GIO_AVAILABLE_IN_2_70
177 GTlsProtocolVersion g_tls_connection_get_protocol_version (GTlsConnection *conn);
179 GIO_AVAILABLE_IN_2_70
180 gchar * g_tls_connection_get_ciphersuite_name (GTlsConnection *conn);
185 * Error domain for TLS. Errors in this domain will be from the
186 * #GTlsError enumeration. See #GError for more information on error
189 #define G_TLS_ERROR (g_tls_error_quark ())
191 GQuark g_tls_error_quark (void);
194 * G_TLS_CHANNEL_BINDING_ERROR:
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
202 #define G_TLS_CHANNEL_BINDING_ERROR (g_tls_channel_binding_error_quark ())
203 GIO_AVAILABLE_IN_2_66
204 GQuark g_tls_channel_binding_error_quark (void);
208 gboolean g_tls_connection_emit_accept_certificate (GTlsConnection *conn,
209 GTlsCertificate *peer_cert,
210 GTlsCertificateFlags errors);
214 #endif /* __G_TLS_CONNECTION_H__ */