annotate src/sslconn.c @ 6703:36897b9e009f

[gaim-migrate @ 7229] Forgot the SSL wrapper code. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Tue, 02 Sep 2003 04:43:28 +0000
parents
children b0913ab92893
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6703
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1 /**
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
2 * @file sslconn.c SSL API
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
3 * @ingroup core
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
4 *
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
5 * gaim
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
6 *
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
7 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org>
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
8 *
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
12 * (at your option) any later version.
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
13 *
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
17 * GNU General Public License for more details.
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
18 *
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
20 * along with this program; if not, write to the Free Software
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
22 */
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
23 #include "internal.h"
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
24
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
25 #include "debug.h"
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
26 #include "sslconn.h"
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
27
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
28 #ifdef HAVE_NSS
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
29 # include <nspr.h>
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
30 # include <nss.h>
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
31 # include <pk11func.h>
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
32 # include <prio.h>
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
33 # include <secerr.h>
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
34 # include <secmod.h>
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
35 # include <ssl.h>
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
36 # include <sslerr.h>
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
37 # include <sslproto.h>
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
38
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
39 typedef struct
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
40 {
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
41 char *host;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
42 int port;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
43 void *user_data;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
44 GaimSslInputFunction input_func;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
45
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
46 int fd;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
47 int inpa;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
48
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
49 PRFileDesc *nss_fd;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
50 PRFileDesc *nss_in;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
51
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
52 } GaimSslData;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
53
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
54 static gboolean _nss_initialized = FALSE;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
55 static const PRIOMethods *_nss_methods = NULL;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
56 static PRDescIdentity _identity;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
57
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
58 static void
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
59 destroy_ssl_data(GaimSslData *data)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
60 {
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
61 if (data->inpa) gaim_input_remove(data->inpa);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
62 if (data->nss_in) PR_Close(data->nss_in);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
63 if (data->nss_fd) PR_Close(data->nss_fd);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
64 if (data->fd) close(data->fd);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
65
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
66 if (data->host != NULL)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
67 g_free(data->host);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
68
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
69 g_free(data);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
70 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
71
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
72 static void
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
73 init_nss(void)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
74 {
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
75 if (_nss_initialized)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
76 return;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
77
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
78 PR_Init(PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
79 NSS_NoDB_Init(NULL);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
80
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
81 /* TODO: Fix this so autoconf does the work trying to find this lib. */
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
82 SECMOD_AddNewModule("Builtins", LIBDIR "/libnssckbi.so", 0, 0);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
83 NSS_SetDomesticPolicy();
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
84
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
85 _identity = PR_GetUniqueIdentity("Gaim");
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
86 _nss_methods = PR_GetDefaultIOMethods();
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
87
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
88 _nss_initialized = TRUE;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
89 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
90
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
91 static SECStatus
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
92 ssl_auth_cert(void *arg, PRFileDesc *socket, PRBool checksig, PRBool is_server)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
93 {
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
94 return SECSuccess;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
95
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
96 #if 0
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
97 CERTCertificate *cert;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
98 void *pinArg;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
99 SECStatus status;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
100
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
101 cert = SSL_PeerCertificate(socket);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
102 pinArg = SSL_RevealPinArg(socket);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
103
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
104 status = CERT_VerifyCertNow((CERTCertDBHandle *)arg, cert, checksig,
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
105 certUsageSSLClient, pinArg);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
106
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
107 if (status != SECSuccess) {
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
108 gaim_debug(GAIM_DEBUG_ERROR, "msn", "CERT_VerifyCertNow failed\n");
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
109 CERT_DestroyCertificate(cert);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
110 return status;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
111 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
112
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
113 CERT_DestroyCertificate(cert);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
114 return SECSuccess;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
115 #endif
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
116 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
117
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
118 SECStatus
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
119 ssl_bad_cert(void *arg, PRFileDesc *socket)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
120 {
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
121 SECStatus status = SECFailure;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
122 PRErrorCode err;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
123
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
124 if (arg == NULL)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
125 return status;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
126
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
127 *(PRErrorCode *)arg = err = PORT_GetError();
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
128
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
129 switch (err)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
130 {
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
131 case SEC_ERROR_INVALID_AVA:
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
132 case SEC_ERROR_INVALID_TIME:
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
133 case SEC_ERROR_BAD_SIGNATURE:
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
134 case SEC_ERROR_EXPIRED_CERTIFICATE:
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
135 case SEC_ERROR_UNKNOWN_ISSUER:
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
136 case SEC_ERROR_UNTRUSTED_CERT:
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
137 case SEC_ERROR_CERT_VALID:
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
138 case SEC_ERROR_EXPIRED_ISSUER_CERTIFICATE:
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
139 case SEC_ERROR_CRL_EXPIRED:
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
140 case SEC_ERROR_CRL_BAD_SIGNATURE:
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
141 case SEC_ERROR_EXTENSION_VALUE_INVALID:
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
142 case SEC_ERROR_CA_CERT_INVALID:
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
143 case SEC_ERROR_CERT_USAGES_INVALID:
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
144 case SEC_ERROR_UNKNOWN_CRITICAL_EXTENSION:
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
145 status = SECSuccess;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
146 break;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
147
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
148 default:
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
149 status = SECFailure;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
150 break;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
151 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
152
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
153 gaim_debug(GAIM_DEBUG_ERROR, "msn",
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
154 "Bad certificate: %d\n");
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
155
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
156 return status;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
157 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
158
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
159 static void
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
160 input_func(gpointer data, gint source, GaimInputCondition cond)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
161 {
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
162 GaimSslData *ssl_data = (GaimSslData *)data;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
163 char *cp, *ip, *sp;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
164 int op, kp0, kp1;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
165 int result;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
166
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
167 result = SSL_SecurityStatus(ssl_data->nss_in, &op, &cp, &kp0,
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
168 &kp1, &ip, &sp);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
169
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
170 gaim_debug(GAIM_DEBUG_MISC, "msn",
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
171 "bulk cipher %s, %d secret key bits, %d key bits, status: %d\n"
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
172 "subject DN: %s\n"
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
173 "issuer DN: %s\n",
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
174 cp, kp1, kp0, op, sp, ip);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
175
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
176 PR_Free(cp);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
177 PR_Free(ip);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
178 PR_Free(sp);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
179
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
180 ssl_data->input_func(ssl_data->user_data, (GaimSslConnection *)ssl_data,
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
181 cond);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
182 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
183
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
184 static void
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
185 ssl_connect_cb(gpointer data, gint source, GaimInputCondition cond)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
186 {
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
187 PRSocketOptionData socket_opt;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
188 GaimSslData *ssl_data = (GaimSslData *)data;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
189
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
190 if (!_nss_initialized)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
191 init_nss();
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
192
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
193 ssl_data->fd = source;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
194
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
195 ssl_data->nss_fd = PR_ImportTCPSocket(ssl_data->fd);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
196
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
197 if (ssl_data->nss_fd == NULL)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
198 {
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
199 gaim_debug(GAIM_DEBUG_ERROR, "ssl", "nss_fd == NULL!\n");
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
200
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
201 destroy_ssl_data(ssl_data);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
202
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
203 return;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
204 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
205
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
206 socket_opt.option = PR_SockOpt_Nonblocking;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
207 socket_opt.value.non_blocking = PR_FALSE;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
208
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
209 PR_SetSocketOption(ssl_data->nss_fd, &socket_opt);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
210
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
211 ssl_data->nss_in = SSL_ImportFD(NULL, ssl_data->nss_fd);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
212
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
213 if (ssl_data->nss_in == NULL)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
214 {
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
215 gaim_debug(GAIM_DEBUG_ERROR, "ssl", "nss_in == NUL!\n");
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
216
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
217 destroy_ssl_data(ssl_data);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
218
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
219 return;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
220 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
221
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
222 SSL_OptionSet(ssl_data->nss_in, SSL_SECURITY, PR_TRUE);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
223 SSL_OptionSet(ssl_data->nss_in, SSL_HANDSHAKE_AS_CLIENT, PR_TRUE);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
224
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
225 SSL_AuthCertificateHook(ssl_data->nss_in,
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
226 (SSLAuthCertificate)ssl_auth_cert,
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
227 (void *)CERT_GetDefaultCertDB());
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
228 SSL_BadCertHook(ssl_data->nss_in, (SSLBadCertHandler)ssl_bad_cert, NULL);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
229
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
230 SSL_SetURL(ssl_data->nss_in, ssl_data->host);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
231
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
232 SSL_ResetHandshake(ssl_data->nss_in, PR_FALSE);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
233
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
234 if (SSL_ForceHandshake(ssl_data->nss_in))
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
235 {
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
236 gaim_debug(GAIM_DEBUG_ERROR, "ssl", "Handshake failed\n");
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
237
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
238 destroy_ssl_data(ssl_data);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
239
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
240 return;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
241 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
242
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
243 #if 0
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
244 ssl_data->input_func(ssl_data->user_data, (GaimSslConnection *)ssl_data,
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
245 cond);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
246 #endif
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
247
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
248 input_func(ssl_data, source, cond);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
249 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
250 #endif /* HAVE_NSS */
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
251
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
252 gboolean
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
253 gaim_ssl_is_supported(void)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
254 {
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
255 #ifdef HAVE_NSS
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
256 return TRUE;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
257 #else
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
258 return FALSE;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
259 #endif
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
260 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
261
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
262 GaimSslConnection *
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
263 gaim_ssl_connect(GaimAccount *account, const char *host, int port,
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
264 GaimSslInputFunction func, void *data)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
265 {
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
266 #ifdef HAVE_NSS
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
267 int i;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
268 GaimSslData *ssl_data;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
269
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
270 g_return_val_if_fail(host != NULL, NULL);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
271 g_return_val_if_fail(port != 0 && port != -1, NULL);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
272 g_return_val_if_fail(func != NULL, NULL);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
273 g_return_val_if_fail(gaim_ssl_is_supported(), NULL);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
274
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
275 ssl_data = g_new0(GaimSslData, 1);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
276
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
277 ssl_data->host = g_strdup(host);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
278 ssl_data->port = port;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
279 ssl_data->user_data = data;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
280 ssl_data->input_func = func;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
281
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
282 i = gaim_proxy_connect(account, host, port, ssl_connect_cb, ssl_data);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
283
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
284 if (i < 0)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
285 {
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
286 g_free(ssl_data->host);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
287 g_free(ssl_data);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
288
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
289 return NULL;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
290 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
291
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
292 return (GaimSslConnection)ssl_data;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
293 #else
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
294 g_return_val_if_fail(gaim_ssl_is_supported(), -1);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
295 #endif
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
296 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
297
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
298 void
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
299 gaim_ssl_close(GaimSslConnection *gsc)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
300 {
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
301 g_return_if_fail(gsc != NULL);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
302
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
303 #ifdef HAVE_NSS
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
304 destroy_ssl_data((GaimSslData *)gsc);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
305 #endif
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
306 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
307
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
308 size_t
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
309 gaim_ssl_read(GaimSslConnection *gsc, void *data, size_t len)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
310 {
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
311 #ifdef HAVE_NSS
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
312 GaimSslData *ssl_data = (GaimSslData *)gsc;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
313
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
314 g_return_val_if_fail(gsc != NULL, 0);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
315 g_return_val_if_fail(data != NULL, 0);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
316 g_return_val_if_fail(len > 0, 0);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
317
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
318 return PR_Read(ssl_data->nss_in, data, len);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
319 #else
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
320 return 0;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
321 #endif
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
322 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
323
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
324 size_t
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
325 gaim_ssl_write(GaimSslConnection *gsc, const void *data, size_t len)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
326 {
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
327 #ifdef HAVE_NSS
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
328 GaimSslData *ssl_data = (GaimSslData *)gsc;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
329
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
330 g_return_val_if_fail(gsc != NULL, 0);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
331 g_return_val_if_fail(data != NULL, 0);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
332 g_return_val_if_fail(len > 0, 0);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
333
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
334 return PR_Write(ssl_data->nss_in, data, len);
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
335 #else
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
336 return 0;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
337 #endif
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
338 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
339
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
340 void
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
341 gaim_ssl_init(void)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
342 {
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
343 }
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
344
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
345 void
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
346 gaim_ssl_uninit(void)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
347 {
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
348 if (!_nss_initialized)
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
349 return;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
350
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
351 #ifdef HAVE_NSS
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
352 PR_Cleanup();
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
353 #endif
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
354
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
355 _nss_initialized = FALSE;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
356 _nss_methods = NULL;
36897b9e009f [gaim-migrate @ 7229]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
357 }