1/* GIO - GLib Input, Output and Streaming Library
2 *
3 * Copyright (C) 2010 Red Hat, Inc.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef __G_TLS_CONNECTION_H__
20#define __G_TLS_CONNECTION_H__
21
22#if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
23#error "Only <gio/gio.h> can be included directly."
24#endif
25
26#include <gio/giostream.h>
27
28G_BEGIN_DECLS
29
30#define G_TYPE_TLS_CONNECTION (g_tls_connection_get_type ())
31#define G_TLS_CONNECTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), G_TYPE_TLS_CONNECTION, GTlsConnection))
32#define G_TLS_CONNECTION_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_TLS_CONNECTION, GTlsConnectionClass))
33#define G_IS_TLS_CONNECTION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), G_TYPE_TLS_CONNECTION))
34#define G_IS_TLS_CONNECTION_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_TLS_CONNECTION))
35#define G_TLS_CONNECTION_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), G_TYPE_TLS_CONNECTION, GTlsConnectionClass))
36
37typedef struct _GTlsConnectionClass GTlsConnectionClass;
38typedef struct _GTlsConnectionPrivate GTlsConnectionPrivate;
39
40struct _GTlsConnection {
41 GIOStream parent_instance;
42
43 GTlsConnectionPrivate *priv;
44};
45
46struct _GTlsConnectionClass
47{
48 GIOStreamClass parent_class;
49
50 /* signals */
51 gboolean ( *accept_certificate) (GTlsConnection *connection,
52 GTlsCertificate *peer_cert,
53 GTlsCertificateFlags errors);
54
55 /* methods */
56 gboolean ( *handshake ) (GTlsConnection *conn,
57 GCancellable *cancellable,
58 GError **error);
59
60 void ( *handshake_async ) (GTlsConnection *conn,
61 int io_priority,
62 GCancellable *cancellable,
63 GAsyncReadyCallback callback,
64 gpointer user_data);
65 gboolean ( *handshake_finish ) (GTlsConnection *conn,
66 GAsyncResult *result,
67 GError **error);
68
69 /*< private >*/
70 /* Padding for future expansion */
71 gpointer padding[8];
72};
73
74GLIB_AVAILABLE_IN_ALL
75GType g_tls_connection_get_type (void) G_GNUC_CONST;
76
77GLIB_DEPRECATED
78void g_tls_connection_set_use_system_certdb (GTlsConnection *conn,
79 gboolean use_system_certdb);
80GLIB_DEPRECATED
81gboolean g_tls_connection_get_use_system_certdb (GTlsConnection *conn);
82
83GLIB_AVAILABLE_IN_ALL
84void g_tls_connection_set_database (GTlsConnection *conn,
85 GTlsDatabase *database);
86GLIB_AVAILABLE_IN_ALL
87GTlsDatabase * g_tls_connection_get_database (GTlsConnection *conn);
88
89GLIB_AVAILABLE_IN_ALL
90void g_tls_connection_set_certificate (GTlsConnection *conn,
91 GTlsCertificate *certificate);
92GLIB_AVAILABLE_IN_ALL
93GTlsCertificate *g_tls_connection_get_certificate (GTlsConnection *conn);
94
95GLIB_AVAILABLE_IN_ALL
96void g_tls_connection_set_interaction (GTlsConnection *conn,
97 GTlsInteraction *interaction);
98GLIB_AVAILABLE_IN_ALL
99GTlsInteraction * g_tls_connection_get_interaction (GTlsConnection *conn);
100
101GLIB_AVAILABLE_IN_ALL
102GTlsCertificate *g_tls_connection_get_peer_certificate (GTlsConnection *conn);
103GLIB_AVAILABLE_IN_ALL
104GTlsCertificateFlags g_tls_connection_get_peer_certificate_errors (GTlsConnection *conn);
105
106GLIB_AVAILABLE_IN_ALL
107void g_tls_connection_set_require_close_notify (GTlsConnection *conn,
108 gboolean require_close_notify);
109GLIB_AVAILABLE_IN_ALL
110gboolean g_tls_connection_get_require_close_notify (GTlsConnection *conn);
111
112G_GNUC_BEGIN_IGNORE_DEPRECATIONS
113GLIB_DEPRECATED_IN_2_60
114void g_tls_connection_set_rehandshake_mode (GTlsConnection *conn,
115 GTlsRehandshakeMode mode);
116GLIB_DEPRECATED_IN_2_60
117GTlsRehandshakeMode g_tls_connection_get_rehandshake_mode (GTlsConnection *conn);
118G_GNUC_END_IGNORE_DEPRECATIONS
119
120GLIB_AVAILABLE_IN_2_60
121void g_tls_connection_set_advertised_protocols (GTlsConnection *conn,
122 const gchar * const *protocols);
123
124GLIB_AVAILABLE_IN_2_60
125const gchar * g_tls_connection_get_negotiated_protocol (GTlsConnection *conn);
126
127GLIB_AVAILABLE_IN_ALL
128gboolean g_tls_connection_handshake (GTlsConnection *conn,
129 GCancellable *cancellable,
130 GError **error);
131
132GLIB_AVAILABLE_IN_ALL
133void g_tls_connection_handshake_async (GTlsConnection *conn,
134 int io_priority,
135 GCancellable *cancellable,
136 GAsyncReadyCallback callback,
137 gpointer user_data);
138GLIB_AVAILABLE_IN_ALL
139gboolean g_tls_connection_handshake_finish (GTlsConnection *conn,
140 GAsyncResult *result,
141 GError **error);
142
143/**
144 * G_TLS_ERROR:
145 *
146 * Error domain for TLS. Errors in this domain will be from the
147 * #GTlsError enumeration. See #GError for more information on error
148 * domains.
149 */
150#define G_TLS_ERROR (g_tls_error_quark ())
151GLIB_AVAILABLE_IN_ALL
152GQuark g_tls_error_quark (void);
153
154
155/*< protected >*/
156GLIB_AVAILABLE_IN_ALL
157gboolean g_tls_connection_emit_accept_certificate (GTlsConnection *conn,
158 GTlsCertificate *peer_cert,
159 GTlsCertificateFlags errors);
160
161G_END_DECLS
162
163#endif /* __G_TLS_CONNECTION_H__ */
164