gtestutils: Fix a typo in a documentation comment
[glib.git] / gio / gtlsbackend.c
bloba0a4b46b7d9057542b2e0f19002616e300b0399b
1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright © 2010 Red Hat, Inc
4 * Copyright © 2015 Collabora, Ltd.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 #include "config.h"
21 #include "glib.h"
23 #include "gtlsbackend.h"
24 #include "gdummytlsbackend.h"
25 #include "gioenumtypes.h"
26 #include "giomodule-priv.h"
28 /**
29 * SECTION:gtls
30 * @title: TLS Overview
31 * @short_description: TLS (aka SSL) support for GSocketConnection
32 * @include: gio/gio.h
34 * #GTlsConnection and related classes provide TLS (Transport Layer
35 * Security, previously known as SSL, Secure Sockets Layer) support for
36 * gio-based network streams.
38 * #GDtlsConnection and related classes provide DTLS (Datagram TLS) support for
39 * GIO-based network sockets, using the #GDatagramBased interface. The TLS and
40 * DTLS APIs are almost identical, except TLS is stream-based and DTLS is
41 * datagram-based. They share certificate and backend infrastructure.
43 * In the simplest case, for a client TLS connection, you can just set the
44 * #GSocketClient:tls flag on a #GSocketClient, and then any
45 * connections created by that client will have TLS negotiated
46 * automatically, using appropriate default settings, and rejecting
47 * any invalid or self-signed certificates (unless you change that
48 * default by setting the #GSocketClient:tls-validation-flags
49 * property). The returned object will be a #GTcpWrapperConnection,
50 * which wraps the underlying #GTlsClientConnection.
52 * For greater control, you can create your own #GTlsClientConnection,
53 * wrapping a #GSocketConnection (or an arbitrary #GIOStream with
54 * pollable input and output streams) and then connect to its signals,
55 * such as #GTlsConnection::accept-certificate, before starting the
56 * handshake.
58 * Server-side TLS is similar, using #GTlsServerConnection. At the
59 * moment, there is no support for automatically wrapping server-side
60 * connections in the way #GSocketClient does for client-side
61 * connections.
64 /**
65 * SECTION:gtlsbackend
66 * @title: GTlsBackend
67 * @short_description: TLS backend implementation
68 * @include: gio/gio.h
70 * TLS (Transport Layer Security, aka SSL) and DTLS backend.
72 * Since: 2.28
75 /**
76 * GTlsBackend:
78 * TLS (Transport Layer Security, aka SSL) and DTLS backend. This is an
79 * internal type used to coordinate the different classes implemented
80 * by a TLS backend.
82 * Since: 2.28
85 G_DEFINE_INTERFACE (GTlsBackend, g_tls_backend, G_TYPE_OBJECT);
87 static void
88 g_tls_backend_default_init (GTlsBackendInterface *iface)
92 /**
93 * g_tls_backend_get_default:
95 * Gets the default #GTlsBackend for the system.
97 * Returns: (transfer none): a #GTlsBackend
99 * Since: 2.28
101 GTlsBackend *
102 g_tls_backend_get_default (void)
104 return _g_io_module_get_default (G_TLS_BACKEND_EXTENSION_POINT_NAME,
105 "GIO_USE_TLS", NULL);
109 * g_tls_backend_supports_tls:
110 * @backend: the #GTlsBackend
112 * Checks if TLS is supported; if this returns %FALSE for the default
113 * #GTlsBackend, it means no "real" TLS backend is available.
115 * Returns: whether or not TLS is supported
117 * Since: 2.28
119 gboolean
120 g_tls_backend_supports_tls (GTlsBackend *backend)
122 if (G_TLS_BACKEND_GET_INTERFACE (backend)->supports_tls)
123 return G_TLS_BACKEND_GET_INTERFACE (backend)->supports_tls (backend);
124 else if (G_IS_DUMMY_TLS_BACKEND (backend))
125 return FALSE;
126 else
127 return TRUE;
131 * g_tls_backend_supports_dtls:
132 * @backend: the #GTlsBackend
134 * Checks if DTLS is supported. DTLS support may not be available even if TLS
135 * support is available, and vice-versa.
137 * Returns: whether DTLS is supported
139 * Since: 2.48
141 gboolean
142 g_tls_backend_supports_dtls (GTlsBackend *backend)
144 if (G_TLS_BACKEND_GET_INTERFACE (backend)->supports_dtls)
145 return G_TLS_BACKEND_GET_INTERFACE (backend)->supports_dtls (backend);
146 else if (G_IS_DUMMY_TLS_BACKEND (backend))
147 return FALSE;
148 else
149 return TRUE;
153 * g_tls_backend_get_default_database:
154 * @backend: the #GTlsBackend
156 * Gets the default #GTlsDatabase used to verify TLS connections.
158 * Returns: (transfer full): the default database, which should be
159 * unreffed when done.
161 * Since: 2.30
163 GTlsDatabase *
164 g_tls_backend_get_default_database (GTlsBackend *backend)
166 g_return_val_if_fail (G_IS_TLS_BACKEND (backend), NULL);
168 /* This method was added later, so accept the (remote) possibility it can be NULL */
169 if (!G_TLS_BACKEND_GET_INTERFACE (backend)->get_default_database)
170 return NULL;
172 return G_TLS_BACKEND_GET_INTERFACE (backend)->get_default_database (backend);
176 * g_tls_backend_get_certificate_type:
177 * @backend: the #GTlsBackend
179 * Gets the #GType of @backend's #GTlsCertificate implementation.
181 * Returns: the #GType of @backend's #GTlsCertificate
182 * implementation.
184 * Since: 2.28
186 GType
187 g_tls_backend_get_certificate_type (GTlsBackend *backend)
189 return G_TLS_BACKEND_GET_INTERFACE (backend)->get_certificate_type ();
193 * g_tls_backend_get_client_connection_type:
194 * @backend: the #GTlsBackend
196 * Gets the #GType of @backend's #GTlsClientConnection implementation.
198 * Returns: the #GType of @backend's #GTlsClientConnection
199 * implementation.
201 * Since: 2.28
203 GType
204 g_tls_backend_get_client_connection_type (GTlsBackend *backend)
206 return G_TLS_BACKEND_GET_INTERFACE (backend)->get_client_connection_type ();
210 * g_tls_backend_get_server_connection_type:
211 * @backend: the #GTlsBackend
213 * Gets the #GType of @backend's #GTlsServerConnection implementation.
215 * Returns: the #GType of @backend's #GTlsServerConnection
216 * implementation.
218 * Since: 2.28
220 GType
221 g_tls_backend_get_server_connection_type (GTlsBackend *backend)
223 return G_TLS_BACKEND_GET_INTERFACE (backend)->get_server_connection_type ();
227 * g_tls_backend_get_dtls_client_connection_type:
228 * @backend: the #GTlsBackend
230 * Gets the #GType of @backend’s #GDtlsClientConnection implementation.
232 * Returns: the #GType of @backend’s #GDtlsClientConnection
233 * implementation.
235 * Since: 2.48
237 GType
238 g_tls_backend_get_dtls_client_connection_type (GTlsBackend *backend)
240 return G_TLS_BACKEND_GET_INTERFACE (backend)->get_dtls_client_connection_type ();
244 * g_tls_backend_get_dtls_server_connection_type:
245 * @backend: the #GTlsBackend
247 * Gets the #GType of @backend’s #GDtlsServerConnection implementation.
249 * Returns: the #GType of @backend’s #GDtlsServerConnection
250 * implementation.
252 * Since: 2.48
254 GType
255 g_tls_backend_get_dtls_server_connection_type (GTlsBackend *backend)
257 return G_TLS_BACKEND_GET_INTERFACE (backend)->get_dtls_server_connection_type ();
261 * g_tls_backend_get_file_database_type:
262 * @backend: the #GTlsBackend
264 * Gets the #GType of @backend's #GTlsFileDatabase implementation.
266 * Returns: the #GType of backend's #GTlsFileDatabase implementation.
268 * Since: 2.30
270 GType
271 g_tls_backend_get_file_database_type (GTlsBackend *backend)
273 g_return_val_if_fail (G_IS_TLS_BACKEND (backend), 0);
275 /* This method was added later, so accept the (remote) possibility it can be NULL */
276 if (!G_TLS_BACKEND_GET_INTERFACE (backend)->get_file_database_type)
277 return 0;
279 return G_TLS_BACKEND_GET_INTERFACE (backend)->get_file_database_type ();