1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2010 Red Hat, Inc.
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 of the License, or (at your option) any later version.
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.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
23 #include "gdummytlsbackend.h"
27 #include "gasyncresult.h"
28 #include "gcancellable.h"
29 #include "ginitable.h"
30 #include "gtlsbackend.h"
31 #include "gtlscertificate.h"
32 #include "gtlsclientconnection.h"
33 #include "gtlsdatabase.h"
34 #include "gtlsfiledatabase.h"
35 #include "gtlsserverconnection.h"
36 #include "gsimpleasyncresult.h"
38 #include "giomodule.h"
39 #include "giomodule-priv.h"
43 static GType _g_dummy_tls_certificate_get_type (void);
44 static GType _g_dummy_tls_connection_get_type (void);
45 static GType _g_dummy_tls_database_get_type (void);
47 struct _GDummyTlsBackend {
48 GObject parent_instance;
49 GTlsDatabase *database;
52 static void g_dummy_tls_backend_iface_init (GTlsBackendInterface *iface);
54 #define g_dummy_tls_backend_get_type _g_dummy_tls_backend_get_type
55 G_DEFINE_TYPE_WITH_CODE (GDummyTlsBackend, g_dummy_tls_backend, G_TYPE_OBJECT,
56 G_IMPLEMENT_INTERFACE (G_TYPE_TLS_BACKEND,
57 g_dummy_tls_backend_iface_init)
58 _g_io_modules_ensure_extension_points_registered ();
59 g_io_extension_point_implement (G_TLS_BACKEND_EXTENSION_POINT_NAME,
65 g_dummy_tls_backend_init (GDummyTlsBackend *backend)
70 g_dummy_tls_backend_class_init (GDummyTlsBackendClass *backend_class)
75 g_dummy_tls_backend_get_default_database (GTlsBackend *backend)
77 return g_object_new (_g_dummy_tls_database_get_type (), NULL);
81 g_dummy_tls_backend_iface_init (GTlsBackendInterface *iface)
83 iface->get_certificate_type = _g_dummy_tls_certificate_get_type;
84 iface->get_client_connection_type = _g_dummy_tls_connection_get_type;
85 iface->get_server_connection_type = _g_dummy_tls_connection_get_type;
86 iface->get_file_database_type = _g_dummy_tls_database_get_type;
87 iface->get_default_database = g_dummy_tls_backend_get_default_database;
90 /* Dummy certificate type */
92 typedef struct _GDummyTlsCertificate GDummyTlsCertificate;
93 typedef struct _GDummyTlsCertificateClass GDummyTlsCertificateClass;
95 struct _GDummyTlsCertificate {
96 GTlsCertificate parent_instance;
99 struct _GDummyTlsCertificateClass {
100 GTlsCertificateClass parent_class;
107 PROP_CERT_CERTIFICATE,
108 PROP_CERT_CERTIFICATE_PEM,
109 PROP_CERT_PRIVATE_KEY,
110 PROP_CERT_PRIVATE_KEY_PEM,
114 static void g_dummy_tls_certificate_initable_iface_init (GInitableIface *iface);
116 #define g_dummy_tls_certificate_get_type _g_dummy_tls_certificate_get_type
117 G_DEFINE_TYPE_WITH_CODE (GDummyTlsCertificate, g_dummy_tls_certificate, G_TYPE_TLS_CERTIFICATE,
118 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
119 g_dummy_tls_certificate_initable_iface_init);)
122 g_dummy_tls_certificate_get_property (GObject *object,
127 /* We need to define this method to make GObject happy, but it will
128 * never be possible to construct a working GDummyTlsCertificate, so
129 * it doesn't have to do anything useful.
134 g_dummy_tls_certificate_set_property (GObject *object,
139 /* Just ignore all attempts to set properties. */
143 g_dummy_tls_certificate_class_init (GDummyTlsCertificateClass *certificate_class)
145 GObjectClass *gobject_class = G_OBJECT_CLASS (certificate_class);
147 gobject_class->get_property = g_dummy_tls_certificate_get_property;
148 gobject_class->set_property = g_dummy_tls_certificate_set_property;
150 g_object_class_override_property (gobject_class, PROP_CERT_CERTIFICATE, "certificate");
151 g_object_class_override_property (gobject_class, PROP_CERT_CERTIFICATE_PEM, "certificate-pem");
152 g_object_class_override_property (gobject_class, PROP_CERT_PRIVATE_KEY, "private-key");
153 g_object_class_override_property (gobject_class, PROP_CERT_PRIVATE_KEY_PEM, "private-key-pem");
154 g_object_class_override_property (gobject_class, PROP_CERT_ISSUER, "issuer");
158 g_dummy_tls_certificate_init (GDummyTlsCertificate *certificate)
163 g_dummy_tls_certificate_initable_init (GInitable *initable,
164 GCancellable *cancellable,
167 g_set_error_literal (error, G_TLS_ERROR, G_TLS_ERROR_UNAVAILABLE,
168 _("TLS support is not available"));
173 g_dummy_tls_certificate_initable_iface_init (GInitableIface *iface)
175 iface->init = g_dummy_tls_certificate_initable_init;
178 /* Dummy connection type; since GTlsClientConnection and
179 * GTlsServerConnection are just interfaces, we can implement them
180 * both on a single object.
183 typedef struct _GDummyTlsConnection GDummyTlsConnection;
184 typedef struct _GDummyTlsConnectionClass GDummyTlsConnectionClass;
186 struct _GDummyTlsConnection {
187 GTlsConnection parent_instance;
190 struct _GDummyTlsConnectionClass {
191 GTlsConnectionClass parent_class;
198 PROP_CONN_BASE_IO_STREAM,
199 PROP_CONN_USE_SYSTEM_CERTDB,
200 PROP_CONN_REQUIRE_CLOSE_NOTIFY,
201 PROP_CONN_REHANDSHAKE_MODE,
202 PROP_CONN_CERTIFICATE,
204 PROP_CONN_PEER_CERTIFICATE,
205 PROP_CONN_PEER_CERTIFICATE_ERRORS,
206 PROP_CONN_VALIDATION_FLAGS,
207 PROP_CONN_SERVER_IDENTITY,
209 PROP_CONN_ACCEPTED_CAS,
210 PROP_CONN_AUTHENTICATION_MODE
213 static void g_dummy_tls_connection_initable_iface_init (GInitableIface *iface);
215 #define g_dummy_tls_connection_get_type _g_dummy_tls_connection_get_type
216 G_DEFINE_TYPE_WITH_CODE (GDummyTlsConnection, g_dummy_tls_connection, G_TYPE_TLS_CONNECTION,
217 G_IMPLEMENT_INTERFACE (G_TYPE_TLS_CLIENT_CONNECTION, NULL);
218 G_IMPLEMENT_INTERFACE (G_TYPE_TLS_SERVER_CONNECTION, NULL);
219 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
220 g_dummy_tls_connection_initable_iface_init);)
223 g_dummy_tls_connection_get_property (GObject *object,
231 g_dummy_tls_connection_set_property (GObject *object,
239 g_dummy_tls_connection_close (GIOStream *stream,
240 GCancellable *cancellable,
247 g_dummy_tls_connection_class_init (GDummyTlsConnectionClass *connection_class)
249 GObjectClass *gobject_class = G_OBJECT_CLASS (connection_class);
250 GIOStreamClass *io_stream_class = G_IO_STREAM_CLASS (connection_class);
252 gobject_class->get_property = g_dummy_tls_connection_get_property;
253 gobject_class->set_property = g_dummy_tls_connection_set_property;
255 /* Need to override this because when initable_init fails it will
256 * dispose the connection, which will close it, which would
257 * otherwise try to close its input/output streams, which don't
260 io_stream_class->close_fn = g_dummy_tls_connection_close;
262 g_object_class_override_property (gobject_class, PROP_CONN_BASE_IO_STREAM, "base-io-stream");
263 g_object_class_override_property (gobject_class, PROP_CONN_USE_SYSTEM_CERTDB, "use-system-certdb");
264 g_object_class_override_property (gobject_class, PROP_CONN_REQUIRE_CLOSE_NOTIFY, "require-close-notify");
265 g_object_class_override_property (gobject_class, PROP_CONN_REHANDSHAKE_MODE, "rehandshake-mode");
266 g_object_class_override_property (gobject_class, PROP_CONN_CERTIFICATE, "certificate");
267 g_object_class_override_property (gobject_class, PROP_CONN_DATABASE, "database");
268 g_object_class_override_property (gobject_class, PROP_CONN_PEER_CERTIFICATE, "peer-certificate");
269 g_object_class_override_property (gobject_class, PROP_CONN_PEER_CERTIFICATE_ERRORS, "peer-certificate-errors");
270 g_object_class_override_property (gobject_class, PROP_CONN_VALIDATION_FLAGS, "validation-flags");
271 g_object_class_override_property (gobject_class, PROP_CONN_SERVER_IDENTITY, "server-identity");
272 g_object_class_override_property (gobject_class, PROP_CONN_USE_SSL3, "use-ssl3");
273 g_object_class_override_property (gobject_class, PROP_CONN_ACCEPTED_CAS, "accepted-cas");
274 g_object_class_override_property (gobject_class, PROP_CONN_AUTHENTICATION_MODE, "authentication-mode");
278 g_dummy_tls_connection_init (GDummyTlsConnection *connection)
283 g_dummy_tls_connection_initable_init (GInitable *initable,
284 GCancellable *cancellable,
287 g_set_error_literal (error, G_TLS_ERROR, G_TLS_ERROR_UNAVAILABLE,
288 _("TLS support is not available"));
293 g_dummy_tls_connection_initable_iface_init (GInitableIface *iface)
295 iface->init = g_dummy_tls_connection_initable_init;
298 /* Dummy database type.
301 typedef struct _GDummyTlsDatabase GDummyTlsDatabase;
302 typedef struct _GDummyTlsDatabaseClass GDummyTlsDatabaseClass;
304 struct _GDummyTlsDatabase {
305 GTlsDatabase parent_instance;
308 struct _GDummyTlsDatabaseClass {
309 GTlsDatabaseClass parent_class;
319 static void g_dummy_tls_database_file_database_iface_init (GTlsFileDatabaseInterface *iface);
320 static void g_dummy_tls_database_initable_iface_init (GInitableIface *iface);
322 #define g_dummy_tls_database_get_type _g_dummy_tls_database_get_type
323 G_DEFINE_TYPE_WITH_CODE (GDummyTlsDatabase, g_dummy_tls_database, G_TYPE_TLS_DATABASE,
324 G_IMPLEMENT_INTERFACE (G_TYPE_TLS_FILE_DATABASE,
325 g_dummy_tls_database_file_database_iface_init);
326 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
327 g_dummy_tls_database_initable_iface_init);)
331 g_dummy_tls_database_get_property (GObject *object,
336 /* We need to define this method to make GObject happy, but it will
337 * never be possible to construct a working GDummyTlsDatabase, so
338 * it doesn't have to do anything useful.
343 g_dummy_tls_database_set_property (GObject *object,
348 /* Just ignore all attempts to set properties. */
352 g_dummy_tls_database_class_init (GDummyTlsDatabaseClass *database_class)
354 GObjectClass *gobject_class = G_OBJECT_CLASS (database_class);
356 gobject_class->get_property = g_dummy_tls_database_get_property;
357 gobject_class->set_property = g_dummy_tls_database_set_property;
359 g_object_class_override_property (gobject_class, PROP_ANCHORS, "anchors");
363 g_dummy_tls_database_init (GDummyTlsDatabase *database)
368 g_dummy_tls_database_file_database_iface_init (GTlsFileDatabaseInterface *iface)
373 g_dummy_tls_database_initable_init (GInitable *initable,
374 GCancellable *cancellable,
377 g_set_error_literal (error, G_TLS_ERROR, G_TLS_ERROR_UNAVAILABLE,
378 _("TLS support is not available"));
383 g_dummy_tls_database_initable_iface_init (GInitableIface *iface)
385 iface->init = g_dummy_tls_database_initable_init;