Thu, 16 Feb 2006 23:02:56 +0000
[gaim-migrate @ 15669]
There was an attempt to make each Jabber resource have its own conversation
window, which wasn't working, and instead sending outgoing messages to the
wrong resource. Different conversations with each resource breaks the whole
"Send to" one-window-per-person metaphor, so I just changed the behavior to
send messages to whichever resources last messaged you. Perhaps later, when
we're not in a freeze, we can consider an API that allows prpls to populate
the Send To menu themselves, letting you easily switch what resource you're
chatting with in the same window
| 7016 | 1 | /** |
| 2 | * @file ssl-nss.c Mozilla NSS SSL plugin. | |
| 3 | * | |
| 4 | * gaim | |
| 5 | * | |
| 6 | * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
| 7 | * | |
| 8 | * This program is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with this program; if not, write to the Free Software | |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 | */ | |
| 22 | #include "internal.h" | |
|
7051
8ddb8f560399
[gaim-migrate @ 7614]
Christian Hammond <chipx86@chipx86.com>
parents:
7050
diff
changeset
|
23 | #include "debug.h" |
| 7016 | 24 | #include "plugin.h" |
|
7051
8ddb8f560399
[gaim-migrate @ 7614]
Christian Hammond <chipx86@chipx86.com>
parents:
7050
diff
changeset
|
25 | #include "sslconn.h" |
| 9943 | 26 | #include "version.h" |
| 7016 | 27 | |
|
7029
fe690e0607ec
[gaim-migrate @ 7592]
Christian Hammond <chipx86@chipx86.com>
parents:
7028
diff
changeset
|
28 | #define SSL_NSS_PLUGIN_ID "ssl-nss" |
| 7016 | 29 | |
| 30 | #ifdef HAVE_NSS | |
| 31 | ||
|
9582
68facdf2b52d
[gaim-migrate @ 10425]
Christian Hammond <chipx86@chipx86.com>
parents:
8749
diff
changeset
|
32 | #undef HAVE_LONG_LONG /* Make Mozilla less angry. If angry, Mozilla SMASH! */ |
|
68facdf2b52d
[gaim-migrate @ 10425]
Christian Hammond <chipx86@chipx86.com>
parents:
8749
diff
changeset
|
33 | |
| 7016 | 34 | #include <nspr.h> |
| 35 | #include <private/pprio.h> | |
| 36 | #include <nss.h> | |
| 37 | #include <pk11func.h> | |
| 38 | #include <prio.h> | |
| 39 | #include <secerr.h> | |
| 40 | #include <secmod.h> | |
| 41 | #include <ssl.h> | |
| 42 | #include <sslerr.h> | |
| 43 | #include <sslproto.h> | |
| 44 | ||
| 45 | typedef struct | |
| 46 | { | |
| 47 | PRFileDesc *fd; | |
| 48 | PRFileDesc *in; | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
49 | guint handshake_handler; |
| 7016 | 50 | |
| 51 | } GaimSslNssData; | |
| 52 | ||
| 53 | #define GAIM_SSL_NSS_DATA(gsc) ((GaimSslNssData *)gsc->private_data) | |
| 54 | ||
| 55 | static const PRIOMethods *_nss_methods = NULL; | |
| 56 | static PRDescIdentity _identity; | |
| 57 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
58 | /* Thank you, Evolution */ |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
59 | static void |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
60 | set_errno(int code) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
61 | { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
62 | /* FIXME: this should handle more. */ |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
63 | switch (code) { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
64 | case PR_INVALID_ARGUMENT_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
65 | errno = EINVAL; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
66 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
67 | case PR_PENDING_INTERRUPT_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
68 | errno = EINTR; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
69 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
70 | case PR_IO_PENDING_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
71 | errno = EAGAIN; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
72 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
73 | case PR_WOULD_BLOCK_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
74 | errno = EAGAIN; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
75 | /*errno = EWOULDBLOCK; */ |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
76 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
77 | case PR_IN_PROGRESS_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
78 | errno = EINPROGRESS; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
79 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
80 | case PR_ALREADY_INITIATED_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
81 | errno = EALREADY; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
82 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
83 | case PR_NETWORK_UNREACHABLE_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
84 | errno = EHOSTUNREACH; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
85 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
86 | case PR_CONNECT_REFUSED_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
87 | errno = ECONNREFUSED; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
88 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
89 | case PR_CONNECT_TIMEOUT_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
90 | case PR_IO_TIMEOUT_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
91 | errno = ETIMEDOUT; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
92 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
93 | case PR_NOT_CONNECTED_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
94 | errno = ENOTCONN; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
95 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
96 | case PR_CONNECT_RESET_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
97 | errno = ECONNRESET; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
98 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
99 | case PR_IO_ERROR: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
100 | default: |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
101 | errno = EIO; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
102 | break; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
103 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
104 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
105 | |
|
7993
3bfea94dd0eb
[gaim-migrate @ 8670]
Christian Hammond <chipx86@chipx86.com>
parents:
7862
diff
changeset
|
106 | static void |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
107 | ssl_nss_init_nss(void) |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
108 | { |
|
10519
80801a34a246
[gaim-migrate @ 11833]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10263
diff
changeset
|
109 | char *lib; |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
110 | PR_Init(PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1); |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
111 | NSS_NoDB_Init(NULL); |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
112 | |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
113 | /* TODO: Fix this so autoconf does the work trying to find this lib. */ |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
114 | #ifndef _WIN32 |
|
10519
80801a34a246
[gaim-migrate @ 11833]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10263
diff
changeset
|
115 | lib = g_strdup(BR_LIBDIR("/libnssckbi.so")); |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
116 | #else |
|
10519
80801a34a246
[gaim-migrate @ 11833]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10263
diff
changeset
|
117 | lib = g_strdup("nssckbi.dll"); |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
118 | #endif |
|
10519
80801a34a246
[gaim-migrate @ 11833]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10263
diff
changeset
|
119 | SECMOD_AddNewModule("Builtins", lib, 0, 0); |
|
80801a34a246
[gaim-migrate @ 11833]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10263
diff
changeset
|
120 | g_free(lib); |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
121 | NSS_SetDomesticPolicy(); |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
122 | |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
123 | _identity = PR_GetUniqueIdentity("Gaim"); |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
124 | _nss_methods = PR_GetDefaultIOMethods(); |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
125 | } |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
126 | |
| 7016 | 127 | static SECStatus |
| 128 | ssl_auth_cert(void *arg, PRFileDesc *socket, PRBool checksig, | |
| 129 | PRBool is_server) | |
| 130 | { | |
| 131 | return SECSuccess; | |
| 132 | ||
| 133 | #if 0 | |
| 134 | CERTCertificate *cert; | |
| 135 | void *pinArg; | |
| 136 | SECStatus status; | |
| 137 | ||
| 138 | cert = SSL_PeerCertificate(socket); | |
| 139 | pinArg = SSL_RevealPinArg(socket); | |
| 140 | ||
| 141 | status = CERT_VerifyCertNow((CERTCertDBHandle *)arg, cert, checksig, | |
| 142 | certUsageSSLClient, pinArg); | |
| 143 | ||
| 144 | if (status != SECSuccess) { | |
| 145 | gaim_debug_error("nss", "CERT_VerifyCertNow failed\n"); | |
| 146 | CERT_DestroyCertificate(cert); | |
| 147 | return status; | |
| 148 | } | |
| 149 | ||
| 150 | CERT_DestroyCertificate(cert); | |
| 151 | return SECSuccess; | |
| 152 | #endif | |
| 153 | } | |
| 154 | ||
| 155 | static SECStatus | |
| 156 | ssl_bad_cert(void *arg, PRFileDesc *socket) | |
| 157 | { | |
| 158 | SECStatus status = SECFailure; | |
| 159 | PRErrorCode err; | |
| 160 | ||
| 161 | if (arg == NULL) | |
| 162 | return status; | |
| 163 | ||
| 164 | *(PRErrorCode *)arg = err = PORT_GetError(); | |
| 165 | ||
| 166 | switch (err) | |
| 167 | { | |
| 168 | case SEC_ERROR_INVALID_AVA: | |
| 169 | case SEC_ERROR_INVALID_TIME: | |
| 170 | case SEC_ERROR_BAD_SIGNATURE: | |
| 171 | case SEC_ERROR_EXPIRED_CERTIFICATE: | |
| 172 | case SEC_ERROR_UNKNOWN_ISSUER: | |
| 173 | case SEC_ERROR_UNTRUSTED_CERT: | |
| 174 | case SEC_ERROR_CERT_VALID: | |
| 175 | case SEC_ERROR_EXPIRED_ISSUER_CERTIFICATE: | |
| 176 | case SEC_ERROR_CRL_EXPIRED: | |
| 177 | case SEC_ERROR_CRL_BAD_SIGNATURE: | |
| 178 | case SEC_ERROR_EXTENSION_VALUE_INVALID: | |
| 179 | case SEC_ERROR_CA_CERT_INVALID: | |
| 180 | case SEC_ERROR_CERT_USAGES_INVALID: | |
| 181 | case SEC_ERROR_UNKNOWN_CRITICAL_EXTENSION: | |
| 182 | status = SECSuccess; | |
| 183 | break; | |
| 184 | ||
| 185 | default: | |
| 186 | status = SECFailure; | |
| 187 | break; | |
| 188 | } | |
| 189 | ||
|
12209
0a393bdb7cb7
[gaim-migrate @ 14511]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11513
diff
changeset
|
190 | gaim_debug_error("nss", "Bad certificate: %d\n", err); |
| 7016 | 191 | |
| 192 | return status; | |
| 193 | } | |
| 194 | ||
| 195 | static gboolean | |
| 196 | ssl_nss_init(void) | |
| 197 | { | |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
198 | return TRUE; |
| 7016 | 199 | } |
| 200 | ||
| 201 | static void | |
| 202 | ssl_nss_uninit(void) | |
| 203 | { | |
| 204 | PR_Cleanup(); | |
| 205 | ||
| 206 | _nss_methods = NULL; | |
| 207 | } | |
| 208 | ||
| 209 | static void | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
210 | ssl_nss_handshake_cb(gpointer data, int fd, GaimInputCondition cond) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
211 | { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
212 | GaimSslConnection *gsc = (GaimSslConnection *)data; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
213 | GaimSslNssData *nss_data = gsc->private_data; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
214 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
215 | /* I don't think this the best way to do this... |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
216 | * It seems to work because it'll eventually use the cached value |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
217 | */ |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
218 | if(SSL_ForceHandshake(nss_data->in) != SECSuccess) { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
219 | set_errno(PR_GetError()); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
220 | if (errno == EAGAIN || errno == EWOULDBLOCK) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
221 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
222 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
223 | gaim_debug_error("nss", "Handshake failed %u\n", PR_GetError()); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
224 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
225 | if (gsc->error_cb != NULL) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
226 | gsc->error_cb(gsc, GAIM_SSL_HANDSHAKE_FAILED, gsc->connect_cb_data); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
227 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
228 | gaim_ssl_close(gsc); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
229 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
230 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
231 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
232 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
233 | gaim_input_remove(nss_data->handshake_handler); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
234 | nss_data->handshake_handler = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
235 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
236 | gsc->connect_cb(gsc->connect_cb_data, gsc, cond); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
237 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
238 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
239 | static void |
| 7016 | 240 | ssl_nss_connect_cb(gpointer data, gint source, GaimInputCondition cond) |
| 241 | { | |
| 242 | GaimSslConnection *gsc = (GaimSslConnection *)data; | |
| 243 | GaimSslNssData *nss_data = g_new0(GaimSslNssData, 1); | |
| 244 | PRSocketOptionData socket_opt; | |
| 245 | ||
| 246 | gsc->private_data = nss_data; | |
| 247 | ||
| 248 | gsc->fd = source; | |
| 249 | ||
| 250 | nss_data->fd = PR_ImportTCPSocket(gsc->fd); | |
| 251 | ||
| 252 | if (nss_data->fd == NULL) | |
| 253 | { | |
| 254 | gaim_debug_error("nss", "nss_data->fd == NULL!\n"); | |
| 255 | ||
| 8362 | 256 | if (gsc->error_cb != NULL) |
| 257 | gsc->error_cb(gsc, GAIM_SSL_CONNECT_FAILED, gsc->connect_cb_data); | |
| 258 | ||
| 7016 | 259 | gaim_ssl_close((GaimSslConnection *)gsc); |
| 260 | ||
| 261 | return; | |
| 262 | } | |
| 263 | ||
| 264 | socket_opt.option = PR_SockOpt_Nonblocking; | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
265 | socket_opt.value.non_blocking = PR_TRUE; |
| 7016 | 266 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
267 | if (PR_SetSocketOption(nss_data->fd, &socket_opt) != PR_SUCCESS) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
268 | gaim_debug_warning("nss", "unable to set socket into non-blocking mode: %u\n", PR_GetError()); |
| 7016 | 269 | |
| 270 | nss_data->in = SSL_ImportFD(NULL, nss_data->fd); | |
| 271 | ||
| 272 | if (nss_data->in == NULL) | |
| 273 | { | |
| 274 | gaim_debug_error("nss", "nss_data->in == NUL!\n"); | |
| 275 | ||
| 8362 | 276 | if (gsc->error_cb != NULL) |
| 277 | gsc->error_cb(gsc, GAIM_SSL_CONNECT_FAILED, gsc->connect_cb_data); | |
| 278 | ||
| 7016 | 279 | gaim_ssl_close((GaimSslConnection *)gsc); |
| 280 | ||
| 281 | return; | |
| 282 | } | |
| 283 | ||
| 284 | SSL_OptionSet(nss_data->in, SSL_SECURITY, PR_TRUE); | |
| 285 | SSL_OptionSet(nss_data->in, SSL_HANDSHAKE_AS_CLIENT, PR_TRUE); | |
| 286 | ||
| 287 | SSL_AuthCertificateHook(nss_data->in, | |
| 288 | (SSLAuthCertificate)ssl_auth_cert, | |
| 289 | (void *)CERT_GetDefaultCertDB()); | |
| 290 | SSL_BadCertHook(nss_data->in, (SSLBadCertHandler)ssl_bad_cert, NULL); | |
| 291 | ||
| 7157 | 292 | if(gsc->host) |
| 293 | SSL_SetURL(nss_data->in, gsc->host); | |
| 7016 | 294 | |
|
13264
f5db933aa42a
[gaim-migrate @ 15629]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13201
diff
changeset
|
295 | #if 0 |
|
f5db933aa42a
[gaim-migrate @ 15629]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13201
diff
changeset
|
296 | /* This seems like it'd the be the correct way to implement the |
|
f5db933aa42a
[gaim-migrate @ 15629]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13201
diff
changeset
|
297 | nonblocking stuff, but it doesn't seem to work */ |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
298 | SSL_HandshakeCallback(nss_data->in, |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
299 | (SSLHandshakeCallback) ssl_nss_handshake_cb, gsc); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
300 | #endif |
| 7016 | 301 | SSL_ResetHandshake(nss_data->in, PR_FALSE); |
| 302 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
303 | nss_data->handshake_handler = gaim_input_add(gsc->fd, |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
304 | GAIM_INPUT_READ, ssl_nss_handshake_cb, gsc); |
|
7274
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
7157
diff
changeset
|
305 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
306 | ssl_nss_handshake_cb(gsc, gsc->fd, GAIM_INPUT_READ); |
| 7016 | 307 | } |
| 308 | ||
| 309 | static void | |
| 310 | ssl_nss_close(GaimSslConnection *gsc) | |
| 311 | { | |
| 312 | GaimSslNssData *nss_data = GAIM_SSL_NSS_DATA(gsc); | |
| 313 | ||
| 7467 | 314 | if(!nss_data) |
| 315 | return; | |
| 316 | ||
| 7016 | 317 | if (nss_data->in) PR_Close(nss_data->in); |
| 318 | /* if (nss_data->fd) PR_Close(nss_data->fd); */ | |
| 319 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
320 | if (nss_data->handshake_handler) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
321 | gaim_input_remove(nss_data->handshake_handler); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
322 | |
| 7016 | 323 | g_free(nss_data); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
324 | gsc->private_data = NULL; |
| 7016 | 325 | } |
| 326 | ||
| 327 | static size_t | |
| 328 | ssl_nss_read(GaimSslConnection *gsc, void *data, size_t len) | |
| 329 | { | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
330 | ssize_t ret; |
| 7016 | 331 | GaimSslNssData *nss_data = GAIM_SSL_NSS_DATA(gsc); |
| 332 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
333 | ret = PR_Read(nss_data->in, data, len); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
334 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
335 | if (ret == -1) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
336 | set_errno(PR_GetError()); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
337 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
338 | return ret; |
| 7016 | 339 | } |
| 340 | ||
| 341 | static size_t | |
| 342 | ssl_nss_write(GaimSslConnection *gsc, const void *data, size_t len) | |
| 343 | { | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
344 | ssize_t ret; |
| 7016 | 345 | GaimSslNssData *nss_data = GAIM_SSL_NSS_DATA(gsc); |
| 346 | ||
| 7467 | 347 | if(!nss_data) |
| 348 | return 0; | |
| 349 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
350 | ret = PR_Write(nss_data->in, data, len); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
351 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
352 | if (ret == -1) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
353 | set_errno(PR_GetError()); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
354 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
355 | return ret; |
| 7016 | 356 | } |
| 357 | ||
| 358 | static GaimSslOps ssl_ops = | |
| 359 | { | |
| 360 | ssl_nss_init, | |
| 361 | ssl_nss_uninit, | |
| 362 | ssl_nss_connect_cb, | |
| 363 | ssl_nss_close, | |
| 364 | ssl_nss_read, | |
| 365 | ssl_nss_write | |
| 366 | }; | |
| 367 | ||
| 368 | #endif /* HAVE_NSS */ | |
| 369 | ||
| 370 | ||
| 371 | static gboolean | |
| 372 | plugin_load(GaimPlugin *plugin) | |
| 373 | { | |
| 374 | #ifdef HAVE_NSS | |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
375 | if (!gaim_ssl_get_ops()) { |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
376 | gaim_ssl_set_ops(&ssl_ops); |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
377 | } |
| 7016 | 378 | |
| 11033 | 379 | /* Init NSS now, so others can use it even if sslconn never does */ |
| 380 | ssl_nss_init_nss(); | |
| 381 | ||
| 7016 | 382 | return TRUE; |
| 383 | #else | |
| 384 | return FALSE; | |
| 385 | #endif | |
| 386 | } | |
| 387 | ||
| 388 | static gboolean | |
| 389 | plugin_unload(GaimPlugin *plugin) | |
| 390 | { | |
| 7053 | 391 | #ifdef HAVE_NSS |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
392 | if (gaim_ssl_get_ops() == &ssl_ops) { |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
393 | gaim_ssl_set_ops(NULL); |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
394 | } |
|
7050
12730863b0f9
[gaim-migrate @ 7613]
Christian Hammond <chipx86@chipx86.com>
parents:
7029
diff
changeset
|
395 | #endif |
|
12730863b0f9
[gaim-migrate @ 7613]
Christian Hammond <chipx86@chipx86.com>
parents:
7029
diff
changeset
|
396 | |
| 7016 | 397 | return TRUE; |
| 398 | } | |
| 399 | ||
| 400 | static GaimPluginInfo info = | |
| 401 | { | |
| 9943 | 402 | GAIM_PLUGIN_MAGIC, |
| 403 | GAIM_MAJOR_VERSION, | |
| 404 | GAIM_MINOR_VERSION, | |
| 7016 | 405 | GAIM_PLUGIN_STANDARD, /**< type */ |
| 406 | NULL, /**< ui_requirement */ | |
| 407 | GAIM_PLUGIN_FLAG_INVISIBLE, /**< flags */ | |
| 408 | NULL, /**< dependencies */ | |
| 409 | GAIM_PRIORITY_DEFAULT, /**< priority */ | |
| 410 | ||
|
7029
fe690e0607ec
[gaim-migrate @ 7592]
Christian Hammond <chipx86@chipx86.com>
parents:
7028
diff
changeset
|
411 | SSL_NSS_PLUGIN_ID, /**< id */ |
| 7016 | 412 | N_("NSS"), /**< name */ |
| 413 | VERSION, /**< version */ | |
| 414 | /** summary */ | |
| 415 | N_("Provides SSL support through Mozilla NSS."), | |
| 416 | /** description */ | |
| 417 | N_("Provides SSL support through Mozilla NSS."), | |
| 418 | "Christian Hammond <chipx86@gnupdate.org>", | |
| 419 | GAIM_WEBSITE, /**< homepage */ | |
| 420 | ||
| 421 | plugin_load, /**< load */ | |
| 422 | plugin_unload, /**< unload */ | |
| 423 | NULL, /**< destroy */ | |
| 424 | ||
| 425 | NULL, /**< ui_info */ | |
|
11513
89bf8d856291
[gaim-migrate @ 13758]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11256
diff
changeset
|
426 | NULL, /**< extra_info */ |
|
89bf8d856291
[gaim-migrate @ 13758]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11256
diff
changeset
|
427 | NULL, /**< prefs_info */ |
|
89bf8d856291
[gaim-migrate @ 13758]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11256
diff
changeset
|
428 | NULL /**< actions */ |
| 7016 | 429 | }; |
| 430 | ||
| 431 | static void | |
| 432 | init_plugin(GaimPlugin *plugin) | |
| 433 | { | |
| 434 | } | |
| 435 | ||
| 436 | GAIM_INIT_PLUGIN(ssl_nss, init_plugin, info) |