Mon, 07 Jul 2014 23:57:43 -0700
Move x509_display_string() from ssl-nss.c and ssl-gnutls.c to certificate.c.
We should try to keep the library-specific abstraction files as small
as possible and avoid putting display logic there. The larger the files,
the more likely it is that behavior will differ, and that's bad.
| 7016 | 1 | /** |
| 2 | * @file ssl-nss.c Mozilla NSS SSL plugin. | |
| 3 | * | |
| 15884 | 4 | * purple |
| 7016 | 5 | * |
| 6 | * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
| 7 | * | |
| 8 | * This program is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19847
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 7016 | 21 | */ |
| 22 | #include "internal.h" | |
|
7051
8ddb8f560399
[gaim-migrate @ 7614]
Christian Hammond <chipx86@chipx86.com>
parents:
7050
diff
changeset
|
23 | #include "debug.h" |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
24 | #include "certificate.h" |
| 7016 | 25 | #include "plugin.h" |
|
7051
8ddb8f560399
[gaim-migrate @ 7614]
Christian Hammond <chipx86@chipx86.com>
parents:
7050
diff
changeset
|
26 | #include "sslconn.h" |
|
19983
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
27 | #include "util.h" |
| 9943 | 28 | #include "version.h" |
| 7016 | 29 | |
|
7029
fe690e0607ec
[gaim-migrate @ 7592]
Christian Hammond <chipx86@chipx86.com>
parents:
7028
diff
changeset
|
30 | #define SSL_NSS_PLUGIN_ID "ssl-nss" |
| 7016 | 31 | |
|
34242
2aa4d5ab8916
Add workaround so that certificates with times that can't be represented using
Daniel Atallah <datallah@pidgin.im>
parents:
33841
diff
changeset
|
32 | #ifdef _WIN32 |
|
2aa4d5ab8916
Add workaround so that certificates with times that can't be represented using
Daniel Atallah <datallah@pidgin.im>
parents:
33841
diff
changeset
|
33 | # ifndef HAVE_LONG_LONG |
|
2aa4d5ab8916
Add workaround so that certificates with times that can't be represented using
Daniel Atallah <datallah@pidgin.im>
parents:
33841
diff
changeset
|
34 | #define HAVE_LONG_LONG |
|
2aa4d5ab8916
Add workaround so that certificates with times that can't be represented using
Daniel Atallah <datallah@pidgin.im>
parents:
33841
diff
changeset
|
35 | # endif |
|
2aa4d5ab8916
Add workaround so that certificates with times that can't be represented using
Daniel Atallah <datallah@pidgin.im>
parents:
33841
diff
changeset
|
36 | #else |
|
2aa4d5ab8916
Add workaround so that certificates with times that can't be represented using
Daniel Atallah <datallah@pidgin.im>
parents:
33841
diff
changeset
|
37 | /* TODO: Why is this done? |
|
2aa4d5ab8916
Add workaround so that certificates with times that can't be represented using
Daniel Atallah <datallah@pidgin.im>
parents:
33841
diff
changeset
|
38 | * This is probably being overridden by <nspr.h> (prcpucfg.h) on *nix OSes */ |
|
9582
68facdf2b52d
[gaim-migrate @ 10425]
Christian Hammond <chipx86@chipx86.com>
parents:
8749
diff
changeset
|
39 | #undef HAVE_LONG_LONG /* Make Mozilla less angry. If angry, Mozilla SMASH! */ |
|
34242
2aa4d5ab8916
Add workaround so that certificates with times that can't be represented using
Daniel Atallah <datallah@pidgin.im>
parents:
33841
diff
changeset
|
40 | #endif |
|
9582
68facdf2b52d
[gaim-migrate @ 10425]
Christian Hammond <chipx86@chipx86.com>
parents:
8749
diff
changeset
|
41 | |
| 7016 | 42 | #include <nspr.h> |
| 43 | #include <nss.h> | |
|
19983
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
44 | #include <nssb64.h> |
| 7016 | 45 | #include <pk11func.h> |
| 46 | #include <prio.h> | |
| 47 | #include <secerr.h> | |
| 48 | #include <secmod.h> | |
| 49 | #include <ssl.h> | |
| 50 | #include <sslerr.h> | |
| 51 | #include <sslproto.h> | |
| 52 | ||
|
17673
efba6798f37e
Avoid including NSPR's private header pprio.h just for the prototype of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17623
diff
changeset
|
53 | /* This is defined in NSPR's <private/pprio.h>, but to avoid including a |
|
efba6798f37e
Avoid including NSPR's private header pprio.h just for the prototype of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17623
diff
changeset
|
54 | * private header we duplicate the prototype here */ |
|
efba6798f37e
Avoid including NSPR's private header pprio.h just for the prototype of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17623
diff
changeset
|
55 | NSPR_API(PRFileDesc*) PR_ImportTCPSocket(PRInt32 osfd); |
|
efba6798f37e
Avoid including NSPR's private header pprio.h just for the prototype of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
17623
diff
changeset
|
56 | |
| 7016 | 57 | typedef struct |
| 58 | { | |
| 59 | PRFileDesc *fd; | |
| 60 | PRFileDesc *in; | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
61 | guint handshake_handler; |
|
29942
4c74f05635c5
gnutls/nss: Don't call the handshake functions synchronously. Fixes #11525
Paul Aurich <darkrain42@pidgin.im>
parents:
29930
diff
changeset
|
62 | guint handshake_timer; |
| 15884 | 63 | } PurpleSslNssData; |
| 7016 | 64 | |
| 15884 | 65 | #define PURPLE_SSL_NSS_DATA(gsc) ((PurpleSslNssData *)gsc->private_data) |
| 7016 | 66 | |
| 67 | static const PRIOMethods *_nss_methods = NULL; | |
| 68 | static PRDescIdentity _identity; | |
|
24065
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
69 | static PurpleCertificateScheme x509_nss; |
| 7016 | 70 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
71 | /* Thank you, Evolution */ |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
72 | static void |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
73 | set_errno(int code) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
74 | { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
75 | /* FIXME: this should handle more. */ |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
76 | switch (code) { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
77 | case PR_INVALID_ARGUMENT_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
78 | errno = EINVAL; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
79 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
80 | case PR_PENDING_INTERRUPT_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
81 | errno = EINTR; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
82 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
83 | case PR_IO_PENDING_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
84 | errno = EAGAIN; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
85 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
86 | case PR_WOULD_BLOCK_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
87 | errno = EAGAIN; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
88 | /*errno = EWOULDBLOCK; */ |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
89 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
90 | case PR_IN_PROGRESS_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
91 | errno = EINPROGRESS; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
92 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
93 | case PR_ALREADY_INITIATED_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
94 | errno = EALREADY; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
95 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
96 | case PR_NETWORK_UNREACHABLE_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
97 | errno = EHOSTUNREACH; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
98 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
99 | case PR_CONNECT_REFUSED_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
100 | errno = ECONNREFUSED; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
101 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
102 | case PR_CONNECT_TIMEOUT_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
103 | case PR_IO_TIMEOUT_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
104 | errno = ETIMEDOUT; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
105 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
106 | case PR_NOT_CONNECTED_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
107 | errno = ENOTCONN; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
108 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
109 | case PR_CONNECT_RESET_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
110 | errno = ECONNRESET; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
111 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
112 | case PR_IO_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
113 | default: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
114 | errno = EIO; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
115 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
116 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
117 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
118 | |
|
22104
56970903b8e9
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@pidgin.im>
parents:
20288
diff
changeset
|
119 | static gchar *get_error_text(void) |
|
19847
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
120 | { |
|
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
121 | PRInt32 len = PR_GetErrorTextLength(); |
|
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
122 | gchar *ret = NULL; |
|
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
123 | |
|
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
124 | if (len > 0) { |
|
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
125 | ret = g_malloc(len + 1); |
|
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
126 | len = PR_GetErrorText(ret); |
|
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
127 | ret[len] = '\0'; |
|
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
128 | } |
|
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
129 | |
|
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
130 | return ret; |
|
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
131 | } |
|
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
132 | |
|
7993
3bfea94dd0eb
[gaim-migrate @ 8670]
Christian Hammond <chipx86@chipx86.com>
parents:
7862
diff
changeset
|
133 | static void |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
134 | ssl_nss_init_nss(void) |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
135 | { |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
136 | PR_Init(PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1); |
|
16866
2187f9250a16
Proabably fixes ticket #578, it's the recommended way of initializing NSS
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16744
diff
changeset
|
137 | NSS_NoDB_Init("."); |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
138 | NSS_SetDomesticPolicy(); |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
139 | |
|
24388
32a4cf358f9c
Enable a number of default-disabled strong ciphers for NSS.
Ethan Blanton <elb@pidgin.im>
parents:
24276
diff
changeset
|
140 | SSL_CipherPrefSetDefault(TLS_DHE_RSA_WITH_AES_256_CBC_SHA, 1); |
|
32a4cf358f9c
Enable a number of default-disabled strong ciphers for NSS.
Ethan Blanton <elb@pidgin.im>
parents:
24276
diff
changeset
|
141 | SSL_CipherPrefSetDefault(TLS_DHE_DSS_WITH_AES_256_CBC_SHA, 1); |
|
32a4cf358f9c
Enable a number of default-disabled strong ciphers for NSS.
Ethan Blanton <elb@pidgin.im>
parents:
24276
diff
changeset
|
142 | SSL_CipherPrefSetDefault(TLS_RSA_WITH_AES_256_CBC_SHA, 1); |
|
32a4cf358f9c
Enable a number of default-disabled strong ciphers for NSS.
Ethan Blanton <elb@pidgin.im>
parents:
24276
diff
changeset
|
143 | SSL_CipherPrefSetDefault(TLS_DHE_DSS_WITH_RC4_128_SHA, 1); |
|
32a4cf358f9c
Enable a number of default-disabled strong ciphers for NSS.
Ethan Blanton <elb@pidgin.im>
parents:
24276
diff
changeset
|
144 | SSL_CipherPrefSetDefault(TLS_DHE_RSA_WITH_AES_128_CBC_SHA, 1); |
|
32a4cf358f9c
Enable a number of default-disabled strong ciphers for NSS.
Ethan Blanton <elb@pidgin.im>
parents:
24276
diff
changeset
|
145 | SSL_CipherPrefSetDefault(TLS_DHE_DSS_WITH_AES_128_CBC_SHA, 1); |
|
32a4cf358f9c
Enable a number of default-disabled strong ciphers for NSS.
Ethan Blanton <elb@pidgin.im>
parents:
24276
diff
changeset
|
146 | SSL_CipherPrefSetDefault(SSL_RSA_WITH_RC4_128_SHA, 1); |
|
32a4cf358f9c
Enable a number of default-disabled strong ciphers for NSS.
Ethan Blanton <elb@pidgin.im>
parents:
24276
diff
changeset
|
147 | SSL_CipherPrefSetDefault(TLS_RSA_WITH_AES_128_CBC_SHA, 1); |
|
32a4cf358f9c
Enable a number of default-disabled strong ciphers for NSS.
Ethan Blanton <elb@pidgin.im>
parents:
24276
diff
changeset
|
148 | SSL_CipherPrefSetDefault(SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, 1); |
|
32a4cf358f9c
Enable a number of default-disabled strong ciphers for NSS.
Ethan Blanton <elb@pidgin.im>
parents:
24276
diff
changeset
|
149 | SSL_CipherPrefSetDefault(SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, 1); |
|
32a4cf358f9c
Enable a number of default-disabled strong ciphers for NSS.
Ethan Blanton <elb@pidgin.im>
parents:
24276
diff
changeset
|
150 | SSL_CipherPrefSetDefault(SSL_DHE_RSA_WITH_DES_CBC_SHA, 1); |
|
32a4cf358f9c
Enable a number of default-disabled strong ciphers for NSS.
Ethan Blanton <elb@pidgin.im>
parents:
24276
diff
changeset
|
151 | SSL_CipherPrefSetDefault(SSL_DHE_DSS_WITH_DES_CBC_SHA, 1); |
|
32a4cf358f9c
Enable a number of default-disabled strong ciphers for NSS.
Ethan Blanton <elb@pidgin.im>
parents:
24276
diff
changeset
|
152 | |
| 15884 | 153 | _identity = PR_GetUniqueIdentity("Purple"); |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
154 | _nss_methods = PR_GetDefaultIOMethods(); |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
155 | } |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
156 | |
| 7016 | 157 | static SECStatus |
|
35135
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
158 | ssl_auth_cert(void *arg, PRFileDesc *socket, PRBool checksig, PRBool is_server) |
| 7016 | 159 | { |
|
35135
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
160 | /* We just skip cert verification here, and will verify the whole chain |
|
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
161 | * in ssl_nss_handshake_cb, after the handshake is complete. |
|
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
162 | * |
|
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
163 | * The problem is, purple_certificate_verify is asynchronous and |
|
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
164 | * ssl_auth_cert should return the result synchronously (it may ask the |
|
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
165 | * user, if an unknown certificate should be trusted or not). |
|
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
166 | * |
|
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
167 | * Ideally, SSL_AuthCertificateHook/ssl_auth_cert should decide |
|
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
168 | * immediately, if the certificate chain is already trusted and possibly |
|
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
169 | * SSL_BadCertHook to deal with unknown certificates. |
|
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
170 | * |
|
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
171 | * Current implementation may not be ideal, but is no less secure in |
|
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
172 | * terms of MITM attack. |
|
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
173 | */ |
|
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
174 | return SECSuccess; |
| 7016 | 175 | } |
| 176 | ||
| 177 | static gboolean | |
| 178 | ssl_nss_init(void) | |
| 179 | { | |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
180 | return TRUE; |
| 7016 | 181 | } |
| 182 | ||
| 183 | static void | |
| 184 | ssl_nss_uninit(void) | |
| 185 | { | |
|
29943
8bd0701c9bbd
nss: NSS should work after reiniting libpurple. Closes #11524.
Paul Aurich <darkrain42@pidgin.im>
parents:
29942
diff
changeset
|
186 | NSS_Shutdown(); |
| 7016 | 187 | PR_Cleanup(); |
| 188 | ||
| 189 | _nss_methods = NULL; | |
| 190 | } | |
| 191 | ||
| 192 | static void | |
|
24065
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
193 | ssl_nss_verified_cb(PurpleCertificateVerificationStatus st, |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
194 | gpointer userdata) |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
195 | { |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
196 | PurpleSslConnection *gsc = (PurpleSslConnection *) userdata; |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
197 | |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
198 | if (st == PURPLE_CERTIFICATE_VALID) { |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
199 | /* Certificate valid? Good! Do the connection! */ |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
200 | gsc->connect_cb(gsc->connect_cb_data, gsc, PURPLE_INPUT_READ); |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
201 | } else { |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
202 | /* Otherwise, signal an error */ |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
203 | if(gsc->error_cb != NULL) |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
204 | gsc->error_cb(gsc, PURPLE_SSL_CERTIFICATE_INVALID, |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
205 | gsc->connect_cb_data); |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
206 | purple_ssl_close(gsc); |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
207 | } |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
208 | } |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
209 | |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
210 | /** Transforms an NSS containing an X.509 certificate into a Certificate instance |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
211 | * |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
212 | * @param cert Certificate to transform |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
213 | * @return A newly allocated Certificate |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
214 | */ |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
215 | static PurpleCertificate * |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
216 | x509_import_from_nss(CERTCertificate* cert) |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
217 | { |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
218 | /* New certificate to return */ |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
219 | PurpleCertificate * crt; |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
220 | |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
221 | /* Allocate the certificate and load it with data */ |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
222 | crt = g_new0(PurpleCertificate, 1); |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
223 | crt->scheme = &x509_nss; |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
224 | crt->data = CERT_DupCertificate(cert); |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
225 | |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
226 | return crt; |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
227 | } |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
228 | |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
229 | static GList * |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
230 | ssl_nss_get_peer_certificates(PRFileDesc *socket, PurpleSslConnection * gsc) |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
231 | { |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
232 | CERTCertificate *curcert; |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
233 | CERTCertificate *issuerCert; |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
234 | PurpleCertificate * newcrt; |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
235 | |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
236 | /* List of Certificate instances to return */ |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
237 | GList * peer_certs = NULL; |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
238 | int count; |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
239 | int64 now = PR_Now(); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
29943
diff
changeset
|
240 | |
|
24065
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
241 | curcert = SSL_PeerCertificate(socket); |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
242 | if (curcert == NULL) { |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
243 | purple_debug_error("nss", "could not DupCertificate\n"); |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
244 | return NULL; |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
245 | } |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
29943
diff
changeset
|
246 | |
|
24065
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
247 | for (count = 0 ; count < CERT_MAX_CERT_CHAIN ; count++) { |
|
24276
469eea3c328d
Fix a NULL pointer deref in the NSS SSL implementation with certain self-signed
Daniel Atallah <datallah@pidgin.im>
parents:
24065
diff
changeset
|
248 | purple_debug_info("nss", "subject=%s issuer=%s\n", curcert->subjectName, |
|
469eea3c328d
Fix a NULL pointer deref in the NSS SSL implementation with certain self-signed
Daniel Atallah <datallah@pidgin.im>
parents:
24065
diff
changeset
|
249 | curcert->issuerName ? curcert->issuerName : "(null)"); |
|
24065
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
250 | newcrt = x509_import_from_nss(curcert); |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
251 | peer_certs = g_list_append(peer_certs, newcrt); |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
252 | |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
253 | if (curcert->isRoot) { |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
254 | break; |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
255 | } |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
256 | issuerCert = CERT_FindCertIssuer(curcert, now, certUsageSSLServer); |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
257 | if (!issuerCert) { |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
258 | purple_debug_error("nss", "partial certificate chain\n"); |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
259 | break; |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
260 | } |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
261 | CERT_DestroyCertificate(curcert); |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
262 | curcert = issuerCert; |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
263 | } |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
264 | CERT_DestroyCertificate(curcert); |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
265 | |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
266 | return peer_certs; |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
267 | } |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
268 | |
|
35368
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
269 | /* |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
270 | * Ideally this information would be exposed to the UI somehow, but for now we |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
271 | * just print it to the debug log |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
272 | */ |
| 35623 | 273 | static void |
|
35622
b29a773d89c1
Avoid camel case function name.
Mark Doliner <mark@kingant.net>
parents:
35368
diff
changeset
|
274 | print_security_info(PRFileDesc *fd) |
|
35368
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
275 | { |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
276 | SECStatus result; |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
277 | SSLChannelInfo channel; |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
278 | SSLCipherSuiteInfo suite; |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
279 | |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
280 | result = SSL_GetChannelInfo(fd, &channel, sizeof channel); |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
281 | if (result == SECSuccess && channel.length == sizeof channel |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
282 | && channel.cipherSuite) { |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
283 | result = SSL_GetCipherSuiteInfo(channel.cipherSuite, |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
284 | &suite, sizeof suite); |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
285 | |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
286 | if (result == SECSuccess) { |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
287 | purple_debug_info("nss", "SSL version %d.%d using " |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
288 | "%d-bit %s with %d-bit %s MAC\n" |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
289 | "Server Auth: %d-bit %s, " |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
290 | "Key Exchange: %d-bit %s, " |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
291 | "Compression: %s\n" |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
292 | "Cipher Suite Name: %s\n", |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
293 | channel.protocolVersion >> 8, |
| 35623 | 294 | channel.protocolVersion & 0xff, |
|
35368
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
295 | suite.effectiveKeyBits, |
| 35623 | 296 | suite.symCipherName, |
|
35368
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
297 | suite.macBits, |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
298 | suite.macAlgorithmName, |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
299 | channel.authKeyBits, |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
300 | suite.authAlgorithmName, |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
301 | channel.keaKeyBits, suite.keaTypeName, |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
302 | channel.compressionMethodName, |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
303 | suite.cipherSuiteName); |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
304 | } |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
305 | } |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
306 | } |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
307 | |
|
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
308 | |
|
24065
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
309 | static void |
| 15884 | 310 | ssl_nss_handshake_cb(gpointer data, int fd, PurpleInputCondition cond) |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
311 | { |
| 15884 | 312 | PurpleSslConnection *gsc = (PurpleSslConnection *)data; |
| 313 | PurpleSslNssData *nss_data = gsc->private_data; | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
314 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
315 | /* I don't think this the best way to do this... |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
316 | * It seems to work because it'll eventually use the cached value |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
317 | */ |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
318 | if(SSL_ForceHandshake(nss_data->in) != SECSuccess) { |
|
19847
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
319 | gchar *error_txt; |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
320 | set_errno(PR_GetError()); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
321 | if (errno == EAGAIN || errno == EWOULDBLOCK) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
322 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
323 | |
|
19847
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
324 | error_txt = get_error_text(); |
|
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
325 | purple_debug_error("nss", "Handshake failed %s (%d)\n", error_txt ? error_txt : "", PR_GetError()); |
|
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
326 | g_free(error_txt); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
327 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
328 | if (gsc->error_cb != NULL) |
| 15884 | 329 | gsc->error_cb(gsc, PURPLE_SSL_HANDSHAKE_FAILED, gsc->connect_cb_data); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
330 | |
| 15884 | 331 | purple_ssl_close(gsc); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
332 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
333 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
334 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
335 | |
|
35622
b29a773d89c1
Avoid camel case function name.
Mark Doliner <mark@kingant.net>
parents:
35368
diff
changeset
|
336 | print_security_info(nss_data->in); |
|
35368
9728bb0f6dcc
Print information about the SSL connection to the debug log
Daniel Atallah <datallah@pidgin.im>
parents:
35135
diff
changeset
|
337 | |
| 15884 | 338 | purple_input_remove(nss_data->handshake_handler); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
339 | nss_data->handshake_handler = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
340 | |
|
24065
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
341 | /* If a Verifier was given, hand control over to it */ |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
342 | if (gsc->verifier) { |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
343 | GList *peers; |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
344 | /* First, get the peer cert chain */ |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
345 | peers = ssl_nss_get_peer_certificates(nss_data->in, gsc); |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
346 | |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
347 | /* Now kick off the verification process */ |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
348 | purple_certificate_verify(gsc->verifier, |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
349 | gsc->host, |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
350 | peers, |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
351 | ssl_nss_verified_cb, |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
352 | gsc); |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
353 | |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
354 | purple_certificate_destroy_list(peers); |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
355 | } else { |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
356 | /* Otherwise, just call the "connection complete" |
|
35135
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
357 | * callback. The verification was already done with |
|
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
358 | * SSL_AuthCertificate, the default verifier |
|
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
359 | * (SSL_AuthCertificateHook was not called in ssl_nss_connect). |
|
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
360 | */ |
|
24065
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
361 | gsc->connect_cb(gsc->connect_cb_data, gsc, cond); |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
362 | } |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
363 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
364 | |
|
29942
4c74f05635c5
gnutls/nss: Don't call the handshake functions synchronously. Fixes #11525
Paul Aurich <darkrain42@pidgin.im>
parents:
29930
diff
changeset
|
365 | static gboolean |
|
4c74f05635c5
gnutls/nss: Don't call the handshake functions synchronously. Fixes #11525
Paul Aurich <darkrain42@pidgin.im>
parents:
29930
diff
changeset
|
366 | start_handshake_cb(gpointer data) |
|
4c74f05635c5
gnutls/nss: Don't call the handshake functions synchronously. Fixes #11525
Paul Aurich <darkrain42@pidgin.im>
parents:
29930
diff
changeset
|
367 | { |
|
4c74f05635c5
gnutls/nss: Don't call the handshake functions synchronously. Fixes #11525
Paul Aurich <darkrain42@pidgin.im>
parents:
29930
diff
changeset
|
368 | PurpleSslConnection *gsc = data; |
|
4c74f05635c5
gnutls/nss: Don't call the handshake functions synchronously. Fixes #11525
Paul Aurich <darkrain42@pidgin.im>
parents:
29930
diff
changeset
|
369 | PurpleSslNssData *nss_data = PURPLE_SSL_NSS_DATA(gsc); |
|
4c74f05635c5
gnutls/nss: Don't call the handshake functions synchronously. Fixes #11525
Paul Aurich <darkrain42@pidgin.im>
parents:
29930
diff
changeset
|
370 | |
|
4c74f05635c5
gnutls/nss: Don't call the handshake functions synchronously. Fixes #11525
Paul Aurich <darkrain42@pidgin.im>
parents:
29930
diff
changeset
|
371 | nss_data->handshake_timer = 0; |
|
4c74f05635c5
gnutls/nss: Don't call the handshake functions synchronously. Fixes #11525
Paul Aurich <darkrain42@pidgin.im>
parents:
29930
diff
changeset
|
372 | |
|
4c74f05635c5
gnutls/nss: Don't call the handshake functions synchronously. Fixes #11525
Paul Aurich <darkrain42@pidgin.im>
parents:
29930
diff
changeset
|
373 | ssl_nss_handshake_cb(gsc, gsc->fd, PURPLE_INPUT_READ); |
|
4c74f05635c5
gnutls/nss: Don't call the handshake functions synchronously. Fixes #11525
Paul Aurich <darkrain42@pidgin.im>
parents:
29930
diff
changeset
|
374 | return FALSE; |
|
4c74f05635c5
gnutls/nss: Don't call the handshake functions synchronously. Fixes #11525
Paul Aurich <darkrain42@pidgin.im>
parents:
29930
diff
changeset
|
375 | } |
|
4c74f05635c5
gnutls/nss: Don't call the handshake functions synchronously. Fixes #11525
Paul Aurich <darkrain42@pidgin.im>
parents:
29930
diff
changeset
|
376 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
377 | static void |
| 15884 | 378 | ssl_nss_connect(PurpleSslConnection *gsc) |
| 7016 | 379 | { |
| 15884 | 380 | PurpleSslNssData *nss_data = g_new0(PurpleSslNssData, 1); |
| 7016 | 381 | PRSocketOptionData socket_opt; |
| 382 | ||
| 383 | gsc->private_data = nss_data; | |
| 384 | ||
| 385 | nss_data->fd = PR_ImportTCPSocket(gsc->fd); | |
| 386 | ||
| 387 | if (nss_data->fd == NULL) | |
| 388 | { | |
| 15884 | 389 | purple_debug_error("nss", "nss_data->fd == NULL!\n"); |
| 7016 | 390 | |
| 8362 | 391 | if (gsc->error_cb != NULL) |
| 15884 | 392 | gsc->error_cb(gsc, PURPLE_SSL_CONNECT_FAILED, gsc->connect_cb_data); |
| 8362 | 393 | |
| 15884 | 394 | purple_ssl_close((PurpleSslConnection *)gsc); |
| 7016 | 395 | |
| 396 | return; | |
| 397 | } | |
| 398 | ||
| 399 | socket_opt.option = PR_SockOpt_Nonblocking; | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
400 | socket_opt.value.non_blocking = PR_TRUE; |
| 7016 | 401 | |
|
19847
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
402 | if (PR_SetSocketOption(nss_data->fd, &socket_opt) != PR_SUCCESS) { |
|
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
403 | gchar *error_txt = get_error_text(); |
|
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
404 | purple_debug_warning("nss", "unable to set socket into non-blocking mode: %s (%d)\n", error_txt ? error_txt : "", PR_GetError()); |
|
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
405 | g_free(error_txt); |
|
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
406 | } |
| 7016 | 407 | |
| 408 | nss_data->in = SSL_ImportFD(NULL, nss_data->fd); | |
| 409 | ||
| 410 | if (nss_data->in == NULL) | |
| 411 | { | |
| 15884 | 412 | purple_debug_error("nss", "nss_data->in == NUL!\n"); |
| 7016 | 413 | |
| 8362 | 414 | if (gsc->error_cb != NULL) |
| 15884 | 415 | gsc->error_cb(gsc, PURPLE_SSL_CONNECT_FAILED, gsc->connect_cb_data); |
| 8362 | 416 | |
| 15884 | 417 | purple_ssl_close((PurpleSslConnection *)gsc); |
| 7016 | 418 | |
| 419 | return; | |
| 420 | } | |
| 421 | ||
| 422 | SSL_OptionSet(nss_data->in, SSL_SECURITY, PR_TRUE); | |
| 423 | SSL_OptionSet(nss_data->in, SSL_HANDSHAKE_AS_CLIENT, PR_TRUE); | |
| 424 | ||
|
35135
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
425 | /* If we have our internal verifier set up, use it. Otherwise, |
|
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
426 | * use default. */ |
|
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
427 | if (gsc->verifier != NULL) |
|
72bdcc0f7267
Clean up unused ssl/NSS code and write up some comments to resolve any doubts. Refs #15308
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34242
diff
changeset
|
428 | SSL_AuthCertificateHook(nss_data->in, ssl_auth_cert, NULL); |
| 7016 | 429 | |
| 7157 | 430 | if(gsc->host) |
| 431 | SSL_SetURL(nss_data->in, gsc->host); | |
| 7016 | 432 | |
|
13264
f5db933aa42a
[gaim-migrate @ 15629]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13201
diff
changeset
|
433 | #if 0 |
|
f5db933aa42a
[gaim-migrate @ 15629]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13201
diff
changeset
|
434 | /* This seems like it'd the be the correct way to implement the |
|
f5db933aa42a
[gaim-migrate @ 15629]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13201
diff
changeset
|
435 | nonblocking stuff, but it doesn't seem to work */ |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
436 | SSL_HandshakeCallback(nss_data->in, |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
437 | (SSLHandshakeCallback) ssl_nss_handshake_cb, gsc); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
438 | #endif |
| 7016 | 439 | SSL_ResetHandshake(nss_data->in, PR_FALSE); |
| 440 | ||
| 15884 | 441 | nss_data->handshake_handler = purple_input_add(gsc->fd, |
| 442 | PURPLE_INPUT_READ, ssl_nss_handshake_cb, gsc); | |
|
7274
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
7157
diff
changeset
|
443 | |
|
29942
4c74f05635c5
gnutls/nss: Don't call the handshake functions synchronously. Fixes #11525
Paul Aurich <darkrain42@pidgin.im>
parents:
29930
diff
changeset
|
444 | nss_data->handshake_timer = purple_timeout_add(0, start_handshake_cb, gsc); |
| 7016 | 445 | } |
| 446 | ||
| 447 | static void | |
| 15884 | 448 | ssl_nss_close(PurpleSslConnection *gsc) |
| 7016 | 449 | { |
| 15884 | 450 | PurpleSslNssData *nss_data = PURPLE_SSL_NSS_DATA(gsc); |
| 7016 | 451 | |
| 7467 | 452 | if(!nss_data) |
| 453 | return; | |
| 454 | ||
|
17623
4f45361d7e3b
A while ago, "Paranoid" emailed devel@p.i, having noticed that purple_ssl_close() closes the ssl fd twice. I meant to commit this fix sooner, but here it is.
Daniel Atallah <datallah@pidgin.im>
parents:
16866
diff
changeset
|
455 | if (nss_data->in) { |
|
4f45361d7e3b
A while ago, "Paranoid" emailed devel@p.i, having noticed that purple_ssl_close() closes the ssl fd twice. I meant to commit this fix sooner, but here it is.
Daniel Atallah <datallah@pidgin.im>
parents:
16866
diff
changeset
|
456 | PR_Close(nss_data->in); |
|
4f45361d7e3b
A while ago, "Paranoid" emailed devel@p.i, having noticed that purple_ssl_close() closes the ssl fd twice. I meant to commit this fix sooner, but here it is.
Daniel Atallah <datallah@pidgin.im>
parents:
16866
diff
changeset
|
457 | gsc->fd = -1; |
|
4f45361d7e3b
A while ago, "Paranoid" emailed devel@p.i, having noticed that purple_ssl_close() closes the ssl fd twice. I meant to commit this fix sooner, but here it is.
Daniel Atallah <datallah@pidgin.im>
parents:
16866
diff
changeset
|
458 | } else if (nss_data->fd) { |
|
4f45361d7e3b
A while ago, "Paranoid" emailed devel@p.i, having noticed that purple_ssl_close() closes the ssl fd twice. I meant to commit this fix sooner, but here it is.
Daniel Atallah <datallah@pidgin.im>
parents:
16866
diff
changeset
|
459 | PR_Close(nss_data->fd); |
|
4f45361d7e3b
A while ago, "Paranoid" emailed devel@p.i, having noticed that purple_ssl_close() closes the ssl fd twice. I meant to commit this fix sooner, but here it is.
Daniel Atallah <datallah@pidgin.im>
parents:
16866
diff
changeset
|
460 | gsc->fd = -1; |
|
4f45361d7e3b
A while ago, "Paranoid" emailed devel@p.i, having noticed that purple_ssl_close() closes the ssl fd twice. I meant to commit this fix sooner, but here it is.
Daniel Atallah <datallah@pidgin.im>
parents:
16866
diff
changeset
|
461 | } |
| 7016 | 462 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
463 | if (nss_data->handshake_handler) |
| 15884 | 464 | purple_input_remove(nss_data->handshake_handler); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
465 | |
|
29942
4c74f05635c5
gnutls/nss: Don't call the handshake functions synchronously. Fixes #11525
Paul Aurich <darkrain42@pidgin.im>
parents:
29930
diff
changeset
|
466 | if (nss_data->handshake_timer) |
|
4c74f05635c5
gnutls/nss: Don't call the handshake functions synchronously. Fixes #11525
Paul Aurich <darkrain42@pidgin.im>
parents:
29930
diff
changeset
|
467 | purple_timeout_remove(nss_data->handshake_timer); |
|
4c74f05635c5
gnutls/nss: Don't call the handshake functions synchronously. Fixes #11525
Paul Aurich <darkrain42@pidgin.im>
parents:
29930
diff
changeset
|
468 | |
| 7016 | 469 | g_free(nss_data); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
470 | gsc->private_data = NULL; |
| 7016 | 471 | } |
| 472 | ||
| 473 | static size_t | |
| 15884 | 474 | ssl_nss_read(PurpleSslConnection *gsc, void *data, size_t len) |
| 7016 | 475 | { |
|
33841
d91084abb15c
Fix return types for PR_Read/PR_Write.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33810
diff
changeset
|
476 | PRInt32 ret; |
| 15884 | 477 | PurpleSslNssData *nss_data = PURPLE_SSL_NSS_DATA(gsc); |
| 7016 | 478 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
479 | ret = PR_Read(nss_data->in, data, len); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
480 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
481 | if (ret == -1) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
482 | set_errno(PR_GetError()); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
483 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
484 | return ret; |
| 7016 | 485 | } |
| 486 | ||
| 487 | static size_t | |
| 15884 | 488 | ssl_nss_write(PurpleSslConnection *gsc, const void *data, size_t len) |
| 7016 | 489 | { |
|
33841
d91084abb15c
Fix return types for PR_Read/PR_Write.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33810
diff
changeset
|
490 | PRInt32 ret; |
| 15884 | 491 | PurpleSslNssData *nss_data = PURPLE_SSL_NSS_DATA(gsc); |
| 7016 | 492 | |
| 7467 | 493 | if(!nss_data) |
| 494 | return 0; | |
| 495 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
496 | ret = PR_Write(nss_data->in, data, len); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
497 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
498 | if (ret == -1) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
499 | set_errno(PR_GetError()); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
500 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
501 | return ret; |
| 7016 | 502 | } |
| 503 | ||
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
504 | static GList * |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
505 | ssl_nss_peer_certs(PurpleSslConnection *gsc) |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
506 | { |
|
20221
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19984
diff
changeset
|
507 | #if 0 |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
508 | PurpleSslNssData *nss_data = PURPLE_SSL_NSS_DATA(gsc); |
|
19847
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
509 | CERTCertificate *cert; |
|
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
510 | /* |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
511 | GList *chain = NULL; |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
512 | void *pinArg; |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
513 | SECStatus status; |
|
19847
c53701927784
Attempt to display user readable error messages for NSS.
Daniel Atallah <datallah@pidgin.im>
parents:
19827
diff
changeset
|
514 | */ |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
515 | |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
516 | /* TODO: this is a blind guess */ |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
517 | cert = SSL_PeerCertificate(nss_data->fd); |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
518 | |
|
20221
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19984
diff
changeset
|
519 | if (cert) |
|
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19984
diff
changeset
|
520 | CERT_DestroyCertificate(cert); |
|
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19984
diff
changeset
|
521 | #endif |
|
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19984
diff
changeset
|
522 | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
29943
diff
changeset
|
523 | |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
524 | |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
525 | return NULL; |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
526 | } |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
527 | |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
528 | /************************************************************************/ |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
529 | /* X.509 functionality */ |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
530 | /************************************************************************/ |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
531 | static PurpleCertificateScheme x509_nss; |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
532 | |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
533 | /** Helpr macro to retrieve the NSS certdata from a PurpleCertificate */ |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
534 | #define X509_NSS_DATA(pcrt) ( (CERTCertificate * ) (pcrt->data) ) |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
535 | |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
536 | /** Imports a PEM-formatted X.509 certificate from the specified file. |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
537 | * @param filename Filename to import from. Format is PEM |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
538 | * |
|
29930
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
539 | * @return A newly allocated Certificate structure of the x509_nss scheme |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
540 | */ |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
541 | static PurpleCertificate * |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
542 | x509_import_from_file(const gchar *filename) |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
543 | { |
|
19486
83d0375f1784
- Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19485
diff
changeset
|
544 | gchar *rawcert; |
|
83d0375f1784
- Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19485
diff
changeset
|
545 | gsize len = 0; |
|
83d0375f1784
- Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19485
diff
changeset
|
546 | CERTCertificate *crt_dat; |
|
83d0375f1784
- Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19485
diff
changeset
|
547 | PurpleCertificate *crt; |
|
83d0375f1784
- Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19485
diff
changeset
|
548 | |
|
27823
8eb52a9d3a6d
Continue verification when we can't find a *cached* peer. Fixes #9664.
Paul Aurich <darkrain42@pidgin.im>
parents:
27692
diff
changeset
|
549 | g_return_val_if_fail(filename != NULL, NULL); |
|
19486
83d0375f1784
- Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19485
diff
changeset
|
550 | |
|
83d0375f1784
- Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19485
diff
changeset
|
551 | purple_debug_info("nss/x509", |
|
83d0375f1784
- Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19485
diff
changeset
|
552 | "Loading certificate from %s\n", |
|
83d0375f1784
- Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19485
diff
changeset
|
553 | filename); |
|
27823
8eb52a9d3a6d
Continue verification when we can't find a *cached* peer. Fixes #9664.
Paul Aurich <darkrain42@pidgin.im>
parents:
27692
diff
changeset
|
554 | |
|
19486
83d0375f1784
- Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19485
diff
changeset
|
555 | /* Load the raw data up */ |
|
20221
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19984
diff
changeset
|
556 | if (!g_file_get_contents(filename, |
|
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19984
diff
changeset
|
557 | &rawcert, &len, |
|
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19984
diff
changeset
|
558 | NULL)) { |
|
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19984
diff
changeset
|
559 | purple_debug_error("nss/x509", "Unable to read certificate file.\n"); |
|
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19984
diff
changeset
|
560 | return NULL; |
|
28e31ee832cd
applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec
Luke Schierer <lschiere@pidgin.im>
parents:
19984
diff
changeset
|
561 | } |
|
19486
83d0375f1784
- Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19485
diff
changeset
|
562 | |
|
27823
8eb52a9d3a6d
Continue verification when we can't find a *cached* peer. Fixes #9664.
Paul Aurich <darkrain42@pidgin.im>
parents:
27692
diff
changeset
|
563 | if (len == 0) { |
|
8eb52a9d3a6d
Continue verification when we can't find a *cached* peer. Fixes #9664.
Paul Aurich <darkrain42@pidgin.im>
parents:
27692
diff
changeset
|
564 | purple_debug_error("nss/x509", |
|
8eb52a9d3a6d
Continue verification when we can't find a *cached* peer. Fixes #9664.
Paul Aurich <darkrain42@pidgin.im>
parents:
27692
diff
changeset
|
565 | "Certificate file has no contents!\n"); |
|
8eb52a9d3a6d
Continue verification when we can't find a *cached* peer. Fixes #9664.
Paul Aurich <darkrain42@pidgin.im>
parents:
27692
diff
changeset
|
566 | if (rawcert) |
|
8eb52a9d3a6d
Continue verification when we can't find a *cached* peer. Fixes #9664.
Paul Aurich <darkrain42@pidgin.im>
parents:
27692
diff
changeset
|
567 | g_free(rawcert); |
|
8eb52a9d3a6d
Continue verification when we can't find a *cached* peer. Fixes #9664.
Paul Aurich <darkrain42@pidgin.im>
parents:
27692
diff
changeset
|
568 | return NULL; |
|
8eb52a9d3a6d
Continue verification when we can't find a *cached* peer. Fixes #9664.
Paul Aurich <darkrain42@pidgin.im>
parents:
27692
diff
changeset
|
569 | } |
|
8eb52a9d3a6d
Continue verification when we can't find a *cached* peer. Fixes #9664.
Paul Aurich <darkrain42@pidgin.im>
parents:
27692
diff
changeset
|
570 | |
|
19486
83d0375f1784
- Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19485
diff
changeset
|
571 | /* Decode the certificate */ |
|
83d0375f1784
- Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19485
diff
changeset
|
572 | crt_dat = CERT_DecodeCertFromPackage(rawcert, len); |
|
83d0375f1784
- Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19485
diff
changeset
|
573 | g_free(rawcert); |
|
83d0375f1784
- Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19485
diff
changeset
|
574 | |
|
27823
8eb52a9d3a6d
Continue verification when we can't find a *cached* peer. Fixes #9664.
Paul Aurich <darkrain42@pidgin.im>
parents:
27692
diff
changeset
|
575 | g_return_val_if_fail(crt_dat != NULL, NULL); |
|
8eb52a9d3a6d
Continue verification when we can't find a *cached* peer. Fixes #9664.
Paul Aurich <darkrain42@pidgin.im>
parents:
27692
diff
changeset
|
576 | |
|
19486
83d0375f1784
- Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19485
diff
changeset
|
577 | crt = g_new0(PurpleCertificate, 1); |
|
83d0375f1784
- Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19485
diff
changeset
|
578 | crt->scheme = &x509_nss; |
|
83d0375f1784
- Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19485
diff
changeset
|
579 | crt->data = crt_dat; |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
29943
diff
changeset
|
580 | |
|
19486
83d0375f1784
- Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19485
diff
changeset
|
581 | return crt; |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
582 | } |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
583 | |
|
29930
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
584 | /** Imports a number of PEM-formatted X.509 certificates from the specified file. |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
585 | * @param filename Filename to import from. Format is PEM |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
586 | * |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
587 | * @return A GSList of newly allocated Certificate structures of the x509_nss scheme |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
588 | */ |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
589 | static GSList * |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
590 | x509_importcerts_from_file(const gchar *filename) |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
591 | { |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
592 | gchar *rawcert, *begin, *end; |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
593 | gsize len = 0; |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
594 | GSList *crts = NULL; |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
595 | CERTCertificate *crt_dat; |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
596 | PurpleCertificate *crt; |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
597 | |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
598 | g_return_val_if_fail(filename != NULL, NULL); |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
599 | |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
600 | purple_debug_info("nss/x509", |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
601 | "Loading certificate from %s\n", |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
602 | filename); |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
603 | |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
604 | /* Load the raw data up */ |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
605 | if (!g_file_get_contents(filename, |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
606 | &rawcert, &len, |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
607 | NULL)) { |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
608 | purple_debug_error("nss/x509", "Unable to read certificate file.\n"); |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
609 | return NULL; |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
610 | } |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
611 | |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
612 | if (len == 0) { |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
613 | purple_debug_error("nss/x509", |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
614 | "Certificate file has no contents!\n"); |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
615 | if (rawcert) |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
616 | g_free(rawcert); |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
617 | return NULL; |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
618 | } |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
619 | |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
620 | begin = rawcert; |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
621 | while((end = strstr(begin, "-----END CERTIFICATE-----")) != NULL) { |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
622 | end += sizeof("-----END CERTIFICATE-----")-1; |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
623 | /* Decode the certificate */ |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
624 | crt_dat = CERT_DecodeCertFromPackage(begin, (end-begin)); |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
625 | |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
626 | g_return_val_if_fail(crt_dat != NULL, NULL); |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
627 | |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
628 | crt = g_new0(PurpleCertificate, 1); |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
629 | crt->scheme = &x509_nss; |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
630 | crt->data = crt_dat; |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
631 | crts = g_slist_prepend(crts, crt); |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
632 | begin = end; |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
633 | } |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
634 | g_free(rawcert); |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
635 | |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
636 | return crts; |
|
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
637 | } |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
638 | /** |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
639 | * Exports a PEM-formatted X.509 certificate to the specified file. |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
640 | * @param filename Filename to export to. Format will be PEM |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
641 | * @param crt Certificate to export |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
642 | * |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
643 | * @return TRUE if success, otherwise FALSE |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
644 | */ |
|
19983
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
645 | /* This function should not be so complicated, but NSS doesn't seem to have a |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
646 | "convert yon certificate to PEM format" function. */ |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
647 | static gboolean |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
648 | x509_export_certificate(const gchar *filename, PurpleCertificate *crt) |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
649 | { |
|
19983
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
650 | CERTCertificate *crt_dat; |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
651 | SECItem *dercrt; |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
652 | gchar *b64crt; |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
653 | gchar *pemcrt; |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
654 | gboolean ret = FALSE; |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
655 | |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
656 | g_return_val_if_fail(filename, FALSE); |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
657 | g_return_val_if_fail(crt, FALSE); |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
658 | g_return_val_if_fail(crt->scheme == &x509_nss, FALSE); |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
659 | |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
660 | crt_dat = X509_NSS_DATA(crt); |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
661 | g_return_val_if_fail(crt_dat, FALSE); |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
662 | |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
663 | purple_debug_info("nss/x509", |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
664 | "Exporting certificate to %s\n", filename); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
29943
diff
changeset
|
665 | |
|
19983
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
666 | /* First, use NSS voodoo to create a DER-formatted certificate */ |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
667 | dercrt = SEC_ASN1EncodeItem(NULL, NULL, crt_dat, |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
668 | SEC_ASN1_GET(SEC_SignedCertificateTemplate)); |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
669 | g_return_val_if_fail(dercrt != NULL, FALSE); |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
670 | |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
671 | /* Now encode it to b64 */ |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
672 | b64crt = NSSBase64_EncodeItem(NULL, NULL, 0, dercrt); |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
673 | SECITEM_FreeItem(dercrt, PR_TRUE); |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
674 | g_return_val_if_fail(b64crt, FALSE); |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
675 | |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
676 | /* Wrap it in nice PEM header things */ |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
677 | pemcrt = g_strdup_printf("-----BEGIN CERTIFICATE-----\n%s\n-----END CERTIFICATE-----\n", b64crt); |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
678 | PORT_Free(b64crt); /* Notice that b64crt was allocated by an NSS |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
679 | function; hence, we'll let NSPR free it. */ |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
680 | |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
681 | /* Finally, dump the silly thing to a file. */ |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
682 | ret = purple_util_write_data_to_file_absolute(filename, pemcrt, -1); |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
683 | |
|
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
684 | g_free(pemcrt); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
29943
diff
changeset
|
685 | |
|
19983
2d79626570ae
- Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19982
diff
changeset
|
686 | return ret; |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
687 | } |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
688 | |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
689 | static PurpleCertificate * |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
690 | x509_copy_certificate(PurpleCertificate *crt) |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
691 | { |
|
19009
01fe9523e6d6
- x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19008
diff
changeset
|
692 | CERTCertificate *crt_dat; |
|
01fe9523e6d6
- x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19008
diff
changeset
|
693 | PurpleCertificate *newcrt; |
|
01fe9523e6d6
- x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19008
diff
changeset
|
694 | |
|
01fe9523e6d6
- x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19008
diff
changeset
|
695 | g_return_val_if_fail(crt, NULL); |
|
01fe9523e6d6
- x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19008
diff
changeset
|
696 | g_return_val_if_fail(crt->scheme == &x509_nss, NULL); |
|
01fe9523e6d6
- x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19008
diff
changeset
|
697 | |
|
01fe9523e6d6
- x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19008
diff
changeset
|
698 | crt_dat = X509_NSS_DATA(crt); |
|
01fe9523e6d6
- x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19008
diff
changeset
|
699 | g_return_val_if_fail(crt_dat, NULL); |
|
01fe9523e6d6
- x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19008
diff
changeset
|
700 | |
|
01fe9523e6d6
- x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19008
diff
changeset
|
701 | /* Create the certificate copy */ |
|
01fe9523e6d6
- x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19008
diff
changeset
|
702 | newcrt = g_new0(PurpleCertificate, 1); |
|
01fe9523e6d6
- x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19008
diff
changeset
|
703 | newcrt->scheme = &x509_nss; |
|
19023
547e94194c7a
- Comment on NSS's refcounting prowess
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19014
diff
changeset
|
704 | /* NSS does refcounting automatically */ |
|
19009
01fe9523e6d6
- x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19008
diff
changeset
|
705 | newcrt->data = CERT_DupCertificate(crt_dat); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
29943
diff
changeset
|
706 | |
|
19009
01fe9523e6d6
- x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19008
diff
changeset
|
707 | return newcrt; |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
708 | } |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
709 | |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
710 | /** Frees a Certificate |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
711 | * |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
712 | * Destroys a Certificate's internal data structures and frees the pointer |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
713 | * given. |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
714 | * @param crt Certificate instance to be destroyed. It WILL NOT be destroyed |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
715 | * if it is not of the correct CertificateScheme. Can be NULL |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
716 | * |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
717 | */ |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
718 | static void |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
719 | x509_destroy_certificate(PurpleCertificate * crt) |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
720 | { |
|
19010
ad839d846fae
- x509_nss destroy_certificate
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19009
diff
changeset
|
721 | CERTCertificate *crt_dat; |
|
ad839d846fae
- x509_nss destroy_certificate
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19009
diff
changeset
|
722 | |
|
ad839d846fae
- x509_nss destroy_certificate
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19009
diff
changeset
|
723 | g_return_if_fail(crt); |
|
ad839d846fae
- x509_nss destroy_certificate
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19009
diff
changeset
|
724 | g_return_if_fail(crt->scheme == &x509_nss); |
|
ad839d846fae
- x509_nss destroy_certificate
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19009
diff
changeset
|
725 | |
|
ad839d846fae
- x509_nss destroy_certificate
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19009
diff
changeset
|
726 | crt_dat = X509_NSS_DATA(crt); |
|
ad839d846fae
- x509_nss destroy_certificate
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19009
diff
changeset
|
727 | g_return_if_fail(crt_dat); |
|
ad839d846fae
- x509_nss destroy_certificate
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19009
diff
changeset
|
728 | |
|
ad839d846fae
- x509_nss destroy_certificate
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19009
diff
changeset
|
729 | /* Finally we have the certificate. So let's kill it */ |
|
19023
547e94194c7a
- Comment on NSS's refcounting prowess
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19014
diff
changeset
|
730 | /* NSS does refcounting automatically */ |
|
19010
ad839d846fae
- x509_nss destroy_certificate
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19009
diff
changeset
|
731 | CERT_DestroyCertificate(crt_dat); |
|
19027
921b7e331382
- x509_destroy_certificate is supposed to free the PurpleCertificate
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19023
diff
changeset
|
732 | |
|
921b7e331382
- x509_destroy_certificate is supposed to free the PurpleCertificate
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19023
diff
changeset
|
733 | /* Delete the PurpleCertificate as well */ |
|
921b7e331382
- x509_destroy_certificate is supposed to free the PurpleCertificate
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19023
diff
changeset
|
734 | g_free(crt); |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
735 | } |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
736 | |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
737 | /** Determines whether one certificate has been issued and signed by another |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
738 | * |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
739 | * @param crt Certificate to check the signature of |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
740 | * @param issuer Issuer's certificate |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
741 | * |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
742 | * @return TRUE if crt was signed and issued by issuer, otherwise FALSE |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
743 | * @TODO Modify this function to return a reason for invalidity? |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
744 | */ |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
745 | static gboolean |
|
19980
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
746 | x509_signed_by(PurpleCertificate * crt, |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
747 | PurpleCertificate * issuer) |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
748 | { |
|
24065
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
749 | CERTCertificate *subjectCert; |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
750 | CERTCertificate *issuerCert; |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
751 | SECStatus st; |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
29943
diff
changeset
|
752 | |
|
24065
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
753 | issuerCert = X509_NSS_DATA(issuer); |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
754 | g_return_val_if_fail(issuerCert, FALSE); |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
755 | |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
756 | subjectCert = X509_NSS_DATA(crt); |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
757 | g_return_val_if_fail(subjectCert, FALSE); |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
758 | |
|
33810
8b2f9fad7227
ssl-nss: Fix handling of certificates without a Subject.
Daniel Atallah <datallah@pidgin.im>
parents:
33669
diff
changeset
|
759 | if (subjectCert->issuerName == NULL || issuerCert->subjectName == NULL |
|
24276
469eea3c328d
Fix a NULL pointer deref in the NSS SSL implementation with certain self-signed
Daniel Atallah <datallah@pidgin.im>
parents:
24065
diff
changeset
|
760 | || PORT_Strcmp(subjectCert->issuerName, issuerCert->subjectName) != 0) |
|
24065
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
761 | return FALSE; |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
762 | st = CERT_VerifySignedData(&subjectCert->signatureWrap, issuerCert, PR_Now(), NULL); |
|
bfc4c0035d91
Patch to fully enable NSS SSL Certificates from #6500.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
22104
diff
changeset
|
763 | return st == SECSuccess; |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
764 | } |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
765 | |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
766 | static GByteArray * |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
767 | x509_sha1sum(PurpleCertificate *crt) |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
768 | { |
|
19014
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
769 | CERTCertificate *crt_dat; |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
770 | size_t hashlen = 20; /* Size of an sha1sum */ |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
771 | GByteArray *sha1sum; |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
772 | SECItem *derCert; /* DER representation of the cert */ |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
773 | SECStatus st; |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
774 | |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
775 | g_return_val_if_fail(crt, NULL); |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
776 | g_return_val_if_fail(crt->scheme == &x509_nss, NULL); |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
777 | |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
778 | crt_dat = X509_NSS_DATA(crt); |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
779 | g_return_val_if_fail(crt_dat, NULL); |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
780 | |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
781 | /* Get the certificate DER representation */ |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
782 | derCert = &(crt_dat->derCert); |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
783 | |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
784 | /* Make a hash! */ |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
785 | sha1sum = g_byte_array_sized_new(hashlen); |
|
19797
92736e34b16a
- ssl-nss now reports a certificate's sha1sum correctly
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19671
diff
changeset
|
786 | /* glib leaves the size as 0 by default */ |
|
92736e34b16a
- ssl-nss now reports a certificate's sha1sum correctly
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19671
diff
changeset
|
787 | sha1sum->len = hashlen; |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
29943
diff
changeset
|
788 | |
|
19014
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
789 | st = PK11_HashBuf(SEC_OID_SHA1, sha1sum->data, |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
790 | derCert->data, derCert->len); |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
791 | |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
792 | /* Check for errors */ |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
793 | if (st != SECSuccess) { |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
794 | g_byte_array_free(sha1sum, TRUE); |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
795 | purple_debug_error("nss/x509", |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
796 | "Error: hashing failed!\n"); |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
797 | return NULL; |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
798 | } |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
799 | |
|
1a67cc27fb12
- x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19013
diff
changeset
|
800 | return sha1sum; |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
801 | } |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
802 | |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
803 | static gchar * |
|
19980
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
804 | x509_dn (PurpleCertificate *crt) |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
805 | { |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
806 | CERTCertificate *crt_dat; |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
29943
diff
changeset
|
807 | |
|
19980
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
808 | g_return_val_if_fail(crt, NULL); |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
809 | g_return_val_if_fail(crt->scheme == &x509_nss, NULL); |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
810 | |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
811 | crt_dat = X509_NSS_DATA(crt); |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
812 | g_return_val_if_fail(crt_dat, NULL); |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
813 | |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
814 | return g_strdup(crt_dat->subjectName); |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
815 | } |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
816 | |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
817 | static gchar * |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
818 | x509_issuer_dn (PurpleCertificate *crt) |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
819 | { |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
820 | CERTCertificate *crt_dat; |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
29943
diff
changeset
|
821 | |
|
19980
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
822 | g_return_val_if_fail(crt, NULL); |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
823 | g_return_val_if_fail(crt->scheme == &x509_nss, NULL); |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
824 | |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
825 | crt_dat = X509_NSS_DATA(crt); |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
826 | g_return_val_if_fail(crt_dat, NULL); |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
827 | |
|
24577
fdb8b167200e
x509_issuer_dn() should return the certificate's issuer name, not the cert
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
24513
diff
changeset
|
828 | return g_strdup(crt_dat->issuerName); |
|
19980
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
829 | } |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
830 | |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
831 | static gchar * |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
832 | x509_common_name (PurpleCertificate *crt) |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
833 | { |
|
19011
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
834 | CERTCertificate *crt_dat; |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
835 | char *nss_cn; |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
836 | gchar *ret_cn; |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
29943
diff
changeset
|
837 | |
|
19011
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
838 | g_return_val_if_fail(crt, NULL); |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
839 | g_return_val_if_fail(crt->scheme == &x509_nss, NULL); |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
840 | |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
841 | crt_dat = X509_NSS_DATA(crt); |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
842 | g_return_val_if_fail(crt_dat, NULL); |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
843 | |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
844 | /* Q: |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
845 | Why get a newly allocated string out of NSS, strdup it, and then |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
846 | return the new copy? |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
847 | |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
848 | A: |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
849 | The NSS LXR docs state that I should use the NSPR free functions on |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
850 | the strings that the NSS cert functions return. Since the libpurple |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
851 | API expects a g_free()-able string, we make our own copy and return |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
852 | that. |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
853 | |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
854 | NSPR is something of a prima donna. */ |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
855 | |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
856 | nss_cn = CERT_GetCommonName( &(crt_dat->subject) ); |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
857 | ret_cn = g_strdup(nss_cn); |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
858 | PORT_Free(nss_cn); |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
859 | |
|
21cdaee203e8
- x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19010
diff
changeset
|
860 | return ret_cn; |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
861 | } |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
862 | |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
863 | static gboolean |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
864 | x509_check_name (PurpleCertificate *crt, const gchar *name) |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
865 | { |
|
19012
7813c38f34e9
- ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19011
diff
changeset
|
866 | CERTCertificate *crt_dat; |
|
7813c38f34e9
- ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19011
diff
changeset
|
867 | SECStatus st; |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
29943
diff
changeset
|
868 | |
|
19012
7813c38f34e9
- ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19011
diff
changeset
|
869 | g_return_val_if_fail(crt, FALSE); |
|
7813c38f34e9
- ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19011
diff
changeset
|
870 | g_return_val_if_fail(crt->scheme == &x509_nss, FALSE); |
|
7813c38f34e9
- ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19011
diff
changeset
|
871 | |
|
7813c38f34e9
- ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19011
diff
changeset
|
872 | crt_dat = X509_NSS_DATA(crt); |
|
7813c38f34e9
- ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19011
diff
changeset
|
873 | g_return_val_if_fail(crt_dat, FALSE); |
|
7813c38f34e9
- ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19011
diff
changeset
|
874 | |
|
7813c38f34e9
- ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19011
diff
changeset
|
875 | st = CERT_VerifyCertName(crt_dat, name); |
|
7813c38f34e9
- ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19011
diff
changeset
|
876 | |
|
7813c38f34e9
- ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19011
diff
changeset
|
877 | if (st == SECSuccess) { |
|
7813c38f34e9
- ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19011
diff
changeset
|
878 | return TRUE; |
|
7813c38f34e9
- ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19011
diff
changeset
|
879 | } |
|
7813c38f34e9
- ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19011
diff
changeset
|
880 | else if (st == SECFailure) { |
|
7813c38f34e9
- ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19011
diff
changeset
|
881 | return FALSE; |
|
7813c38f34e9
- ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19011
diff
changeset
|
882 | } |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
29943
diff
changeset
|
883 | |
|
19012
7813c38f34e9
- ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19011
diff
changeset
|
884 | /* If we get here...bad things! */ |
|
19671
3848f6f679fd
- Change g_assert to purple_debug_error
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19486
diff
changeset
|
885 | purple_debug_error("nss/x509", |
|
3848f6f679fd
- Change g_assert to purple_debug_error
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19486
diff
changeset
|
886 | "x509_check_name fell through where it shouldn't " |
|
3848f6f679fd
- Change g_assert to purple_debug_error
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19486
diff
changeset
|
887 | "have.\n"); |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
888 | return FALSE; |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
889 | } |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
890 | |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
891 | static gboolean |
|
34246
2ca1bb194693
Update certificate API to use 64-bit unsigned values instead of time_t.
Daniel Atallah <datallah@pidgin.im>
parents:
34243
diff
changeset
|
892 | x509_times (PurpleCertificate *crt, gint64 *activation, gint64 *expiration) |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
893 | { |
|
19013
60c74d9597f3
- x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19012
diff
changeset
|
894 | CERTCertificate *crt_dat; |
|
60c74d9597f3
- x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19012
diff
changeset
|
895 | PRTime nss_activ, nss_expir; |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
29943
diff
changeset
|
896 | |
|
19013
60c74d9597f3
- x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19012
diff
changeset
|
897 | g_return_val_if_fail(crt, FALSE); |
|
60c74d9597f3
- x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19012
diff
changeset
|
898 | g_return_val_if_fail(crt->scheme == &x509_nss, FALSE); |
|
60c74d9597f3
- x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19012
diff
changeset
|
899 | |
|
60c74d9597f3
- x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19012
diff
changeset
|
900 | crt_dat = X509_NSS_DATA(crt); |
|
60c74d9597f3
- x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19012
diff
changeset
|
901 | g_return_val_if_fail(crt_dat, FALSE); |
|
60c74d9597f3
- x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19012
diff
changeset
|
902 | |
|
60c74d9597f3
- x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19012
diff
changeset
|
903 | /* Extract the times into ugly PRTime thingies */ |
|
60c74d9597f3
- x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19012
diff
changeset
|
904 | /* TODO: Maybe this shouldn't throw an error? */ |
|
60c74d9597f3
- x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19012
diff
changeset
|
905 | g_return_val_if_fail( |
|
60c74d9597f3
- x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19012
diff
changeset
|
906 | SECSuccess == CERT_GetCertTimes(crt_dat, |
|
60c74d9597f3
- x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19012
diff
changeset
|
907 | &nss_activ, &nss_expir), |
|
60c74d9597f3
- x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19012
diff
changeset
|
908 | FALSE); |
|
60c74d9597f3
- x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19012
diff
changeset
|
909 | |
|
19982
1b453261f6ec
- Fix ssl-nss x509 to properly convert NSPR PRTime to time_t (in
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19980
diff
changeset
|
910 | /* NSS's native PRTime type *almost* corresponds to time_t; however, |
|
1b453261f6ec
- Fix ssl-nss x509 to properly convert NSPR PRTime to time_t (in
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19980
diff
changeset
|
911 | it measures *microseconds* since the epoch, not seconds. Hence |
|
1b453261f6ec
- Fix ssl-nss x509 to properly convert NSPR PRTime to time_t (in
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19980
diff
changeset
|
912 | the funny conversion. */ |
|
34242
2aa4d5ab8916
Add workaround so that certificates with times that can't be represented using
Daniel Atallah <datallah@pidgin.im>
parents:
33841
diff
changeset
|
913 | nss_activ = nss_activ / 1000000; |
|
2aa4d5ab8916
Add workaround so that certificates with times that can't be represented using
Daniel Atallah <datallah@pidgin.im>
parents:
33841
diff
changeset
|
914 | nss_expir = nss_expir / 1000000; |
|
2aa4d5ab8916
Add workaround so that certificates with times that can't be represented using
Daniel Atallah <datallah@pidgin.im>
parents:
33841
diff
changeset
|
915 | |
|
19013
60c74d9597f3
- x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19012
diff
changeset
|
916 | if (activation) { |
|
34242
2aa4d5ab8916
Add workaround so that certificates with times that can't be represented using
Daniel Atallah <datallah@pidgin.im>
parents:
33841
diff
changeset
|
917 | *activation = nss_activ; |
|
19013
60c74d9597f3
- x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19012
diff
changeset
|
918 | } |
|
60c74d9597f3
- x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19012
diff
changeset
|
919 | if (expiration) { |
|
34242
2aa4d5ab8916
Add workaround so that certificates with times that can't be represented using
Daniel Atallah <datallah@pidgin.im>
parents:
33841
diff
changeset
|
920 | *expiration = nss_expir; |
|
19013
60c74d9597f3
- x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19012
diff
changeset
|
921 | } |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
29943
diff
changeset
|
922 | |
|
19013
60c74d9597f3
- x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19012
diff
changeset
|
923 | return TRUE; |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
924 | } |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
925 | |
|
32438
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
926 | static GByteArray * |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
927 | x509_get_der_data(PurpleCertificate *crt) |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
928 | { |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
929 | CERTCertificate *crt_dat; |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
930 | SECItem *dercrt; |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
931 | GByteArray *data; |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
932 | |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
933 | crt_dat = X509_NSS_DATA(crt); |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
934 | g_return_val_if_fail(crt_dat, NULL); |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
935 | |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
936 | dercrt = SEC_ASN1EncodeItem(NULL, NULL, crt_dat, |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
937 | SEC_ASN1_GET(SEC_SignedCertificateTemplate)); |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
938 | g_return_val_if_fail(dercrt != NULL, FALSE); |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
939 | |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
940 | data = g_byte_array_sized_new(dercrt->len); |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
941 | memcpy(data->data, dercrt->data, dercrt->len); |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
942 | data->len = dercrt->len; |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
943 | |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
944 | SECITEM_FreeItem(dercrt, PR_TRUE); |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
945 | |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
946 | return data; |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
947 | } |
|
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
948 | |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
949 | static PurpleCertificateScheme x509_nss = { |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
950 | "x509", /* Scheme name */ |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
951 | N_("X.509 Certificates"), /* User-visible scheme name */ |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
952 | x509_import_from_file, /* Certificate import function */ |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
953 | x509_export_certificate, /* Certificate export function */ |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
954 | x509_copy_certificate, /* Copy */ |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
955 | x509_destroy_certificate, /* Destroy cert */ |
|
19980
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
956 | x509_signed_by, /* Signed-by */ |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
957 | x509_sha1sum, /* SHA1 fingerprint */ |
|
19980
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
958 | x509_dn, /* Unique ID */ |
|
35d5d780ba42
- Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19859
diff
changeset
|
959 | x509_issuer_dn, /* Issuer Unique ID */ |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
960 | x509_common_name, /* Subject name */ |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
961 | x509_check_name, /* Check subject name */ |
|
19827
62c3805f723e
- Add purple_reserved fields to various structures.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19797
diff
changeset
|
962 | x509_times, /* Activation/Expiration time */ |
|
29930
80f4616de5ce
Implement reading multiple certificates from a single "bundle" of
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
27935
diff
changeset
|
963 | x509_importcerts_from_file, /* Multiple certificate import function */ |
|
32438
dc8991868906
A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31294
diff
changeset
|
964 | x509_get_der_data, /* Binary DER data */ |
|
19827
62c3805f723e
- Add purple_reserved fields to various structures.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19797
diff
changeset
|
965 | |
|
62c3805f723e
- Add purple_reserved fields to various structures.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19797
diff
changeset
|
966 | NULL |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
967 | }; |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
968 | |
| 15884 | 969 | static PurpleSslOps ssl_ops = |
| 7016 | 970 | { |
| 971 | ssl_nss_init, | |
| 972 | ssl_nss_uninit, | |
|
14222
71d8761db708
[gaim-migrate @ 16808]
Mark Doliner <markdoliner@pidgin.im>
parents:
13530
diff
changeset
|
973 | ssl_nss_connect, |
| 7016 | 974 | ssl_nss_close, |
| 975 | ssl_nss_read, | |
|
16744
fcdab37ba1c2
Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents:
16158
diff
changeset
|
976 | ssl_nss_write, |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
977 | ssl_nss_peer_certs, |
|
16744
fcdab37ba1c2
Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents:
16158
diff
changeset
|
978 | |
|
fcdab37ba1c2
Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents:
16158
diff
changeset
|
979 | /* padding */ |
|
fcdab37ba1c2
Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents:
16158
diff
changeset
|
980 | NULL, |
|
fcdab37ba1c2
Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents:
16158
diff
changeset
|
981 | NULL, |
|
35024
eb3afb7643ce
Added /*< private >*/ for padding members, clean them up and add missing ones
Ankit Vani <a@nevitus.org>
parents:
34249
diff
changeset
|
982 | NULL, |
|
16744
fcdab37ba1c2
Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents:
16158
diff
changeset
|
983 | NULL |
| 7016 | 984 | }; |
| 985 | ||
| 986 | ||
| 987 | static gboolean | |
| 15884 | 988 | plugin_load(PurplePlugin *plugin) |
| 7016 | 989 | { |
| 15884 | 990 | if (!purple_ssl_get_ops()) { |
| 991 | purple_ssl_set_ops(&ssl_ops); | |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
992 | } |
| 7016 | 993 | |
| 11033 | 994 | /* Init NSS now, so others can use it even if sslconn never does */ |
| 995 | ssl_nss_init_nss(); | |
| 996 | ||
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
997 | /* Register the X.509 functions we provide */ |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
998 | purple_certificate_register_scheme(&x509_nss); |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
999 | |
| 7016 | 1000 | return TRUE; |
| 1001 | } | |
| 1002 | ||
| 1003 | static gboolean | |
| 15884 | 1004 | plugin_unload(PurplePlugin *plugin) |
| 7016 | 1005 | { |
| 15884 | 1006 | if (purple_ssl_get_ops() == &ssl_ops) { |
| 1007 | purple_ssl_set_ops(NULL); | |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
1008 | } |
|
19008
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
1009 | |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
1010 | /* Unregister our X.509 functions */ |
|
222e4861b5a2
- Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17673
diff
changeset
|
1011 | purple_certificate_unregister_scheme(&x509_nss); |
|
7050
12730863b0f9
[gaim-migrate @ 7613]
Christian Hammond <chipx86@chipx86.com>
parents:
7029
diff
changeset
|
1012 | |
| 7016 | 1013 | return TRUE; |
| 1014 | } | |
| 1015 | ||
| 15884 | 1016 | static PurplePluginInfo info = |
| 7016 | 1017 | { |
| 15884 | 1018 | PURPLE_PLUGIN_MAGIC, |
| 1019 | PURPLE_MAJOR_VERSION, | |
| 1020 | PURPLE_MINOR_VERSION, | |
| 1021 | PURPLE_PLUGIN_STANDARD, /**< type */ | |
| 7016 | 1022 | NULL, /**< ui_requirement */ |
| 15884 | 1023 | PURPLE_PLUGIN_FLAG_INVISIBLE, /**< flags */ |
| 7016 | 1024 | NULL, /**< dependencies */ |
| 15884 | 1025 | PURPLE_PRIORITY_DEFAULT, /**< priority */ |
| 7016 | 1026 | |
|
7029
fe690e0607ec
[gaim-migrate @ 7592]
Christian Hammond <chipx86@chipx86.com>
parents:
7028
diff
changeset
|
1027 | SSL_NSS_PLUGIN_ID, /**< id */ |
| 7016 | 1028 | N_("NSS"), /**< name */ |
|
20288
5ca925a094e2
applied changes from 03b709ec2a153e7e82719df0ba4635108bb1d3c6
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
20221
diff
changeset
|
1029 | DISPLAY_VERSION, /**< version */ |
| 7016 | 1030 | /** summary */ |
| 1031 | N_("Provides SSL support through Mozilla NSS."), | |
| 1032 | /** description */ | |
| 1033 | N_("Provides SSL support through Mozilla NSS."), | |
| 1034 | "Christian Hammond <chipx86@gnupdate.org>", | |
| 15884 | 1035 | PURPLE_WEBSITE, /**< homepage */ |
| 7016 | 1036 | |
| 1037 | plugin_load, /**< load */ | |
| 1038 | plugin_unload, /**< unload */ | |
| 1039 | NULL, /**< destroy */ | |
| 1040 | ||
| 1041 | NULL, /**< ui_info */ | |
|
11513
89bf8d856291
[gaim-migrate @ 13758]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11256
diff
changeset
|
1042 | NULL, /**< extra_info */ |
|
89bf8d856291
[gaim-migrate @ 13758]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11256
diff
changeset
|
1043 | NULL, /**< prefs_info */ |
|
16744
fcdab37ba1c2
Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents:
16158
diff
changeset
|
1044 | NULL, /**< actions */ |
|
fcdab37ba1c2
Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents:
16158
diff
changeset
|
1045 | |
|
fcdab37ba1c2
Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents:
16158
diff
changeset
|
1046 | /* padding */ |
|
fcdab37ba1c2
Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents:
16158
diff
changeset
|
1047 | NULL, |
|
fcdab37ba1c2
Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents:
16158
diff
changeset
|
1048 | NULL, |
|
fcdab37ba1c2
Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents:
16158
diff
changeset
|
1049 | NULL, |
|
fcdab37ba1c2
Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents:
16158
diff
changeset
|
1050 | NULL |
| 7016 | 1051 | }; |
| 1052 | ||
| 1053 | static void | |
| 15884 | 1054 | init_plugin(PurplePlugin *plugin) |
| 7016 | 1055 | { |
| 1056 | } | |
| 1057 | ||
| 15884 | 1058 | PURPLE_INIT_PLUGIN(ssl_nss, init_plugin, info) |