2
* tls-certificate.c - Source for IdleTLSCertificate
3
* Copyright (C) 2010 Collabora Ltd.
4
* @author Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
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.1 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 Public
17
* License along with this library; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include "tls-certificate.h"
24
#include <telepathy-glib/telepathy-glib.h>
25
#include <telepathy-glib/telepathy-glib-dbus.h>
27
#define IDLE_DEBUG_FLAG IDLE_DEBUG_TLS
28
#include "idle-debug.h"
31
tls_certificate_iface_init (gpointer g_iface, gpointer iface_data);
33
G_DEFINE_TYPE_WITH_CODE (IdleTLSCertificate,
36
G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_AUTHENTICATION_TLS_CERTIFICATE,
37
tls_certificate_iface_init);
38
G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES,
39
tp_dbus_properties_mixin_iface_init);)
41
struct _IdleTLSCertificatePrivate {
45
TpTLSCertificateState cert_state;
47
GPtrArray *rejections;
52
gboolean dispose_has_run;
59
PROP_CERTIFICATE_TYPE,
60
PROP_CERTIFICATE_CHAIN_DATA,
69
idle_tls_certificate_get_property (GObject *object,
74
IdleTLSCertificate *self = IDLE_TLS_CERTIFICATE (object);
78
case PROP_OBJECT_PATH:
79
g_value_set_string (value, self->priv->object_path);
82
g_value_set_uint (value, self->priv->cert_state);
85
g_value_set_boxed (value, self->priv->rejections);
87
case PROP_CERTIFICATE_TYPE:
88
g_value_set_string (value, self->priv->cert_type);
90
case PROP_CERTIFICATE_CHAIN_DATA:
91
g_value_set_boxed (value, self->priv->cert_data);
94
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
100
idle_tls_certificate_set_property (GObject *object,
105
IdleTLSCertificate *self = IDLE_TLS_CERTIFICATE (object);
109
case PROP_OBJECT_PATH:
110
self->priv->object_path = g_value_dup_string (value);
112
case PROP_CERTIFICATE_TYPE:
113
self->priv->cert_type = g_value_dup_string (value);
115
case PROP_CERTIFICATE_CHAIN_DATA:
116
self->priv->cert_data = g_value_dup_boxed (value);
118
case PROP_DBUS_DAEMON:
119
self->priv->daemon = g_value_dup_object (value);
122
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, value);
128
idle_tls_certificate_finalize (GObject *object)
130
IdleTLSCertificate *self = IDLE_TLS_CERTIFICATE (object);
132
tp_clear_boxed (TP_ARRAY_TYPE_TLS_CERTIFICATE_REJECTION_LIST,
133
&self->priv->rejections);
135
g_free (self->priv->object_path);
136
g_free (self->priv->cert_type);
137
g_ptr_array_unref (self->priv->cert_data);
139
G_OBJECT_CLASS (idle_tls_certificate_parent_class)->finalize (object);
143
idle_tls_certificate_dispose (GObject *object)
145
IdleTLSCertificate *self = IDLE_TLS_CERTIFICATE (object);
147
if (self->priv->dispose_has_run)
150
self->priv->dispose_has_run = TRUE;
152
tp_clear_object (&self->priv->daemon);
154
G_OBJECT_CLASS (idle_tls_certificate_parent_class)->dispose (object);
158
idle_tls_certificate_constructed (GObject *object)
160
IdleTLSCertificate *self = IDLE_TLS_CERTIFICATE (object);
161
void (*chain_up) (GObject *) =
162
G_OBJECT_CLASS (idle_tls_certificate_parent_class)->constructed;
164
if (chain_up != NULL)
167
/* register the certificate on the bus */
168
tp_dbus_daemon_register_object (self->priv->daemon,
169
self->priv->object_path, self);
173
idle_tls_certificate_init (IdleTLSCertificate *self)
175
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
176
IDLE_TYPE_TLS_CERTIFICATE, IdleTLSCertificatePrivate);
177
self->priv->rejections = g_ptr_array_new ();
181
idle_tls_certificate_class_init (IdleTLSCertificateClass *klass)
183
static TpDBusPropertiesMixinPropImpl object_props[] = {
184
{ "State", "state", NULL },
185
{ "Rejections", "rejections", NULL },
186
{ "CertificateType", "certificate-type", NULL },
187
{ "CertificateChainData", "certificate-chain-data", NULL },
190
static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = {
191
{ TP_IFACE_AUTHENTICATION_TLS_CERTIFICATE,
192
tp_dbus_properties_mixin_getter_gobject_properties,
198
GObjectClass *oclass = G_OBJECT_CLASS (klass);
201
g_type_class_add_private (klass, sizeof (IdleTLSCertificatePrivate));
203
oclass->finalize = idle_tls_certificate_finalize;
204
oclass->dispose = idle_tls_certificate_dispose;
205
oclass->set_property = idle_tls_certificate_set_property;
206
oclass->get_property = idle_tls_certificate_get_property;
207
oclass->constructed = idle_tls_certificate_constructed;
209
pspec = g_param_spec_string ("object-path",
211
"The D-Bus object path used for this object on the bus.",
213
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
214
g_object_class_install_property (oclass, PROP_OBJECT_PATH, pspec);
216
pspec = g_param_spec_uint ("state",
217
"State of this certificate",
218
"The state of this TLS certificate.",
219
0, NUM_TP_TLS_CERTIFICATE_STATES - 1,
220
TP_TLS_CERTIFICATE_STATE_PENDING,
221
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
222
g_object_class_install_property (oclass, PROP_STATE, pspec);
224
pspec = g_param_spec_boxed ("rejections",
225
"The reject reasons",
226
"The reasons why this TLS certificate has been rejected",
227
TP_ARRAY_TYPE_TLS_CERTIFICATE_REJECTION_LIST,
228
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
229
g_object_class_install_property (oclass, PROP_REJECTIONS, pspec);
231
pspec = g_param_spec_string ("certificate-type",
232
"The certificate type",
233
"The type of this certificate.",
235
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
236
g_object_class_install_property (oclass, PROP_CERTIFICATE_TYPE, pspec);
238
pspec = g_param_spec_boxed ("certificate-chain-data",
239
"The certificate chain data",
240
"The raw PEM-encoded trust chain of this certificate.",
241
TP_ARRAY_TYPE_UCHAR_ARRAY_LIST,
242
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
243
g_object_class_install_property (oclass, PROP_CERTIFICATE_CHAIN_DATA, pspec);
245
pspec = g_param_spec_object ("dbus-daemon",
246
"The DBus daemon connection",
247
"The connection to the DBus daemon owning the CM",
249
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
250
g_object_class_install_property (oclass, PROP_DBUS_DAEMON, pspec);
252
klass->dbus_props_class.interfaces = prop_interfaces;
253
tp_dbus_properties_mixin_class_init (oclass,
254
G_STRUCT_OFFSET (IdleTLSCertificateClass, dbus_props_class));
258
idle_tls_certificate_accept (TpSvcAuthenticationTLSCertificate *cert,
259
DBusGMethodInvocation *context)
261
IdleTLSCertificate *self = IDLE_TLS_CERTIFICATE (cert);
263
IDLE_DEBUG ("Accept() called on the TLS certificate; current state %u",
264
self->priv->cert_state);
266
if (self->priv->cert_state != TP_TLS_CERTIFICATE_STATE_PENDING)
270
TP_ERROR_INVALID_ARGUMENT,
271
"Calling Accept() on a certificate with state != PENDING "
272
"doesn't make sense."
275
dbus_g_method_return_error (context, &error);
279
self->priv->cert_state = TP_TLS_CERTIFICATE_STATE_ACCEPTED;
280
tp_svc_authentication_tls_certificate_emit_accepted (self);
282
tp_svc_authentication_tls_certificate_return_from_accept (context);
286
idle_tls_certificate_reject (TpSvcAuthenticationTLSCertificate *cert,
287
const GPtrArray *rejections,
288
DBusGMethodInvocation *context)
290
IdleTLSCertificate *self = IDLE_TLS_CERTIFICATE (cert);
292
IDLE_DEBUG ("Reject() called on the TLS certificate with rejections %p, "
293
"length %u; current state %u", rejections, rejections->len,
294
self->priv->cert_state);
296
if (rejections->len < 1)
298
GError error = { TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
299
"Calling Reject() with a zero-length rejection list." };
301
dbus_g_method_return_error (context, &error);
305
if (self->priv->cert_state != TP_TLS_CERTIFICATE_STATE_PENDING)
309
TP_ERROR_INVALID_ARGUMENT,
310
"Calling Reject() on a certificate with state != PENDING "
311
"doesn't make sense."
314
dbus_g_method_return_error (context, &error);
318
tp_clear_boxed (TP_ARRAY_TYPE_TLS_CERTIFICATE_REJECTION_LIST,
319
&self->priv->rejections);
321
self->priv->rejections =
322
g_boxed_copy (TP_ARRAY_TYPE_TLS_CERTIFICATE_REJECTION_LIST,
324
self->priv->cert_state = TP_TLS_CERTIFICATE_STATE_REJECTED;
326
tp_svc_authentication_tls_certificate_emit_rejected (
327
self, self->priv->rejections);
329
tp_svc_authentication_tls_certificate_return_from_reject (context);
333
tls_certificate_iface_init (gpointer g_iface,
336
TpSvcAuthenticationTLSCertificateClass *klass = g_iface;
338
#define IMPLEMENT(x) \
339
tp_svc_authentication_tls_certificate_implement_##x ( \
340
klass, idle_tls_certificate_##x)