Wed, 12 Nov 2008 05:14:03 +0000
merge of '77693555855fe9cd3215414f79964dba346cc5fa'
and '19a87e98e5857ad0289f2c760d460f7f1dbbb42d'
| 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 | |
|
13530
2fbf309637b2
[gaim-migrate @ 15906]
Daniel Atallah <datallah@pidgin.im>
parents:
13264
diff
changeset
|
223 | gaim_debug_error("nss", "Handshake failed %d\n", PR_GetError()); |
|
13201
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 |
|
14222
71d8761db708
[gaim-migrate @ 16808]
Mark Doliner <markdoliner@pidgin.im>
parents:
13530
diff
changeset
|
240 | ssl_nss_connect(GaimSslConnection *gsc) |
| 7016 | 241 | { |
| 242 | GaimSslNssData *nss_data = g_new0(GaimSslNssData, 1); | |
| 243 | PRSocketOptionData socket_opt; | |
| 244 | ||
| 245 | gsc->private_data = nss_data; | |
| 246 | ||
| 247 | nss_data->fd = PR_ImportTCPSocket(gsc->fd); | |
| 248 | ||
| 249 | if (nss_data->fd == NULL) | |
| 250 | { | |
| 251 | gaim_debug_error("nss", "nss_data->fd == NULL!\n"); | |
| 252 | ||
| 8362 | 253 | if (gsc->error_cb != NULL) |
| 254 | gsc->error_cb(gsc, GAIM_SSL_CONNECT_FAILED, gsc->connect_cb_data); | |
| 255 | ||
| 7016 | 256 | gaim_ssl_close((GaimSslConnection *)gsc); |
| 257 | ||
| 258 | return; | |
| 259 | } | |
| 260 | ||
| 261 | socket_opt.option = PR_SockOpt_Nonblocking; | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
262 | socket_opt.value.non_blocking = PR_TRUE; |
| 7016 | 263 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
264 | if (PR_SetSocketOption(nss_data->fd, &socket_opt) != PR_SUCCESS) |
|
13530
2fbf309637b2
[gaim-migrate @ 15906]
Daniel Atallah <datallah@pidgin.im>
parents:
13264
diff
changeset
|
265 | gaim_debug_warning("nss", "unable to set socket into non-blocking mode: %d\n", PR_GetError()); |
| 7016 | 266 | |
| 267 | nss_data->in = SSL_ImportFD(NULL, nss_data->fd); | |
| 268 | ||
| 269 | if (nss_data->in == NULL) | |
| 270 | { | |
| 271 | gaim_debug_error("nss", "nss_data->in == NUL!\n"); | |
| 272 | ||
| 8362 | 273 | if (gsc->error_cb != NULL) |
| 274 | gsc->error_cb(gsc, GAIM_SSL_CONNECT_FAILED, gsc->connect_cb_data); | |
| 275 | ||
| 7016 | 276 | gaim_ssl_close((GaimSslConnection *)gsc); |
| 277 | ||
| 278 | return; | |
| 279 | } | |
| 280 | ||
| 281 | SSL_OptionSet(nss_data->in, SSL_SECURITY, PR_TRUE); | |
| 282 | SSL_OptionSet(nss_data->in, SSL_HANDSHAKE_AS_CLIENT, PR_TRUE); | |
| 283 | ||
| 284 | SSL_AuthCertificateHook(nss_data->in, | |
| 285 | (SSLAuthCertificate)ssl_auth_cert, | |
| 286 | (void *)CERT_GetDefaultCertDB()); | |
| 287 | SSL_BadCertHook(nss_data->in, (SSLBadCertHandler)ssl_bad_cert, NULL); | |
| 288 | ||
| 7157 | 289 | if(gsc->host) |
| 290 | SSL_SetURL(nss_data->in, gsc->host); | |
| 7016 | 291 | |
|
13264
f5db933aa42a
[gaim-migrate @ 15629]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13201
diff
changeset
|
292 | #if 0 |
|
f5db933aa42a
[gaim-migrate @ 15629]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13201
diff
changeset
|
293 | /* 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
|
294 | nonblocking stuff, but it doesn't seem to work */ |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
295 | SSL_HandshakeCallback(nss_data->in, |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
296 | (SSLHandshakeCallback) ssl_nss_handshake_cb, gsc); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
297 | #endif |
| 7016 | 298 | SSL_ResetHandshake(nss_data->in, PR_FALSE); |
| 299 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
300 | nss_data->handshake_handler = gaim_input_add(gsc->fd, |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
301 | GAIM_INPUT_READ, ssl_nss_handshake_cb, gsc); |
|
7274
42ec5f56e32a
[gaim-migrate @ 7851]
Christian Hammond <chipx86@chipx86.com>
parents:
7157
diff
changeset
|
302 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
303 | ssl_nss_handshake_cb(gsc, gsc->fd, GAIM_INPUT_READ); |
| 7016 | 304 | } |
| 305 | ||
| 306 | static void | |
| 307 | ssl_nss_close(GaimSslConnection *gsc) | |
| 308 | { | |
| 309 | GaimSslNssData *nss_data = GAIM_SSL_NSS_DATA(gsc); | |
| 310 | ||
| 7467 | 311 | if(!nss_data) |
| 312 | return; | |
| 313 | ||
| 7016 | 314 | if (nss_data->in) PR_Close(nss_data->in); |
| 315 | /* if (nss_data->fd) PR_Close(nss_data->fd); */ | |
| 316 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
317 | if (nss_data->handshake_handler) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
318 | gaim_input_remove(nss_data->handshake_handler); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
319 | |
| 7016 | 320 | g_free(nss_data); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
321 | gsc->private_data = NULL; |
| 7016 | 322 | } |
| 323 | ||
| 324 | static size_t | |
| 325 | ssl_nss_read(GaimSslConnection *gsc, void *data, size_t len) | |
| 326 | { | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
327 | ssize_t ret; |
| 7016 | 328 | GaimSslNssData *nss_data = GAIM_SSL_NSS_DATA(gsc); |
| 329 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
330 | ret = PR_Read(nss_data->in, data, len); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
331 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
332 | if (ret == -1) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
333 | set_errno(PR_GetError()); |
|
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 | return ret; |
| 7016 | 336 | } |
| 337 | ||
| 338 | static size_t | |
| 339 | ssl_nss_write(GaimSslConnection *gsc, const void *data, size_t len) | |
| 340 | { | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
341 | ssize_t ret; |
| 7016 | 342 | GaimSslNssData *nss_data = GAIM_SSL_NSS_DATA(gsc); |
| 343 | ||
| 7467 | 344 | if(!nss_data) |
| 345 | return 0; | |
| 346 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
347 | ret = PR_Write(nss_data->in, data, len); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
348 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
349 | if (ret == -1) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12209
diff
changeset
|
350 | set_errno(PR_GetError()); |
|
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 | return ret; |
| 7016 | 353 | } |
| 354 | ||
| 355 | static GaimSslOps ssl_ops = | |
| 356 | { | |
| 357 | ssl_nss_init, | |
| 358 | ssl_nss_uninit, | |
|
14222
71d8761db708
[gaim-migrate @ 16808]
Mark Doliner <markdoliner@pidgin.im>
parents:
13530
diff
changeset
|
359 | ssl_nss_connect, |
| 7016 | 360 | ssl_nss_close, |
| 361 | ssl_nss_read, | |
| 362 | ssl_nss_write | |
| 363 | }; | |
| 364 | ||
| 365 | #endif /* HAVE_NSS */ | |
| 366 | ||
| 367 | ||
| 368 | static gboolean | |
| 369 | plugin_load(GaimPlugin *plugin) | |
| 370 | { | |
| 371 | #ifdef HAVE_NSS | |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
372 | if (!gaim_ssl_get_ops()) { |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
373 | gaim_ssl_set_ops(&ssl_ops); |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
374 | } |
| 7016 | 375 | |
| 11033 | 376 | /* Init NSS now, so others can use it even if sslconn never does */ |
| 377 | ssl_nss_init_nss(); | |
| 378 | ||
| 7016 | 379 | return TRUE; |
| 380 | #else | |
| 381 | return FALSE; | |
| 382 | #endif | |
| 383 | } | |
| 384 | ||
| 385 | static gboolean | |
| 386 | plugin_unload(GaimPlugin *plugin) | |
| 387 | { | |
| 7053 | 388 | #ifdef HAVE_NSS |
|
7862
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
389 | if (gaim_ssl_get_ops() == &ssl_ops) { |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
390 | gaim_ssl_set_ops(NULL); |
|
9b96706e44e7
[gaim-migrate @ 8516]
Bill Tompkins <obobo@users.sourceforge.net>
parents:
7467
diff
changeset
|
391 | } |
|
7050
12730863b0f9
[gaim-migrate @ 7613]
Christian Hammond <chipx86@chipx86.com>
parents:
7029
diff
changeset
|
392 | #endif |
|
12730863b0f9
[gaim-migrate @ 7613]
Christian Hammond <chipx86@chipx86.com>
parents:
7029
diff
changeset
|
393 | |
| 7016 | 394 | return TRUE; |
| 395 | } | |
| 396 | ||
| 397 | static GaimPluginInfo info = | |
| 398 | { | |
| 9943 | 399 | GAIM_PLUGIN_MAGIC, |
| 400 | GAIM_MAJOR_VERSION, | |
| 401 | GAIM_MINOR_VERSION, | |
| 7016 | 402 | GAIM_PLUGIN_STANDARD, /**< type */ |
| 403 | NULL, /**< ui_requirement */ | |
| 404 | GAIM_PLUGIN_FLAG_INVISIBLE, /**< flags */ | |
| 405 | NULL, /**< dependencies */ | |
| 406 | GAIM_PRIORITY_DEFAULT, /**< priority */ | |
| 407 | ||
|
7029
fe690e0607ec
[gaim-migrate @ 7592]
Christian Hammond <chipx86@chipx86.com>
parents:
7028
diff
changeset
|
408 | SSL_NSS_PLUGIN_ID, /**< id */ |
| 7016 | 409 | N_("NSS"), /**< name */ |
| 410 | VERSION, /**< version */ | |
| 411 | /** summary */ | |
| 412 | N_("Provides SSL support through Mozilla NSS."), | |
| 413 | /** description */ | |
| 414 | N_("Provides SSL support through Mozilla NSS."), | |
| 415 | "Christian Hammond <chipx86@gnupdate.org>", | |
| 416 | GAIM_WEBSITE, /**< homepage */ | |
| 417 | ||
| 418 | plugin_load, /**< load */ | |
| 419 | plugin_unload, /**< unload */ | |
| 420 | NULL, /**< destroy */ | |
| 421 | ||
| 422 | NULL, /**< ui_info */ | |
|
11513
89bf8d856291
[gaim-migrate @ 13758]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11256
diff
changeset
|
423 | NULL, /**< extra_info */ |
|
89bf8d856291
[gaim-migrate @ 13758]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11256
diff
changeset
|
424 | NULL, /**< prefs_info */ |
|
89bf8d856291
[gaim-migrate @ 13758]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11256
diff
changeset
|
425 | NULL /**< actions */ |
| 7016 | 426 | }; |
| 427 | ||
| 428 | static void | |
| 429 | init_plugin(GaimPlugin *plugin) | |
| 430 | { | |
| 431 | } | |
| 432 | ||
| 433 | GAIM_INIT_PLUGIN(ssl_nss, init_plugin, info) |