annotate libpurple/plugins/ssl/ssl-nss.c @ 20282:62b83cebbb59

applied changes from 8b8bc5b1ef1263e1c0f00a9ed208accff09d988e through 38a516984dfbc8fb0def05acb69fc1180ec0b971
author Richard Laager <rlaager@wiktel.com>
date Sat, 29 Sep 2007 13:54:10 +0000
parents 401d1182d1dc
children 24ce4fcce5b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2 * @file ssl-nss.c Mozilla NSS SSL plugin.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
4 * purple
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
6 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11 * (at your option) any later version.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 * GNU General Public License for more details.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
19681
44b4e8bd759b The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19670
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22 #include "internal.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 #include "debug.h"
19068
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
24 #include "certificate.h"
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25 #include "plugin.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26 #include "sslconn.h"
19990
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
27 #include "util.h"
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28 #include "version.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 #define SSL_NSS_PLUGIN_ID "ssl-nss"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 #ifdef HAVE_NSS
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34 #undef HAVE_LONG_LONG /* Make Mozilla less angry. If angry, Mozilla SMASH! */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36 #include <nspr.h>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37 #include <nss.h>
19990
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
38 #include <nssb64.h>
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39 #include <pk11func.h>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40 #include <prio.h>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 #include <secerr.h>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42 #include <secmod.h>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
43 #include <ssl.h>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
44 #include <sslerr.h>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45 #include <sslproto.h>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
46
17566
016eee704a96 Avoid including NSPR's private header pprio.h just for the prototype of
Stu Tomlinson <stu@nosnilmot.com>
parents: 17514
diff changeset
47 /* This is defined in NSPR's <private/pprio.h>, but to avoid including a
016eee704a96 Avoid including NSPR's private header pprio.h just for the prototype of
Stu Tomlinson <stu@nosnilmot.com>
parents: 17514
diff changeset
48 * private header we duplicate the prototype here */
016eee704a96 Avoid including NSPR's private header pprio.h just for the prototype of
Stu Tomlinson <stu@nosnilmot.com>
parents: 17514
diff changeset
49 NSPR_API(PRFileDesc*) PR_ImportTCPSocket(PRInt32 osfd);
016eee704a96 Avoid including NSPR's private header pprio.h just for the prototype of
Stu Tomlinson <stu@nosnilmot.com>
parents: 17514
diff changeset
50
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51 typedef struct
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 PRFileDesc *fd;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54 PRFileDesc *in;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55 guint handshake_handler;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
57 } PurpleSslNssData;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
59 #define PURPLE_SSL_NSS_DATA(gsc) ((PurpleSslNssData *)gsc->private_data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61 static const PRIOMethods *_nss_methods = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62 static PRDescIdentity _identity;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64 /* Thank you, Evolution */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 static void
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66 set_errno(int code)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68 /* FIXME: this should handle more. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69 switch (code) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70 case PR_INVALID_ARGUMENT_ERROR:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
71 errno = EINVAL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
73 case PR_PENDING_INTERRUPT_ERROR:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
74 errno = EINTR;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
75 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
76 case PR_IO_PENDING_ERROR:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
77 errno = EAGAIN;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
78 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
79 case PR_WOULD_BLOCK_ERROR:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
80 errno = EAGAIN;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
81 /*errno = EWOULDBLOCK; */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
82 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
83 case PR_IN_PROGRESS_ERROR:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
84 errno = EINPROGRESS;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
85 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
86 case PR_ALREADY_INITIATED_ERROR:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
87 errno = EALREADY;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
88 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
89 case PR_NETWORK_UNREACHABLE_ERROR:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
90 errno = EHOSTUNREACH;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
91 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
92 case PR_CONNECT_REFUSED_ERROR:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
93 errno = ECONNREFUSED;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
94 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
95 case PR_CONNECT_TIMEOUT_ERROR:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
96 case PR_IO_TIMEOUT_ERROR:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
97 errno = ETIMEDOUT;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
98 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
99 case PR_NOT_CONNECTED_ERROR:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
100 errno = ENOTCONN;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
101 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
102 case PR_CONNECT_RESET_ERROR:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
103 errno = ECONNRESET;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
104 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
105 case PR_IO_ERROR:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
106 default:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
107 errno = EIO;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
108 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
109 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
110 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
111
19670
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
112 static gchar *get_error_text()
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
113 {
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
114 PRInt32 len = PR_GetErrorTextLength();
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
115 gchar *ret = NULL;
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
116
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
117 if (len > 0) {
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
118 ret = g_malloc(len + 1);
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
119 len = PR_GetErrorText(ret);
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
120 ret[len] = '\0';
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
121 }
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
122
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
123 return ret;
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
124 }
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
125
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
126 static void
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
127 ssl_nss_init_nss(void)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
128 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
129 char *lib;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
130 PR_Init(PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1);
16809
2a98d8b6095e Proabably fixes ticket #578, it's the recommended way of initializing NSS
Stu Tomlinson <stu@nosnilmot.com>
parents: 16665
diff changeset
131 NSS_NoDB_Init(".");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
133 /* TODO: Fix this so autoconf does the work trying to find this lib. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
134 #ifndef _WIN32
16098
634b96915d2e Death to Binreloc\!
Sean Egan <seanegan@gmail.com>
parents: 15822
diff changeset
135 lib = g_strdup(LIBDIR "/libnssckbi.so");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
136 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
137 lib = g_strdup("nssckbi.dll");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
138 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
139 SECMOD_AddNewModule("Builtins", lib, 0, 0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
140 g_free(lib);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
141 NSS_SetDomesticPolicy();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
142
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
143 _identity = PR_GetUniqueIdentity("Purple");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
144 _nss_methods = PR_GetDefaultIOMethods();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
145 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
146
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
147 static SECStatus
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
148 ssl_auth_cert(void *arg, PRFileDesc *socket, PRBool checksig,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
149 PRBool is_server)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
150 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
151 return SECSuccess;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
152
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
153 #if 0
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
154 CERTCertificate *cert;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
155 void *pinArg;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
156 SECStatus status;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
157
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
158 cert = SSL_PeerCertificate(socket);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
159 pinArg = SSL_RevealPinArg(socket);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
160
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
161 status = CERT_VerifyCertNow((CERTCertDBHandle *)arg, cert, checksig,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
162 certUsageSSLClient, pinArg);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
163
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
164 if (status != SECSuccess) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
165 purple_debug_error("nss", "CERT_VerifyCertNow failed\n");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
166 CERT_DestroyCertificate(cert);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
167 return status;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
168 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
169
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
170 CERT_DestroyCertificate(cert);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
171 return SECSuccess;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
172 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
173 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
174
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
175 static SECStatus
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
176 ssl_bad_cert(void *arg, PRFileDesc *socket)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
177 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
178 SECStatus status = SECFailure;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
179 PRErrorCode err;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
180
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
181 if (arg == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
182 return status;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
183
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
184 *(PRErrorCode *)arg = err = PORT_GetError();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
185
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
186 switch (err)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
187 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
188 case SEC_ERROR_INVALID_AVA:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
189 case SEC_ERROR_INVALID_TIME:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
190 case SEC_ERROR_BAD_SIGNATURE:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
191 case SEC_ERROR_EXPIRED_CERTIFICATE:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
192 case SEC_ERROR_UNKNOWN_ISSUER:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
193 case SEC_ERROR_UNTRUSTED_CERT:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
194 case SEC_ERROR_CERT_VALID:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
195 case SEC_ERROR_EXPIRED_ISSUER_CERTIFICATE:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
196 case SEC_ERROR_CRL_EXPIRED:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
197 case SEC_ERROR_CRL_BAD_SIGNATURE:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
198 case SEC_ERROR_EXTENSION_VALUE_INVALID:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
199 case SEC_ERROR_CA_CERT_INVALID:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
200 case SEC_ERROR_CERT_USAGES_INVALID:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
201 case SEC_ERROR_UNKNOWN_CRITICAL_EXTENSION:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
202 status = SECSuccess;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
203 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
204
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
205 default:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
206 status = SECFailure;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
207 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
208 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
209
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
210 purple_debug_error("nss", "Bad certificate: %d\n", err);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
211
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
212 return status;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
213 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
214
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
215 static gboolean
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
216 ssl_nss_init(void)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
217 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
218 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
219 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
220
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
221 static void
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
222 ssl_nss_uninit(void)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
223 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
224 PR_Cleanup();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
225
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
226 _nss_methods = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
227 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
228
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
229 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
230 ssl_nss_handshake_cb(gpointer data, int fd, PurpleInputCondition cond)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
231 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
232 PurpleSslConnection *gsc = (PurpleSslConnection *)data;
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
233 PurpleSslNssData *nss_data = gsc->private_data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
234
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
235 /* I don't think this the best way to do this...
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
236 * It seems to work because it'll eventually use the cached value
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
237 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
238 if(SSL_ForceHandshake(nss_data->in) != SECSuccess) {
19670
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
239 gchar *error_txt;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
240 set_errno(PR_GetError());
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
241 if (errno == EAGAIN || errno == EWOULDBLOCK)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
242 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
243
19670
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
244 error_txt = get_error_text();
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
245 purple_debug_error("nss", "Handshake failed %s (%d)\n", error_txt ? error_txt : "", PR_GetError());
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
246 g_free(error_txt);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
247
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
248 if (gsc->error_cb != NULL)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
249 gsc->error_cb(gsc, PURPLE_SSL_HANDSHAKE_FAILED, gsc->connect_cb_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
250
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
251 purple_ssl_close(gsc);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
252
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
253 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
254 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
255
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
256 purple_input_remove(nss_data->handshake_handler);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
257 nss_data->handshake_handler = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
258
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
259 gsc->connect_cb(gsc->connect_cb_data, gsc, cond);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
260 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
261
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
262 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
263 ssl_nss_connect(PurpleSslConnection *gsc)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
264 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
265 PurpleSslNssData *nss_data = g_new0(PurpleSslNssData, 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
266 PRSocketOptionData socket_opt;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
267
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
268 gsc->private_data = nss_data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
269
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
270 nss_data->fd = PR_ImportTCPSocket(gsc->fd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
271
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
272 if (nss_data->fd == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
273 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
274 purple_debug_error("nss", "nss_data->fd == NULL!\n");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
275
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
276 if (gsc->error_cb != NULL)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
277 gsc->error_cb(gsc, PURPLE_SSL_CONNECT_FAILED, gsc->connect_cb_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
278
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
279 purple_ssl_close((PurpleSslConnection *)gsc);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
280
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
281 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
282 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
283
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
284 socket_opt.option = PR_SockOpt_Nonblocking;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
285 socket_opt.value.non_blocking = PR_TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
286
19670
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
287 if (PR_SetSocketOption(nss_data->fd, &socket_opt) != PR_SUCCESS) {
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
288 gchar *error_txt = get_error_text();
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
289 purple_debug_warning("nss", "unable to set socket into non-blocking mode: %s (%d)\n", error_txt ? error_txt : "", PR_GetError());
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
290 g_free(error_txt);
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
291 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
292
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
293 nss_data->in = SSL_ImportFD(NULL, nss_data->fd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
294
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
295 if (nss_data->in == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
296 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
297 purple_debug_error("nss", "nss_data->in == NUL!\n");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
298
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
299 if (gsc->error_cb != NULL)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
300 gsc->error_cb(gsc, PURPLE_SSL_CONNECT_FAILED, gsc->connect_cb_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
301
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
302 purple_ssl_close((PurpleSslConnection *)gsc);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
303
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
304 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
305 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
306
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
307 SSL_OptionSet(nss_data->in, SSL_SECURITY, PR_TRUE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
308 SSL_OptionSet(nss_data->in, SSL_HANDSHAKE_AS_CLIENT, PR_TRUE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
309
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
310 SSL_AuthCertificateHook(nss_data->in,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
311 (SSLAuthCertificate)ssl_auth_cert,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
312 (void *)CERT_GetDefaultCertDB());
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
313 SSL_BadCertHook(nss_data->in, (SSLBadCertHandler)ssl_bad_cert, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
314
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
315 if(gsc->host)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
316 SSL_SetURL(nss_data->in, gsc->host);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
317
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
318 #if 0
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
319 /* This seems like it'd the be the correct way to implement the
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
320 nonblocking stuff, but it doesn't seem to work */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
321 SSL_HandshakeCallback(nss_data->in,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
322 (SSLHandshakeCallback) ssl_nss_handshake_cb, gsc);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
323 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
324 SSL_ResetHandshake(nss_data->in, PR_FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
325
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
326 nss_data->handshake_handler = purple_input_add(gsc->fd,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
327 PURPLE_INPUT_READ, ssl_nss_handshake_cb, gsc);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
328
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
329 ssl_nss_handshake_cb(gsc, gsc->fd, PURPLE_INPUT_READ);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
330 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
331
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
332 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
333 ssl_nss_close(PurpleSslConnection *gsc)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
334 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
335 PurpleSslNssData *nss_data = PURPLE_SSL_NSS_DATA(gsc);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
336
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
337 if(!nss_data)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
338 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
339
17514
278e22624ce5 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 <daniel.atallah@gmail.com>
parents: 16809
diff changeset
340 if (nss_data->in) {
278e22624ce5 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 <daniel.atallah@gmail.com>
parents: 16809
diff changeset
341 PR_Close(nss_data->in);
278e22624ce5 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 <daniel.atallah@gmail.com>
parents: 16809
diff changeset
342 gsc->fd = -1;
278e22624ce5 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 <daniel.atallah@gmail.com>
parents: 16809
diff changeset
343 } else if (nss_data->fd) {
278e22624ce5 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 <daniel.atallah@gmail.com>
parents: 16809
diff changeset
344 PR_Close(nss_data->fd);
278e22624ce5 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 <daniel.atallah@gmail.com>
parents: 16809
diff changeset
345 gsc->fd = -1;
278e22624ce5 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 <daniel.atallah@gmail.com>
parents: 16809
diff changeset
346 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
347
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
348 if (nss_data->handshake_handler)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
349 purple_input_remove(nss_data->handshake_handler);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
350
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
351 g_free(nss_data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
352 gsc->private_data = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
353 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
354
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
355 static size_t
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
356 ssl_nss_read(PurpleSslConnection *gsc, void *data, size_t len)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
357 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
358 ssize_t ret;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
359 PurpleSslNssData *nss_data = PURPLE_SSL_NSS_DATA(gsc);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
360
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
361 ret = PR_Read(nss_data->in, data, len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
362
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
363 if (ret == -1)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
364 set_errno(PR_GetError());
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
365
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
366 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
367 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
368
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
369 static size_t
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
370 ssl_nss_write(PurpleSslConnection *gsc, const void *data, size_t len)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
371 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
372 ssize_t ret;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
373 PurpleSslNssData *nss_data = PURPLE_SSL_NSS_DATA(gsc);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
375 if(!nss_data)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
376 return 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
377
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
378 ret = PR_Write(nss_data->in, data, len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
379
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
380 if (ret == -1)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
381 set_errno(PR_GetError());
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
382
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
383 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
384 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
385
19068
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
386 static GList *
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
387 ssl_nss_peer_certs(PurpleSslConnection *gsc)
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
388 {
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
389 PurpleSslNssData *nss_data = PURPLE_SSL_NSS_DATA(gsc);
19670
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
390 CERTCertificate *cert;
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
391 /*
19068
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
392 GList *chain = NULL;
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
393 void *pinArg;
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
394 SECStatus status;
19670
fb3b3e93b9ca Attempt to display user readable error messages for NSS.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19649
diff changeset
395 */
19068
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
396
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
397 /* TODO: this is a blind guess */
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
398 cert = SSL_PeerCertificate(nss_data->fd);
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
399
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
400
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
401
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
402 return NULL;
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
403 }
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
404
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
405 /************************************************************************/
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
406 /* X.509 functionality */
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
407 /************************************************************************/
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
408 static PurpleCertificateScheme x509_nss;
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
409
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
410 /** Helpr macro to retrieve the NSS certdata from a PurpleCertificate */
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
411 #define X509_NSS_DATA(pcrt) ( (CERTCertificate * ) (pcrt->data) )
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
412
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
413 /** Imports a PEM-formatted X.509 certificate from the specified file.
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
414 * @param filename Filename to import from. Format is PEM
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
415 *
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
416 * @return A newly allocated Certificate structure of the x509_gnutls scheme
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
417 */
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
418 static PurpleCertificate *
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
419 x509_import_from_file(const gchar *filename)
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
420 {
19273
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
421 gchar *rawcert;
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
422 gsize len = 0;
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
423 CERTCertificate *crt_dat;
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
424 PurpleCertificate *crt;
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
425
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
426 g_return_val_if_fail(filename, NULL);
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
427
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
428 purple_debug_info("nss/x509",
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
429 "Loading certificate from %s\n",
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
430 filename);
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
431
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
432 /* Load the raw data up */
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
433 g_return_val_if_fail(
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
434 g_file_get_contents(filename,
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
435 &rawcert, &len,
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
436 NULL ),
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
437 NULL);
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
438
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
439 /* Decode the certificate */
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
440 crt_dat = CERT_DecodeCertFromPackage(rawcert, len);
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
441 g_free(rawcert);
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
442
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
443 g_return_val_if_fail(crt_dat, NULL);
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
444
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
445 crt = g_new0(PurpleCertificate, 1);
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
446 crt->scheme = &x509_nss;
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
447 crt->data = crt_dat;
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
448
db42632ac756 - Add x509_import_from_file
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19272
diff changeset
449 return crt;
19068
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
450 }
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
451
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
452 /**
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
453 * Exports a PEM-formatted X.509 certificate to the specified file.
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
454 * @param filename Filename to export to. Format will be PEM
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
455 * @param crt Certificate to export
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
456 *
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
457 * @return TRUE if success, otherwise FALSE
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
458 */
19990
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
459 /* This function should not be so complicated, but NSS doesn't seem to have a
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
460 "convert yon certificate to PEM format" function. */
19068
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
461 static gboolean
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
462 x509_export_certificate(const gchar *filename, PurpleCertificate *crt)
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
463 {
19990
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
464 CERTCertificate *crt_dat;
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
465 SECItem *dercrt;
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
466 gchar *b64crt;
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
467 gchar *pemcrt;
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
468 gboolean ret = FALSE;
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
469
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
470 g_return_val_if_fail(filename, FALSE);
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
471 g_return_val_if_fail(crt, FALSE);
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
472 g_return_val_if_fail(crt->scheme == &x509_nss, FALSE);
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
473
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
474 crt_dat = X509_NSS_DATA(crt);
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
475 g_return_val_if_fail(crt_dat, FALSE);
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
476
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
477 purple_debug_info("nss/x509",
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
478 "Exporting certificate to %s\n", filename);
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
479
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
480 /* First, use NSS voodoo to create a DER-formatted certificate */
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
481 dercrt = SEC_ASN1EncodeItem(NULL, NULL, crt_dat,
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
482 SEC_ASN1_GET(SEC_SignedCertificateTemplate));
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
483 g_return_val_if_fail(dercrt != NULL, FALSE);
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
484
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
485 /* Now encode it to b64 */
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
486 b64crt = NSSBase64_EncodeItem(NULL, NULL, 0, dercrt);
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
487 SECITEM_FreeItem(dercrt, PR_TRUE);
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
488 g_return_val_if_fail(b64crt, FALSE);
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
489
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
490 /* Wrap it in nice PEM header things */
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
491 pemcrt = g_strdup_printf("-----BEGIN CERTIFICATE-----\n%s\n-----END CERTIFICATE-----\n", b64crt);
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
492 PORT_Free(b64crt); /* Notice that b64crt was allocated by an NSS
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
493 function; hence, we'll let NSPR free it. */
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
494
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
495 /* Finally, dump the silly thing to a file. */
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
496 ret = purple_util_write_data_to_file_absolute(filename, pemcrt, -1);
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
497
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
498 g_free(pemcrt);
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
499
47f2becb7a60 - Make ssl-nss x509_export_certificate work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19989
diff changeset
500 return ret;
19068
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
501 }
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
502
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
503 static PurpleCertificate *
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
504 x509_copy_certificate(PurpleCertificate *crt)
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
505 {
19069
fcb3e4a2aa9a - x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19068
diff changeset
506 CERTCertificate *crt_dat;
fcb3e4a2aa9a - x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19068
diff changeset
507 PurpleCertificate *newcrt;
fcb3e4a2aa9a - x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19068
diff changeset
508
fcb3e4a2aa9a - x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19068
diff changeset
509 g_return_val_if_fail(crt, NULL);
fcb3e4a2aa9a - x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19068
diff changeset
510 g_return_val_if_fail(crt->scheme == &x509_nss, NULL);
fcb3e4a2aa9a - x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19068
diff changeset
511
fcb3e4a2aa9a - x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19068
diff changeset
512 crt_dat = X509_NSS_DATA(crt);
fcb3e4a2aa9a - x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19068
diff changeset
513 g_return_val_if_fail(crt_dat, NULL);
fcb3e4a2aa9a - x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19068
diff changeset
514
fcb3e4a2aa9a - x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19068
diff changeset
515 /* Create the certificate copy */
fcb3e4a2aa9a - x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19068
diff changeset
516 newcrt = g_new0(PurpleCertificate, 1);
fcb3e4a2aa9a - x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19068
diff changeset
517 newcrt->scheme = &x509_nss;
19083
5b8035030053 - Comment on NSS's refcounting prowess
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19074
diff changeset
518 /* NSS does refcounting automatically */
19069
fcb3e4a2aa9a - x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19068
diff changeset
519 newcrt->data = CERT_DupCertificate(crt_dat);
fcb3e4a2aa9a - x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19068
diff changeset
520
fcb3e4a2aa9a - x509_nss copy op
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19068
diff changeset
521 return newcrt;
19068
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
522 }
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
523
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
524 /** Frees a Certificate
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
525 *
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
526 * Destroys a Certificate's internal data structures and frees the pointer
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
527 * given.
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
528 * @param crt Certificate instance to be destroyed. It WILL NOT be destroyed
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
529 * if it is not of the correct CertificateScheme. Can be NULL
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
530 *
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
531 */
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
532 static void
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
533 x509_destroy_certificate(PurpleCertificate * crt)
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
534 {
19070
7ccb5ab3e07e - x509_nss destroy_certificate
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19069
diff changeset
535 CERTCertificate *crt_dat;
7ccb5ab3e07e - x509_nss destroy_certificate
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19069
diff changeset
536
7ccb5ab3e07e - x509_nss destroy_certificate
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19069
diff changeset
537 g_return_if_fail(crt);
7ccb5ab3e07e - x509_nss destroy_certificate
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19069
diff changeset
538 g_return_if_fail(crt->scheme == &x509_nss);
7ccb5ab3e07e - x509_nss destroy_certificate
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19069
diff changeset
539
7ccb5ab3e07e - x509_nss destroy_certificate
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19069
diff changeset
540 crt_dat = X509_NSS_DATA(crt);
7ccb5ab3e07e - x509_nss destroy_certificate
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19069
diff changeset
541 g_return_if_fail(crt_dat);
7ccb5ab3e07e - x509_nss destroy_certificate
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19069
diff changeset
542
7ccb5ab3e07e - x509_nss destroy_certificate
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19069
diff changeset
543 /* Finally we have the certificate. So let's kill it */
19083
5b8035030053 - Comment on NSS's refcounting prowess
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19074
diff changeset
544 /* NSS does refcounting automatically */
19070
7ccb5ab3e07e - x509_nss destroy_certificate
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19069
diff changeset
545 CERT_DestroyCertificate(crt_dat);
19087
7fa5d10969f4 - x509_destroy_certificate is supposed to free the PurpleCertificate
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19083
diff changeset
546
7fa5d10969f4 - x509_destroy_certificate is supposed to free the PurpleCertificate
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19083
diff changeset
547 /* Delete the PurpleCertificate as well */
7fa5d10969f4 - x509_destroy_certificate is supposed to free the PurpleCertificate
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19083
diff changeset
548 g_free(crt);
19068
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
549 }
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
550
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
551 /** Determines whether one certificate has been issued and signed by another
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
552 *
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
553 * @param crt Certificate to check the signature of
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
554 * @param issuer Issuer's certificate
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
555 *
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
556 * @return TRUE if crt was signed and issued by issuer, otherwise FALSE
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
557 * @TODO Modify this function to return a reason for invalidity?
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
558 */
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
559 static gboolean
19987
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
560 x509_signed_by(PurpleCertificate * crt,
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
561 PurpleCertificate * issuer)
19068
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
562 {
19991
401d1182d1dc - Make x509_signed_by return TRUE indiscriminately so that other things
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19990
diff changeset
563 return TRUE;
19068
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
564 }
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
565
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
566 static GByteArray *
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
567 x509_sha1sum(PurpleCertificate *crt)
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
568 {
19074
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
569 CERTCertificate *crt_dat;
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
570 size_t hashlen = 20; /* Size of an sha1sum */
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
571 GByteArray *sha1sum;
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
572 SECItem *derCert; /* DER representation of the cert */
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
573 SECStatus st;
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
574
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
575 g_return_val_if_fail(crt, NULL);
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
576 g_return_val_if_fail(crt->scheme == &x509_nss, NULL);
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
577
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
578 crt_dat = X509_NSS_DATA(crt);
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
579 g_return_val_if_fail(crt_dat, NULL);
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
580
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
581 /* Get the certificate DER representation */
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
582 derCert = &(crt_dat->derCert);
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
583
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
584 /* Make a hash! */
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
585 sha1sum = g_byte_array_sized_new(hashlen);
19631
578b3c67d52c - ssl-nss now reports a certificate's sha1sum correctly
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19508
diff changeset
586 /* glib leaves the size as 0 by default */
578b3c67d52c - ssl-nss now reports a certificate's sha1sum correctly
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19508
diff changeset
587 sha1sum->len = hashlen;
578b3c67d52c - ssl-nss now reports a certificate's sha1sum correctly
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19508
diff changeset
588
19074
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
589 st = PK11_HashBuf(SEC_OID_SHA1, sha1sum->data,
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
590 derCert->data, derCert->len);
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
591
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
592 /* Check for errors */
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
593 if (st != SECSuccess) {
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
594 g_byte_array_free(sha1sum, TRUE);
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
595 purple_debug_error("nss/x509",
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
596 "Error: hashing failed!\n");
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
597 return NULL;
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
598 }
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
599
3004bfa0e846 - x509_nss sha1sum
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19073
diff changeset
600 return sha1sum;
19068
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
601 }
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
602
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
603 static gchar *
19987
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
604 x509_dn (PurpleCertificate *crt)
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
605 {
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
606 CERTCertificate *crt_dat;
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
607
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
608 g_return_val_if_fail(crt, NULL);
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
609 g_return_val_if_fail(crt->scheme == &x509_nss, NULL);
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
610
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
611 crt_dat = X509_NSS_DATA(crt);
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
612 g_return_val_if_fail(crt_dat, NULL);
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
613
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
614 return g_strdup(crt_dat->subjectName);
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
615 }
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
616
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
617 static gchar *
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
618 x509_issuer_dn (PurpleCertificate *crt)
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
619 {
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
620 CERTCertificate *crt_dat;
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
621
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
622 g_return_val_if_fail(crt, NULL);
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
623 g_return_val_if_fail(crt->scheme == &x509_nss, NULL);
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
624
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
625 crt_dat = X509_NSS_DATA(crt);
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
626 g_return_val_if_fail(crt_dat, NULL);
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
627
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
628 return g_strdup(crt_dat->subjectName);
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
629 }
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
630
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
631 static gchar *
19068
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
632 x509_common_name (PurpleCertificate *crt)
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
633 {
19071
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
634 CERTCertificate *crt_dat;
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
635 char *nss_cn;
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
636 gchar *ret_cn;
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
637
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
638 g_return_val_if_fail(crt, NULL);
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
639 g_return_val_if_fail(crt->scheme == &x509_nss, NULL);
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
640
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
641 crt_dat = X509_NSS_DATA(crt);
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
642 g_return_val_if_fail(crt_dat, NULL);
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
643
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
644 /* Q:
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
645 Why get a newly allocated string out of NSS, strdup it, and then
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
646 return the new copy?
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
647
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
648 A:
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
649 The NSS LXR docs state that I should use the NSPR free functions on
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
650 the strings that the NSS cert functions return. Since the libpurple
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
651 API expects a g_free()-able string, we make our own copy and return
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
652 that.
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
653
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
654 NSPR is something of a prima donna. */
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
655
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
656 nss_cn = CERT_GetCommonName( &(crt_dat->subject) );
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
657 ret_cn = g_strdup(nss_cn);
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
658 PORT_Free(nss_cn);
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
659
d224a1e4b919 - x509_nss get_subject_name (x509_common_name)
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19070
diff changeset
660 return ret_cn;
19068
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
661 }
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
662
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
663 static gboolean
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
664 x509_check_name (PurpleCertificate *crt, const gchar *name)
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
665 {
19072
4bdf4ce3473b - ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19071
diff changeset
666 CERTCertificate *crt_dat;
4bdf4ce3473b - ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19071
diff changeset
667 SECStatus st;
4bdf4ce3473b - ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19071
diff changeset
668
4bdf4ce3473b - ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19071
diff changeset
669 g_return_val_if_fail(crt, FALSE);
4bdf4ce3473b - ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19071
diff changeset
670 g_return_val_if_fail(crt->scheme == &x509_nss, FALSE);
4bdf4ce3473b - ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19071
diff changeset
671
4bdf4ce3473b - ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19071
diff changeset
672 crt_dat = X509_NSS_DATA(crt);
4bdf4ce3473b - ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19071
diff changeset
673 g_return_val_if_fail(crt_dat, FALSE);
4bdf4ce3473b - ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19071
diff changeset
674
4bdf4ce3473b - ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19071
diff changeset
675 st = CERT_VerifyCertName(crt_dat, name);
4bdf4ce3473b - ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19071
diff changeset
676
4bdf4ce3473b - ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19071
diff changeset
677 if (st == SECSuccess) {
4bdf4ce3473b - ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19071
diff changeset
678 return TRUE;
4bdf4ce3473b - ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19071
diff changeset
679 }
4bdf4ce3473b - ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19071
diff changeset
680 else if (st == SECFailure) {
4bdf4ce3473b - ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19071
diff changeset
681 return FALSE;
4bdf4ce3473b - ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19071
diff changeset
682 }
4bdf4ce3473b - ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19071
diff changeset
683
4bdf4ce3473b - ssl-nss x509_nss check_name
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19071
diff changeset
684 /* If we get here...bad things! */
19508
f0c3497e2ea6 - Change g_assert to purple_debug_error
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19273
diff changeset
685 purple_debug_error("nss/x509",
f0c3497e2ea6 - Change g_assert to purple_debug_error
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19273
diff changeset
686 "x509_check_name fell through where it shouldn't "
f0c3497e2ea6 - Change g_assert to purple_debug_error
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19273
diff changeset
687 "have.\n");
19068
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
688 return FALSE;
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
689 }
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
690
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
691 static gboolean
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
692 x509_times (PurpleCertificate *crt, time_t *activation, time_t *expiration)
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
693 {
19073
2156321c5482 - x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19072
diff changeset
694 CERTCertificate *crt_dat;
2156321c5482 - x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19072
diff changeset
695 PRTime nss_activ, nss_expir;
2156321c5482 - x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19072
diff changeset
696
2156321c5482 - x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19072
diff changeset
697 g_return_val_if_fail(crt, FALSE);
2156321c5482 - x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19072
diff changeset
698 g_return_val_if_fail(crt->scheme == &x509_nss, FALSE);
2156321c5482 - x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19072
diff changeset
699
2156321c5482 - x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19072
diff changeset
700 crt_dat = X509_NSS_DATA(crt);
2156321c5482 - x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19072
diff changeset
701 g_return_val_if_fail(crt_dat, FALSE);
2156321c5482 - x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19072
diff changeset
702
2156321c5482 - x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19072
diff changeset
703 /* Extract the times into ugly PRTime thingies */
2156321c5482 - x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19072
diff changeset
704 /* TODO: Maybe this shouldn't throw an error? */
2156321c5482 - x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19072
diff changeset
705 g_return_val_if_fail(
2156321c5482 - x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19072
diff changeset
706 SECSuccess == CERT_GetCertTimes(crt_dat,
2156321c5482 - x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19072
diff changeset
707 &nss_activ, &nss_expir),
2156321c5482 - x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19072
diff changeset
708 FALSE);
2156321c5482 - x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19072
diff changeset
709
19989
4f870bb6d3e6 - Fix ssl-nss x509 to properly convert NSPR PRTime to time_t (in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19987
diff changeset
710 /* NSS's native PRTime type *almost* corresponds to time_t; however,
4f870bb6d3e6 - Fix ssl-nss x509 to properly convert NSPR PRTime to time_t (in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19987
diff changeset
711 it measures *microseconds* since the epoch, not seconds. Hence
4f870bb6d3e6 - Fix ssl-nss x509 to properly convert NSPR PRTime to time_t (in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19987
diff changeset
712 the funny conversion. */
19073
2156321c5482 - x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19072
diff changeset
713 if (activation) {
19989
4f870bb6d3e6 - Fix ssl-nss x509 to properly convert NSPR PRTime to time_t (in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19987
diff changeset
714 *activation = nss_activ / 1000000;
19073
2156321c5482 - x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19072
diff changeset
715 }
2156321c5482 - x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19072
diff changeset
716 if (expiration) {
19989
4f870bb6d3e6 - Fix ssl-nss x509 to properly convert NSPR PRTime to time_t (in
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19987
diff changeset
717 *expiration = nss_expir / 1000000;
19073
2156321c5482 - x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19072
diff changeset
718 }
2156321c5482 - x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19072
diff changeset
719
2156321c5482 - x509_nss get_times
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19072
diff changeset
720 return TRUE;
19068
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
721 }
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
722
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
723 static PurpleCertificateScheme x509_nss = {
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
724 "x509", /* Scheme name */
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
725 N_("X.509 Certificates"), /* User-visible scheme name */
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
726 x509_import_from_file, /* Certificate import function */
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
727 x509_export_certificate, /* Certificate export function */
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
728 x509_copy_certificate, /* Copy */
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
729 x509_destroy_certificate, /* Destroy cert */
19987
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
730 x509_signed_by, /* Signed-by */
19068
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
731 x509_sha1sum, /* SHA1 fingerprint */
19987
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
732 x509_dn, /* Unique ID */
eda223b50bdc - Make ssl-nss unique_id and issuer_unique_id work
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19681
diff changeset
733 x509_issuer_dn, /* Issuer Unique ID */
19068
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
734 x509_common_name, /* Subject name */
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
735 x509_check_name, /* Check subject name */
19649
450f4a3c4c0f - Add purple_reserved fields to various structures.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19631
diff changeset
736 x509_times, /* Activation/Expiration time */
450f4a3c4c0f - Add purple_reserved fields to various structures.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19631
diff changeset
737
450f4a3c4c0f - Add purple_reserved fields to various structures.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19631
diff changeset
738 NULL,
450f4a3c4c0f - Add purple_reserved fields to various structures.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19631
diff changeset
739 NULL,
450f4a3c4c0f - Add purple_reserved fields to various structures.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19631
diff changeset
740 NULL,
450f4a3c4c0f - Add purple_reserved fields to various structures.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19631
diff changeset
741 NULL
19068
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
742 };
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
743
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
744 static PurpleSslOps ssl_ops =
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
745 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
746 ssl_nss_init,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
747 ssl_nss_uninit,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
748 ssl_nss_connect,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
749 ssl_nss_close,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
750 ssl_nss_read,
16665
6531f1a2e1d7 Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents: 16098
diff changeset
751 ssl_nss_write,
19068
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
752 ssl_nss_peer_certs,
16665
6531f1a2e1d7 Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents: 16098
diff changeset
753
6531f1a2e1d7 Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents: 16098
diff changeset
754 /* padding */
6531f1a2e1d7 Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents: 16098
diff changeset
755 NULL,
6531f1a2e1d7 Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents: 16098
diff changeset
756 NULL,
6531f1a2e1d7 Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents: 16098
diff changeset
757 NULL
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
758 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
759
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
760 #endif /* HAVE_NSS */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
761
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
762
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
763 static gboolean
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
764 plugin_load(PurplePlugin *plugin)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
765 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
766 #ifdef HAVE_NSS
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
767 if (!purple_ssl_get_ops()) {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
768 purple_ssl_set_ops(&ssl_ops);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
769 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
770
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
771 /* Init NSS now, so others can use it even if sslconn never does */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
772 ssl_nss_init_nss();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
773
19068
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
774 /* Register the X.509 functions we provide */
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
775 purple_certificate_register_scheme(&x509_nss);
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
776
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
777 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
778 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
779 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
780 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
781 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
782
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
783 static gboolean
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
784 plugin_unload(PurplePlugin *plugin)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
785 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
786 #ifdef HAVE_NSS
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
787 if (purple_ssl_get_ops() == &ssl_ops) {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
788 purple_ssl_set_ops(NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
789 }
19068
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
790
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
791 /* Unregister our X.509 functions */
9ac0fbb569a5 - Skeleton for ssl-nss x509 provider
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17566
diff changeset
792 purple_certificate_unregister_scheme(&x509_nss);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
793 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
794
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
795 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
796 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
797
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
798 static PurplePluginInfo info =
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
799 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
800 PURPLE_PLUGIN_MAGIC,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
801 PURPLE_MAJOR_VERSION,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
802 PURPLE_MINOR_VERSION,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
803 PURPLE_PLUGIN_STANDARD, /**< type */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
804 NULL, /**< ui_requirement */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
805 PURPLE_PLUGIN_FLAG_INVISIBLE, /**< flags */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
806 NULL, /**< dependencies */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
807 PURPLE_PRIORITY_DEFAULT, /**< priority */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
808
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
809 SSL_NSS_PLUGIN_ID, /**< id */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
810 N_("NSS"), /**< name */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
811 VERSION, /**< version */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
812 /** summary */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
813 N_("Provides SSL support through Mozilla NSS."),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
814 /** description */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
815 N_("Provides SSL support through Mozilla NSS."),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
816 "Christian Hammond <chipx86@gnupdate.org>",
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
817 PURPLE_WEBSITE, /**< homepage */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
818
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
819 plugin_load, /**< load */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
820 plugin_unload, /**< unload */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
821 NULL, /**< destroy */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
822
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
823 NULL, /**< ui_info */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
824 NULL, /**< extra_info */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
825 NULL, /**< prefs_info */
16665
6531f1a2e1d7 Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents: 16098
diff changeset
826 NULL, /**< actions */
6531f1a2e1d7 Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents: 16098
diff changeset
827
6531f1a2e1d7 Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents: 16098
diff changeset
828 /* padding */
6531f1a2e1d7 Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents: 16098
diff changeset
829 NULL,
6531f1a2e1d7 Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents: 16098
diff changeset
830 NULL,
6531f1a2e1d7 Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents: 16098
diff changeset
831 NULL,
6531f1a2e1d7 Added NULL pads to ssl stuff
Gary Kramlich <grim@reaperworld.com>
parents: 16098
diff changeset
832 NULL
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
833 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
834
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
835 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
836 init_plugin(PurplePlugin *plugin)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
837 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
838 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
839
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15373
diff changeset
840 PURPLE_INIT_PLUGIN(ssl_nss, init_plugin, info)