/src/glib/gio/gtlsfiledatabase.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* GIO - GLib Input, Output and Streaming Library |
2 | | * |
3 | | * Copyright © 2010 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.1 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 | | * Author: Stef Walter <stefw@collabora.co.uk> |
19 | | */ |
20 | | |
21 | | #include "config.h" |
22 | | |
23 | | #include "gtlsfiledatabase.h" |
24 | | |
25 | | #include "ginitable.h" |
26 | | #include "gtlsbackend.h" |
27 | | #include "gtlsdatabase.h" |
28 | | #include "glibintl.h" |
29 | | |
30 | | /** |
31 | | * SECTION:gtlsfiledatabase |
32 | | * @short_description: TLS file based database type |
33 | | * @include: gio/gio.h |
34 | | * |
35 | | * #GTlsFileDatabase is implemented by #GTlsDatabase objects which load |
36 | | * their certificate information from a file. It is an interface which |
37 | | * TLS library specific subtypes implement. |
38 | | * |
39 | | * Since: 2.30 |
40 | | */ |
41 | | |
42 | | /** |
43 | | * GTlsFileDatabase: |
44 | | * |
45 | | * Implemented by a #GTlsDatabase which allows you to load certificates |
46 | | * from a file. |
47 | | * |
48 | | * Since: 2.30 |
49 | | */ |
50 | | G_DEFINE_INTERFACE (GTlsFileDatabase, g_tls_file_database, G_TYPE_TLS_DATABASE) |
51 | | |
52 | | static void |
53 | | g_tls_file_database_default_init (GTlsFileDatabaseInterface *iface) |
54 | 0 | { |
55 | | /** |
56 | | * GTlsFileDatabase:anchors: |
57 | | * |
58 | | * The path to a file containing PEM encoded certificate authority |
59 | | * root anchors. The certificates in this file will be treated as |
60 | | * root authorities for the purpose of verifying other certificates |
61 | | * via the g_tls_database_verify_chain() operation. |
62 | | * |
63 | | * Since: 2.30 |
64 | | */ |
65 | 0 | g_object_interface_install_property (iface, |
66 | 0 | g_param_spec_string ("anchors", |
67 | 0 | P_("Anchors"), |
68 | 0 | P_("The certificate authority anchor file"), |
69 | 0 | NULL, |
70 | 0 | G_PARAM_READWRITE | |
71 | 0 | G_PARAM_CONSTRUCT | |
72 | 0 | G_PARAM_STATIC_STRINGS)); |
73 | 0 | } |
74 | | |
75 | | /** |
76 | | * g_tls_file_database_new: |
77 | | * @anchors: (type filename): filename of anchor certificate authorities. |
78 | | * @error: #GError for error reporting, or %NULL to ignore. |
79 | | * |
80 | | * Creates a new #GTlsFileDatabase which uses anchor certificate authorities |
81 | | * in @anchors to verify certificate chains. |
82 | | * |
83 | | * The certificates in @anchors must be PEM encoded. |
84 | | * |
85 | | * Returns: (transfer full) (type GTlsFileDatabase): the new |
86 | | * #GTlsFileDatabase, or %NULL on error |
87 | | * |
88 | | * Since: 2.30 |
89 | | */ |
90 | | GTlsDatabase* |
91 | | g_tls_file_database_new (const gchar *anchors, |
92 | | GError **error) |
93 | 0 | { |
94 | 0 | GObject *database; |
95 | 0 | GTlsBackend *backend; |
96 | |
|
97 | 0 | backend = g_tls_backend_get_default (); |
98 | 0 | database = g_initable_new (g_tls_backend_get_file_database_type (backend), |
99 | 0 | NULL, error, |
100 | 0 | "anchors", anchors, |
101 | 0 | NULL); |
102 | 0 | return G_TLS_DATABASE (database); |
103 | 0 | } |