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 "gtlsserverconnection.h"
34 #include "gsimpleasyncresult.h"
36 #include "giomodule.h"
37 #include "giomodule-priv.h"
41 static GType _g_dummy_tls_certificate_get_type (void);
42 static GType _g_dummy_tls_connection_get_type (void);
44 struct _GDummyTlsBackend {
45 GObject parent_instance;
48 static void g_dummy_tls_backend_iface_init (GTlsBackendInterface *iface);
50 #define g_dummy_tls_backend_get_type _g_dummy_tls_backend_get_type
51 G_DEFINE_TYPE_WITH_CODE (GDummyTlsBackend, g_dummy_tls_backend, G_TYPE_OBJECT,
52 G_IMPLEMENT_INTERFACE (G_TYPE_TLS_BACKEND,
53 g_dummy_tls_backend_iface_init)
54 _g_io_modules_ensure_extension_points_registered ();
55 g_io_extension_point_implement (G_TLS_BACKEND_EXTENSION_POINT_NAME,
61 g_dummy_tls_backend_init (GDummyTlsBackend *backend)
66 g_dummy_tls_backend_class_init (GDummyTlsBackendClass *backend_class)
71 g_dummy_tls_backend_iface_init (GTlsBackendInterface *iface)
73 iface->get_certificate_type = _g_dummy_tls_certificate_get_type;
74 iface->get_client_connection_type = _g_dummy_tls_connection_get_type;
75 iface->get_server_connection_type = _g_dummy_tls_connection_get_type;
78 /* Dummy certificate type */
80 typedef struct _GDummyTlsCertificate GDummyTlsCertificate;
81 typedef struct _GDummyTlsCertificateClass GDummyTlsCertificateClass;
83 struct _GDummyTlsCertificate {
84 GTlsCertificate parent_instance;
87 struct _GDummyTlsCertificateClass {
88 GTlsCertificateClass parent_class;
95 PROP_CERT_CERTIFICATE,
96 PROP_CERT_CERTIFICATE_PEM,
97 PROP_CERT_PRIVATE_KEY,
98 PROP_CERT_PRIVATE_KEY_PEM,
102 static void g_dummy_tls_certificate_initable_iface_init (GInitableIface *iface);
104 #define g_dummy_tls_certificate_get_type _g_dummy_tls_certificate_get_type
105 G_DEFINE_TYPE_WITH_CODE (GDummyTlsCertificate, g_dummy_tls_certificate, G_TYPE_TLS_CERTIFICATE,
106 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
107 g_dummy_tls_certificate_initable_iface_init);)
110 g_dummy_tls_certificate_get_property (GObject *object,
115 /* We need to define this method to make GObject happy, but it will
116 * never be possible to construct a working GDummyTlsCertificate, so
117 * it doesn't have to do anything useful.
122 g_dummy_tls_certificate_set_property (GObject *object,
127 /* Just ignore all attempts to set properties. */
131 g_dummy_tls_certificate_class_init (GDummyTlsCertificateClass *certificate_class)
133 GObjectClass *gobject_class = G_OBJECT_CLASS (certificate_class);
135 gobject_class->get_property = g_dummy_tls_certificate_get_property;
136 gobject_class->set_property = g_dummy_tls_certificate_set_property;
138 g_object_class_override_property (gobject_class, PROP_CERT_CERTIFICATE, "certificate");
139 g_object_class_override_property (gobject_class, PROP_CERT_CERTIFICATE_PEM, "certificate-pem");
140 g_object_class_override_property (gobject_class, PROP_CERT_PRIVATE_KEY, "private-key");
141 g_object_class_override_property (gobject_class, PROP_CERT_PRIVATE_KEY_PEM, "private-key-pem");
142 g_object_class_override_property (gobject_class, PROP_CERT_ISSUER, "issuer");
146 g_dummy_tls_certificate_init (GDummyTlsCertificate *certificate)
151 g_dummy_tls_certificate_initable_init (GInitable *initable,
152 GCancellable *cancellable,
155 g_set_error_literal (error, G_TLS_ERROR, G_TLS_ERROR_UNAVAILABLE,
156 _("TLS support is not available"));
161 g_dummy_tls_certificate_initable_iface_init (GInitableIface *iface)
163 iface->init = g_dummy_tls_certificate_initable_init;
166 /* Dummy connection type; since GTlsClientConnection and
167 * GTlsServerConnection are just interfaces, we can implement them
168 * both on a single object.
171 typedef struct _GDummyTlsConnection GDummyTlsConnection;
172 typedef struct _GDummyTlsConnectionClass GDummyTlsConnectionClass;
174 struct _GDummyTlsConnection {
175 GTlsConnection parent_instance;
178 struct _GDummyTlsConnectionClass {
179 GTlsConnectionClass parent_class;
186 PROP_CONN_BASE_IO_STREAM,
187 PROP_CONN_USE_SYSTEM_CERTDB,
188 PROP_CONN_REQUIRE_CLOSE_NOTIFY,
189 PROP_CONN_REHANDSHAKE_MODE,
190 PROP_CONN_CERTIFICATE,
191 PROP_CONN_PEER_CERTIFICATE,
192 PROP_CONN_PEER_CERTIFICATE_ERRORS,
193 PROP_CONN_VALIDATION_FLAGS,
194 PROP_CONN_SERVER_IDENTITY,
196 PROP_CONN_ACCEPTED_CAS,
197 PROP_CONN_AUTHENTICATION_MODE
200 static void g_dummy_tls_connection_initable_iface_init (GInitableIface *iface);
202 #define g_dummy_tls_connection_get_type _g_dummy_tls_connection_get_type
203 G_DEFINE_TYPE_WITH_CODE (GDummyTlsConnection, g_dummy_tls_connection, G_TYPE_TLS_CONNECTION,
204 G_IMPLEMENT_INTERFACE (G_TYPE_TLS_CLIENT_CONNECTION, NULL);
205 G_IMPLEMENT_INTERFACE (G_TYPE_TLS_SERVER_CONNECTION, NULL);
206 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
207 g_dummy_tls_connection_initable_iface_init);)
210 g_dummy_tls_connection_get_property (GObject *object,
218 g_dummy_tls_connection_set_property (GObject *object,
226 g_dummy_tls_connection_close (GIOStream *stream,
227 GCancellable *cancellable,
234 g_dummy_tls_connection_class_init (GDummyTlsConnectionClass *connection_class)
236 GObjectClass *gobject_class = G_OBJECT_CLASS (connection_class);
237 GIOStreamClass *io_stream_class = G_IO_STREAM_CLASS (connection_class);
239 gobject_class->get_property = g_dummy_tls_connection_get_property;
240 gobject_class->set_property = g_dummy_tls_connection_set_property;
242 /* Need to override this because when initable_init fails it will
243 * dispose the connection, which will close it, which would
244 * otherwise try to close its input/output streams, which don't
247 io_stream_class->close_fn = g_dummy_tls_connection_close;
249 g_object_class_override_property (gobject_class, PROP_CONN_BASE_IO_STREAM, "base-io-stream");
250 g_object_class_override_property (gobject_class, PROP_CONN_USE_SYSTEM_CERTDB, "use-system-certdb");
251 g_object_class_override_property (gobject_class, PROP_CONN_REQUIRE_CLOSE_NOTIFY, "require-close-notify");
252 g_object_class_override_property (gobject_class, PROP_CONN_REHANDSHAKE_MODE, "rehandshake-mode");
253 g_object_class_override_property (gobject_class, PROP_CONN_CERTIFICATE, "certificate");
254 g_object_class_override_property (gobject_class, PROP_CONN_PEER_CERTIFICATE, "peer-certificate");
255 g_object_class_override_property (gobject_class, PROP_CONN_PEER_CERTIFICATE_ERRORS, "peer-certificate-errors");
256 g_object_class_override_property (gobject_class, PROP_CONN_VALIDATION_FLAGS, "validation-flags");
257 g_object_class_override_property (gobject_class, PROP_CONN_SERVER_IDENTITY, "server-identity");
258 g_object_class_override_property (gobject_class, PROP_CONN_USE_SSL3, "use-ssl3");
259 g_object_class_override_property (gobject_class, PROP_CONN_ACCEPTED_CAS, "accepted-cas");
260 g_object_class_override_property (gobject_class, PROP_CONN_AUTHENTICATION_MODE, "authentication-mode");
264 g_dummy_tls_connection_init (GDummyTlsConnection *connection)
269 g_dummy_tls_connection_initable_init (GInitable *initable,
270 GCancellable *cancellable,
273 g_set_error_literal (error, G_TLS_ERROR, G_TLS_ERROR_UNAVAILABLE,
274 _("TLS support is not available"));
279 g_dummy_tls_connection_initable_iface_init (GInitableIface *iface)
281 iface->init = g_dummy_tls_connection_initable_init;