nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* GIO - GLib Input, Output and Streaming Library |
2 | * |
||
3 | * Copyright (C) 2011 Collabora Ltd. |
||
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 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 | #include "gtesttlsbackend.h" |
||
20 | |||
21 | #include <glib.h> |
||
22 | |||
23 | static GType _g_test_tls_certificate_get_type (void); |
||
24 | static GType _g_test_tls_connection_get_type (void); |
||
25 | |||
26 | struct _GTestTlsBackend { |
||
27 | GObject parent_instance; |
||
28 | }; |
||
29 | |||
30 | static void g_test_tls_backend_iface_init (GTlsBackendInterface *iface); |
||
31 | |||
32 | #define g_test_tls_backend_get_type _g_test_tls_backend_get_type |
||
33 | G_DEFINE_TYPE_WITH_CODE (GTestTlsBackend, g_test_tls_backend, G_TYPE_OBJECT, |
||
34 | G_IMPLEMENT_INTERFACE (G_TYPE_TLS_BACKEND, |
||
35 | g_test_tls_backend_iface_init) |
||
36 | g_io_extension_point_set_required_type ( |
||
37 | g_io_extension_point_register (G_TLS_BACKEND_EXTENSION_POINT_NAME), |
||
38 | G_TYPE_TLS_BACKEND); |
||
39 | g_io_extension_point_implement (G_TLS_BACKEND_EXTENSION_POINT_NAME, |
||
40 | g_define_type_id, |
||
41 | "test", |
||
42 | 999)) |
||
43 | |||
44 | static void |
||
45 | g_test_tls_backend_init (GTestTlsBackend *backend) |
||
46 | { |
||
47 | } |
||
48 | |||
49 | static void |
||
50 | g_test_tls_backend_class_init (GTestTlsBackendClass *backend_class) |
||
51 | { |
||
52 | } |
||
53 | |||
54 | static void |
||
55 | g_test_tls_backend_iface_init (GTlsBackendInterface *iface) |
||
56 | { |
||
57 | iface->get_certificate_type = _g_test_tls_certificate_get_type; |
||
58 | iface->get_client_connection_type = _g_test_tls_connection_get_type; |
||
59 | iface->get_server_connection_type = _g_test_tls_connection_get_type; |
||
60 | } |
||
61 | |||
62 | /* Test certificate type */ |
||
63 | |||
64 | typedef struct _GTestTlsCertificate GTestTlsCertificate; |
||
65 | typedef struct _GTestTlsCertificateClass GTestTlsCertificateClass; |
||
66 | |||
67 | struct _GTestTlsCertificate { |
||
68 | GTlsCertificate parent_instance; |
||
69 | gchar *key_pem; |
||
70 | gchar *cert_pem; |
||
71 | GTlsCertificate *issuer; |
||
72 | }; |
||
73 | |||
74 | struct _GTestTlsCertificateClass { |
||
75 | GTlsCertificateClass parent_class; |
||
76 | }; |
||
77 | |||
78 | enum |
||
79 | { |
||
80 | PROP_CERTIFICATE_0, |
||
81 | |||
82 | PROP_CERT_CERTIFICATE, |
||
83 | PROP_CERT_CERTIFICATE_PEM, |
||
84 | PROP_CERT_PRIVATE_KEY, |
||
85 | PROP_CERT_PRIVATE_KEY_PEM, |
||
86 | PROP_CERT_ISSUER |
||
87 | }; |
||
88 | |||
89 | static void g_test_tls_certificate_initable_iface_init (GInitableIface *iface); |
||
90 | |||
91 | #define g_test_tls_certificate_get_type _g_test_tls_certificate_get_type |
||
92 | G_DEFINE_TYPE_WITH_CODE (GTestTlsCertificate, g_test_tls_certificate, G_TYPE_TLS_CERTIFICATE, |
||
93 | G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, |
||
94 | g_test_tls_certificate_initable_iface_init);) |
||
95 | |||
96 | static GTlsCertificateFlags |
||
97 | g_test_tls_certificate_verify (GTlsCertificate *cert, |
||
98 | GSocketConnectable *identity, |
||
99 | GTlsCertificate *trusted_ca) |
||
100 | { |
||
101 | /* For now, all of the tests expect the certificate to verify */ |
||
102 | return 0; |
||
103 | } |
||
104 | |||
105 | static void |
||
106 | g_test_tls_certificate_get_property (GObject *object, |
||
107 | guint prop_id, |
||
108 | GValue *value, |
||
109 | GParamSpec *pspec) |
||
110 | { |
||
111 | GTestTlsCertificate *cert = (GTestTlsCertificate *) object; |
||
112 | |||
113 | switch (prop_id) |
||
114 | { |
||
115 | case PROP_CERT_CERTIFICATE_PEM: |
||
116 | g_value_set_string (value, cert->cert_pem); |
||
117 | break; |
||
118 | case PROP_CERT_PRIVATE_KEY_PEM: |
||
119 | g_value_set_string (value, cert->key_pem); |
||
120 | break; |
||
121 | case PROP_CERT_ISSUER: |
||
122 | g_value_set_object (value, cert->issuer); |
||
123 | break; |
||
124 | default: |
||
125 | g_assert_not_reached (); |
||
126 | break; |
||
127 | } |
||
128 | } |
||
129 | |||
130 | static void |
||
131 | g_test_tls_certificate_set_property (GObject *object, |
||
132 | guint prop_id, |
||
133 | const GValue *value, |
||
134 | GParamSpec *pspec) |
||
135 | { |
||
136 | GTestTlsCertificate *cert = (GTestTlsCertificate *) object; |
||
137 | |||
138 | switch (prop_id) |
||
139 | { |
||
140 | case PROP_CERT_CERTIFICATE_PEM: |
||
141 | cert->cert_pem = g_value_dup_string (value); |
||
142 | break; |
||
143 | case PROP_CERT_PRIVATE_KEY_PEM: |
||
144 | cert->key_pem = g_value_dup_string (value); |
||
145 | break; |
||
146 | case PROP_CERT_ISSUER: |
||
147 | cert->issuer = g_value_dup_object (value); |
||
148 | break; |
||
149 | case PROP_CERT_CERTIFICATE: |
||
150 | case PROP_CERT_PRIVATE_KEY: |
||
151 | /* ignore */ |
||
152 | break; |
||
153 | default: |
||
154 | g_assert_not_reached (); |
||
155 | break; |
||
156 | } |
||
157 | } |
||
158 | |||
159 | static void |
||
160 | g_test_tls_certificate_finalize (GObject *object) |
||
161 | { |
||
162 | GTestTlsCertificate *cert = (GTestTlsCertificate *) object; |
||
163 | |||
164 | g_free (cert->cert_pem); |
||
165 | g_free (cert->key_pem); |
||
166 | g_clear_object (&cert->issuer); |
||
167 | } |
||
168 | |||
169 | static void |
||
170 | g_test_tls_certificate_class_init (GTestTlsCertificateClass *test_class) |
||
171 | { |
||
172 | GObjectClass *gobject_class = G_OBJECT_CLASS (test_class); |
||
173 | GTlsCertificateClass *certificate_class = G_TLS_CERTIFICATE_CLASS (test_class); |
||
174 | |||
175 | gobject_class->get_property = g_test_tls_certificate_get_property; |
||
176 | gobject_class->set_property = g_test_tls_certificate_set_property; |
||
177 | gobject_class->finalize = g_test_tls_certificate_finalize; |
||
178 | |||
179 | certificate_class->verify = g_test_tls_certificate_verify; |
||
180 | |||
181 | g_object_class_override_property (gobject_class, PROP_CERT_CERTIFICATE, "certificate"); |
||
182 | g_object_class_override_property (gobject_class, PROP_CERT_CERTIFICATE_PEM, "certificate-pem"); |
||
183 | g_object_class_override_property (gobject_class, PROP_CERT_PRIVATE_KEY, "private-key"); |
||
184 | g_object_class_override_property (gobject_class, PROP_CERT_PRIVATE_KEY_PEM, "private-key-pem"); |
||
185 | g_object_class_override_property (gobject_class, PROP_CERT_ISSUER, "issuer"); |
||
186 | } |
||
187 | |||
188 | static void |
||
189 | g_test_tls_certificate_init (GTestTlsCertificate *certificate) |
||
190 | { |
||
191 | } |
||
192 | |||
193 | static gboolean |
||
194 | g_test_tls_certificate_initable_init (GInitable *initable, |
||
195 | GCancellable *cancellable, |
||
196 | GError **error) |
||
197 | { |
||
198 | return TRUE; |
||
199 | } |
||
200 | |||
201 | static void |
||
202 | g_test_tls_certificate_initable_iface_init (GInitableIface *iface) |
||
203 | { |
||
204 | iface->init = g_test_tls_certificate_initable_init; |
||
205 | } |
||
206 | |||
207 | /* Dummy connection type; since GTlsClientConnection and |
||
208 | * GTlsServerConnection are just interfaces, we can implement them |
||
209 | * both on a single object. |
||
210 | */ |
||
211 | |||
212 | typedef struct _GTestTlsConnection GTestTlsConnection; |
||
213 | typedef struct _GTestTlsConnectionClass GTestTlsConnectionClass; |
||
214 | |||
215 | struct _GTestTlsConnection { |
||
216 | GTlsConnection parent_instance; |
||
217 | }; |
||
218 | |||
219 | struct _GTestTlsConnectionClass { |
||
220 | GTlsConnectionClass parent_class; |
||
221 | }; |
||
222 | |||
223 | enum |
||
224 | { |
||
225 | PROP_CONNECTION_0, |
||
226 | |||
227 | PROP_CONN_BASE_IO_STREAM, |
||
228 | PROP_CONN_USE_SYSTEM_CERTDB, |
||
229 | PROP_CONN_REQUIRE_CLOSE_NOTIFY, |
||
230 | PROP_CONN_REHANDSHAKE_MODE, |
||
231 | PROP_CONN_CERTIFICATE, |
||
232 | PROP_CONN_PEER_CERTIFICATE, |
||
233 | PROP_CONN_PEER_CERTIFICATE_ERRORS, |
||
234 | PROP_CONN_VALIDATION_FLAGS, |
||
235 | PROP_CONN_SERVER_IDENTITY, |
||
236 | PROP_CONN_USE_SSL3, |
||
237 | PROP_CONN_ACCEPTED_CAS, |
||
238 | PROP_CONN_AUTHENTICATION_MODE |
||
239 | }; |
||
240 | |||
241 | static void g_test_tls_connection_initable_iface_init (GInitableIface *iface); |
||
242 | |||
243 | #define g_test_tls_connection_get_type _g_test_tls_connection_get_type |
||
244 | G_DEFINE_TYPE_WITH_CODE (GTestTlsConnection, g_test_tls_connection, G_TYPE_TLS_CONNECTION, |
||
245 | G_IMPLEMENT_INTERFACE (G_TYPE_TLS_CLIENT_CONNECTION, NULL); |
||
246 | G_IMPLEMENT_INTERFACE (G_TYPE_TLS_SERVER_CONNECTION, NULL); |
||
247 | G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, |
||
248 | g_test_tls_connection_initable_iface_init);) |
||
249 | |||
250 | static void |
||
251 | g_test_tls_connection_get_property (GObject *object, |
||
252 | guint prop_id, |
||
253 | GValue *value, |
||
254 | GParamSpec *pspec) |
||
255 | { |
||
256 | } |
||
257 | |||
258 | static void |
||
259 | g_test_tls_connection_set_property (GObject *object, |
||
260 | guint prop_id, |
||
261 | const GValue *value, |
||
262 | GParamSpec *pspec) |
||
263 | { |
||
264 | } |
||
265 | |||
266 | static gboolean |
||
267 | g_test_tls_connection_close (GIOStream *stream, |
||
268 | GCancellable *cancellable, |
||
269 | GError **error) |
||
270 | { |
||
271 | return TRUE; |
||
272 | } |
||
273 | |||
274 | static void |
||
275 | g_test_tls_connection_class_init (GTestTlsConnectionClass *connection_class) |
||
276 | { |
||
277 | GObjectClass *gobject_class = G_OBJECT_CLASS (connection_class); |
||
278 | GIOStreamClass *io_stream_class = G_IO_STREAM_CLASS (connection_class); |
||
279 | |||
280 | gobject_class->get_property = g_test_tls_connection_get_property; |
||
281 | gobject_class->set_property = g_test_tls_connection_set_property; |
||
282 | |||
283 | /* Need to override this because when initable_init fails it will |
||
284 | * dispose the connection, which will close it, which would |
||
285 | * otherwise try to close its input/output streams, which don't |
||
286 | * exist. |
||
287 | */ |
||
288 | io_stream_class->close_fn = g_test_tls_connection_close; |
||
289 | |||
290 | g_object_class_override_property (gobject_class, PROP_CONN_BASE_IO_STREAM, "base-io-stream"); |
||
291 | g_object_class_override_property (gobject_class, PROP_CONN_USE_SYSTEM_CERTDB, "use-system-certdb"); |
||
292 | g_object_class_override_property (gobject_class, PROP_CONN_REQUIRE_CLOSE_NOTIFY, "require-close-notify"); |
||
293 | g_object_class_override_property (gobject_class, PROP_CONN_REHANDSHAKE_MODE, "rehandshake-mode"); |
||
294 | g_object_class_override_property (gobject_class, PROP_CONN_CERTIFICATE, "certificate"); |
||
295 | g_object_class_override_property (gobject_class, PROP_CONN_PEER_CERTIFICATE, "peer-certificate"); |
||
296 | g_object_class_override_property (gobject_class, PROP_CONN_PEER_CERTIFICATE_ERRORS, "peer-certificate-errors"); |
||
297 | g_object_class_override_property (gobject_class, PROP_CONN_VALIDATION_FLAGS, "validation-flags"); |
||
298 | g_object_class_override_property (gobject_class, PROP_CONN_SERVER_IDENTITY, "server-identity"); |
||
299 | g_object_class_override_property (gobject_class, PROP_CONN_USE_SSL3, "use-ssl3"); |
||
300 | g_object_class_override_property (gobject_class, PROP_CONN_ACCEPTED_CAS, "accepted-cas"); |
||
301 | g_object_class_override_property (gobject_class, PROP_CONN_AUTHENTICATION_MODE, "authentication-mode"); |
||
302 | } |
||
303 | |||
304 | static void |
||
305 | g_test_tls_connection_init (GTestTlsConnection *connection) |
||
306 | { |
||
307 | } |
||
308 | |||
309 | static gboolean |
||
310 | g_test_tls_connection_initable_init (GInitable *initable, |
||
311 | GCancellable *cancellable, |
||
312 | GError **error) |
||
313 | { |
||
314 | g_set_error_literal (error, G_TLS_ERROR, G_TLS_ERROR_UNAVAILABLE, |
||
315 | "TLS Connection support is not available"); |
||
316 | return FALSE; |
||
317 | } |
||
318 | |||
319 | static void |
||
320 | g_test_tls_connection_initable_iface_init (GInitableIface *iface) |
||
321 | { |
||
322 | iface->init = g_test_tls_connection_initable_init; |
||
323 | } |
||
324 | |||
325 | const gchar * |
||
326 | g_test_tls_connection_get_private_key_pem (GTlsCertificate *cert) |
||
327 | { |
||
328 | return ((GTestTlsCertificate *)cert)->key_pem; |
||
329 | } |