Bug Summary

File:root/firefox-clang/security/nss/lib/ssl/sslimpl.h
Warning:line 660, column 16
Excessive padding in 'struct SSL3HandshakeStateStr' (57 padding bytes, where 1 is optimal). Optimal fields order: md5, sha, shaEchInner, shaPostHandshake, kea_def, suite_def, msg_len, clientAuthSignatureSchemes, restartTarget, rtTimer, ackTimer, hdTimer, currentSecret, resumptionMasterSecret, dheSecret, clientEarlyTrafficSecret, clientHsTrafficSecret, serverHsTrafficSecret, clientTrafficSecret, serverTrafficSecret, earlyExporterSecret, exporterSecret, rttEstimate, echHpkeCtx, echPublicName, grease, dtlsHandhakeKeyUpdateMessage, chExtensionPermutation, remoteExtensions, echOuterExtensions, lastMessageFlight, cipherSpecs, bufferedEarlyData, psks, dtlsSentHandshake, dtlsRcvdHandshake, messages, echInnerMessages, msg_body, recvdFragments, cookie, srvVirtName, fakeSid, greaseEchBuf, dtls13ClientMessageBuffer, newSessionTicket, timers, ws, hashType, signatureScheme, header_bytes, msg_type, isResuming, sendingSCSV, receivedNewSessionTicket, clientCertificatePending, clientAuthSignatureSchemesLen, authCertificatePending, canFalseStart, preliminaryInfo, recvdHighWater, isKeyUpdateInProgress, allowPreviousEpoch, rtRetries, zeroRttState, zeroRttIgnore, helloRetry, dtlsReceivedHVR, receivedCcs, rejectCcs, clientCertRequested, endOfFlight, echAccepted, echDecided, echInvalidExtension, keyUpdateDeferred, deferredKeyUpdateRequest, kea_def_mutable, cipher_suite, finishedBytes, sendMessageSeq, maxMessageSent, recvMessageSeq, zeroRttSuite, ticketNonce, greaseEchSize, server_random, client_random, client_inner_random, finishedMsgs, consider reordering the fields or adding explicit padding members

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name authcert.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/security/nss/lib/ssl/ssl_ssl -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/security/nss/lib/ssl/ssl_ssl -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG -D NSS_FIPS_DISABLED -D NSS_NO_INIT_SUPPORT -D NSS_X86_OR_X64 -D NSS_X64 -D NSS_USE_64 -D NSS_ALLOW_SSLKEYLOGFILE -D USE_UTIL_DIRECTLY -D NO_NSPR_10_SUPPORT -D SSL_DISABLE_DEPRECATED_CIPHER_SUITE_NAMES -D LINUX2_1 -D LINUX -D linux -D _DEFAULT_SOURCE -D _BSD_SOURCE -D _POSIX_SOURCE -D SDB_MEASURE_USE_TEMP_DIR -D HAVE_STRERROR -D XP_UNIX -D _REENTRANT -D NSS_DISABLE_DBM -D NSS_DISABLE_LIBPKIX -D NSS_USE_PKCS5_PBKD2_PARAMS2_ONLY -D SOFTOKEN_USE_PKCS5_PBKD2_PARAMS2_ONLY -I /root/firefox-clang/security/nss/lib/ssl -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/security/nss/lib/ssl/ssl_ssl -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/private/nss -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -D MOZILLA_CLIENT -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=tautological-type-limit-compare -Wno-range-loop-analysis -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-unknown-warning-option -Wno-character-conversion -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-09-01-224014-2642839-1 -x c /root/firefox-clang/security/nss/lib/ssl/authcert.c
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is PRIVATE to SSL and should be the first thing included by
4 * any SSL implementation file.
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9
10#ifndef __sslimpl_h_
11#define __sslimpl_h_
12
13#ifdef DEBUG1
14#undef NDEBUG
15#else
16#undef NDEBUG
17#define NDEBUG
18#endif
19#include "secport.h"
20#include "secerr.h"
21#include "sslerr.h"
22#include "sslexp.h"
23#include "ssl3prot.h"
24#include "hasht.h"
25#include "cryptohi.h"
26#include "pkcs11t.h"
27#if defined(XP_UNIX1)
28#include "unistd.h"
29#elif defined(XP_WIN)
30#include <process.h>
31#endif
32#include "nssrwlk.h"
33#include "prthread.h"
34#include "prclist.h"
35#include "private/pprthred.h"
36
37#include "sslt.h" /* for some formerly private types, now public */
38
39typedef struct sslSocketStr sslSocket;
40typedef struct sslNamedGroupDefStr sslNamedGroupDef;
41typedef struct sslEchConfigStr sslEchConfig;
42typedef struct sslEchConfigContentsStr sslEchConfigContents;
43typedef struct sslEchCookieDataStr sslEchCookieData;
44typedef struct sslEchXtnStateStr sslEchXtnState;
45typedef struct sslPskStr sslPsk;
46typedef struct sslDelegatedCredentialStr sslDelegatedCredential;
47typedef struct sslEphemeralKeyPairStr sslEphemeralKeyPair;
48typedef struct TLS13KeyShareEntryStr TLS13KeyShareEntry;
49typedef struct tlsSignOrVerifyContextStr tlsSignOrVerifyContext;
50
51#include "sslencode.h"
52#include "sslexp.h"
53#include "ssl3ext.h"
54#include "sslspec.h"
55
56#if defined(DEBUG1) || defined(TRACE)
57#ifdef __cplusplus
58#define Debug 1
59#else
60extern int Debug;
61#endif
62#else
63#undef Debug
64#endif
65
66#if defined(DEBUG1) && !defined(TRACE) && !defined(NISCC_TEST)
67#define TRACE
68#endif
69
70#ifdef TRACE
71#define SSL_TRC(a, b)if (ssl_trace >= (a)) ssl_Trace b \
72 if (ssl_trace >= (a)) \
73 ssl_Trace b
74#define PRINT_BUF(a, b)if (ssl_trace >= (a)) ssl_PrintBuf b \
75 if (ssl_trace >= (a)) \
76 ssl_PrintBuf b
77#define PRINT_KEY(a, b)if (ssl_trace >= (a)) ssl_PrintKey b \
78 if (ssl_trace >= (a)) \
79 ssl_PrintKey b
80#else
81#define SSL_TRC(a, b)if (ssl_trace >= (a)) ssl_Trace b
82#define PRINT_BUF(a, b)if (ssl_trace >= (a)) ssl_PrintBuf b
83#define PRINT_KEY(a, b)if (ssl_trace >= (a)) ssl_PrintKey b
84#endif
85
86#ifdef DEBUG1
87#define SSL_DBG(b)if (ssl_debug) ssl_Trace b \
88 if (ssl_debug) \
89 ssl_Trace b
90#else
91#define SSL_DBG(b)if (ssl_debug) ssl_Trace b
92#endif
93
94#define LSB(x)((unsigned char)((x) & 0xff)) ((unsigned char)((x) & 0xff))
95#define MSB(x)((unsigned char)(((unsigned)(x)) >> 8)) ((unsigned char)(((unsigned)(x)) >> 8))
96
97#define CONST_CAST(T, X)((T *)(X)) ((T *)(X))
98
99/************************************************************************/
100
101typedef enum { SSLAppOpRead = 0,
102 SSLAppOpWrite,
103 SSLAppOpRDWR,
104 SSLAppOpPost,
105 SSLAppOpHeader
106} SSLAppOperation;
107
108#define SSL3_SESSIONID_BYTES32 32
109
110#define SSL_MIN_CHALLENGE_BYTES16 16
111#define SSL_MAX_CHALLENGE_BYTES32 32
112
113#define SSL3_MASTER_SECRET_LENGTH48 48
114
115/* number of wrap mechanisms potentially used to wrap master secrets. */
116#define SSL_NUM_WRAP_MECHS15 15
117#define SSL_NUM_WRAP_KEYS6 6
118
119/* This makes the cert cache entry exactly 4k. */
120#define SSL_MAX_CACHED_CERT_LEN4060 4060
121
122#ifndef BPB8
123#define BPB8 8 /* Bits Per Byte */
124#endif
125
126/* The default value from RFC 4347 is 1s, which is too slow. */
127#define DTLS_RETRANSMIT_INITIAL_MS50 50
128/* The maximum time to wait between retransmissions. */
129#define DTLS_RETRANSMIT_MAX_MS10000 10000
130/* Time to wait in FINISHED state for retransmissions. */
131#define DTLS_RETRANSMIT_FINISHED_MS30000 30000
132
133/* default number of entries in namedGroupPreferences */
134#define SSL_NAMED_GROUP_COUNT36 36
135
136/* The maximum DH and RSA bit-length supported. */
137#define SSL_MAX_DH_KEY_BITS8192 8192
138#define SSL_MAX_RSA_KEY_BITS8192 8192
139
140/* are we signing or verifying */
141typedef enum {
142 sig_verify = 0,
143 sig_sign,
144} sslSignOrVerify;
145
146/* sign or verify context */
147struct tlsSignOrVerifyContextStr {
148 sslSignOrVerify type;
149 union {
150 SGNContext *sig;
151 VFYContext *vfy;
152 void *ptr;
153 } u;
154};
155
156/* Types and names of elliptic curves used in TLS */
157typedef enum {
158 ec_type_explicitPrime = 1, /* not supported */
159 ec_type_explicitChar2Curve = 2, /* not supported */
160 ec_type_named = 3
161} ECType;
162
163typedef enum {
164 ticket_allow_early_data = 1,
165 ticket_allow_psk_ke = 2,
166 ticket_allow_psk_dhe_ke = 4,
167 ticket_allow_psk_auth = 8,
168 ticket_allow_psk_sign_auth = 16
169} TLS13SessionTicketFlags;
170
171typedef enum {
172 update_not_requested = 0,
173 update_requested = 1
174} tls13KeyUpdateRequest;
175
176struct sslNamedGroupDefStr {
177 /* The name is the value that is encoded on the wire in TLS. */
178 SSLNamedGroup name;
179 /* The number of bits in the group. */
180 unsigned int bits;
181 /* The key exchange algorithm this group provides. */
182 SSLKEAType keaType;
183 /* The OID that identifies the group to PKCS11. This also determines
184 * whether the group is enabled in policy. */
185 SECOidTag oidTag;
186 /* Assume that the group is always supported. */
187 PRBool assumeSupported;
188};
189
190typedef struct sslConnectInfoStr sslConnectInfo;
191typedef struct sslGatherStr sslGather;
192typedef struct sslSecurityInfoStr sslSecurityInfo;
193typedef struct sslSessionIDStr sslSessionID;
194typedef struct sslSocketOpsStr sslSocketOps;
195
196typedef struct ssl3StateStr ssl3State;
197typedef struct ssl3CertNodeStr ssl3CertNode;
198typedef struct sslKeyPairStr sslKeyPair;
199typedef struct ssl3DHParamsStr ssl3DHParams;
200
201struct ssl3CertNodeStr {
202 struct ssl3CertNodeStr *next;
203 SECItem *derCert;
204};
205
206typedef SECStatus (*sslHandshakeFunc)(sslSocket *ss);
207
208void ssl_CacheSessionID(sslSocket *ss);
209void ssl_UncacheSessionID(sslSocket *ss);
210void ssl_ServerCacheSessionID(sslSessionID *sid, PRTime creationTime);
211void ssl_ServerUncacheSessionID(sslSessionID *sid);
212
213typedef sslSessionID *(*sslSessionIDLookupFunc)(PRTime ssl_now,
214 const PRIPv6Addr *addr,
215 unsigned char *sid,
216 unsigned int sidLen,
217 CERTCertDBHandle *dbHandle);
218
219/* Socket ops */
220struct sslSocketOpsStr {
221 int (*connect)(sslSocket *, const PRNetAddr *);
222 PRFileDesc *(*accept)(sslSocket *, PRNetAddr *);
223 int (*bind)(sslSocket *, const PRNetAddr *);
224 int (*listen)(sslSocket *, int);
225 int (*shutdown)(sslSocket *, int);
226 int (*close)(sslSocket *);
227
228 int (*recv)(sslSocket *, unsigned char *, int, int);
229
230 /* points to the higher-layer send func, e.g. ssl_SecureSend. */
231 int (*send)(sslSocket *, const unsigned char *, int, int);
232 int (*read)(sslSocket *, unsigned char *, int);
233 int (*write)(sslSocket *, const unsigned char *, int);
234
235 int (*getpeername)(sslSocket *, PRNetAddr *);
236 int (*getsockname)(sslSocket *, PRNetAddr *);
237};
238
239/* Flags interpreted by ssl send functions. */
240#define ssl_SEND_FLAG_FORCE_INTO_BUFFER0x40000000 0x40000000
241#define ssl_SEND_FLAG_NO_BUFFER0x20000000 0x20000000
242#define ssl_SEND_FLAG_NO_RETRANSMIT0x08000000 0x08000000 /* DTLS only */
243#define ssl_SEND_FLAG_MASK0x7f000000 0x7f000000
244
245/*
246** SSL3 cipher suite policy and preference struct.
247*/
248typedef struct {
249#if !defined(_WIN32)
250 unsigned int cipher_suite : 16;
251 unsigned int policy : 8;
252 unsigned int enabled : 1;
253 unsigned int isPresent : 1;
254#else
255 ssl3CipherSuite cipher_suite;
256 PRUint8 policy;
257 unsigned char enabled : 1;
258 unsigned char isPresent : 1;
259#endif
260} ssl3CipherSuiteCfg;
261
262#define ssl_V3_SUITES_IMPLEMENTED71 71
263
264#define MAX_DTLS_SRTP_CIPHER_SUITES4 4
265
266/* MAX_SIGNATURE_SCHEMES allows for all the values we support. */
267#define MAX_SIGNATURE_SCHEMES21 21
268
269#define MAX_SUPPORTED_CERTIFICATE_COMPRESSION_ALGS32 32
270
271typedef struct sslOptionsStr {
272 /* If SSL_SetNextProtoNego has been called, then this contains the
273 * list of supported protocols. */
274 SECItem nextProtoNego;
275 PRUint16 recordSizeLimit;
276
277 PRUint32 maxEarlyDataSize;
278 unsigned int useSecurity : 1;
279 unsigned int useSocks : 1;
280 unsigned int requestCertificate : 1;
281 unsigned int requireCertificate : 2;
282 unsigned int handshakeAsClient : 1;
283 unsigned int handshakeAsServer : 1;
284 unsigned int noCache : 1;
285 unsigned int fdx : 1;
286 unsigned int detectRollBack : 1;
287 unsigned int noLocks : 1;
288 unsigned int enableSessionTickets : 1;
289 unsigned int enableDeflate : 1; /* Deprecated. */
290 unsigned int enableRenegotiation : 2;
291 unsigned int requireSafeNegotiation : 1;
292 unsigned int enableFalseStart : 1;
293 unsigned int cbcRandomIV : 1;
294 unsigned int enableOCSPStapling : 1;
295 unsigned int enableALPN : 1;
296 unsigned int reuseServerECDHEKey : 1;
297 unsigned int enableFallbackSCSV : 1;
298 unsigned int enableServerDhe : 1;
299 unsigned int enableExtendedMS : 1;
300 unsigned int enableSignedCertTimestamps : 1;
301 unsigned int requireDHENamedGroups : 1;
302 unsigned int enable0RttData : 1;
303 unsigned int enableTls13CompatMode : 1;
304 unsigned int enableDtlsShortHeader : 1;
305 unsigned int enableHelloDowngradeCheck : 1;
306 unsigned int enableV2CompatibleHello : 1;
307 unsigned int enablePostHandshakeAuth : 1;
308 unsigned int enableDelegatedCredentials : 1;
309 unsigned int enableDtls13VersionCompat : 1;
310 unsigned int suppressEndOfEarlyData : 1;
311 unsigned int enableTls13GreaseEch : 1;
312 unsigned int enableTls13BackendEch : 1;
313 unsigned int callExtensionWriterOnEchInner : 1;
314 unsigned int enableEchXtnCompression : 1;
315 unsigned int enableGrease : 1;
316 unsigned int enableChXtnPermutation : 1;
317 unsigned int dbLoadCertChain : 1;
318} sslOptions;
319
320typedef enum { sslHandshakingUndetermined = 0,
321 sslHandshakingAsClient,
322 sslHandshakingAsServer
323} sslHandshakingType;
324
325#define SSL_LOCK_RANK_SPEC255 255
326
327/* These are the valid values for shutdownHow.
328** These values are each 1 greater than the NSPR values, and the code
329** depends on that relation to efficiently convert PR_SHUTDOWN values
330** into ssl_SHUTDOWN values. These values use one bit for read, and
331** another bit for write, and can be used as bitmasks.
332*/
333#define ssl_SHUTDOWN_NONE0 0 /* NOT shutdown at all */
334#define ssl_SHUTDOWN_RCV1 1 /* PR_SHUTDOWN_RCV +1 */
335#define ssl_SHUTDOWN_SEND2 2 /* PR_SHUTDOWN_SEND +1 */
336#define ssl_SHUTDOWN_BOTH3 3 /* PR_SHUTDOWN_BOTH +1 */
337
338/*
339** A gather object. Used to read some data until a count has been
340** satisfied. Primarily for support of async sockets.
341** Everything in here is protected by the recvBufLock.
342*/
343struct sslGatherStr {
344 int state; /* see GS_ values below. */
345
346 /* "buf" holds received plaintext SSL records, after decrypt and MAC check.
347 * recv'd ciphertext records are put in inbuf (see below), then decrypted
348 * into buf.
349 */
350 sslBuffer buf; /*recvBufLock*/
351
352 /* number of bytes previously read into hdr or inbuf.
353 ** (offset - writeOffset) is the number of ciphertext bytes read in but
354 ** not yet deciphered.
355 */
356 unsigned int offset;
357
358 /* number of bytes to read in next call to ssl_DefRecv (recv) */
359 unsigned int remainder;
360
361 /* DoRecv uses the next two values to extract application data.
362 ** The difference between writeOffset and readOffset is the amount of
363 ** data available to the application. Note that the actual offset of
364 ** the data in "buf" is recordOffset (above), not readOffset.
365 ** In the current implementation, this is made available before the
366 ** MAC is checked!!
367 */
368 unsigned int readOffset; /* Spot where DATA reader (e.g. application
369 ** or handshake code) will read next.
370 ** Always zero for SSl3 application data.
371 */
372 /* offset in buf/inbuf/hdr into which new data will be read from socket. */
373 unsigned int writeOffset;
374
375 /* Buffer for ssl3 to read (encrypted) data from the socket */
376 sslBuffer inbuf; /*recvBufLock*/
377
378 /* The ssl[23]_GatherData functions read data into this buffer, rather
379 ** than into buf or inbuf, while in the GS_HEADER state.
380 ** The portion of the SSL record header put here always comes off the wire
381 ** as plaintext, never ciphertext.
382 ** For SSL3/TLS, the plaintext portion is 5 bytes long. For DTLS it
383 ** varies based on version and header type.
384 */
385 unsigned char hdr[13];
386 unsigned int hdrLen;
387
388 /* Buffer for DTLS data read off the wire as a single datagram */
389 sslBuffer dtlsPacket;
390
391 /* the start of the buffered DTLS record in dtlsPacket */
392 unsigned int dtlsPacketOffset;
393
394 /* tracks whether we've seen a v3-type record before and must reject
395 * any further v2-type records. */
396 PRBool rejectV2Records;
397};
398
399/* sslGather.state */
400#define GS_INIT0 0
401#define GS_HEADER1 1
402#define GS_DATA2 2
403
404#define WRAPPED_MASTER_SECRET_SIZE48 48
405
406typedef struct {
407 PRUint8 wrapped_master_secret[WRAPPED_MASTER_SECRET_SIZE48];
408 PRUint8 wrapped_master_secret_len;
409 PRUint8 resumable;
410 PRUint8 extendedMasterSecretUsed;
411} ssl3SidKeys; /* 52 bytes */
412
413typedef enum { never_cached,
414 in_client_cache,
415 in_server_cache,
416 invalid_cache, /* no longer in any cache. */
417 in_external_cache
418} Cached;
419
420#include "sslcert.h"
421
422struct sslSessionIDStr {
423 /* The global cache lock must be held when accessing these members when the
424 * sid is in any cache.
425 */
426 sslSessionID *next; /* chain used for client sockets, only */
427 Cached cached;
428 int references;
429 PRTime lastAccessTime;
430
431 /* The rest of the members, except for the members of u.ssl3.locked, may
432 * be modified only when the sid is not in any cache.
433 */
434
435 CERTCertificate *peerCert;
436 SECItemArray peerCertStatus; /* client only */
437 const char *peerID; /* client only */
438 const char *urlSvrName; /* client only */
439 const sslNamedGroupDef *namedCurve; /* (server) for certificate lookup */
440 CERTCertificate *localCert;
441
442 PRIPv6Addr addr;
443 PRUint16 port;
444
445 SSL3ProtocolVersion version;
446
447 PRTime creationTime;
448 PRTime expirationTime;
449
450 SSLAuthType authType;
451 PRUint32 authKeyBits;
452 SSLKEAType keaType;
453 PRUint32 keaKeyBits;
454 SSLNamedGroup keaGroup;
455 SSLSignatureScheme sigScheme;
456
457 union {
458 struct {
459 /* values that are copied into the server's on-disk SID cache. */
460 PRUint8 sessionIDLength;
461 PRUint8 sessionID[SSL3_SESSIONID_BYTES32];
462
463 ssl3CipherSuite cipherSuite;
464 PRUint8 policy;
465 ssl3SidKeys keys;
466 /* mechanism used to wrap master secret */
467 CK_MECHANISM_TYPE masterWrapMech;
468
469 /* The following values pertain to the slot that wrapped the
470 ** master secret. (used only in client)
471 */
472 SECMODModuleID masterModuleID;
473 /* what module wrapped the master secret */
474 CK_SLOT_ID masterSlotID;
475 PRUint16 masterWrapIndex;
476 /* what's the key index for the wrapping key */
477 PRUint16 masterWrapSeries;
478 /* keep track of the slot series, so we don't
479 * accidently try to use new keys after the
480 * card gets removed and replaced.*/
481
482 /* The following values pertain to the slot that did the signature
483 ** for client auth. (used only in client)
484 */
485 SECMODModuleID clAuthModuleID;
486 CK_SLOT_ID clAuthSlotID;
487 PRUint16 clAuthSeries;
488
489 char masterValid;
490 char clAuthValid;
491
492 SECItem srvName;
493
494 /* Signed certificate timestamps received in a TLS extension.
495 ** (used only in client).
496 */
497 SECItem signedCertTimestamps;
498
499 /* The ALPN value negotiated in the original connection.
500 * Used for TLS 1.3. */
501 SECItem alpnSelection;
502
503 /* This lock is lazily initialized by CacheSID when a sid is first
504 * cached. Before then, there is no need to lock anything because
505 * the sid isn't being shared by anything.
506 */
507 PRRWLock *lock;
508
509 /* The lock must be held while reading or writing these members
510 * because they change while the sid is cached.
511 */
512 struct {
513 /* The session ticket, if we have one, is sent as an extension
514 * in the ClientHello message. This field is used only by
515 * clients. It is protected by lock when lock is non-null
516 * (after the sid has been added to the client session cache).
517 */
518 NewSessionTicket sessionTicket;
519 } locked;
520 } ssl3;
521 } u;
522};
523
524struct ssl3CipherSuiteDefStr {
525 ssl3CipherSuite cipher_suite;
526 SSL3BulkCipher bulk_cipher_alg;
527 SSL3MACAlgorithm mac_alg;
528 SSL3KeyExchangeAlgorithm key_exchange_alg;
529 SSLHashType prf_hash;
530};
531
532/*
533** There are tables of these, all const.
534*/
535typedef struct {
536 /* An identifier for this struct. */
537 SSL3KeyExchangeAlgorithm kea;
538 /* The type of key exchange used by the cipher suite. */
539 SSLKEAType exchKeyType;
540 /* If the cipher suite uses a signature, the type of key used in the
541 * signature. */
542 KeyType signKeyType;
543 /* In most cases, cipher suites depend on their signature type for
544 * authentication, ECDH certificates being the exception. */
545 SSLAuthType authKeyType;
546 /* True if the key exchange for the suite is ephemeral. Or to be more
547 * precise: true if the ServerKeyExchange message is always required. */
548 PRBool ephemeral;
549 /* An OID describing the key exchange */
550 SECOidTag oid;
551} ssl3KEADef;
552
553typedef enum {
554 ssl_0rtt_none, /* 0-RTT not present */
555 ssl_0rtt_sent, /* 0-RTT sent (no decision yet) */
556 ssl_0rtt_accepted, /* 0-RTT sent and accepted */
557 ssl_0rtt_ignored, /* 0-RTT sent but rejected/ignored */
558 ssl_0rtt_done /* 0-RTT accepted, but finished */
559} sslZeroRttState;
560
561typedef enum {
562 ssl_0rtt_ignore_none, /* not ignoring */
563 ssl_0rtt_ignore_trial, /* ignoring with trial decryption */
564 ssl_0rtt_ignore_hrr /* ignoring until ClientHello (due to HRR) */
565} sslZeroRttIgnore;
566
567typedef enum {
568 idle_handshake,
569 wait_client_hello,
570 wait_end_of_early_data,
571 wait_client_cert,
572 wait_client_key,
573 wait_cert_verify,
574 wait_change_cipher,
575 wait_finished,
576 wait_server_hello,
577 wait_certificate_status,
578 wait_server_cert,
579 wait_server_key,
580 wait_cert_request,
581 wait_hello_done,
582 wait_new_session_ticket,
583 wait_encrypted_extensions,
584 wait_invalid /* Invalid value. There is no handshake message "invalid". */
585} SSL3WaitState;
586
587typedef enum {
588 client_hello_initial, /* The first attempt. */
589 client_hello_retry, /* If we receive HelloRetryRequest. */
590 client_hello_retransmit, /* In DTLS, if we receive HelloVerifyRequest. */
591 client_hello_renegotiation /* A renegotiation attempt. */
592} sslClientHelloType;
593
594typedef struct SessionTicketDataStr SessionTicketData;
595
596typedef SECStatus (*sslRestartTarget)(sslSocket *);
597
598/*
599** A DTLS queued message (potentially to be retransmitted)
600*/
601typedef struct DTLSQueuedMessageStr {
602 PRCList link; /* The linked list link */
603 ssl3CipherSpec *cwSpec; /* The cipher spec to use, null for none */
604 SSLContentType type; /* The message type */
605 unsigned char *data; /* The data */
606 PRUint16 len; /* The data length */
607} DTLSQueuedMessage;
608
609struct TLS13KeyShareEntryStr {
610 PRCList link; /* The linked list link */
611 const sslNamedGroupDef *group; /* The group for the entry */
612 SECItem key_exchange; /* The share itself */
613};
614
615typedef struct TLS13EarlyDataStr {
616 PRCList link; /* The linked list link */
617 unsigned int consumed; /* How much has been read. */
618 SECItem data; /* The data */
619} TLS13EarlyData;
620
621typedef enum {
622 handshake_hash_unknown = 0,
623 handshake_hash_combo = 1, /* The MD5/SHA-1 combination */
624 handshake_hash_single = 2, /* A single hash */
625 handshake_hash_record
626} SSL3HandshakeHashType;
627
628// A DTLS Timer.
629typedef void (*DTLSTimerCb)(sslSocket *);
630
631typedef struct {
632 const char *label;
633 DTLSTimerCb cb;
634 PRIntervalTime started;
635 PRUint32 timeout;
636} dtlsTimer;
637
638/* TLS 1.3 client GREASE entry indices. */
639typedef enum {
640 grease_cipher,
641 grease_extension1,
642 grease_extension2,
643 grease_group,
644 grease_sigalg,
645 grease_version,
646 grease_alpn,
647 grease_entries
648} tls13ClientGreaseEntry;
649
650/* TLS 1.3 client GREASE values struct. */
651typedef struct tls13ClientGreaseStr {
652 PRUint16 idx[grease_entries];
653 PRUint8 pskKem;
654} tls13ClientGrease;
655
656/*
657** This is the "hs" member of the "ssl3" struct.
658** This entire struct is protected by ssl3HandshakeLock
659*/
660typedef struct SSL3HandshakeStateStr {
Excessive padding in 'struct SSL3HandshakeStateStr' (57 padding bytes, where 1 is optimal). Optimal fields order: md5, sha, shaEchInner, shaPostHandshake, kea_def, suite_def, msg_len, clientAuthSignatureSchemes, restartTarget, rtTimer, ackTimer, hdTimer, currentSecret, resumptionMasterSecret, dheSecret, clientEarlyTrafficSecret, clientHsTrafficSecret, serverHsTrafficSecret, clientTrafficSecret, serverTrafficSecret, earlyExporterSecret, exporterSecret, rttEstimate, echHpkeCtx, echPublicName, grease, dtlsHandhakeKeyUpdateMessage, chExtensionPermutation, remoteExtensions, echOuterExtensions, lastMessageFlight, cipherSpecs, bufferedEarlyData, psks, dtlsSentHandshake, dtlsRcvdHandshake, messages, echInnerMessages, msg_body, recvdFragments, cookie, srvVirtName, fakeSid, greaseEchBuf, dtls13ClientMessageBuffer, newSessionTicket, timers, ws, hashType, signatureScheme, header_bytes, msg_type, isResuming, sendingSCSV, receivedNewSessionTicket, clientCertificatePending, clientAuthSignatureSchemesLen, authCertificatePending, canFalseStart, preliminaryInfo, recvdHighWater, isKeyUpdateInProgress, allowPreviousEpoch, rtRetries, zeroRttState, zeroRttIgnore, helloRetry, dtlsReceivedHVR, receivedCcs, rejectCcs, clientCertRequested, endOfFlight, echAccepted, echDecided, echInvalidExtension, keyUpdateDeferred, deferredKeyUpdateRequest, kea_def_mutable, cipher_suite, finishedBytes, sendMessageSeq, maxMessageSent, recvMessageSeq, zeroRttSuite, ticketNonce, greaseEchSize, server_random, client_random, client_inner_random, finishedMsgs, consider reordering the fields or adding explicit padding members
661 SSL3Random server_random;
662 SSL3Random client_random;
663 SSL3Random client_inner_random; /* TLS 1.3 ECH Inner. */
664 SSL3WaitState ws; /* May also contain SSL3WaitState | 0x80 for TLS 1.3 */
665
666 /* This group of members is used for handshake running hashes. */
667 SSL3HandshakeHashType hashType;
668 sslBuffer messages; /* Accumulated handshake messages */
669 sslBuffer echInnerMessages; /* Accumulated ECH Inner handshake messages */
670 /* PKCS #11 mode:
671 * SSL 3.0 - TLS 1.1 use both |md5| and |sha|. |md5| is used for MD5 and
672 * |sha| for SHA-1.
673 * TLS 1.2 and later use only |sha| variants, for SHA-256.
674 * Under normal (non-1.3 ECH) handshakes, only |sha| and |shaPostHandshake|
675 * are used. When doing 1.3 ECH, |sha| contains the transcript hash
676 * corresponding to the outer Client Hello. To facilitate secure retry and
677 * disablement, |shaEchInner|, tracks, in parallel, the transcript hash
678 * corresponding to the inner Client Hello. Once we process the SH
679 * extensions, coalesce into |sha|. */
680 PK11Context *md5;
681 PK11Context *sha;
682 PK11Context *shaEchInner;
683 PK11Context *shaPostHandshake;
684 SSLSignatureScheme signatureScheme;
685 const ssl3KEADef *kea_def;
686 ssl3CipherSuite cipher_suite;
687 const ssl3CipherSuiteDef *suite_def;
688 sslBuffer msg_body; /* protected by recvBufLock */
689 /* partial handshake message from record layer */
690 unsigned int header_bytes;
691 /* number of bytes consumed from handshake */
692 /* message for message type and header length */
693 SSLHandshakeType msg_type;
694 unsigned long msg_len;
695 PRBool isResuming; /* we are resuming (not used in TLS 1.3) */
696 PRBool sendingSCSV; /* instead of empty RI */
697
698 /* The session ticket received in a NewSessionTicket message is temporarily
699 * stored in newSessionTicket until the handshake is finished; then it is
700 * moved to the sid.
701 */
702 PRBool receivedNewSessionTicket;
703 NewSessionTicket newSessionTicket;
704
705 PRUint16 finishedBytes; /* size of single finished below */
706 union {
707 TLSFinished tFinished[2]; /* client, then server */
708 SSL3Finished sFinished[2];
709 PRUint8 data[72];
710 } finishedMsgs;
711
712 /* True when handshake is blocked on client certificate selection */
713 PRBool clientCertificatePending;
714 /* Parameters stored whilst waiting for client certificate */
715 SSLSignatureScheme *clientAuthSignatureSchemes;
716 unsigned int clientAuthSignatureSchemesLen;
717
718 PRBool authCertificatePending;
719 /* Which function should SSL_RestartHandshake* call if we're blocked?
720 * One of NULL, ssl3_SendClientSecondRound, ssl3_FinishHandshake,
721 * or ssl3_AlwaysFail */
722 sslRestartTarget restartTarget;
723
724 PRBool canFalseStart; /* Can/did we False Start */
725 /* Which preliminaryinfo values have been set. */
726 PRUint32 preliminaryInfo;
727
728 /* Parsed extensions */
729 PRCList remoteExtensions; /* Parsed incoming extensions */
730 PRCList echOuterExtensions; /* If ECH, hold CHOuter extensions for decompression. */
731
732 /* This group of values is used for DTLS */
733 PRUint16 sendMessageSeq; /* The sending message sequence
734 * number */
735 PRCList lastMessageFlight; /* The last message flight we
736 * sent */
737 PRUint16 maxMessageSent; /* The largest message we sent */
738 PRUint16 recvMessageSeq; /* The receiving message sequence
739 * number */
740 sslBuffer recvdFragments; /* The fragments we have received in
741 * a bitmask */
742 PRInt32 recvdHighWater; /* The high water mark for fragments
743 * received. -1 means no reassembly
744 * in progress. */
745 SECItem cookie; /* The Hello(Retry|Verify)Request cookie. */
746 dtlsTimer timers[3]; /* Holder for timers. */
747 dtlsTimer *rtTimer; /* Retransmit timer. */
748 dtlsTimer *ackTimer; /* Ack timer (DTLS 1.3 only). */
749 dtlsTimer *hdTimer; /* Read cipher holddown timer. */
750
751 /* KeyUpdate state machines */
752 PRBool isKeyUpdateInProgress; /* The status of KeyUpdate -: {true == started, false == finished}. */
753 PRBool allowPreviousEpoch; /* The flag whether the previous epoch messages are allowed or not: {true == allowed, false == forbidden}. */
754
755 PRUint32 rtRetries; /* The retry counter */
756 SECItem srvVirtName; /* for server: name that was negotiated
757 * with a client. For client - is
758 * always set to NULL.*/
759
760 /* This group of values is used for TLS 1.3 and above */
761 PK11SymKey *currentSecret; /* The secret down the "left hand side"
762 * of the TLS 1.3 key schedule. */
763 PK11SymKey *resumptionMasterSecret; /* The resumption_master_secret. */
764 PK11SymKey *dheSecret; /* The (EC)DHE shared secret. */
765 PK11SymKey *clientEarlyTrafficSecret; /* The secret we use for 0-RTT. */
766 PK11SymKey *clientHsTrafficSecret; /* The source keys for handshake */
767 PK11SymKey *serverHsTrafficSecret; /* traffic keys. */
768 PK11SymKey *clientTrafficSecret; /* The source keys for application */
769 PK11SymKey *serverTrafficSecret; /* traffic keys */
770 PK11SymKey *earlyExporterSecret; /* for 0-RTT exporters */
771 PK11SymKey *exporterSecret; /* for exporters */
772 PRCList cipherSpecs; /* The cipher specs in the sequence they
773 * will be applied. */
774 sslZeroRttState zeroRttState; /* Are we doing a 0-RTT handshake? */
775 sslZeroRttIgnore zeroRttIgnore; /* Are we ignoring 0-RTT? */
776 ssl3CipherSuite zeroRttSuite; /* The cipher suite we used for 0-RTT. */
777 PRCList bufferedEarlyData; /* Buffered TLS 1.3 early data
778 * on server.*/
779 PRBool helloRetry; /* True if HelloRetryRequest has been sent
780 * or received. */
781 PRBool dtlsReceivedHVR; /* True if a DTLS HelloVerifyRequest was
782 * received. */
783 PRBool receivedCcs; /* A server received ChangeCipherSpec
784 * before the handshake started. */
785 PRBool rejectCcs; /* Excessive ChangeCipherSpecs are rejected. */
786 PRBool clientCertRequested; /* True if CertificateRequest received. */
787 PRBool endOfFlight; /* Processed a full flight (DTLS 1.3). */
788 ssl3KEADef kea_def_mutable; /* Used to hold the writable kea_def
789 * we use for TLS 1.3 */
790 PRUint16 ticketNonce; /* A counter we use for tickets. */
791 SECItem fakeSid; /* ... (server) the SID the client used. */
792 PRCList psks; /* A list of PSKs, resumption and/or external. */
793
794 /* rttEstimate is used to guess the round trip time between server and client.
795 * When the server sends ServerHello it sets this to the current time.
796 * Only after it receives a message from the client's second flight does it
797 * set the value to something resembling an RTT estimate. */
798 PRTime rttEstimate;
799
800 /* The following lists contain DTLSHandshakeRecordEntry */
801 PRCList dtlsSentHandshake; /* Used to map records to handshake fragments. */
802 PRCList dtlsRcvdHandshake; /* Handshake records we have received
803 * used to generate ACKs. */
804
805 /* TLS 1.3 ECH state. */
806 PRUint8 greaseEchSize;
807 PRBool echAccepted; /* Client/Server: True if we've commited to using CHInner. */
808 PRBool echDecided;
809 HpkeContext *echHpkeCtx; /* Client/Server: HPKE context for ECH. */
810 const char *echPublicName; /* Client: If rejected, the ECHConfig.publicName to
811 * use for certificate verification. */
812 sslBuffer greaseEchBuf; /* Client: Remember GREASE ECH, as advertised, for CH2 (HRR case).
813 Server: Remember HRR Grease Value, for transcript calculations */
814 PRBool echInvalidExtension; /* Client: True if the server offered an invalid extension for the ClientHelloInner */
815
816 /* TLS 1.3 GREASE state. */
817 tls13ClientGrease *grease;
818
819 /*
820 KeyUpdate variables:
821 This is true if we deferred sending a key update as
822 * post-handshake auth is in progress. */
823 PRBool keyUpdateDeferred;
824 tls13KeyUpdateRequest deferredKeyUpdateRequest;
825 /* The identifier of the keyUpdate message that is sent but not yet acknowledged */
826 PRUint64 dtlsHandhakeKeyUpdateMessage;
827
828 /* ClientHello Extension Permutation state. */
829 sslExtensionBuilder *chExtensionPermutation;
830
831 /* Used by client to store a message that's to be hashed during the HandleServerHello. */
832 sslBuffer dtls13ClientMessageBuffer;
833} SSL3HandshakeState;
834
835#define SSL_ASSERT_HASHES_EMPTY(ss)do { ((ss->ssl3.hs.hashType == handshake_hash_unknown) ? (
(void)0) : PR_Assert("ss->ssl3.hs.hashType == handshake_hash_unknown"
, "/root/firefox-clang/security/nss/lib/ssl/sslimpl.h", 835))
; ((ss->ssl3.hs.messages.len == 0) ? ((void)0) : PR_Assert
("ss->ssl3.hs.messages.len == 0", "/root/firefox-clang/security/nss/lib/ssl/sslimpl.h"
, 835)); ((ss->ssl3.hs.echInnerMessages.len == 0) ? ((void
)0) : PR_Assert("ss->ssl3.hs.echInnerMessages.len == 0", "/root/firefox-clang/security/nss/lib/ssl/sslimpl.h"
, 835)); } while (0)
\
836 do { \
837 PORT_Assert(ss->ssl3.hs.hashType == handshake_hash_unknown)((ss->ssl3.hs.hashType == handshake_hash_unknown) ? ((void
)0) : PR_Assert("ss->ssl3.hs.hashType == handshake_hash_unknown"
, "/root/firefox-clang/security/nss/lib/ssl/sslimpl.h", 837))
; \
838 PORT_Assert(ss->ssl3.hs.messages.len == 0)((ss->ssl3.hs.messages.len == 0) ? ((void)0) : PR_Assert("ss->ssl3.hs.messages.len == 0"
, "/root/firefox-clang/security/nss/lib/ssl/sslimpl.h", 838))
; \
839 PORT_Assert(ss->ssl3.hs.echInnerMessages.len == 0)((ss->ssl3.hs.echInnerMessages.len == 0) ? ((void)0) : PR_Assert
("ss->ssl3.hs.echInnerMessages.len == 0", "/root/firefox-clang/security/nss/lib/ssl/sslimpl.h"
, 839))
; \
840 } while (0)
841/*
842** This is the "ssl3" struct, as in "ss->ssl3".
843** note:
844** usually, crSpec == cwSpec and prSpec == pwSpec.
845** Sometimes, crSpec == pwSpec and prSpec == cwSpec.
846** But there are never more than 2 actual specs.
847** No spec must ever be modified if either "current" pointer points to it.
848*/
849struct ssl3StateStr {
850
851 /*
852 ** The following Specs and Spec pointers must be protected using the
853 ** Spec Lock.
854 */
855 ssl3CipherSpec *crSpec; /* current read spec. */
856 ssl3CipherSpec *prSpec; /* pending read spec. */
857 ssl3CipherSpec *cwSpec; /* current write spec. */
858 ssl3CipherSpec *pwSpec; /* pending write spec. */
859
860 /* This is true after the peer requests a key update; false after a key
861 * update is initiated locally. */
862 PRBool peerRequestedKeyUpdate;
863
864 /* This is true after the server requests client certificate;
865 * false after the client certificate is received. Used by the
866 * server. */
867 PRBool clientCertRequested;
868
869 CERTCertificate *clientCertificate; /* used by client */
870 SECKEYPrivateKey *clientPrivateKey; /* used by client */
871 CERTCertificateList *clientCertChain; /* used by client */
872 PRBool sendEmptyCert; /* used by client */
873
874 PRUint8 policy;
875 /* This says what cipher suites we can do, and should
876 * be either SSL_ALLOWED or SSL_RESTRICTED
877 */
878 PLArenaPool *peerCertArena;
879 /* These are used to keep track of the peer CA */
880 void *peerCertChain;
881 /* chain while we are trying to validate it. */
882 CERTDistNames *ca_list;
883 /* used by server. trusted CAs for this socket. */
884 SSL3HandshakeState hs;
885
886 PRUint16 mtu; /* Our estimate of the MTU */
887
888 /* DTLS-SRTP cipher suite preferences (if any) */
889 PRUint16 dtlsSRTPCiphers[MAX_DTLS_SRTP_CIPHER_SUITES4];
890 PRUint16 dtlsSRTPCipherCount;
891 PRBool fatalAlertSent;
892 PRBool dheWeakGroupEnabled; /* used by server */
893 const sslNamedGroupDef *dhePreferredGroup;
894
895 /* TLS 1.2 introduces separate signature algorithm negotiation.
896 * TLS 1.3 combined signature and hash into a single enum.
897 * This is our preference order. */
898 SSLSignatureScheme signatureSchemes[MAX_SIGNATURE_SCHEMES21];
899 unsigned int signatureSchemeCount;
900
901 /* The version to check if we fell back from our highest version
902 * of TLS. Default is 0 in which case we check against the maximum
903 * configured version for this socket. Used only on the client. */
904 SSL3ProtocolVersion downgradeCheckVersion;
905 /* supported certificate compression algorithms (if any) */
906 SSLCertificateCompressionAlgorithm supportedCertCompressionAlgorithms[MAX_SUPPORTED_CERTIFICATE_COMPRESSION_ALGS32];
907 PRUint8 supportedCertCompressionAlgorithmsCount;
908};
909
910/* Ethernet MTU but without subtracting the headers,
911 * so slightly larger than expected */
912#define DTLS_MAX_MTU1500U 1500U
913#define IS_DTLS(ss)(ss->protocolVariant == ssl_variant_datagram) (ss->protocolVariant == ssl_variant_datagram)
914#define IS_DTLS_1_OR_12(ss)((ss->protocolVariant == ssl_variant_datagram) && ss
->version < SSL_LIBRARY_VERSION_TLS_1_3)
(IS_DTLS(ss)(ss->protocolVariant == ssl_variant_datagram) && ss->version < SSL_LIBRARY_VERSION_TLS_1_3)
915#define IS_DTLS_13_OR_ABOVE(ss)((ss->protocolVariant == ssl_variant_datagram) && ss
->version >= SSL_LIBRARY_VERSION_TLS_1_3)
(IS_DTLS(ss)(ss->protocolVariant == ssl_variant_datagram) && ss->version >= SSL_LIBRARY_VERSION_TLS_1_3)
916
917typedef struct {
918 /* |seqNum| eventually contains the reconstructed sequence number. */
919 sslSequenceNumber seqNum;
920 /* The header of the cipherText. */
921 PRUint8 *hdr;
922 unsigned int hdrLen;
923
924 /* |buf| is the payload of the ciphertext. */
925 sslBuffer *buf;
926} SSL3Ciphertext;
927
928struct sslKeyPairStr {
929 SECKEYPrivateKey *privKey;
930 SECKEYPublicKey *pubKey;
931 PRInt32 refCount; /* use PR_Atomic calls for this. */
932};
933
934struct sslEphemeralKeyPairStr {
935 PRCList link;
936 const sslNamedGroupDef *group;
937 sslKeyPair *keys;
938 sslKeyPair *kemKeys;
939 SECItem *kemCt;
940};
941
942struct ssl3DHParamsStr {
943 SSLNamedGroup name;
944 SECItem prime; /* p */
945 SECItem base; /* g */
946};
947
948typedef struct SSLWrappedSymWrappingKeyStr {
949 PRUint8 wrappedSymmetricWrappingkey[SSL_MAX_RSA_KEY_BITS8192 / 8];
950 CK_MECHANISM_TYPE symWrapMechanism;
951 /* unwrapped symmetric wrapping key uses this mechanism */
952 CK_MECHANISM_TYPE asymWrapMechanism;
953 /* mechanism used to wrap the SymmetricWrappingKey using
954 * server's public and/or private keys. */
955 PRInt16 wrapMechIndex;
956 PRUint16 wrapKeyIndex;
957 PRUint16 wrappedSymKeyLen;
958} SSLWrappedSymWrappingKey;
959
960typedef struct SessionTicketStr {
961 PRBool valid;
962 SSL3ProtocolVersion ssl_version;
963 ssl3CipherSuite cipher_suite;
964 SSLAuthType authType;
965 PRUint32 authKeyBits;
966 SSLKEAType keaType;
967 PRUint32 keaKeyBits;
968 SSLNamedGroup originalKeaGroup;
969 SSLSignatureScheme signatureScheme;
970 const sslNamedGroupDef *namedCurve; /* For certificate lookup. */
971
972 /*
973 * msWrapMech contains a meaningful value only if ms_is_wrapped is true.
974 */
975 PRUint8 ms_is_wrapped;
976 CK_MECHANISM_TYPE msWrapMech;
977 PRUint16 ms_length;
978 PRUint8 master_secret[48];
979 PRBool extendedMasterSecretUsed;
980 ClientAuthenticationType client_auth_type;
981 SECItem peer_cert;
982 PRTime timestamp;
983 PRUint32 flags;
984 SECItem srvName; /* negotiated server name */
985 SECItem alpnSelection;
986 PRUint32 maxEarlyData;
987 PRUint32 ticketAgeBaseline;
988 SECItem applicationToken;
989} SessionTicket;
990
991/*
992 * SSL2 buffers used in SSL3.
993 * writeBuf in the SecurityInfo maintained by sslsecur.c is used
994 * to hold the data just about to be passed to the kernel
995 * sendBuf in the ConnectInfo maintained by sslcon.c is used
996 * to hold handshake messages as they are accumulated
997 */
998
999/*
1000** This is "ci", as in "ss->sec.ci".
1001**
1002** Protection: All the variables in here are protected by
1003** firstHandshakeLock AND ssl3HandshakeLock
1004*/
1005struct sslConnectInfoStr {
1006 /* outgoing handshakes appended to this. */
1007 sslBuffer sendBuf; /*xmitBufLock*/
1008
1009 PRIPv6Addr peer;
1010 unsigned short port;
1011
1012 sslSessionID *sid;
1013};
1014
1015/* Note: The entire content of this struct and whatever it points to gets
1016 * blown away by SSL_ResetHandshake(). This is "sec" as in "ss->sec".
1017 *
1018 * Unless otherwise specified below, the contents of this struct are
1019 * protected by firstHandshakeLock AND ssl3HandshakeLock.
1020 */
1021struct sslSecurityInfoStr {
1022
1023#define SSL_ROLE(ss)(ss->sec.isServer ? "server" : "client") (ss->sec.isServer ? "server" : "client")
1024
1025 PRBool isServer;
1026 sslBuffer writeBuf; /*xmitBufLock*/
1027
1028 CERTCertificate *localCert;
1029 CERTCertificate *peerCert;
1030 SECKEYPublicKey *peerKey;
1031
1032 SSLAuthType authType;
1033 PRUint32 authKeyBits;
1034 SSLSignatureScheme signatureScheme;
1035 SSLKEAType keaType;
1036 PRUint32 keaKeyBits;
1037 const sslNamedGroupDef *keaGroup;
1038 const sslNamedGroupDef *originalKeaGroup;
1039 /* The selected certificate (for servers only). */
1040 const sslServerCert *serverCert;
1041
1042 /* These are used during a connection handshake */
1043 sslConnectInfo ci;
1044};
1045
1046/*
1047** SSL Socket struct
1048**
1049** Protection: XXX
1050*/
1051struct sslSocketStr {
1052 PRFileDesc *fd;
1053
1054 /* Pointer to operations vector for this socket */
1055 const sslSocketOps *ops;
1056
1057 /* SSL socket options */
1058 sslOptions opt;
1059 /* Enabled version range */
1060 SSLVersionRange vrange;
1061
1062 /* A function that returns the current time. */
1063 SSLTimeFunc now;
1064 void *nowArg;
1065
1066 /* State flags */
1067 unsigned long clientAuthRequested;
1068 unsigned long delayDisabled; /* Nagle delay disabled */
1069 unsigned long firstHsDone; /* first handshake is complete. */
1070 unsigned long enoughFirstHsDone; /* enough of the first handshake is
1071 * done for callbacks to be able to
1072 * retrieve channel security
1073 * parameters from the SSL socket. */
1074 unsigned long handshakeBegun;
1075 unsigned long lastWriteBlocked;
1076 unsigned long recvdCloseNotify; /* received SSL EOF. */
1077 unsigned long TCPconnected;
1078 unsigned long appDataBuffered;
1079 unsigned long peerRequestedProtection; /* from old renegotiation */
1080
1081 /* version of the protocol to use */
1082 SSL3ProtocolVersion version;
1083 SSL3ProtocolVersion clientHelloVersion; /* version sent in client hello. */
1084
1085 sslSecurityInfo sec; /* not a pointer any more */
1086
1087 /* protected by firstHandshakeLock AND ssl3HandshakeLock. */
1088 const char *url;
1089
1090 sslHandshakeFunc handshake; /*firstHandshakeLock*/
1091
1092 /* the following variable is only used with socks or other proxies. */
1093 char *peerID; /* String uniquely identifies target server. */
1094
1095 /* ECDHE and DHE keys: In TLS 1.3, we might have to maintain multiple of
1096 * these on the client side. The server inserts a single value into this
1097 * list for all versions. */
1098 PRCList /*<sslEphemeralKeyPair>*/ ephemeralKeyPairs;
1099
1100 /* Callbacks */
1101 SSLAuthCertificate authCertificate;
1102 void *authCertificateArg;
1103 SSLGetClientAuthData getClientAuthData;
1104 void *getClientAuthDataArg;
1105 SSLSNISocketConfig sniSocketConfig;
1106 void *sniSocketConfigArg;
1107 SSLAlertCallback alertReceivedCallback;
1108 void *alertReceivedCallbackArg;
1109 SSLAlertCallback alertSentCallback;
1110 void *alertSentCallbackArg;
1111 SSLBadCertHandler handleBadCert;
1112 void *badCertArg;
1113 SSLHandshakeCallback handshakeCallback;
1114 void *handshakeCallbackData;
1115 SSLCanFalseStartCallback canFalseStartCallback;
1116 void *canFalseStartCallbackData;
1117 void *pkcs11PinArg;
1118 SSLNextProtoCallback nextProtoCallback;
1119 void *nextProtoArg;
1120 SSLHelloRetryRequestCallback hrrCallback;
1121 void *hrrCallbackArg;
1122 PRCList extensionHooks;
1123 SSLResumptionTokenCallback resumptionTokenCallback;
1124 void *resumptionTokenContext;
1125 SSLSecretCallback secretCallback;
1126 void *secretCallbackArg;
1127 SSLRecordWriteCallback recordWriteCallback;
1128 void *recordWriteCallbackArg;
1129
1130 PRIntervalTime rTimeout; /* timeout for NSPR I/O */
1131 PRIntervalTime wTimeout; /* timeout for NSPR I/O */
1132 PRIntervalTime cTimeout; /* timeout for NSPR I/O */
1133
1134 PRLock *recvLock; /* lock against multiple reader threads. */
1135 PRLock *sendLock; /* lock against multiple sender threads. */
1136
1137 PRMonitor *recvBufLock; /* locks low level recv buffers. */
1138 PRMonitor *xmitBufLock; /* locks low level xmit buffers. */
1139
1140 /* Only one thread may operate on the socket until the initial handshake
1141 ** is complete. This Monitor ensures that. Since SSL2 handshake is
1142 ** only done once, this is also effectively the SSL2 handshake lock.
1143 */
1144 PRMonitor *firstHandshakeLock;
1145
1146 /* This monitor protects the ssl3 handshake state machine data.
1147 ** Only one thread (reader or writer) may be in the ssl3 handshake state
1148 ** machine at any time. */
1149 PRMonitor *ssl3HandshakeLock;
1150
1151 /* reader/writer lock, protects the secret data needed to encrypt and MAC
1152 ** outgoing records, and to decrypt and MAC check incoming ciphertext
1153 ** records. */
1154 NSSRWLock *specLock;
1155
1156 /* handle to perm cert db (and implicitly to the temp cert db) used
1157 ** with this socket.
1158 */
1159 CERTCertDBHandle *dbHandle;
1160
1161 PRThread *writerThread; /* thread holds SSL_LOCK_WRITER lock */
1162
1163 PRUint16 shutdownHow; /* See ssl_SHUTDOWN defines below. */
1164
1165 sslHandshakingType handshaking;
1166
1167 /* Gather object used for gathering data */
1168 sslGather gs; /*recvBufLock*/
1169
1170 sslBuffer saveBuf; /*xmitBufLock*/
1171 sslBuffer pendingBuf; /*xmitBufLock*/
1172
1173 /* Configuration state for server sockets */
1174 /* One server cert and key for each authentication type. */
1175 PRCList /* <sslServerCert> */ serverCerts;
1176
1177 ssl3CipherSuiteCfg cipherSuites[ssl_V3_SUITES_IMPLEMENTED71];
1178
1179 /* A list of groups that are sorted according to user preferences pointing
1180 * to entries of ssl_named_groups. By default this list contains pointers
1181 * to all elements in ssl_named_groups in the default order.
1182 * This list also determines which groups are enabled. This
1183 * starts with all being enabled and can be modified either by negotiation
1184 * (in which case groups not supported by a peer are masked off), or by
1185 * calling SSL_DHEGroupPrefSet().
1186 * Note that renegotiation will ignore groups that were disabled in the
1187 * first handshake.
1188 */
1189 const sslNamedGroupDef *namedGroupPreferences[SSL_NAMED_GROUP_COUNT36];
1190 /* The number of additional shares to generate for the TLS 1.3 ClientHello */
1191 unsigned int additionalShares;
1192
1193 /* SSL3 state info. Formerly was a pointer */
1194 ssl3State ssl3;
1195
1196 /*
1197 * TLS extension related data.
1198 */
1199 /* True when the current session is a stateless resume. */
1200 PRBool statelessResume;
1201 /* Like ss->ssl3.hs, this is handshake state: it is written by the
1202 * extension handlers and senders, and is protected by
1203 * ssl3HandshakeLock. */
1204 TLSExtensionData xtnData;
1205
1206 /* Whether we are doing stream or datagram mode */
1207 SSLProtocolVariant protocolVariant;
1208
1209 /* TLS 1.3 Encrypted Client Hello. */
1210 PRCList echConfigs; /* Client/server: Must not change while hs
1211 * is in-progress. */
1212 SECKEYPublicKey *echPubKey; /* Server: The ECH keypair used in HPKE. */
1213 SECKEYPrivateKey *echPrivKey; /* As above. */
1214
1215 /* Anti-replay for TLS 1.3 0-RTT. */
1216 SSLAntiReplayContext *antiReplay;
1217
1218 /* An out-of-band PSK. */
1219 sslPsk *psk;
1220};
1221
1222struct sslSelfEncryptKeysStr {
1223 PRCallOnceType setup;
1224 PRUint8 keyName[SELF_ENCRYPT_KEY_NAME_LEN16];
1225 PK11SymKey *encKey;
1226 PK11SymKey *macKey;
1227};
1228typedef struct sslSelfEncryptKeysStr sslSelfEncryptKeys;
1229
1230extern char ssl_debug;
1231extern char ssl_trace;
1232extern FILE *ssl_trace_iob;
1233extern FILE *ssl_keylog_iob;
1234extern PRLock *ssl_keylog_lock;
1235static const PRUint32 ssl_ticket_lifetime = 2 * 24 * 60 * 60; // 2 days.
1236
1237extern const char *const ssl3_cipherName[];
1238
1239extern sslSessionIDLookupFunc ssl_sid_lookup;
1240
1241extern const sslNamedGroupDef ssl_named_groups[];
1242
1243/************************************************************************/
1244
1245SEC_BEGIN_PROTOS
1246
1247/* Internal initialization and installation of the SSL error tables */
1248extern SECStatus ssl_Init(void);
1249extern SECStatus ssl_InitializePRErrorTable(void);
1250
1251/* Implementation of ops for default (non socks, non secure) case */
1252extern int ssl_DefConnect(sslSocket *ss, const PRNetAddr *addr);
1253extern PRFileDesc *ssl_DefAccept(sslSocket *ss, PRNetAddr *addr);
1254extern int ssl_DefBind(sslSocket *ss, const PRNetAddr *addr);
1255extern int ssl_DefListen(sslSocket *ss, int backlog);
1256extern int ssl_DefShutdown(sslSocket *ss, int how);
1257extern int ssl_DefClose(sslSocket *ss);
1258extern int ssl_DefRecv(sslSocket *ss, unsigned char *buf, int len, int flags);
1259extern int ssl_DefSend(sslSocket *ss, const unsigned char *buf,
1260 int len, int flags);
1261extern int ssl_DefRead(sslSocket *ss, unsigned char *buf, int len);
1262extern int ssl_DefWrite(sslSocket *ss, const unsigned char *buf, int len);
1263extern int ssl_DefGetpeername(sslSocket *ss, PRNetAddr *name);
1264extern int ssl_DefGetsockname(sslSocket *ss, PRNetAddr *name);
1265extern int ssl_DefGetsockopt(sslSocket *ss, PRSockOption optname,
1266 void *optval, PRInt32 *optlen);
1267extern int ssl_DefSetsockopt(sslSocket *ss, PRSockOption optname,
1268 const void *optval, PRInt32 optlen);
1269
1270/* Implementation of ops for socks only case */
1271extern int ssl_SocksConnect(sslSocket *ss, const PRNetAddr *addr);
1272extern PRFileDesc *ssl_SocksAccept(sslSocket *ss, PRNetAddr *addr);
1273extern int ssl_SocksBind(sslSocket *ss, const PRNetAddr *addr);
1274extern int ssl_SocksListen(sslSocket *ss, int backlog);
1275extern int ssl_SocksGetsockname(sslSocket *ss, PRNetAddr *name);
1276extern int ssl_SocksRecv(sslSocket *ss, unsigned char *buf, int len, int flags);
1277extern int ssl_SocksSend(sslSocket *ss, const unsigned char *buf,
1278 int len, int flags);
1279extern int ssl_SocksRead(sslSocket *ss, unsigned char *buf, int len);
1280extern int ssl_SocksWrite(sslSocket *ss, const unsigned char *buf, int len);
1281
1282/* Implementation of ops for secure only case */
1283extern int ssl_SecureConnect(sslSocket *ss, const PRNetAddr *addr);
1284extern PRFileDesc *ssl_SecureAccept(sslSocket *ss, PRNetAddr *addr);
1285extern int ssl_SecureRecv(sslSocket *ss, unsigned char *buf,
1286 int len, int flags);
1287extern int ssl_SecureSend(sslSocket *ss, const unsigned char *buf,
1288 int len, int flags);
1289extern int ssl_SecureRead(sslSocket *ss, unsigned char *buf, int len);
1290extern int ssl_SecureWrite(sslSocket *ss, const unsigned char *buf, int len);
1291extern int ssl_SecureShutdown(sslSocket *ss, int how);
1292extern int ssl_SecureClose(sslSocket *ss);
1293
1294/* Implementation of ops for secure socks case */
1295extern int ssl_SecureSocksConnect(sslSocket *ss, const PRNetAddr *addr);
1296extern PRFileDesc *ssl_SecureSocksAccept(sslSocket *ss, PRNetAddr *addr);
1297extern PRFileDesc *ssl_FindTop(sslSocket *ss);
1298
1299/* Gather funcs. */
1300extern sslGather *ssl_NewGather(void);
1301extern SECStatus ssl3_InitGather(sslGather *gs);
1302extern void ssl3_DestroyGather(sslGather *gs);
1303extern SECStatus ssl_GatherRecord1stHandshake(sslSocket *ss);
1304
1305extern SECStatus ssl_CreateSecurityInfo(sslSocket *ss);
1306extern SECStatus ssl_CopySecurityInfo(sslSocket *ss, sslSocket *os);
1307extern void ssl_ResetSecurityInfo(sslSecurityInfo *sec, PRBool doMemset);
1308extern void ssl_DestroySecurityInfo(sslSecurityInfo *sec);
1309
1310extern void ssl_PrintBuf(const sslSocket *ss, const char *msg, const void *cp,
1311 int len);
1312extern void ssl_PrintKey(const sslSocket *ss, const char *msg, PK11SymKey *key);
1313
1314extern int ssl_SendSavedWriteData(sslSocket *ss);
1315extern SECStatus ssl_SaveWriteData(sslSocket *ss,
1316 const void *p, unsigned int l);
1317extern SECStatus ssl_BeginClientHandshake(sslSocket *ss);
1318extern SECStatus ssl_BeginServerHandshake(sslSocket *ss);
1319extern SECStatus ssl_Do1stHandshake(sslSocket *ss);
1320
1321extern SECStatus ssl3_InitPendingCipherSpecs(sslSocket *ss, PK11SymKey *secret,
1322 PRBool derive);
1323extern void ssl_DestroyKeyMaterial(ssl3KeyMaterial *keyMaterial);
1324extern sslSessionID *ssl3_NewSessionID(sslSocket *ss, PRBool is_server);
1325extern sslSessionID *ssl_LookupSID(PRTime now, const PRIPv6Addr *addr,
1326 PRUint16 port, const char *peerID,
1327 const char *urlSvrName);
1328extern void ssl_FreeSID(sslSessionID *sid);
1329extern void ssl_DestroySID(sslSessionID *sid, PRBool freeIt);
1330extern sslSessionID *ssl_ReferenceSID(sslSessionID *sid);
1331
1332extern int ssl3_SendApplicationData(sslSocket *ss, const PRUint8 *in,
1333 int len, int flags);
1334
1335extern PRBool ssl_FdIsBlocking(PRFileDesc *fd);
1336
1337extern PRBool ssl_SocketIsBlocking(sslSocket *ss);
1338
1339extern void ssl3_SetAlwaysBlock(sslSocket *ss);
1340
1341extern SECStatus ssl_EnableNagleDelay(sslSocket *ss, PRBool enabled);
1342
1343extern SECStatus ssl_FinishHandshake(sslSocket *ss);
1344
1345extern SECStatus ssl_CipherPolicySet(PRInt32 which, PRInt32 policy);
1346
1347extern SECStatus ssl_CipherPrefSetDefault(PRInt32 which, PRBool enabled);
1348
1349extern SECStatus ssl3_ConstrainRangeByPolicy(void);
1350
1351extern SECStatus ssl3_InitState(sslSocket *ss);
1352extern SECStatus Null_Cipher(void *ctx, unsigned char *output, unsigned int *outputLen,
1353 unsigned int maxOutputLen, const unsigned char *input,
1354 unsigned int inputLen);
1355extern void ssl3_RestartHandshakeHashes(sslSocket *ss);
1356typedef SECStatus (*sslUpdateHandshakeHashes)(sslSocket *ss,
1357 const unsigned char *b,
1358 unsigned int l);
1359extern SECStatus ssl3_UpdateHandshakeHashes(sslSocket *ss,
1360 const unsigned char *b,
1361 unsigned int l);
1362extern SECStatus ssl3_UpdatePostHandshakeHashes(sslSocket *ss,
1363 const unsigned char *b,
1364 unsigned int l);
1365SECStatus
1366ssl_HashHandshakeMessageInt(sslSocket *ss, SSLHandshakeType type,
1367 PRUint32 dtlsSeq,
1368 const PRUint8 *b, PRUint32 length,
1369 sslUpdateHandshakeHashes cb);
1370SECStatus ssl_HashHandshakeMessage(sslSocket *ss, SSLHandshakeType type,
1371 const PRUint8 *b, PRUint32 length);
1372SECStatus ssl_HashHandshakeMessageEchInner(sslSocket *ss, SSLHandshakeType type,
1373 const PRUint8 *b, PRUint32 length);
1374SECStatus ssl_HashHandshakeMessageDefault(sslSocket *ss, SSLHandshakeType type,
1375 const PRUint8 *b, PRUint32 length);
1376SECStatus ssl_HashPostHandshakeMessage(sslSocket *ss, SSLHandshakeType type,
1377 const PRUint8 *b, PRUint32 length);
1378
1379/* Returns PR_TRUE if we are still waiting for the server to complete its
1380 * response to our client second round. Once we've received the Finished from
1381 * the server then there is no need to check false start.
1382 */
1383extern PRBool ssl3_WaitingForServerSecondRound(sslSocket *ss);
1384
1385extern PRInt32 ssl3_SendRecord(sslSocket *ss, ssl3CipherSpec *cwSpec,
1386 SSLContentType type,
1387 const PRUint8 *pIn, PRInt32 nIn,
1388 PRInt32 flags);
1389
1390/* Clear any PRCList, optionally calling f on the value. */
1391void ssl_ClearPRCList(PRCList *list, void (*f)(void *));
1392
1393/*
1394 * Make sure there is room in the write buffer for padding and
1395 * cryptographic expansions.
1396 */
1397#define SSL3_BUFFER_FUDGE100 100
1398
1399#define SSL_LOCK_READER(ss)if (ss->recvLock) PR_Lock(ss->recvLock) \
1400 if (ss->recvLock) \
1401 PR_Lock(ss->recvLock)
1402#define SSL_UNLOCK_READER(ss)if (ss->recvLock) PR_Unlock(ss->recvLock) \
1403 if (ss->recvLock) \
1404 PR_Unlock(ss->recvLock)
1405#define SSL_LOCK_WRITER(ss)if (ss->sendLock) PR_Lock(ss->sendLock) \
1406 if (ss->sendLock) \
1407 PR_Lock(ss->sendLock)
1408#define SSL_UNLOCK_WRITER(ss)if (ss->sendLock) PR_Unlock(ss->sendLock) \
1409 if (ss->sendLock) \
1410 PR_Unlock(ss->sendLock)
1411
1412PRBool ssl_HaveRecvBufLock(sslSocket *ss);
1413PRBool ssl_HaveXmitBufLock(sslSocket *ss);
1414PRBool ssl_Have1stHandshakeLock(sslSocket *ss);
1415PRBool ssl_HaveSSL3HandshakeLock(sslSocket *ss);
1416PRBool ssl_HaveSpecWriteLock(sslSocket *ss);
1417
1418void ssl_Get1stHandshakeLock(sslSocket *ss);
1419void ssl_Release1stHandshakeLock(sslSocket *ss);
1420
1421void ssl_GetSSL3HandshakeLock(sslSocket *ss);
1422void ssl_ReleaseSSL3HandshakeLock(sslSocket *ss);
1423
1424void ssl_GetSpecReadLock(sslSocket *ss);
1425void ssl_ReleaseSpecReadLock(sslSocket *ss);
1426
1427void ssl_GetSpecWriteLock(sslSocket *ss);
1428void ssl_ReleaseSpecWriteLock(sslSocket *ss);
1429
1430void ssl_GetRecvBufLock(sslSocket *ss);
1431void ssl_ReleaseRecvBufLock(sslSocket *ss);
1432
1433void ssl_GetXmitBufLock(sslSocket *ss);
1434void ssl_ReleaseXmitBufLock(sslSocket *ss);
1435
1436/* Placeholder value used in version ranges when SSL 3.0 and all
1437 * versions of TLS are disabled.
1438 */
1439#define SSL_LIBRARY_VERSION_NONE0 0
1440
1441/* SSL_LIBRARY_VERSION_MIN_SUPPORTED is the minimum version that this version
1442 * of libssl supports. Applications should use SSL_VersionRangeGetSupported at
1443 * runtime to determine which versions are supported by the version of libssl
1444 * in use.
1445 */
1446#define SSL_LIBRARY_VERSION_MIN_SUPPORTED_DATAGRAMSSL_LIBRARY_VERSION_TLS_1_1 SSL_LIBRARY_VERSION_TLS_1_1
1447#define SSL_LIBRARY_VERSION_MIN_SUPPORTED_STREAMSSL_LIBRARY_VERSION_3_0 SSL_LIBRARY_VERSION_3_0
1448
1449/* SSL_LIBRARY_VERSION_MAX_SUPPORTED is the maximum version that this version
1450 * of libssl supports. Applications should use SSL_VersionRangeGetSupported at
1451 * runtime to determine which versions are supported by the version of libssl
1452 * in use.
1453 */
1454#ifndef NSS_DISABLE_TLS_1_3
1455#define SSL_LIBRARY_VERSION_MAX_SUPPORTEDSSL_LIBRARY_VERSION_TLS_1_3 SSL_LIBRARY_VERSION_TLS_1_3
1456#else
1457#define SSL_LIBRARY_VERSION_MAX_SUPPORTEDSSL_LIBRARY_VERSION_TLS_1_3 SSL_LIBRARY_VERSION_TLS_1_2
1458#endif
1459
1460#define SSL_ALL_VERSIONS_DISABLED(vrange)((vrange)->min == 0) \
1461 ((vrange)->min == SSL_LIBRARY_VERSION_NONE0)
1462
1463extern PRBool ssl3_VersionIsSupported(SSLProtocolVariant protocolVariant,
1464 SSL3ProtocolVersion version);
1465
1466/* These functions are called from secnav, even though they're "private". */
1467
1468extern int SSL_RestartHandshakeAfterCertReq(struct sslSocketStr *ss,
1469 CERTCertificate *cert,
1470 SECKEYPrivateKey *key,
1471 CERTCertificateList *certChain);
1472extern sslSocket *ssl_FindSocket(PRFileDesc *fd);
1473extern void ssl_FreeSocket(struct sslSocketStr *ssl);
1474extern SECStatus SSL3_SendAlert(sslSocket *ss, SSL3AlertLevel level,
1475 SSL3AlertDescription desc);
1476extern SECStatus ssl3_DecodeError(sslSocket *ss);
1477
1478extern SECStatus ssl3_AuthCertificateComplete(sslSocket *ss, PRErrorCode error);
1479extern SECStatus ssl3_ClientCertCallbackComplete(sslSocket *ss, SECStatus outcome, SECKEYPrivateKey *clientPrivateKey, CERTCertificate *clientCertificate);
1480
1481/*
1482 * for dealing with SSL 3.0 clients sending SSL 2.0 format hellos
1483 */
1484extern SECStatus ssl3_HandleV2ClientHello(
1485 sslSocket *ss, unsigned char *buffer, unsigned int length, PRUint8 padding);
1486
1487SECStatus
1488ssl3_CreateClientHelloPreamble(sslSocket *ss, const sslSessionID *sid,
1489 PRBool realSid, PRUint16 version, PRBool isEchInner,
1490 const sslBuffer *extensions, sslBuffer *preamble);
1491SECStatus ssl3_InsertChHeaderSize(const sslSocket *ss, sslBuffer *preamble, const sslBuffer *extensions);
1492SECStatus ssl3_SendClientHello(sslSocket *ss, sslClientHelloType type);
1493
1494/*
1495 * input into the SSL3 machinery from the actualy network reading code
1496 */
1497SECStatus ssl3_HandleRecord(sslSocket *ss, SSL3Ciphertext *cipher);
1498SECStatus ssl3_HandleNonApplicationData(sslSocket *ss, SSLContentType rType,
1499 DTLSEpoch epoch,
1500 sslSequenceNumber seqNum,
1501 sslBuffer *databuf);
1502SECStatus ssl_RemoveTLSCBCPadding(sslBuffer *plaintext, unsigned int macSize);
1503
1504int ssl3_GatherAppDataRecord(sslSocket *ss, int flags);
1505int ssl3_GatherCompleteHandshake(sslSocket *ss, int flags);
1506
1507/* Create a new ref counted key pair object from two keys. */
1508extern sslKeyPair *ssl_NewKeyPair(SECKEYPrivateKey *privKey,
1509 SECKEYPublicKey *pubKey);
1510
1511/* get a new reference (bump ref count) to an ssl3KeyPair. */
1512extern sslKeyPair *ssl_GetKeyPairRef(sslKeyPair *keyPair);
1513
1514/* Decrement keypair's ref count and free if zero. */
1515extern void ssl_FreeKeyPair(sslKeyPair *keyPair);
1516
1517extern sslEphemeralKeyPair *ssl_NewEphemeralKeyPair(
1518 const sslNamedGroupDef *group,
1519 SECKEYPrivateKey *privKey, SECKEYPublicKey *pubKey);
1520extern sslEphemeralKeyPair *ssl_NewEphemeralKeyPairWithKeys(
1521 const sslNamedGroupDef *group, sslKeyPair *keys);
1522extern sslEphemeralKeyPair *ssl_CopyEphemeralKeyPair(
1523 sslEphemeralKeyPair *keyPair);
1524extern void ssl_FreeEphemeralKeyPair(sslEphemeralKeyPair *keyPair);
1525extern sslEphemeralKeyPair *ssl_LookupEphemeralKeyPair(
1526 sslSocket *ss, const sslNamedGroupDef *groupDef);
1527extern PRBool ssl_HaveEphemeralKeyPair(const sslSocket *ss,
1528 const sslNamedGroupDef *groupDef);
1529extern void ssl_FreeEphemeralKeyPairs(sslSocket *ss);
1530
1531extern SECStatus ssl_AppendPaddedDHKeyShare(sslBuffer *buf,
1532 const SECKEYPublicKey *pubKey,
1533 PRBool appendLength);
1534extern PRBool ssl_CanUseSignatureScheme(SSLSignatureScheme scheme,
1535 const SSLSignatureScheme *peerSchemes,
1536 unsigned int peerSchemeCount,
1537 PRBool requireSha1,
1538 PRBool slotDoesPss);
1539extern const ssl3DHParams *ssl_GetDHEParams(const sslNamedGroupDef *groupDef);
1540extern SECStatus ssl_SelectDHEGroup(sslSocket *ss,
1541 const sslNamedGroupDef **groupDef);
1542extern SECStatus ssl_CreateDHEKeyPair(const sslNamedGroupDef *groupDef,
1543 const ssl3DHParams *params,
1544 sslEphemeralKeyPair **keyPair);
1545extern PRBool ssl_IsValidDHEShare(const SECItem *dh_p, const SECItem *dh_Ys);
1546extern SECStatus ssl_ValidateDHENamedGroup(sslSocket *ss,
1547 const SECItem *dh_p,
1548 const SECItem *dh_g,
1549 const sslNamedGroupDef **groupDef,
1550 const ssl3DHParams **dhParams);
1551
1552extern PRBool ssl_IsECCEnabled(const sslSocket *ss);
1553extern PRBool ssl_IsDHEEnabled(const sslSocket *ss);
1554
1555/* Macro for finding a curve equivalent in strength to RSA key's */
1556#define SSL_RSASTRENGTH_TO_ECSTRENGTH(s)((s <= 1024) ? 160 : ((s <= 2048) ? 224 : ((s <= 3072
) ? 256 : ((s <= 7168) ? 384 : 521))))
\
1557 ((s <= 1024) ? 160 \
1558 : ((s <= 2048) ? 224 \
1559 : ((s <= 3072) ? 256 \
1560 : ((s <= 7168) ? 384 \
1561 : 521))))
1562
1563extern const sslNamedGroupDef *ssl_LookupNamedGroup(SSLNamedGroup group);
1564extern PRBool ssl_NamedGroupEnabled(const sslSocket *ss, const sslNamedGroupDef *group);
1565extern SECStatus ssl_NamedGroup2ECParams(PLArenaPool *arena,
1566 const sslNamedGroupDef *curve,
1567 SECKEYECParams *params);
1568extern const sslNamedGroupDef *ssl_ECPubKey2NamedGroup(
1569 const SECKEYPublicKey *pubKey);
1570
1571extern const sslNamedGroupDef *ssl_GetECGroupForServerSocket(sslSocket *ss);
1572extern void ssl_FilterSupportedGroups(sslSocket *ss);
1573
1574extern SECStatus ssl3_CipherPrefSetDefault(ssl3CipherSuite which, PRBool on);
1575extern SECStatus ssl3_CipherPrefGetDefault(ssl3CipherSuite which, PRBool *on);
1576
1577extern SECStatus ssl3_CipherPrefSet(sslSocket *ss, ssl3CipherSuite which, PRBool on);
1578extern SECStatus ssl3_CipherPrefGet(const sslSocket *ss, ssl3CipherSuite which, PRBool *on);
1579
1580extern SECStatus ssl3_SetPolicy(ssl3CipherSuite which, PRInt32 policy);
1581extern SECStatus ssl3_GetPolicy(ssl3CipherSuite which, PRInt32 *policy);
1582
1583extern void ssl3_InitSocketPolicy(sslSocket *ss);
1584
1585extern SECStatus ssl3_RedoHandshake(sslSocket *ss, PRBool flushCache);
1586extern SECStatus ssl3_HandleHandshakeMessage(sslSocket *ss, PRUint8 *b,
1587 PRUint32 length,
1588 PRBool endOfRecord);
1589
1590extern void ssl3_DestroySSL3Info(sslSocket *ss);
1591
1592extern SECStatus ssl_ClientReadVersion(sslSocket *ss, PRUint8 **b,
1593 PRUint32 *length,
1594 SSL3ProtocolVersion *version);
1595extern SECStatus ssl3_NegotiateVersion(sslSocket *ss,
1596 SSL3ProtocolVersion peerVersion,
1597 PRBool allowLargerPeerVersion);
1598extern SECStatus ssl_ClientSetCipherSuite(sslSocket *ss,
1599 SSL3ProtocolVersion version,
1600 ssl3CipherSuite suite,
1601 PRBool initHashes);
1602
1603extern SECStatus ssl_GetPeerInfo(sslSocket *ss);
1604
1605/* ECDH functions */
1606extern SECStatus ssl3_SendECDHClientKeyExchange(sslSocket *ss,
1607 SECKEYPublicKey *svrPubKey);
1608extern SECStatus ssl3_HandleECDHServerKeyExchange(sslSocket *ss,
1609 PRUint8 *b, PRUint32 length);
1610extern SECStatus ssl3_HandleECDHClientKeyExchange(sslSocket *ss,
1611 PRUint8 *b, PRUint32 length,
1612 sslKeyPair *serverKeys);
1613extern SECStatus ssl3_SendECDHServerKeyExchange(sslSocket *ss);
1614extern SECStatus ssl_ImportECDHKeyShare(
1615 SECKEYPublicKey *peerKey,
1616 PRUint8 *b, PRUint32 length, const sslNamedGroupDef *curve);
1617
1618extern SECStatus ssl3_ComputeCommonKeyHash(SSLHashType hashAlg,
1619 PRUint8 *hashBuf,
1620 unsigned int bufLen,
1621 SSL3Hashes *hashes);
1622extern SECStatus ssl3_AppendSignatureAndHashAlgorithm(
1623 sslSocket *ss, const SSLSignatureAndHashAlg *sigAndHash);
1624extern SECStatus ssl3_ConsumeHandshake(sslSocket *ss, void *v, PRUint32 bytes,
1625 PRUint8 **b, PRUint32 *length);
1626extern SECStatus ssl3_ConsumeHandshakeNumber(sslSocket *ss, PRUint32 *num,
1627 PRUint32 bytes, PRUint8 **b,
1628 PRUint32 *length);
1629extern SECStatus ssl3_ConsumeHandshakeNumber64(sslSocket *ss, PRUint64 *num,
1630 PRUint32 bytes, PRUint8 **b,
1631 PRUint32 *length);
1632extern SECStatus ssl3_ConsumeHandshakeVariable(sslSocket *ss, SECItem *i,
1633 PRUint32 bytes, PRUint8 **b,
1634 PRUint32 *length);
1635extern SECStatus ssl_SignatureSchemeFromSpki(const CERTSubjectPublicKeyInfo *spki,
1636 PRBool isTls13,
1637 SSLSignatureScheme *scheme);
1638extern PRBool ssl_SignatureSchemeEnabled(const sslSocket *ss,
1639 SSLSignatureScheme scheme);
1640extern PRBool ssl_IsSupportedSignatureScheme(SSLSignatureScheme scheme);
1641extern SECStatus ssl_CheckSignatureSchemeConsistency(
1642 sslSocket *ss, SSLSignatureScheme scheme, CERTSubjectPublicKeyInfo *spki);
1643extern SECStatus ssl_ParseSignatureSchemes(const sslSocket *ss, PLArenaPool *arena,
1644 SSLSignatureScheme **schemesOut,
1645 unsigned int *numSchemesOut,
1646 unsigned char **b,
1647 unsigned int *len);
1648extern SECStatus ssl_ConsumeSignatureScheme(
1649 sslSocket *ss, PRUint8 **b, PRUint32 *length, SSLSignatureScheme *out);
1650extern SECStatus ssl3_SignHashes(sslSocket *ss, SSL3Hashes *hash,
1651 SECKEYPrivateKey *key, SECItem *buf);
1652extern SECStatus ssl3_VerifySignedHashes(sslSocket *ss, SSLSignatureScheme scheme,
1653 SSL3Hashes *hash, SECItem *buf);
1654/* new signature algorithms don't really have a 'sign hashes' interface,
1655 * TLS13 now supports proper signing, where, if we are signing hashes, we
1656 * will sign them with a proper hash-and-sign signature. Provide
1657 * an API for those places in TLS13 where we need to sign. This leverages
1658 * the work in secsign and secvfy, so we don't need to add a lot of
1659 * algorithm specific code. Once the sign/verify interfaces work, we can
1660 * just add the oid in tls13con.c and the ssl_sig_xxxx value and we are
1661 * good to go */
1662extern tlsSignOrVerifyContext tls_CreateSignOrVerifyContext(
1663 SECKEYPrivateKey *privKey,
1664 SECKEYPublicKey *pubKey,
1665 SSLSignatureScheme scheme, sslSignOrVerify type,
1666 SECItem *signature, void *pwArg);
1667SECStatus tls_SignOrVerifyUpdate(tlsSignOrVerifyContext ctx,
1668 const unsigned char *buf, int len);
1669SECStatus tls_SignOrVerifyEnd(tlsSignOrVerifyContext ctx, SECItem *sig);
1670void tls_DestroySignOrVerifyContext(tlsSignOrVerifyContext *ctx);
1671
1672extern SECStatus ssl3_CacheWrappedSecret(sslSocket *ss, sslSessionID *sid,
1673 PK11SymKey *secret);
1674extern void ssl3_FreeSniNameArray(TLSExtensionData *xtnData);
1675
1676/* Hello Extension related routines. */
1677extern void ssl3_SetSIDSessionTicket(sslSessionID *sid,
1678 /*in/out*/ NewSessionTicket *session_ticket);
1679SECStatus ssl3_EncodeSessionTicket(sslSocket *ss,
1680 const NewSessionTicket *ticket,
1681 const PRUint8 *appToken,
1682 unsigned int appTokenLen,
1683 PK11SymKey *secret, SECItem *ticket_data);
1684SECStatus SSLExp_SendSessionTicket(PRFileDesc *fd, const PRUint8 *token,
1685 unsigned int tokenLen);
1686
1687SECStatus ssl_MaybeSetSelfEncryptKeyPair(const sslKeyPair *keyPair);
1688SECStatus ssl_GetSelfEncryptKeys(sslSocket *ss, unsigned char *keyName,
1689 PK11SymKey **encKey, PK11SymKey **macKey);
1690void ssl_ResetSelfEncryptKeys();
1691
1692extern SECStatus ssl3_ValidateAppProtocol(const unsigned char *data,
1693 unsigned int length);
1694
1695/* Construct a new NSPR socket for the app to use */
1696extern PRFileDesc *ssl_NewPRSocket(sslSocket *ss, PRFileDesc *fd);
1697extern void ssl_FreePRSocket(PRFileDesc *fd);
1698
1699/* Internal config function so SSL3 can initialize the present state of
1700 * various ciphers */
1701extern unsigned int ssl3_config_match_init(sslSocket *);
1702
1703/* Return PR_TRUE if suite is usable. This if the suite is permitted by policy,
1704 * enabled, has a certificate (as needed), has a viable key agreement method, is
1705 * usable with the negotiated TLS version, and is otherwise usable. */
1706PRBool ssl3_config_match(const ssl3CipherSuiteCfg *suite, PRUint8 policy,
1707 const SSLVersionRange *vrange, const sslSocket *ss);
1708
1709/* calls for accessing wrapping keys across processes. */
1710extern SECStatus
1711ssl_GetWrappingKey(unsigned int symWrapMechIndex,
1712 unsigned int wrapKeyIndex, SSLWrappedSymWrappingKey *wswk);
1713
1714/* The caller passes in the new value it wants
1715 * to set. This code tests the wrapped sym key entry in the file on disk.
1716 * If it is uninitialized, this function writes the caller's value into
1717 * the disk entry, and returns false.
1718 * Otherwise, it overwrites the caller's wswk with the value obtained from
1719 * the disk, and returns PR_TRUE.
1720 * This is all done while holding the locks/semaphores necessary to make
1721 * the operation atomic.
1722 */
1723extern SECStatus
1724ssl_SetWrappingKey(SSLWrappedSymWrappingKey *wswk);
1725
1726/* get rid of the symmetric wrapping key references. */
1727extern SECStatus SSL3_ShutdownServerCache(void);
1728
1729extern SECStatus ssl_InitSymWrapKeysLock(void);
1730
1731extern SECStatus ssl_FreeSymWrapKeysLock(void);
1732
1733extern SECStatus ssl_InitSessionCacheLocks(PRBool lazyInit);
1734
1735extern SECStatus ssl_FreeSessionCacheLocks(void);
1736
1737CK_MECHANISM_TYPE ssl3_Alg2Mech(SSLCipherAlgorithm calg);
1738SECStatus ssl3_NegotiateCipherSuiteInner(sslSocket *ss, const SECItem *suites,
1739 PRUint16 version, PRUint16 *suitep);
1740SECStatus ssl3_NegotiateCipherSuite(sslSocket *ss, const SECItem *suites,
1741 PRBool initHashes);
1742SECStatus ssl3_InitHandshakeHashes(sslSocket *ss);
1743void ssl3_CoalesceEchHandshakeHashes(sslSocket *ss);
1744SECStatus ssl3_ServerCallSNICallback(sslSocket *ss);
1745SECStatus ssl3_FlushHandshake(sslSocket *ss, PRInt32 flags);
1746SECStatus ssl3_CompleteHandleCertificate(sslSocket *ss,
1747 PRUint8 *b, PRUint32 length);
1748void ssl3_SendAlertForCertError(sslSocket *ss, PRErrorCode errCode);
1749SECStatus ssl3_HandleNoCertificate(sslSocket *ss);
1750SECStatus ssl3_SendEmptyCertificate(sslSocket *ss);
1751void ssl3_CleanupPeerCerts(sslSocket *ss);
1752SECStatus ssl3_SendCertificateStatus(sslSocket *ss);
1753SECStatus ssl_SetAuthKeyBits(sslSocket *ss, const SECKEYPublicKey *pubKey);
1754SECStatus ssl3_HandleServerSpki(sslSocket *ss);
1755SECStatus ssl3_AuthCertificate(sslSocket *ss);
1756SECStatus ssl_ReadCertificateStatus(sslSocket *ss, PRUint8 *b,
1757 PRUint32 length);
1758SECStatus ssl3_EncodeSigAlgs(const sslSocket *ss, PRUint16 maxVersion,
1759 PRUint16 minVersion, PRBool forCert,
1760 PRBool grease, sslBuffer *buf);
1761SECStatus ssl3_EncodeFilteredSigAlgs(const sslSocket *ss,
1762 const SSLSignatureScheme *schemes,
1763 PRUint32 numSchemes, PRBool grease, sslBuffer *buf);
1764SECStatus ssl3_FilterSigAlgs(const sslSocket *ss, PRUint16 maxVersion, PRUint16 minVersion,
1765 PRBool disableRsae, PRBool forCert,
1766 unsigned int maxSchemes, SSLSignatureScheme *filteredSchemes,
1767 unsigned int *numFilteredSchemes);
1768SECStatus ssl_GetCertificateRequestCAs(const sslSocket *ss,
1769 unsigned int *calenp,
1770 const SECItem **namesp,
1771 unsigned int *nnamesp);
1772SECStatus ssl3_ParseCertificateRequestCAs(sslSocket *ss, PRUint8 **b,
1773 PRUint32 *length, CERTDistNames *ca_list);
1774SECStatus ssl3_BeginHandleCertificateRequest(
1775 sslSocket *ss, const SSLSignatureScheme *signatureSchemes,
1776 unsigned int signatureSchemeCount, CERTDistNames *ca_list);
1777SECStatus ssl_ConstructServerHello(sslSocket *ss, PRBool helloRetry,
1778 const sslBuffer *extensionBuf,
1779 sslBuffer *messageBuf);
1780SECStatus ssl3_SendServerHello(sslSocket *ss);
1781SECStatus ssl3_SendChangeCipherSpecsInt(sslSocket *ss);
1782SECStatus ssl3_ComputeHandshakeHashes(sslSocket *ss,
1783 ssl3CipherSpec *spec,
1784 SSL3Hashes *hashes,
1785 PRUint32 sender);
1786SECStatus ssl_CreateECDHEphemeralKeyPair(const sslSocket *ss,
1787 const sslNamedGroupDef *ecGroup,
1788 sslEphemeralKeyPair **keyPair);
1789SECStatus ssl_CreateStaticECDHEKey(sslSocket *ss,
1790 const sslNamedGroupDef *ecGroup);
1791SECStatus ssl3_FlushHandshake(sslSocket *ss, PRInt32 flags);
1792SECStatus ssl3_GetNewRandom(SSL3Random random);
1793PK11SymKey *ssl3_GetWrappingKey(sslSocket *ss,
1794 PK11SlotInfo *masterSecretSlot,
1795 CK_MECHANISM_TYPE masterWrapMech,
1796 void *pwArg);
1797SECStatus ssl3_FillInCachedSID(sslSocket *ss, sslSessionID *sid,
1798 PK11SymKey *secret);
1799const ssl3CipherSuiteDef *ssl_LookupCipherSuiteDef(ssl3CipherSuite suite);
1800const ssl3CipherSuiteCfg *ssl_LookupCipherSuiteCfg(ssl3CipherSuite suite,
1801 const ssl3CipherSuiteCfg *suites);
1802PRBool ssl3_CipherSuiteAllowedForVersionRange(ssl3CipherSuite cipherSuite,
1803 const SSLVersionRange *vrange);
1804
1805SECStatus ssl3_SelectServerCert(sslSocket *ss);
1806SECStatus ssl_PrivateKeySupportsRsaPss(SECKEYPrivateKey *privKey,
1807 CERTCertificate *cert,
1808 void *pwArg,
1809 PRBool *supportsRsaPss);
1810SECStatus ssl_PickSignatureScheme(sslSocket *ss,
1811 CERTCertificate *cert,
1812 SECKEYPublicKey *pubKey,
1813 SECKEYPrivateKey *privKey,
1814 const SSLSignatureScheme *peerSchemes,
1815 unsigned int peerSchemeCount,
1816 PRBool requireSha1,
1817 SSLSignatureScheme *schemPtr);
1818SECStatus ssl_PickClientSignatureScheme(sslSocket *ss,
1819 CERTCertificate *clientCertificate,
1820 SECKEYPrivateKey *privKey,
1821 const SSLSignatureScheme *schemes,
1822 unsigned int numSchemes,
1823 SSLSignatureScheme *schemePtr);
1824SECOidTag ssl3_HashTypeToOID(SSLHashType hashType);
1825SECOidTag ssl3_AuthTypeToOID(SSLAuthType hashType);
1826SSLHashType ssl_SignatureSchemeToHashType(SSLSignatureScheme scheme);
1827SSLAuthType ssl_SignatureSchemeToAuthType(SSLSignatureScheme scheme);
1828
1829SECStatus ssl3_SetupCipherSuite(sslSocket *ss, PRBool initHashes);
1830SECStatus ssl_InsertRecordHeader(const sslSocket *ss, ssl3CipherSpec *cwSpec,
1831 SSLContentType contentType, sslBuffer *wrBuf,
1832 PRBool *needsLength);
1833PRBool ssl_SignatureSchemeValid(SSLSignatureScheme scheme, SECOidTag spkiOid,
1834 PRBool isTls13);
1835
1836/* Pull in DTLS functions */
1837#include "dtlscon.h"
1838
1839/* Pull in TLS 1.3 functions */
1840#include "tls13con.h"
1841#include "dtls13con.h"
1842
1843/********************** misc calls *********************/
1844
1845#ifdef DEBUG1
1846extern void ssl3_CheckCipherSuiteOrderConsistency();
1847#endif
1848
1849extern int ssl_MapLowLevelError(int hiLevelError);
1850
1851PRTime ssl_Time(const sslSocket *ss);
1852PRBool ssl_TicketTimeValid(const sslSocket *ss, const NewSessionTicket *ticket);
1853
1854extern void SSL_AtomicIncrementLong(long *x);
1855
1856SECStatus ssl3_ApplyNSSPolicy(void);
1857
1858extern SECStatus
1859ssl3_TLSPRFWithMasterSecret(sslSocket *ss, ssl3CipherSpec *spec,
1860 const char *label, unsigned int labelLen,
1861 const unsigned char *val, unsigned int valLen,
1862 unsigned char *out, unsigned int outLen);
1863
1864extern void
1865ssl3_RecordKeyLog(sslSocket *ss, const char *label, PK11SymKey *secret);
1866
1867extern void
1868ssl3_WriteKeyLog(sslSocket *ss, const char *label, const SECItem *item);
1869
1870PRBool ssl_AlpnTagAllowed(const sslSocket *ss, const SECItem *tag);
1871
1872#ifdef TRACE
1873#define SSL_TRACE(msg)ssl_Trace msg ssl_Trace msg
1874#else
1875#define SSL_TRACE(msg)ssl_Trace msg
1876#endif
1877
1878void ssl_Trace(const char *format, ...);
1879
1880void ssl_CacheExternalToken(sslSocket *ss);
1881SECStatus ssl_DecodeResumptionToken(sslSessionID *sid, const PRUint8 *encodedTicket,
1882 PRUint32 encodedTicketLen);
1883PRBool ssl_IsResumptionTokenUsable(sslSocket *ss, sslSessionID *sid);
1884
1885/* unwrap helper function to handle the case where the wrapKey doesn't wind
1886 * * up in the correct token for the master secret */
1887PK11SymKey *ssl_unwrapSymKey(PK11SymKey *wrapKey,
1888 CK_MECHANISM_TYPE wrapType, SECItem *param,
1889 SECItem *wrappedKey,
1890 CK_MECHANISM_TYPE target, CK_ATTRIBUTE_TYPE operation,
1891 int keySize, CK_FLAGS keyFlags, void *pinArg);
1892
1893/* determine if the current ssl connection is operating in FIPS mode */
1894PRBool ssl_isFIPS(sslSocket *ss);
1895
1896/* Experimental APIs. Remove when stable. */
1897
1898SECStatus SSLExp_SetResumptionTokenCallback(PRFileDesc *fd,
1899 SSLResumptionTokenCallback cb,
1900 void *ctx);
1901SECStatus SSLExp_SetResumptionToken(PRFileDesc *fd, const PRUint8 *token,
1902 unsigned int len);
1903
1904SECStatus SSLExp_GetResumptionTokenInfo(const PRUint8 *tokenData, unsigned int tokenLen,
1905 SSLResumptionTokenInfo *token, unsigned int version);
1906
1907SECStatus SSLExp_DestroyResumptionTokenInfo(SSLResumptionTokenInfo *token);
1908
1909SECStatus SSLExp_SecretCallback(PRFileDesc *fd, SSLSecretCallback cb,
1910 void *arg);
1911SECStatus SSLExp_RecordLayerWriteCallback(PRFileDesc *fd,
1912 SSLRecordWriteCallback write,
1913 void *arg);
1914SECStatus SSLExp_RecordLayerData(PRFileDesc *fd, PRUint16 epoch,
1915 SSLContentType contentType,
1916 const PRUint8 *data, unsigned int len);
1917SECStatus SSLExp_GetCurrentEpoch(PRFileDesc *fd, PRUint16 *readEpoch,
1918 PRUint16 *writeEpoch);
1919
1920#define SSLResumptionTokenVersion2 2
1921
1922SECStatus SSLExp_MakeAead(PRUint16 version, PRUint16 cipherSuite, PK11SymKey *secret,
1923 const char *labelPrefix, unsigned int labelPrefixLen,
1924 SSLAeadContext **ctx);
1925
1926SECStatus SSLExp_MakeVariantAead(PRUint16 version, PRUint16 cipherSuite, SSLProtocolVariant variant,
1927 PK11SymKey *secret, const char *labelPrefix,
1928 unsigned int labelPrefixLen, SSLAeadContext **ctx);
1929SECStatus SSLExp_DestroyAead(SSLAeadContext *ctx);
1930SECStatus SSLExp_AeadEncrypt(const SSLAeadContext *ctx, PRUint64 counter,
1931 const PRUint8 *aad, unsigned int aadLen,
1932 const PRUint8 *plaintext, unsigned int plaintextLen,
1933 PRUint8 *out, unsigned int *outLen, unsigned int maxOut);
1934SECStatus SSLExp_AeadDecrypt(const SSLAeadContext *ctx, PRUint64 counter,
1935 const PRUint8 *aad, unsigned int aadLen,
1936 const PRUint8 *plaintext, unsigned int plaintextLen,
1937 PRUint8 *out, unsigned int *outLen, unsigned int maxOut);
1938
1939/* The next function is responsible for registering a certificate compression mechanism
1940 to be used for TLS connection.
1941 The caller passes SSLCertificateCompressionAlgorithm algorithm:
1942
1943 typedef struct SSLCertificateCompressionAlgorithmStr {
1944 SSLCertificateCompressionAlgorithmID id;
1945 const char* name;
1946 SECStatus (*encode)(const SECItem* input, SECItem* output);
1947 SECStatus (*decode)(const SECItem* input, unsigned char* output, size_t outputLen, size_t* usedLen);
1948 } SSLCertificateCompressionAlgorithm;
1949
1950 Certificate Compression encoding function is responsible for allocating the output buffer itself.
1951 If encoding function fails, the function has the install the appropriate error code and return an error.
1952
1953 Certificate Compression decoding function operates an output buffer allocated in NSS.
1954 The function returns success or an error code.
1955 If successful, the function sets the number of bytes used to stored the decoded certificate
1956 in the outparam usedLen. If provided buffer is not enough to store the output (or any problem has occured during
1957 decoding of the buffer), the function has the install the appropriate error code and return an error.
1958 Note: usedLen is always <= outputLen.
1959
1960 */
1961SECStatus SSLExp_SetCertificateCompressionAlgorithm(PRFileDesc *fd, SSLCertificateCompressionAlgorithm alg);
1962SECStatus SSLExp_HkdfExtract(PRUint16 version, PRUint16 cipherSuite,
1963 PK11SymKey *salt, PK11SymKey *ikm, PK11SymKey **keyp);
1964SECStatus SSLExp_HkdfExpandLabel(PRUint16 version, PRUint16 cipherSuite, PK11SymKey *prk,
1965 const PRUint8 *hsHash, unsigned int hsHashLen,
1966 const char *label, unsigned int labelLen,
1967 PK11SymKey **key);
1968SECStatus SSLExp_HkdfVariantExpandLabel(PRUint16 version, PRUint16 cipherSuite, PK11SymKey *prk,
1969 const PRUint8 *hsHash, unsigned int hsHashLen,
1970 const char *label, unsigned int labelLen,
1971 SSLProtocolVariant variant, PK11SymKey **key);
1972SECStatus
1973SSLExp_HkdfExpandLabelWithMech(PRUint16 version, PRUint16 cipherSuite, PK11SymKey *prk,
1974 const PRUint8 *hsHash, unsigned int hsHashLen,
1975 const char *label, unsigned int labelLen,
1976 CK_MECHANISM_TYPE mech, unsigned int keySize,
1977 PK11SymKey **keyp);
1978SECStatus
1979SSLExp_HkdfVariantExpandLabelWithMech(PRUint16 version, PRUint16 cipherSuite, PK11SymKey *prk,
1980 const PRUint8 *hsHash, unsigned int hsHashLen,
1981 const char *label, unsigned int labelLen,
1982 CK_MECHANISM_TYPE mech, unsigned int keySize,
1983 SSLProtocolVariant variant, PK11SymKey **keyp);
1984
1985SECStatus SSLExp_SetDtls13VersionWorkaround(PRFileDesc *fd, PRBool enabled);
1986
1987SECStatus SSLExp_SetTimeFunc(PRFileDesc *fd, SSLTimeFunc f, void *arg);
1988
1989extern SECStatus ssl_CreateMaskingContextInner(PRUint16 version, PRUint16 cipherSuite,
1990 SSLProtocolVariant variant,
1991 PK11SymKey *secret,
1992 const char *label,
1993 unsigned int labelLen,
1994 SSLMaskingContext **ctx);
1995
1996extern SECStatus ssl_CreateMaskInner(SSLMaskingContext *ctx, const PRUint8 *sample,
1997 unsigned int sampleLen, PRUint8 *outMask,
1998 unsigned int maskLen);
1999
2000extern SECStatus ssl_DestroyMaskingContextInner(SSLMaskingContext *ctx);
2001
2002SECStatus SSLExp_CreateMaskingContext(PRUint16 version, PRUint16 cipherSuite,
2003 PK11SymKey *secret,
2004 const char *label,
2005 unsigned int labelLen,
2006 SSLMaskingContext **ctx);
2007
2008SECStatus SSLExp_CreateVariantMaskingContext(PRUint16 version, PRUint16 cipherSuite,
2009 SSLProtocolVariant variant,
2010 PK11SymKey *secret,
2011 const char *label,
2012 unsigned int labelLen,
2013 SSLMaskingContext **ctx);
2014
2015SECStatus SSLExp_CreateMask(SSLMaskingContext *ctx, const PRUint8 *sample,
2016 unsigned int sampleLen, PRUint8 *mask,
2017 unsigned int len);
2018
2019SECStatus SSLExp_DestroyMaskingContext(SSLMaskingContext *ctx);
2020
2021SECStatus SSLExp_EnableTls13GreaseEch(PRFileDesc *fd, PRBool enabled);
2022SECStatus SSLExp_SetTls13GreaseEchSize(PRFileDesc *fd, PRUint8 size);
2023
2024SECStatus SSLExp_EnableTls13BackendEch(PRFileDesc *fd, PRBool enabled);
2025SECStatus SSLExp_CallExtensionWriterOnEchInner(PRFileDesc *fd, PRBool enabled);
2026
2027SECStatus SSLExp_PeerCertificateChainDER(PRFileDesc *fd, SECItemArray **out);
2028
2029SEC_END_PROTOS
2030
2031#if defined(XP_UNIX1)
2032#define SSL_GETPIDgetpid getpid
2033#elif defined(WIN32)
2034#define SSL_GETPIDgetpid _getpid
2035#else
2036#define SSL_GETPIDgetpid() 0
2037#endif
2038
2039#endif /* __sslimpl_h_ */