annotate libpurple/certificate.c @ 19093:f96b53df8d17

- Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
author William Ehlhardt <williamehlhardt@gmail.com>
date Sun, 12 Aug 2007 03:06:47 +0000
parents b98151ac2251
children dd9f69ebaae8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17910
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
1 /**
19075
a0138be8d725 - Typo fix
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19067
diff changeset
2 * @file certificate.c Public-Key Certificate API
17910
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
3 * @ingroup core
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
4 */
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
5
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
6 /*
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
7 *
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
8 * purple
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
9 *
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
10 * Purple is the legal property of its developers, whose names are too numerous
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
11 * to list here. Please refer to the COPYRIGHT file distributed with this
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
12 * source distribution.
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
13 *
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
14 * This program is free software; you can redistribute it and/or modify
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
15 * it under the terms of the GNU General Public License as published by
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
16 * the Free Software Foundation; either version 2 of the License, or
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
17 * (at your option) any later version.
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
18 *
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
19 * This program is distributed in the hope that it will be useful,
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
22 * GNU General Public License for more details.
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
23 *
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
24 * You should have received a copy of the GNU General Public License
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
25 * along with this program; if not, write to the Free Software
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
27 */
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
28
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
29 #include <glib.h>
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
30
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
31 #include "certificate.h"
18192
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
32 #include "debug.h"
18953
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
33 #include "internal.h"
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
34 #include "request.h"
19044
602295db8e6b - Register the certificate-stored and certificate-deleted signals
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19034
diff changeset
35 #include "signals.h"
18953
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
36 #include "util.h"
17910
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
37
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
38 /** List holding pointers to all registered certificate schemes */
18192
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
39 static GList *cert_schemes = NULL;
18941
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
40 /** List of registered Verifiers */
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
41 static GList *cert_verifiers = NULL;
18971
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
42 /** List of registered Pools */
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
43 static GList *cert_pools = NULL;
18941
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
44
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
45 void
18942
02102eccc4be - purple_certificate_verify now takes a Verifier argument, creates its
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18941
diff changeset
46 purple_certificate_verify (PurpleCertificateVerifier *verifier,
02102eccc4be - purple_certificate_verify now takes a Verifier argument, creates its
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18941
diff changeset
47 const gchar *subject_name, GList *cert_chain,
18941
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
48 PurpleCertificateVerifiedCallback cb,
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
49 gpointer cb_data)
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
50 {
18942
02102eccc4be - purple_certificate_verify now takes a Verifier argument, creates its
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18941
diff changeset
51 PurpleCertificateVerificationRequest *vrq;
18941
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
52 PurpleCertificateScheme *scheme;
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
53
18942
02102eccc4be - purple_certificate_verify now takes a Verifier argument, creates its
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18941
diff changeset
54 g_return_if_fail(subject_name != NULL);
18941
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
55 /* If you don't have a cert to check, why are you requesting that it
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
56 be verified? */
18942
02102eccc4be - purple_certificate_verify now takes a Verifier argument, creates its
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18941
diff changeset
57 g_return_if_fail(cert_chain != NULL);
02102eccc4be - purple_certificate_verify now takes a Verifier argument, creates its
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18941
diff changeset
58 g_return_if_fail(cb != NULL);
18941
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
59
18942
02102eccc4be - purple_certificate_verify now takes a Verifier argument, creates its
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18941
diff changeset
60 /* Look up the CertificateScheme */
02102eccc4be - purple_certificate_verify now takes a Verifier argument, creates its
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18941
diff changeset
61 scheme = purple_certificate_find_scheme(verifier->scheme_name);
02102eccc4be - purple_certificate_verify now takes a Verifier argument, creates its
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18941
diff changeset
62 g_return_if_fail(scheme);
18941
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
63
18943
c519ff185569 - purple_certificate_verify attempts to check that the cert chain is of
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18942
diff changeset
64 /* Check that at least the first cert in the chain matches the
c519ff185569 - purple_certificate_verify attempts to check that the cert chain is of
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18942
diff changeset
65 Verifier scheme */
18960
6831c126bcf3 - Fixed an inverted assertion
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18957
diff changeset
66 g_return_if_fail(scheme ==
18943
c519ff185569 - purple_certificate_verify attempts to check that the cert chain is of
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18942
diff changeset
67 ((PurpleCertificate *) (cert_chain->data))->scheme);
c519ff185569 - purple_certificate_verify attempts to check that the cert chain is of
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18942
diff changeset
68
18941
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
69 /* Construct and fill in the request fields */
18949
8902f0d7e40f - Use g_new0 instead of g_new
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18947
diff changeset
70 vrq = g_new0(PurpleCertificateVerificationRequest, 1);
18942
02102eccc4be - purple_certificate_verify now takes a Verifier argument, creates its
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18941
diff changeset
71 vrq->verifier = verifier;
02102eccc4be - purple_certificate_verify now takes a Verifier argument, creates its
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18941
diff changeset
72 vrq->scheme = scheme;
02102eccc4be - purple_certificate_verify now takes a Verifier argument, creates its
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18941
diff changeset
73 vrq->subject_name = g_strdup(subject_name);
19021
fcca10d0ac7d - purple_certificate_verify no longer takes possession of the
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19020
diff changeset
74 vrq->cert_chain = purple_certificate_copy_list(cert_chain);
18941
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
75 vrq->cb = cb;
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
76 vrq->cb_data = cb_data;
18942
02102eccc4be - purple_certificate_verify now takes a Verifier argument, creates its
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18941
diff changeset
77
02102eccc4be - purple_certificate_verify now takes a Verifier argument, creates its
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18941
diff changeset
78 /* Initiate verification */
02102eccc4be - purple_certificate_verify now takes a Verifier argument, creates its
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18941
diff changeset
79 (verifier->start_verification)(vrq);
18941
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
80 }
18192
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
81
18946
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
82 void
19088
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
83 purple_certificate_verify_complete(PurpleCertificateVerificationRequest *vrq,
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
84 PurpleCertificateVerificationStatus st)
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
85 {
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
86 PurpleCertificateVerifier *vr;
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
87
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
88 g_return_if_fail(vrq);
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
89
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
90 /* Pass the results on to the request's callback */
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
91 (vrq->cb)(st, vrq->cb_data);
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
92
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
93 /* And now to eliminate the request */
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
94 /* Fetch the Verifier responsible... */
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
95 vr = vrq->verifier;
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
96 /* ...and order it to KILL */
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
97 (vr->destroy_request)(vrq);
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
98
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
99 /* Now the internals have been cleaned up, so clean up the libpurple-
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
100 created elements */
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
101 g_free(vrq->subject_name);
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
102 purple_certificate_destroy_list(vrq->cert_chain);
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
103
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
104 /* A structure born
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
105 * to much ado
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
106 * and with so much within.
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
107 * It reaches now
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
108 * its quiet end. */
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
109 g_free(vrq);
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
110 }
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
111
f5802217844d - Add verify_complete, which should deprecate verify_destroy
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19086
diff changeset
112
19018
d6f902265076 - Add purple_certificate_copy and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19014
diff changeset
113 PurpleCertificate *
d6f902265076 - Add purple_certificate_copy and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19014
diff changeset
114 purple_certificate_copy(PurpleCertificate *crt)
d6f902265076 - Add purple_certificate_copy and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19014
diff changeset
115 {
d6f902265076 - Add purple_certificate_copy and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19014
diff changeset
116 g_return_val_if_fail(crt, NULL);
d6f902265076 - Add purple_certificate_copy and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19014
diff changeset
117 g_return_val_if_fail(crt->scheme, NULL);
d6f902265076 - Add purple_certificate_copy and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19014
diff changeset
118 g_return_val_if_fail(crt->scheme->copy_certificate, NULL);
d6f902265076 - Add purple_certificate_copy and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19014
diff changeset
119
d6f902265076 - Add purple_certificate_copy and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19014
diff changeset
120 return (crt->scheme->copy_certificate)(crt);
d6f902265076 - Add purple_certificate_copy and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19014
diff changeset
121 }
18947
3c6bf77bf7c4 - Add purple_certificate_verify_destroy and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18946
diff changeset
122
19020
d69355001a6e - Add purple_certificate_copy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19018
diff changeset
123 GList *
d69355001a6e - Add purple_certificate_copy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19018
diff changeset
124 purple_certificate_copy_list(GList *crt_list)
d69355001a6e - Add purple_certificate_copy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19018
diff changeset
125 {
d69355001a6e - Add purple_certificate_copy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19018
diff changeset
126 GList *new, *l;
d69355001a6e - Add purple_certificate_copy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19018
diff changeset
127
d69355001a6e - Add purple_certificate_copy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19018
diff changeset
128 /* First, make a shallow copy of the list */
d69355001a6e - Add purple_certificate_copy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19018
diff changeset
129 new = g_list_copy(crt_list);
d69355001a6e - Add purple_certificate_copy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19018
diff changeset
130
d69355001a6e - Add purple_certificate_copy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19018
diff changeset
131 /* Now go through and actually duplicate each certificate */
d69355001a6e - Add purple_certificate_copy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19018
diff changeset
132 for (l = new; l; l = l->next) {
d69355001a6e - Add purple_certificate_copy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19018
diff changeset
133 l->data = purple_certificate_copy(l->data);
d69355001a6e - Add purple_certificate_copy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19018
diff changeset
134 }
d69355001a6e - Add purple_certificate_copy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19018
diff changeset
135
d69355001a6e - Add purple_certificate_copy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19018
diff changeset
136 return new;
d69355001a6e - Add purple_certificate_copy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19018
diff changeset
137 }
d69355001a6e - Add purple_certificate_copy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19018
diff changeset
138
18947
3c6bf77bf7c4 - Add purple_certificate_verify_destroy and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18946
diff changeset
139 void
18946
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
140 purple_certificate_destroy (PurpleCertificate *crt)
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
141 {
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
142 PurpleCertificateScheme *scheme;
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
143
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
144 if (NULL == crt) return;
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
145
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
146 scheme = crt->scheme;
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
147
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
148 (scheme->destroy_certificate)(crt);
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
149 }
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
150
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
151 void
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
152 purple_certificate_destroy_list (GList * crt_list)
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
153 {
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
154 PurpleCertificate *crt;
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
155 GList *l;
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
156
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
157 for (l=crt_list; l; l = l->next) {
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
158 crt = (PurpleCertificate *) l->data;
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
159 purple_certificate_destroy(crt);
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
160 }
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
161
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
162 g_list_free(crt_list);
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
163 }
18953
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
164
19076
daa68185a018 - Add purple_certificate_signed_by
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19075
diff changeset
165 gboolean
daa68185a018 - Add purple_certificate_signed_by
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19075
diff changeset
166 purple_certificate_signed_by(PurpleCertificate *crt, PurpleCertificate *issuer)
daa68185a018 - Add purple_certificate_signed_by
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19075
diff changeset
167 {
daa68185a018 - Add purple_certificate_signed_by
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19075
diff changeset
168 PurpleCertificateScheme *scheme;
daa68185a018 - Add purple_certificate_signed_by
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19075
diff changeset
169
daa68185a018 - Add purple_certificate_signed_by
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19075
diff changeset
170 g_return_val_if_fail(crt, FALSE);
daa68185a018 - Add purple_certificate_signed_by
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19075
diff changeset
171 g_return_val_if_fail(issuer, FALSE);
daa68185a018 - Add purple_certificate_signed_by
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19075
diff changeset
172
daa68185a018 - Add purple_certificate_signed_by
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19075
diff changeset
173 scheme = crt->scheme;
daa68185a018 - Add purple_certificate_signed_by
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19075
diff changeset
174 g_return_val_if_fail(scheme, FALSE);
daa68185a018 - Add purple_certificate_signed_by
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19075
diff changeset
175 /* We can't compare two certs of unrelated schemes, obviously */
daa68185a018 - Add purple_certificate_signed_by
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19075
diff changeset
176 g_return_val_if_fail(issuer->scheme == scheme, FALSE);
daa68185a018 - Add purple_certificate_signed_by
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19075
diff changeset
177
daa68185a018 - Add purple_certificate_signed_by
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19075
diff changeset
178 return (scheme->signed_by)(crt, issuer);
daa68185a018 - Add purple_certificate_signed_by
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19075
diff changeset
179 }
daa68185a018 - Add purple_certificate_signed_by
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19075
diff changeset
180
19077
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
181 gboolean
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
182 purple_certificate_check_signature_chain(GList *chain)
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
183 {
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
184 GList *cur;
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
185 PurpleCertificate *crt, *issuer;
19081
bdd8911d5031 - Add debugging babble to check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19080
diff changeset
186 gchar *uid;
19077
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
187
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
188 g_return_val_if_fail(chain, FALSE);
19081
bdd8911d5031 - Add debugging babble to check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19080
diff changeset
189
bdd8911d5031 - Add debugging babble to check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19080
diff changeset
190 uid = purple_certificate_get_unique_id((PurpleCertificate *) chain->data);
bdd8911d5031 - Add debugging babble to check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19080
diff changeset
191 purple_debug_info("certificate",
bdd8911d5031 - Add debugging babble to check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19080
diff changeset
192 "Checking signature chain for uid=%s\n",
bdd8911d5031 - Add debugging babble to check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19080
diff changeset
193 uid);
bdd8911d5031 - Add debugging babble to check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19080
diff changeset
194 g_free(uid);
19077
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
195
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
196 /* If this is a single-certificate chain, say that it is valid */
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
197 if (chain->next == NULL) {
19081
bdd8911d5031 - Add debugging babble to check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19080
diff changeset
198 purple_debug_info("certificate",
bdd8911d5031 - Add debugging babble to check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19080
diff changeset
199 "...Singleton. We'll say it's valid.\n");
19077
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
200 return TRUE;
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
201 }
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
202
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
203 /* Load crt with the first certificate */
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
204 crt = (PurpleCertificate *)(chain->data);
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
205 /* And start with the second certificate in the chain */
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
206 for ( cur = chain->next; cur; cur = cur->next ) {
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
207
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
208 issuer = (PurpleCertificate *)(cur->data);
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
209
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
210 /* Check the signature for this link */
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
211 if (! purple_certificate_signed_by(crt, issuer) ) {
19081
bdd8911d5031 - Add debugging babble to check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19080
diff changeset
212 uid = purple_certificate_get_unique_id(issuer);
bdd8911d5031 - Add debugging babble to check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19080
diff changeset
213 purple_debug_info("certificate",
bdd8911d5031 - Add debugging babble to check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19080
diff changeset
214 "...Bad or missing signature by %s\nChain is INVALID\n",
bdd8911d5031 - Add debugging babble to check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19080
diff changeset
215 uid);
bdd8911d5031 - Add debugging babble to check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19080
diff changeset
216 g_free(uid);
bdd8911d5031 - Add debugging babble to check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19080
diff changeset
217
19077
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
218 return FALSE;
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
219 }
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
220
19081
bdd8911d5031 - Add debugging babble to check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19080
diff changeset
221 uid = purple_certificate_get_unique_id(issuer);
bdd8911d5031 - Add debugging babble to check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19080
diff changeset
222 purple_debug_info("certificate",
bdd8911d5031 - Add debugging babble to check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19080
diff changeset
223 "...Good signature by %s\n",
bdd8911d5031 - Add debugging babble to check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19080
diff changeset
224 uid);
bdd8911d5031 - Add debugging babble to check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19080
diff changeset
225 g_free(uid);
bdd8911d5031 - Add debugging babble to check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19080
diff changeset
226
19077
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
227 /* The issuer is now the next crt whose signature is to be
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
228 checked */
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
229 crt = issuer;
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
230 }
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
231
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
232 /* If control reaches this point, the chain is valid */
19081
bdd8911d5031 - Add debugging babble to check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19080
diff changeset
233 purple_debug_info("certificate", "Chain is VALID\n");
19077
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
234 return TRUE;
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
235 }
8275c3cbc9da - Add purple_certificate_check_signature_chain
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19076
diff changeset
236
18988
4189fc3befba - Add purple_certificate_import
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18987
diff changeset
237 PurpleCertificate *
18989
43d1ee6a3ed5 - Fixed naming issues in previous revision
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18988
diff changeset
238 purple_certificate_import(PurpleCertificateScheme *scheme, const gchar *filename)
18988
4189fc3befba - Add purple_certificate_import
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18987
diff changeset
239 {
4189fc3befba - Add purple_certificate_import
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18987
diff changeset
240 g_return_val_if_fail(scheme, NULL);
4189fc3befba - Add purple_certificate_import
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18987
diff changeset
241 g_return_val_if_fail(scheme->import_certificate, NULL);
4189fc3befba - Add purple_certificate_import
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18987
diff changeset
242 g_return_val_if_fail(filename, NULL);
4189fc3befba - Add purple_certificate_import
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18987
diff changeset
243
4189fc3befba - Add purple_certificate_import
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18987
diff changeset
244 return (scheme->import_certificate)(filename);
4189fc3befba - Add purple_certificate_import
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18987
diff changeset
245 }
4189fc3befba - Add purple_certificate_import
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18987
diff changeset
246
18977
31bdbb82de7e - Add purple_certificate_export and associated libpurple stuff
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18976
diff changeset
247 gboolean
31bdbb82de7e - Add purple_certificate_export and associated libpurple stuff
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18976
diff changeset
248 purple_certificate_export(const gchar *filename, PurpleCertificate *crt)
31bdbb82de7e - Add purple_certificate_export and associated libpurple stuff
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18976
diff changeset
249 {
31bdbb82de7e - Add purple_certificate_export and associated libpurple stuff
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18976
diff changeset
250 PurpleCertificateScheme *scheme;
31bdbb82de7e - Add purple_certificate_export and associated libpurple stuff
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18976
diff changeset
251
31bdbb82de7e - Add purple_certificate_export and associated libpurple stuff
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18976
diff changeset
252 g_return_val_if_fail(filename, FALSE);
31bdbb82de7e - Add purple_certificate_export and associated libpurple stuff
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18976
diff changeset
253 g_return_val_if_fail(crt, FALSE);
31bdbb82de7e - Add purple_certificate_export and associated libpurple stuff
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18976
diff changeset
254 g_return_val_if_fail(crt->scheme, FALSE);
31bdbb82de7e - Add purple_certificate_export and associated libpurple stuff
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18976
diff changeset
255
31bdbb82de7e - Add purple_certificate_export and associated libpurple stuff
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18976
diff changeset
256 scheme = crt->scheme;
31bdbb82de7e - Add purple_certificate_export and associated libpurple stuff
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18976
diff changeset
257 g_return_val_if_fail(scheme->export_certificate, FALSE);
31bdbb82de7e - Add purple_certificate_export and associated libpurple stuff
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18976
diff changeset
258
31bdbb82de7e - Add purple_certificate_export and associated libpurple stuff
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18976
diff changeset
259 return (scheme->export_certificate)(filename, crt);
31bdbb82de7e - Add purple_certificate_export and associated libpurple stuff
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18976
diff changeset
260 }
31bdbb82de7e - Add purple_certificate_export and associated libpurple stuff
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18976
diff changeset
261
18953
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
262 GByteArray *
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
263 purple_certificate_get_fingerprint_sha1(PurpleCertificate *crt)
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
264 {
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
265 PurpleCertificateScheme *scheme;
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
266 GByteArray *fpr;
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
267
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
268 g_return_val_if_fail(crt, NULL);
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
269 g_return_val_if_fail(crt->scheme, NULL);
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
270
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
271 scheme = crt->scheme;
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
272
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
273 g_return_val_if_fail(scheme->get_fingerprint_sha1, NULL);
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
274
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
275 fpr = (scheme->get_fingerprint_sha1)(crt);
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
276
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
277 return fpr;
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
278 }
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
279
18962
fcd05c39803e - Add purple_certificate_get_subject_name and associated libpurple
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18960
diff changeset
280 gchar *
19080
3bdede51c007 - Expose get_unique_id and get_issuer_unique_id through libpurple functions
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19078
diff changeset
281 purple_certificate_get_unique_id(PurpleCertificate *crt)
3bdede51c007 - Expose get_unique_id and get_issuer_unique_id through libpurple functions
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19078
diff changeset
282 {
3bdede51c007 - Expose get_unique_id and get_issuer_unique_id through libpurple functions
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19078
diff changeset
283 g_return_val_if_fail(crt, NULL);
3bdede51c007 - Expose get_unique_id and get_issuer_unique_id through libpurple functions
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19078
diff changeset
284 g_return_val_if_fail(crt->scheme, NULL);
3bdede51c007 - Expose get_unique_id and get_issuer_unique_id through libpurple functions
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19078
diff changeset
285 g_return_val_if_fail(crt->scheme->get_unique_id, NULL);
3bdede51c007 - Expose get_unique_id and get_issuer_unique_id through libpurple functions
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19078
diff changeset
286
3bdede51c007 - Expose get_unique_id and get_issuer_unique_id through libpurple functions
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19078
diff changeset
287 return (crt->scheme->get_unique_id)(crt);
3bdede51c007 - Expose get_unique_id and get_issuer_unique_id through libpurple functions
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19078
diff changeset
288 }
3bdede51c007 - Expose get_unique_id and get_issuer_unique_id through libpurple functions
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19078
diff changeset
289
3bdede51c007 - Expose get_unique_id and get_issuer_unique_id through libpurple functions
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19078
diff changeset
290 gchar *
3bdede51c007 - Expose get_unique_id and get_issuer_unique_id through libpurple functions
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19078
diff changeset
291 purple_certificate_get_issuer_unique_id(PurpleCertificate *crt)
3bdede51c007 - Expose get_unique_id and get_issuer_unique_id through libpurple functions
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19078
diff changeset
292 {
3bdede51c007 - Expose get_unique_id and get_issuer_unique_id through libpurple functions
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19078
diff changeset
293 g_return_val_if_fail(crt, NULL);
3bdede51c007 - Expose get_unique_id and get_issuer_unique_id through libpurple functions
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19078
diff changeset
294 g_return_val_if_fail(crt->scheme, NULL);
3bdede51c007 - Expose get_unique_id and get_issuer_unique_id through libpurple functions
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19078
diff changeset
295 g_return_val_if_fail(crt->scheme->get_issuer_unique_id, NULL);
3bdede51c007 - Expose get_unique_id and get_issuer_unique_id through libpurple functions
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19078
diff changeset
296
3bdede51c007 - Expose get_unique_id and get_issuer_unique_id through libpurple functions
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19078
diff changeset
297 return (crt->scheme->get_issuer_unique_id)(crt);
3bdede51c007 - Expose get_unique_id and get_issuer_unique_id through libpurple functions
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19078
diff changeset
298 }
3bdede51c007 - Expose get_unique_id and get_issuer_unique_id through libpurple functions
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19078
diff changeset
299
3bdede51c007 - Expose get_unique_id and get_issuer_unique_id through libpurple functions
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19078
diff changeset
300 gchar *
18962
fcd05c39803e - Add purple_certificate_get_subject_name and associated libpurple
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18960
diff changeset
301 purple_certificate_get_subject_name(PurpleCertificate *crt)
fcd05c39803e - Add purple_certificate_get_subject_name and associated libpurple
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18960
diff changeset
302 {
fcd05c39803e - Add purple_certificate_get_subject_name and associated libpurple
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18960
diff changeset
303 PurpleCertificateScheme *scheme;
fcd05c39803e - Add purple_certificate_get_subject_name and associated libpurple
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18960
diff changeset
304 gchar *subject_name;
fcd05c39803e - Add purple_certificate_get_subject_name and associated libpurple
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18960
diff changeset
305
fcd05c39803e - Add purple_certificate_get_subject_name and associated libpurple
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18960
diff changeset
306 g_return_val_if_fail(crt, NULL);
fcd05c39803e - Add purple_certificate_get_subject_name and associated libpurple
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18960
diff changeset
307 g_return_val_if_fail(crt->scheme, NULL);
fcd05c39803e - Add purple_certificate_get_subject_name and associated libpurple
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18960
diff changeset
308
fcd05c39803e - Add purple_certificate_get_subject_name and associated libpurple
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18960
diff changeset
309 scheme = crt->scheme;
fcd05c39803e - Add purple_certificate_get_subject_name and associated libpurple
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18960
diff changeset
310
fcd05c39803e - Add purple_certificate_get_subject_name and associated libpurple
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18960
diff changeset
311 g_return_val_if_fail(scheme->get_subject_name, NULL);
fcd05c39803e - Add purple_certificate_get_subject_name and associated libpurple
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18960
diff changeset
312
fcd05c39803e - Add purple_certificate_get_subject_name and associated libpurple
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18960
diff changeset
313 subject_name = (scheme->get_subject_name)(crt);
fcd05c39803e - Add purple_certificate_get_subject_name and associated libpurple
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18960
diff changeset
314
fcd05c39803e - Add purple_certificate_get_subject_name and associated libpurple
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18960
diff changeset
315 return subject_name;
fcd05c39803e - Add purple_certificate_get_subject_name and associated libpurple
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18960
diff changeset
316 }
fcd05c39803e - Add purple_certificate_get_subject_name and associated libpurple
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18960
diff changeset
317
19008
7fd9bd55f8d0 - Add certificate_check_subject_name and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19001
diff changeset
318 gboolean
7fd9bd55f8d0 - Add certificate_check_subject_name and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19001
diff changeset
319 purple_certificate_check_subject_name(PurpleCertificate *crt, const gchar *name)
7fd9bd55f8d0 - Add certificate_check_subject_name and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19001
diff changeset
320 {
7fd9bd55f8d0 - Add certificate_check_subject_name and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19001
diff changeset
321 PurpleCertificateScheme *scheme;
7fd9bd55f8d0 - Add certificate_check_subject_name and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19001
diff changeset
322
7fd9bd55f8d0 - Add certificate_check_subject_name and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19001
diff changeset
323 g_return_val_if_fail(crt, FALSE);
7fd9bd55f8d0 - Add certificate_check_subject_name and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19001
diff changeset
324 g_return_val_if_fail(crt->scheme, FALSE);
7fd9bd55f8d0 - Add certificate_check_subject_name and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19001
diff changeset
325 g_return_val_if_fail(name, FALSE);
7fd9bd55f8d0 - Add certificate_check_subject_name and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19001
diff changeset
326
7fd9bd55f8d0 - Add certificate_check_subject_name and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19001
diff changeset
327 scheme = crt->scheme;
7fd9bd55f8d0 - Add certificate_check_subject_name and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19001
diff changeset
328
7fd9bd55f8d0 - Add certificate_check_subject_name and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19001
diff changeset
329 /* TODO: Instead of failing, maybe use get_subject_name and strcmp? */
7fd9bd55f8d0 - Add certificate_check_subject_name and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19001
diff changeset
330 g_return_val_if_fail(scheme->check_subject_name, FALSE);
7fd9bd55f8d0 - Add certificate_check_subject_name and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19001
diff changeset
331
7fd9bd55f8d0 - Add certificate_check_subject_name and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19001
diff changeset
332 return (scheme->check_subject_name)(crt, name);
7fd9bd55f8d0 - Add certificate_check_subject_name and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19001
diff changeset
333 }
7fd9bd55f8d0 - Add certificate_check_subject_name and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19001
diff changeset
334
19012
b1090cbfc286 - Add expiration/activation functions for Certificates
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19010
diff changeset
335 gboolean
b1090cbfc286 - Add expiration/activation functions for Certificates
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19010
diff changeset
336 purple_certificate_get_times(PurpleCertificate *crt, time_t *activation, time_t *expiration)
b1090cbfc286 - Add expiration/activation functions for Certificates
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19010
diff changeset
337 {
b1090cbfc286 - Add expiration/activation functions for Certificates
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19010
diff changeset
338 PurpleCertificateScheme *scheme;
b1090cbfc286 - Add expiration/activation functions for Certificates
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19010
diff changeset
339
b1090cbfc286 - Add expiration/activation functions for Certificates
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19010
diff changeset
340 g_return_val_if_fail(crt, FALSE);
b1090cbfc286 - Add expiration/activation functions for Certificates
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19010
diff changeset
341
b1090cbfc286 - Add expiration/activation functions for Certificates
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19010
diff changeset
342 scheme = crt->scheme;
b1090cbfc286 - Add expiration/activation functions for Certificates
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19010
diff changeset
343
b1090cbfc286 - Add expiration/activation functions for Certificates
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19010
diff changeset
344 g_return_val_if_fail(scheme, FALSE);
b1090cbfc286 - Add expiration/activation functions for Certificates
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19010
diff changeset
345
b1090cbfc286 - Add expiration/activation functions for Certificates
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19010
diff changeset
346 /* If both provided references are NULL, what are you doing calling
b1090cbfc286 - Add expiration/activation functions for Certificates
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19010
diff changeset
347 this? */
b1090cbfc286 - Add expiration/activation functions for Certificates
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19010
diff changeset
348 g_return_val_if_fail( (activation != NULL) || (expiration != NULL), FALSE);
b1090cbfc286 - Add expiration/activation functions for Certificates
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19010
diff changeset
349
19067
6c0aad79c4c5 - Change the internal structure of activation/expiration times to match
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19063
diff changeset
350 /* Throw the request on down to the certscheme */
6c0aad79c4c5 - Change the internal structure of activation/expiration times to match
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19063
diff changeset
351 return (scheme->get_times)(crt, activation, expiration);
19012
b1090cbfc286 - Add expiration/activation functions for Certificates
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19010
diff changeset
352 }
b1090cbfc286 - Add expiration/activation functions for Certificates
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19010
diff changeset
353
19008
7fd9bd55f8d0 - Add certificate_check_subject_name and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19001
diff changeset
354
18984
2b4150624cf2 - Add purple_certificate_pool_mkpath helper function
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18982
diff changeset
355 gchar *
2b4150624cf2 - Add purple_certificate_pool_mkpath helper function
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18982
diff changeset
356 purple_certificate_pool_mkpath(PurpleCertificatePool *pool, const gchar *id)
2b4150624cf2 - Add purple_certificate_pool_mkpath helper function
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18982
diff changeset
357 {
19010
0d4b84820390 - Fix overzealous escaping cause by ancestor revision
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19009
diff changeset
358 gchar *path;
0d4b84820390 - Fix overzealous escaping cause by ancestor revision
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19009
diff changeset
359 gchar *esc_scheme_name, *esc_name, *esc_id;
18984
2b4150624cf2 - Add purple_certificate_pool_mkpath helper function
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18982
diff changeset
360
2b4150624cf2 - Add purple_certificate_pool_mkpath helper function
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18982
diff changeset
361 g_return_val_if_fail(pool, NULL);
2b4150624cf2 - Add purple_certificate_pool_mkpath helper function
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18982
diff changeset
362 g_return_val_if_fail(pool->scheme_name, NULL);
2b4150624cf2 - Add purple_certificate_pool_mkpath helper function
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18982
diff changeset
363 g_return_val_if_fail(pool->name, NULL);
2b4150624cf2 - Add purple_certificate_pool_mkpath helper function
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18982
diff changeset
364
19010
0d4b84820390 - Fix overzealous escaping cause by ancestor revision
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19009
diff changeset
365 /* Escape all the elements for filesystem-friendliness */
19033
6b4e874e47c1 - Handle NULLs given to certificate_pool_mkpath without causing errors
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19027
diff changeset
366 esc_scheme_name = pool ? g_strdup(purple_escape_filename(pool->scheme_name)) : NULL;
6b4e874e47c1 - Handle NULLs given to certificate_pool_mkpath without causing errors
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19027
diff changeset
367 esc_name = pool ? g_strdup(purple_escape_filename(pool->name)) : NULL;
6b4e874e47c1 - Handle NULLs given to certificate_pool_mkpath without causing errors
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19027
diff changeset
368 esc_id = id ? g_strdup(purple_escape_filename(id)) : NULL;
19010
0d4b84820390 - Fix overzealous escaping cause by ancestor revision
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19009
diff changeset
369
18984
2b4150624cf2 - Add purple_certificate_pool_mkpath helper function
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18982
diff changeset
370 path = g_build_filename(purple_user_dir(),
18986
dfd9f883b774 - Correct the certstore folder paths
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18985
diff changeset
371 "certificates", /* TODO: constantize this? */
19010
0d4b84820390 - Fix overzealous escaping cause by ancestor revision
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19009
diff changeset
372 esc_scheme_name,
0d4b84820390 - Fix overzealous escaping cause by ancestor revision
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19009
diff changeset
373 esc_name,
0d4b84820390 - Fix overzealous escaping cause by ancestor revision
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19009
diff changeset
374 esc_id,
18984
2b4150624cf2 - Add purple_certificate_pool_mkpath helper function
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18982
diff changeset
375 NULL);
19009
b64aa0222a7a - pool_mkpath now runs purple_escape_filename on its return value
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19008
diff changeset
376
19010
0d4b84820390 - Fix overzealous escaping cause by ancestor revision
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19009
diff changeset
377 g_free(esc_scheme_name);
0d4b84820390 - Fix overzealous escaping cause by ancestor revision
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19009
diff changeset
378 g_free(esc_name);
0d4b84820390 - Fix overzealous escaping cause by ancestor revision
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19009
diff changeset
379 g_free(esc_id);
0d4b84820390 - Fix overzealous escaping cause by ancestor revision
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19009
diff changeset
380 return path;
18984
2b4150624cf2 - Add purple_certificate_pool_mkpath helper function
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18982
diff changeset
381 }
2b4150624cf2 - Add purple_certificate_pool_mkpath helper function
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18982
diff changeset
382
18995
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
383 gboolean
19034
8b627694bf4a - Add purple_certificate_pool_usable to check whether a pool's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19033
diff changeset
384 purple_certificate_pool_usable(PurpleCertificatePool *pool)
8b627694bf4a - Add purple_certificate_pool_usable to check whether a pool's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19033
diff changeset
385 {
8b627694bf4a - Add purple_certificate_pool_usable to check whether a pool's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19033
diff changeset
386 g_return_val_if_fail(pool, FALSE);
8b627694bf4a - Add purple_certificate_pool_usable to check whether a pool's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19033
diff changeset
387 g_return_val_if_fail(pool->scheme_name, FALSE);
8b627694bf4a - Add purple_certificate_pool_usable to check whether a pool's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19033
diff changeset
388
8b627694bf4a - Add purple_certificate_pool_usable to check whether a pool's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19033
diff changeset
389 /* Check that the pool's scheme is loaded */
8b627694bf4a - Add purple_certificate_pool_usable to check whether a pool's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19033
diff changeset
390 if (purple_certificate_find_scheme(pool->scheme_name) == NULL) {
8b627694bf4a - Add purple_certificate_pool_usable to check whether a pool's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19033
diff changeset
391 return FALSE;
8b627694bf4a - Add purple_certificate_pool_usable to check whether a pool's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19033
diff changeset
392 }
8b627694bf4a - Add purple_certificate_pool_usable to check whether a pool's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19033
diff changeset
393
8b627694bf4a - Add purple_certificate_pool_usable to check whether a pool's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19033
diff changeset
394 return TRUE;
8b627694bf4a - Add purple_certificate_pool_usable to check whether a pool's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19033
diff changeset
395 }
8b627694bf4a - Add purple_certificate_pool_usable to check whether a pool's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19033
diff changeset
396
19060
c79b54f03f9d - Add purple_certificate_pool_get_scheme helper function
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19050
diff changeset
397 PurpleCertificateScheme *
c79b54f03f9d - Add purple_certificate_pool_get_scheme helper function
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19050
diff changeset
398 purple_certificate_pool_get_scheme(PurpleCertificatePool *pool)
c79b54f03f9d - Add purple_certificate_pool_get_scheme helper function
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19050
diff changeset
399 {
c79b54f03f9d - Add purple_certificate_pool_get_scheme helper function
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19050
diff changeset
400 g_return_val_if_fail(pool, NULL);
c79b54f03f9d - Add purple_certificate_pool_get_scheme helper function
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19050
diff changeset
401 g_return_val_if_fail(pool->scheme_name, NULL);
c79b54f03f9d - Add purple_certificate_pool_get_scheme helper function
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19050
diff changeset
402
c79b54f03f9d - Add purple_certificate_pool_get_scheme helper function
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19050
diff changeset
403 return purple_certificate_find_scheme(pool->scheme_name);
c79b54f03f9d - Add purple_certificate_pool_get_scheme helper function
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19050
diff changeset
404 }
c79b54f03f9d - Add purple_certificate_pool_get_scheme helper function
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19050
diff changeset
405
19034
8b627694bf4a - Add purple_certificate_pool_usable to check whether a pool's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19033
diff changeset
406 gboolean
18995
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
407 purple_certificate_pool_contains(PurpleCertificatePool *pool, const gchar *id)
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
408 {
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
409 g_return_val_if_fail(pool, FALSE);
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
410 g_return_val_if_fail(id, FALSE);
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
411 g_return_val_if_fail(pool->cert_in_pool, FALSE);
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
412
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
413 return (pool->cert_in_pool)(id);
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
414 }
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
415
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
416 PurpleCertificate *
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
417 purple_certificate_pool_retrieve(PurpleCertificatePool *pool, const gchar *id)
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
418 {
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
419 g_return_val_if_fail(pool, NULL);
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
420 g_return_val_if_fail(id, NULL);
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
421 g_return_val_if_fail(pool->get_cert, NULL);
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
422
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
423 return (pool->get_cert)(id);
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
424 }
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
425
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
426 gboolean
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
427 purple_certificate_pool_store(PurpleCertificatePool *pool, const gchar *id, PurpleCertificate *crt)
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
428 {
19046
8599a27ad69c - Emit certificate-stored signal in purple_certificate_pool_store
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19044
diff changeset
429 gboolean ret = FALSE;
8599a27ad69c - Emit certificate-stored signal in purple_certificate_pool_store
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19044
diff changeset
430
18995
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
431 g_return_val_if_fail(pool, FALSE);
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
432 g_return_val_if_fail(id, FALSE);
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
433 g_return_val_if_fail(pool->put_cert, FALSE);
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
434
18996
24fc5ca67afc - Do some weak checking to ensure that you don't attempt to store a
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18995
diff changeset
435 /* TODO: Should this just be someone else's problem? */
24fc5ca67afc - Do some weak checking to ensure that you don't attempt to store a
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18995
diff changeset
436 /* Whether crt->scheme matches find_scheme(pool->scheme_name) is not
24fc5ca67afc - Do some weak checking to ensure that you don't attempt to store a
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18995
diff changeset
437 relevant... I think... */
24fc5ca67afc - Do some weak checking to ensure that you don't attempt to store a
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18995
diff changeset
438 g_return_val_if_fail(
24fc5ca67afc - Do some weak checking to ensure that you don't attempt to store a
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18995
diff changeset
439 g_ascii_strcasecmp(pool->scheme_name, crt->scheme->name) == 0,
24fc5ca67afc - Do some weak checking to ensure that you don't attempt to store a
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18995
diff changeset
440 FALSE);
18995
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
441
19046
8599a27ad69c - Emit certificate-stored signal in purple_certificate_pool_store
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19044
diff changeset
442 ret = (pool->put_cert)(id, crt);
8599a27ad69c - Emit certificate-stored signal in purple_certificate_pool_store
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19044
diff changeset
443
19050
c563b8f84aa0 - Only emit certificate-stored and certificate-deleted if the operation
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19049
diff changeset
444 /* Signal that the certificate was stored if success*/
c563b8f84aa0 - Only emit certificate-stored and certificate-deleted if the operation
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19049
diff changeset
445 if (ret) {
c563b8f84aa0 - Only emit certificate-stored and certificate-deleted if the operation
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19049
diff changeset
446 purple_signal_emit(pool, "certificate-stored",
c563b8f84aa0 - Only emit certificate-stored and certificate-deleted if the operation
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19049
diff changeset
447 pool, id);
c563b8f84aa0 - Only emit certificate-stored and certificate-deleted if the operation
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19049
diff changeset
448 }
19046
8599a27ad69c - Emit certificate-stored signal in purple_certificate_pool_store
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19044
diff changeset
449
8599a27ad69c - Emit certificate-stored signal in purple_certificate_pool_store
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19044
diff changeset
450 return ret;
18995
47b06daea9d1 - Add pool retrieve, contains, and store functions to certificate API
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18993
diff changeset
451 }
18984
2b4150624cf2 - Add purple_certificate_pool_mkpath helper function
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18982
diff changeset
452
19049
8cbc110456ac - Add purple_certificate_pool_delete
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19048
diff changeset
453 gboolean
8cbc110456ac - Add purple_certificate_pool_delete
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19048
diff changeset
454 purple_certificate_pool_delete(PurpleCertificatePool *pool, const gchar *id)
8cbc110456ac - Add purple_certificate_pool_delete
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19048
diff changeset
455 {
8cbc110456ac - Add purple_certificate_pool_delete
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19048
diff changeset
456 gboolean ret = FALSE;
8cbc110456ac - Add purple_certificate_pool_delete
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19048
diff changeset
457
8cbc110456ac - Add purple_certificate_pool_delete
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19048
diff changeset
458 g_return_val_if_fail(pool, FALSE);
8cbc110456ac - Add purple_certificate_pool_delete
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19048
diff changeset
459 g_return_val_if_fail(id, FALSE);
8cbc110456ac - Add purple_certificate_pool_delete
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19048
diff changeset
460 g_return_val_if_fail(pool->delete_cert, FALSE);
8cbc110456ac - Add purple_certificate_pool_delete
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19048
diff changeset
461
8cbc110456ac - Add purple_certificate_pool_delete
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19048
diff changeset
462 ret = (pool->delete_cert)(id);
8cbc110456ac - Add purple_certificate_pool_delete
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19048
diff changeset
463
19050
c563b8f84aa0 - Only emit certificate-stored and certificate-deleted if the operation
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19049
diff changeset
464 /* Signal that the certificate was deleted if success */
c563b8f84aa0 - Only emit certificate-stored and certificate-deleted if the operation
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19049
diff changeset
465 if (ret) {
c563b8f84aa0 - Only emit certificate-stored and certificate-deleted if the operation
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19049
diff changeset
466 purple_signal_emit(pool, "certificate-deleted",
c563b8f84aa0 - Only emit certificate-stored and certificate-deleted if the operation
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19049
diff changeset
467 pool, id);
c563b8f84aa0 - Only emit certificate-stored and certificate-deleted if the operation
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19049
diff changeset
468 }
19049
8cbc110456ac - Add purple_certificate_pool_delete
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19048
diff changeset
469
8cbc110456ac - Add purple_certificate_pool_delete
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19048
diff changeset
470 return ret;
8cbc110456ac - Add purple_certificate_pool_delete
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19048
diff changeset
471 }
8cbc110456ac - Add purple_certificate_pool_delete
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19048
diff changeset
472
19026
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
473 GList *
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
474 purple_certificate_pool_get_idlist(PurpleCertificatePool *pool)
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
475 {
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
476 g_return_val_if_fail(pool, NULL);
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
477 g_return_val_if_fail(pool->get_idlist, NULL);
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
478
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
479 return (pool->get_idlist)();
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
480 }
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
481
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
482 void
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
483 purple_certificate_pool_destroy_idlist(GList *idlist)
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
484 {
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
485 GList *l;
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
486
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
487 /* Iterate through and free them strings */
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
488 for ( l = idlist; l; l = l->next ) {
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
489 g_free(l->data);
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
490 }
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
491
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
492 g_list_free(idlist);
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
493 }
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
494
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
495
18953
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
496 /****************************************************************************/
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
497 /* Builtin Verifiers, Pools, etc. */
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
498 /****************************************************************************/
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
499
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
500 static void
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
501 x509_singleuse_verify_cb (PurpleCertificateVerificationRequest *vrq, gint id)
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
502 {
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
503 g_return_if_fail(vrq);
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
504
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
505 purple_debug_info("certificate/x509_singleuse",
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
506 "VRQ on cert from %s gave %d\n",
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
507 vrq->subject_name, id);
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
508
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
509 /* Signal what happened back to the caller */
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
510 if (1 == id) {
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
511 /* Accepted! */
19091
489889091b14 - Remove all usage of purple_certificate_verify_destroy, as it is
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19090
diff changeset
512 purple_certificate_verify_complete(vrq,
489889091b14 - Remove all usage of purple_certificate_verify_destroy, as it is
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19090
diff changeset
513 PURPLE_CERTIFICATE_VALID);
18953
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
514 } else {
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
515 /* Not accepted */
19091
489889091b14 - Remove all usage of purple_certificate_verify_destroy, as it is
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19090
diff changeset
516 purple_certificate_verify_complete(vrq,
489889091b14 - Remove all usage of purple_certificate_verify_destroy, as it is
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19090
diff changeset
517 PURPLE_CERTIFICATE_INVALID);
18953
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
518
19091
489889091b14 - Remove all usage of purple_certificate_verify_destroy, as it is
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19090
diff changeset
519 }
18953
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
520 }
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
521
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
522 static void
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
523 x509_singleuse_start_verify (PurpleCertificateVerificationRequest *vrq)
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
524 {
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
525 gchar *sha_asc;
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
526 GByteArray *sha_bin;
18964
7b03727b10b4 - x509_singleuse uses the subject_name field...somewhat
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18962
diff changeset
527 gchar *cn;
7b03727b10b4 - x509_singleuse uses the subject_name field...somewhat
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18962
diff changeset
528 const gchar *cn_match;
18953
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
529 gchar *primary, *secondary;
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
530 PurpleCertificate *crt = (PurpleCertificate *) vrq->cert_chain->data;
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
531
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
532 /* Pull out the SHA1 checksum */
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
533 sha_bin = purple_certificate_get_fingerprint_sha1(crt);
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
534 /* Now decode it for display */
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
535 sha_asc = purple_base16_encode_chunked(sha_bin->data,
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
536 sha_bin->len);
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
537
18964
7b03727b10b4 - x509_singleuse uses the subject_name field...somewhat
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18962
diff changeset
538 /* Get the cert Common Name */
7b03727b10b4 - x509_singleuse uses the subject_name field...somewhat
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18962
diff changeset
539 cn = purple_certificate_get_subject_name(crt);
7b03727b10b4 - x509_singleuse uses the subject_name field...somewhat
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18962
diff changeset
540
7b03727b10b4 - x509_singleuse uses the subject_name field...somewhat
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18962
diff changeset
541 /* Determine whether the name matches */
7b03727b10b4 - x509_singleuse uses the subject_name field...somewhat
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18962
diff changeset
542 /* TODO: Worry about strcmp safety? */
7b03727b10b4 - x509_singleuse uses the subject_name field...somewhat
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18962
diff changeset
543 if (!strcmp(cn, vrq->subject_name)) {
7b03727b10b4 - x509_singleuse uses the subject_name field...somewhat
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18962
diff changeset
544 cn_match = _("");
7b03727b10b4 - x509_singleuse uses the subject_name field...somewhat
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18962
diff changeset
545 } else {
7b03727b10b4 - x509_singleuse uses the subject_name field...somewhat
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18962
diff changeset
546 cn_match = _("(DOES NOT MATCH)");
7b03727b10b4 - x509_singleuse uses the subject_name field...somewhat
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18962
diff changeset
547 }
7b03727b10b4 - x509_singleuse uses the subject_name field...somewhat
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18962
diff changeset
548
18953
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
549 /* Make messages */
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
550 primary = g_strdup_printf(_("%s has presented the following certificate for just-this-once use:"), vrq->subject_name);
18964
7b03727b10b4 - x509_singleuse uses the subject_name field...somewhat
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18962
diff changeset
551 secondary = g_strdup_printf(_("Common name: %s %s\nFingerprint (SHA1): %s"), cn, cn_match, sha_asc);
18953
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
552
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
553 /* Make a semi-pretty display */
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
554 purple_request_accept_cancel(
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
555 vrq->cb_data, /* TODO: Find what the handle ought to be */
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
556 _("Single-use Certificate Verification"),
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
557 primary,
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
558 secondary,
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
559 1, /* Accept by default */
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
560 NULL, /* No account */
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
561 NULL, /* No other user */
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
562 NULL, /* No associated conversation */
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
563 vrq,
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
564 x509_singleuse_verify_cb,
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
565 x509_singleuse_verify_cb );
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
566
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
567 /* Cleanup */
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
568 g_free(primary);
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
569 g_free(secondary);
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
570 g_free(sha_asc);
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
571 g_byte_array_free(sha_bin, TRUE);
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
572 }
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
573
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
574 static void
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
575 x509_singleuse_destroy_request (PurpleCertificateVerificationRequest *vrq)
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
576 {
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
577 /* I don't do anything! */
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
578 }
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
579
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
580 PurpleCertificateVerifier x509_singleuse = {
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
581 "x509", /* Scheme name */
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
582 "singleuse", /* Verifier name */
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
583 x509_singleuse_start_verify, /* start_verification function */
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
584 x509_singleuse_destroy_request /* Request cleanup operation */
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
585 };
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
586
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
587
18975
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
588
19093
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
589 /***** X.509 Certificate Authority pool, keyed by Distinguished Name *****/
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
590 static PurpleCertificatePool x509_ca;
18975
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
591
19093
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
592 static gboolean
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
593 x509_ca_init(void)
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
594 {
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
595 return TRUE;
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
596 }
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
597
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
598 static void
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
599 x509_ca_uninit(void)
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
600 {
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
601
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
602 }
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
603
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
604 static gboolean
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
605 x509_ca_cert_in_pool(const gchar *id)
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
606 {
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
607 gboolean ret = FALSE;
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
608
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
609 g_return_val_if_fail(id, FALSE);
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
610
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
611 return ret;
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
612 }
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
613
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
614 static PurpleCertificate *
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
615 x509_ca_get_cert(const gchar *id)
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
616 {
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
617 PurpleCertificateScheme *x509;
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
618 PurpleCertificate *crt = NULL;
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
619
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
620 g_return_val_if_fail(id, NULL);
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
621
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
622 /* Is it in the pool? */
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
623 if ( !x509_ca_cert_in_pool(id) ) {
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
624 return NULL;
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
625 }
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
626
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
627 /* Look up the X.509 scheme */
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
628 x509 = purple_certificate_find_scheme("x509");
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
629 g_return_val_if_fail(x509, NULL);
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
630
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
631 return crt;
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
632 }
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
633
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
634 static gboolean
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
635 x509_ca_put_cert(const gchar *id, PurpleCertificate *crt)
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
636 {
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
637 gboolean ret = FALSE;
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
638
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
639 g_return_val_if_fail(crt, FALSE);
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
640 g_return_val_if_fail(crt->scheme, FALSE);
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
641 /* Make sure that this is some kind of X.509 certificate */
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
642 /* TODO: Perhaps just check crt->scheme->name instead? */
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
643 g_return_val_if_fail(crt->scheme == purple_certificate_find_scheme(x509_ca.scheme_name), FALSE);
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
644
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
645 return ret;
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
646 }
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
647
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
648 static gboolean
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
649 x509_ca_delete_cert(const gchar *id)
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
650 {
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
651 gboolean ret = FALSE;
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
652
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
653 g_return_val_if_fail(id, FALSE);
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
654
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
655 /* Is the id even in the pool? */
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
656 if (!x509_ca_cert_in_pool(id)) {
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
657 purple_debug_warning("certificate/ca",
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
658 "Id %s wasn't in the pool\n",
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
659 id);
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
660 return FALSE;
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
661 }
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
662
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
663 return ret;
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
664 }
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
665
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
666 static GList *
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
667 x509_ca_get_idlist(void)
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
668 {
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
669 return NULL;
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
670 }
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
671
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
672
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
673 static PurpleCertificatePool x509_ca = {
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
674 "x509", /* Scheme name */
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
675 "ca", /* Pool name */
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
676 N_("Certificate Authorities"),/* User-friendly name */
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
677 NULL, /* Internal data */
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
678 x509_ca_init, /* init */
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
679 x509_ca_uninit, /* uninit */
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
680 x509_ca_cert_in_pool, /* Certificate exists? */
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
681 x509_ca_get_cert, /* Cert retriever */
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
682 x509_ca_put_cert, /* Cert writer */
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
683 x509_ca_delete_cert, /* Cert remover */
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
684 x509_ca_get_idlist /* idlist retriever */
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
685 };
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
686
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
687
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
688
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
689 /***** Cache of certificates given by TLS/SSL peers *****/
18975
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
690 static PurpleCertificatePool x509_tls_peers;
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
691
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
692 static gboolean
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
693 x509_tls_peers_init(void)
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
694 {
18985
806c610ac5a0 - Add init for x509_tls_peers pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18984
diff changeset
695 gchar *poolpath;
806c610ac5a0 - Add init for x509_tls_peers pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18984
diff changeset
696 int ret;
806c610ac5a0 - Add init for x509_tls_peers pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18984
diff changeset
697
806c610ac5a0 - Add init for x509_tls_peers pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18984
diff changeset
698 /* Set up key cache here if it isn't already done */
806c610ac5a0 - Add init for x509_tls_peers pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18984
diff changeset
699 poolpath = purple_certificate_pool_mkpath(&x509_tls_peers, NULL);
806c610ac5a0 - Add init for x509_tls_peers pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18984
diff changeset
700 ret = purple_build_dir(poolpath, 0700); /* Make it this user only */
18975
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
701
18985
806c610ac5a0 - Add init for x509_tls_peers pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18984
diff changeset
702 g_free(poolpath);
806c610ac5a0 - Add init for x509_tls_peers pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18984
diff changeset
703
806c610ac5a0 - Add init for x509_tls_peers pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18984
diff changeset
704 g_return_val_if_fail(ret == 0, FALSE);
18975
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
705 return TRUE;
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
706 }
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
707
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
708 static gboolean
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
709 x509_tls_peers_cert_in_pool(const gchar *id)
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
710 {
18987
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
711 gchar *keypath;
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
712 gboolean ret = FALSE;
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
713
18975
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
714 g_return_val_if_fail(id, FALSE);
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
715
18987
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
716 keypath = purple_certificate_pool_mkpath(&x509_tls_peers, id);
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
717
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
718 ret = g_file_test(keypath, G_FILE_TEST_IS_REGULAR);
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
719
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
720 g_free(keypath);
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
721 return ret;
18975
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
722 }
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
723
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
724 static PurpleCertificate *
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
725 x509_tls_peers_get_cert(const gchar *id)
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
726 {
18987
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
727 PurpleCertificateScheme *x509;
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
728 PurpleCertificate *crt;
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
729 gchar *keypath;
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
730
18975
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
731 g_return_val_if_fail(id, NULL);
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
732
18987
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
733 /* Is it in the pool? */
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
734 if ( !x509_tls_peers_cert_in_pool(id) ) {
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
735 return NULL;
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
736 }
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
737
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
738 /* Look up the X.509 scheme */
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
739 x509 = purple_certificate_find_scheme("x509");
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
740 g_return_val_if_fail(x509, NULL);
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
741
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
742 /* Okay, now find and load that key */
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
743 keypath = purple_certificate_pool_mkpath(&x509_tls_peers, id);
18990
3f2944bdb404 - Finish tls_peers get_cert
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18989
diff changeset
744 crt = purple_certificate_import(x509, keypath);
18987
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
745
18990
3f2944bdb404 - Finish tls_peers get_cert
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18989
diff changeset
746 g_free(keypath);
18987
a763dd083b79 - Finished tls_peers cert_in_pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18986
diff changeset
747
18990
3f2944bdb404 - Finish tls_peers get_cert
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18989
diff changeset
748 return crt;
18975
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
749 }
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
750
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
751 static gboolean
18982
8948cd6bb8bc - CertificatePool put_cert now accepts an id argument
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18977
diff changeset
752 x509_tls_peers_put_cert(const gchar *id, PurpleCertificate *crt)
18975
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
753 {
18991
7a144f2229c6 - Add tls_peers put_cert
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18990
diff changeset
754 gboolean ret = FALSE;
7a144f2229c6 - Add tls_peers put_cert
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18990
diff changeset
755 gchar *keypath;
18975
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
756
18991
7a144f2229c6 - Add tls_peers put_cert
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18990
diff changeset
757 g_return_val_if_fail(crt, FALSE);
7a144f2229c6 - Add tls_peers put_cert
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18990
diff changeset
758 g_return_val_if_fail(crt->scheme, FALSE);
7a144f2229c6 - Add tls_peers put_cert
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18990
diff changeset
759 /* Make sure that this is some kind of X.509 certificate */
18992
605e69fa7108 - Comment change
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18991
diff changeset
760 /* TODO: Perhaps just check crt->scheme->name instead? */
18991
7a144f2229c6 - Add tls_peers put_cert
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18990
diff changeset
761 g_return_val_if_fail(crt->scheme == purple_certificate_find_scheme(x509_tls_peers.scheme_name), FALSE);
7a144f2229c6 - Add tls_peers put_cert
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18990
diff changeset
762
7a144f2229c6 - Add tls_peers put_cert
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18990
diff changeset
763 /* Work out the filename and export */
7a144f2229c6 - Add tls_peers put_cert
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18990
diff changeset
764 keypath = purple_certificate_pool_mkpath(&x509_tls_peers, id);
7a144f2229c6 - Add tls_peers put_cert
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18990
diff changeset
765 ret = purple_certificate_export(keypath, crt);
7a144f2229c6 - Add tls_peers put_cert
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18990
diff changeset
766
7a144f2229c6 - Add tls_peers put_cert
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18990
diff changeset
767 g_free(keypath);
7a144f2229c6 - Add tls_peers put_cert
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18990
diff changeset
768 return ret;
18975
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
769 }
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
770
19047
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
771 static gboolean
19048
fd0b4b2f6cf0 - remove_cert => delete_cert, because naming conventions are our
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19047
diff changeset
772 x509_tls_peers_delete_cert(const gchar *id)
19047
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
773 {
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
774 gboolean ret = FALSE;
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
775 gchar *keypath;
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
776
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
777 g_return_val_if_fail(id, FALSE);
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
778
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
779 /* Is the id even in the pool? */
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
780 if (!x509_tls_peers_cert_in_pool(id)) {
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
781 purple_debug_warning("certificate/tls_peers",
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
782 "Id %s wasn't in the pool\n",
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
783 id);
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
784 return FALSE;
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
785 }
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
786
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
787 /* OK, so work out the keypath and delete the thing */
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
788 keypath = purple_certificate_pool_mkpath(&x509_tls_peers, id);
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
789 if ( unlink(keypath) != 0 ) {
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
790 purple_debug_error("certificate/tls_peers",
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
791 "Unlink of %s failed!\n",
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
792 keypath);
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
793 ret = FALSE;
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
794 } else {
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
795 ret = TRUE;
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
796 }
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
797
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
798 g_free(keypath);
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
799 return ret;
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
800 }
3af5d9ed9ad3 - Write remove_cert function for tls_peers Pool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19046
diff changeset
801
19027
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
802 static GList *
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
803 x509_tls_peers_get_idlist(void)
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
804 {
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
805 GList *idlist = NULL;
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
806 GDir *dir;
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
807 const gchar *entry;
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
808 gchar *poolpath;
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
809
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
810 /* Get a handle on the pool directory */
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
811 poolpath = purple_certificate_pool_mkpath(&x509_tls_peers, NULL);
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
812 dir = g_dir_open(poolpath,
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
813 0, /* No flags */
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
814 NULL); /* Not interested in what the error is */
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
815 g_free(poolpath);
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
816
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
817 g_return_val_if_fail(dir, NULL);
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
818
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
819 /* Traverse the directory listing and create an idlist */
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
820 while ( (entry = g_dir_read_name(dir)) != NULL ) {
19078
3987f76c0e4b - tls_peers pool unescapes filenames in its directory, as it should
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19077
diff changeset
821 /* Unescape the filename */
3987f76c0e4b - tls_peers pool unescapes filenames in its directory, as it should
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19077
diff changeset
822 const char *unescaped = purple_unescape_filename(entry);
3987f76c0e4b - tls_peers pool unescapes filenames in its directory, as it should
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19077
diff changeset
823
19027
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
824 /* Copy the entry name into our list (GLib owns the original
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
825 string) */
19078
3987f76c0e4b - tls_peers pool unescapes filenames in its directory, as it should
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19077
diff changeset
826 idlist = g_list_prepend(idlist, g_strdup(unescaped));
19027
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
827 }
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
828
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
829 /* Release the directory */
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
830 g_dir_close(dir);
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
831
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
832 return idlist;
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
833 }
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
834
18975
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
835 static PurpleCertificatePool x509_tls_peers = {
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
836 "x509", /* Scheme name */
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
837 "tls_peers", /* Pool name */
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
838 N_("SSL Peers Cache"), /* User-friendly name */
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
839 NULL, /* Internal data */
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
840 x509_tls_peers_init, /* init */
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
841 NULL, /* uninit not required */
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
842 x509_tls_peers_cert_in_pool, /* Certificate exists? */
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
843 x509_tls_peers_get_cert, /* Cert retriever */
19026
b3acaf46d9ad - Add pool_get_idlist / pool_destroy_idlist
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19024
diff changeset
844 x509_tls_peers_put_cert, /* Cert writer */
19049
8cbc110456ac - Add purple_certificate_pool_delete
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19048
diff changeset
845 x509_tls_peers_delete_cert, /* Cert remover */
19027
15d9031e03b2 - Add get_idlist support to tls_peers CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19026
diff changeset
846 x509_tls_peers_get_idlist /* idlist retriever */
18975
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
847 };
18993
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
848
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
849
19093
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
850 /***** A Verifier that uses the tls_peers cache and the CA pool to validate certificates *****/
18993
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
851 static PurpleCertificateVerifier x509_tls_cached;
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
852
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
853 static void
19085
1bd9557f866e In tls_cached Verifier:
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19084
diff changeset
854 x509_tls_cached_user_auth_cb (PurpleCertificateVerificationRequest *vrq, gint id)
19001
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
855 {
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
856 PurpleCertificatePool *tls_peers;
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
857
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
858 g_return_if_fail(vrq);
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
859
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
860 tls_peers = purple_certificate_find_pool("x509","tls_peers");
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
861
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
862 if (1 == id) {
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
863 gchar *cache_id = vrq->subject_name;
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
864 purple_debug_info("certificate/x509/tls_cached",
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
865 "User ACCEPTED cert\nCaching first in chain for future use as %s...\n",
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
866 cache_id);
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
867
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
868 purple_certificate_pool_store(tls_peers, cache_id,
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
869 vrq->cert_chain->data);
19091
489889091b14 - Remove all usage of purple_certificate_verify_destroy, as it is
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19090
diff changeset
870
489889091b14 - Remove all usage of purple_certificate_verify_destroy, as it is
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19090
diff changeset
871 purple_certificate_verify_complete(vrq,
489889091b14 - Remove all usage of purple_certificate_verify_destroy, as it is
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19090
diff changeset
872 PURPLE_CERTIFICATE_VALID);
19001
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
873 } else {
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
874 purple_debug_info("certificate/x509/tls_cached",
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
875 "User REJECTED cert\n");
19091
489889091b14 - Remove all usage of purple_certificate_verify_destroy, as it is
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19090
diff changeset
876 purple_certificate_verify_complete(vrq,
489889091b14 - Remove all usage of purple_certificate_verify_destroy, as it is
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19090
diff changeset
877 PURPLE_CERTIFICATE_INVALID);
19001
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
878 }
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
879 }
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
880
19085
1bd9557f866e In tls_cached Verifier:
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19084
diff changeset
881 /* Validates a certificate by asking the user */
19001
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
882 static void
19085
1bd9557f866e In tls_cached Verifier:
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19084
diff changeset
883 x509_tls_cached_user_auth(PurpleCertificateVerificationRequest *vrq)
19000
986413850713 - More skeletonizing for tls_cached logic.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18999
diff changeset
884 {
19001
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
885 gchar *sha_asc;
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
886 GByteArray *sha_bin;
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
887 gchar *cn;
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
888 const gchar *cn_match;
19014
bc4d0ebeabd3 - Add expiration/activation time display to tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19012
diff changeset
889 time_t activation, expiration;
bc4d0ebeabd3 - Add expiration/activation time display to tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19012
diff changeset
890 /* Length of these buffers is dictated by 'man ctime_r' */
bc4d0ebeabd3 - Add expiration/activation time display to tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19012
diff changeset
891 gchar activ_str[26], expir_str[26];
19001
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
892 gchar *primary, *secondary;
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
893 PurpleCertificate *crt = (PurpleCertificate *) vrq->cert_chain->data;
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
894
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
895 /* Pull out the SHA1 checksum */
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
896 sha_bin = purple_certificate_get_fingerprint_sha1(crt);
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
897 /* Now decode it for display */
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
898 sha_asc = purple_base16_encode_chunked(sha_bin->data,
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
899 sha_bin->len);
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
900
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
901 /* Get the cert Common Name */
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
902 cn = purple_certificate_get_subject_name(crt);
19000
986413850713 - More skeletonizing for tls_cached logic.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18999
diff changeset
903
19001
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
904 /* Determine whether the name matches */
19008
7fd9bd55f8d0 - Add certificate_check_subject_name and associated machinery
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19001
diff changeset
905 if (purple_certificate_check_subject_name(crt, vrq->subject_name)) {
19001
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
906 cn_match = _("");
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
907 } else {
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
908 cn_match = _("(DOES NOT MATCH)");
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
909 }
19014
bc4d0ebeabd3 - Add expiration/activation time display to tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19012
diff changeset
910
bc4d0ebeabd3 - Add expiration/activation time display to tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19012
diff changeset
911 /* Get the certificate times */
bc4d0ebeabd3 - Add expiration/activation time display to tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19012
diff changeset
912 /* TODO: Check the times against localtime */
bc4d0ebeabd3 - Add expiration/activation time display to tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19012
diff changeset
913 /* TODO: errorcheck? */
bc4d0ebeabd3 - Add expiration/activation time display to tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19012
diff changeset
914 g_assert(purple_certificate_get_times(crt, &activation, &expiration));
bc4d0ebeabd3 - Add expiration/activation time display to tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19012
diff changeset
915 ctime_r(&activation, activ_str);
bc4d0ebeabd3 - Add expiration/activation time display to tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19012
diff changeset
916 ctime_r(&expiration, expir_str);
19001
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
917
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
918 /* Make messages */
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
919 primary = g_strdup_printf(_("%s has presented the following certificate:"), vrq->subject_name);
19014
bc4d0ebeabd3 - Add expiration/activation time display to tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19012
diff changeset
920 secondary = g_strdup_printf(_("Common name: %s %s\n\nFingerprint (SHA1): %s\n\nActivation date: %s\nExpiration date: %s\n"), cn, cn_match, sha_asc, activ_str, expir_str);
19001
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
921
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
922 /* Make a semi-pretty display */
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
923 purple_request_accept_cancel(
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
924 vrq->cb_data, /* TODO: Find what the handle ought to be */
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
925 _("SSL Certificate Verification"),
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
926 primary,
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
927 secondary,
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
928 1, /* Accept by default */
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
929 NULL, /* No account */
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
930 NULL, /* No other user */
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
931 NULL, /* No associated conversation */
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
932 vrq,
19085
1bd9557f866e In tls_cached Verifier:
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19084
diff changeset
933 x509_tls_cached_user_auth_cb,
1bd9557f866e In tls_cached Verifier:
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19084
diff changeset
934 x509_tls_cached_user_auth_cb );
19001
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
935
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
936 /* Cleanup */
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
937 g_free(primary);
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
938 g_free(secondary);
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
939 g_free(sha_asc);
b207701cb5a3 - Wrote the logic for the "previously unknown host" condition in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19000
diff changeset
940 g_byte_array_free(sha_bin, TRUE);
19000
986413850713 - More skeletonizing for tls_cached logic.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18999
diff changeset
941 }
986413850713 - More skeletonizing for tls_cached logic.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18999
diff changeset
942
986413850713 - More skeletonizing for tls_cached logic.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18999
diff changeset
943 static void
986413850713 - More skeletonizing for tls_cached logic.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18999
diff changeset
944 x509_tls_cached_peer_cert_changed(PurpleCertificateVerificationRequest *vrq)
986413850713 - More skeletonizing for tls_cached logic.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18999
diff changeset
945 {
986413850713 - More skeletonizing for tls_cached logic.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18999
diff changeset
946 /* TODO: Prompt the user, etc. */
986413850713 - More skeletonizing for tls_cached logic.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18999
diff changeset
947
19091
489889091b14 - Remove all usage of purple_certificate_verify_destroy, as it is
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19090
diff changeset
948 purple_debug_info("certificate/x509/tls_cached",
489889091b14 - Remove all usage of purple_certificate_verify_destroy, as it is
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19090
diff changeset
949 "Certificate for %s does not match cached. "
489889091b14 - Remove all usage of purple_certificate_verify_destroy, as it is
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19090
diff changeset
950 "Auto-rejecting!\n",
489889091b14 - Remove all usage of purple_certificate_verify_destroy, as it is
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19090
diff changeset
951 vrq->subject_name);
489889091b14 - Remove all usage of purple_certificate_verify_destroy, as it is
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19090
diff changeset
952
489889091b14 - Remove all usage of purple_certificate_verify_destroy, as it is
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19090
diff changeset
953 purple_certificate_verify_complete(vrq, PURPLE_CERTIFICATE_INVALID);
19000
986413850713 - More skeletonizing for tls_cached logic.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18999
diff changeset
954 return;
986413850713 - More skeletonizing for tls_cached logic.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18999
diff changeset
955 }
986413850713 - More skeletonizing for tls_cached logic.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18999
diff changeset
956
19086
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
957 static void
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
958 x509_tls_cached_cert_in_cache(PurpleCertificateVerificationRequest *vrq)
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
959 {
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
960 /* TODO: Looking this up by name over and over is expensive.
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
961 Fix, please! */
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
962 PurpleCertificatePool *tls_peers =
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
963 purple_certificate_find_pool(x509_tls_cached.scheme_name,
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
964 "tls_peers");
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
965
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
966 /* The peer's certificate should be the first in the list */
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
967 PurpleCertificate *peer_crt =
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
968 (PurpleCertificate *) vrq->cert_chain->data;
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
969
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
970 PurpleCertificate *cached_crt;
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
971 GByteArray *peer_fpr, *cached_fpr;
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
972
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
973 /* Load up the cached certificate */
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
974 cached_crt = purple_certificate_pool_retrieve(
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
975 tls_peers, vrq->subject_name);
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
976 g_assert(cached_crt);
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
977
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
978 /* Now get SHA1 sums for both and compare them */
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
979 /* TODO: This is not an elegant way to compare certs */
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
980 peer_fpr = purple_certificate_get_fingerprint_sha1(peer_crt);
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
981 cached_fpr = purple_certificate_get_fingerprint_sha1(cached_crt);
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
982 if (!memcmp(peer_fpr->data, cached_fpr->data, peer_fpr->len)) {
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
983 purple_debug_info("certificate/x509/tls_cached",
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
984 "Peer cert matched cached\n");
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
985 /* vrq is now finished */
19091
489889091b14 - Remove all usage of purple_certificate_verify_destroy, as it is
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19090
diff changeset
986 purple_certificate_verify_complete(vrq,
489889091b14 - Remove all usage of purple_certificate_verify_destroy, as it is
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19090
diff changeset
987 PURPLE_CERTIFICATE_VALID);
19086
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
988 } else {
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
989 purple_debug_info("certificate/x509/tls_cached",
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
990 "Peer cert did NOT match cached\n");
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
991 /* vrq now becomes the problem of cert_changed */
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
992 x509_tls_cached_peer_cert_changed(vrq);
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
993 }
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
994
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
995 purple_certificate_destroy(cached_crt);
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
996 g_byte_array_free(peer_fpr, TRUE);
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
997 g_byte_array_free(cached_fpr, TRUE);
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
998 }
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
999
19085
1bd9557f866e In tls_cached Verifier:
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19084
diff changeset
1000 /* For when we've never communicated with this party before */
1bd9557f866e In tls_cached Verifier:
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19084
diff changeset
1001 static void
1bd9557f866e In tls_cached Verifier:
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19084
diff changeset
1002 x509_tls_cached_unknown_peer(PurpleCertificateVerificationRequest *vrq)
1bd9557f866e In tls_cached Verifier:
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19084
diff changeset
1003 {
19089
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1004 PurpleCertificatePool *ca, *tls_peers;
19090
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1005 PurpleCertificate *end_crt, *ca_crt, *peer_crt;
19089
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1006 GList *chain = vrq->cert_chain;
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1007 GList *last;
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1008 gchar *ca_id;
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1009
19090
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1010 peer_crt = (PurpleCertificate *) chain->data;
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1011
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1012 /* First, check that the hostname matches */
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1013 if ( ! purple_certificate_check_subject_name(peer_crt,
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1014 vrq->subject_name) ) {
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1015 gchar *sn = purple_certificate_get_subject_name(peer_crt);
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1016
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1017 purple_debug_info("certificate/x509/tls_cached",
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1018 "Name mismatch: Certificate given for %s "
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1019 "has a name of %s\n",
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1020 vrq->subject_name, sn);
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1021 g_free(sn);
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1022
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1023 /* Prompt the user to authenticate the certificate */
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1024 /* TODO: Provide the user with more guidance about why he is
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1025 being prompted */
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1026 /* vrq will be completed by user_auth */
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1027 x509_tls_cached_user_auth(vrq);
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1028 return;
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1029 } /* if (name mismatch) */
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1030
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1031
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1032
5310b1294287 - Add HOSTNAME CHECKING to tls_cached unknown_peer mode, which is kind
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19089
diff changeset
1033 /* Next, check that the certificate chain is valid */
19089
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1034 if ( ! purple_certificate_check_signature_chain(chain) ) {
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1035 /* TODO: Tell the user where the chain broke? */
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1036 /* TODO: This error will hopelessly confuse any
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1037 non-elite user. */
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1038 gchar *secondary;
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1039
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1040 secondary = g_strdup_printf(_("The certificate chain presented"
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1041 " for %s is not valid."),
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1042 vrq->subject_name);
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1043
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1044 /* TODO: Make this error either block the ensuing SSL
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1045 connection error until the user dismisses this one, or
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1046 stifle it. */
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1047 purple_notify_error(NULL, /* TODO: Probably wrong. */
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1048 _("SSL Certificate Error"),
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1049 _("Invalid certificate chain"),
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1050 secondary );
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1051 g_free(secondary);
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1052
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1053 /* Okay, we're done here */
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1054 purple_certificate_verify_complete(vrq,
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1055 PURPLE_CERTIFICATE_INVALID);
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1056 } /* if (signature chain not good) */
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1057
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1058 /* Next, attempt to verify the last certificate against a CA */
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1059 ca = purple_certificate_find_pool(x509_tls_cached.scheme_name, "ca");
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1060
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1061 /* If, for whatever reason, there is no Certificate Authority pool
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1062 loaded, we will simply present it to the user for checking. */
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1063 if ( !ca ) {
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1064 purple_debug_error("certificate/x509/tls_cached",
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1065 "No X.509 Certificate Authority pool "
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1066 "could be found!\n");
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1067
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1068 /* vrq will be completed by user_auth */
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1069 x509_tls_cached_user_auth(vrq);
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1070 return;
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1071 }
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1072
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1073 /* TODO: I don't have the Glib documentation handy; is this correct? */
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1074 last = g_list_last(chain);
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1075 end_crt = (PurpleCertificate *) last->data;
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1076
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1077 /* Attempt to look up the last certificate's issuer */
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1078 ca_id = purple_certificate_get_issuer_unique_id(end_crt);
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1079 if ( !purple_certificate_pool_contains(ca, ca_id) ) {
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1080 purple_debug_info("certificate/x509/tls_cached",
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1081 "Certificate Authority with DN='%s' not "
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1082 "found. I'll prompt the user, I guess.\n",
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1083 ca_id);
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1084 g_free(ca_id);
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1085 /* vrq will be completed by user_auth */
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1086 x509_tls_cached_user_auth(vrq);
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1087 return;
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1088 }
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1089
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1090 ca_crt = purple_certificate_pool_retrieve(ca, ca_id);
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1091 g_free(ca_id);
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1092 g_assert(ca_crt);
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1093
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1094 /* Check the signature */
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1095 if ( !purple_certificate_signed_by(end_crt, ca_crt) ) {
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1096 /* TODO: If signed_by ever returns a reason, maybe mention
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1097 that, too. */
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1098 /* TODO: Also mention the CA involved. While I could do this
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1099 now, a full DN is a little much with which to assault the
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1100 user's poor, leaky eyes. */
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1101 /* TODO: This error message makes my eyes cross, and I wrote it */
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1102 gchar * secondary =
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1103 g_strdup_printf(_("The certificate chain presented by "
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1104 "%s does not have a valid digital "
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1105 "signature from the Certificate "
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1106 "Authority it claims to have one "
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1107 "from."),
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1108 vrq->subject_name);
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1109
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1110 purple_notify_error(NULL, /* TODO: Probably wrong */
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1111 _("SSL Certificate Error"),
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1112 _("Invalid certificate authority"
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1113 " signature"),
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1114 secondary);
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1115 g_free(secondary);
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1116
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1117 /* Signal "bad cert" */
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1118 purple_certificate_verify_complete(vrq,
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1119 PURPLE_CERTIFICATE_INVALID);
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1120 return;
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1121 } /* if (CA signature not good) */
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1122
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1123 /* If we reach this point, the certificate is good. */
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1124 /* Look up the local cache and store it there for future use */
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1125 tls_peers = purple_certificate_find_pool(x509_tls_cached.scheme_name,
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1126 "tls_peers");
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1127
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1128 if (tls_peers) {
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1129 g_assert(purple_certificate_pool_store(tls_peers,
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1130 vrq->subject_name,
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1131 peer_crt) );
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1132 } else {
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1133 purple_debug_error("certificate/x509/tls_cached",
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1134 "Unable to locate tls_peers certificate "
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1135 "cache.\n");
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1136 }
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1137
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1138 /* Whew! Done! */
c8962b52579e - Wrote a tls_cached unknown_peer function that does many fun things,
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19088
diff changeset
1139 purple_certificate_verify_complete(vrq, PURPLE_CERTIFICATE_VALID);
19085
1bd9557f866e In tls_cached Verifier:
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19084
diff changeset
1140 }
1bd9557f866e In tls_cached Verifier:
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19084
diff changeset
1141
19000
986413850713 - More skeletonizing for tls_cached logic.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18999
diff changeset
1142 static void
18993
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
1143 x509_tls_cached_start_verify(PurpleCertificateVerificationRequest *vrq)
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
1144 {
18999
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1145 const gchar *tls_peers_name = "tls_peers"; /* Name of local cache */
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1146 PurpleCertificatePool *tls_peers;
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1147
18993
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
1148 g_return_if_fail(vrq);
18999
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1149
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1150 purple_debug_info("certificate/x509/tls_cached",
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1151 "Starting verify for %s\n",
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1152 vrq->subject_name);
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1153
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1154 tls_peers = purple_certificate_find_pool(x509_tls_cached.scheme_name,tls_peers_name);
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1155
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1156 /* TODO: This should probably just prompt the user instead of throwing
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1157 an angry fit */
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1158 if (!tls_peers) {
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1159 purple_debug_error("certificate/x509/tls_cached",
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1160 "Couldn't find local peers cache %s\nReturning INVALID to callback\n",
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1161 tls_peers_name);
19091
489889091b14 - Remove all usage of purple_certificate_verify_destroy, as it is
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19090
diff changeset
1162
489889091b14 - Remove all usage of purple_certificate_verify_destroy, as it is
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19090
diff changeset
1163 purple_certificate_verify_complete(vrq,
489889091b14 - Remove all usage of purple_certificate_verify_destroy, as it is
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19090
diff changeset
1164 PURPLE_CERTIFICATE_INVALID);
18999
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1165 return;
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1166 }
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1167
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1168 /* Check if the peer has a certificate cached already */
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1169 purple_debug_info("certificate/x509/tls_cached",
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1170 "Checking for cached cert...\n");
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1171 if (purple_certificate_pool_contains(tls_peers, vrq->subject_name)) {
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1172 purple_debug_info("certificate/x509/tls_cached",
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1173 "...Found cached cert\n");
19086
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
1174 /* vrq is now the responsibility of cert_in_cache */
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
1175 x509_tls_cached_cert_in_cache(vrq);
e256e0bf8ae1 - Move "certificate found in cache" out of tls_cached_start_verify into
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19085
diff changeset
1176 } else {
18999
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1177 /* TODO: Prompt the user, etc. */
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1178 purple_debug_info("certificate/x509/tls_cached",
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1179 "...Not in cache\n");
19000
986413850713 - More skeletonizing for tls_cached logic.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18999
diff changeset
1180 /* vrq now becomes the problem of unknown_peer */
986413850713 - More skeletonizing for tls_cached logic.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18999
diff changeset
1181 x509_tls_cached_unknown_peer(vrq);
18999
7fbd0a6ac8d6 - Made a logic skeleton for tls_cached verifier
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18996
diff changeset
1182 }
18993
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
1183 }
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
1184
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
1185 static void
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
1186 x509_tls_cached_destroy_request(PurpleCertificateVerificationRequest *vrq)
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
1187 {
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
1188 g_return_if_fail(vrq);
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
1189 }
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
1190
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
1191 static PurpleCertificateVerifier x509_tls_cached = {
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
1192 "x509", /* Scheme name */
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
1193 "tls_cached", /* Verifier name */
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
1194 x509_tls_cached_start_verify, /* Verification begin */
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
1195 x509_tls_cached_destroy_request /* Request cleanup */
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
1196 };
18975
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
1197
18950
f78a9efa9eaf - Add purple_certificate_register_builtins
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18949
diff changeset
1198 /****************************************************************************/
f78a9efa9eaf - Add purple_certificate_register_builtins
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18949
diff changeset
1199 /* Subsystem */
f78a9efa9eaf - Add purple_certificate_register_builtins
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18949
diff changeset
1200 /****************************************************************************/
f78a9efa9eaf - Add purple_certificate_register_builtins
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18949
diff changeset
1201 void
18957
9205841eed06 - Certificate system now has init and uninit like other systems
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18953
diff changeset
1202 purple_certificate_init(void)
18950
f78a9efa9eaf - Add purple_certificate_register_builtins
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18949
diff changeset
1203 {
18957
9205841eed06 - Certificate system now has init and uninit like other systems
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18953
diff changeset
1204 /* Register builtins */
18953
89b32569890c - Add purple_certificate_get_fingerprint_sha1
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18952
diff changeset
1205 purple_certificate_register_verifier(&x509_singleuse);
19093
f96b53df8d17 - Add skeleton for X.509 Certificate Authority (x509_ca) CertificatePool
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19092
diff changeset
1206 purple_certificate_register_pool(&x509_ca);
18975
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
1207 purple_certificate_register_pool(&x509_tls_peers);
18993
33fb4930ad2b - Add x509_tls_cached skeleton
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18992
diff changeset
1208 purple_certificate_register_verifier(&x509_tls_cached);
18950
f78a9efa9eaf - Add purple_certificate_register_builtins
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18949
diff changeset
1209 }
18946
617447a71ab7 - Add certificate_destroy and certificate_destroy_list
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18943
diff changeset
1210
18957
9205841eed06 - Certificate system now has init and uninit like other systems
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18953
diff changeset
1211 void
9205841eed06 - Certificate system now has init and uninit like other systems
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18953
diff changeset
1212 purple_certificate_uninit(void)
9205841eed06 - Certificate system now has init and uninit like other systems
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18953
diff changeset
1213 {
19024
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1214 GList *full_list, *l;
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1215
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1216 /* Unregister all Schemes */
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1217 full_list = g_list_copy(cert_schemes); /* Make a working copy */
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1218 for (l = full_list; l; l = l->next) {
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1219 purple_certificate_unregister_scheme(
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1220 (PurpleCertificateScheme *) l->data );
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1221 }
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1222 g_list_free(full_list);
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1223
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1224 /* Unregister all Verifiers */
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1225 full_list = g_list_copy(cert_verifiers); /* Make a working copy */
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1226 for (l = full_list; l; l = l->next) {
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1227 purple_certificate_unregister_verifier(
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1228 (PurpleCertificateVerifier *) l->data );
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1229 }
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1230 g_list_free(full_list);
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1231
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1232 /* Unregister all Pools */
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1233 full_list = g_list_copy(cert_pools); /* Make a working copy */
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1234 for (l = full_list; l; l = l->next) {
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1235 purple_certificate_unregister_pool(
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1236 (PurpleCertificatePool *) l->data );
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1237 }
264f00bc8f22 - Change certificate_uninit to unregister all Pools, Schemes, and
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19023
diff changeset
1238 g_list_free(full_list);
18957
9205841eed06 - Certificate system now has init and uninit like other systems
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18953
diff changeset
1239 }
9205841eed06 - Certificate system now has init and uninit like other systems
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18953
diff changeset
1240
19022
1f07f96dc1ce - Add purple_certificate_get_handle
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19021
diff changeset
1241 gpointer
1f07f96dc1ce - Add purple_certificate_get_handle
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19021
diff changeset
1242 purple_certificate_get_handle(void)
1f07f96dc1ce - Add purple_certificate_get_handle
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19021
diff changeset
1243 {
1f07f96dc1ce - Add purple_certificate_get_handle
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19021
diff changeset
1244 static gint handle;
1f07f96dc1ce - Add purple_certificate_get_handle
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19021
diff changeset
1245 return &handle;
1f07f96dc1ce - Add purple_certificate_get_handle
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19021
diff changeset
1246 }
1f07f96dc1ce - Add purple_certificate_get_handle
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19021
diff changeset
1247
18192
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1248 PurpleCertificateScheme *
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1249 purple_certificate_find_scheme(const gchar *name)
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1250 {
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1251 PurpleCertificateScheme *scheme = NULL;
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1252 GList *l;
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1253
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1254 g_return_val_if_fail(name, NULL);
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1255
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1256 /* Traverse the list of registered schemes and locate the
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1257 one whose name matches */
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1258 for(l = cert_schemes; l; l = l->next) {
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1259 scheme = (PurpleCertificateScheme *)(l->data);
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1260
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1261 /* Name matches? that's our man */
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1262 if(!g_ascii_strcasecmp(scheme->name, name))
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1263 return scheme;
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1264 }
17910
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
1265
18192
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1266 purple_debug_warning("certificate",
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1267 "CertificateScheme %s requested but not found.\n",
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1268 name);
17910
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
1269
18192
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1270 /* TODO: Signalling and such? */
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1271
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1272 return NULL;
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1273 }
17910
668a294f9a72 - Added certificate.[ch] and got them integrated into the build
William Ehlhardt <williamehlhardt@gmail.com>
parents:
diff changeset
1274
19023
eb86ff3ba21a - Add get_pools, get_verifiers, and get_schemes
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19022
diff changeset
1275 GList *
eb86ff3ba21a - Add get_pools, get_verifiers, and get_schemes
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19022
diff changeset
1276 purple_certificate_get_schemes(void)
eb86ff3ba21a - Add get_pools, get_verifiers, and get_schemes
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19022
diff changeset
1277 {
eb86ff3ba21a - Add get_pools, get_verifiers, and get_schemes
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19022
diff changeset
1278 return cert_schemes;
eb86ff3ba21a - Add get_pools, get_verifiers, and get_schemes
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19022
diff changeset
1279 }
eb86ff3ba21a - Add get_pools, get_verifiers, and get_schemes
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19022
diff changeset
1280
18192
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1281 gboolean
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1282 purple_certificate_register_scheme(PurpleCertificateScheme *scheme)
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1283 {
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1284 g_return_val_if_fail(scheme != NULL, FALSE);
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1285
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1286 /* Make sure no scheme is registered with the same name */
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1287 if (purple_certificate_find_scheme(scheme->name) != NULL) {
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1288 return FALSE;
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1289 }
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1290
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1291 /* Okay, we're golden. Register it. */
18972
486563a6bb5c - prepend > append
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18971
diff changeset
1292 cert_schemes = g_list_prepend(cert_schemes, scheme);
18192
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1293
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1294 /* TODO: Signalling and such? */
19063
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1295
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1296 purple_debug_info("certificate",
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1297 "CertificateScheme %s registered\n",
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1298 scheme->name);
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1299
18192
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1300 return TRUE;
dc7e7b8bdc8c - Add chunks of the certificate scheme registration interface
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17913
diff changeset
1301 }
18926
8c4d52bc0319 - Add unregister_scheme
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18192
diff changeset
1302
8c4d52bc0319 - Add unregister_scheme
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18192
diff changeset
1303 gboolean
8c4d52bc0319 - Add unregister_scheme
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18192
diff changeset
1304 purple_certificate_unregister_scheme(PurpleCertificateScheme *scheme)
8c4d52bc0319 - Add unregister_scheme
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18192
diff changeset
1305 {
8c4d52bc0319 - Add unregister_scheme
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18192
diff changeset
1306 if (NULL == scheme) {
8c4d52bc0319 - Add unregister_scheme
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18192
diff changeset
1307 purple_debug_warning("certificate",
18973
28673b6fb8a2 - Fix some errors and return values
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18972
diff changeset
1308 "Attempting to unregister NULL scheme\n");
28673b6fb8a2 - Fix some errors and return values
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18972
diff changeset
1309 return FALSE;
18926
8c4d52bc0319 - Add unregister_scheme
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18192
diff changeset
1310 }
8c4d52bc0319 - Add unregister_scheme
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18192
diff changeset
1311
8c4d52bc0319 - Add unregister_scheme
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18192
diff changeset
1312 /* TODO: signalling? */
8c4d52bc0319 - Add unregister_scheme
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18192
diff changeset
1313
18941
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1314 /* TODO: unregister all CertificateVerifiers for this scheme?*/
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1315 /* TODO: unregister all CertificatePools for this scheme? */
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1316 /* Neither of the above should be necessary, though */
18926
8c4d52bc0319 - Add unregister_scheme
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18192
diff changeset
1317 cert_schemes = g_list_remove(cert_schemes, scheme);
8c4d52bc0319 - Add unregister_scheme
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18192
diff changeset
1318
19063
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1319 purple_debug_info("certificate",
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1320 "CertificateScheme %s unregistered\n",
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1321 scheme->name);
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1322
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1323
18926
8c4d52bc0319 - Add unregister_scheme
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18192
diff changeset
1324 return TRUE;
8c4d52bc0319 - Add unregister_scheme
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18192
diff changeset
1325 }
18941
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1326
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1327 PurpleCertificateVerifier *
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1328 purple_certificate_find_verifier(const gchar *scheme_name, const gchar *ver_name)
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1329 {
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1330 PurpleCertificateVerifier *vr = NULL;
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1331 GList *l;
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1332
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1333 g_return_val_if_fail(scheme_name, NULL);
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1334 g_return_val_if_fail(ver_name, NULL);
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1335
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1336 /* Traverse the list of registered verifiers and locate the
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1337 one whose name matches */
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1338 for(l = cert_verifiers; l; l = l->next) {
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1339 vr = (PurpleCertificateVerifier *)(l->data);
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1340
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1341 /* Scheme and name match? */
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1342 if(!g_ascii_strcasecmp(vr->scheme_name, scheme_name) &&
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1343 !g_ascii_strcasecmp(vr->name, ver_name))
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1344 return vr;
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1345 }
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1346
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1347 purple_debug_warning("certificate",
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1348 "CertificateVerifier %s, %s requested but not found.\n",
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1349 scheme_name, ver_name);
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1350
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1351 /* TODO: Signalling and such? */
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1352
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1353 return NULL;
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1354 }
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1355
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1356
19023
eb86ff3ba21a - Add get_pools, get_verifiers, and get_schemes
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19022
diff changeset
1357 GList *
eb86ff3ba21a - Add get_pools, get_verifiers, and get_schemes
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19022
diff changeset
1358 purple_certificate_get_verifiers(void)
eb86ff3ba21a - Add get_pools, get_verifiers, and get_schemes
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19022
diff changeset
1359 {
eb86ff3ba21a - Add get_pools, get_verifiers, and get_schemes
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19022
diff changeset
1360 return cert_verifiers;
eb86ff3ba21a - Add get_pools, get_verifiers, and get_schemes
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19022
diff changeset
1361 }
eb86ff3ba21a - Add get_pools, get_verifiers, and get_schemes
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19022
diff changeset
1362
18941
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1363 gboolean
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1364 purple_certificate_register_verifier(PurpleCertificateVerifier *vr)
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1365 {
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1366 g_return_val_if_fail(vr != NULL, FALSE);
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1367
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1368 /* Make sure no verifier is registered with the same scheme/name */
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1369 if (purple_certificate_find_verifier(vr->scheme_name, vr->name) != NULL) {
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1370 return FALSE;
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1371 }
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1372
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1373 /* Okay, we're golden. Register it. */
18972
486563a6bb5c - prepend > append
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18971
diff changeset
1374 cert_verifiers = g_list_prepend(cert_verifiers, vr);
18941
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1375
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1376 /* TODO: Signalling and such? */
19063
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1377
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1378 purple_debug_info("certificate",
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1379 "CertificateVerifier %s registered\n",
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1380 vr->name);
18941
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1381 return TRUE;
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1382 }
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1383
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1384 gboolean
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1385 purple_certificate_unregister_verifier(PurpleCertificateVerifier *vr)
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1386 {
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1387 if (NULL == vr) {
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1388 purple_debug_warning("certificate",
18973
28673b6fb8a2 - Fix some errors and return values
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18972
diff changeset
1389 "Attempting to unregister NULL verifier\n");
28673b6fb8a2 - Fix some errors and return values
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18972
diff changeset
1390 return FALSE;
18941
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1391 }
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1392
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1393 /* TODO: signalling? */
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1394
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1395 cert_verifiers = g_list_remove(cert_verifiers, vr);
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1396
19063
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1397
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1398 purple_debug_info("certificate",
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1399 "CertificateVerifier %s unregistered\n",
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1400 vr->name);
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1401
18941
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1402 return TRUE;
425f494bd1ec - CertificateVerifier register/unregister/find
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18926
diff changeset
1403 }
18971
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1404
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1405 PurpleCertificatePool *
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1406 purple_certificate_find_pool(const gchar *scheme_name, const gchar *pool_name)
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1407 {
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1408 PurpleCertificatePool *pool = NULL;
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1409 GList *l;
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1410
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1411 g_return_val_if_fail(scheme_name, NULL);
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1412 g_return_val_if_fail(pool_name, NULL);
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1413
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1414 /* Traverse the list of registered pools and locate the
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1415 one whose name matches */
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1416 for(l = cert_pools; l; l = l->next) {
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1417 pool = (PurpleCertificatePool *)(l->data);
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1418
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1419 /* Scheme and name match? */
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1420 if(!g_ascii_strcasecmp(pool->scheme_name, scheme_name) &&
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1421 !g_ascii_strcasecmp(pool->name, pool_name))
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1422 return pool;
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1423 }
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1424
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1425 purple_debug_warning("certificate",
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1426 "CertificatePool %s, %s requested but not found.\n",
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1427 scheme_name, pool_name);
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1428
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1429 /* TODO: Signalling and such? */
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1430
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1431 return NULL;
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1432
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1433 }
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1434
19023
eb86ff3ba21a - Add get_pools, get_verifiers, and get_schemes
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19022
diff changeset
1435 GList *
eb86ff3ba21a - Add get_pools, get_verifiers, and get_schemes
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19022
diff changeset
1436 purple_certificate_get_pools(void)
eb86ff3ba21a - Add get_pools, get_verifiers, and get_schemes
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19022
diff changeset
1437 {
eb86ff3ba21a - Add get_pools, get_verifiers, and get_schemes
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19022
diff changeset
1438 return cert_pools;
eb86ff3ba21a - Add get_pools, get_verifiers, and get_schemes
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19022
diff changeset
1439 }
18971
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1440
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1441 gboolean
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1442 purple_certificate_register_pool(PurpleCertificatePool *pool)
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1443 {
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1444 gboolean success = FALSE;
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1445 g_return_val_if_fail(pool, FALSE);
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1446 g_return_val_if_fail(pool->scheme_name, FALSE);
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1447 g_return_val_if_fail(pool->name, FALSE);
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1448 g_return_val_if_fail(pool->fullname, FALSE);
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1449
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1450 /* Make sure no pools are registered under this name */
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1451 if (purple_certificate_find_pool(pool->scheme_name, pool->name)) {
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1452 return FALSE;
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1453 }
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1454
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1455 /* Initialize the pool if needed */
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1456 if (pool->init) {
18975
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
1457 success = pool->init();
18971
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1458 } else {
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1459 success = TRUE;
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1460 }
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1461
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1462 if (success) {
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1463 /* Register the Pool */
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1464 cert_pools = g_list_prepend(cert_pools, pool);
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1465
19044
602295db8e6b - Register the certificate-stored and certificate-deleted signals
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19034
diff changeset
1466 /* TODO: Emit a signal that the pool got registered */
602295db8e6b - Register the certificate-stored and certificate-deleted signals
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19034
diff changeset
1467
602295db8e6b - Register the certificate-stored and certificate-deleted signals
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19034
diff changeset
1468 purple_signal_register(pool, /* Signals emitted from pool */
602295db8e6b - Register the certificate-stored and certificate-deleted signals
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19034
diff changeset
1469 "certificate-stored",
602295db8e6b - Register the certificate-stored and certificate-deleted signals
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19034
diff changeset
1470 purple_marshal_VOID__POINTER_POINTER,
602295db8e6b - Register the certificate-stored and certificate-deleted signals
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19034
diff changeset
1471 NULL, /* No callback return value */
602295db8e6b - Register the certificate-stored and certificate-deleted signals
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19034
diff changeset
1472 2, /* Two non-data arguments */
602295db8e6b - Register the certificate-stored and certificate-deleted signals
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19034
diff changeset
1473 purple_value_new(PURPLE_TYPE_SUBTYPE,
602295db8e6b - Register the certificate-stored and certificate-deleted signals
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19034
diff changeset
1474 PURPLE_SUBTYPE_CERTIFICATEPOOL),
602295db8e6b - Register the certificate-stored and certificate-deleted signals
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19034
diff changeset
1475 purple_value_new(PURPLE_TYPE_STRING));
602295db8e6b - Register the certificate-stored and certificate-deleted signals
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19034
diff changeset
1476
602295db8e6b - Register the certificate-stored and certificate-deleted signals
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19034
diff changeset
1477 purple_signal_register(pool, /* Signals emitted from pool */
602295db8e6b - Register the certificate-stored and certificate-deleted signals
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19034
diff changeset
1478 "certificate-deleted",
602295db8e6b - Register the certificate-stored and certificate-deleted signals
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19034
diff changeset
1479 purple_marshal_VOID__POINTER_POINTER,
602295db8e6b - Register the certificate-stored and certificate-deleted signals
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19034
diff changeset
1480 NULL, /* No callback return value */
602295db8e6b - Register the certificate-stored and certificate-deleted signals
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19034
diff changeset
1481 2, /* Two non-data arguments */
602295db8e6b - Register the certificate-stored and certificate-deleted signals
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19034
diff changeset
1482 purple_value_new(PURPLE_TYPE_SUBTYPE,
602295db8e6b - Register the certificate-stored and certificate-deleted signals
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19034
diff changeset
1483 PURPLE_SUBTYPE_CERTIFICATEPOOL),
602295db8e6b - Register the certificate-stored and certificate-deleted signals
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19034
diff changeset
1484 purple_value_new(PURPLE_TYPE_STRING));
19063
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1485
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1486
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1487 purple_debug_info("certificate",
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1488 "CertificatePool %s registered\n",
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1489 pool->name);
18971
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1490 return TRUE;
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1491 } else {
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1492 return FALSE;
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1493 }
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1494
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1495 /* Control does not reach this point */
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1496 }
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1497
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1498 gboolean
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1499 purple_certificate_unregister_pool(PurpleCertificatePool *pool)
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1500 {
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1501 /* TODO: Better error checking? */
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1502 if (NULL == pool) {
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1503 purple_debug_warning("certificate",
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1504 "Attempting to unregister NULL pool\n");
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1505 return FALSE;
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1506 }
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1507
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1508 /* Check that the pool is registered */
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1509 if (!g_list_find(cert_pools, pool)) {
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1510 purple_debug_warning("certificate",
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1511 "Pool to unregister isn't registered!\n");
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1512
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1513 return FALSE;
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1514 }
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1515
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1516 /* Uninit the pool if needed */
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1517 if (pool->uninit) {
18975
172b8d1dc2be - CertificatePool member functions no longer accept a Pool instance, as Pools are expected to be singletons
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18973
diff changeset
1518 pool->uninit();
18971
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1519 }
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1520
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1521 cert_pools = g_list_remove(cert_pools, pool);
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1522
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1523 /* TODO: Signalling? */
19044
602295db8e6b - Register the certificate-stored and certificate-deleted signals
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19034
diff changeset
1524 purple_signal_unregister(pool, "certificate-stored");
602295db8e6b - Register the certificate-stored and certificate-deleted signals
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19034
diff changeset
1525 purple_signal_unregister(pool, "certificate-deleted");
18971
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1526
19063
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1527 purple_debug_info("certificate",
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1528 "CertificatePool %s unregistered\n",
2f51578e6602 - Add debugging babble for registers/unregisters
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19060
diff changeset
1529 pool->name);
18971
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1530 return TRUE;
898e2bd70f23 - Add find, register, and unregister for CertificatePools
William Ehlhardt <williamehlhardt@gmail.com>
parents: 18964
diff changeset
1531 }