OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This file is PRIVATE to SSL and should be the first thing included by |
| 3 * any SSL implementation file. |
| 4 * |
| 5 * ***** BEGIN LICENSE BLOCK ***** |
| 6 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 7 * |
| 8 * The contents of this file are subject to the Mozilla Public License Version |
| 9 * 1.1 (the "License"); you may not use this file except in compliance with |
| 10 * the License. You may obtain a copy of the License at |
| 11 * http://www.mozilla.org/MPL/ |
| 12 * |
| 13 * Software distributed under the License is distributed on an "AS IS" basis, |
| 14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 15 * for the specific language governing rights and limitations under the |
| 16 * License. |
| 17 * |
| 18 * The Original Code is the Netscape security libraries. |
| 19 * |
| 20 * The Initial Developer of the Original Code is |
| 21 * Netscape Communications Corporation. |
| 22 * Portions created by the Initial Developer are Copyright (C) 1994-2000 |
| 23 * the Initial Developer. All Rights Reserved. |
| 24 * |
| 25 * Contributor(s): |
| 26 * Dr Stephen Henson <stephen.henson@gemplus.com> |
| 27 * Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories |
| 28 * |
| 29 * Alternatively, the contents of this file may be used under the terms of |
| 30 * either the GNU General Public License Version 2 or later (the "GPL"), or |
| 31 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
| 32 * in which case the provisions of the GPL or the LGPL are applicable instead |
| 33 * of those above. If you wish to allow use of your version of this file only |
| 34 * under the terms of either the GPL or the LGPL, and not to allow others to |
| 35 * use your version of this file under the terms of the MPL, indicate your |
| 36 * decision by deleting the provisions above and replace them with the notice |
| 37 * and other provisions required by the GPL or the LGPL. If you do not delete |
| 38 * the provisions above, a recipient may use your version of this file under |
| 39 * the terms of any one of the MPL, the GPL or the LGPL. |
| 40 * |
| 41 * ***** END LICENSE BLOCK ***** */ |
| 42 /* $Id: sslimpl.h,v 1.69 2009/11/07 18:23:06 wtc%google.com Exp $ */ |
| 43 |
| 44 #ifndef __sslimpl_h_ |
| 45 #define __sslimpl_h_ |
| 46 |
| 47 #ifdef DEBUG |
| 48 #undef NDEBUG |
| 49 #else |
| 50 #undef NDEBUG |
| 51 #define NDEBUG |
| 52 #endif |
| 53 #include "secport.h" |
| 54 #include "secerr.h" |
| 55 #include "sslerr.h" |
| 56 #include "ssl3prot.h" |
| 57 #include "hasht.h" |
| 58 #include "nssilock.h" |
| 59 #include "pkcs11t.h" |
| 60 #if defined(XP_UNIX) || defined(XP_BEOS) |
| 61 #include "unistd.h" |
| 62 #endif |
| 63 #include "nssrwlk.h" |
| 64 #include "prthread.h" |
| 65 |
| 66 #include "sslt.h" /* for some formerly private types, now public */ |
| 67 |
| 68 /* to make some of these old enums public without namespace pollution, |
| 69 ** it was necessary to prepend ssl_ to the names. |
| 70 ** These #defines preserve compatibility with the old code here in libssl. |
| 71 */ |
| 72 typedef SSLKEAType SSL3KEAType; |
| 73 typedef SSLMACAlgorithm SSL3MACAlgorithm; |
| 74 typedef SSLSignType SSL3SignType; |
| 75 |
| 76 #define sign_null ssl_sign_null |
| 77 #define sign_rsa ssl_sign_rsa |
| 78 #define sign_dsa ssl_sign_dsa |
| 79 #define sign_ecdsa ssl_sign_ecdsa |
| 80 |
| 81 #define calg_null ssl_calg_null |
| 82 #define calg_rc4 ssl_calg_rc4 |
| 83 #define calg_rc2 ssl_calg_rc2 |
| 84 #define calg_des ssl_calg_des |
| 85 #define calg_3des ssl_calg_3des |
| 86 #define calg_idea ssl_calg_idea |
| 87 #define calg_fortezza ssl_calg_fortezza /* deprecated, must preserve */ |
| 88 #define calg_aes ssl_calg_aes |
| 89 #define calg_camellia ssl_calg_camellia |
| 90 #define calg_seed ssl_calg_seed |
| 91 |
| 92 #define mac_null ssl_mac_null |
| 93 #define mac_md5 ssl_mac_md5 |
| 94 #define mac_sha ssl_mac_sha |
| 95 #define hmac_md5 ssl_hmac_md5 |
| 96 #define hmac_sha ssl_hmac_sha |
| 97 |
| 98 #define SET_ERROR_CODE /* reminder */ |
| 99 #define SEND_ALERT /* reminder */ |
| 100 #define TEST_FOR_FAILURE /* reminder */ |
| 101 #define DEAL_WITH_FAILURE /* reminder */ |
| 102 |
| 103 #if defined(DEBUG) || defined(TRACE) |
| 104 #ifdef __cplusplus |
| 105 #define Debug 1 |
| 106 #else |
| 107 extern int Debug; |
| 108 #endif |
| 109 #else |
| 110 #undef Debug |
| 111 #endif |
| 112 |
| 113 #if defined(DEBUG) && !defined(TRACE) && !defined(NISCC_TEST) |
| 114 #define TRACE |
| 115 #endif |
| 116 |
| 117 #ifdef TRACE |
| 118 #define SSL_TRC(a,b) if (ssl_trace >= (a)) ssl_Trace b |
| 119 #define PRINT_BUF(a,b) if (ssl_trace >= (a)) ssl_PrintBuf b |
| 120 #define DUMP_MSG(a,b) if (ssl_trace >= (a)) ssl_DumpMsg b |
| 121 #else |
| 122 #define SSL_TRC(a,b) |
| 123 #define PRINT_BUF(a,b) |
| 124 #define DUMP_MSG(a,b) |
| 125 #endif |
| 126 |
| 127 #ifdef DEBUG |
| 128 #define SSL_DBG(b) if (ssl_debug) ssl_Trace b |
| 129 #else |
| 130 #define SSL_DBG(b) |
| 131 #endif |
| 132 |
| 133 #ifdef macintosh |
| 134 #include "pprthred.h" |
| 135 #else |
| 136 #include "private/pprthred.h" /* for PR_InMonitor() */ |
| 137 #endif |
| 138 #define ssl_InMonitor(m) PZ_InMonitor(m) |
| 139 |
| 140 #define LSB(x) ((unsigned char) (x & 0xff)) |
| 141 #define MSB(x) ((unsigned char) (((unsigned)(x)) >> 8)) |
| 142 |
| 143 /************************************************************************/ |
| 144 |
| 145 typedef enum { SSLAppOpRead = 0, |
| 146 SSLAppOpWrite, |
| 147 SSLAppOpRDWR, |
| 148 SSLAppOpPost, |
| 149 SSLAppOpHeader |
| 150 } SSLAppOperation; |
| 151 |
| 152 #define SSL_MIN_MASTER_KEY_BYTES 5 |
| 153 #define SSL_MAX_MASTER_KEY_BYTES 64 |
| 154 |
| 155 #define SSL2_SESSIONID_BYTES 16 |
| 156 #define SSL3_SESSIONID_BYTES 32 |
| 157 |
| 158 #define SSL_MIN_CHALLENGE_BYTES 16 |
| 159 #define SSL_MAX_CHALLENGE_BYTES 32 |
| 160 #define SSL_CHALLENGE_BYTES 16 |
| 161 |
| 162 #define SSL_CONNECTIONID_BYTES 16 |
| 163 |
| 164 #define SSL_MIN_CYPHER_ARG_BYTES 0 |
| 165 #define SSL_MAX_CYPHER_ARG_BYTES 32 |
| 166 |
| 167 #define SSL_MAX_MAC_BYTES 16 |
| 168 |
| 169 #define SSL3_RSA_PMS_LENGTH 48 |
| 170 #define SSL3_MASTER_SECRET_LENGTH 48 |
| 171 |
| 172 /* number of wrap mechanisms potentially used to wrap master secrets. */ |
| 173 #define SSL_NUM_WRAP_MECHS 16 |
| 174 |
| 175 /* This makes the cert cache entry exactly 4k. */ |
| 176 #define SSL_MAX_CACHED_CERT_LEN 4060 |
| 177 |
| 178 #define NUM_MIXERS 9 |
| 179 |
| 180 /* Mask of the 25 named curves we support. */ |
| 181 #ifndef NSS_ECC_MORE_THAN_SUITE_B |
| 182 #define SSL3_SUPPORTED_CURVES_MASK 0x3800000 /* only 3 curves, suite B*/ |
| 183 #else |
| 184 #define SSL3_SUPPORTED_CURVES_MASK 0x3fffffe |
| 185 #endif |
| 186 |
| 187 #ifndef BPB |
| 188 #define BPB 8 /* Bits Per Byte */ |
| 189 #endif |
| 190 |
| 191 #define EXPORT_RSA_KEY_LENGTH 64 /* bytes */ |
| 192 |
| 193 typedef struct sslBufferStr sslBuffer; |
| 194 typedef struct sslConnectInfoStr sslConnectInfo; |
| 195 typedef struct sslGatherStr sslGather; |
| 196 typedef struct sslSecurityInfoStr sslSecurityInfo; |
| 197 typedef struct sslSessionIDStr sslSessionID; |
| 198 typedef struct sslSocketStr sslSocket; |
| 199 typedef struct sslSocketOpsStr sslSocketOps; |
| 200 |
| 201 typedef struct ssl3StateStr ssl3State; |
| 202 typedef struct ssl3CertNodeStr ssl3CertNode; |
| 203 typedef struct ssl3BulkCipherDefStr ssl3BulkCipherDef; |
| 204 typedef struct ssl3MACDefStr ssl3MACDef; |
| 205 typedef struct ssl3KeyPairStr ssl3KeyPair; |
| 206 |
| 207 struct ssl3CertNodeStr { |
| 208 struct ssl3CertNodeStr *next; |
| 209 CERTCertificate * cert; |
| 210 }; |
| 211 |
| 212 typedef SECStatus (*sslHandshakeFunc)(sslSocket *ss); |
| 213 |
| 214 /* This type points to the low layer send func, |
| 215 ** e.g. ssl2_SendStream or ssl3_SendPlainText. |
| 216 ** These functions return the same values as PR_Send, |
| 217 ** i.e. >= 0 means number of bytes sent, < 0 means error. |
| 218 */ |
| 219 typedef PRInt32 (*sslSendFunc)(sslSocket *ss, const unsigned char *buf, |
| 220 PRInt32 n, PRInt32 flags); |
| 221 |
| 222 typedef void (*sslSessionIDCacheFunc) (sslSessionID *sid); |
| 223 typedef void (*sslSessionIDUncacheFunc)(sslSessionID *sid); |
| 224 typedef sslSessionID *(*sslSessionIDLookupFunc)(const PRIPv6Addr *addr, |
| 225 unsigned char* sid, |
| 226 unsigned int sidLen, |
| 227 CERTCertDBHandle * dbHandle); |
| 228 |
| 229 /* registerable callback function that either appends extension to buffer |
| 230 * or returns length of data that it would have appended. |
| 231 */ |
| 232 typedef PRInt32 (*ssl3HelloExtensionSenderFunc)(sslSocket *ss, PRBool append, |
| 233 PRUint32 maxBytes); |
| 234 |
| 235 /* registerable callback function that handles a received extension, |
| 236 * of the given type. |
| 237 */ |
| 238 typedef SECStatus (* ssl3HelloExtensionHandlerFunc)(sslSocket *ss, |
| 239 PRUint16 ex_type, |
| 240 SECItem * data); |
| 241 |
| 242 /* row in a table of hello extension senders */ |
| 243 typedef struct { |
| 244 PRInt32 ex_type; |
| 245 ssl3HelloExtensionSenderFunc ex_sender; |
| 246 } ssl3HelloExtensionSender; |
| 247 |
| 248 /* row in a table of hello extension handlers */ |
| 249 typedef struct { |
| 250 PRInt32 ex_type; |
| 251 ssl3HelloExtensionHandlerFunc ex_handler; |
| 252 } ssl3HelloExtensionHandler; |
| 253 |
| 254 extern SECStatus |
| 255 ssl3_RegisterServerHelloExtensionSender(sslSocket *ss, PRUint16 ex_type, |
| 256 ssl3HelloExtensionSenderFunc cb); |
| 257 |
| 258 extern PRInt32 |
| 259 ssl3_CallHelloExtensionSenders(sslSocket *ss, PRBool append, PRUint32 maxBytes, |
| 260 const ssl3HelloExtensionSender *sender); |
| 261 |
| 262 /* Socket ops */ |
| 263 struct sslSocketOpsStr { |
| 264 int (*connect) (sslSocket *, const PRNetAddr *); |
| 265 PRFileDesc *(*accept) (sslSocket *, PRNetAddr *); |
| 266 int (*bind) (sslSocket *, const PRNetAddr *); |
| 267 int (*listen) (sslSocket *, int); |
| 268 int (*shutdown)(sslSocket *, int); |
| 269 int (*close) (sslSocket *); |
| 270 |
| 271 int (*recv) (sslSocket *, unsigned char *, int, int); |
| 272 |
| 273 /* points to the higher-layer send func, e.g. ssl_SecureSend. */ |
| 274 int (*send) (sslSocket *, const unsigned char *, int, int); |
| 275 int (*read) (sslSocket *, unsigned char *, int); |
| 276 int (*write) (sslSocket *, const unsigned char *, int); |
| 277 |
| 278 int (*getpeername)(sslSocket *, PRNetAddr *); |
| 279 int (*getsockname)(sslSocket *, PRNetAddr *); |
| 280 }; |
| 281 |
| 282 /* Flags interpreted by ssl send functions. */ |
| 283 #define ssl_SEND_FLAG_FORCE_INTO_BUFFER 0x40000000 |
| 284 #define ssl_SEND_FLAG_NO_BUFFER 0x20000000 |
| 285 #define ssl_SEND_FLAG_MASK 0x7f000000 |
| 286 |
| 287 /* |
| 288 ** A buffer object. |
| 289 */ |
| 290 struct sslBufferStr { |
| 291 unsigned char * buf; |
| 292 unsigned int len; |
| 293 unsigned int space; |
| 294 }; |
| 295 |
| 296 /* |
| 297 ** SSL3 cipher suite policy and preference struct. |
| 298 */ |
| 299 typedef struct { |
| 300 #if !defined(_WIN32) |
| 301 unsigned int cipher_suite : 16; |
| 302 unsigned int policy : 8; |
| 303 unsigned int enabled : 1; |
| 304 unsigned int isPresent : 1; |
| 305 #else |
| 306 ssl3CipherSuite cipher_suite; |
| 307 PRUint8 policy; |
| 308 unsigned char enabled : 1; |
| 309 unsigned char isPresent : 1; |
| 310 #endif |
| 311 } ssl3CipherSuiteCfg; |
| 312 |
| 313 #ifdef NSS_ENABLE_ECC |
| 314 #define ssl_V3_SUITES_IMPLEMENTED 50 |
| 315 #else |
| 316 #define ssl_V3_SUITES_IMPLEMENTED 30 |
| 317 #endif /* NSS_ENABLE_ECC */ |
| 318 |
| 319 typedef struct sslOptionsStr { |
| 320 unsigned int useSecurity : 1; /* 1 */ |
| 321 unsigned int useSocks : 1; /* 2 */ |
| 322 unsigned int requestCertificate : 1; /* 3 */ |
| 323 unsigned int requireCertificate : 2; /* 4-5 */ |
| 324 unsigned int handshakeAsClient : 1; /* 6 */ |
| 325 unsigned int handshakeAsServer : 1; /* 7 */ |
| 326 unsigned int enableSSL2 : 1; /* 8 */ |
| 327 unsigned int enableSSL3 : 1; /* 9 */ |
| 328 unsigned int enableTLS : 1; /* 10 */ |
| 329 unsigned int noCache : 1; /* 11 */ |
| 330 unsigned int fdx : 1; /* 12 */ |
| 331 unsigned int v2CompatibleHello : 1; /* 13 */ |
| 332 unsigned int detectRollBack : 1; /* 14 */ |
| 333 unsigned int noStepDown : 1; /* 15 */ |
| 334 unsigned int bypassPKCS11 : 1; /* 16 */ |
| 335 unsigned int noLocks : 1; /* 17 */ |
| 336 unsigned int enableSessionTickets : 1; /* 18 */ |
| 337 unsigned int enableDeflate : 1; /* 19 */ |
| 338 unsigned int enableRenegotiation : 2; /* 20-21 */ |
| 339 unsigned int requireSafeNegotiation : 1; /* 22 */ |
| 340 } sslOptions; |
| 341 |
| 342 typedef enum { sslHandshakingUndetermined = 0, |
| 343 sslHandshakingAsClient, |
| 344 sslHandshakingAsServer |
| 345 } sslHandshakingType; |
| 346 |
| 347 typedef struct sslServerCertsStr { |
| 348 /* Configuration state for server sockets */ |
| 349 CERTCertificate * serverCert; |
| 350 CERTCertificateList * serverCertChain; |
| 351 ssl3KeyPair * serverKeyPair; |
| 352 unsigned int serverKeyBits; |
| 353 } sslServerCerts; |
| 354 |
| 355 #define SERVERKEY serverKeyPair->privKey |
| 356 |
| 357 #define SSL_LOCK_RANK_SPEC 255 |
| 358 #define SSL_LOCK_RANK_GLOBAL NSS_RWLOCK_RANK_NONE |
| 359 |
| 360 /* These are the valid values for shutdownHow. |
| 361 ** These values are each 1 greater than the NSPR values, and the code |
| 362 ** depends on that relation to efficiently convert PR_SHUTDOWN values |
| 363 ** into ssl_SHUTDOWN values. These values use one bit for read, and |
| 364 ** another bit for write, and can be used as bitmasks. |
| 365 */ |
| 366 #define ssl_SHUTDOWN_NONE 0 /* NOT shutdown at all */ |
| 367 #define ssl_SHUTDOWN_RCV 1 /* PR_SHUTDOWN_RCV +1 */ |
| 368 #define ssl_SHUTDOWN_SEND 2 /* PR_SHUTDOWN_SEND +1 */ |
| 369 #define ssl_SHUTDOWN_BOTH 3 /* PR_SHUTDOWN_BOTH +1 */ |
| 370 |
| 371 /* |
| 372 ** A gather object. Used to read some data until a count has been |
| 373 ** satisfied. Primarily for support of async sockets. |
| 374 ** Everything in here is protected by the recvBufLock. |
| 375 */ |
| 376 struct sslGatherStr { |
| 377 int state; /* see GS_ values below. */ /* ssl 2 & 3 */ |
| 378 |
| 379 /* "buf" holds received plaintext SSL records, after decrypt and MAC check. |
| 380 * SSL2: recv'd ciphertext records are put here, then decrypted in place. |
| 381 * SSL3: recv'd ciphertext records are put in inbuf (see below), then |
| 382 * decrypted into buf. |
| 383 */ |
| 384 sslBuffer buf; /*recvBufLock*/ /* ssl 2 & 3 */ |
| 385 |
| 386 /* number of bytes previously read into hdr or buf(ssl2) or inbuf (ssl3). |
| 387 ** (offset - writeOffset) is the number of ciphertext bytes read in but |
| 388 ** not yet deciphered. |
| 389 */ |
| 390 unsigned int offset; /* ssl 2 & 3 */ |
| 391 |
| 392 /* number of bytes to read in next call to ssl_DefRecv (recv) */ |
| 393 unsigned int remainder; /* ssl 2 & 3 */ |
| 394 |
| 395 /* Number of ciphertext bytes to read in after 2-byte SSL record header. */ |
| 396 unsigned int count; /* ssl2 only */ |
| 397 |
| 398 /* size of the final plaintext record. |
| 399 ** == count - (recordPadding + MAC size) |
| 400 */ |
| 401 unsigned int recordLen; /* ssl2 only */ |
| 402 |
| 403 /* number of bytes of padding to be removed after decrypting. */ |
| 404 /* This value is taken from the record's hdr[2], which means a too large |
| 405 * value could crash us. |
| 406 */ |
| 407 unsigned int recordPadding; /* ssl2 only */ |
| 408 |
| 409 /* plaintext DATA begins this many bytes into "buf". */ |
| 410 unsigned int recordOffset; /* ssl2 only */ |
| 411 |
| 412 int encrypted; /* SSL2 session is now encrypted. ssl2 only */ |
| 413 |
| 414 /* These next two values are used by SSL2 and SSL3. |
| 415 ** DoRecv uses them to extract application data. |
| 416 ** The difference between writeOffset and readOffset is the amount of |
| 417 ** data available to the application. Note that the actual offset of |
| 418 ** the data in "buf" is recordOffset (above), not readOffset. |
| 419 ** In the current implementation, this is made available before the |
| 420 ** MAC is checked!! |
| 421 */ |
| 422 unsigned int readOffset; /* Spot where DATA reader (e.g. application |
| 423 ** or handshake code) will read next. |
| 424 ** Always zero for SSl3 application data. |
| 425 */ |
| 426 /* offset in buf/inbuf/hdr into which new data will be read from socket. */ |
| 427 unsigned int writeOffset; |
| 428 |
| 429 /* Buffer for ssl3 to read (encrypted) data from the socket */ |
| 430 sslBuffer inbuf; /*recvBufLock*/ /* ssl3 only */ |
| 431 |
| 432 /* The ssl[23]_GatherData functions read data into this buffer, rather |
| 433 ** than into buf or inbuf, while in the GS_HEADER state. |
| 434 ** The portion of the SSL record header put here always comes off the wire |
| 435 ** as plaintext, never ciphertext. |
| 436 ** For SSL2, the plaintext portion is two bytes long. For SSl3 it is 5. |
| 437 */ |
| 438 unsigned char hdr[5]; /* ssl 2 & 3 */ |
| 439 }; |
| 440 |
| 441 /* sslGather.state */ |
| 442 #define GS_INIT 0 |
| 443 #define GS_HEADER 1 |
| 444 #define GS_MAC 2 |
| 445 #define GS_DATA 3 |
| 446 #define GS_PAD 4 |
| 447 |
| 448 typedef SECStatus (*SSLCipher)(void * context, |
| 449 unsigned char * out, |
| 450 int * outlen, |
| 451 int maxout, |
| 452 const unsigned char *in, |
| 453 int inlen); |
| 454 typedef SECStatus (*SSLCompressor)(void * context, |
| 455 unsigned char * out, |
| 456 int * outlen, |
| 457 int maxout, |
| 458 const unsigned char *in, |
| 459 int inlen); |
| 460 typedef SECStatus (*SSLDestroy)(void *context, PRBool freeit); |
| 461 |
| 462 |
| 463 |
| 464 /* |
| 465 ** ssl3State and CipherSpec structs |
| 466 */ |
| 467 |
| 468 /* The SSL bulk cipher definition */ |
| 469 typedef enum { |
| 470 cipher_null, |
| 471 cipher_rc4, |
| 472 cipher_rc4_40, |
| 473 cipher_rc4_56, |
| 474 cipher_rc2, |
| 475 cipher_rc2_40, |
| 476 cipher_des, |
| 477 cipher_3des, |
| 478 cipher_des40, |
| 479 cipher_idea, |
| 480 cipher_aes_128, |
| 481 cipher_aes_256, |
| 482 cipher_camellia_128, |
| 483 cipher_camellia_256, |
| 484 cipher_seed, |
| 485 cipher_missing /* reserved for no such supported cipher */ |
| 486 /* This enum must match ssl3_cipherName[] in ssl3con.c. */ |
| 487 } SSL3BulkCipher; |
| 488 |
| 489 typedef enum { type_stream, type_block } CipherType; |
| 490 |
| 491 #define MAX_IV_LENGTH 64 |
| 492 |
| 493 /* |
| 494 * Do not depend upon 64 bit arithmetic in the underlying machine. |
| 495 */ |
| 496 typedef struct { |
| 497 PRUint32 high; |
| 498 PRUint32 low; |
| 499 } SSL3SequenceNumber; |
| 500 |
| 501 #define MAX_MAC_CONTEXT_BYTES 400 |
| 502 #define MAX_MAC_CONTEXT_LLONGS (MAX_MAC_CONTEXT_BYTES / 8) |
| 503 |
| 504 #define MAX_CIPHER_CONTEXT_BYTES 2080 |
| 505 #define MAX_CIPHER_CONTEXT_LLONGS (MAX_CIPHER_CONTEXT_BYTES / 8) |
| 506 |
| 507 typedef struct { |
| 508 SSL3Opaque client_write_iv [24]; |
| 509 SSL3Opaque server_write_iv [24]; |
| 510 SSL3Opaque wrapped_master_secret [48]; |
| 511 PRUint16 wrapped_master_secret_len; |
| 512 PRUint8 msIsWrapped; |
| 513 PRUint8 resumable; |
| 514 } ssl3SidKeys; /* 100 bytes */ |
| 515 |
| 516 typedef struct { |
| 517 PK11SymKey *write_key; |
| 518 PK11SymKey *write_mac_key; |
| 519 PK11Context *write_mac_context; |
| 520 SECItem write_key_item; |
| 521 SECItem write_iv_item; |
| 522 SECItem write_mac_key_item; |
| 523 SSL3Opaque write_iv[MAX_IV_LENGTH]; |
| 524 PRUint64 cipher_context[MAX_CIPHER_CONTEXT_LLONGS]; |
| 525 } ssl3KeyMaterial; |
| 526 |
| 527 /* |
| 528 ** These are the "specs" in the "ssl3" struct. |
| 529 ** Access to the pointers to these specs, and all the specs' contents |
| 530 ** (direct and indirect) is protected by the reader/writer lock ss->specLock. |
| 531 */ |
| 532 typedef struct { |
| 533 const ssl3BulkCipherDef *cipher_def; |
| 534 const ssl3MACDef * mac_def; |
| 535 SSLCompressionMethod compression_method; |
| 536 int mac_size; |
| 537 SSLCipher encode; |
| 538 SSLCipher decode; |
| 539 SSLDestroy destroy; |
| 540 void * encodeContext; |
| 541 void * decodeContext; |
| 542 SSLCompressor compress; |
| 543 SSLCompressor decompress; |
| 544 SSLDestroy destroyCompressContext; |
| 545 void * compressContext; |
| 546 SSLDestroy destroyDecompressContext; |
| 547 void * decompressContext; |
| 548 PRBool bypassCiphers; /* did double bypass (at least) */ |
| 549 PK11SymKey * master_secret; |
| 550 SSL3SequenceNumber write_seq_num; |
| 551 SSL3SequenceNumber read_seq_num; |
| 552 SSL3ProtocolVersion version; |
| 553 ssl3KeyMaterial client; |
| 554 ssl3KeyMaterial server; |
| 555 SECItem msItem; |
| 556 unsigned char key_block[NUM_MIXERS * MD5_LENGTH]; |
| 557 unsigned char raw_master_secret[56]; |
| 558 } ssl3CipherSpec; |
| 559 |
| 560 typedef enum { never_cached, |
| 561 in_client_cache, |
| 562 in_server_cache, |
| 563 invalid_cache /* no longer in any cache. */ |
| 564 } Cached; |
| 565 |
| 566 struct sslSessionIDStr { |
| 567 sslSessionID * next; /* chain used for client sockets, only */ |
| 568 |
| 569 CERTCertificate * peerCert; |
| 570 const char * peerID; /* client only */ |
| 571 const char * urlSvrName; /* client only */ |
| 572 CERTCertificate * localCert; |
| 573 |
| 574 PRIPv6Addr addr; |
| 575 PRUint16 port; |
| 576 |
| 577 SSL3ProtocolVersion version; |
| 578 |
| 579 PRUint32 creationTime; /* seconds since Jan 1, 1970 */ |
| 580 PRUint32 lastAccessTime; /* seconds since Jan 1, 1970 */ |
| 581 PRUint32 expirationTime; /* seconds since Jan 1, 1970 */ |
| 582 Cached cached; |
| 583 int references; |
| 584 |
| 585 SSLSignType authAlgorithm; |
| 586 PRUint32 authKeyBits; |
| 587 SSLKEAType keaType; |
| 588 PRUint32 keaKeyBits; |
| 589 |
| 590 union { |
| 591 struct { |
| 592 /* the V2 code depends upon the size of sessionID. */ |
| 593 unsigned char sessionID[SSL2_SESSIONID_BYTES]; |
| 594 |
| 595 /* Stuff used to recreate key and read/write cipher objects */ |
| 596 SECItem masterKey; /* never wrapped */ |
| 597 int cipherType; |
| 598 SECItem cipherArg; |
| 599 int keyBits; |
| 600 int secretKeyBits; |
| 601 } ssl2; |
| 602 struct { |
| 603 /* values that are copied into the server's on-disk SID cache. */ |
| 604 uint8 sessionIDLength; |
| 605 SSL3Opaque sessionID[SSL3_SESSIONID_BYTES]; |
| 606 |
| 607 ssl3CipherSuite cipherSuite; |
| 608 SSLCompressionMethod compression; |
| 609 int policy; |
| 610 ssl3SidKeys keys; |
| 611 CK_MECHANISM_TYPE masterWrapMech; |
| 612 /* mechanism used to wrap master secret */ |
| 613 SSL3KEAType exchKeyType; |
| 614 /* key type used in exchange algorithm, |
| 615 * and to wrap the sym wrapping key. */ |
| 616 #ifdef NSS_ENABLE_ECC |
| 617 PRUint32 negotiatedECCurves; |
| 618 #endif /* NSS_ENABLE_ECC */ |
| 619 |
| 620 /* The following values are NOT restored from the server's on-disk |
| 621 * session cache, but are restored from the client's cache. |
| 622 */ |
| 623 PK11SymKey * clientWriteKey; |
| 624 PK11SymKey * serverWriteKey; |
| 625 |
| 626 /* The following values pertain to the slot that wrapped the |
| 627 ** master secret. (used only in client) |
| 628 */ |
| 629 SECMODModuleID masterModuleID; |
| 630 /* what module wrapped the master secret */ |
| 631 CK_SLOT_ID masterSlotID; |
| 632 PRUint16 masterWrapIndex; |
| 633 /* what's the key index for the wrapping key */ |
| 634 PRUint16 masterWrapSeries; |
| 635 /* keep track of the slot series, so we don't |
| 636 * accidently try to use new keys after the |
| 637 * card gets removed and replaced.*/ |
| 638 |
| 639 /* The following values pertain to the slot that did the signature |
| 640 ** for client auth. (used only in client) |
| 641 */ |
| 642 SECMODModuleID clAuthModuleID; |
| 643 CK_SLOT_ID clAuthSlotID; |
| 644 PRUint16 clAuthSeries; |
| 645 |
| 646 char masterValid; |
| 647 char clAuthValid; |
| 648 |
| 649 /* Session ticket if we have one, is sent as an extension in the |
| 650 * ClientHello message. This field is used by clients. |
| 651 */ |
| 652 NewSessionTicket sessionTicket; |
| 653 } ssl3; |
| 654 } u; |
| 655 }; |
| 656 |
| 657 |
| 658 typedef struct ssl3CipherSuiteDefStr { |
| 659 ssl3CipherSuite cipher_suite; |
| 660 SSL3BulkCipher bulk_cipher_alg; |
| 661 SSL3MACAlgorithm mac_alg; |
| 662 SSL3KeyExchangeAlgorithm key_exchange_alg; |
| 663 } ssl3CipherSuiteDef; |
| 664 |
| 665 /* |
| 666 ** There are tables of these, all const. |
| 667 */ |
| 668 typedef struct { |
| 669 SSL3KeyExchangeAlgorithm kea; |
| 670 SSL3KEAType exchKeyType; |
| 671 SSL3SignType signKeyType; |
| 672 PRBool is_limited; |
| 673 int key_size_limit; |
| 674 PRBool tls_keygen; |
| 675 } ssl3KEADef; |
| 676 |
| 677 typedef enum { kg_null, kg_strong, kg_export } SSL3KeyGenMode; |
| 678 |
| 679 /* |
| 680 ** There are tables of these, all const. |
| 681 */ |
| 682 struct ssl3BulkCipherDefStr { |
| 683 SSL3BulkCipher cipher; |
| 684 SSLCipherAlgorithm calg; |
| 685 int key_size; |
| 686 int secret_key_size; |
| 687 CipherType type; |
| 688 int iv_size; |
| 689 int block_size; |
| 690 SSL3KeyGenMode keygen_mode; |
| 691 }; |
| 692 |
| 693 /* |
| 694 ** There are tables of these, all const. |
| 695 */ |
| 696 struct ssl3MACDefStr { |
| 697 SSL3MACAlgorithm mac; |
| 698 CK_MECHANISM_TYPE mmech; |
| 699 int pad_size; |
| 700 int mac_size; |
| 701 }; |
| 702 |
| 703 typedef enum { |
| 704 wait_client_hello, |
| 705 wait_client_cert, |
| 706 wait_client_key, |
| 707 wait_cert_verify, |
| 708 wait_change_cipher, |
| 709 wait_finished, |
| 710 wait_server_hello, |
| 711 wait_server_cert, |
| 712 wait_server_key, |
| 713 wait_cert_request, |
| 714 wait_hello_done, |
| 715 wait_new_session_ticket, |
| 716 idle_handshake |
| 717 } SSL3WaitState; |
| 718 |
| 719 /* |
| 720 * TLS extension related constants and data structures. |
| 721 */ |
| 722 typedef struct TLSExtensionDataStr TLSExtensionData; |
| 723 typedef struct SessionTicketDataStr SessionTicketData; |
| 724 |
| 725 struct TLSExtensionDataStr { |
| 726 /* registered callbacks that send server hello extensions */ |
| 727 ssl3HelloExtensionSender serverSenders[MAX_EXTENSIONS]; |
| 728 /* Keep track of the extensions that are negotiated. */ |
| 729 PRUint16 numAdvertised; |
| 730 PRUint16 numNegotiated; |
| 731 PRUint16 advertised[MAX_EXTENSIONS]; |
| 732 PRUint16 negotiated[MAX_EXTENSIONS]; |
| 733 |
| 734 /* SessionTicket Extension related data. */ |
| 735 PRBool ticketTimestampVerified; |
| 736 PRBool emptySessionTicket; |
| 737 }; |
| 738 |
| 739 /* |
| 740 ** This is the "hs" member of the "ssl3" struct. |
| 741 ** This entire struct is protected by ssl3HandshakeLock |
| 742 */ |
| 743 typedef struct SSL3HandshakeStateStr { |
| 744 SSL3Random server_random; |
| 745 SSL3Random client_random; |
| 746 SSL3WaitState ws; |
| 747 PRUint64 md5_cx[MAX_MAC_CONTEXT_LLONGS]; |
| 748 PRUint64 sha_cx[MAX_MAC_CONTEXT_LLONGS]; |
| 749 PK11Context * md5; /* handshake running hashes */ |
| 750 PK11Context * sha; |
| 751 const ssl3KEADef * kea_def; |
| 752 ssl3CipherSuite cipher_suite; |
| 753 const ssl3CipherSuiteDef *suite_def; |
| 754 SSLCompressionMethod compression; |
| 755 sslBuffer msg_body; /* protected by recvBufLock */ |
| 756 /* partial handshake message from record layer */ |
| 757 unsigned int header_bytes; |
| 758 /* number of bytes consumed from handshake */ |
| 759 /* message for message type and header length */ |
| 760 SSL3HandshakeType msg_type; |
| 761 unsigned long msg_len; |
| 762 SECItem ca_list; /* used only by client */ |
| 763 PRBool isResuming; /* are we resuming a session */ |
| 764 PRBool rehandshake; /* immediately start another handshake |
| 765 * when this one finishes */ |
| 766 PRBool usedStepDownKey; /* we did a server key exchange. */ |
| 767 sslBuffer msgState; /* current state for handshake messages*/ |
| 768 /* protected by recvBufLock */ |
| 769 sslBuffer messages; /* Accumulated handshake messages */ |
| 770 #ifdef NSS_ENABLE_ECC |
| 771 PRUint32 negotiatedECCurves; /* bit mask */ |
| 772 #endif /* NSS_ENABLE_ECC */ |
| 773 } SSL3HandshakeState; |
| 774 |
| 775 |
| 776 |
| 777 /* |
| 778 ** This is the "ssl3" struct, as in "ss->ssl3". |
| 779 ** note: |
| 780 ** usually, crSpec == cwSpec and prSpec == pwSpec. |
| 781 ** Sometimes, crSpec == pwSpec and prSpec == cwSpec. |
| 782 ** But there are never more than 2 actual specs. |
| 783 ** No spec must ever be modified if either "current" pointer points to it. |
| 784 */ |
| 785 struct ssl3StateStr { |
| 786 |
| 787 /* |
| 788 ** The following Specs and Spec pointers must be protected using the |
| 789 ** Spec Lock. |
| 790 */ |
| 791 ssl3CipherSpec * crSpec; /* current read spec. */ |
| 792 ssl3CipherSpec * prSpec; /* pending read spec. */ |
| 793 ssl3CipherSpec * cwSpec; /* current write spec. */ |
| 794 ssl3CipherSpec * pwSpec; /* pending write spec. */ |
| 795 |
| 796 CERTCertificate * clientCertificate; /* used by client */ |
| 797 SECKEYPrivateKey * clientPrivateKey; /* used by client */ |
| 798 CERTCertificateList *clientCertChain; /* used by client */ |
| 799 PRBool sendEmptyCert; /* used by client */ |
| 800 |
| 801 int policy; |
| 802 /* This says what cipher suites we can do, and should |
| 803 * be either SSL_ALLOWED or SSL_RESTRICTED |
| 804 */ |
| 805 PRArenaPool * peerCertArena; |
| 806 /* These are used to keep track of the peer CA */ |
| 807 void * peerCertChain; |
| 808 /* chain while we are trying to validate it. */ |
| 809 CERTDistNames * ca_list; |
| 810 /* used by server. trusted CAs for this socket. */ |
| 811 PRBool initialized; |
| 812 SSL3HandshakeState hs; |
| 813 ssl3CipherSpec specs[2]; /* one is current, one is pending. */ |
| 814 }; |
| 815 |
| 816 typedef struct { |
| 817 SSL3ContentType type; |
| 818 SSL3ProtocolVersion version; |
| 819 sslBuffer * buf; |
| 820 } SSL3Ciphertext; |
| 821 |
| 822 struct ssl3KeyPairStr { |
| 823 SECKEYPrivateKey * privKey; |
| 824 SECKEYPublicKey * pubKey; |
| 825 PRInt32 refCount; /* use PR_Atomic calls for this. */ |
| 826 }; |
| 827 |
| 828 typedef struct SSLWrappedSymWrappingKeyStr { |
| 829 SSL3Opaque wrappedSymmetricWrappingkey[512]; |
| 830 SSL3Opaque wrapIV[24]; |
| 831 CK_MECHANISM_TYPE symWrapMechanism; |
| 832 /* unwrapped symmetric wrapping key uses this mechanism */ |
| 833 CK_MECHANISM_TYPE asymWrapMechanism; |
| 834 /* mechanism used to wrap the SymmetricWrappingKey using |
| 835 * server's public and/or private keys. */ |
| 836 SSL3KEAType exchKeyType; /* type of keys used to wrap SymWrapKey*/ |
| 837 PRInt32 symWrapMechIndex; |
| 838 PRUint16 wrappedSymKeyLen; |
| 839 PRUint16 wrapIVLen; |
| 840 } SSLWrappedSymWrappingKey; |
| 841 |
| 842 typedef struct SessionTicketStr { |
| 843 uint16 ticket_version; |
| 844 SSL3ProtocolVersion ssl_version; |
| 845 ssl3CipherSuite cipher_suite; |
| 846 SSLCompressionMethod compression_method; |
| 847 SSLSignType authAlgorithm; |
| 848 uint32 authKeyBits; |
| 849 SSLKEAType keaType; |
| 850 uint32 keaKeyBits; |
| 851 /* |
| 852 * exchKeyType and msWrapMech contain meaningful values only if |
| 853 * ms_is_wrapped is true. |
| 854 */ |
| 855 uint8 ms_is_wrapped; |
| 856 SSLKEAType exchKeyType; /* XXX(wtc): same as keaType above? */ |
| 857 CK_MECHANISM_TYPE msWrapMech; |
| 858 uint16 ms_length; |
| 859 SSL3Opaque master_secret[48]; |
| 860 ClientIdentity client_identity; |
| 861 SECItem peer_cert; |
| 862 uint32 timestamp; |
| 863 } SessionTicket; |
| 864 |
| 865 /* |
| 866 * SSL2 buffers used in SSL3. |
| 867 * writeBuf in the SecurityInfo maintained by sslsecur.c is used |
| 868 * to hold the data just about to be passed to the kernel |
| 869 * sendBuf in the ConnectInfo maintained by sslcon.c is used |
| 870 * to hold handshake messages as they are accumulated |
| 871 */ |
| 872 |
| 873 /* |
| 874 ** This is "ci", as in "ss->sec.ci". |
| 875 ** |
| 876 ** Protection: All the variables in here are protected by |
| 877 ** firstHandshakeLock AND (in ssl3) ssl3HandshakeLock |
| 878 */ |
| 879 struct sslConnectInfoStr { |
| 880 /* outgoing handshakes appended to this. */ |
| 881 sslBuffer sendBuf; /*xmitBufLock*/ /* ssl 2 & 3 */ |
| 882 |
| 883 PRIPv6Addr peer; /* ssl 2 & 3 */ |
| 884 unsigned short port; /* ssl 2 & 3 */ |
| 885 |
| 886 sslSessionID *sid; /* ssl 2 & 3 */ |
| 887 |
| 888 /* see CIS_HAVE defines below for the bit values in *elements. */ |
| 889 char elements; /* ssl2 only */ |
| 890 char requiredElements; /* ssl2 only */ |
| 891 char sentElements; /* ssl2 only */ |
| 892 |
| 893 char sentFinished; /* ssl2 only */ |
| 894 |
| 895 /* Length of server challenge. Used by client when saving challenge */ |
| 896 int serverChallengeLen; /* ssl2 only */ |
| 897 /* type of authentication requested by server */ |
| 898 unsigned char authType; /* ssl2 only */ |
| 899 |
| 900 /* Challenge sent by client to server in client-hello message */ |
| 901 /* SSL3 gets a copy of this. See ssl3_StartHandshakeHash(). */ |
| 902 unsigned char clientChallenge[SSL_MAX_CHALLENGE_BYTES]; /* ssl 2 & 3 */ |
| 903 |
| 904 /* Connection-id sent by server to client in server-hello message */ |
| 905 unsigned char connectionID[SSL_CONNECTIONID_BYTES]; /* ssl2 only */ |
| 906 |
| 907 /* Challenge sent by server to client in request-certificate message */ |
| 908 unsigned char serverChallenge[SSL_MAX_CHALLENGE_BYTES]; /* ssl2 only */ |
| 909 |
| 910 /* Information kept to handle a request-certificate message */ |
| 911 unsigned char readKey[SSL_MAX_MASTER_KEY_BYTES]; /* ssl2 only */ |
| 912 unsigned char writeKey[SSL_MAX_MASTER_KEY_BYTES]; /* ssl2 only */ |
| 913 unsigned keySize; /* ssl2 only */ |
| 914 }; |
| 915 |
| 916 /* bit values for ci->elements, ci->requiredElements, sentElements. */ |
| 917 #define CIS_HAVE_MASTER_KEY 0x01 |
| 918 #define CIS_HAVE_CERTIFICATE 0x02 |
| 919 #define CIS_HAVE_FINISHED 0x04 |
| 920 #define CIS_HAVE_VERIFY 0x08 |
| 921 |
| 922 /* Note: The entire content of this struct and whatever it points to gets |
| 923 * blown away by SSL_ResetHandshake(). This is "sec" as in "ss->sec". |
| 924 * |
| 925 * Unless otherwise specified below, the contents of this struct are |
| 926 * protected by firstHandshakeLock AND (in ssl3) ssl3HandshakeLock. |
| 927 */ |
| 928 struct sslSecurityInfoStr { |
| 929 sslSendFunc send; /*xmitBufLock*/ /* ssl 2 & 3 */ |
| 930 int isServer; /* Spec Lock?*/ /* ssl 2 & 3 */ |
| 931 sslBuffer writeBuf; /*xmitBufLock*/ /* ssl 2 & 3 */ |
| 932 |
| 933 int cipherType; /* ssl 2 & 3 */ |
| 934 int keyBits; /* ssl 2 & 3 */ |
| 935 int secretKeyBits; /* ssl 2 & 3 */ |
| 936 CERTCertificate *localCert; /* ssl 2 & 3 */ |
| 937 CERTCertificate *peerCert; /* ssl 2 & 3 */ |
| 938 SECKEYPublicKey *peerKey; /* ssl3 only */ |
| 939 |
| 940 SSLSignType authAlgorithm; |
| 941 PRUint32 authKeyBits; |
| 942 SSLKEAType keaType; |
| 943 PRUint32 keaKeyBits; |
| 944 |
| 945 /* |
| 946 ** Procs used for SID cache (nonce) management. |
| 947 ** Different implementations exist for clients/servers |
| 948 ** The lookup proc is only used for servers. Baloney! |
| 949 */ |
| 950 sslSessionIDCacheFunc cache; /* ssl 2 & 3 */ |
| 951 sslSessionIDUncacheFunc uncache; /* ssl 2 & 3 */ |
| 952 |
| 953 /* |
| 954 ** everything below here is for ssl2 only. |
| 955 ** This stuff is equivalent to SSL3's "spec", and is protected by the |
| 956 ** same "Spec Lock" as used for SSL3's specs. |
| 957 */ |
| 958 PRUint32 sendSequence; /*xmitBufLock*/ /* ssl2 only */ |
| 959 PRUint32 rcvSequence; /*recvBufLock*/ /* ssl2 only */ |
| 960 |
| 961 /* Hash information; used for one-way-hash functions (MD2, MD5, etc.) */ |
| 962 const SECHashObject *hash; /* Spec Lock */ /* ssl2 only */ |
| 963 void *hashcx; /* Spec Lock */ /* ssl2 only */ |
| 964 |
| 965 SECItem sendSecret; /* Spec Lock */ /* ssl2 only */ |
| 966 SECItem rcvSecret; /* Spec Lock */ /* ssl2 only */ |
| 967 |
| 968 /* Session cypher contexts; one for each direction */ |
| 969 void *readcx; /* Spec Lock */ /* ssl2 only */ |
| 970 void *writecx; /* Spec Lock */ /* ssl2 only */ |
| 971 SSLCipher enc; /* Spec Lock */ /* ssl2 only */ |
| 972 SSLCipher dec; /* Spec Lock */ /* ssl2 only */ |
| 973 void (*destroy)(void *, PRBool); /* Spec Lock */ /* ssl2 only */ |
| 974 |
| 975 /* Blocking information for the session cypher */ |
| 976 int blockShift; /* Spec Lock */ /* ssl2 only */ |
| 977 int blockSize; /* Spec Lock */ /* ssl2 only */ |
| 978 |
| 979 /* These are used during a connection handshake */ |
| 980 sslConnectInfo ci; /* ssl 2 & 3 */ |
| 981 |
| 982 }; |
| 983 |
| 984 |
| 985 /* |
| 986 ** SSL Socket struct |
| 987 ** |
| 988 ** Protection: XXX |
| 989 */ |
| 990 struct sslSocketStr { |
| 991 PRFileDesc * fd; |
| 992 |
| 993 /* Pointer to operations vector for this socket */ |
| 994 const sslSocketOps * ops; |
| 995 |
| 996 /* SSL socket options */ |
| 997 sslOptions opt; |
| 998 |
| 999 /* State flags */ |
| 1000 unsigned long clientAuthRequested; |
| 1001 unsigned long delayDisabled; /* Nagle delay disabled */ |
| 1002 unsigned long firstHsDone; /* first handshake is complete. */ |
| 1003 unsigned long handshakeBegun; |
| 1004 unsigned long lastWriteBlocked; |
| 1005 unsigned long recvdCloseNotify; /* received SSL EOF. */ |
| 1006 unsigned long TCPconnected; |
| 1007 unsigned long appDataBuffered; |
| 1008 |
| 1009 /* version of the protocol to use */ |
| 1010 SSL3ProtocolVersion version; |
| 1011 SSL3ProtocolVersion clientHelloVersion; /* version sent in client hello. */ |
| 1012 |
| 1013 sslSecurityInfo sec; /* not a pointer any more */ |
| 1014 |
| 1015 /* protected by firstHandshakeLock AND (in ssl3) ssl3HandshakeLock. */ |
| 1016 const char *url; /* ssl 2 & 3 */ |
| 1017 |
| 1018 sslHandshakeFunc handshake; /*firstHandshakeLock*/ |
| 1019 sslHandshakeFunc nextHandshake; /*firstHandshakeLock*/ |
| 1020 sslHandshakeFunc securityHandshake; /*firstHandshakeLock*/ |
| 1021 |
| 1022 /* the following variable is only used with socks or other proxies. */ |
| 1023 char * peerID; /* String uniquely identifies target server. */ |
| 1024 |
| 1025 unsigned char * cipherSpecs; |
| 1026 unsigned int sizeCipherSpecs; |
| 1027 const unsigned char * preferredCipher; |
| 1028 |
| 1029 ssl3KeyPair * stepDownKeyPair; /* RSA step down keys */ |
| 1030 |
| 1031 /* Callbacks */ |
| 1032 SSLAuthCertificate authCertificate; |
| 1033 void *authCertificateArg; |
| 1034 SSLGetClientAuthData getClientAuthData; |
| 1035 void *getClientAuthDataArg; |
| 1036 SSLBadCertHandler handleBadCert; |
| 1037 void *badCertArg; |
| 1038 SSLHandshakeCallback handshakeCallback; |
| 1039 void *handshakeCallbackData; |
| 1040 void *pkcs11PinArg; |
| 1041 |
| 1042 PRIntervalTime rTimeout; /* timeout for NSPR I/O */ |
| 1043 PRIntervalTime wTimeout; /* timeout for NSPR I/O */ |
| 1044 PRIntervalTime cTimeout; /* timeout for NSPR I/O */ |
| 1045 |
| 1046 PZLock * recvLock; /* lock against multiple reader threads. */ |
| 1047 PZLock * sendLock; /* lock against multiple sender threads. */ |
| 1048 |
| 1049 PZMonitor * recvBufLock; /* locks low level recv buffers. */ |
| 1050 PZMonitor * xmitBufLock; /* locks low level xmit buffers. */ |
| 1051 |
| 1052 /* Only one thread may operate on the socket until the initial handshake |
| 1053 ** is complete. This Monitor ensures that. Since SSL2 handshake is |
| 1054 ** only done once, this is also effectively the SSL2 handshake lock. |
| 1055 */ |
| 1056 PZMonitor * firstHandshakeLock; |
| 1057 |
| 1058 /* This monitor protects the ssl3 handshake state machine data. |
| 1059 ** Only one thread (reader or writer) may be in the ssl3 handshake state |
| 1060 ** machine at any time. */ |
| 1061 PZMonitor * ssl3HandshakeLock; |
| 1062 |
| 1063 /* reader/writer lock, protects the secret data needed to encrypt and MAC |
| 1064 ** outgoing records, and to decrypt and MAC check incoming ciphertext |
| 1065 ** records. */ |
| 1066 NSSRWLock * specLock; |
| 1067 |
| 1068 /* handle to perm cert db (and implicitly to the temp cert db) used |
| 1069 ** with this socket. |
| 1070 */ |
| 1071 CERTCertDBHandle * dbHandle; |
| 1072 |
| 1073 PRThread * writerThread; /* thread holds SSL_LOCK_WRITER lock */ |
| 1074 |
| 1075 PRUint16 shutdownHow; /* See ssl_SHUTDOWN defines below. */ |
| 1076 |
| 1077 PRUint16 allowedByPolicy; /* copy of global policy bits. */ |
| 1078 PRUint16 maybeAllowedByPolicy; /* copy of global policy bits. */ |
| 1079 PRUint16 chosenPreference; /* SSL2 cipher preferences. */ |
| 1080 |
| 1081 sslHandshakingType handshaking; |
| 1082 |
| 1083 /* Gather object used for gathering data */ |
| 1084 sslGather gs; /*recvBufLock*/ |
| 1085 |
| 1086 sslBuffer saveBuf; /*xmitBufLock*/ |
| 1087 sslBuffer pendingBuf; /*xmitBufLock*/ |
| 1088 |
| 1089 /* Configuration state for server sockets */ |
| 1090 /* server cert and key for each KEA type */ |
| 1091 sslServerCerts serverCerts[kt_kea_size]; |
| 1092 |
| 1093 ssl3CipherSuiteCfg cipherSuites[ssl_V3_SUITES_IMPLEMENTED]; |
| 1094 ssl3KeyPair * ephemeralECDHKeyPair; /* for ECDHE-* handshake */ |
| 1095 |
| 1096 /* SSL3 state info. Formerly was a pointer */ |
| 1097 ssl3State ssl3; |
| 1098 |
| 1099 /* |
| 1100 * TLS extension related data. |
| 1101 */ |
| 1102 /* True when the current session is a stateless resume. */ |
| 1103 PRBool statelessResume; |
| 1104 TLSExtensionData xtnData; |
| 1105 }; |
| 1106 |
| 1107 |
| 1108 |
| 1109 /* All the global data items declared here should be protected using the |
| 1110 ** ssl_global_data_lock, which is a reader/writer lock. |
| 1111 */ |
| 1112 extern NSSRWLock * ssl_global_data_lock; |
| 1113 extern char ssl_debug; |
| 1114 extern char ssl_trace; |
| 1115 extern FILE * ssl_trace_iob; |
| 1116 extern CERTDistNames * ssl3_server_ca_list; |
| 1117 extern PRUint32 ssl_sid_timeout; |
| 1118 extern PRUint32 ssl3_sid_timeout; |
| 1119 extern PRBool ssl3_global_policy_some_restricted; |
| 1120 |
| 1121 extern const char * const ssl_cipherName[]; |
| 1122 extern const char * const ssl3_cipherName[]; |
| 1123 |
| 1124 extern sslSessionIDLookupFunc ssl_sid_lookup; |
| 1125 extern sslSessionIDCacheFunc ssl_sid_cache; |
| 1126 extern sslSessionIDUncacheFunc ssl_sid_uncache; |
| 1127 |
| 1128 /************************************************************************/ |
| 1129 |
| 1130 SEC_BEGIN_PROTOS |
| 1131 |
| 1132 /* Implementation of ops for default (non socks, non secure) case */ |
| 1133 extern int ssl_DefConnect(sslSocket *ss, const PRNetAddr *addr); |
| 1134 extern PRFileDesc *ssl_DefAccept(sslSocket *ss, PRNetAddr *addr); |
| 1135 extern int ssl_DefBind(sslSocket *ss, const PRNetAddr *addr); |
| 1136 extern int ssl_DefListen(sslSocket *ss, int backlog); |
| 1137 extern int ssl_DefShutdown(sslSocket *ss, int how); |
| 1138 extern int ssl_DefClose(sslSocket *ss); |
| 1139 extern int ssl_DefRecv(sslSocket *ss, unsigned char *buf, int len, int flags); |
| 1140 extern int ssl_DefSend(sslSocket *ss, const unsigned char *buf, |
| 1141 int len, int flags); |
| 1142 extern int ssl_DefRead(sslSocket *ss, unsigned char *buf, int len); |
| 1143 extern int ssl_DefWrite(sslSocket *ss, const unsigned char *buf, int len); |
| 1144 extern int ssl_DefGetpeername(sslSocket *ss, PRNetAddr *name); |
| 1145 extern int ssl_DefGetsockname(sslSocket *ss, PRNetAddr *name); |
| 1146 extern int ssl_DefGetsockopt(sslSocket *ss, PRSockOption optname, |
| 1147 void *optval, PRInt32 *optlen); |
| 1148 extern int ssl_DefSetsockopt(sslSocket *ss, PRSockOption optname, |
| 1149 const void *optval, PRInt32 optlen); |
| 1150 |
| 1151 /* Implementation of ops for socks only case */ |
| 1152 extern int ssl_SocksConnect(sslSocket *ss, const PRNetAddr *addr); |
| 1153 extern PRFileDesc *ssl_SocksAccept(sslSocket *ss, PRNetAddr *addr); |
| 1154 extern int ssl_SocksBind(sslSocket *ss, const PRNetAddr *addr); |
| 1155 extern int ssl_SocksListen(sslSocket *ss, int backlog); |
| 1156 extern int ssl_SocksGetsockname(sslSocket *ss, PRNetAddr *name); |
| 1157 extern int ssl_SocksRecv(sslSocket *ss, unsigned char *buf, int len, int flags); |
| 1158 extern int ssl_SocksSend(sslSocket *ss, const unsigned char *buf, |
| 1159 int len, int flags); |
| 1160 extern int ssl_SocksRead(sslSocket *ss, unsigned char *buf, int len); |
| 1161 extern int ssl_SocksWrite(sslSocket *ss, const unsigned char *buf, int len); |
| 1162 |
| 1163 /* Implementation of ops for secure only case */ |
| 1164 extern int ssl_SecureConnect(sslSocket *ss, const PRNetAddr *addr); |
| 1165 extern PRFileDesc *ssl_SecureAccept(sslSocket *ss, PRNetAddr *addr); |
| 1166 extern int ssl_SecureRecv(sslSocket *ss, unsigned char *buf, |
| 1167 int len, int flags); |
| 1168 extern int ssl_SecureSend(sslSocket *ss, const unsigned char *buf, |
| 1169 int len, int flags); |
| 1170 extern int ssl_SecureRead(sslSocket *ss, unsigned char *buf, int len); |
| 1171 extern int ssl_SecureWrite(sslSocket *ss, const unsigned char *buf, int len); |
| 1172 extern int ssl_SecureShutdown(sslSocket *ss, int how); |
| 1173 extern int ssl_SecureClose(sslSocket *ss); |
| 1174 |
| 1175 /* Implementation of ops for secure socks case */ |
| 1176 extern int ssl_SecureSocksConnect(sslSocket *ss, const PRNetAddr *addr); |
| 1177 extern PRFileDesc *ssl_SecureSocksAccept(sslSocket *ss, PRNetAddr *addr); |
| 1178 extern PRFileDesc *ssl_FindTop(sslSocket *ss); |
| 1179 |
| 1180 /* Gather funcs. */ |
| 1181 extern sslGather * ssl_NewGather(void); |
| 1182 extern SECStatus ssl_InitGather(sslGather *gs); |
| 1183 extern void ssl_DestroyGather(sslGather *gs); |
| 1184 extern int ssl2_GatherData(sslSocket *ss, sslGather *gs, int flags); |
| 1185 extern int ssl2_GatherRecord(sslSocket *ss, int flags); |
| 1186 extern SECStatus ssl_GatherRecord1stHandshake(sslSocket *ss); |
| 1187 |
| 1188 extern SECStatus ssl2_HandleClientHelloMessage(sslSocket *ss); |
| 1189 extern SECStatus ssl2_HandleServerHelloMessage(sslSocket *ss); |
| 1190 extern int ssl2_StartGatherBytes(sslSocket *ss, sslGather *gs, |
| 1191 unsigned int count); |
| 1192 |
| 1193 extern SECStatus ssl_CreateSecurityInfo(sslSocket *ss); |
| 1194 extern SECStatus ssl_CopySecurityInfo(sslSocket *ss, sslSocket *os); |
| 1195 extern void ssl_ResetSecurityInfo(sslSecurityInfo *sec, PRBool doMemset); |
| 1196 extern void ssl_DestroySecurityInfo(sslSecurityInfo *sec); |
| 1197 |
| 1198 extern sslSocket * ssl_DupSocket(sslSocket *old); |
| 1199 |
| 1200 extern void ssl_PrintBuf(sslSocket *ss, const char *msg, const void *cp,
int len); |
| 1201 extern void ssl_DumpMsg(sslSocket *ss, unsigned char *bp, unsigned len); |
| 1202 |
| 1203 extern int ssl_SendSavedWriteData(sslSocket *ss); |
| 1204 extern SECStatus ssl_SaveWriteData(sslSocket *ss, |
| 1205 const void* p, unsigned int l); |
| 1206 extern SECStatus ssl2_BeginClientHandshake(sslSocket *ss); |
| 1207 extern SECStatus ssl2_BeginServerHandshake(sslSocket *ss); |
| 1208 extern int ssl_Do1stHandshake(sslSocket *ss); |
| 1209 |
| 1210 extern SECStatus sslBuffer_Grow(sslBuffer *b, unsigned int newLen); |
| 1211 extern SECStatus sslBuffer_Append(sslBuffer *b, const void * data, |
| 1212 unsigned int len); |
| 1213 |
| 1214 extern void ssl2_UseClearSendFunc(sslSocket *ss); |
| 1215 extern void ssl_ChooseSessionIDProcs(sslSecurityInfo *sec); |
| 1216 |
| 1217 extern sslSessionID *ssl3_NewSessionID(sslSocket *ss, PRBool is_server); |
| 1218 extern sslSessionID *ssl_LookupSID(const PRIPv6Addr *addr, PRUint16 port, |
| 1219 const char *peerID, const char *urlSvrName); |
| 1220 extern void ssl_FreeSID(sslSessionID *sid); |
| 1221 |
| 1222 extern int ssl3_SendApplicationData(sslSocket *ss, const PRUint8 *in, |
| 1223 int len, int flags); |
| 1224 |
| 1225 extern PRBool ssl_FdIsBlocking(PRFileDesc *fd); |
| 1226 |
| 1227 extern PRBool ssl_SocketIsBlocking(sslSocket *ss); |
| 1228 |
| 1229 extern void ssl_SetAlwaysBlock(sslSocket *ss); |
| 1230 |
| 1231 extern SECStatus ssl_EnableNagleDelay(sslSocket *ss, PRBool enabled); |
| 1232 |
| 1233 #define SSL_LOCK_READER(ss) if (ss->recvLock) PZ_Lock(ss->recvLock) |
| 1234 #define SSL_UNLOCK_READER(ss) if (ss->recvLock) PZ_Unlock(ss->recvLock
) |
| 1235 #define SSL_LOCK_WRITER(ss) if (ss->sendLock) PZ_Lock(ss->sendLock) |
| 1236 #define SSL_UNLOCK_WRITER(ss) if (ss->sendLock) PZ_Unlock(ss->sendLock
) |
| 1237 |
| 1238 #define ssl_Get1stHandshakeLock(ss) \ |
| 1239 { if (!ss->opt.noLocks) PZ_EnterMonitor((ss)->firstHandshakeLock); } |
| 1240 #define ssl_Release1stHandshakeLock(ss) \ |
| 1241 { if (!ss->opt.noLocks) PZ_ExitMonitor((ss)->firstHandshakeLock); } |
| 1242 #define ssl_Have1stHandshakeLock(ss) \ |
| 1243 (PZ_InMonitor((ss)->firstHandshakeLock)) |
| 1244 |
| 1245 #define ssl_GetSSL3HandshakeLock(ss) \ |
| 1246 { if (!ss->opt.noLocks) PZ_EnterMonitor((ss)->ssl3HandshakeLock); } |
| 1247 #define ssl_ReleaseSSL3HandshakeLock(ss) \ |
| 1248 { if (!ss->opt.noLocks) PZ_ExitMonitor((ss)->ssl3HandshakeLock); } |
| 1249 #define ssl_HaveSSL3HandshakeLock(ss) \ |
| 1250 (PZ_InMonitor((ss)->ssl3HandshakeLock)) |
| 1251 |
| 1252 #define ssl_GetSpecReadLock(ss) \ |
| 1253 { if (!ss->opt.noLocks) NSSRWLock_LockRead((ss)->specLock); } |
| 1254 #define ssl_ReleaseSpecReadLock(ss) \ |
| 1255 { if (!ss->opt.noLocks) NSSRWLock_UnlockRead((ss)->specLock); } |
| 1256 |
| 1257 #define ssl_GetSpecWriteLock(ss) \ |
| 1258 { if (!ss->opt.noLocks) NSSRWLock_LockWrite((ss)->specLock); } |
| 1259 #define ssl_ReleaseSpecWriteLock(ss) \ |
| 1260 { if (!ss->opt.noLocks) NSSRWLock_UnlockWrite((ss)->specLock); } |
| 1261 #define ssl_HaveSpecWriteLock(ss) \ |
| 1262 (NSSRWLock_HaveWriteLock((ss)->specLock)) |
| 1263 |
| 1264 #define ssl_GetRecvBufLock(ss) \ |
| 1265 { if (!ss->opt.noLocks) PZ_EnterMonitor((ss)->recvBufLock); } |
| 1266 #define ssl_ReleaseRecvBufLock(ss) \ |
| 1267 { if (!ss->opt.noLocks) PZ_ExitMonitor( (ss)->recvBufLock); } |
| 1268 #define ssl_HaveRecvBufLock(ss) \ |
| 1269 (PZ_InMonitor((ss)->recvBufLock)) |
| 1270 |
| 1271 #define ssl_GetXmitBufLock(ss) \ |
| 1272 { if (!ss->opt.noLocks) PZ_EnterMonitor((ss)->xmitBufLock); } |
| 1273 #define ssl_ReleaseXmitBufLock(ss) \ |
| 1274 { if (!ss->opt.noLocks) PZ_ExitMonitor( (ss)->xmitBufLock); } |
| 1275 #define ssl_HaveXmitBufLock(ss) \ |
| 1276 (PZ_InMonitor((ss)->xmitBufLock)) |
| 1277 |
| 1278 |
| 1279 extern SECStatus ssl3_KeyAndMacDeriveBypass(ssl3CipherSpec * pwSpec, |
| 1280 const unsigned char * cr, const unsigned char * sr, |
| 1281 PRBool isTLS, PRBool isExport); |
| 1282 extern SECStatus ssl3_MasterKeyDeriveBypass( ssl3CipherSpec * pwSpec, |
| 1283 const unsigned char * cr, const unsigned char * sr, |
| 1284 const SECItem * pms, PRBool isTLS, PRBool isRSA); |
| 1285 |
| 1286 /* These functions are called from secnav, even though they're "private". */ |
| 1287 |
| 1288 extern int ssl2_SendErrorMessage(struct sslSocketStr *ss, int error); |
| 1289 extern int SSL_RestartHandshakeAfterServerCert(struct sslSocketStr *ss); |
| 1290 extern int SSL_RestartHandshakeAfterCertReq(struct sslSocketStr *ss, |
| 1291 CERTCertificate *cert, |
| 1292 SECKEYPrivateKey *key, |
| 1293 CERTCertificateList *certChain); |
| 1294 extern sslSocket *ssl_FindSocket(PRFileDesc *fd); |
| 1295 extern void ssl_FreeSocket(struct sslSocketStr *ssl); |
| 1296 extern SECStatus SSL3_SendAlert(sslSocket *ss, SSL3AlertLevel level, |
| 1297 SSL3AlertDescription desc); |
| 1298 |
| 1299 extern int ssl2_RestartHandshakeAfterCertReq(sslSocket * ss, |
| 1300 CERTCertificate * cert, |
| 1301 SECKEYPrivateKey * key); |
| 1302 |
| 1303 extern SECStatus ssl3_RestartHandshakeAfterCertReq(sslSocket * ss, |
| 1304 CERTCertificate * cert, |
| 1305 SECKEYPrivateKey * key, |
| 1306 CERTCertificateList *certChain); |
| 1307 |
| 1308 extern int ssl2_RestartHandshakeAfterServerCert(sslSocket *ss); |
| 1309 extern int ssl3_RestartHandshakeAfterServerCert(sslSocket *ss); |
| 1310 |
| 1311 /* |
| 1312 * for dealing with SSL 3.0 clients sending SSL 2.0 format hellos |
| 1313 */ |
| 1314 extern SECStatus ssl3_HandleV2ClientHello( |
| 1315 sslSocket *ss, unsigned char *buffer, int length); |
| 1316 extern SECStatus ssl3_StartHandshakeHash( |
| 1317 sslSocket *ss, unsigned char *buf, int length); |
| 1318 |
| 1319 /* |
| 1320 * SSL3 specific routines |
| 1321 */ |
| 1322 SECStatus ssl3_SendClientHello(sslSocket *ss); |
| 1323 |
| 1324 /* |
| 1325 * input into the SSL3 machinery from the actualy network reading code |
| 1326 */ |
| 1327 SECStatus ssl3_HandleRecord( |
| 1328 sslSocket *ss, SSL3Ciphertext *cipher, sslBuffer *out); |
| 1329 |
| 1330 int ssl3_GatherAppDataRecord(sslSocket *ss, int flags); |
| 1331 int ssl3_GatherCompleteHandshake(sslSocket *ss, int flags); |
| 1332 /* |
| 1333 * When talking to export clients or using export cipher suites, servers |
| 1334 * with public RSA keys larger than 512 bits need to use a 512-bit public |
| 1335 * key, signed by the larger key. The smaller key is a "step down" key. |
| 1336 * Generate that key pair and keep it around. |
| 1337 */ |
| 1338 extern SECStatus ssl3_CreateRSAStepDownKeys(sslSocket *ss); |
| 1339 |
| 1340 #ifdef NSS_ENABLE_ECC |
| 1341 extern void ssl3_FilterECCipherSuitesByServerCerts(sslSocket *ss); |
| 1342 extern PRBool ssl3_IsECCEnabled(sslSocket *ss); |
| 1343 extern SECStatus ssl3_DisableECCSuites(sslSocket * ss, |
| 1344 const ssl3CipherSuite * suite); |
| 1345 |
| 1346 /* Macro for finding a curve equivalent in strength to RSA key's */ |
| 1347 #define SSL_RSASTRENGTH_TO_ECSTRENGTH(s) \ |
| 1348 ((s <= 1024) ? 160 \ |
| 1349 : ((s <= 2048) ? 224 \ |
| 1350 : ((s <= 3072) ? 256 \ |
| 1351 : ((s <= 7168) ? 384 : 521 ) ) ) ) |
| 1352 |
| 1353 /* Types and names of elliptic curves used in TLS */ |
| 1354 typedef enum { ec_type_explicitPrime = 1, |
| 1355 ec_type_explicitChar2Curve = 2, |
| 1356 ec_type_named |
| 1357 } ECType; |
| 1358 |
| 1359 typedef enum { ec_noName = 0, |
| 1360 ec_sect163k1 = 1, |
| 1361 ec_sect163r1 = 2, |
| 1362 ec_sect163r2 = 3, |
| 1363 ec_sect193r1 = 4, |
| 1364 ec_sect193r2 = 5, |
| 1365 ec_sect233k1 = 6, |
| 1366 ec_sect233r1 = 7, |
| 1367 ec_sect239k1 = 8, |
| 1368 ec_sect283k1 = 9, |
| 1369 ec_sect283r1 = 10, |
| 1370 ec_sect409k1 = 11, |
| 1371 ec_sect409r1 = 12, |
| 1372 ec_sect571k1 = 13, |
| 1373 ec_sect571r1 = 14, |
| 1374 ec_secp160k1 = 15, |
| 1375 ec_secp160r1 = 16, |
| 1376 ec_secp160r2 = 17, |
| 1377 ec_secp192k1 = 18, |
| 1378 ec_secp192r1 = 19, |
| 1379 ec_secp224k1 = 20, |
| 1380 ec_secp224r1 = 21, |
| 1381 ec_secp256k1 = 22, |
| 1382 ec_secp256r1 = 23, |
| 1383 ec_secp384r1 = 24, |
| 1384 ec_secp521r1 = 25, |
| 1385 ec_pastLastName |
| 1386 } ECName; |
| 1387 |
| 1388 extern SECStatus ssl3_ECName2Params(PRArenaPool *arena, ECName curve, |
| 1389 SECKEYECParams *params); |
| 1390 ECName ssl3_GetCurveWithECKeyStrength(PRUint32 curvemsk, int requiredECCbits); |
| 1391 |
| 1392 |
| 1393 #endif /* NSS_ENABLE_ECC */ |
| 1394 |
| 1395 extern SECStatus ssl3_CipherPrefSetDefault(ssl3CipherSuite which, PRBool on); |
| 1396 extern SECStatus ssl3_CipherPrefGetDefault(ssl3CipherSuite which, PRBool *on); |
| 1397 extern SECStatus ssl2_CipherPrefSetDefault(PRInt32 which, PRBool enabled); |
| 1398 extern SECStatus ssl2_CipherPrefGetDefault(PRInt32 which, PRBool *enabled); |
| 1399 |
| 1400 extern SECStatus ssl3_CipherPrefSet(sslSocket *ss, ssl3CipherSuite which, PRBool
on); |
| 1401 extern SECStatus ssl3_CipherPrefGet(sslSocket *ss, ssl3CipherSuite which, PRBool
*on); |
| 1402 extern SECStatus ssl2_CipherPrefSet(sslSocket *ss, PRInt32 which, PRBool enabled
); |
| 1403 extern SECStatus ssl2_CipherPrefGet(sslSocket *ss, PRInt32 which, PRBool *enable
d); |
| 1404 |
| 1405 extern SECStatus ssl3_SetPolicy(ssl3CipherSuite which, PRInt32 policy); |
| 1406 extern SECStatus ssl3_GetPolicy(ssl3CipherSuite which, PRInt32 *policy); |
| 1407 extern SECStatus ssl2_SetPolicy(PRInt32 which, PRInt32 policy); |
| 1408 extern SECStatus ssl2_GetPolicy(PRInt32 which, PRInt32 *policy); |
| 1409 |
| 1410 extern void ssl2_InitSocketPolicy(sslSocket *ss); |
| 1411 extern void ssl3_InitSocketPolicy(sslSocket *ss); |
| 1412 |
| 1413 extern SECStatus ssl3_ConstructV2CipherSpecsHack(sslSocket *ss, |
| 1414 unsigned char *cs, int *size); |
| 1415 |
| 1416 extern SECStatus ssl3_RedoHandshake(sslSocket *ss, PRBool flushCache); |
| 1417 |
| 1418 extern void ssl3_DestroySSL3Info(sslSocket *ss); |
| 1419 |
| 1420 extern SECStatus ssl3_NegotiateVersion(sslSocket *ss, |
| 1421 SSL3ProtocolVersion peerVersion); |
| 1422 |
| 1423 extern SECStatus ssl_GetPeerInfo(sslSocket *ss); |
| 1424 |
| 1425 #ifdef NSS_ENABLE_ECC |
| 1426 /* ECDH functions */ |
| 1427 extern SECStatus ssl3_SendECDHClientKeyExchange(sslSocket * ss, |
| 1428 SECKEYPublicKey * svrPubKey); |
| 1429 extern SECStatus ssl3_HandleECDHServerKeyExchange(sslSocket *ss, |
| 1430 SSL3Opaque *b, PRUint32 length); |
| 1431 extern SECStatus ssl3_HandleECDHClientKeyExchange(sslSocket *ss, |
| 1432 SSL3Opaque *b, PRUint32 length, |
| 1433 SECKEYPublicKey *srvrPubKey, |
| 1434 SECKEYPrivateKey *srvrPrivKey); |
| 1435 extern SECStatus ssl3_SendECDHServerKeyExchange(sslSocket *ss); |
| 1436 #endif |
| 1437 |
| 1438 extern SECStatus ssl3_ComputeCommonKeyHash(PRUint8 * hashBuf, |
| 1439 unsigned int bufLen, SSL3Hashes *hashes, |
| 1440 PRBool bypassPKCS11); |
| 1441 extern SECStatus ssl3_InitPendingCipherSpec(sslSocket *ss, PK11SymKey *pms); |
| 1442 extern SECStatus ssl3_AppendHandshake(sslSocket *ss, const void *void_src, |
| 1443 PRInt32 bytes); |
| 1444 extern SECStatus ssl3_AppendHandshakeHeader(sslSocket *ss, |
| 1445 SSL3HandshakeType t, PRUint32 length); |
| 1446 extern SECStatus ssl3_AppendHandshakeNumber(sslSocket *ss, PRInt32 num, |
| 1447 PRInt32 lenSize); |
| 1448 extern SECStatus ssl3_AppendHandshakeVariable( sslSocket *ss, |
| 1449 const SSL3Opaque *src, PRInt32 bytes, PRInt32 lenSize); |
| 1450 extern SECStatus ssl3_ConsumeHandshake(sslSocket *ss, void *v, PRInt32 bytes, |
| 1451 SSL3Opaque **b, PRUint32 *length); |
| 1452 extern PRInt32 ssl3_ConsumeHandshakeNumber(sslSocket *ss, PRInt32 bytes, |
| 1453 SSL3Opaque **b, PRUint32 *length); |
| 1454 extern SECStatus ssl3_ConsumeHandshakeVariable(sslSocket *ss, SECItem *i, |
| 1455 PRInt32 bytes, SSL3Opaque **b, PRUint32 *length); |
| 1456 extern SECStatus ssl3_SignHashes(SSL3Hashes *hash, SECKEYPrivateKey *key, |
| 1457 SECItem *buf, PRBool isTLS); |
| 1458 extern SECStatus ssl3_VerifySignedHashes(SSL3Hashes *hash, |
| 1459 CERTCertificate *cert, SECItem *buf, PRBool isTLS, |
| 1460 void *pwArg); |
| 1461 extern SECStatus ssl3_CacheWrappedMasterSecret(sslSocket *ss, |
| 1462 sslSessionID *sid, ssl3CipherSpec *spec, |
| 1463 SSL3KEAType effectiveExchKeyType); |
| 1464 |
| 1465 /* Functions that handle ClientHello and ServerHello extensions. */ |
| 1466 extern SECStatus ssl3_HandleServerNameXtn(sslSocket * ss, |
| 1467 PRUint16 ex_type, SECItem *data); |
| 1468 extern SECStatus ssl3_HandleSupportedCurvesXtn(sslSocket * ss, |
| 1469 PRUint16 ex_type, SECItem *data); |
| 1470 extern SECStatus ssl3_HandleSupportedPointFormatsXtn(sslSocket * ss, |
| 1471 PRUint16 ex_type, SECItem *data); |
| 1472 extern SECStatus ssl3_ClientHandleSessionTicketXtn(sslSocket *ss, |
| 1473 PRUint16 ex_type, SECItem *data); |
| 1474 extern SECStatus ssl3_ServerHandleSessionTicketXtn(sslSocket *ss, |
| 1475 PRUint16 ex_type, SECItem *data); |
| 1476 |
| 1477 /* ClientHello and ServerHello extension senders. |
| 1478 * Note that not all extension senders are exposed here; only those that |
| 1479 * that need exposure. |
| 1480 */ |
| 1481 extern PRInt32 ssl3_SendSessionTicketXtn(sslSocket *ss, PRBool append, |
| 1482 PRUint32 maxBytes); |
| 1483 #ifdef NSS_ENABLE_ECC |
| 1484 extern PRInt32 ssl3_SendSupportedCurvesXtn(sslSocket *ss, |
| 1485 PRBool append, PRUint32 maxBytes); |
| 1486 extern PRInt32 ssl3_SendSupportedPointFormatsXtn(sslSocket *ss, |
| 1487 PRBool append, PRUint32 maxBytes); |
| 1488 #endif |
| 1489 |
| 1490 /* call the registered extension handlers. */ |
| 1491 extern SECStatus ssl3_HandleHelloExtensions(sslSocket *ss, |
| 1492 SSL3Opaque **b, PRUint32 *length); |
| 1493 |
| 1494 /* Hello Extension related routines. */ |
| 1495 extern PRBool ssl3_ExtensionNegotiated(sslSocket *ss, PRUint16 ex_type); |
| 1496 extern SECStatus ssl3_SetSIDSessionTicket(sslSessionID *sid, |
| 1497 NewSessionTicket *session_ticket); |
| 1498 extern SECStatus ssl3_SendNewSessionTicket(sslSocket *ss); |
| 1499 extern PRBool ssl_GetSessionTicketKeys(unsigned char *keyName, |
| 1500 unsigned char *encKey, unsigned char *macKey); |
| 1501 extern PRBool ssl_GetSessionTicketKeysPKCS11(SECKEYPrivateKey *svrPrivKey, |
| 1502 SECKEYPublicKey *svrPubKey, void *pwArg, |
| 1503 unsigned char *keyName, PK11SymKey **aesKey, |
| 1504 PK11SymKey **macKey); |
| 1505 |
| 1506 /* Tell clients to consider tickets valid for this long. */ |
| 1507 #define TLS_EX_SESS_TICKET_LIFETIME_HINT (2 * 24 * 60 * 60) /* 2 days */ |
| 1508 #define TLS_EX_SESS_TICKET_VERSION (0x0100) |
| 1509 |
| 1510 /* Construct a new NSPR socket for the app to use */ |
| 1511 extern PRFileDesc *ssl_NewPRSocket(sslSocket *ss, PRFileDesc *fd); |
| 1512 extern void ssl_FreePRSocket(PRFileDesc *fd); |
| 1513 |
| 1514 /* Internal config function so SSL2 can initialize the present state of |
| 1515 * various ciphers */ |
| 1516 extern int ssl3_config_match_init(sslSocket *); |
| 1517 |
| 1518 |
| 1519 /* Create a new ref counted key pair object from two keys. */ |
| 1520 extern ssl3KeyPair * ssl3_NewKeyPair( SECKEYPrivateKey * privKey, |
| 1521 SECKEYPublicKey * pubKey); |
| 1522 |
| 1523 /* get a new reference (bump ref count) to an ssl3KeyPair. */ |
| 1524 extern ssl3KeyPair * ssl3_GetKeyPairRef(ssl3KeyPair * keyPair); |
| 1525 |
| 1526 /* Decrement keypair's ref count and free if zero. */ |
| 1527 extern void ssl3_FreeKeyPair(ssl3KeyPair * keyPair); |
| 1528 |
| 1529 /* calls for accessing wrapping keys across processes. */ |
| 1530 extern PRBool |
| 1531 ssl_GetWrappingKey( PRInt32 symWrapMechIndex, |
| 1532 SSL3KEAType exchKeyType, |
| 1533 SSLWrappedSymWrappingKey *wswk); |
| 1534 |
| 1535 /* The caller passes in the new value it wants |
| 1536 * to set. This code tests the wrapped sym key entry in the file on disk. |
| 1537 * If it is uninitialized, this function writes the caller's value into |
| 1538 * the disk entry, and returns false. |
| 1539 * Otherwise, it overwrites the caller's wswk with the value obtained from |
| 1540 * the disk, and returns PR_TRUE. |
| 1541 * This is all done while holding the locks/semaphores necessary to make |
| 1542 * the operation atomic. |
| 1543 */ |
| 1544 extern PRBool |
| 1545 ssl_SetWrappingKey(SSLWrappedSymWrappingKey *wswk); |
| 1546 |
| 1547 /* get rid of the symmetric wrapping key references. */ |
| 1548 extern SECStatus SSL3_ShutdownServerCache(void); |
| 1549 |
| 1550 extern SECStatus ssl_InitSymWrapKeysLock(void); |
| 1551 |
| 1552 extern SECStatus ssl_FreeSymWrapKeysLock(void); |
| 1553 |
| 1554 extern SECStatus ssl_InitSessionCacheLocks(PRBool lazyInit); |
| 1555 |
| 1556 extern SECStatus ssl_FreeSessionCacheLocks(void); |
| 1557 |
| 1558 |
| 1559 /********************** misc calls *********************/ |
| 1560 |
| 1561 extern int ssl_MapLowLevelError(int hiLevelError); |
| 1562 |
| 1563 extern PRUint32 ssl_Time(void); |
| 1564 |
| 1565 extern void SSL_AtomicIncrementLong(long * x); |
| 1566 |
| 1567 SECStatus SSL_DisableDefaultExportCipherSuites(void); |
| 1568 SECStatus SSL_DisableExportCipherSuites(PRFileDesc * fd); |
| 1569 PRBool SSL_IsExportCipherSuite(PRUint16 cipherSuite); |
| 1570 |
| 1571 |
| 1572 #ifdef TRACE |
| 1573 #define SSL_TRACE(msg) ssl_Trace msg |
| 1574 #else |
| 1575 #define SSL_TRACE(msg) |
| 1576 #endif |
| 1577 |
| 1578 void ssl_Trace(const char *format, ...); |
| 1579 |
| 1580 SEC_END_PROTOS |
| 1581 |
| 1582 #if defined(XP_UNIX) || defined(XP_OS2) || defined(XP_BEOS) |
| 1583 #define SSL_GETPID getpid |
| 1584 #elif defined(_WIN32_WCE) |
| 1585 #define SSL_GETPID GetCurrentProcessId |
| 1586 #elif defined(WIN32) |
| 1587 extern int __cdecl _getpid(void); |
| 1588 #define SSL_GETPID _getpid |
| 1589 #else |
| 1590 #define SSL_GETPID() 0 |
| 1591 #endif |
| 1592 |
| 1593 #endif /* __sslimpl_h_ */ |
OLD | NEW |