~ubuntu-branches/ubuntu/lucid/seamonkey/lucid-security

« back to all changes in this revision

Viewing changes to security/nss-fips/lib/ssl/sslinfo.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabien Tassin
  • Date: 2008-07-29 21:29:02 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080729212902-spm9kpvchp9udwbw
Tags: 1.1.11+nobinonly-0ubuntu1
* New security upstream release: 1.1.11 (LP: #218534)
  Fixes USN-602-1, USN-619-1, USN-623-1 and USN-629-1
* Refresh diverged patch:
  - update debian/patches/80_security_build.patch
* Fix FTBFS with missing -lfontconfig
  - add debian/patches/11_fix_ftbfs_with_fontconfig.patch
  - update debian/patches/series
* Build with default gcc (hardy: 4.2, intrepid: 4.3)
  - update debian/rules
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ***** BEGIN LICENSE BLOCK *****
 
2
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
3
 *
 
4
 * The contents of this file are subject to the Mozilla Public License Version
 
5
 * 1.1 (the "License"); you may not use this file except in compliance with
 
6
 * the License. You may obtain a copy of the License at
 
7
 * http://www.mozilla.org/MPL/
 
8
 *
 
9
 * Software distributed under the License is distributed on an "AS IS" basis,
 
10
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
11
 * for the specific language governing rights and limitations under the
 
12
 * License.
 
13
 *
 
14
 * The Original Code is the Netscape security libraries.
 
15
 *
 
16
 * The Initial Developer of the Original Code is
 
17
 * Netscape Communications Corporation.
 
18
 * Portions created by the Initial Developer are Copyright (C) 2001
 
19
 * the Initial Developer. All Rights Reserved.
 
20
 *
 
21
 * Contributor(s):
 
22
 *   Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
 
23
 *
 
24
 * Alternatively, the contents of this file may be used under the terms of
 
25
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
26
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
27
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
28
 * of those above. If you wish to allow use of your version of this file only
 
29
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
30
 * use your version of this file under the terms of the MPL, indicate your
 
31
 * decision by deleting the provisions above and replace them with the notice
 
32
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
33
 * the provisions above, a recipient may use your version of this file under
 
34
 * the terms of any one of the MPL, the GPL or the LGPL.
 
35
 *
 
36
 * ***** END LICENSE BLOCK ***** */
 
37
/* $Id: sslinfo.c,v 1.14.2.1 2006/01/28 00:13:37 wtchang%redhat.com Exp $ */
 
38
#include "ssl.h"
 
39
#include "sslimpl.h"
 
40
#include "sslproto.h"
 
41
 
 
42
SECStatus 
 
43
SSL_GetChannelInfo(PRFileDesc *fd, SSLChannelInfo *info, PRUintn len)
 
44
{
 
45
    sslSocket *      ss;
 
46
    SSLChannelInfo   inf;
 
47
    sslSessionID *   sid;
 
48
 
 
49
    if (!info || len < sizeof inf.length) { 
 
50
        return SECSuccess;
 
51
    }
 
52
 
 
53
    ss = ssl_FindSocket(fd);
 
54
    if (!ss) {
 
55
        SSL_DBG(("%d: SSL[%d]: bad socket in SSL_GetChannelInfo",
 
56
                 SSL_GETPID(), fd));
 
57
        return SECFailure;
 
58
    }
 
59
 
 
60
    memset(&inf, 0, sizeof inf);
 
61
    inf.length = PR_MIN(sizeof inf, len);
 
62
 
 
63
    if (ss->opt.useSecurity && ss->firstHsDone) {
 
64
        sid = ss->sec.ci.sid;
 
65
        inf.protocolVersion  = ss->version;
 
66
        inf.authKeyBits      = ss->sec.authKeyBits;
 
67
        inf.keaKeyBits       = ss->sec.keaKeyBits;
 
68
        if (ss->version < SSL_LIBRARY_VERSION_3_0) { /* SSL2 */
 
69
            inf.cipherSuite      = ss->sec.cipherType | 0xff00;
 
70
        } else if (ss->ssl3.initialized) {      /* SSL3 and TLS */
 
71
 
 
72
            /* XXX  These should come from crSpec */
 
73
            inf.cipherSuite      = ss->ssl3.hs.cipher_suite;
 
74
        }
 
75
        if (sid) {
 
76
            inf.creationTime   = sid->creationTime;
 
77
            inf.lastAccessTime = sid->lastAccessTime;
 
78
            inf.expirationTime = sid->expirationTime;
 
79
            if (ss->version < SSL_LIBRARY_VERSION_3_0) { /* SSL2 */
 
80
                inf.sessionIDLength = SSL2_SESSIONID_BYTES;
 
81
                memcpy(inf.sessionID, sid->u.ssl2.sessionID, 
 
82
                       SSL2_SESSIONID_BYTES);
 
83
            } else {
 
84
                unsigned int sidLen = sid->u.ssl3.sessionIDLength;
 
85
                sidLen = PR_MIN(sidLen, sizeof inf.sessionID);
 
86
                inf.sessionIDLength = sidLen;
 
87
                memcpy(inf.sessionID, sid->u.ssl3.sessionID, sidLen);
 
88
            }
 
89
        }
 
90
    }
 
91
 
 
92
    memcpy(info, &inf, inf.length);
 
93
 
 
94
    return SECSuccess;
 
95
}
 
96
 
 
97
 
 
98
#define CS(x) x, #x
 
99
#define CK(x) x | 0xff00, #x
 
100
 
 
101
#define S_DSA   "DSA", ssl_auth_dsa
 
102
#define S_RSA   "RSA", ssl_auth_rsa
 
103
#define S_KEA   "KEA", ssl_auth_kea
 
104
#define S_ECDSA "ECDSA", ssl_auth_ecdsa
 
105
 
 
106
#define K_DHE   "DHE", kt_dh
 
107
#define K_RSA   "RSA", kt_rsa
 
108
#define K_KEA   "KEA", kt_kea
 
109
#define K_ECDH  "ECDH", kt_ecdh
 
110
#define K_ECDHE "ECDHE", kt_ecdh
 
111
 
 
112
#define C_AES   "AES", calg_aes
 
113
#define C_RC4   "RC4", calg_rc4
 
114
#define C_RC2   "RC2", calg_rc2
 
115
#define C_DES   "DES", calg_des
 
116
#define C_3DES  "3DES", calg_3des
 
117
#define C_NULL  "NULL", calg_null
 
118
#define C_SJ    "SKIPJACK", calg_sj
 
119
 
 
120
#define B_256   256, 256, 256
 
121
#define B_128   128, 128, 128
 
122
#define B_3DES  192, 156, 112
 
123
#define B_SJ     96,  80,  80
 
124
#define B_DES    64,  56,  56
 
125
#define B_56    128,  56,  56
 
126
#define B_40    128,  40,  40
 
127
#define B_0       0,   0,   0
 
128
 
 
129
#define M_SHA   "SHA1", ssl_mac_sha, 160
 
130
#define M_MD5   "MD5",  ssl_mac_md5, 128
 
131
 
 
132
static const SSLCipherSuiteInfo suiteInfo[] = {
 
133
/* <------ Cipher suite --------------------> <auth> <KEA>  <bulk cipher> <MAC> <FIPS> */
 
134
{0,CS(TLS_DHE_RSA_WITH_AES_256_CBC_SHA),      S_RSA, K_DHE, C_AES, B_256, M_SHA, 1, 0, 0, },
 
135
{0,CS(TLS_DHE_DSS_WITH_AES_256_CBC_SHA),      S_DSA, K_DHE, C_AES, B_256, M_SHA, 1, 0, 0, },
 
136
{0,CS(TLS_RSA_WITH_AES_256_CBC_SHA),          S_RSA, K_RSA, C_AES, B_256, M_SHA, 1, 0, 0, },
 
137
 
 
138
{0,CS(TLS_DHE_DSS_WITH_RC4_128_SHA),          S_DSA, K_DHE, C_RC4, B_128, M_SHA, 0, 0, 0, },
 
139
{0,CS(TLS_DHE_RSA_WITH_AES_128_CBC_SHA),      S_RSA, K_DHE, C_AES, B_128, M_SHA, 1, 0, 0, },
 
140
{0,CS(TLS_DHE_DSS_WITH_AES_128_CBC_SHA),      S_DSA, K_DHE, C_AES, B_128, M_SHA, 1, 0, 0, },
 
141
{0,CS(SSL_RSA_WITH_RC4_128_MD5),              S_RSA, K_RSA, C_RC4, B_128, M_MD5, 0, 0, 0, },
 
142
{0,CS(SSL_RSA_WITH_RC4_128_SHA),              S_RSA, K_RSA, C_RC4, B_128, M_SHA, 0, 0, 0, },
 
143
{0,CS(TLS_RSA_WITH_AES_128_CBC_SHA),          S_RSA, K_RSA, C_AES, B_128, M_SHA, 1, 0, 0, },
 
144
 
 
145
{0,CS(SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA),     S_RSA, K_DHE, C_3DES,B_3DES,M_SHA, 1, 0, 0, },
 
146
{0,CS(SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA),     S_DSA, K_DHE, C_3DES,B_3DES,M_SHA, 1, 0, 0, },
 
147
{0,CS(SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA),    S_RSA, K_RSA, C_3DES,B_3DES,M_SHA, 1, 0, 1, },
 
148
{0,CS(SSL_RSA_WITH_3DES_EDE_CBC_SHA),         S_RSA, K_RSA, C_3DES,B_3DES,M_SHA, 1, 0, 0, },
 
149
 
 
150
{0,CS(SSL_DHE_RSA_WITH_DES_CBC_SHA),          S_RSA, K_DHE, C_DES, B_DES, M_SHA, 0, 0, 0, },
 
151
{0,CS(SSL_DHE_DSS_WITH_DES_CBC_SHA),          S_DSA, K_DHE, C_DES, B_DES, M_SHA, 0, 0, 0, },
 
152
{0,CS(SSL_RSA_FIPS_WITH_DES_CBC_SHA),         S_RSA, K_RSA, C_DES, B_DES, M_SHA, 0, 0, 1, },
 
153
{0,CS(SSL_RSA_WITH_DES_CBC_SHA),              S_RSA, K_RSA, C_DES, B_DES, M_SHA, 0, 0, 0, },
 
154
 
 
155
{0,CS(TLS_RSA_EXPORT1024_WITH_RC4_56_SHA),    S_RSA, K_RSA, C_RC4, B_56,  M_SHA, 0, 1, 0, },
 
156
{0,CS(TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA),   S_RSA, K_RSA, C_DES, B_DES, M_SHA, 0, 1, 0, },
 
157
{0,CS(SSL_RSA_EXPORT_WITH_RC4_40_MD5),        S_RSA, K_RSA, C_RC4, B_40,  M_MD5, 0, 1, 0, },
 
158
{0,CS(SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5),    S_RSA, K_RSA, C_RC2, B_40,  M_MD5, 0, 1, 0, },
 
159
{0,CS(SSL_RSA_WITH_NULL_SHA),                 S_RSA, K_RSA, C_NULL,B_0,   M_SHA, 0, 1, 0, },
 
160
{0,CS(SSL_RSA_WITH_NULL_MD5),                 S_RSA, K_RSA, C_NULL,B_0,   M_MD5, 0, 1, 0, },
 
161
 
 
162
#ifdef NSS_ENABLE_ECC
 
163
/* ECC cipher suites */
 
164
{0,CS(TLS_ECDH_ECDSA_WITH_NULL_SHA),          S_ECDSA, K_ECDH, C_NULL, B_0, M_SHA, 0, 0, 0, },
 
165
{0,CS(TLS_ECDH_ECDSA_WITH_RC4_128_SHA),       S_ECDSA, K_ECDH, C_RC4, B_128, M_SHA, 0, 0, 0, },
 
166
{0,CS(TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA),  S_ECDSA, K_ECDH, C_3DES, B_3DES, M_SHA, 1, 0, 0, },
 
167
{0,CS(TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA),   S_ECDSA, K_ECDH, C_AES, B_128, M_SHA, 1, 0, 0, },
 
168
{0,CS(TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA),   S_ECDSA, K_ECDH, C_AES, B_256, M_SHA, 1, 0, 0, },
 
169
 
 
170
{0,CS(TLS_ECDHE_ECDSA_WITH_NULL_SHA),         S_ECDSA, K_ECDHE, C_NULL, B_0, M_SHA, 0, 0, 0, },
 
171
{0,CS(TLS_ECDHE_ECDSA_WITH_RC4_128_SHA),      S_ECDSA, K_ECDHE, C_RC4, B_128, M_SHA, 0, 0, 0, },
 
172
{0,CS(TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA), S_ECDSA, K_ECDHE, C_3DES, B_3DES, M_SHA, 1, 0, 0, },
 
173
{0,CS(TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA),  S_ECDSA, K_ECDHE, C_AES, B_128, M_SHA, 1, 0, 0, },
 
174
{0,CS(TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA),  S_ECDSA, K_ECDHE, C_AES, B_256, M_SHA, 1, 0, 0, },
 
175
 
 
176
{0,CS(TLS_ECDH_RSA_WITH_NULL_SHA),            S_RSA, K_ECDH, C_NULL, B_0, M_SHA, 0, 0, 0, },
 
177
{0,CS(TLS_ECDH_RSA_WITH_RC4_128_SHA),         S_RSA, K_ECDH, C_RC4, B_128, M_SHA, 0, 0, 0, },
 
178
{0,CS(TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA),    S_RSA, K_ECDH, C_3DES, B_3DES, M_SHA, 1, 0, 0, },
 
179
{0,CS(TLS_ECDH_RSA_WITH_AES_128_CBC_SHA),     S_RSA, K_ECDH, C_AES, B_128, M_SHA, 1, 0, 0, },
 
180
{0,CS(TLS_ECDH_RSA_WITH_AES_256_CBC_SHA),     S_RSA, K_ECDH, C_AES, B_256, M_SHA, 1, 0, 0, },
 
181
 
 
182
{0,CS(TLS_ECDHE_RSA_WITH_NULL_SHA),           S_RSA, K_ECDHE, C_NULL, B_0, M_SHA, 0, 0, 0, },
 
183
{0,CS(TLS_ECDHE_RSA_WITH_RC4_128_SHA),        S_RSA, K_ECDHE, C_RC4, B_128, M_SHA, 0, 0, 0, },
 
184
{0,CS(TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA),   S_RSA, K_ECDHE, C_3DES, B_3DES, M_SHA, 1, 0, 0, },
 
185
{0,CS(TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA),    S_RSA, K_ECDHE, C_AES, B_128, M_SHA, 1, 0, 0, },
 
186
{0,CS(TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA),    S_RSA, K_ECDHE, C_AES, B_256, M_SHA, 1, 0, 0, },
 
187
#endif /* NSS_ENABLE_ECC */
 
188
 
 
189
/* SSL 2 table */
 
190
{0,CK(SSL_CK_RC4_128_WITH_MD5),               S_RSA, K_RSA, C_RC4, B_128, M_MD5, 0, 0, 0, },
 
191
{0,CK(SSL_CK_RC2_128_CBC_WITH_MD5),           S_RSA, K_RSA, C_RC2, B_128, M_MD5, 0, 0, 0, },
 
192
{0,CK(SSL_CK_DES_192_EDE3_CBC_WITH_MD5),      S_RSA, K_RSA, C_3DES,B_3DES,M_MD5, 0, 0, 0, },
 
193
{0,CK(SSL_CK_DES_64_CBC_WITH_MD5),            S_RSA, K_RSA, C_DES, B_DES, M_MD5, 0, 0, 0, },
 
194
{0,CK(SSL_CK_RC4_128_EXPORT40_WITH_MD5),      S_RSA, K_RSA, C_RC4, B_40,  M_MD5, 0, 1, 0, },
 
195
{0,CK(SSL_CK_RC2_128_CBC_EXPORT40_WITH_MD5),  S_RSA, K_RSA, C_RC2, B_40,  M_MD5, 0, 1, 0, }
 
196
};
 
197
 
 
198
#define NUM_SUITEINFOS ((sizeof suiteInfo) / (sizeof suiteInfo[0]))
 
199
 
 
200
 
 
201
SECStatus SSL_GetCipherSuiteInfo(PRUint16 cipherSuite, 
 
202
                                 SSLCipherSuiteInfo *info, PRUintn len)
 
203
{
 
204
    unsigned int i;
 
205
 
 
206
    len = PR_MIN(len, sizeof suiteInfo[0]);
 
207
    if (!info || len < sizeof suiteInfo[0].length) {
 
208
        PORT_SetError(SEC_ERROR_INVALID_ARGS);
 
209
        return SECFailure;
 
210
    }
 
211
    for (i = 0; i < NUM_SUITEINFOS; i++) {
 
212
        if (suiteInfo[i].cipherSuite == cipherSuite) {
 
213
            memcpy(info, &suiteInfo[i], len);
 
214
            info->length = len;
 
215
            return SECSuccess;
 
216
        }
 
217
    }
 
218
    PORT_SetError(SEC_ERROR_INVALID_ARGS);
 
219
    return SECFailure;
 
220
}
 
221
 
 
222
/* This function might be a candidate to be public. 
 
223
 * Disables all export ciphers in the default set of enabled ciphers.
 
224
 */
 
225
SECStatus 
 
226
SSL_DisableDefaultExportCipherSuites(void)
 
227
{
 
228
    const SSLCipherSuiteInfo * pInfo = suiteInfo;
 
229
    unsigned int i;
 
230
    SECStatus rv;
 
231
 
 
232
    for (i = 0; i < NUM_SUITEINFOS; ++i, ++pInfo) {
 
233
        if (pInfo->isExportable) {
 
234
            rv = SSL_CipherPrefSetDefault(pInfo->cipherSuite, PR_FALSE);
 
235
            PORT_Assert(rv == SECSuccess);
 
236
        }
 
237
    }
 
238
    return SECSuccess;
 
239
}
 
240
 
 
241
/* This function might be a candidate to be public, 
 
242
 * except that it takes an sslSocket pointer as an argument.
 
243
 * A Public version would take a PRFileDesc pointer.
 
244
 * Disables all export ciphers in the default set of enabled ciphers.
 
245
 */
 
246
SECStatus 
 
247
SSL_DisableExportCipherSuites(PRFileDesc * fd)
 
248
{
 
249
    const SSLCipherSuiteInfo * pInfo = suiteInfo;
 
250
    unsigned int i;
 
251
    SECStatus rv;
 
252
 
 
253
    for (i = 0; i < NUM_SUITEINFOS; ++i, ++pInfo) {
 
254
        if (pInfo->isExportable) {
 
255
            rv = SSL_CipherPrefSet(fd, pInfo->cipherSuite, PR_FALSE);
 
256
            PORT_Assert(rv == SECSuccess);
 
257
        }
 
258
    }
 
259
    return SECSuccess;
 
260
}
 
261
 
 
262
/* Tells us if the named suite is exportable 
 
263
 * returns false for unknown suites.
 
264
 */
 
265
PRBool
 
266
SSL_IsExportCipherSuite(PRUint16 cipherSuite)
 
267
{
 
268
    unsigned int i;
 
269
    for (i = 0; i < NUM_SUITEINFOS; i++) {
 
270
        if (suiteInfo[i].cipherSuite == cipherSuite) {
 
271
            return (PRBool)(suiteInfo[i].isExportable);
 
272
        }
 
273
    }
 
274
    return PR_FALSE;
 
275
}