1
/* ***** BEGIN LICENSE BLOCK *****
2
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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
14
* The Original Code is the Netscape security libraries.
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.
22
* Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
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.
36
* ***** END LICENSE BLOCK ***** */
37
/* $Id: sslinfo.c,v 1.14.2.1 2006/01/28 00:13:37 wtchang%redhat.com Exp $ */
43
SSL_GetChannelInfo(PRFileDesc *fd, SSLChannelInfo *info, PRUintn len)
49
if (!info || len < sizeof inf.length) {
53
ss = ssl_FindSocket(fd);
55
SSL_DBG(("%d: SSL[%d]: bad socket in SSL_GetChannelInfo",
60
memset(&inf, 0, sizeof inf);
61
inf.length = PR_MIN(sizeof inf, len);
63
if (ss->opt.useSecurity && ss->firstHsDone) {
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 */
72
/* XXX These should come from crSpec */
73
inf.cipherSuite = ss->ssl3.hs.cipher_suite;
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);
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);
92
memcpy(info, &inf, inf.length);
99
#define CK(x) x | 0xff00, #x
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
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
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
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
129
#define M_SHA "SHA1", ssl_mac_sha, 160
130
#define M_MD5 "MD5", ssl_mac_md5, 128
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, },
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, },
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, },
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, },
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, },
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, },
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, },
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, },
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 */
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, }
198
#define NUM_SUITEINFOS ((sizeof suiteInfo) / (sizeof suiteInfo[0]))
201
SECStatus SSL_GetCipherSuiteInfo(PRUint16 cipherSuite,
202
SSLCipherSuiteInfo *info, PRUintn len)
206
len = PR_MIN(len, sizeof suiteInfo[0]);
207
if (!info || len < sizeof suiteInfo[0].length) {
208
PORT_SetError(SEC_ERROR_INVALID_ARGS);
211
for (i = 0; i < NUM_SUITEINFOS; i++) {
212
if (suiteInfo[i].cipherSuite == cipherSuite) {
213
memcpy(info, &suiteInfo[i], len);
218
PORT_SetError(SEC_ERROR_INVALID_ARGS);
222
/* This function might be a candidate to be public.
223
* Disables all export ciphers in the default set of enabled ciphers.
226
SSL_DisableDefaultExportCipherSuites(void)
228
const SSLCipherSuiteInfo * pInfo = suiteInfo;
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);
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.
247
SSL_DisableExportCipherSuites(PRFileDesc * fd)
249
const SSLCipherSuiteInfo * pInfo = suiteInfo;
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);
262
/* Tells us if the named suite is exportable
263
* returns false for unknown suites.
266
SSL_IsExportCipherSuite(PRUint16 cipherSuite)
269
for (i = 0; i < NUM_SUITEINFOS; i++) {
270
if (suiteInfo[i].cipherSuite == cipherSuite) {
271
return (PRBool)(suiteInfo[i].isExportable);