security/nss/lib/ssl/sslimpl.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /*
michael@0 2 * This file is PRIVATE to SSL and should be the first thing included by
michael@0 3 * any SSL implementation file.
michael@0 4 *
michael@0 5 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 6 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 8
michael@0 9 #ifndef __sslimpl_h_
michael@0 10 #define __sslimpl_h_
michael@0 11
michael@0 12 #ifdef DEBUG
michael@0 13 #undef NDEBUG
michael@0 14 #else
michael@0 15 #undef NDEBUG
michael@0 16 #define NDEBUG
michael@0 17 #endif
michael@0 18 #include "secport.h"
michael@0 19 #include "secerr.h"
michael@0 20 #include "sslerr.h"
michael@0 21 #include "ssl3prot.h"
michael@0 22 #include "hasht.h"
michael@0 23 #include "nssilock.h"
michael@0 24 #include "pkcs11t.h"
michael@0 25 #if defined(XP_UNIX) || defined(XP_BEOS)
michael@0 26 #include "unistd.h"
michael@0 27 #endif
michael@0 28 #include "nssrwlk.h"
michael@0 29 #include "prthread.h"
michael@0 30 #include "prclist.h"
michael@0 31
michael@0 32 #include "sslt.h" /* for some formerly private types, now public */
michael@0 33
michael@0 34 /* to make some of these old enums public without namespace pollution,
michael@0 35 ** it was necessary to prepend ssl_ to the names.
michael@0 36 ** These #defines preserve compatibility with the old code here in libssl.
michael@0 37 */
michael@0 38 typedef SSLKEAType SSL3KEAType;
michael@0 39 typedef SSLMACAlgorithm SSL3MACAlgorithm;
michael@0 40 typedef SSLSignType SSL3SignType;
michael@0 41
michael@0 42 #define sign_null ssl_sign_null
michael@0 43 #define sign_rsa ssl_sign_rsa
michael@0 44 #define sign_dsa ssl_sign_dsa
michael@0 45 #define sign_ecdsa ssl_sign_ecdsa
michael@0 46
michael@0 47 #define calg_null ssl_calg_null
michael@0 48 #define calg_rc4 ssl_calg_rc4
michael@0 49 #define calg_rc2 ssl_calg_rc2
michael@0 50 #define calg_des ssl_calg_des
michael@0 51 #define calg_3des ssl_calg_3des
michael@0 52 #define calg_idea ssl_calg_idea
michael@0 53 #define calg_fortezza ssl_calg_fortezza /* deprecated, must preserve */
michael@0 54 #define calg_aes ssl_calg_aes
michael@0 55 #define calg_camellia ssl_calg_camellia
michael@0 56 #define calg_seed ssl_calg_seed
michael@0 57 #define calg_aes_gcm ssl_calg_aes_gcm
michael@0 58
michael@0 59 #define mac_null ssl_mac_null
michael@0 60 #define mac_md5 ssl_mac_md5
michael@0 61 #define mac_sha ssl_mac_sha
michael@0 62 #define hmac_md5 ssl_hmac_md5
michael@0 63 #define hmac_sha ssl_hmac_sha
michael@0 64 #define hmac_sha256 ssl_hmac_sha256
michael@0 65 #define mac_aead ssl_mac_aead
michael@0 66
michael@0 67 #define SET_ERROR_CODE /* reminder */
michael@0 68 #define SEND_ALERT /* reminder */
michael@0 69 #define TEST_FOR_FAILURE /* reminder */
michael@0 70 #define DEAL_WITH_FAILURE /* reminder */
michael@0 71
michael@0 72 #if defined(DEBUG) || defined(TRACE)
michael@0 73 #ifdef __cplusplus
michael@0 74 #define Debug 1
michael@0 75 #else
michael@0 76 extern int Debug;
michael@0 77 #endif
michael@0 78 #else
michael@0 79 #undef Debug
michael@0 80 #endif
michael@0 81
michael@0 82 #if defined(DEBUG) && !defined(TRACE) && !defined(NISCC_TEST)
michael@0 83 #define TRACE
michael@0 84 #endif
michael@0 85
michael@0 86 #ifdef TRACE
michael@0 87 #define SSL_TRC(a,b) if (ssl_trace >= (a)) ssl_Trace b
michael@0 88 #define PRINT_BUF(a,b) if (ssl_trace >= (a)) ssl_PrintBuf b
michael@0 89 #define DUMP_MSG(a,b) if (ssl_trace >= (a)) ssl_DumpMsg b
michael@0 90 #else
michael@0 91 #define SSL_TRC(a,b)
michael@0 92 #define PRINT_BUF(a,b)
michael@0 93 #define DUMP_MSG(a,b)
michael@0 94 #endif
michael@0 95
michael@0 96 #ifdef DEBUG
michael@0 97 #define SSL_DBG(b) if (ssl_debug) ssl_Trace b
michael@0 98 #else
michael@0 99 #define SSL_DBG(b)
michael@0 100 #endif
michael@0 101
michael@0 102 #include "private/pprthred.h" /* for PR_InMonitor() */
michael@0 103 #define ssl_InMonitor(m) PZ_InMonitor(m)
michael@0 104
michael@0 105 #define LSB(x) ((unsigned char) ((x) & 0xff))
michael@0 106 #define MSB(x) ((unsigned char) (((unsigned)(x)) >> 8))
michael@0 107
michael@0 108 /************************************************************************/
michael@0 109
michael@0 110 typedef enum { SSLAppOpRead = 0,
michael@0 111 SSLAppOpWrite,
michael@0 112 SSLAppOpRDWR,
michael@0 113 SSLAppOpPost,
michael@0 114 SSLAppOpHeader
michael@0 115 } SSLAppOperation;
michael@0 116
michael@0 117 #define SSL_MIN_MASTER_KEY_BYTES 5
michael@0 118 #define SSL_MAX_MASTER_KEY_BYTES 64
michael@0 119
michael@0 120 #define SSL2_SESSIONID_BYTES 16
michael@0 121 #define SSL3_SESSIONID_BYTES 32
michael@0 122
michael@0 123 #define SSL_MIN_CHALLENGE_BYTES 16
michael@0 124 #define SSL_MAX_CHALLENGE_BYTES 32
michael@0 125 #define SSL_CHALLENGE_BYTES 16
michael@0 126
michael@0 127 #define SSL_CONNECTIONID_BYTES 16
michael@0 128
michael@0 129 #define SSL_MIN_CYPHER_ARG_BYTES 0
michael@0 130 #define SSL_MAX_CYPHER_ARG_BYTES 32
michael@0 131
michael@0 132 #define SSL_MAX_MAC_BYTES 16
michael@0 133
michael@0 134 #define SSL3_RSA_PMS_LENGTH 48
michael@0 135 #define SSL3_MASTER_SECRET_LENGTH 48
michael@0 136
michael@0 137 /* number of wrap mechanisms potentially used to wrap master secrets. */
michael@0 138 #define SSL_NUM_WRAP_MECHS 16
michael@0 139
michael@0 140 /* This makes the cert cache entry exactly 4k. */
michael@0 141 #define SSL_MAX_CACHED_CERT_LEN 4060
michael@0 142
michael@0 143 #define NUM_MIXERS 9
michael@0 144
michael@0 145 /* Mask of the 25 named curves we support. */
michael@0 146 #define SSL3_ALL_SUPPORTED_CURVES_MASK 0x3fffffe
michael@0 147 /* Mask of only 3 curves, suite B */
michael@0 148 #define SSL3_SUITE_B_SUPPORTED_CURVES_MASK 0x3800000
michael@0 149
michael@0 150 #ifndef BPB
michael@0 151 #define BPB 8 /* Bits Per Byte */
michael@0 152 #endif
michael@0 153
michael@0 154 #define EXPORT_RSA_KEY_LENGTH 64 /* bytes */
michael@0 155
michael@0 156 #define INITIAL_DTLS_TIMEOUT_MS 1000 /* Default value from RFC 4347 = 1s*/
michael@0 157 #define MAX_DTLS_TIMEOUT_MS 60000 /* 1 minute */
michael@0 158 #define DTLS_FINISHED_TIMER_MS 120000 /* Time to wait in FINISHED state */
michael@0 159
michael@0 160 typedef struct sslBufferStr sslBuffer;
michael@0 161 typedef struct sslConnectInfoStr sslConnectInfo;
michael@0 162 typedef struct sslGatherStr sslGather;
michael@0 163 typedef struct sslSecurityInfoStr sslSecurityInfo;
michael@0 164 typedef struct sslSessionIDStr sslSessionID;
michael@0 165 typedef struct sslSocketStr sslSocket;
michael@0 166 typedef struct sslSocketOpsStr sslSocketOps;
michael@0 167
michael@0 168 typedef struct ssl3StateStr ssl3State;
michael@0 169 typedef struct ssl3CertNodeStr ssl3CertNode;
michael@0 170 typedef struct ssl3BulkCipherDefStr ssl3BulkCipherDef;
michael@0 171 typedef struct ssl3MACDefStr ssl3MACDef;
michael@0 172 typedef struct ssl3KeyPairStr ssl3KeyPair;
michael@0 173
michael@0 174 struct ssl3CertNodeStr {
michael@0 175 struct ssl3CertNodeStr *next;
michael@0 176 CERTCertificate * cert;
michael@0 177 };
michael@0 178
michael@0 179 typedef SECStatus (*sslHandshakeFunc)(sslSocket *ss);
michael@0 180
michael@0 181 /* This type points to the low layer send func,
michael@0 182 ** e.g. ssl2_SendStream or ssl3_SendPlainText.
michael@0 183 ** These functions return the same values as PR_Send,
michael@0 184 ** i.e. >= 0 means number of bytes sent, < 0 means error.
michael@0 185 */
michael@0 186 typedef PRInt32 (*sslSendFunc)(sslSocket *ss, const unsigned char *buf,
michael@0 187 PRInt32 n, PRInt32 flags);
michael@0 188
michael@0 189 typedef void (*sslSessionIDCacheFunc) (sslSessionID *sid);
michael@0 190 typedef void (*sslSessionIDUncacheFunc)(sslSessionID *sid);
michael@0 191 typedef sslSessionID *(*sslSessionIDLookupFunc)(const PRIPv6Addr *addr,
michael@0 192 unsigned char* sid,
michael@0 193 unsigned int sidLen,
michael@0 194 CERTCertDBHandle * dbHandle);
michael@0 195
michael@0 196 /* registerable callback function that either appends extension to buffer
michael@0 197 * or returns length of data that it would have appended.
michael@0 198 */
michael@0 199 typedef PRInt32 (*ssl3HelloExtensionSenderFunc)(sslSocket *ss, PRBool append,
michael@0 200 PRUint32 maxBytes);
michael@0 201
michael@0 202 /* registerable callback function that handles a received extension,
michael@0 203 * of the given type.
michael@0 204 */
michael@0 205 typedef SECStatus (* ssl3HelloExtensionHandlerFunc)(sslSocket *ss,
michael@0 206 PRUint16 ex_type,
michael@0 207 SECItem * data);
michael@0 208
michael@0 209 /* row in a table of hello extension senders */
michael@0 210 typedef struct {
michael@0 211 PRInt32 ex_type;
michael@0 212 ssl3HelloExtensionSenderFunc ex_sender;
michael@0 213 } ssl3HelloExtensionSender;
michael@0 214
michael@0 215 /* row in a table of hello extension handlers */
michael@0 216 typedef struct {
michael@0 217 PRInt32 ex_type;
michael@0 218 ssl3HelloExtensionHandlerFunc ex_handler;
michael@0 219 } ssl3HelloExtensionHandler;
michael@0 220
michael@0 221 extern SECStatus
michael@0 222 ssl3_RegisterServerHelloExtensionSender(sslSocket *ss, PRUint16 ex_type,
michael@0 223 ssl3HelloExtensionSenderFunc cb);
michael@0 224
michael@0 225 extern PRInt32
michael@0 226 ssl3_CallHelloExtensionSenders(sslSocket *ss, PRBool append, PRUint32 maxBytes,
michael@0 227 const ssl3HelloExtensionSender *sender);
michael@0 228
michael@0 229 extern unsigned int
michael@0 230 ssl3_CalculatePaddingExtensionLength(unsigned int clientHelloLength);
michael@0 231
michael@0 232 extern PRInt32
michael@0 233 ssl3_AppendPaddingExtension(sslSocket *ss, unsigned int extensionLen,
michael@0 234 PRUint32 maxBytes);
michael@0 235
michael@0 236 /* Socket ops */
michael@0 237 struct sslSocketOpsStr {
michael@0 238 int (*connect) (sslSocket *, const PRNetAddr *);
michael@0 239 PRFileDesc *(*accept) (sslSocket *, PRNetAddr *);
michael@0 240 int (*bind) (sslSocket *, const PRNetAddr *);
michael@0 241 int (*listen) (sslSocket *, int);
michael@0 242 int (*shutdown)(sslSocket *, int);
michael@0 243 int (*close) (sslSocket *);
michael@0 244
michael@0 245 int (*recv) (sslSocket *, unsigned char *, int, int);
michael@0 246
michael@0 247 /* points to the higher-layer send func, e.g. ssl_SecureSend. */
michael@0 248 int (*send) (sslSocket *, const unsigned char *, int, int);
michael@0 249 int (*read) (sslSocket *, unsigned char *, int);
michael@0 250 int (*write) (sslSocket *, const unsigned char *, int);
michael@0 251
michael@0 252 int (*getpeername)(sslSocket *, PRNetAddr *);
michael@0 253 int (*getsockname)(sslSocket *, PRNetAddr *);
michael@0 254 };
michael@0 255
michael@0 256 /* Flags interpreted by ssl send functions. */
michael@0 257 #define ssl_SEND_FLAG_FORCE_INTO_BUFFER 0x40000000
michael@0 258 #define ssl_SEND_FLAG_NO_BUFFER 0x20000000
michael@0 259 #define ssl_SEND_FLAG_USE_EPOCH 0x10000000 /* DTLS only */
michael@0 260 #define ssl_SEND_FLAG_NO_RETRANSMIT 0x08000000 /* DTLS only */
michael@0 261 #define ssl_SEND_FLAG_CAP_RECORD_VERSION \
michael@0 262 0x04000000 /* TLS only */
michael@0 263 #define ssl_SEND_FLAG_MASK 0x7f000000
michael@0 264
michael@0 265 /*
michael@0 266 ** A buffer object.
michael@0 267 */
michael@0 268 struct sslBufferStr {
michael@0 269 unsigned char * buf;
michael@0 270 unsigned int len;
michael@0 271 unsigned int space;
michael@0 272 };
michael@0 273
michael@0 274 /*
michael@0 275 ** SSL3 cipher suite policy and preference struct.
michael@0 276 */
michael@0 277 typedef struct {
michael@0 278 #if !defined(_WIN32)
michael@0 279 unsigned int cipher_suite : 16;
michael@0 280 unsigned int policy : 8;
michael@0 281 unsigned int enabled : 1;
michael@0 282 unsigned int isPresent : 1;
michael@0 283 #else
michael@0 284 ssl3CipherSuite cipher_suite;
michael@0 285 PRUint8 policy;
michael@0 286 unsigned char enabled : 1;
michael@0 287 unsigned char isPresent : 1;
michael@0 288 #endif
michael@0 289 } ssl3CipherSuiteCfg;
michael@0 290
michael@0 291 #ifndef NSS_DISABLE_ECC
michael@0 292 #define ssl_V3_SUITES_IMPLEMENTED 61
michael@0 293 #else
michael@0 294 #define ssl_V3_SUITES_IMPLEMENTED 37
michael@0 295 #endif /* NSS_DISABLE_ECC */
michael@0 296
michael@0 297 #define MAX_DTLS_SRTP_CIPHER_SUITES 4
michael@0 298
michael@0 299 typedef struct sslOptionsStr {
michael@0 300 /* If SSL_SetNextProtoNego has been called, then this contains the
michael@0 301 * list of supported protocols. */
michael@0 302 SECItem nextProtoNego;
michael@0 303
michael@0 304 unsigned int useSecurity : 1; /* 1 */
michael@0 305 unsigned int useSocks : 1; /* 2 */
michael@0 306 unsigned int requestCertificate : 1; /* 3 */
michael@0 307 unsigned int requireCertificate : 2; /* 4-5 */
michael@0 308 unsigned int handshakeAsClient : 1; /* 6 */
michael@0 309 unsigned int handshakeAsServer : 1; /* 7 */
michael@0 310 unsigned int enableSSL2 : 1; /* 8 */
michael@0 311 unsigned int unusedBit9 : 1; /* 9 */
michael@0 312 unsigned int unusedBit10 : 1; /* 10 */
michael@0 313 unsigned int noCache : 1; /* 11 */
michael@0 314 unsigned int fdx : 1; /* 12 */
michael@0 315 unsigned int v2CompatibleHello : 1; /* 13 */
michael@0 316 unsigned int detectRollBack : 1; /* 14 */
michael@0 317 unsigned int noStepDown : 1; /* 15 */
michael@0 318 unsigned int bypassPKCS11 : 1; /* 16 */
michael@0 319 unsigned int noLocks : 1; /* 17 */
michael@0 320 unsigned int enableSessionTickets : 1; /* 18 */
michael@0 321 unsigned int enableDeflate : 1; /* 19 */
michael@0 322 unsigned int enableRenegotiation : 2; /* 20-21 */
michael@0 323 unsigned int requireSafeNegotiation : 1; /* 22 */
michael@0 324 unsigned int enableFalseStart : 1; /* 23 */
michael@0 325 unsigned int cbcRandomIV : 1; /* 24 */
michael@0 326 unsigned int enableOCSPStapling : 1; /* 25 */
michael@0 327 unsigned int enableNPN : 1; /* 26 */
michael@0 328 unsigned int enableALPN : 1; /* 27 */
michael@0 329 unsigned int dummy : 1; /* 28 */
michael@0 330 unsigned int enableFallbackSCSV : 1; /* 29 */
michael@0 331 } sslOptions;
michael@0 332
michael@0 333 typedef enum { sslHandshakingUndetermined = 0,
michael@0 334 sslHandshakingAsClient,
michael@0 335 sslHandshakingAsServer
michael@0 336 } sslHandshakingType;
michael@0 337
michael@0 338 typedef struct sslServerCertsStr {
michael@0 339 /* Configuration state for server sockets */
michael@0 340 CERTCertificate * serverCert;
michael@0 341 CERTCertificateList * serverCertChain;
michael@0 342 ssl3KeyPair * serverKeyPair;
michael@0 343 unsigned int serverKeyBits;
michael@0 344 } sslServerCerts;
michael@0 345
michael@0 346 #define SERVERKEY serverKeyPair->privKey
michael@0 347
michael@0 348 #define SSL_LOCK_RANK_SPEC 255
michael@0 349 #define SSL_LOCK_RANK_GLOBAL NSS_RWLOCK_RANK_NONE
michael@0 350
michael@0 351 /* These are the valid values for shutdownHow.
michael@0 352 ** These values are each 1 greater than the NSPR values, and the code
michael@0 353 ** depends on that relation to efficiently convert PR_SHUTDOWN values
michael@0 354 ** into ssl_SHUTDOWN values. These values use one bit for read, and
michael@0 355 ** another bit for write, and can be used as bitmasks.
michael@0 356 */
michael@0 357 #define ssl_SHUTDOWN_NONE 0 /* NOT shutdown at all */
michael@0 358 #define ssl_SHUTDOWN_RCV 1 /* PR_SHUTDOWN_RCV +1 */
michael@0 359 #define ssl_SHUTDOWN_SEND 2 /* PR_SHUTDOWN_SEND +1 */
michael@0 360 #define ssl_SHUTDOWN_BOTH 3 /* PR_SHUTDOWN_BOTH +1 */
michael@0 361
michael@0 362 /*
michael@0 363 ** A gather object. Used to read some data until a count has been
michael@0 364 ** satisfied. Primarily for support of async sockets.
michael@0 365 ** Everything in here is protected by the recvBufLock.
michael@0 366 */
michael@0 367 struct sslGatherStr {
michael@0 368 int state; /* see GS_ values below. */ /* ssl 2 & 3 */
michael@0 369
michael@0 370 /* "buf" holds received plaintext SSL records, after decrypt and MAC check.
michael@0 371 * SSL2: recv'd ciphertext records are put here, then decrypted in place.
michael@0 372 * SSL3: recv'd ciphertext records are put in inbuf (see below), then
michael@0 373 * decrypted into buf.
michael@0 374 */
michael@0 375 sslBuffer buf; /*recvBufLock*/ /* ssl 2 & 3 */
michael@0 376
michael@0 377 /* number of bytes previously read into hdr or buf(ssl2) or inbuf (ssl3).
michael@0 378 ** (offset - writeOffset) is the number of ciphertext bytes read in but
michael@0 379 ** not yet deciphered.
michael@0 380 */
michael@0 381 unsigned int offset; /* ssl 2 & 3 */
michael@0 382
michael@0 383 /* number of bytes to read in next call to ssl_DefRecv (recv) */
michael@0 384 unsigned int remainder; /* ssl 2 & 3 */
michael@0 385
michael@0 386 /* Number of ciphertext bytes to read in after 2-byte SSL record header. */
michael@0 387 unsigned int count; /* ssl2 only */
michael@0 388
michael@0 389 /* size of the final plaintext record.
michael@0 390 ** == count - (recordPadding + MAC size)
michael@0 391 */
michael@0 392 unsigned int recordLen; /* ssl2 only */
michael@0 393
michael@0 394 /* number of bytes of padding to be removed after decrypting. */
michael@0 395 /* This value is taken from the record's hdr[2], which means a too large
michael@0 396 * value could crash us.
michael@0 397 */
michael@0 398 unsigned int recordPadding; /* ssl2 only */
michael@0 399
michael@0 400 /* plaintext DATA begins this many bytes into "buf". */
michael@0 401 unsigned int recordOffset; /* ssl2 only */
michael@0 402
michael@0 403 int encrypted; /* SSL2 session is now encrypted. ssl2 only */
michael@0 404
michael@0 405 /* These next two values are used by SSL2 and SSL3.
michael@0 406 ** DoRecv uses them to extract application data.
michael@0 407 ** The difference between writeOffset and readOffset is the amount of
michael@0 408 ** data available to the application. Note that the actual offset of
michael@0 409 ** the data in "buf" is recordOffset (above), not readOffset.
michael@0 410 ** In the current implementation, this is made available before the
michael@0 411 ** MAC is checked!!
michael@0 412 */
michael@0 413 unsigned int readOffset; /* Spot where DATA reader (e.g. application
michael@0 414 ** or handshake code) will read next.
michael@0 415 ** Always zero for SSl3 application data.
michael@0 416 */
michael@0 417 /* offset in buf/inbuf/hdr into which new data will be read from socket. */
michael@0 418 unsigned int writeOffset;
michael@0 419
michael@0 420 /* Buffer for ssl3 to read (encrypted) data from the socket */
michael@0 421 sslBuffer inbuf; /*recvBufLock*/ /* ssl3 only */
michael@0 422
michael@0 423 /* The ssl[23]_GatherData functions read data into this buffer, rather
michael@0 424 ** than into buf or inbuf, while in the GS_HEADER state.
michael@0 425 ** The portion of the SSL record header put here always comes off the wire
michael@0 426 ** as plaintext, never ciphertext.
michael@0 427 ** For SSL2, the plaintext portion is two bytes long. For SSl3 it is 5.
michael@0 428 ** For DTLS it is 13.
michael@0 429 */
michael@0 430 unsigned char hdr[13]; /* ssl 2 & 3 or dtls */
michael@0 431
michael@0 432 /* Buffer for DTLS data read off the wire as a single datagram */
michael@0 433 sslBuffer dtlsPacket;
michael@0 434
michael@0 435 /* the start of the buffered DTLS record in dtlsPacket */
michael@0 436 unsigned int dtlsPacketOffset;
michael@0 437 };
michael@0 438
michael@0 439 /* sslGather.state */
michael@0 440 #define GS_INIT 0
michael@0 441 #define GS_HEADER 1
michael@0 442 #define GS_MAC 2
michael@0 443 #define GS_DATA 3
michael@0 444 #define GS_PAD 4
michael@0 445
michael@0 446
michael@0 447
michael@0 448 /*
michael@0 449 ** ssl3State and CipherSpec structs
michael@0 450 */
michael@0 451
michael@0 452 /* The SSL bulk cipher definition */
michael@0 453 typedef enum {
michael@0 454 cipher_null,
michael@0 455 cipher_rc4,
michael@0 456 cipher_rc4_40,
michael@0 457 cipher_rc4_56,
michael@0 458 cipher_rc2,
michael@0 459 cipher_rc2_40,
michael@0 460 cipher_des,
michael@0 461 cipher_3des,
michael@0 462 cipher_des40,
michael@0 463 cipher_idea,
michael@0 464 cipher_aes_128,
michael@0 465 cipher_aes_256,
michael@0 466 cipher_camellia_128,
michael@0 467 cipher_camellia_256,
michael@0 468 cipher_seed,
michael@0 469 cipher_aes_128_gcm,
michael@0 470 cipher_missing /* reserved for no such supported cipher */
michael@0 471 /* This enum must match ssl3_cipherName[] in ssl3con.c. */
michael@0 472 } SSL3BulkCipher;
michael@0 473
michael@0 474 typedef enum { type_stream, type_block, type_aead } CipherType;
michael@0 475
michael@0 476 #define MAX_IV_LENGTH 24
michael@0 477
michael@0 478 /*
michael@0 479 * Do not depend upon 64 bit arithmetic in the underlying machine.
michael@0 480 */
michael@0 481 typedef struct {
michael@0 482 PRUint32 high;
michael@0 483 PRUint32 low;
michael@0 484 } SSL3SequenceNumber;
michael@0 485
michael@0 486 typedef PRUint16 DTLSEpoch;
michael@0 487
michael@0 488 typedef void (*DTLSTimerCb)(sslSocket *);
michael@0 489
michael@0 490 #define MAX_MAC_CONTEXT_BYTES 400 /* 400 is large enough for MD5, SHA-1, and
michael@0 491 * SHA-256. For SHA-384 support, increase
michael@0 492 * it to 712. */
michael@0 493 #define MAX_MAC_CONTEXT_LLONGS (MAX_MAC_CONTEXT_BYTES / 8)
michael@0 494
michael@0 495 #define MAX_CIPHER_CONTEXT_BYTES 2080
michael@0 496 #define MAX_CIPHER_CONTEXT_LLONGS (MAX_CIPHER_CONTEXT_BYTES / 8)
michael@0 497
michael@0 498 typedef struct {
michael@0 499 SSL3Opaque wrapped_master_secret[48];
michael@0 500 PRUint16 wrapped_master_secret_len;
michael@0 501 PRUint8 msIsWrapped;
michael@0 502 PRUint8 resumable;
michael@0 503 } ssl3SidKeys; /* 52 bytes */
michael@0 504
michael@0 505 typedef struct {
michael@0 506 PK11SymKey *write_key;
michael@0 507 PK11SymKey *write_mac_key;
michael@0 508 PK11Context *write_mac_context;
michael@0 509 SECItem write_key_item;
michael@0 510 SECItem write_iv_item;
michael@0 511 SECItem write_mac_key_item;
michael@0 512 SSL3Opaque write_iv[MAX_IV_LENGTH];
michael@0 513 PRUint64 cipher_context[MAX_CIPHER_CONTEXT_LLONGS];
michael@0 514 } ssl3KeyMaterial;
michael@0 515
michael@0 516 typedef SECStatus (*SSLCipher)(void * context,
michael@0 517 unsigned char * out,
michael@0 518 int * outlen,
michael@0 519 int maxout,
michael@0 520 const unsigned char *in,
michael@0 521 int inlen);
michael@0 522 typedef SECStatus (*SSLAEADCipher)(
michael@0 523 ssl3KeyMaterial * keys,
michael@0 524 PRBool doDecrypt,
michael@0 525 unsigned char * out,
michael@0 526 int * outlen,
michael@0 527 int maxout,
michael@0 528 const unsigned char *in,
michael@0 529 int inlen,
michael@0 530 const unsigned char *additionalData,
michael@0 531 int additionalDataLen);
michael@0 532 typedef SECStatus (*SSLCompressor)(void * context,
michael@0 533 unsigned char * out,
michael@0 534 int * outlen,
michael@0 535 int maxout,
michael@0 536 const unsigned char *in,
michael@0 537 int inlen);
michael@0 538 typedef SECStatus (*SSLDestroy)(void *context, PRBool freeit);
michael@0 539
michael@0 540 /* The DTLS anti-replay window. Defined here because we need it in
michael@0 541 * the cipher spec. Note that this is a ring buffer but left and
michael@0 542 * right represent the true window, with modular arithmetic used to
michael@0 543 * map them onto the buffer.
michael@0 544 */
michael@0 545 #define DTLS_RECVD_RECORDS_WINDOW 1024 /* Packets; approximate
michael@0 546 * Must be divisible by 8
michael@0 547 */
michael@0 548 typedef struct DTLSRecvdRecordsStr {
michael@0 549 unsigned char data[DTLS_RECVD_RECORDS_WINDOW/8];
michael@0 550 PRUint64 left;
michael@0 551 PRUint64 right;
michael@0 552 } DTLSRecvdRecords;
michael@0 553
michael@0 554 /*
michael@0 555 ** These are the "specs" in the "ssl3" struct.
michael@0 556 ** Access to the pointers to these specs, and all the specs' contents
michael@0 557 ** (direct and indirect) is protected by the reader/writer lock ss->specLock.
michael@0 558 */
michael@0 559 typedef struct {
michael@0 560 const ssl3BulkCipherDef *cipher_def;
michael@0 561 const ssl3MACDef * mac_def;
michael@0 562 SSLCompressionMethod compression_method;
michael@0 563 int mac_size;
michael@0 564 SSLCipher encode;
michael@0 565 SSLCipher decode;
michael@0 566 SSLAEADCipher aead;
michael@0 567 SSLDestroy destroy;
michael@0 568 void * encodeContext;
michael@0 569 void * decodeContext;
michael@0 570 SSLCompressor compressor; /* Don't name these fields compress */
michael@0 571 SSLCompressor decompressor; /* and uncompress because zconf.h */
michael@0 572 /* may define them as macros. */
michael@0 573 SSLDestroy destroyCompressContext;
michael@0 574 void * compressContext;
michael@0 575 SSLDestroy destroyDecompressContext;
michael@0 576 void * decompressContext;
michael@0 577 PRBool bypassCiphers; /* did double bypass (at least) */
michael@0 578 PK11SymKey * master_secret;
michael@0 579 SSL3SequenceNumber write_seq_num;
michael@0 580 SSL3SequenceNumber read_seq_num;
michael@0 581 SSL3ProtocolVersion version;
michael@0 582 ssl3KeyMaterial client;
michael@0 583 ssl3KeyMaterial server;
michael@0 584 SECItem msItem;
michael@0 585 unsigned char key_block[NUM_MIXERS * MD5_LENGTH];
michael@0 586 unsigned char raw_master_secret[56];
michael@0 587 SECItem srvVirtName; /* for server: name that was negotiated
michael@0 588 * with a client. For client - is
michael@0 589 * always set to NULL.*/
michael@0 590 DTLSEpoch epoch;
michael@0 591 DTLSRecvdRecords recvdRecords;
michael@0 592 } ssl3CipherSpec;
michael@0 593
michael@0 594 typedef enum { never_cached,
michael@0 595 in_client_cache,
michael@0 596 in_server_cache,
michael@0 597 invalid_cache /* no longer in any cache. */
michael@0 598 } Cached;
michael@0 599
michael@0 600 struct sslSessionIDStr {
michael@0 601 /* The global cache lock must be held when accessing these members when the
michael@0 602 * sid is in any cache.
michael@0 603 */
michael@0 604 sslSessionID * next; /* chain used for client sockets, only */
michael@0 605 Cached cached;
michael@0 606 int references;
michael@0 607 PRUint32 lastAccessTime; /* seconds since Jan 1, 1970 */
michael@0 608
michael@0 609 /* The rest of the members, except for the members of u.ssl3.locked, may
michael@0 610 * be modified only when the sid is not in any cache.
michael@0 611 */
michael@0 612
michael@0 613 CERTCertificate * peerCert;
michael@0 614 SECItemArray peerCertStatus; /* client only */
michael@0 615 const char * peerID; /* client only */
michael@0 616 const char * urlSvrName; /* client only */
michael@0 617 CERTCertificate * localCert;
michael@0 618
michael@0 619 PRIPv6Addr addr;
michael@0 620 PRUint16 port;
michael@0 621
michael@0 622 SSL3ProtocolVersion version;
michael@0 623
michael@0 624 PRUint32 creationTime; /* seconds since Jan 1, 1970 */
michael@0 625 PRUint32 expirationTime; /* seconds since Jan 1, 1970 */
michael@0 626
michael@0 627 SSLSignType authAlgorithm;
michael@0 628 PRUint32 authKeyBits;
michael@0 629 SSLKEAType keaType;
michael@0 630 PRUint32 keaKeyBits;
michael@0 631
michael@0 632 union {
michael@0 633 struct {
michael@0 634 /* the V2 code depends upon the size of sessionID. */
michael@0 635 unsigned char sessionID[SSL2_SESSIONID_BYTES];
michael@0 636
michael@0 637 /* Stuff used to recreate key and read/write cipher objects */
michael@0 638 SECItem masterKey; /* never wrapped */
michael@0 639 int cipherType;
michael@0 640 SECItem cipherArg;
michael@0 641 int keyBits;
michael@0 642 int secretKeyBits;
michael@0 643 } ssl2;
michael@0 644 struct {
michael@0 645 /* values that are copied into the server's on-disk SID cache. */
michael@0 646 PRUint8 sessionIDLength;
michael@0 647 SSL3Opaque sessionID[SSL3_SESSIONID_BYTES];
michael@0 648
michael@0 649 ssl3CipherSuite cipherSuite;
michael@0 650 SSLCompressionMethod compression;
michael@0 651 int policy;
michael@0 652 ssl3SidKeys keys;
michael@0 653 CK_MECHANISM_TYPE masterWrapMech;
michael@0 654 /* mechanism used to wrap master secret */
michael@0 655 SSL3KEAType exchKeyType;
michael@0 656 /* key type used in exchange algorithm,
michael@0 657 * and to wrap the sym wrapping key. */
michael@0 658 #ifndef NSS_DISABLE_ECC
michael@0 659 PRUint32 negotiatedECCurves;
michael@0 660 #endif /* NSS_DISABLE_ECC */
michael@0 661
michael@0 662 /* The following values are NOT restored from the server's on-disk
michael@0 663 * session cache, but are restored from the client's cache.
michael@0 664 */
michael@0 665 PK11SymKey * clientWriteKey;
michael@0 666 PK11SymKey * serverWriteKey;
michael@0 667
michael@0 668 /* The following values pertain to the slot that wrapped the
michael@0 669 ** master secret. (used only in client)
michael@0 670 */
michael@0 671 SECMODModuleID masterModuleID;
michael@0 672 /* what module wrapped the master secret */
michael@0 673 CK_SLOT_ID masterSlotID;
michael@0 674 PRUint16 masterWrapIndex;
michael@0 675 /* what's the key index for the wrapping key */
michael@0 676 PRUint16 masterWrapSeries;
michael@0 677 /* keep track of the slot series, so we don't
michael@0 678 * accidently try to use new keys after the
michael@0 679 * card gets removed and replaced.*/
michael@0 680
michael@0 681 /* The following values pertain to the slot that did the signature
michael@0 682 ** for client auth. (used only in client)
michael@0 683 */
michael@0 684 SECMODModuleID clAuthModuleID;
michael@0 685 CK_SLOT_ID clAuthSlotID;
michael@0 686 PRUint16 clAuthSeries;
michael@0 687
michael@0 688 char masterValid;
michael@0 689 char clAuthValid;
michael@0 690
michael@0 691 SECItem srvName;
michael@0 692
michael@0 693 /* This lock is lazily initialized by CacheSID when a sid is first
michael@0 694 * cached. Before then, there is no need to lock anything because
michael@0 695 * the sid isn't being shared by anything.
michael@0 696 */
michael@0 697 PRRWLock *lock;
michael@0 698
michael@0 699 /* The lock must be held while reading or writing these members
michael@0 700 * because they change while the sid is cached.
michael@0 701 */
michael@0 702 struct {
michael@0 703 /* The session ticket, if we have one, is sent as an extension
michael@0 704 * in the ClientHello message. This field is used only by
michael@0 705 * clients. It is protected by lock when lock is non-null
michael@0 706 * (after the sid has been added to the client session cache).
michael@0 707 */
michael@0 708 NewSessionTicket sessionTicket;
michael@0 709 } locked;
michael@0 710 } ssl3;
michael@0 711 } u;
michael@0 712 };
michael@0 713
michael@0 714 typedef struct ssl3CipherSuiteDefStr {
michael@0 715 ssl3CipherSuite cipher_suite;
michael@0 716 SSL3BulkCipher bulk_cipher_alg;
michael@0 717 SSL3MACAlgorithm mac_alg;
michael@0 718 SSL3KeyExchangeAlgorithm key_exchange_alg;
michael@0 719 } ssl3CipherSuiteDef;
michael@0 720
michael@0 721 /*
michael@0 722 ** There are tables of these, all const.
michael@0 723 */
michael@0 724 typedef struct {
michael@0 725 SSL3KeyExchangeAlgorithm kea;
michael@0 726 SSL3KEAType exchKeyType;
michael@0 727 SSL3SignType signKeyType;
michael@0 728 PRBool is_limited;
michael@0 729 int key_size_limit;
michael@0 730 PRBool tls_keygen;
michael@0 731 } ssl3KEADef;
michael@0 732
michael@0 733 /*
michael@0 734 ** There are tables of these, all const.
michael@0 735 */
michael@0 736 struct ssl3BulkCipherDefStr {
michael@0 737 SSL3BulkCipher cipher;
michael@0 738 SSLCipherAlgorithm calg;
michael@0 739 int key_size;
michael@0 740 int secret_key_size;
michael@0 741 CipherType type;
michael@0 742 int iv_size;
michael@0 743 int block_size;
michael@0 744 int tag_size; /* authentication tag size for AEAD ciphers. */
michael@0 745 int explicit_nonce_size; /* for AEAD ciphers. */
michael@0 746 };
michael@0 747
michael@0 748 /*
michael@0 749 ** There are tables of these, all const.
michael@0 750 */
michael@0 751 struct ssl3MACDefStr {
michael@0 752 SSL3MACAlgorithm mac;
michael@0 753 CK_MECHANISM_TYPE mmech;
michael@0 754 int pad_size;
michael@0 755 int mac_size;
michael@0 756 };
michael@0 757
michael@0 758 typedef enum {
michael@0 759 wait_client_hello,
michael@0 760 wait_client_cert,
michael@0 761 wait_client_key,
michael@0 762 wait_cert_verify,
michael@0 763 wait_change_cipher,
michael@0 764 wait_finished,
michael@0 765 wait_server_hello,
michael@0 766 wait_certificate_status,
michael@0 767 wait_server_cert,
michael@0 768 wait_server_key,
michael@0 769 wait_cert_request,
michael@0 770 wait_hello_done,
michael@0 771 wait_new_session_ticket,
michael@0 772 idle_handshake
michael@0 773 } SSL3WaitState;
michael@0 774
michael@0 775 /*
michael@0 776 * TLS extension related constants and data structures.
michael@0 777 */
michael@0 778 typedef struct TLSExtensionDataStr TLSExtensionData;
michael@0 779 typedef struct SessionTicketDataStr SessionTicketData;
michael@0 780
michael@0 781 struct TLSExtensionDataStr {
michael@0 782 /* registered callbacks that send server hello extensions */
michael@0 783 ssl3HelloExtensionSender serverSenders[SSL_MAX_EXTENSIONS];
michael@0 784 /* Keep track of the extensions that are negotiated. */
michael@0 785 PRUint16 numAdvertised;
michael@0 786 PRUint16 numNegotiated;
michael@0 787 PRUint16 advertised[SSL_MAX_EXTENSIONS];
michael@0 788 PRUint16 negotiated[SSL_MAX_EXTENSIONS];
michael@0 789
michael@0 790 /* SessionTicket Extension related data. */
michael@0 791 PRBool ticketTimestampVerified;
michael@0 792 PRBool emptySessionTicket;
michael@0 793 PRBool sentSessionTicketInClientHello;
michael@0 794
michael@0 795 /* SNI Extension related data
michael@0 796 * Names data is not coppied from the input buffer. It can not be
michael@0 797 * used outside the scope where input buffer is defined and that
michael@0 798 * is beyond ssl3_HandleClientHello function. */
michael@0 799 SECItem *sniNameArr;
michael@0 800 PRUint32 sniNameArrSize;
michael@0 801 };
michael@0 802
michael@0 803 typedef SECStatus (*sslRestartTarget)(sslSocket *);
michael@0 804
michael@0 805 /*
michael@0 806 ** A DTLS queued message (potentially to be retransmitted)
michael@0 807 */
michael@0 808 typedef struct DTLSQueuedMessageStr {
michael@0 809 PRCList link; /* The linked list link */
michael@0 810 DTLSEpoch epoch; /* The epoch to use */
michael@0 811 SSL3ContentType type; /* The message type */
michael@0 812 unsigned char *data; /* The data */
michael@0 813 PRUint16 len; /* The data length */
michael@0 814 } DTLSQueuedMessage;
michael@0 815
michael@0 816 typedef enum {
michael@0 817 handshake_hash_unknown = 0,
michael@0 818 handshake_hash_combo = 1, /* The MD5/SHA-1 combination */
michael@0 819 handshake_hash_single = 2 /* A single hash */
michael@0 820 } SSL3HandshakeHashType;
michael@0 821
michael@0 822 /*
michael@0 823 ** This is the "hs" member of the "ssl3" struct.
michael@0 824 ** This entire struct is protected by ssl3HandshakeLock
michael@0 825 */
michael@0 826 typedef struct SSL3HandshakeStateStr {
michael@0 827 SSL3Random server_random;
michael@0 828 SSL3Random client_random;
michael@0 829 SSL3WaitState ws;
michael@0 830
michael@0 831 /* This group of members is used for handshake running hashes. */
michael@0 832 SSL3HandshakeHashType hashType;
michael@0 833 sslBuffer messages; /* Accumulated handshake messages */
michael@0 834 #ifndef NO_PKCS11_BYPASS
michael@0 835 /* Bypass mode:
michael@0 836 * SSL 3.0 - TLS 1.1 use both |md5_cx| and |sha_cx|. |md5_cx| is used for
michael@0 837 * MD5 and |sha_cx| for SHA-1.
michael@0 838 * TLS 1.2 and later use only |sha_cx|, for SHA-256. NOTE: When we support
michael@0 839 * SHA-384, increase MAX_MAC_CONTEXT_BYTES to 712. */
michael@0 840 PRUint64 md5_cx[MAX_MAC_CONTEXT_LLONGS];
michael@0 841 PRUint64 sha_cx[MAX_MAC_CONTEXT_LLONGS];
michael@0 842 const SECHashObject * sha_obj;
michael@0 843 /* The function prototype of sha_obj->clone() does not match the prototype
michael@0 844 * of the freebl <HASH>_Clone functions, so we need a dedicated function
michael@0 845 * pointer for the <HASH>_Clone function. */
michael@0 846 void (*sha_clone)(void *dest, void *src);
michael@0 847 #endif
michael@0 848 /* PKCS #11 mode:
michael@0 849 * SSL 3.0 - TLS 1.1 use both |md5| and |sha|. |md5| is used for MD5 and
michael@0 850 * |sha| for SHA-1.
michael@0 851 * TLS 1.2 and later use only |sha|, for SHA-256. */
michael@0 852 /* NOTE: On the client side, TLS 1.2 and later use |md5| as a backup
michael@0 853 * handshake hash for generating client auth signatures. Confusingly, the
michael@0 854 * backup hash function is SHA-1. */
michael@0 855 #define backupHash md5
michael@0 856 PK11Context * md5;
michael@0 857 PK11Context * sha;
michael@0 858
michael@0 859 const ssl3KEADef * kea_def;
michael@0 860 ssl3CipherSuite cipher_suite;
michael@0 861 const ssl3CipherSuiteDef *suite_def;
michael@0 862 SSLCompressionMethod compression;
michael@0 863 sslBuffer msg_body; /* protected by recvBufLock */
michael@0 864 /* partial handshake message from record layer */
michael@0 865 unsigned int header_bytes;
michael@0 866 /* number of bytes consumed from handshake */
michael@0 867 /* message for message type and header length */
michael@0 868 SSL3HandshakeType msg_type;
michael@0 869 unsigned long msg_len;
michael@0 870 SECItem ca_list; /* used only by client */
michael@0 871 PRBool isResuming; /* are we resuming a session */
michael@0 872 PRBool usedStepDownKey; /* we did a server key exchange. */
michael@0 873 PRBool sendingSCSV; /* instead of empty RI */
michael@0 874 sslBuffer msgState; /* current state for handshake messages*/
michael@0 875 /* protected by recvBufLock */
michael@0 876
michael@0 877 /* The session ticket received in a NewSessionTicket message is temporarily
michael@0 878 * stored in newSessionTicket until the handshake is finished; then it is
michael@0 879 * moved to the sid.
michael@0 880 */
michael@0 881 PRBool receivedNewSessionTicket;
michael@0 882 NewSessionTicket newSessionTicket;
michael@0 883
michael@0 884 PRUint16 finishedBytes; /* size of single finished below */
michael@0 885 union {
michael@0 886 TLSFinished tFinished[2]; /* client, then server */
michael@0 887 SSL3Finished sFinished[2];
michael@0 888 SSL3Opaque data[72];
michael@0 889 } finishedMsgs;
michael@0 890 #ifndef NSS_DISABLE_ECC
michael@0 891 PRUint32 negotiatedECCurves; /* bit mask */
michael@0 892 #endif /* NSS_DISABLE_ECC */
michael@0 893
michael@0 894 PRBool authCertificatePending;
michael@0 895 /* Which function should SSL_RestartHandshake* call if we're blocked?
michael@0 896 * One of NULL, ssl3_SendClientSecondRound, ssl3_FinishHandshake,
michael@0 897 * or ssl3_AlwaysFail */
michael@0 898 sslRestartTarget restartTarget;
michael@0 899 /* Shared state between ssl3_HandleFinished and ssl3_FinishHandshake */
michael@0 900 PRBool cacheSID;
michael@0 901
michael@0 902 PRBool canFalseStart; /* Can/did we False Start */
michael@0 903
michael@0 904 /* clientSigAndHash contains the contents of the signature_algorithms
michael@0 905 * extension (if any) from the client. This is only valid for TLS 1.2
michael@0 906 * or later. */
michael@0 907 SSL3SignatureAndHashAlgorithm *clientSigAndHash;
michael@0 908 unsigned int numClientSigAndHash;
michael@0 909
michael@0 910 /* This group of values is used for DTLS */
michael@0 911 PRUint16 sendMessageSeq; /* The sending message sequence
michael@0 912 * number */
michael@0 913 PRCList lastMessageFlight; /* The last message flight we
michael@0 914 * sent */
michael@0 915 PRUint16 maxMessageSent; /* The largest message we sent */
michael@0 916 PRUint16 recvMessageSeq; /* The receiving message sequence
michael@0 917 * number */
michael@0 918 sslBuffer recvdFragments; /* The fragments we have received in
michael@0 919 * a bitmask */
michael@0 920 PRInt32 recvdHighWater; /* The high water mark for fragments
michael@0 921 * received. -1 means no reassembly
michael@0 922 * in progress. */
michael@0 923 unsigned char cookie[32]; /* The cookie */
michael@0 924 unsigned char cookieLen; /* The length of the cookie */
michael@0 925 PRIntervalTime rtTimerStarted; /* When the timer was started */
michael@0 926 DTLSTimerCb rtTimerCb; /* The function to call on expiry */
michael@0 927 PRUint32 rtTimeoutMs; /* The length of the current timeout
michael@0 928 * used for backoff (in ms) */
michael@0 929 PRUint32 rtRetries; /* The retry counter */
michael@0 930 } SSL3HandshakeState;
michael@0 931
michael@0 932
michael@0 933
michael@0 934 /*
michael@0 935 ** This is the "ssl3" struct, as in "ss->ssl3".
michael@0 936 ** note:
michael@0 937 ** usually, crSpec == cwSpec and prSpec == pwSpec.
michael@0 938 ** Sometimes, crSpec == pwSpec and prSpec == cwSpec.
michael@0 939 ** But there are never more than 2 actual specs.
michael@0 940 ** No spec must ever be modified if either "current" pointer points to it.
michael@0 941 */
michael@0 942 struct ssl3StateStr {
michael@0 943
michael@0 944 /*
michael@0 945 ** The following Specs and Spec pointers must be protected using the
michael@0 946 ** Spec Lock.
michael@0 947 */
michael@0 948 ssl3CipherSpec * crSpec; /* current read spec. */
michael@0 949 ssl3CipherSpec * prSpec; /* pending read spec. */
michael@0 950 ssl3CipherSpec * cwSpec; /* current write spec. */
michael@0 951 ssl3CipherSpec * pwSpec; /* pending write spec. */
michael@0 952
michael@0 953 CERTCertificate * clientCertificate; /* used by client */
michael@0 954 SECKEYPrivateKey * clientPrivateKey; /* used by client */
michael@0 955 CERTCertificateList *clientCertChain; /* used by client */
michael@0 956 PRBool sendEmptyCert; /* used by client */
michael@0 957
michael@0 958 int policy;
michael@0 959 /* This says what cipher suites we can do, and should
michael@0 960 * be either SSL_ALLOWED or SSL_RESTRICTED
michael@0 961 */
michael@0 962 PLArenaPool * peerCertArena;
michael@0 963 /* These are used to keep track of the peer CA */
michael@0 964 void * peerCertChain;
michael@0 965 /* chain while we are trying to validate it. */
michael@0 966 CERTDistNames * ca_list;
michael@0 967 /* used by server. trusted CAs for this socket. */
michael@0 968 PRBool initialized;
michael@0 969 SSL3HandshakeState hs;
michael@0 970 ssl3CipherSpec specs[2]; /* one is current, one is pending. */
michael@0 971
michael@0 972 /* In a client: if the server supports Next Protocol Negotiation, then
michael@0 973 * this is the protocol that was negotiated.
michael@0 974 */
michael@0 975 SECItem nextProto;
michael@0 976 SSLNextProtoState nextProtoState;
michael@0 977
michael@0 978 PRUint16 mtu; /* Our estimate of the MTU */
michael@0 979
michael@0 980 /* DTLS-SRTP cipher suite preferences (if any) */
michael@0 981 PRUint16 dtlsSRTPCiphers[MAX_DTLS_SRTP_CIPHER_SUITES];
michael@0 982 PRUint16 dtlsSRTPCipherCount;
michael@0 983 PRUint16 dtlsSRTPCipherSuite; /* 0 if not selected */
michael@0 984 };
michael@0 985
michael@0 986 #define DTLS_MAX_MTU 1500 /* Ethernet MTU but without subtracting the
michael@0 987 * headers, so slightly larger than expected */
michael@0 988 #define IS_DTLS(ss) (ss->protocolVariant == ssl_variant_datagram)
michael@0 989
michael@0 990 typedef struct {
michael@0 991 SSL3ContentType type;
michael@0 992 SSL3ProtocolVersion version;
michael@0 993 SSL3SequenceNumber seq_num; /* DTLS only */
michael@0 994 sslBuffer * buf;
michael@0 995 } SSL3Ciphertext;
michael@0 996
michael@0 997 struct ssl3KeyPairStr {
michael@0 998 SECKEYPrivateKey * privKey;
michael@0 999 SECKEYPublicKey * pubKey;
michael@0 1000 PRInt32 refCount; /* use PR_Atomic calls for this. */
michael@0 1001 };
michael@0 1002
michael@0 1003 typedef struct SSLWrappedSymWrappingKeyStr {
michael@0 1004 SSL3Opaque wrappedSymmetricWrappingkey[512];
michael@0 1005 CK_MECHANISM_TYPE symWrapMechanism;
michael@0 1006 /* unwrapped symmetric wrapping key uses this mechanism */
michael@0 1007 CK_MECHANISM_TYPE asymWrapMechanism;
michael@0 1008 /* mechanism used to wrap the SymmetricWrappingKey using
michael@0 1009 * server's public and/or private keys. */
michael@0 1010 SSL3KEAType exchKeyType; /* type of keys used to wrap SymWrapKey*/
michael@0 1011 PRInt32 symWrapMechIndex;
michael@0 1012 PRUint16 wrappedSymKeyLen;
michael@0 1013 } SSLWrappedSymWrappingKey;
michael@0 1014
michael@0 1015 typedef struct SessionTicketStr {
michael@0 1016 PRUint16 ticket_version;
michael@0 1017 SSL3ProtocolVersion ssl_version;
michael@0 1018 ssl3CipherSuite cipher_suite;
michael@0 1019 SSLCompressionMethod compression_method;
michael@0 1020 SSLSignType authAlgorithm;
michael@0 1021 PRUint32 authKeyBits;
michael@0 1022 SSLKEAType keaType;
michael@0 1023 PRUint32 keaKeyBits;
michael@0 1024 /*
michael@0 1025 * exchKeyType and msWrapMech contain meaningful values only if
michael@0 1026 * ms_is_wrapped is true.
michael@0 1027 */
michael@0 1028 PRUint8 ms_is_wrapped;
michael@0 1029 SSLKEAType exchKeyType; /* XXX(wtc): same as keaType above? */
michael@0 1030 CK_MECHANISM_TYPE msWrapMech;
michael@0 1031 PRUint16 ms_length;
michael@0 1032 SSL3Opaque master_secret[48];
michael@0 1033 ClientIdentity client_identity;
michael@0 1034 SECItem peer_cert;
michael@0 1035 PRUint32 timestamp;
michael@0 1036 SECItem srvName; /* negotiated server name */
michael@0 1037 } SessionTicket;
michael@0 1038
michael@0 1039 /*
michael@0 1040 * SSL2 buffers used in SSL3.
michael@0 1041 * writeBuf in the SecurityInfo maintained by sslsecur.c is used
michael@0 1042 * to hold the data just about to be passed to the kernel
michael@0 1043 * sendBuf in the ConnectInfo maintained by sslcon.c is used
michael@0 1044 * to hold handshake messages as they are accumulated
michael@0 1045 */
michael@0 1046
michael@0 1047 /*
michael@0 1048 ** This is "ci", as in "ss->sec.ci".
michael@0 1049 **
michael@0 1050 ** Protection: All the variables in here are protected by
michael@0 1051 ** firstHandshakeLock AND (in ssl3) ssl3HandshakeLock
michael@0 1052 */
michael@0 1053 struct sslConnectInfoStr {
michael@0 1054 /* outgoing handshakes appended to this. */
michael@0 1055 sslBuffer sendBuf; /*xmitBufLock*/ /* ssl 2 & 3 */
michael@0 1056
michael@0 1057 PRIPv6Addr peer; /* ssl 2 & 3 */
michael@0 1058 unsigned short port; /* ssl 2 & 3 */
michael@0 1059
michael@0 1060 sslSessionID *sid; /* ssl 2 & 3 */
michael@0 1061
michael@0 1062 /* see CIS_HAVE defines below for the bit values in *elements. */
michael@0 1063 char elements; /* ssl2 only */
michael@0 1064 char requiredElements; /* ssl2 only */
michael@0 1065 char sentElements; /* ssl2 only */
michael@0 1066
michael@0 1067 char sentFinished; /* ssl2 only */
michael@0 1068
michael@0 1069 /* Length of server challenge. Used by client when saving challenge */
michael@0 1070 int serverChallengeLen; /* ssl2 only */
michael@0 1071 /* type of authentication requested by server */
michael@0 1072 unsigned char authType; /* ssl2 only */
michael@0 1073
michael@0 1074 /* Challenge sent by client to server in client-hello message */
michael@0 1075 /* SSL3 gets a copy of this. See ssl3_StartHandshakeHash(). */
michael@0 1076 unsigned char clientChallenge[SSL_MAX_CHALLENGE_BYTES]; /* ssl 2 & 3 */
michael@0 1077
michael@0 1078 /* Connection-id sent by server to client in server-hello message */
michael@0 1079 unsigned char connectionID[SSL_CONNECTIONID_BYTES]; /* ssl2 only */
michael@0 1080
michael@0 1081 /* Challenge sent by server to client in request-certificate message */
michael@0 1082 unsigned char serverChallenge[SSL_MAX_CHALLENGE_BYTES]; /* ssl2 only */
michael@0 1083
michael@0 1084 /* Information kept to handle a request-certificate message */
michael@0 1085 unsigned char readKey[SSL_MAX_MASTER_KEY_BYTES]; /* ssl2 only */
michael@0 1086 unsigned char writeKey[SSL_MAX_MASTER_KEY_BYTES]; /* ssl2 only */
michael@0 1087 unsigned keySize; /* ssl2 only */
michael@0 1088 };
michael@0 1089
michael@0 1090 /* bit values for ci->elements, ci->requiredElements, sentElements. */
michael@0 1091 #define CIS_HAVE_MASTER_KEY 0x01
michael@0 1092 #define CIS_HAVE_CERTIFICATE 0x02
michael@0 1093 #define CIS_HAVE_FINISHED 0x04
michael@0 1094 #define CIS_HAVE_VERIFY 0x08
michael@0 1095
michael@0 1096 /* Note: The entire content of this struct and whatever it points to gets
michael@0 1097 * blown away by SSL_ResetHandshake(). This is "sec" as in "ss->sec".
michael@0 1098 *
michael@0 1099 * Unless otherwise specified below, the contents of this struct are
michael@0 1100 * protected by firstHandshakeLock AND (in ssl3) ssl3HandshakeLock.
michael@0 1101 */
michael@0 1102 struct sslSecurityInfoStr {
michael@0 1103 sslSendFunc send; /*xmitBufLock*/ /* ssl 2 & 3 */
michael@0 1104 int isServer; /* Spec Lock?*/ /* ssl 2 & 3 */
michael@0 1105 sslBuffer writeBuf; /*xmitBufLock*/ /* ssl 2 & 3 */
michael@0 1106
michael@0 1107 int cipherType; /* ssl 2 & 3 */
michael@0 1108 int keyBits; /* ssl 2 & 3 */
michael@0 1109 int secretKeyBits; /* ssl 2 & 3 */
michael@0 1110 CERTCertificate *localCert; /* ssl 2 & 3 */
michael@0 1111 CERTCertificate *peerCert; /* ssl 2 & 3 */
michael@0 1112 SECKEYPublicKey *peerKey; /* ssl3 only */
michael@0 1113
michael@0 1114 SSLSignType authAlgorithm;
michael@0 1115 PRUint32 authKeyBits;
michael@0 1116 SSLKEAType keaType;
michael@0 1117 PRUint32 keaKeyBits;
michael@0 1118
michael@0 1119 /*
michael@0 1120 ** Procs used for SID cache (nonce) management.
michael@0 1121 ** Different implementations exist for clients/servers
michael@0 1122 ** The lookup proc is only used for servers. Baloney!
michael@0 1123 */
michael@0 1124 sslSessionIDCacheFunc cache; /* ssl 2 & 3 */
michael@0 1125 sslSessionIDUncacheFunc uncache; /* ssl 2 & 3 */
michael@0 1126
michael@0 1127 /*
michael@0 1128 ** everything below here is for ssl2 only.
michael@0 1129 ** This stuff is equivalent to SSL3's "spec", and is protected by the
michael@0 1130 ** same "Spec Lock" as used for SSL3's specs.
michael@0 1131 */
michael@0 1132 PRUint32 sendSequence; /*xmitBufLock*/ /* ssl2 only */
michael@0 1133 PRUint32 rcvSequence; /*recvBufLock*/ /* ssl2 only */
michael@0 1134
michael@0 1135 /* Hash information; used for one-way-hash functions (MD2, MD5, etc.) */
michael@0 1136 const SECHashObject *hash; /* Spec Lock */ /* ssl2 only */
michael@0 1137 void *hashcx; /* Spec Lock */ /* ssl2 only */
michael@0 1138
michael@0 1139 SECItem sendSecret; /* Spec Lock */ /* ssl2 only */
michael@0 1140 SECItem rcvSecret; /* Spec Lock */ /* ssl2 only */
michael@0 1141
michael@0 1142 /* Session cypher contexts; one for each direction */
michael@0 1143 void *readcx; /* Spec Lock */ /* ssl2 only */
michael@0 1144 void *writecx; /* Spec Lock */ /* ssl2 only */
michael@0 1145 SSLCipher enc; /* Spec Lock */ /* ssl2 only */
michael@0 1146 SSLCipher dec; /* Spec Lock */ /* ssl2 only */
michael@0 1147 void (*destroy)(void *, PRBool); /* Spec Lock */ /* ssl2 only */
michael@0 1148
michael@0 1149 /* Blocking information for the session cypher */
michael@0 1150 int blockShift; /* Spec Lock */ /* ssl2 only */
michael@0 1151 int blockSize; /* Spec Lock */ /* ssl2 only */
michael@0 1152
michael@0 1153 /* These are used during a connection handshake */
michael@0 1154 sslConnectInfo ci; /* ssl 2 & 3 */
michael@0 1155
michael@0 1156 };
michael@0 1157
michael@0 1158 /*
michael@0 1159 ** SSL Socket struct
michael@0 1160 **
michael@0 1161 ** Protection: XXX
michael@0 1162 */
michael@0 1163 struct sslSocketStr {
michael@0 1164 PRFileDesc * fd;
michael@0 1165
michael@0 1166 /* Pointer to operations vector for this socket */
michael@0 1167 const sslSocketOps * ops;
michael@0 1168
michael@0 1169 /* SSL socket options */
michael@0 1170 sslOptions opt;
michael@0 1171 /* Enabled version range */
michael@0 1172 SSLVersionRange vrange;
michael@0 1173
michael@0 1174 /* State flags */
michael@0 1175 unsigned long clientAuthRequested;
michael@0 1176 unsigned long delayDisabled; /* Nagle delay disabled */
michael@0 1177 unsigned long firstHsDone; /* first handshake is complete. */
michael@0 1178 unsigned long enoughFirstHsDone; /* enough of the first handshake is
michael@0 1179 * done for callbacks to be able to
michael@0 1180 * retrieve channel security
michael@0 1181 * parameters from the SSL socket. */
michael@0 1182 unsigned long handshakeBegun;
michael@0 1183 unsigned long lastWriteBlocked;
michael@0 1184 unsigned long recvdCloseNotify; /* received SSL EOF. */
michael@0 1185 unsigned long TCPconnected;
michael@0 1186 unsigned long appDataBuffered;
michael@0 1187 unsigned long peerRequestedProtection; /* from old renegotiation */
michael@0 1188
michael@0 1189 /* version of the protocol to use */
michael@0 1190 SSL3ProtocolVersion version;
michael@0 1191 SSL3ProtocolVersion clientHelloVersion; /* version sent in client hello. */
michael@0 1192
michael@0 1193 sslSecurityInfo sec; /* not a pointer any more */
michael@0 1194
michael@0 1195 /* protected by firstHandshakeLock AND (in ssl3) ssl3HandshakeLock. */
michael@0 1196 const char *url; /* ssl 2 & 3 */
michael@0 1197
michael@0 1198 sslHandshakeFunc handshake; /*firstHandshakeLock*/
michael@0 1199 sslHandshakeFunc nextHandshake; /*firstHandshakeLock*/
michael@0 1200 sslHandshakeFunc securityHandshake; /*firstHandshakeLock*/
michael@0 1201
michael@0 1202 /* the following variable is only used with socks or other proxies. */
michael@0 1203 char * peerID; /* String uniquely identifies target server. */
michael@0 1204
michael@0 1205 unsigned char * cipherSpecs;
michael@0 1206 unsigned int sizeCipherSpecs;
michael@0 1207 const unsigned char * preferredCipher;
michael@0 1208
michael@0 1209 ssl3KeyPair * stepDownKeyPair; /* RSA step down keys */
michael@0 1210
michael@0 1211 /* Callbacks */
michael@0 1212 SSLAuthCertificate authCertificate;
michael@0 1213 void *authCertificateArg;
michael@0 1214 SSLGetClientAuthData getClientAuthData;
michael@0 1215 void *getClientAuthDataArg;
michael@0 1216 SSLSNISocketConfig sniSocketConfig;
michael@0 1217 void *sniSocketConfigArg;
michael@0 1218 SSLBadCertHandler handleBadCert;
michael@0 1219 void *badCertArg;
michael@0 1220 SSLHandshakeCallback handshakeCallback;
michael@0 1221 void *handshakeCallbackData;
michael@0 1222 SSLCanFalseStartCallback canFalseStartCallback;
michael@0 1223 void *canFalseStartCallbackData;
michael@0 1224 void *pkcs11PinArg;
michael@0 1225 SSLNextProtoCallback nextProtoCallback;
michael@0 1226 void *nextProtoArg;
michael@0 1227
michael@0 1228 PRIntervalTime rTimeout; /* timeout for NSPR I/O */
michael@0 1229 PRIntervalTime wTimeout; /* timeout for NSPR I/O */
michael@0 1230 PRIntervalTime cTimeout; /* timeout for NSPR I/O */
michael@0 1231
michael@0 1232 PZLock * recvLock; /* lock against multiple reader threads. */
michael@0 1233 PZLock * sendLock; /* lock against multiple sender threads. */
michael@0 1234
michael@0 1235 PZMonitor * recvBufLock; /* locks low level recv buffers. */
michael@0 1236 PZMonitor * xmitBufLock; /* locks low level xmit buffers. */
michael@0 1237
michael@0 1238 /* Only one thread may operate on the socket until the initial handshake
michael@0 1239 ** is complete. This Monitor ensures that. Since SSL2 handshake is
michael@0 1240 ** only done once, this is also effectively the SSL2 handshake lock.
michael@0 1241 */
michael@0 1242 PZMonitor * firstHandshakeLock;
michael@0 1243
michael@0 1244 /* This monitor protects the ssl3 handshake state machine data.
michael@0 1245 ** Only one thread (reader or writer) may be in the ssl3 handshake state
michael@0 1246 ** machine at any time. */
michael@0 1247 PZMonitor * ssl3HandshakeLock;
michael@0 1248
michael@0 1249 /* reader/writer lock, protects the secret data needed to encrypt and MAC
michael@0 1250 ** outgoing records, and to decrypt and MAC check incoming ciphertext
michael@0 1251 ** records. */
michael@0 1252 NSSRWLock * specLock;
michael@0 1253
michael@0 1254 /* handle to perm cert db (and implicitly to the temp cert db) used
michael@0 1255 ** with this socket.
michael@0 1256 */
michael@0 1257 CERTCertDBHandle * dbHandle;
michael@0 1258
michael@0 1259 PRThread * writerThread; /* thread holds SSL_LOCK_WRITER lock */
michael@0 1260
michael@0 1261 PRUint16 shutdownHow; /* See ssl_SHUTDOWN defines below. */
michael@0 1262
michael@0 1263 PRUint16 allowedByPolicy; /* copy of global policy bits. */
michael@0 1264 PRUint16 maybeAllowedByPolicy; /* copy of global policy bits. */
michael@0 1265 PRUint16 chosenPreference; /* SSL2 cipher preferences. */
michael@0 1266
michael@0 1267 sslHandshakingType handshaking;
michael@0 1268
michael@0 1269 /* Gather object used for gathering data */
michael@0 1270 sslGather gs; /*recvBufLock*/
michael@0 1271
michael@0 1272 sslBuffer saveBuf; /*xmitBufLock*/
michael@0 1273 sslBuffer pendingBuf; /*xmitBufLock*/
michael@0 1274
michael@0 1275 /* Configuration state for server sockets */
michael@0 1276 /* server cert and key for each KEA type */
michael@0 1277 sslServerCerts serverCerts[kt_kea_size];
michael@0 1278 /* each cert needs its own status */
michael@0 1279 SECItemArray * certStatusArray[kt_kea_size];
michael@0 1280
michael@0 1281 ssl3CipherSuiteCfg cipherSuites[ssl_V3_SUITES_IMPLEMENTED];
michael@0 1282 ssl3KeyPair * ephemeralECDHKeyPair; /* for ECDHE-* handshake */
michael@0 1283
michael@0 1284 /* SSL3 state info. Formerly was a pointer */
michael@0 1285 ssl3State ssl3;
michael@0 1286
michael@0 1287 /*
michael@0 1288 * TLS extension related data.
michael@0 1289 */
michael@0 1290 /* True when the current session is a stateless resume. */
michael@0 1291 PRBool statelessResume;
michael@0 1292 TLSExtensionData xtnData;
michael@0 1293
michael@0 1294 /* Whether we are doing stream or datagram mode */
michael@0 1295 SSLProtocolVariant protocolVariant;
michael@0 1296 };
michael@0 1297
michael@0 1298
michael@0 1299
michael@0 1300 /* All the global data items declared here should be protected using the
michael@0 1301 ** ssl_global_data_lock, which is a reader/writer lock.
michael@0 1302 */
michael@0 1303 extern NSSRWLock * ssl_global_data_lock;
michael@0 1304 extern char ssl_debug;
michael@0 1305 extern char ssl_trace;
michael@0 1306 extern FILE * ssl_trace_iob;
michael@0 1307 extern FILE * ssl_keylog_iob;
michael@0 1308 extern CERTDistNames * ssl3_server_ca_list;
michael@0 1309 extern PRUint32 ssl_sid_timeout;
michael@0 1310 extern PRUint32 ssl3_sid_timeout;
michael@0 1311
michael@0 1312 extern const char * const ssl_cipherName[];
michael@0 1313 extern const char * const ssl3_cipherName[];
michael@0 1314
michael@0 1315 extern sslSessionIDLookupFunc ssl_sid_lookup;
michael@0 1316 extern sslSessionIDCacheFunc ssl_sid_cache;
michael@0 1317 extern sslSessionIDUncacheFunc ssl_sid_uncache;
michael@0 1318
michael@0 1319 /************************************************************************/
michael@0 1320
michael@0 1321 SEC_BEGIN_PROTOS
michael@0 1322
michael@0 1323 /* Internal initialization and installation of the SSL error tables */
michael@0 1324 extern SECStatus ssl_Init(void);
michael@0 1325 extern SECStatus ssl_InitializePRErrorTable(void);
michael@0 1326
michael@0 1327 /* Implementation of ops for default (non socks, non secure) case */
michael@0 1328 extern int ssl_DefConnect(sslSocket *ss, const PRNetAddr *addr);
michael@0 1329 extern PRFileDesc *ssl_DefAccept(sslSocket *ss, PRNetAddr *addr);
michael@0 1330 extern int ssl_DefBind(sslSocket *ss, const PRNetAddr *addr);
michael@0 1331 extern int ssl_DefListen(sslSocket *ss, int backlog);
michael@0 1332 extern int ssl_DefShutdown(sslSocket *ss, int how);
michael@0 1333 extern int ssl_DefClose(sslSocket *ss);
michael@0 1334 extern int ssl_DefRecv(sslSocket *ss, unsigned char *buf, int len, int flags);
michael@0 1335 extern int ssl_DefSend(sslSocket *ss, const unsigned char *buf,
michael@0 1336 int len, int flags);
michael@0 1337 extern int ssl_DefRead(sslSocket *ss, unsigned char *buf, int len);
michael@0 1338 extern int ssl_DefWrite(sslSocket *ss, const unsigned char *buf, int len);
michael@0 1339 extern int ssl_DefGetpeername(sslSocket *ss, PRNetAddr *name);
michael@0 1340 extern int ssl_DefGetsockname(sslSocket *ss, PRNetAddr *name);
michael@0 1341 extern int ssl_DefGetsockopt(sslSocket *ss, PRSockOption optname,
michael@0 1342 void *optval, PRInt32 *optlen);
michael@0 1343 extern int ssl_DefSetsockopt(sslSocket *ss, PRSockOption optname,
michael@0 1344 const void *optval, PRInt32 optlen);
michael@0 1345
michael@0 1346 /* Implementation of ops for socks only case */
michael@0 1347 extern int ssl_SocksConnect(sslSocket *ss, const PRNetAddr *addr);
michael@0 1348 extern PRFileDesc *ssl_SocksAccept(sslSocket *ss, PRNetAddr *addr);
michael@0 1349 extern int ssl_SocksBind(sslSocket *ss, const PRNetAddr *addr);
michael@0 1350 extern int ssl_SocksListen(sslSocket *ss, int backlog);
michael@0 1351 extern int ssl_SocksGetsockname(sslSocket *ss, PRNetAddr *name);
michael@0 1352 extern int ssl_SocksRecv(sslSocket *ss, unsigned char *buf, int len, int flags);
michael@0 1353 extern int ssl_SocksSend(sslSocket *ss, const unsigned char *buf,
michael@0 1354 int len, int flags);
michael@0 1355 extern int ssl_SocksRead(sslSocket *ss, unsigned char *buf, int len);
michael@0 1356 extern int ssl_SocksWrite(sslSocket *ss, const unsigned char *buf, int len);
michael@0 1357
michael@0 1358 /* Implementation of ops for secure only case */
michael@0 1359 extern int ssl_SecureConnect(sslSocket *ss, const PRNetAddr *addr);
michael@0 1360 extern PRFileDesc *ssl_SecureAccept(sslSocket *ss, PRNetAddr *addr);
michael@0 1361 extern int ssl_SecureRecv(sslSocket *ss, unsigned char *buf,
michael@0 1362 int len, int flags);
michael@0 1363 extern int ssl_SecureSend(sslSocket *ss, const unsigned char *buf,
michael@0 1364 int len, int flags);
michael@0 1365 extern int ssl_SecureRead(sslSocket *ss, unsigned char *buf, int len);
michael@0 1366 extern int ssl_SecureWrite(sslSocket *ss, const unsigned char *buf, int len);
michael@0 1367 extern int ssl_SecureShutdown(sslSocket *ss, int how);
michael@0 1368 extern int ssl_SecureClose(sslSocket *ss);
michael@0 1369
michael@0 1370 /* Implementation of ops for secure socks case */
michael@0 1371 extern int ssl_SecureSocksConnect(sslSocket *ss, const PRNetAddr *addr);
michael@0 1372 extern PRFileDesc *ssl_SecureSocksAccept(sslSocket *ss, PRNetAddr *addr);
michael@0 1373 extern PRFileDesc *ssl_FindTop(sslSocket *ss);
michael@0 1374
michael@0 1375 /* Gather funcs. */
michael@0 1376 extern sslGather * ssl_NewGather(void);
michael@0 1377 extern SECStatus ssl_InitGather(sslGather *gs);
michael@0 1378 extern void ssl_DestroyGather(sslGather *gs);
michael@0 1379 extern int ssl2_GatherData(sslSocket *ss, sslGather *gs, int flags);
michael@0 1380 extern int ssl2_GatherRecord(sslSocket *ss, int flags);
michael@0 1381 extern SECStatus ssl_GatherRecord1stHandshake(sslSocket *ss);
michael@0 1382
michael@0 1383 extern SECStatus ssl2_HandleClientHelloMessage(sslSocket *ss);
michael@0 1384 extern SECStatus ssl2_HandleServerHelloMessage(sslSocket *ss);
michael@0 1385
michael@0 1386 extern SECStatus ssl_CreateSecurityInfo(sslSocket *ss);
michael@0 1387 extern SECStatus ssl_CopySecurityInfo(sslSocket *ss, sslSocket *os);
michael@0 1388 extern void ssl_ResetSecurityInfo(sslSecurityInfo *sec, PRBool doMemset);
michael@0 1389 extern void ssl_DestroySecurityInfo(sslSecurityInfo *sec);
michael@0 1390
michael@0 1391 extern void ssl_PrintBuf(sslSocket *ss, const char *msg, const void *cp, int len);
michael@0 1392 extern void ssl_DumpMsg(sslSocket *ss, unsigned char *bp, unsigned len);
michael@0 1393
michael@0 1394 extern int ssl_SendSavedWriteData(sslSocket *ss);
michael@0 1395 extern SECStatus ssl_SaveWriteData(sslSocket *ss,
michael@0 1396 const void* p, unsigned int l);
michael@0 1397 extern SECStatus ssl2_BeginClientHandshake(sslSocket *ss);
michael@0 1398 extern SECStatus ssl2_BeginServerHandshake(sslSocket *ss);
michael@0 1399 extern int ssl_Do1stHandshake(sslSocket *ss);
michael@0 1400
michael@0 1401 extern SECStatus sslBuffer_Grow(sslBuffer *b, unsigned int newLen);
michael@0 1402 extern SECStatus sslBuffer_Append(sslBuffer *b, const void * data,
michael@0 1403 unsigned int len);
michael@0 1404
michael@0 1405 extern void ssl2_UseClearSendFunc(sslSocket *ss);
michael@0 1406 extern void ssl_ChooseSessionIDProcs(sslSecurityInfo *sec);
michael@0 1407
michael@0 1408 extern sslSessionID *ssl3_NewSessionID(sslSocket *ss, PRBool is_server);
michael@0 1409 extern sslSessionID *ssl_LookupSID(const PRIPv6Addr *addr, PRUint16 port,
michael@0 1410 const char *peerID, const char *urlSvrName);
michael@0 1411 extern void ssl_FreeSID(sslSessionID *sid);
michael@0 1412
michael@0 1413 extern int ssl3_SendApplicationData(sslSocket *ss, const PRUint8 *in,
michael@0 1414 int len, int flags);
michael@0 1415
michael@0 1416 extern PRBool ssl_FdIsBlocking(PRFileDesc *fd);
michael@0 1417
michael@0 1418 extern PRBool ssl_SocketIsBlocking(sslSocket *ss);
michael@0 1419
michael@0 1420 extern void ssl3_SetAlwaysBlock(sslSocket *ss);
michael@0 1421
michael@0 1422 extern SECStatus ssl_EnableNagleDelay(sslSocket *ss, PRBool enabled);
michael@0 1423
michael@0 1424 extern void ssl_FinishHandshake(sslSocket *ss);
michael@0 1425
michael@0 1426 /* Returns PR_TRUE if we are still waiting for the server to respond to our
michael@0 1427 * client second round. Once we've received any part of the server's second
michael@0 1428 * round then we don't bother trying to false start since it is almost always
michael@0 1429 * the case that the NewSessionTicket, ChangeCipherSoec, and Finished messages
michael@0 1430 * were sent in the same packet and we want to process them all at the same
michael@0 1431 * time. If we were to try to false start in the middle of the server's second
michael@0 1432 * round, then we would increase the number of I/O operations
michael@0 1433 * (SSL_ForceHandshake/PR_Recv/PR_Send/etc.) needed to finish the handshake.
michael@0 1434 */
michael@0 1435 extern PRBool ssl3_WaitingForStartOfServerSecondRound(sslSocket *ss);
michael@0 1436
michael@0 1437 extern SECStatus
michael@0 1438 ssl3_CompressMACEncryptRecord(ssl3CipherSpec * cwSpec,
michael@0 1439 PRBool isServer,
michael@0 1440 PRBool isDTLS,
michael@0 1441 PRBool capRecordVersion,
michael@0 1442 SSL3ContentType type,
michael@0 1443 const SSL3Opaque * pIn,
michael@0 1444 PRUint32 contentLen,
michael@0 1445 sslBuffer * wrBuf);
michael@0 1446 extern PRInt32 ssl3_SendRecord(sslSocket *ss, DTLSEpoch epoch,
michael@0 1447 SSL3ContentType type,
michael@0 1448 const SSL3Opaque* pIn, PRInt32 nIn,
michael@0 1449 PRInt32 flags);
michael@0 1450
michael@0 1451 #ifdef NSS_ENABLE_ZLIB
michael@0 1452 /*
michael@0 1453 * The DEFLATE algorithm can result in an expansion of 0.1% + 12 bytes. For a
michael@0 1454 * maximum TLS record payload of 2**14 bytes, that's 29 bytes.
michael@0 1455 */
michael@0 1456 #define SSL3_COMPRESSION_MAX_EXPANSION 29
michael@0 1457 #else /* !NSS_ENABLE_ZLIB */
michael@0 1458 #define SSL3_COMPRESSION_MAX_EXPANSION 0
michael@0 1459 #endif
michael@0 1460
michael@0 1461 /*
michael@0 1462 * make sure there is room in the write buffer for padding and
michael@0 1463 * other compression and cryptographic expansions.
michael@0 1464 */
michael@0 1465 #define SSL3_BUFFER_FUDGE 100 + SSL3_COMPRESSION_MAX_EXPANSION
michael@0 1466
michael@0 1467 #define SSL_LOCK_READER(ss) if (ss->recvLock) PZ_Lock(ss->recvLock)
michael@0 1468 #define SSL_UNLOCK_READER(ss) if (ss->recvLock) PZ_Unlock(ss->recvLock)
michael@0 1469 #define SSL_LOCK_WRITER(ss) if (ss->sendLock) PZ_Lock(ss->sendLock)
michael@0 1470 #define SSL_UNLOCK_WRITER(ss) if (ss->sendLock) PZ_Unlock(ss->sendLock)
michael@0 1471
michael@0 1472 /* firstHandshakeLock -> recvBufLock */
michael@0 1473 #define ssl_Get1stHandshakeLock(ss) \
michael@0 1474 { if (!ss->opt.noLocks) { \
michael@0 1475 PORT_Assert(PZ_InMonitor((ss)->firstHandshakeLock) || \
michael@0 1476 !ssl_HaveRecvBufLock(ss)); \
michael@0 1477 PZ_EnterMonitor((ss)->firstHandshakeLock); \
michael@0 1478 } }
michael@0 1479 #define ssl_Release1stHandshakeLock(ss) \
michael@0 1480 { if (!ss->opt.noLocks) PZ_ExitMonitor((ss)->firstHandshakeLock); }
michael@0 1481 #define ssl_Have1stHandshakeLock(ss) \
michael@0 1482 (PZ_InMonitor((ss)->firstHandshakeLock))
michael@0 1483
michael@0 1484 /* ssl3HandshakeLock -> xmitBufLock */
michael@0 1485 #define ssl_GetSSL3HandshakeLock(ss) \
michael@0 1486 { if (!ss->opt.noLocks) { \
michael@0 1487 PORT_Assert(!ssl_HaveXmitBufLock(ss)); \
michael@0 1488 PZ_EnterMonitor((ss)->ssl3HandshakeLock); \
michael@0 1489 } }
michael@0 1490 #define ssl_ReleaseSSL3HandshakeLock(ss) \
michael@0 1491 { if (!ss->opt.noLocks) PZ_ExitMonitor((ss)->ssl3HandshakeLock); }
michael@0 1492 #define ssl_HaveSSL3HandshakeLock(ss) \
michael@0 1493 (PZ_InMonitor((ss)->ssl3HandshakeLock))
michael@0 1494
michael@0 1495 #define ssl_GetSpecReadLock(ss) \
michael@0 1496 { if (!ss->opt.noLocks) NSSRWLock_LockRead((ss)->specLock); }
michael@0 1497 #define ssl_ReleaseSpecReadLock(ss) \
michael@0 1498 { if (!ss->opt.noLocks) NSSRWLock_UnlockRead((ss)->specLock); }
michael@0 1499 /* NSSRWLock_HaveReadLock is not exported so there's no
michael@0 1500 * ssl_HaveSpecReadLock macro. */
michael@0 1501
michael@0 1502 #define ssl_GetSpecWriteLock(ss) \
michael@0 1503 { if (!ss->opt.noLocks) NSSRWLock_LockWrite((ss)->specLock); }
michael@0 1504 #define ssl_ReleaseSpecWriteLock(ss) \
michael@0 1505 { if (!ss->opt.noLocks) NSSRWLock_UnlockWrite((ss)->specLock); }
michael@0 1506 #define ssl_HaveSpecWriteLock(ss) \
michael@0 1507 (NSSRWLock_HaveWriteLock((ss)->specLock))
michael@0 1508
michael@0 1509 /* recvBufLock -> ssl3HandshakeLock -> xmitBufLock */
michael@0 1510 #define ssl_GetRecvBufLock(ss) \
michael@0 1511 { if (!ss->opt.noLocks) { \
michael@0 1512 PORT_Assert(!ssl_HaveSSL3HandshakeLock(ss)); \
michael@0 1513 PORT_Assert(!ssl_HaveXmitBufLock(ss)); \
michael@0 1514 PZ_EnterMonitor((ss)->recvBufLock); \
michael@0 1515 } }
michael@0 1516 #define ssl_ReleaseRecvBufLock(ss) \
michael@0 1517 { if (!ss->opt.noLocks) PZ_ExitMonitor( (ss)->recvBufLock); }
michael@0 1518 #define ssl_HaveRecvBufLock(ss) \
michael@0 1519 (PZ_InMonitor((ss)->recvBufLock))
michael@0 1520
michael@0 1521 /* xmitBufLock -> specLock */
michael@0 1522 #define ssl_GetXmitBufLock(ss) \
michael@0 1523 { if (!ss->opt.noLocks) PZ_EnterMonitor((ss)->xmitBufLock); }
michael@0 1524 #define ssl_ReleaseXmitBufLock(ss) \
michael@0 1525 { if (!ss->opt.noLocks) PZ_ExitMonitor( (ss)->xmitBufLock); }
michael@0 1526 #define ssl_HaveXmitBufLock(ss) \
michael@0 1527 (PZ_InMonitor((ss)->xmitBufLock))
michael@0 1528
michael@0 1529 /* Placeholder value used in version ranges when SSL 3.0 and all
michael@0 1530 * versions of TLS are disabled.
michael@0 1531 */
michael@0 1532 #define SSL_LIBRARY_VERSION_NONE 0
michael@0 1533
michael@0 1534 /* SSL_LIBRARY_VERSION_MAX_SUPPORTED is the maximum version that this version
michael@0 1535 * of libssl supports. Applications should use SSL_VersionRangeGetSupported at
michael@0 1536 * runtime to determine which versions are supported by the version of libssl
michael@0 1537 * in use.
michael@0 1538 */
michael@0 1539 #define SSL_LIBRARY_VERSION_MAX_SUPPORTED SSL_LIBRARY_VERSION_TLS_1_2
michael@0 1540
michael@0 1541 /* Rename this macro SSL_ALL_VERSIONS_DISABLED when SSL 2.0 is removed. */
michael@0 1542 #define SSL3_ALL_VERSIONS_DISABLED(vrange) \
michael@0 1543 ((vrange)->min == SSL_LIBRARY_VERSION_NONE)
michael@0 1544
michael@0 1545 extern PRBool ssl3_VersionIsSupported(SSLProtocolVariant protocolVariant,
michael@0 1546 SSL3ProtocolVersion version);
michael@0 1547
michael@0 1548 extern SECStatus ssl3_KeyAndMacDeriveBypass(ssl3CipherSpec * pwSpec,
michael@0 1549 const unsigned char * cr, const unsigned char * sr,
michael@0 1550 PRBool isTLS, PRBool isExport);
michael@0 1551 extern SECStatus ssl3_MasterKeyDeriveBypass( ssl3CipherSpec * pwSpec,
michael@0 1552 const unsigned char * cr, const unsigned char * sr,
michael@0 1553 const SECItem * pms, PRBool isTLS, PRBool isRSA);
michael@0 1554
michael@0 1555 /* These functions are called from secnav, even though they're "private". */
michael@0 1556
michael@0 1557 extern int ssl2_SendErrorMessage(struct sslSocketStr *ss, int error);
michael@0 1558 extern int SSL_RestartHandshakeAfterCertReq(struct sslSocketStr *ss,
michael@0 1559 CERTCertificate *cert,
michael@0 1560 SECKEYPrivateKey *key,
michael@0 1561 CERTCertificateList *certChain);
michael@0 1562 extern sslSocket *ssl_FindSocket(PRFileDesc *fd);
michael@0 1563 extern void ssl_FreeSocket(struct sslSocketStr *ssl);
michael@0 1564 extern SECStatus SSL3_SendAlert(sslSocket *ss, SSL3AlertLevel level,
michael@0 1565 SSL3AlertDescription desc);
michael@0 1566 extern SECStatus ssl3_DecodeError(sslSocket *ss);
michael@0 1567
michael@0 1568 extern SECStatus ssl3_AuthCertificateComplete(sslSocket *ss, PRErrorCode error);
michael@0 1569
michael@0 1570 /*
michael@0 1571 * for dealing with SSL 3.0 clients sending SSL 2.0 format hellos
michael@0 1572 */
michael@0 1573 extern SECStatus ssl3_HandleV2ClientHello(
michael@0 1574 sslSocket *ss, unsigned char *buffer, int length);
michael@0 1575 extern SECStatus ssl3_StartHandshakeHash(
michael@0 1576 sslSocket *ss, unsigned char *buf, int length);
michael@0 1577
michael@0 1578 /*
michael@0 1579 * SSL3 specific routines
michael@0 1580 */
michael@0 1581 SECStatus ssl3_SendClientHello(sslSocket *ss, PRBool resending);
michael@0 1582
michael@0 1583 /*
michael@0 1584 * input into the SSL3 machinery from the actualy network reading code
michael@0 1585 */
michael@0 1586 SECStatus ssl3_HandleRecord(
michael@0 1587 sslSocket *ss, SSL3Ciphertext *cipher, sslBuffer *out);
michael@0 1588
michael@0 1589 int ssl3_GatherAppDataRecord(sslSocket *ss, int flags);
michael@0 1590 int ssl3_GatherCompleteHandshake(sslSocket *ss, int flags);
michael@0 1591 /*
michael@0 1592 * When talking to export clients or using export cipher suites, servers
michael@0 1593 * with public RSA keys larger than 512 bits need to use a 512-bit public
michael@0 1594 * key, signed by the larger key. The smaller key is a "step down" key.
michael@0 1595 * Generate that key pair and keep it around.
michael@0 1596 */
michael@0 1597 extern SECStatus ssl3_CreateRSAStepDownKeys(sslSocket *ss);
michael@0 1598
michael@0 1599 #ifndef NSS_DISABLE_ECC
michael@0 1600 extern void ssl3_FilterECCipherSuitesByServerCerts(sslSocket *ss);
michael@0 1601 extern PRBool ssl3_IsECCEnabled(sslSocket *ss);
michael@0 1602 extern SECStatus ssl3_DisableECCSuites(sslSocket * ss,
michael@0 1603 const ssl3CipherSuite * suite);
michael@0 1604 extern PRUint32 ssl3_GetSupportedECCurveMask(sslSocket *ss);
michael@0 1605
michael@0 1606
michael@0 1607 /* Macro for finding a curve equivalent in strength to RSA key's */
michael@0 1608 #define SSL_RSASTRENGTH_TO_ECSTRENGTH(s) \
michael@0 1609 ((s <= 1024) ? 160 \
michael@0 1610 : ((s <= 2048) ? 224 \
michael@0 1611 : ((s <= 3072) ? 256 \
michael@0 1612 : ((s <= 7168) ? 384 : 521 ) ) ) )
michael@0 1613
michael@0 1614 /* Types and names of elliptic curves used in TLS */
michael@0 1615 typedef enum { ec_type_explicitPrime = 1,
michael@0 1616 ec_type_explicitChar2Curve = 2,
michael@0 1617 ec_type_named
michael@0 1618 } ECType;
michael@0 1619
michael@0 1620 typedef enum { ec_noName = 0,
michael@0 1621 ec_sect163k1 = 1,
michael@0 1622 ec_sect163r1 = 2,
michael@0 1623 ec_sect163r2 = 3,
michael@0 1624 ec_sect193r1 = 4,
michael@0 1625 ec_sect193r2 = 5,
michael@0 1626 ec_sect233k1 = 6,
michael@0 1627 ec_sect233r1 = 7,
michael@0 1628 ec_sect239k1 = 8,
michael@0 1629 ec_sect283k1 = 9,
michael@0 1630 ec_sect283r1 = 10,
michael@0 1631 ec_sect409k1 = 11,
michael@0 1632 ec_sect409r1 = 12,
michael@0 1633 ec_sect571k1 = 13,
michael@0 1634 ec_sect571r1 = 14,
michael@0 1635 ec_secp160k1 = 15,
michael@0 1636 ec_secp160r1 = 16,
michael@0 1637 ec_secp160r2 = 17,
michael@0 1638 ec_secp192k1 = 18,
michael@0 1639 ec_secp192r1 = 19,
michael@0 1640 ec_secp224k1 = 20,
michael@0 1641 ec_secp224r1 = 21,
michael@0 1642 ec_secp256k1 = 22,
michael@0 1643 ec_secp256r1 = 23,
michael@0 1644 ec_secp384r1 = 24,
michael@0 1645 ec_secp521r1 = 25,
michael@0 1646 ec_pastLastName
michael@0 1647 } ECName;
michael@0 1648
michael@0 1649 extern SECStatus ssl3_ECName2Params(PLArenaPool *arena, ECName curve,
michael@0 1650 SECKEYECParams *params);
michael@0 1651 ECName ssl3_GetCurveWithECKeyStrength(PRUint32 curvemsk, int requiredECCbits);
michael@0 1652
michael@0 1653
michael@0 1654 #endif /* NSS_DISABLE_ECC */
michael@0 1655
michael@0 1656 extern SECStatus ssl3_CipherPrefSetDefault(ssl3CipherSuite which, PRBool on);
michael@0 1657 extern SECStatus ssl3_CipherPrefGetDefault(ssl3CipherSuite which, PRBool *on);
michael@0 1658 extern SECStatus ssl2_CipherPrefSetDefault(PRInt32 which, PRBool enabled);
michael@0 1659 extern SECStatus ssl2_CipherPrefGetDefault(PRInt32 which, PRBool *enabled);
michael@0 1660
michael@0 1661 extern SECStatus ssl3_CipherPrefSet(sslSocket *ss, ssl3CipherSuite which, PRBool on);
michael@0 1662 extern SECStatus ssl3_CipherPrefGet(sslSocket *ss, ssl3CipherSuite which, PRBool *on);
michael@0 1663 extern SECStatus ssl2_CipherPrefSet(sslSocket *ss, PRInt32 which, PRBool enabled);
michael@0 1664 extern SECStatus ssl2_CipherPrefGet(sslSocket *ss, PRInt32 which, PRBool *enabled);
michael@0 1665
michael@0 1666 extern SECStatus ssl3_SetPolicy(ssl3CipherSuite which, PRInt32 policy);
michael@0 1667 extern SECStatus ssl3_GetPolicy(ssl3CipherSuite which, PRInt32 *policy);
michael@0 1668 extern SECStatus ssl2_SetPolicy(PRInt32 which, PRInt32 policy);
michael@0 1669 extern SECStatus ssl2_GetPolicy(PRInt32 which, PRInt32 *policy);
michael@0 1670
michael@0 1671 extern void ssl2_InitSocketPolicy(sslSocket *ss);
michael@0 1672 extern void ssl3_InitSocketPolicy(sslSocket *ss);
michael@0 1673
michael@0 1674 extern SECStatus ssl3_ConstructV2CipherSpecsHack(sslSocket *ss,
michael@0 1675 unsigned char *cs, int *size);
michael@0 1676
michael@0 1677 extern SECStatus ssl3_RedoHandshake(sslSocket *ss, PRBool flushCache);
michael@0 1678 extern SECStatus ssl3_HandleHandshakeMessage(sslSocket *ss, SSL3Opaque *b,
michael@0 1679 PRUint32 length);
michael@0 1680
michael@0 1681 extern void ssl3_DestroySSL3Info(sslSocket *ss);
michael@0 1682
michael@0 1683 extern SECStatus ssl3_NegotiateVersion(sslSocket *ss,
michael@0 1684 SSL3ProtocolVersion peerVersion,
michael@0 1685 PRBool allowLargerPeerVersion);
michael@0 1686
michael@0 1687 extern SECStatus ssl_GetPeerInfo(sslSocket *ss);
michael@0 1688
michael@0 1689 #ifndef NSS_DISABLE_ECC
michael@0 1690 /* ECDH functions */
michael@0 1691 extern SECStatus ssl3_SendECDHClientKeyExchange(sslSocket * ss,
michael@0 1692 SECKEYPublicKey * svrPubKey);
michael@0 1693 extern SECStatus ssl3_HandleECDHServerKeyExchange(sslSocket *ss,
michael@0 1694 SSL3Opaque *b, PRUint32 length);
michael@0 1695 extern SECStatus ssl3_HandleECDHClientKeyExchange(sslSocket *ss,
michael@0 1696 SSL3Opaque *b, PRUint32 length,
michael@0 1697 SECKEYPublicKey *srvrPubKey,
michael@0 1698 SECKEYPrivateKey *srvrPrivKey);
michael@0 1699 extern SECStatus ssl3_SendECDHServerKeyExchange(sslSocket *ss,
michael@0 1700 const SSL3SignatureAndHashAlgorithm *sigAndHash);
michael@0 1701 #endif
michael@0 1702
michael@0 1703 extern SECStatus ssl3_ComputeCommonKeyHash(SECOidTag hashAlg,
michael@0 1704 PRUint8 * hashBuf,
michael@0 1705 unsigned int bufLen, SSL3Hashes *hashes,
michael@0 1706 PRBool bypassPKCS11);
michael@0 1707 extern void ssl3_DestroyCipherSpec(ssl3CipherSpec *spec, PRBool freeSrvName);
michael@0 1708 extern SECStatus ssl3_InitPendingCipherSpec(sslSocket *ss, PK11SymKey *pms);
michael@0 1709 extern SECStatus ssl3_AppendHandshake(sslSocket *ss, const void *void_src,
michael@0 1710 PRInt32 bytes);
michael@0 1711 extern SECStatus ssl3_AppendHandshakeHeader(sslSocket *ss,
michael@0 1712 SSL3HandshakeType t, PRUint32 length);
michael@0 1713 extern SECStatus ssl3_AppendHandshakeNumber(sslSocket *ss, PRInt32 num,
michael@0 1714 PRInt32 lenSize);
michael@0 1715 extern SECStatus ssl3_AppendHandshakeVariable( sslSocket *ss,
michael@0 1716 const SSL3Opaque *src, PRInt32 bytes, PRInt32 lenSize);
michael@0 1717 extern SECStatus ssl3_AppendSignatureAndHashAlgorithm(sslSocket *ss,
michael@0 1718 const SSL3SignatureAndHashAlgorithm* sigAndHash);
michael@0 1719 extern SECStatus ssl3_ConsumeHandshake(sslSocket *ss, void *v, PRInt32 bytes,
michael@0 1720 SSL3Opaque **b, PRUint32 *length);
michael@0 1721 extern PRInt32 ssl3_ConsumeHandshakeNumber(sslSocket *ss, PRInt32 bytes,
michael@0 1722 SSL3Opaque **b, PRUint32 *length);
michael@0 1723 extern SECStatus ssl3_ConsumeHandshakeVariable(sslSocket *ss, SECItem *i,
michael@0 1724 PRInt32 bytes, SSL3Opaque **b, PRUint32 *length);
michael@0 1725 extern SECOidTag ssl3_TLSHashAlgorithmToOID(int hashFunc);
michael@0 1726 extern SECStatus ssl3_CheckSignatureAndHashAlgorithmConsistency(
michael@0 1727 const SSL3SignatureAndHashAlgorithm *sigAndHash,
michael@0 1728 CERTCertificate* cert);
michael@0 1729 extern SECStatus ssl3_ConsumeSignatureAndHashAlgorithm(sslSocket *ss,
michael@0 1730 SSL3Opaque **b, PRUint32 *length,
michael@0 1731 SSL3SignatureAndHashAlgorithm *out);
michael@0 1732 extern SECStatus ssl3_SignHashes(SSL3Hashes *hash, SECKEYPrivateKey *key,
michael@0 1733 SECItem *buf, PRBool isTLS);
michael@0 1734 extern SECStatus ssl3_VerifySignedHashes(SSL3Hashes *hash,
michael@0 1735 CERTCertificate *cert, SECItem *buf, PRBool isTLS,
michael@0 1736 void *pwArg);
michael@0 1737 extern SECStatus ssl3_CacheWrappedMasterSecret(sslSocket *ss,
michael@0 1738 sslSessionID *sid, ssl3CipherSpec *spec,
michael@0 1739 SSL3KEAType effectiveExchKeyType);
michael@0 1740
michael@0 1741 /* Functions that handle ClientHello and ServerHello extensions. */
michael@0 1742 extern SECStatus ssl3_HandleServerNameXtn(sslSocket * ss,
michael@0 1743 PRUint16 ex_type, SECItem *data);
michael@0 1744 extern SECStatus ssl3_HandleSupportedCurvesXtn(sslSocket * ss,
michael@0 1745 PRUint16 ex_type, SECItem *data);
michael@0 1746 extern SECStatus ssl3_HandleSupportedPointFormatsXtn(sslSocket * ss,
michael@0 1747 PRUint16 ex_type, SECItem *data);
michael@0 1748 extern SECStatus ssl3_ClientHandleSessionTicketXtn(sslSocket *ss,
michael@0 1749 PRUint16 ex_type, SECItem *data);
michael@0 1750 extern SECStatus ssl3_ServerHandleSessionTicketXtn(sslSocket *ss,
michael@0 1751 PRUint16 ex_type, SECItem *data);
michael@0 1752
michael@0 1753 /* ClientHello and ServerHello extension senders.
michael@0 1754 * Note that not all extension senders are exposed here; only those that
michael@0 1755 * that need exposure.
michael@0 1756 */
michael@0 1757 extern PRInt32 ssl3_SendSessionTicketXtn(sslSocket *ss, PRBool append,
michael@0 1758 PRUint32 maxBytes);
michael@0 1759
michael@0 1760 /* ClientHello and ServerHello extension senders.
michael@0 1761 * The code is in ssl3ext.c.
michael@0 1762 */
michael@0 1763 extern PRInt32 ssl3_SendServerNameXtn(sslSocket *ss, PRBool append,
michael@0 1764 PRUint32 maxBytes);
michael@0 1765
michael@0 1766 /* Assigns new cert, cert chain and keys to ss->serverCerts
michael@0 1767 * struct. If certChain is NULL, tries to find one. Aborts if
michael@0 1768 * fails to do so. If cert and keyPair are NULL - unconfigures
michael@0 1769 * sslSocket of kea type.*/
michael@0 1770 extern SECStatus ssl_ConfigSecureServer(sslSocket *ss, CERTCertificate *cert,
michael@0 1771 const CERTCertificateList *certChain,
michael@0 1772 ssl3KeyPair *keyPair, SSLKEAType kea);
michael@0 1773
michael@0 1774 #ifndef NSS_DISABLE_ECC
michael@0 1775 extern PRInt32 ssl3_SendSupportedCurvesXtn(sslSocket *ss,
michael@0 1776 PRBool append, PRUint32 maxBytes);
michael@0 1777 extern PRInt32 ssl3_SendSupportedPointFormatsXtn(sslSocket *ss,
michael@0 1778 PRBool append, PRUint32 maxBytes);
michael@0 1779 #endif
michael@0 1780
michael@0 1781 /* call the registered extension handlers. */
michael@0 1782 extern SECStatus ssl3_HandleHelloExtensions(sslSocket *ss,
michael@0 1783 SSL3Opaque **b, PRUint32 *length);
michael@0 1784
michael@0 1785 /* Hello Extension related routines. */
michael@0 1786 extern PRBool ssl3_ExtensionNegotiated(sslSocket *ss, PRUint16 ex_type);
michael@0 1787 extern void ssl3_SetSIDSessionTicket(sslSessionID *sid,
michael@0 1788 /*in/out*/ NewSessionTicket *session_ticket);
michael@0 1789 extern SECStatus ssl3_SendNewSessionTicket(sslSocket *ss);
michael@0 1790 extern PRBool ssl_GetSessionTicketKeys(unsigned char *keyName,
michael@0 1791 unsigned char *encKey, unsigned char *macKey);
michael@0 1792 extern PRBool ssl_GetSessionTicketKeysPKCS11(SECKEYPrivateKey *svrPrivKey,
michael@0 1793 SECKEYPublicKey *svrPubKey, void *pwArg,
michael@0 1794 unsigned char *keyName, PK11SymKey **aesKey,
michael@0 1795 PK11SymKey **macKey);
michael@0 1796
michael@0 1797 /* Tell clients to consider tickets valid for this long. */
michael@0 1798 #define TLS_EX_SESS_TICKET_LIFETIME_HINT (2 * 24 * 60 * 60) /* 2 days */
michael@0 1799 #define TLS_EX_SESS_TICKET_VERSION (0x0100)
michael@0 1800
michael@0 1801 extern SECStatus ssl3_ValidateNextProtoNego(const unsigned char* data,
michael@0 1802 unsigned int length);
michael@0 1803
michael@0 1804 /* Construct a new NSPR socket for the app to use */
michael@0 1805 extern PRFileDesc *ssl_NewPRSocket(sslSocket *ss, PRFileDesc *fd);
michael@0 1806 extern void ssl_FreePRSocket(PRFileDesc *fd);
michael@0 1807
michael@0 1808 /* Internal config function so SSL3 can initialize the present state of
michael@0 1809 * various ciphers */
michael@0 1810 extern int ssl3_config_match_init(sslSocket *);
michael@0 1811
michael@0 1812
michael@0 1813 /* Create a new ref counted key pair object from two keys. */
michael@0 1814 extern ssl3KeyPair * ssl3_NewKeyPair( SECKEYPrivateKey * privKey,
michael@0 1815 SECKEYPublicKey * pubKey);
michael@0 1816
michael@0 1817 /* get a new reference (bump ref count) to an ssl3KeyPair. */
michael@0 1818 extern ssl3KeyPair * ssl3_GetKeyPairRef(ssl3KeyPair * keyPair);
michael@0 1819
michael@0 1820 /* Decrement keypair's ref count and free if zero. */
michael@0 1821 extern void ssl3_FreeKeyPair(ssl3KeyPair * keyPair);
michael@0 1822
michael@0 1823 /* calls for accessing wrapping keys across processes. */
michael@0 1824 extern PRBool
michael@0 1825 ssl_GetWrappingKey( PRInt32 symWrapMechIndex,
michael@0 1826 SSL3KEAType exchKeyType,
michael@0 1827 SSLWrappedSymWrappingKey *wswk);
michael@0 1828
michael@0 1829 /* The caller passes in the new value it wants
michael@0 1830 * to set. This code tests the wrapped sym key entry in the file on disk.
michael@0 1831 * If it is uninitialized, this function writes the caller's value into
michael@0 1832 * the disk entry, and returns false.
michael@0 1833 * Otherwise, it overwrites the caller's wswk with the value obtained from
michael@0 1834 * the disk, and returns PR_TRUE.
michael@0 1835 * This is all done while holding the locks/semaphores necessary to make
michael@0 1836 * the operation atomic.
michael@0 1837 */
michael@0 1838 extern PRBool
michael@0 1839 ssl_SetWrappingKey(SSLWrappedSymWrappingKey *wswk);
michael@0 1840
michael@0 1841 /* get rid of the symmetric wrapping key references. */
michael@0 1842 extern SECStatus SSL3_ShutdownServerCache(void);
michael@0 1843
michael@0 1844 extern SECStatus ssl_InitSymWrapKeysLock(void);
michael@0 1845
michael@0 1846 extern SECStatus ssl_FreeSymWrapKeysLock(void);
michael@0 1847
michael@0 1848 extern SECStatus ssl_InitSessionCacheLocks(PRBool lazyInit);
michael@0 1849
michael@0 1850 extern SECStatus ssl_FreeSessionCacheLocks(void);
michael@0 1851
michael@0 1852
michael@0 1853 /**************** DTLS-specific functions **************/
michael@0 1854 extern void dtls_FreeQueuedMessage(DTLSQueuedMessage *msg);
michael@0 1855 extern void dtls_FreeQueuedMessages(PRCList *lst);
michael@0 1856 extern void dtls_FreeHandshakeMessages(PRCList *lst);
michael@0 1857
michael@0 1858 extern SECStatus dtls_HandleHandshake(sslSocket *ss, sslBuffer *origBuf);
michael@0 1859 extern SECStatus dtls_HandleHelloVerifyRequest(sslSocket *ss,
michael@0 1860 SSL3Opaque *b, PRUint32 length);
michael@0 1861 extern SECStatus dtls_StageHandshakeMessage(sslSocket *ss);
michael@0 1862 extern SECStatus dtls_QueueMessage(sslSocket *ss, SSL3ContentType type,
michael@0 1863 const SSL3Opaque *pIn, PRInt32 nIn);
michael@0 1864 extern SECStatus dtls_FlushHandshakeMessages(sslSocket *ss, PRInt32 flags);
michael@0 1865 extern SECStatus dtls_CompressMACEncryptRecord(sslSocket *ss,
michael@0 1866 DTLSEpoch epoch,
michael@0 1867 PRBool use_epoch,
michael@0 1868 SSL3ContentType type,
michael@0 1869 const SSL3Opaque *pIn,
michael@0 1870 PRUint32 contentLen,
michael@0 1871 sslBuffer *wrBuf);
michael@0 1872 SECStatus ssl3_DisableNonDTLSSuites(sslSocket * ss);
michael@0 1873 extern SECStatus dtls_StartTimer(sslSocket *ss, DTLSTimerCb cb);
michael@0 1874 extern SECStatus dtls_RestartTimer(sslSocket *ss, PRBool backoff,
michael@0 1875 DTLSTimerCb cb);
michael@0 1876 extern void dtls_CheckTimer(sslSocket *ss);
michael@0 1877 extern void dtls_CancelTimer(sslSocket *ss);
michael@0 1878 extern void dtls_FinishedTimerCb(sslSocket *ss);
michael@0 1879 extern void dtls_SetMTU(sslSocket *ss, PRUint16 advertised);
michael@0 1880 extern void dtls_InitRecvdRecords(DTLSRecvdRecords *records);
michael@0 1881 extern int dtls_RecordGetRecvd(DTLSRecvdRecords *records, PRUint64 seq);
michael@0 1882 extern void dtls_RecordSetRecvd(DTLSRecvdRecords *records, PRUint64 seq);
michael@0 1883 extern void dtls_RehandshakeCleanup(sslSocket *ss);
michael@0 1884 extern SSL3ProtocolVersion
michael@0 1885 dtls_TLSVersionToDTLSVersion(SSL3ProtocolVersion tlsv);
michael@0 1886 extern SSL3ProtocolVersion
michael@0 1887 dtls_DTLSVersionToTLSVersion(SSL3ProtocolVersion dtlsv);
michael@0 1888
michael@0 1889 /********************** misc calls *********************/
michael@0 1890
michael@0 1891 #ifdef DEBUG
michael@0 1892 extern void ssl3_CheckCipherSuiteOrderConsistency();
michael@0 1893 #endif
michael@0 1894
michael@0 1895 extern int ssl_MapLowLevelError(int hiLevelError);
michael@0 1896
michael@0 1897 extern PRUint32 ssl_Time(void);
michael@0 1898
michael@0 1899 extern void SSL_AtomicIncrementLong(long * x);
michael@0 1900
michael@0 1901 SECStatus SSL_DisableDefaultExportCipherSuites(void);
michael@0 1902 SECStatus SSL_DisableExportCipherSuites(PRFileDesc * fd);
michael@0 1903 PRBool SSL_IsExportCipherSuite(PRUint16 cipherSuite);
michael@0 1904
michael@0 1905 extern SECStatus
michael@0 1906 ssl3_TLSPRFWithMasterSecret(ssl3CipherSpec *spec,
michael@0 1907 const char *label, unsigned int labelLen,
michael@0 1908 const unsigned char *val, unsigned int valLen,
michael@0 1909 unsigned char *out, unsigned int outLen);
michael@0 1910
michael@0 1911 #ifdef TRACE
michael@0 1912 #define SSL_TRACE(msg) ssl_Trace msg
michael@0 1913 #else
michael@0 1914 #define SSL_TRACE(msg)
michael@0 1915 #endif
michael@0 1916
michael@0 1917 void ssl_Trace(const char *format, ...);
michael@0 1918
michael@0 1919 SEC_END_PROTOS
michael@0 1920
michael@0 1921 #if defined(XP_UNIX) || defined(XP_OS2) || defined(XP_BEOS)
michael@0 1922 #define SSL_GETPID getpid
michael@0 1923 #elif defined(WIN32)
michael@0 1924 extern int __cdecl _getpid(void);
michael@0 1925 #define SSL_GETPID _getpid
michael@0 1926 #else
michael@0 1927 #define SSL_GETPID() 0
michael@0 1928 #endif
michael@0 1929
michael@0 1930 #endif /* __sslimpl_h_ */

mercurial