1 /* 2 * This file contains prototypes for the public SSL functions. 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 7 8 #ifndef __ssl_h_ 9 #define __ssl_h_ 10 11 #include "prtypes.h" 12 #include "prerror.h" 13 #include "prio.h" 14 #include "seccomon.h" 15 #include "cert.h" 16 #include "keyt.h" 17 18 #include "sslt.h" /* public ssl data types */ 19 20 #if defined(_WIN32) && !defined(IN_LIBSSL) && !defined(NSS_USE_STATIC_LIBS) 21 #define SSL_IMPORT extern __declspec(dllimport) 22 #else 23 #define SSL_IMPORT extern 24 #endif 25 26 SEC_BEGIN_PROTOS 27 28 /* constant table enumerating all implemented cipher suites. */ 29 SSL_IMPORT const PRUint16 SSL_ImplementedCiphers[]; 30 31 /* the same as the above, but is a function */ 32 SSL_IMPORT const PRUint16 *SSL_GetImplementedCiphers(void); 33 34 /* number of entries in the above table. */ 35 SSL_IMPORT const PRUint16 SSL_NumImplementedCiphers; 36 37 /* the same as the above, but is a function */ 38 SSL_IMPORT PRUint16 SSL_GetNumImplementedCiphers(void); 39 40 /* Macro to tell which ciphers in table are SSL2 vs SSL3/TLS. */ 41 #define SSL_IS_SSL2_CIPHER(which) (((which)&0xfff0) == 0xff00) 42 43 /* 44 ** Imports fd into SSL, returning a new socket. Copies SSL configuration 45 ** from model. 46 */ 47 SSL_IMPORT PRFileDesc *SSL_ImportFD(PRFileDesc *model, PRFileDesc *fd); 48 49 /* 50 ** Imports fd into DTLS, returning a new socket. Copies DTLS configuration 51 ** from model. 52 */ 53 SSL_IMPORT PRFileDesc *DTLS_ImportFD(PRFileDesc *model, PRFileDesc *fd); 54 55 /* 56 ** Enable/disable an ssl mode 57 ** 58 ** SSL_SECURITY: 59 ** enable/disable use of SSL security protocol before connect 60 ** 61 ** SSL_SOCKS: 62 ** enable/disable use of socks before connect 63 ** (No longer supported). 64 ** 65 ** SSL_REQUEST_CERTIFICATE: 66 ** require a certificate during secure connect 67 */ 68 /* options */ 69 #define SSL_SECURITY 1 /* (on by default) */ 70 #define SSL_SOCKS 2 /* (off by default) */ 71 #define SSL_REQUEST_CERTIFICATE 3 /* (off by default) */ 72 #define SSL_HANDSHAKE_AS_CLIENT 5 /* force accept to hs as client */ 73 /* (off by default) */ 74 #define SSL_HANDSHAKE_AS_SERVER 6 /* force connect to hs as server */ 75 /* (off by default) */ 76 77 /* OBSOLETE: SSL v2 is obsolete and may be removed soon. */ 78 #define SSL_ENABLE_SSL2 7 /* enable ssl v2 (off by default) */ 79 80 /* OBSOLETE: See "SSL Version Range API" below for the replacement and a 81 ** description of the non-obvious semantics of using SSL_ENABLE_SSL3. 82 */ 83 #define SSL_ENABLE_SSL3 8 /* enable ssl v3 (on by default) */ 84 85 #define SSL_NO_CACHE 9 /* don't use the session cache */ 86 /* (off by default) */ 87 #define SSL_REQUIRE_CERTIFICATE 10 /* (SSL_REQUIRE_FIRST_HANDSHAKE */ 88 /* by default) */ 89 #define SSL_ENABLE_FDX 11 /* permit simultaneous read/write */ 90 /* (off by default) */ 91 92 /* OBSOLETE: SSL v2 compatible hellos are not accepted by some TLS servers 93 ** and cannot negotiate extensions. SSL v2 is obsolete. This option may be 94 ** removed soon. 95 */ 96 #define SSL_V2_COMPATIBLE_HELLO 12 /* send v3 client hello in v2 fmt */ 97 /* (off by default) */ 98 99 /* OBSOLETE: See "SSL Version Range API" below for the replacement and a 100 ** description of the non-obvious semantics of using SSL_ENABLE_TLS. 101 */ 102 #define SSL_ENABLE_TLS 13 /* enable TLS (on by default) */ 103 104 #define SSL_ROLLBACK_DETECTION 14 /* for compatibility, default: on */ 105 #define SSL_NO_STEP_DOWN 15 /* (unsupported, deprecated, off) */ 106 #define SSL_BYPASS_PKCS11 16 /* (unsupported, deprecated, off) */ 107 #define SSL_NO_LOCKS 17 /* Don't use locks for protection */ 108 #define SSL_ENABLE_SESSION_TICKETS 18 /* Enable TLS SessionTicket */ 109 /* extension (off by default) */ 110 #define SSL_ENABLE_DEFLATE 19 /* (unsupported, deprecated, off) */ 111 #define SSL_ENABLE_RENEGOTIATION 20 /* Values below (default: never) */ 112 #define SSL_REQUIRE_SAFE_NEGOTIATION 21 /* Peer must send Signaling */ 113 /* Cipher Suite Value (SCSV) or */ 114 /* Renegotiation Info (RI) */ 115 /* extension in ALL handshakes. */ 116 /* default: off */ 117 #define SSL_ENABLE_FALSE_START 22 /* Enable SSL false start (off by */ 118 /* default, applies only to */ 119 /* clients). False start is a */ 120 /* mode where an SSL client will start sending application data before 121 * verifying the server's Finished message. This means that we could end up 122 * sending data to an imposter. However, the data will be encrypted and 123 * only the true server can derive the session key. Thus, so long as the 124 * cipher isn't broken this is safe. The advantage of false start is that 125 * it saves a round trip for client-speaks-first protocols when performing a 126 * full handshake. 127 * 128 * In addition to enabling this option, the application must register a 129 * callback using the SSL_SetCanFalseStartCallback function. 130 */ 131 132 /* For SSL 3.0 and TLS 1.0, by default we prevent chosen plaintext attacks 133 * on SSL CBC mode cipher suites (see RFC 4346 Section F.3) by splitting 134 * non-empty application_data records into two records; the first record has 135 * only the first byte of plaintext, and the second has the rest. 136 * 137 * This only prevents the attack in the sending direction; the connection may 138 * still be vulnerable to such attacks if the peer does not implement a similar 139 * countermeasure. 140 * 141 * This protection mechanism is on by default; the default can be overridden by 142 * setting NSS_SSL_CBC_RANDOM_IV=0 in the environment prior to execution, 143 * and/or by the application setting the option SSL_CBC_RANDOM_IV to PR_FALSE. 144 * 145 * The per-record IV in TLS 1.1 and later adds one block of overhead per 146 * record, whereas this hack will add at least two blocks of overhead per 147 * record, so TLS 1.1+ will always be more efficient. 148 * 149 * Other implementations (e.g. some versions of OpenSSL, in some 150 * configurations) prevent the same attack by prepending an empty 151 * application_data record to every application_data record they send; we do 152 * not do that because some implementations cannot handle empty 153 * application_data records. Also, we only split application_data records and 154 * not other types of records, because some implementations will not accept 155 * fragmented records of some other types (e.g. some versions of NSS do not 156 * accept fragmented alerts). 157 */ 158 #define SSL_CBC_RANDOM_IV 23 159 #define SSL_ENABLE_OCSP_STAPLING 24 /* Request OCSP stapling (client) */ 160 161 /* SSL_ENABLE_NPN controls whether the NPN extension is enabled for the initial 162 * handshake when application layer protocol negotiation is used. 163 * SSL_SetNextProtoCallback or SSL_SetNextProtoNego must be used to control the 164 * application layer protocol negotiation; otherwise, the NPN extension will 165 * not be negotiated. SSL_ENABLE_NPN is currently enabled by default but this 166 * may change in future versions. 167 */ 168 #define SSL_ENABLE_NPN 25 169 170 /* SSL_ENABLE_ALPN controls whether the ALPN extension is enabled for the 171 * initial handshake when application layer protocol negotiation is used. 172 * SSL_SetNextProtoNego (not SSL_SetNextProtoCallback) must be used to control 173 * the application layer protocol negotiation; otherwise, the ALPN extension 174 * will not be negotiated. ALPN is not negotiated for renegotiation handshakes, 175 * even though the ALPN specification defines a way to use ALPN during 176 * renegotiations. SSL_ENABLE_ALPN is currently disabled by default, but this 177 * may change in future versions. 178 */ 179 #define SSL_ENABLE_ALPN 26 180 181 /* SSL_REUSE_SERVER_ECDHE_KEY controls whether the ECDHE server key is 182 * reused for multiple handshakes or generated each time. 183 * SSL_REUSE_SERVER_ECDHE_KEY is currently enabled by default. 184 * This socket option is for ECDHE, only. It is unrelated to DHE. 185 */ 186 #define SSL_REUSE_SERVER_ECDHE_KEY 27 187 188 #define SSL_ENABLE_FALLBACK_SCSV 28 /* Send fallback SCSV in \ 189 * handshakes. */ 190 191 /* SSL_ENABLE_SERVER_DHE controls whether DHE is enabled for the server socket. 192 */ 193 #define SSL_ENABLE_SERVER_DHE 29 194 195 /* Use draft-ietf-tls-session-hash. Controls whether we offer the 196 * extended_master_secret extension which, when accepted, hashes 197 * the handshake transcript into the master secret. This option is 198 * disabled by default. 199 */ 200 #define SSL_ENABLE_EXTENDED_MASTER_SECRET 30 201 202 /* Request Signed Certificate Timestamps via TLS extension (client) */ 203 #define SSL_ENABLE_SIGNED_CERT_TIMESTAMPS 31 204 205 /* Ordinarily, when negotiating a TLS_DHE_* cipher suite the server picks the 206 * group. draft-ietf-tls-negotiated-ff-dhe changes this to use supported_groups 207 * (formerly supported_curves) to signal which pre-defined groups are OK. 208 * 209 * This option causes an NSS client to use this extension and demand that those 210 * groups be used. A client will signal any enabled DHE groups in the 211 * supported_groups extension and reject groups that don't match what it has 212 * enabled. A server will only negotiate TLS_DHE_* cipher suites if the 213 * client includes the extension. 214 * 215 * See SSL_NamedGroupConfig() for how to control which groups are enabled. 216 * 217 * This option cannot be enabled if NSS is not compiled with ECC support. 218 */ 219 #define SSL_REQUIRE_DH_NAMED_GROUPS 32 220 221 /* Allow 0-RTT data (for TLS 1.3). 222 * 223 * When this option is set, the server's session tickets will contain 224 * a flag indicating that it accepts 0-RTT. When resuming such a 225 * session, PR_Write() on the client will be allowed immediately after 226 * starting the handshake and PR_Read() on the server will be allowed 227 * on the server to read that data. Calls to 228 * SSL_GetPreliminaryChannelInfo() and SSL_GetNextProto() 229 * can be made used during this period to learn about the channel 230 * parameters. 231 * 232 * The transition between the 0-RTT and 1-RTT modes is marked by the 233 * handshake callback. However, it is possible to force the completion 234 * of the handshake (and cause the handshake callback to be called) 235 * prior to reading all 0-RTT data using SSL_ForceHandshake(). To 236 * ensure that all early data is read before the handshake callback, any 237 * time that SSL_ForceHandshake() returns a PR_WOULD_BLOCK_ERROR, use 238 * PR_Read() to read all available data. If PR_Read() is called 239 * multiple times, this will result in the handshake completing, but the 240 * handshake callback will occur after early data has all been read. 241 * 242 * WARNING: 0-RTT data has different anti-replay and PFS properties than 243 * the rest of the TLS data. See [draft-ietf-tls-tls13; Section 8] 244 * for more details. 245 * 246 * Note: when DTLS 1.3 is in use, any 0-RTT data received after EndOfEarlyData 247 * (e.g., because of reordering) is discarded. 248 */ 249 #define SSL_ENABLE_0RTT_DATA 33 250 251 /* Enables TLS 1.3 compatibility mode. In this mode, the client includes a fake 252 * session ID in the handshake and sends a ChangeCipherSpec. A server will 253 * always use the setting chosen by the client, so the value of this option has 254 * no effect for a server. This setting is ignored for DTLS. */ 255 #define SSL_ENABLE_TLS13_COMPAT_MODE 35 256 257 #ifdef SSL_DEPRECATED_FUNCTION 258 /* Old deprecated function names */ 259 SSL_IMPORT SECStatus SSL_Enable(PRFileDesc *fd, int option, PRIntn on); 260 SSL_IMPORT SECStatus SSL_EnableDefault(int option, PRIntn on); 261 #endif 262 263 /* Set (and get) options for sockets and defaults for newly created sockets. 264 * 265 * While the |val| parameter of these methods is PRIntn, options only support 266 * two values by default: PR_TRUE or PR_FALSE. The documentation of specific 267 * options will explain if other values are permitted. 268 */ 269 SSL_IMPORT SECStatus SSL_OptionSet(PRFileDesc *fd, PRInt32 option, PRIntn val); 270 SSL_IMPORT SECStatus SSL_OptionGet(PRFileDesc *fd, PRInt32 option, PRIntn *val); 271 SSL_IMPORT SECStatus SSL_OptionSetDefault(PRInt32 option, PRIntn val); 272 SSL_IMPORT SECStatus SSL_OptionGetDefault(PRInt32 option, PRIntn *val); 273 SSL_IMPORT SECStatus SSL_CertDBHandleSet(PRFileDesc *fd, CERTCertDBHandle *dbHandle); 274 275 /* SSLNextProtoCallback is called during the handshake for the client, when a 276 * Next Protocol Negotiation (NPN) extension has been received from the server. 277 * |protos| and |protosLen| define a buffer which contains the server's 278 * advertisement. This data is guaranteed to be well formed per the NPN spec. 279 * |protoOut| is a buffer provided by the caller, of length 255 (the maximum 280 * allowed by the protocol). On successful return, the protocol to be announced 281 * to the server will be in |protoOut| and its length in |*protoOutLen|. 282 * 283 * The callback must return SECFailure or SECSuccess (not SECWouldBlock). 284 */ 285 typedef SECStatus(PR_CALLBACK *SSLNextProtoCallback)( 286 void *arg, 287 PRFileDesc *fd, 288 const unsigned char *protos, 289 unsigned int protosLen, 290 unsigned char *protoOut, 291 unsigned int *protoOutLen, 292 unsigned int protoMaxOut); 293 294 /* SSL_SetNextProtoCallback sets a callback function to handle Next Protocol 295 * Negotiation. It causes a client to advertise NPN. */ 296 SSL_IMPORT SECStatus SSL_SetNextProtoCallback(PRFileDesc *fd, 297 SSLNextProtoCallback callback, 298 void *arg); 299 300 /* SSL_SetNextProtoNego can be used as an alternative to 301 * SSL_SetNextProtoCallback. It also causes a client to advertise NPN and 302 * installs a default callback function which selects the first supported 303 * protocol in server-preference order. If no matching protocol is found it 304 * selects the first supported protocol. 305 * 306 * Using this function also allows the client to transparently support ALPN. 307 * The same set of protocols will be advertised via ALPN and, if the server 308 * uses ALPN to select a protocol, SSL_GetNextProto will return 309 * SSL_NEXT_PROTO_SELECTED as the state. 310 * 311 * Since NPN uses the first protocol as the fallback protocol, when sending an 312 * ALPN extension, the first protocol is moved to the end of the list. This 313 * indicates that the fallback protocol is the least preferred. The other 314 * protocols should be in preference order. 315 * 316 * The supported protocols are specified in |data| in wire-format (8-bit 317 * length-prefixed). For example: "\010http/1.1\006spdy/2". */ 318 SSL_IMPORT SECStatus SSL_SetNextProtoNego(PRFileDesc *fd, 319 const unsigned char *data, 320 unsigned int length); 321 322 typedef enum SSLNextProtoState { 323 SSL_NEXT_PROTO_NO_SUPPORT = 0, /* No peer support */ 324 SSL_NEXT_PROTO_NEGOTIATED = 1, /* Mutual agreement */ 325 SSL_NEXT_PROTO_NO_OVERLAP = 2, /* No protocol overlap found */ 326 SSL_NEXT_PROTO_SELECTED = 3, /* Server selected proto (ALPN) */ 327 SSL_NEXT_PROTO_EARLY_VALUE = 4 /* We are in 0-RTT using this value. */ 328 } SSLNextProtoState; 329 330 /* SSL_GetNextProto can be used in the HandshakeCallback or any time after 331 * a handshake to retrieve the result of the Next Protocol negotiation. 332 * 333 * The length of the negotiated protocol, if any, is written into *bufLen. 334 * If the negotiated protocol is longer than bufLenMax, then SECFailure is 335 * returned. Otherwise, the negotiated protocol, if any, is written into buf, 336 * and SECSuccess is returned. */ 337 SSL_IMPORT SECStatus SSL_GetNextProto(PRFileDesc *fd, 338 SSLNextProtoState *state, 339 unsigned char *buf, 340 unsigned int *bufLen, 341 unsigned int bufLenMax); 342 343 /* 344 ** Control ciphers that SSL uses. If on is non-zero then the named cipher 345 ** is enabled, otherwise it is disabled. 346 ** The "cipher" values are defined in sslproto.h (the SSL_EN_* values). 347 ** EnableCipher records user preferences. 348 ** SetPolicy sets the policy according to the policy module. 349 */ 350 #ifdef SSL_DEPRECATED_FUNCTION 351 /* Old deprecated function names */ 352 SSL_IMPORT SECStatus SSL_EnableCipher(long which, PRBool enabled); 353 SSL_IMPORT SECStatus SSL_SetPolicy(long which, int policy); 354 #endif 355 356 /* New function names */ 357 SSL_IMPORT SECStatus SSL_CipherPrefSet(PRFileDesc *fd, PRInt32 cipher, PRBool enabled); 358 SSL_IMPORT SECStatus SSL_CipherPrefGet(PRFileDesc *fd, PRInt32 cipher, PRBool *enabled); 359 SSL_IMPORT SECStatus SSL_CipherPrefSetDefault(PRInt32 cipher, PRBool enabled); 360 SSL_IMPORT SECStatus SSL_CipherPrefGetDefault(PRInt32 cipher, PRBool *enabled); 361 SSL_IMPORT SECStatus SSL_CipherPolicySet(PRInt32 cipher, PRInt32 policy); 362 SSL_IMPORT SECStatus SSL_CipherPolicyGet(PRInt32 cipher, PRInt32 *policy); 363 364 /* 365 ** Control for TLS signature schemes for TLS 1.2 and 1.3. 366 ** 367 ** This governs what signature schemes (or algorithms) are sent by a client in 368 ** the signature_algorithms extension. A client will not accept a signature 369 ** from a server unless it uses an enabled algorithm. 370 ** 371 ** This also governs what the server sends in the supported_signature_algorithms 372 ** field of a CertificateRequest. 373 ** 374 ** This changes what the server uses to sign ServerKeyExchange and 375 ** CertificateVerify messages. An endpoint uses the first entry from this list 376 ** that is compatible with both its certificate and its peer's supported 377 ** values. 378 ** 379 ** This configuration affects TLS 1.2, but the combination of EC group and hash 380 ** algorithm is interpreted loosely to be compatible with other implementations. 381 ** For TLS 1.2, NSS will ignore the curve group when generating or verifying 382 ** ECDSA signatures. For example, a P-384 ECDSA certificate is used with 383 ** SHA-256 if ssl_sig_ecdsa_secp256r1_sha256 is enabled. 384 ** 385 ** Omitting SHA-256 schemes from this list might be foolish. Support is 386 ** mandatory in TLS 1.2 and 1.3 and there might be interoperability issues. 387 */ 388 SSL_IMPORT SECStatus SSL_SignatureSchemePrefSet( 389 PRFileDesc *fd, const SSLSignatureScheme *schemes, unsigned int count); 390 391 /* Deprecated, use SSL_SignatureSchemePrefSet() instead. */ 392 SSL_IMPORT SECStatus SSL_SignaturePrefSet( 393 PRFileDesc *fd, const SSLSignatureAndHashAlg *algorithms, 394 unsigned int count); 395 396 /* 397 ** Get the currently configured signature schemes. 398 ** 399 ** The schemes are written to |schemes| but not if there are more than 400 ** |maxCount| values configured. The number of schemes that are in use are 401 ** written to |count|. This fails if |maxCount| is insufficiently large. 402 */ 403 SSL_IMPORT SECStatus SSL_SignatureSchemePrefGet( 404 PRFileDesc *fd, SSLSignatureScheme *algorithms, unsigned int *count, 405 unsigned int maxCount); 406 407 /* Deprecated, use SSL_SignatureSchemePrefGet() instead. */ 408 SSL_IMPORT SECStatus SSL_SignaturePrefGet( 409 PRFileDesc *fd, SSLSignatureAndHashAlg *algorithms, unsigned int *count, 410 unsigned int maxCount); 411 412 /* 413 ** Returns the maximum number of signature algorithms that are supported and 414 ** can be set or retrieved using SSL_SignatureSchemePrefSet or 415 ** SSL_SignatureSchemePrefGet. 416 */ 417 SSL_IMPORT unsigned int SSL_SignatureMaxCount(void); 418 419 /* 420 ** Define custom priorities for EC and FF groups used in DH key exchange and EC 421 ** groups for ECDSA. This only changes the order of enabled lists (and thus 422 ** their priorities) and enables all groups in |groups| while disabling all other 423 ** groups. 424 */ 425 SSL_IMPORT SECStatus SSL_NamedGroupConfig(PRFileDesc *fd, 426 const SSLNamedGroup *groups, 427 unsigned int num_groups); 428 429 /* 430 ** Configure the socket to configure additional key shares. Normally when a TLS 431 ** 1.3 ClientHello is sent, just one key share is included using the first 432 ** preference group (as set by SSL_NamedGroupConfig). If the server decides to 433 ** pick a different group for key exchange, it is forced to send a 434 ** HelloRetryRequest, which adds an entire round trip of latency. 435 ** 436 ** This function can be used to configure libssl to generate additional key 437 ** shares when sending a TLS 1.3 ClientHello. If |count| is set to a non-zero 438 ** value, then additional key shares are generated. Shares are added in the 439 ** preference order set in SSL_NamedGroupConfig. |count| can be set to any 440 ** value; NSS limits the number of shares to the number of supported groups. 441 */ 442 SSL_IMPORT SECStatus SSL_SendAdditionalKeyShares(PRFileDesc *fd, 443 unsigned int count); 444 445 /* Deprecated: use SSL_NamedGroupConfig() instead. 446 ** SSL_DHEGroupPrefSet is used to configure the set of allowed/enabled DHE group 447 ** parameters that can be used by NSS for the given server socket. 448 ** The first item in the array is used as the default group, if no other 449 ** selection criteria can be used by NSS. 450 ** The set is provided as an array of identifiers as defined by SSLDHEGroupType. 451 ** If more than one group identifier is provided, NSS will select the one to use. 452 ** For example, a TLS extension sent by the client might indicate a preference. 453 */ 454 SSL_IMPORT SECStatus SSL_DHEGroupPrefSet(PRFileDesc *fd, 455 const SSLDHEGroupType *groups, 456 PRUint16 num_groups); 457 458 /* Enable the use of a DHE group that's smaller than the library default, 459 ** for backwards compatibility reasons. The DH parameters will be created 460 ** at the time this function is called, which might take a very long time. 461 ** The function will block until generation is completed. 462 ** The intention is to enforce that fresh and safe parameters are generated 463 ** each time a process is started. 464 ** At the time this API was initially implemented, the API will enable the 465 ** use of 1024 bit DHE parameters. This value might get increased in future 466 ** versions of NSS. 467 ** 468 ** It is allowed to call this API will a NULL value for parameter fd, 469 ** which will prepare the global parameters that NSS will reuse for the remainder 470 ** of the process lifetime. This can be used early after startup of a process, 471 ** to avoid a delay when handling incoming client connections. 472 ** This preparation with a NULL for parameter fd will NOT enable the weak group 473 ** on sockets. The function needs to be called again for every socket that 474 ** should use the weak group. 475 ** 476 ** It is allowed to use this API in combination with the SSL_NamedGroupConfig API. 477 ** If both APIs have been called, the weakest group will be used, unless it is 478 ** certain that the client supports larger group parameters. The weak group will 479 ** be used as the default group for TLS <= 1.2, overriding the preference for 480 ** the first group potentially set with a call to SSL_NamedGroupConfig. 481 */ 482 SSL_IMPORT SECStatus SSL_EnableWeakDHEPrimeGroup(PRFileDesc *fd, PRBool enabled); 483 484 /* SSL Version Range API 485 ** 486 ** This API should be used to control SSL 3.0 & TLS support instead of the 487 ** older SSL_Option* API; however, the SSL_Option* API MUST still be used to 488 ** control SSL 2.0 support. In this version of libssl, SSL 3.0 and TLS 1.0 are 489 ** enabled by default. Future versions of libssl may change which versions of 490 ** the protocol are enabled by default. 491 ** 492 ** The SSLProtocolVariant enum indicates whether the protocol is of type 493 ** stream or datagram. This must be provided to the functions that do not 494 ** take an fd. Functions which take an fd will get the variant from the fd, 495 ** which is typed. 496 ** 497 ** Using the new version range API in conjunction with the older 498 ** SSL_OptionSet-based API for controlling the enabled protocol versions may 499 ** cause unexpected results. Going forward, we guarantee only the following: 500 ** 501 ** SSL_OptionGet(SSL_ENABLE_TLS) will return PR_TRUE if *ANY* versions of TLS 502 ** are enabled. 503 ** 504 ** SSL_OptionSet(SSL_ENABLE_TLS, PR_FALSE) will disable *ALL* versions of TLS, 505 ** including TLS 1.0 and later. 506 ** 507 ** The above two properties provide compatibility for applications that use 508 ** SSL_OptionSet to implement the insecure fallback from TLS 1.x to SSL 3.0. 509 ** 510 ** SSL_OptionSet(SSL_ENABLE_TLS, PR_TRUE) will enable TLS 1.0, and may also 511 ** enable some later versions of TLS, if it is necessary to do so in order to 512 ** keep the set of enabled versions contiguous. For example, if TLS 1.2 is 513 ** enabled, then after SSL_OptionSet(SSL_ENABLE_TLS, PR_TRUE), TLS 1.0, 514 ** TLS 1.1, and TLS 1.2 will be enabled, and the call will have no effect on 515 ** whether SSL 3.0 is enabled. If no later versions of TLS are enabled at the 516 ** time SSL_OptionSet(SSL_ENABLE_TLS, PR_TRUE) is called, then no later 517 ** versions of TLS will be enabled by the call. 518 ** 519 ** SSL_OptionSet(SSL_ENABLE_SSL3, PR_FALSE) will disable SSL 3.0, and will not 520 ** change the set of TLS versions that are enabled. 521 ** 522 ** SSL_OptionSet(SSL_ENABLE_SSL3, PR_TRUE) will enable SSL 3.0, and may also 523 ** enable some versions of TLS if TLS 1.1 or later is enabled at the time of 524 ** the call, the same way SSL_OptionSet(SSL_ENABLE_TLS, PR_TRUE) works, in 525 ** order to keep the set of enabled versions contiguous. 526 */ 527 528 /* Returns, in |*vrange|, the range of SSL3/TLS versions supported for the 529 ** given protocol variant by the version of libssl linked-to at runtime. 530 */ 531 SSL_IMPORT SECStatus SSL_VersionRangeGetSupported( 532 SSLProtocolVariant protocolVariant, SSLVersionRange *vrange); 533 534 /* Returns, in |*vrange|, the range of SSL3/TLS versions enabled by default 535 ** for the given protocol variant. 536 */ 537 SSL_IMPORT SECStatus SSL_VersionRangeGetDefault( 538 SSLProtocolVariant protocolVariant, SSLVersionRange *vrange); 539 540 /* Sets the range of enabled-by-default SSL3/TLS versions for the given 541 ** protocol variant to |*vrange|. 542 */ 543 SSL_IMPORT SECStatus SSL_VersionRangeSetDefault( 544 SSLProtocolVariant protocolVariant, const SSLVersionRange *vrange); 545 546 /* Returns, in |*vrange|, the range of enabled SSL3/TLS versions for |fd|. */ 547 SSL_IMPORT SECStatus SSL_VersionRangeGet(PRFileDesc *fd, 548 SSLVersionRange *vrange); 549 550 /* Sets the range of enabled SSL3/TLS versions for |fd| to |*vrange|. */ 551 SSL_IMPORT SECStatus SSL_VersionRangeSet(PRFileDesc *fd, 552 const SSLVersionRange *vrange); 553 554 /* Sets the version to check the server random against for the 555 * fallback check defined in [draft-ietf-tls-tls13-11 Section 6.3.1.1]. 556 * This function is provided to allow for detection of forced downgrade 557 * attacks against client-side reconnect-and-fallback outside of TLS 558 * by setting |version| to be that of the original connection, rather 559 * than that of the new connection. 560 * 561 * The default, which can also be enabled by setting |version| to 562 * zero, is just to check against the max version in the 563 * version range (see SSL_VersionRangeSet). */ 564 SSL_IMPORT SECStatus SSL_SetDowngradeCheckVersion(PRFileDesc *fd, 565 PRUint16 version); 566 567 /* Values for "policy" argument to SSL_CipherPolicySet */ 568 /* Values returned by SSL_CipherPolicyGet. */ 569 #define SSL_NOT_ALLOWED 0 /* or invalid or unimplemented */ 570 #define SSL_ALLOWED 1 571 #define SSL_RESTRICTED 2 /* only with "Step-Up" certs. */ 572 573 /* Values for "on" with SSL_REQUIRE_CERTIFICATE. */ 574 #define SSL_REQUIRE_NEVER ((PRBool)0) 575 #define SSL_REQUIRE_ALWAYS ((PRBool)1) 576 #define SSL_REQUIRE_FIRST_HANDSHAKE ((PRBool)2) 577 #define SSL_REQUIRE_NO_ERROR ((PRBool)3) 578 579 /* Values for "on" with SSL_ENABLE_RENEGOTIATION */ 580 /* Never renegotiate at all. */ 581 #define SSL_RENEGOTIATE_NEVER ((PRBool)0) 582 /* Renegotiate without restriction, whether or not the peer's client hello */ 583 /* bears the renegotiation info extension. Vulnerable, as in the past. */ 584 #define SSL_RENEGOTIATE_UNRESTRICTED ((PRBool)1) 585 /* Only renegotiate if the peer's hello bears the TLS renegotiation_info */ 586 /* extension. This is safe renegotiation. */ 587 #define SSL_RENEGOTIATE_REQUIRES_XTN ((PRBool)2) 588 /* Disallow unsafe renegotiation in server sockets only, but allow clients */ 589 /* to continue to renegotiate with vulnerable servers. */ 590 /* This value should only be used during the transition period when few */ 591 /* servers have been upgraded. */ 592 #define SSL_RENEGOTIATE_TRANSITIONAL ((PRBool)3) 593 594 /* 595 ** Reset the handshake state for fd. This will make the complete SSL 596 ** handshake protocol execute from the ground up on the next i/o 597 ** operation. 598 */ 599 SSL_IMPORT SECStatus SSL_ResetHandshake(PRFileDesc *fd, PRBool asServer); 600 601 /* 602 ** Force the handshake for fd to complete immediately. This blocks until 603 ** the complete SSL handshake protocol is finished. 604 */ 605 SSL_IMPORT SECStatus SSL_ForceHandshake(PRFileDesc *fd); 606 607 /* 608 ** Same as above, but with an I/O timeout. 609 */ 610 SSL_IMPORT SECStatus SSL_ForceHandshakeWithTimeout(PRFileDesc *fd, 611 PRIntervalTime timeout); 612 613 /* 614 ** Query security status of socket. *on is set to one if security is 615 ** enabled. *keySize will contain the stream key size used. *issuer will 616 ** contain the RFC1485 verison of the name of the issuer of the 617 ** certificate at the other end of the connection. For a client, this is 618 ** the issuer of the server's certificate; for a server, this is the 619 ** issuer of the client's certificate (if any). Subject is the subject of 620 ** the other end's certificate. The pointers can be zero if the desired 621 ** data is not needed. All strings returned by this function are owned 622 ** by the caller, and need to be freed with PORT_Free. 623 */ 624 SSL_IMPORT SECStatus SSL_SecurityStatus(PRFileDesc *fd, int *on, char **cipher, 625 int *keySize, int *secretKeySize, 626 char **issuer, char **subject); 627 628 /* Values for "on" */ 629 #define SSL_SECURITY_STATUS_NOOPT -1 630 #define SSL_SECURITY_STATUS_OFF 0 631 #define SSL_SECURITY_STATUS_ON_HIGH 1 632 #define SSL_SECURITY_STATUS_ON_LOW 2 633 #define SSL_SECURITY_STATUS_FORTEZZA 3 /* NO LONGER SUPPORTED */ 634 635 /* 636 ** Return the certificate for our SSL peer. If the client calls this 637 ** it will always return the server's certificate. If the server calls 638 ** this, it may return NULL if client authentication is not enabled or 639 ** if the client had no certificate when asked. 640 ** "fd" the socket "file" descriptor 641 */ 642 SSL_IMPORT CERTCertificate *SSL_PeerCertificate(PRFileDesc *fd); 643 644 /* 645 ** Return the certificates presented by the SSL peer. If the SSL peer 646 ** did not present certificates, return NULL with the 647 ** SSL_ERROR_NO_CERTIFICATE error. On failure, return NULL with an error 648 ** code other than SSL_ERROR_NO_CERTIFICATE. 649 ** "fd" the socket "file" descriptor 650 */ 651 SSL_IMPORT CERTCertList *SSL_PeerCertificateChain(PRFileDesc *fd); 652 653 /* SSL_PeerStapledOCSPResponses returns the OCSP responses that were provided 654 * by the TLS server. The return value is a pointer to an internal SECItemArray 655 * that contains the returned OCSP responses; it is only valid until the 656 * callback function that calls SSL_PeerStapledOCSPResponses returns. 657 * 658 * If no OCSP responses were given by the server then the result will be empty. 659 * If there was an error, then the result will be NULL. 660 * 661 * You must set the SSL_ENABLE_OCSP_STAPLING option to enable OCSP stapling. 662 * to be provided by a server. 663 * 664 * libssl does not do any validation of the OCSP response itself; the 665 * authenticate certificate hook is responsible for doing so. The default 666 * authenticate certificate hook, SSL_AuthCertificate, does not implement 667 * any OCSP stapling funtionality, but this may change in future versions. 668 */ 669 SSL_IMPORT const SECItemArray *SSL_PeerStapledOCSPResponses(PRFileDesc *fd); 670 671 /* SSL_PeerSignedCertTimestamps returns the signed_certificate_timestamp 672 * extension data provided by the TLS server. The return value is a pointer 673 * to an internal SECItem that contains the returned response (as a serialized 674 * SignedCertificateTimestampList, see RFC 6962). The returned pointer is only 675 * valid until the callback function that calls SSL_PeerSignedCertTimestamps 676 * (e.g. the authenticate certificate hook, or the handshake callback) returns. 677 * 678 * If no Signed Certificate Timestamps were given by the server then the result 679 * will be empty. If there was an error, then the result will be NULL. 680 * 681 * You must set the SSL_ENABLE_SIGNED_CERT_TIMESTAMPS option to indicate support 682 * for Signed Certificate Timestamps to a server. 683 * 684 * libssl does not do any parsing or validation of the response itself. 685 */ 686 SSL_IMPORT const SECItem *SSL_PeerSignedCertTimestamps(PRFileDesc *fd); 687 688 /* SSL_SetStapledOCSPResponses stores an array of one or multiple OCSP responses 689 * in the fd's data, which may be sent as part of a server side cert_status 690 * handshake message. Parameter |responses| is for the server certificate of 691 * the key exchange type |kea|. 692 * The function will duplicate the responses array. 693 * 694 * Deprecated: see SSL_ConfigSecureServer for details. 695 */ 696 SSL_IMPORT SECStatus 697 SSL_SetStapledOCSPResponses(PRFileDesc *fd, const SECItemArray *responses, 698 SSLKEAType kea); 699 700 /* 701 * SSL_SetSignedCertTimestamps stores serialized signed_certificate_timestamp 702 * extension data in the fd. The signed_certificate_timestamp data is sent 703 * during the handshake (if requested by the client). Parameter |scts| 704 * is for the server certificate of the key exchange type |kea|. 705 * The function will duplicate the provided data item. To clear previously 706 * set data for a given key exchange type |kea|, pass NULL to |scts|. 707 * 708 * Deprecated: see SSL_ConfigSecureServer for details. 709 */ 710 SSL_IMPORT SECStatus 711 SSL_SetSignedCertTimestamps(PRFileDesc *fd, const SECItem *scts, 712 SSLKEAType kea); 713 714 /* 715 ** Authenticate certificate hook. Called when a certificate comes in 716 ** (because of SSL_REQUIRE_CERTIFICATE in SSL_Enable) to authenticate the 717 ** certificate. 718 ** 719 ** The authenticate certificate hook must return SECSuccess to indicate the 720 ** certificate is valid, SECFailure to indicate the certificate is invalid, 721 ** or SECWouldBlock if the application will authenticate the certificate 722 ** asynchronously. SECWouldBlock is only supported for non-blocking sockets. 723 ** 724 ** If the authenticate certificate hook returns SECFailure, then the bad cert 725 ** hook will be called. The bad cert handler is NEVER called if the 726 ** authenticate certificate hook returns SECWouldBlock. If the application 727 ** needs to handle and/or override a bad cert, it should do so before it 728 ** calls SSL_AuthCertificateComplete (modifying the error it passes to 729 ** SSL_AuthCertificateComplete as needed). 730 ** 731 ** See the documentation for SSL_AuthCertificateComplete for more information 732 ** about the asynchronous behavior that occurs when the authenticate 733 ** certificate hook returns SECWouldBlock. 734 ** 735 ** RFC 6066 says that clients should send the bad_certificate_status_response 736 ** alert when they encounter an error processing the stapled OCSP response. 737 ** libssl does not provide a way for the authenticate certificate hook to 738 ** indicate that an OCSP error (SEC_ERROR_OCSP_*) that it returns is an error 739 ** in the stapled OCSP response or an error in some other OCSP response. 740 ** Further, NSS does not provide a convenient way to control or determine 741 ** which OCSP response(s) were used to validate a certificate chain. 742 ** Consequently, the current version of libssl does not ever send the 743 ** bad_certificate_status_response alert. This may change in future releases. 744 */ 745 typedef SECStatus(PR_CALLBACK *SSLAuthCertificate)(void *arg, PRFileDesc *fd, 746 PRBool checkSig, 747 PRBool isServer); 748 749 SSL_IMPORT SECStatus SSL_AuthCertificateHook(PRFileDesc *fd, 750 SSLAuthCertificate f, 751 void *arg); 752 753 /* An implementation of the certificate authentication hook */ 754 SSL_IMPORT SECStatus SSL_AuthCertificate(void *arg, PRFileDesc *fd, 755 PRBool checkSig, PRBool isServer); 756 757 /* 758 * Prototype for SSL callback to get client auth data from the application. 759 * arg - application passed argument 760 * caNames - pointer to distinguished names of CAs that the server likes 761 * pRetCert - pointer to pointer to cert, for return of cert 762 * pRetKey - pointer to key pointer, for return of key 763 */ 764 typedef SECStatus(PR_CALLBACK *SSLGetClientAuthData)(void *arg, 765 PRFileDesc *fd, 766 CERTDistNames *caNames, 767 CERTCertificate **pRetCert, /*return */ 768 SECKEYPrivateKey **pRetKey); /* return */ 769 770 /* 771 * Set the client side callback for SSL to retrieve user's private key 772 * and certificate. 773 * fd - the file descriptor for the connection in question 774 * f - the application's callback that delivers the key and cert 775 * a - application specific data 776 */ 777 SSL_IMPORT SECStatus SSL_GetClientAuthDataHook(PRFileDesc *fd, 778 SSLGetClientAuthData f, void *a); 779 780 /* 781 ** SNI extension processing callback function. 782 ** It is called when SSL socket receives SNI extension in ClientHello message. 783 ** Upon this callback invocation, application is responsible to reconfigure the 784 ** socket with the data for a particular server name. 785 ** There are three potential outcomes of this function invocation: 786 ** * application does not recognize the name or the type and wants the 787 ** "unrecognized_name" alert be sent to the client. In this case the callback 788 ** function must return SSL_SNI_SEND_ALERT status. 789 ** * application does not recognize the name, but wants to continue with 790 ** the handshake using the current socket configuration. In this case, 791 ** no socket reconfiguration is needed and the function should return 792 ** SSL_SNI_CURRENT_CONFIG_IS_USED. 793 ** * application recognizes the name and reconfigures the socket with 794 ** appropriate certs, key, etc. There are many ways to reconfigure. NSS 795 ** provides SSL_ReconfigFD function that can be used to update the socket 796 ** data from model socket. To continue with the rest of the handshake, the 797 ** implementation function should return an index of a name it has chosen. 798 ** LibSSL will ignore any SNI extension received in a ClientHello message 799 ** if application does not register a SSLSNISocketConfig callback. 800 ** Each type field of SECItem indicates the name type. 801 ** NOTE: currently RFC3546 defines only one name type: sni_host_name. 802 ** Client is allowed to send only one name per known type. LibSSL will 803 ** send an "unrecognized_name" alert if SNI extension name list contains more 804 ** then one name of a type. 805 */ 806 typedef PRInt32(PR_CALLBACK *SSLSNISocketConfig)(PRFileDesc *fd, 807 const SECItem *srvNameArr, 808 PRUint32 srvNameArrSize, 809 void *arg); 810 811 /* 812 ** SSLSNISocketConfig should return an index within 0 and srvNameArrSize-1 813 ** when it has reconfigured the socket fd to use certs and keys, etc 814 ** for a specific name. There are two other allowed return values. One 815 ** tells libSSL to use the default cert and key. The other tells libSSL 816 ** to send the "unrecognized_name" alert. These values are: 817 **/ 818 #define SSL_SNI_CURRENT_CONFIG_IS_USED -1 819 #define SSL_SNI_SEND_ALERT -2 820 821 /* 822 ** Set application implemented SNISocketConfig callback. 823 */ 824 SSL_IMPORT SECStatus SSL_SNISocketConfigHook(PRFileDesc *fd, 825 SSLSNISocketConfig f, 826 void *arg); 827 828 /* 829 ** Reconfigure fd SSL socket with model socket parameters. Sets 830 ** server certs and keys, list of trust anchor, socket options 831 ** and all SSL socket call backs and parameters. 832 */ 833 SSL_IMPORT PRFileDesc *SSL_ReconfigFD(PRFileDesc *model, PRFileDesc *fd); 834 835 /* 836 * Set the client side argument for SSL to retrieve PKCS #11 pin. 837 * fd - the file descriptor for the connection in question 838 * a - pkcs11 application specific data 839 */ 840 SSL_IMPORT SECStatus SSL_SetPKCS11PinArg(PRFileDesc *fd, void *a); 841 842 /* 843 ** These are callbacks for dealing with SSL alerts. 844 */ 845 846 typedef PRUint8 SSLAlertLevel; 847 typedef PRUint8 SSLAlertDescription; 848 849 typedef struct { 850 SSLAlertLevel level; 851 SSLAlertDescription description; 852 } SSLAlert; 853 854 typedef void(PR_CALLBACK *SSLAlertCallback)(const PRFileDesc *fd, void *arg, 855 const SSLAlert *alert); 856 857 SSL_IMPORT SECStatus SSL_AlertReceivedCallback(PRFileDesc *fd, SSLAlertCallback cb, 858 void *arg); 859 SSL_IMPORT SECStatus SSL_AlertSentCallback(PRFileDesc *fd, SSLAlertCallback cb, 860 void *arg); 861 /* 862 ** This is a callback for dealing with server certs that are not authenticated 863 ** by the client. The client app can decide that it actually likes the 864 ** cert by some external means and restart the connection. 865 ** 866 ** The bad cert hook must return SECSuccess to override the result of the 867 ** authenticate certificate hook, SECFailure if the certificate should still be 868 ** considered invalid, or SECWouldBlock if the application will authenticate 869 ** the certificate asynchronously. SECWouldBlock is only supported for 870 ** non-blocking sockets. 871 ** 872 ** See the documentation for SSL_AuthCertificateComplete for more information 873 ** about the asynchronous behavior that occurs when the bad cert hook returns 874 ** SECWouldBlock. 875 */ 876 typedef SECStatus(PR_CALLBACK *SSLBadCertHandler)(void *arg, PRFileDesc *fd); 877 SSL_IMPORT SECStatus SSL_BadCertHook(PRFileDesc *fd, SSLBadCertHandler f, 878 void *arg); 879 880 /* 881 ** Configure SSL socket for running a secure server. Needs the 882 ** certificate for the server and the servers private key. The arguments 883 ** are copied. 884 ** 885 ** This method should be used in preference to SSL_ConfigSecureServer, 886 ** SSL_ConfigSecureServerWithCertChain, SSL_SetStapledOCSPResponses, and 887 ** SSL_SetSignedCertTimestamps. 888 ** 889 ** The authentication method is determined from the certificate and private key 890 ** based on how libssl authenticates peers. Primarily, this uses the value of 891 ** the SSLAuthType enum and is derived from the type of public key in the 892 ** certificate. For example, different RSA certificates might be saved for 893 ** signing (ssl_auth_rsa_sign) and key encipherment 894 ** (ssl_auth_rsa_decrypt). Unique to RSA, the same certificate can be used for 895 ** both usages. Additional information about the authentication method is also 896 ** used: EC keys with different curves are separately stored. 897 ** 898 ** Only one certificate is stored for each authentication method. 899 ** 900 ** The optional |data| argument contains additional information about the 901 ** certificate: 902 ** 903 ** - |authType| (with a value other than ssl_auth_null) limits the 904 ** authentication method; this is primarily useful in limiting the use of an 905 ** RSA certificate to one particular key usage (either signing or key 906 ** encipherment) when its key usages indicate support for both. 907 ** 908 ** - |certChain| provides an explicit certificate chain, rather than relying on 909 ** NSS functions for finding a certificate chain. 910 ** 911 ** - |stapledOCSPResponses| provides a response for OCSP stapling. 912 ** 913 ** - |signedCertTimestamps| provides a value for the 914 ** signed_certificate_timestamp extension used in certificate transparency. 915 ** 916 ** The |data_len| argument provides the length of the data. This should be set 917 ** to |sizeof(data)|. 918 ** 919 ** This function allows an application to provide certificates with narrow key 920 ** usages attached to them. For instance, RSA keys can be provided that are 921 ** limited to signing or decryption only. Multiple EC certificates with keys on 922 ** different named curves can be provided. 923 ** 924 ** Unlike SSL_ConfigSecureServer(WithCertChain), this function does not accept 925 ** NULL for the |cert| and |key| arguments. It will replace certificates that 926 ** have the same type, but it cannot be used to remove certificates that have 927 ** already been configured. 928 */ 929 SSL_IMPORT SECStatus SSL_ConfigServerCert( 930 PRFileDesc *fd, CERTCertificate *cert, SECKEYPrivateKey *key, 931 const SSLExtraServerCertData *data, unsigned int data_len); 932 933 /* 934 ** Deprecated variant of SSL_ConfigServerCert. 935 ** 936 ** This uses values from the SSLKEAType to identify the type of |key| that the 937 ** |cert| contains. This is incorrect, since key exchange and authentication 938 ** are separated in some cipher suites (in particular, ECDHE_RSA_* suites). 939 ** 940 ** Providing a |kea| parameter of ssl_kea_ecdh (or kt_ecdh) is interpreted as 941 ** providing both ECDH and ECDSA certificates. 942 */ 943 SSL_IMPORT SECStatus SSL_ConfigSecureServer( 944 PRFileDesc *fd, CERTCertificate *cert, 945 SECKEYPrivateKey *key, SSLKEAType kea); 946 947 /* 948 ** Deprecated variant of SSL_ConfigSecureServerCert. The |data| argument to 949 ** SSL_ConfigSecureServerCert can be used to pass a certificate chain. 950 */ 951 SSL_IMPORT SECStatus 952 SSL_ConfigSecureServerWithCertChain(PRFileDesc *fd, CERTCertificate *cert, 953 const CERTCertificateList *certChainOpt, 954 SECKEYPrivateKey *key, SSLKEAType kea); 955 956 /* 957 ** SSL_SetSessionTicketKeyPair configures an asymmetric key pair for use in 958 ** wrapping session ticket keys, used by the server. This function currently 959 ** only accepts an RSA public/private key pair. 960 ** 961 ** Prior to the existence of this function, NSS used an RSA private key 962 ** associated with a configured certificate to perform session ticket 963 ** encryption. If this function isn't used, the keys provided with a configured 964 ** RSA certificate are used for wrapping session ticket keys. 965 ** 966 ** NOTE: This key is used for all self-encryption but is named for 967 ** session tickets for historical reasons. 968 */ 969 SSL_IMPORT SECStatus 970 SSL_SetSessionTicketKeyPair(SECKEYPublicKey *pubKey, SECKEYPrivateKey *privKey); 971 972 /* 973 ** Configure a secure server's session-id cache. Define the maximum number 974 ** of entries in the cache, the longevity of the entires, and the directory 975 ** where the cache files will be placed. These values can be zero, and 976 ** if so, the implementation will choose defaults. 977 ** This version of the function is for use in applications that have only one 978 ** process that uses the cache (even if that process has multiple threads). 979 */ 980 SSL_IMPORT SECStatus SSL_ConfigServerSessionIDCache(int maxCacheEntries, 981 PRUint32 timeout, 982 PRUint32 ssl3_timeout, 983 const char *directory); 984 985 /* Configure a secure server's session-id cache. Depends on value of 986 * enableMPCache, configures malti-proc or single proc cache. */ 987 SSL_IMPORT SECStatus SSL_ConfigServerSessionIDCacheWithOpt( 988 PRUint32 timeout, 989 PRUint32 ssl3_timeout, 990 const char *directory, 991 int maxCacheEntries, 992 int maxCertCacheEntries, 993 int maxSrvNameCacheEntries, 994 PRBool enableMPCache); 995 996 /* 997 ** Like SSL_ConfigServerSessionIDCache, with one important difference. 998 ** If the application will run multiple processes (as opposed to, or in 999 ** addition to multiple threads), then it must call this function, instead 1000 ** of calling SSL_ConfigServerSessionIDCache(). 1001 ** This has nothing to do with the number of processORs, only processEs. 1002 ** This function sets up a Server Session ID (SID) cache that is safe for 1003 ** access by multiple processes on the same system. 1004 */ 1005 SSL_IMPORT SECStatus SSL_ConfigMPServerSIDCache(int maxCacheEntries, 1006 PRUint32 timeout, 1007 PRUint32 ssl3_timeout, 1008 const char *directory); 1009 1010 /* Get and set the configured maximum number of mutexes used for the 1011 ** server's store of SSL sessions. This value is used by the server 1012 ** session ID cache initialization functions shown above. Note that on 1013 ** some platforms, these mutexes are actually implemented with POSIX 1014 ** semaphores, or with unnamed pipes. The default value varies by platform. 1015 ** An attempt to set a too-low maximum will return an error and the 1016 ** configured value will not be changed. 1017 */ 1018 SSL_IMPORT PRUint32 SSL_GetMaxServerCacheLocks(void); 1019 SSL_IMPORT SECStatus SSL_SetMaxServerCacheLocks(PRUint32 maxLocks); 1020 1021 /* environment variable set by SSL_ConfigMPServerSIDCache, and queried by 1022 * SSL_InheritMPServerSIDCache when envString is NULL. 1023 */ 1024 #define SSL_ENV_VAR_NAME "SSL_INHERITANCE" 1025 1026 /* called in child to inherit SID Cache variables. 1027 * If envString is NULL, this function will use the value of the environment 1028 * variable "SSL_INHERITANCE", otherwise the string value passed in will be 1029 * used. 1030 */ 1031 SSL_IMPORT SECStatus SSL_InheritMPServerSIDCache(const char *envString); 1032 1033 /* 1034 ** Set the callback that gets called when a TLS handshake is complete. The 1035 ** handshake callback is called after verifying the peer's Finished message and 1036 ** before processing incoming application data. 1037 ** 1038 ** For the initial handshake: If the handshake false started (see 1039 ** SSL_ENABLE_FALSE_START), then application data may already have been sent 1040 ** before the handshake callback is called. If we did not false start then the 1041 ** callback will get called before any application data is sent. 1042 */ 1043 typedef void(PR_CALLBACK *SSLHandshakeCallback)(PRFileDesc *fd, 1044 void *client_data); 1045 SSL_IMPORT SECStatus SSL_HandshakeCallback(PRFileDesc *fd, 1046 SSLHandshakeCallback cb, void *client_data); 1047 1048 /* Applications that wish to enable TLS false start must set this callback 1049 ** function. NSS will invoke the functon to determine if a particular 1050 ** connection should use false start or not. SECSuccess indicates that the 1051 ** callback completed successfully, and if so *canFalseStart indicates if false 1052 ** start can be used. If the callback does not return SECSuccess then the 1053 ** handshake will be canceled. NSS's recommended criteria can be evaluated by 1054 ** calling SSL_RecommendedCanFalseStart. 1055 ** 1056 ** If no false start callback is registered then false start will never be 1057 ** done, even if the SSL_ENABLE_FALSE_START option is enabled. 1058 **/ 1059 typedef SECStatus(PR_CALLBACK *SSLCanFalseStartCallback)( 1060 PRFileDesc *fd, void *arg, PRBool *canFalseStart); 1061 1062 SSL_IMPORT SECStatus SSL_SetCanFalseStartCallback( 1063 PRFileDesc *fd, SSLCanFalseStartCallback callback, void *arg); 1064 1065 /* This function sets *canFalseStart according to the recommended criteria for 1066 ** false start. These criteria may change from release to release and may depend 1067 ** on which handshake features have been negotiated and/or properties of the 1068 ** certifciates/keys used on the connection. 1069 */ 1070 SSL_IMPORT SECStatus SSL_RecommendedCanFalseStart(PRFileDesc *fd, 1071 PRBool *canFalseStart); 1072 1073 /* 1074 ** For the server, request a new handshake. For the client, begin a new 1075 ** handshake. If flushCache is non-zero, the SSL3 cache entry will be 1076 ** flushed first, ensuring that a full SSL handshake will be done. 1077 ** If flushCache is zero, and an SSL connection is established, it will 1078 ** do the much faster session restart handshake. This will change the 1079 ** session keys without doing another private key operation. 1080 */ 1081 SSL_IMPORT SECStatus SSL_ReHandshake(PRFileDesc *fd, PRBool flushCache); 1082 1083 /* 1084 ** Same as above, but with an I/O timeout. 1085 */ 1086 SSL_IMPORT SECStatus SSL_ReHandshakeWithTimeout(PRFileDesc *fd, 1087 PRBool flushCache, 1088 PRIntervalTime timeout); 1089 1090 #ifdef SSL_DEPRECATED_FUNCTION 1091 /* deprecated! 1092 ** For the server, request a new handshake. For the client, begin a new 1093 ** handshake. Flushes SSL3 session cache entry first, ensuring that a 1094 ** full handshake will be done. 1095 ** This call is equivalent to SSL_ReHandshake(fd, PR_TRUE) 1096 */ 1097 SSL_IMPORT SECStatus SSL_RedoHandshake(PRFileDesc *fd); 1098 #endif 1099 1100 /* 1101 * Allow the application to pass a URL or hostname into the SSL library. 1102 */ 1103 SSL_IMPORT SECStatus SSL_SetURL(PRFileDesc *fd, const char *url); 1104 1105 /* 1106 * Allow an application to define a set of trust anchors for peer 1107 * cert validation. 1108 */ 1109 SSL_IMPORT SECStatus SSL_SetTrustAnchors(PRFileDesc *fd, CERTCertList *list); 1110 1111 /* 1112 ** Return the number of bytes that SSL has waiting in internal buffers. 1113 ** Return 0 if security is not enabled. 1114 */ 1115 SSL_IMPORT int SSL_DataPending(PRFileDesc *fd); 1116 1117 /* 1118 ** Invalidate the SSL session associated with fd. 1119 */ 1120 SSL_IMPORT SECStatus SSL_InvalidateSession(PRFileDesc *fd); 1121 1122 /* 1123 ** Return a SECItem containing the SSL session ID associated with the fd. 1124 */ 1125 SSL_IMPORT SECItem *SSL_GetSessionID(PRFileDesc *fd); 1126 1127 /* 1128 ** Clear out the client's SSL session cache, not the server's session cache. 1129 */ 1130 SSL_IMPORT void SSL_ClearSessionCache(void); 1131 1132 /* 1133 ** Close the server's SSL session cache. 1134 */ 1135 SSL_IMPORT SECStatus SSL_ShutdownServerSessionIDCache(void); 1136 1137 /* 1138 ** Set peer information so we can correctly look up SSL session later. 1139 ** You only have to do this if you're tunneling through a proxy. 1140 */ 1141 SSL_IMPORT SECStatus SSL_SetSockPeerID(PRFileDesc *fd, const char *peerID); 1142 1143 /* 1144 ** Reveal the security information for the peer. 1145 */ 1146 SSL_IMPORT CERTCertificate *SSL_RevealCert(PRFileDesc *socket); 1147 SSL_IMPORT void *SSL_RevealPinArg(PRFileDesc *socket); 1148 SSL_IMPORT char *SSL_RevealURL(PRFileDesc *socket); 1149 1150 /* This callback may be passed to the SSL library via a call to 1151 * SSL_GetClientAuthDataHook() for each SSL client socket. 1152 * It will be invoked when SSL needs to know what certificate and private key 1153 * (if any) to use to respond to a request for client authentication. 1154 * If arg is non-NULL, it is a pointer to a NULL-terminated string containing 1155 * the nickname of the cert/key pair to use. 1156 * If arg is NULL, this function will search the cert and key databases for 1157 * a suitable match and send it if one is found. 1158 */ 1159 SSL_IMPORT SECStatus 1160 NSS_GetClientAuthData(void *arg, 1161 PRFileDesc *socket, 1162 struct CERTDistNamesStr *caNames, 1163 struct CERTCertificateStr **pRetCert, 1164 struct SECKEYPrivateKeyStr **pRetKey); 1165 1166 /* 1167 ** Configure DTLS-SRTP (RFC 5764) cipher suite preferences. 1168 ** Input is a list of ciphers in descending preference order and a length 1169 ** of the list. As a side effect, this causes the use_srtp extension to be 1170 ** negotiated. 1171 ** 1172 ** Invalid or unimplemented cipher suites in |ciphers| are ignored. If at 1173 ** least one cipher suite in |ciphers| is implemented, returns SECSuccess. 1174 ** Otherwise returns SECFailure. 1175 */ 1176 SSL_IMPORT SECStatus SSL_SetSRTPCiphers(PRFileDesc *fd, 1177 const PRUint16 *ciphers, 1178 unsigned int numCiphers); 1179 1180 /* 1181 ** Get the selected DTLS-SRTP cipher suite (if any). 1182 ** To be called after the handshake completes. 1183 ** Returns SECFailure if not negotiated. 1184 */ 1185 SSL_IMPORT SECStatus SSL_GetSRTPCipher(PRFileDesc *fd, 1186 PRUint16 *cipher); 1187 1188 /* 1189 * Look to see if any of the signers in the cert chain for "cert" are found 1190 * in the list of caNames. 1191 * Returns SECSuccess if so, SECFailure if not. 1192 * Used by NSS_GetClientAuthData. May be used by other callback functions. 1193 */ 1194 SSL_IMPORT SECStatus NSS_CmpCertChainWCANames(CERTCertificate *cert, 1195 CERTDistNames *caNames); 1196 1197 /* Deprecated. This reports a misleading value for certificates that might 1198 * be used for signing rather than key exchange. 1199 * Returns key exchange type of the keys in an SSL server certificate. 1200 */ 1201 SSL_IMPORT SSLKEAType NSS_FindCertKEAType(CERTCertificate *cert); 1202 1203 /* Set cipher policies to a predefined Domestic (U.S.A.) policy. 1204 * This essentially allows all supported ciphers. 1205 */ 1206 SSL_IMPORT SECStatus NSS_SetDomesticPolicy(void); 1207 1208 /* Set cipher policies to a predefined Policy that is exportable from the USA 1209 * according to present U.S. policies as we understand them. 1210 * It is the same as NSS_SetDomesticPolicy now. 1211 */ 1212 SSL_IMPORT SECStatus NSS_SetExportPolicy(void); 1213 1214 /* Set cipher policies to a predefined Policy that is exportable from the USA 1215 * according to present U.S. policies as we understand them, and that the 1216 * nation of France will permit to be imported into their country. 1217 * It is the same as NSS_SetDomesticPolicy now. 1218 */ 1219 SSL_IMPORT SECStatus NSS_SetFrancePolicy(void); 1220 1221 SSL_IMPORT SSL3Statistics *SSL_GetStatistics(void); 1222 1223 /* Report more information than SSL_SecurityStatus. 1224 * Caller supplies the info struct. This function fills it in. Caller should 1225 * pass sizeof(SSLChannelInfo) as the |len| argument. 1226 * 1227 * The information here will be zeroed prior to details being confirmed. The 1228 * details are confirmed either when a Finished message is received, or - for a 1229 * client - when the second flight of messages have been sent. This function 1230 * therefore produces unreliable results prior to receiving the 1231 * SSLHandshakeCallback or the SSLCanFalseStartCallback. 1232 */ 1233 SSL_IMPORT SECStatus SSL_GetChannelInfo(PRFileDesc *fd, SSLChannelInfo *info, 1234 PRUintn len); 1235 /* Get preliminary information about a channel. 1236 * Caller supplies the info struct. This function fills it in. Caller should 1237 * pass sizeof(SSLPreliminaryChannelInfo) as the |len| argument. 1238 * 1239 * This function can be called prior to handshake details being confirmed (see 1240 * SSL_GetChannelInfo above for what that means). Thus, information provided by 1241 * this function is available to SSLAuthCertificate, SSLGetClientAuthData, 1242 * SSLSNISocketConfig, and other callbacks that might be called during the 1243 * processing of the first flight of client of server handshake messages. 1244 * Values are marked as being unavailable when renegotiation is initiated. 1245 */ 1246 SSL_IMPORT SECStatus 1247 SSL_GetPreliminaryChannelInfo(PRFileDesc *fd, 1248 SSLPreliminaryChannelInfo *info, 1249 PRUintn len); 1250 /* Get information about cipher suite with id of |cipherSuite|. 1251 * Caller supplies the info struct. This function fills it in. Caller should 1252 * pass sizeof(SSLCipherSuiteInfo) as the |len| argument. 1253 */ 1254 SSL_IMPORT SECStatus SSL_GetCipherSuiteInfo(PRUint16 cipherSuite, 1255 SSLCipherSuiteInfo *info, PRUintn len); 1256 1257 /* Returnes negotiated through SNI host info. */ 1258 SSL_IMPORT SECItem *SSL_GetNegotiatedHostInfo(PRFileDesc *fd); 1259 1260 /* Export keying material according to RFC 5705. 1261 ** fd must correspond to a TLS 1.0 or higher socket and out must 1262 ** already be allocated. If hasContext is false, it uses the no-context 1263 ** construction from the RFC and ignores the context and contextLen 1264 ** arguments. 1265 */ 1266 SSL_IMPORT SECStatus SSL_ExportKeyingMaterial(PRFileDesc *fd, 1267 const char *label, 1268 unsigned int labelLen, 1269 PRBool hasContext, 1270 const unsigned char *context, 1271 unsigned int contextLen, 1272 unsigned char *out, 1273 unsigned int outLen); 1274 1275 /* Early exporters are used if 0-RTT is enabled. This is TLS 1.3 only. Note 1276 * that in TLS 1.3, an empty context is equivalent to an absent context. */ 1277 SSL_IMPORT SECStatus SSL_ExportEarlyKeyingMaterial(PRFileDesc *fd, 1278 const char *label, 1279 unsigned int labelLen, 1280 const unsigned char *context, 1281 unsigned int contextLen, 1282 unsigned char *out, 1283 unsigned int outLen); 1284 1285 /* 1286 ** Return a new reference to the certificate that was most recently sent 1287 ** to the peer on this SSL/TLS connection, or NULL if none has been sent. 1288 */ 1289 SSL_IMPORT CERTCertificate *SSL_LocalCertificate(PRFileDesc *fd); 1290 1291 #define SSL_CBP_SSL3 0x0001 /* (deprecated) */ 1292 #define SSL_CBP_TLS1_0 0x0002 /* (deprecated) */ 1293 1294 /* DEPRECATED: The PKCS#11 bypass has been removed. 1295 ** This function will now always return false. */ 1296 SSL_IMPORT SECStatus SSL_CanBypass(CERTCertificate *cert, 1297 SECKEYPrivateKey *privKey, 1298 PRUint32 protocolmask, 1299 PRUint16 *ciphers, int nciphers, 1300 PRBool *pcanbypass, void *pwArg); 1301 1302 /* 1303 ** Did the handshake with the peer negotiate the given extension? 1304 ** Output parameter valid only if function returns SECSuccess 1305 */ 1306 SSL_IMPORT SECStatus SSL_HandshakeNegotiatedExtension(PRFileDesc *socket, 1307 SSLExtensionType extId, 1308 PRBool *yes); 1309 1310 /* 1311 ** How long should we wait before retransmitting the next flight of 1312 ** the DTLS handshake? Returns SECFailure if not DTLS or not in a 1313 ** handshake. 1314 */ 1315 SSL_IMPORT SECStatus DTLS_GetHandshakeTimeout(PRFileDesc *socket, 1316 PRIntervalTime *timeout); 1317 1318 /* 1319 * Return a boolean that indicates whether the underlying library 1320 * will perform as the caller expects. 1321 * 1322 * The only argument is a string, which should be the version 1323 * identifier of the NSS library. That string will be compared 1324 * against a string that represents the actual build version of 1325 * the SSL library. 1326 */ 1327 extern PRBool NSSSSL_VersionCheck(const char *importedVersion); 1328 1329 /* 1330 * Returns a const string of the SSL library version. 1331 */ 1332 extern const char *NSSSSL_GetVersion(void); 1333 1334 /* Restart an SSL connection that was paused to do asynchronous certificate 1335 * chain validation (when the auth certificate hook or bad cert handler 1336 * returned SECWouldBlock). 1337 * 1338 * This function only works for non-blocking sockets; Do not use it for 1339 * blocking sockets. Currently, this function works only for the client role of 1340 * a connection; it does not work for the server role. 1341 * 1342 * The application must call SSL_AuthCertificateComplete with 0 as the value of 1343 * the error parameter after it has successfully validated the peer's 1344 * certificate, in order to continue the SSL handshake. 1345 * 1346 * The application may call SSL_AuthCertificateComplete with a non-zero value 1347 * for error (e.g. SEC_ERROR_REVOKED_CERTIFICATE) when certificate validation 1348 * fails, before it closes the connection. If the application does so, an 1349 * alert corresponding to the error (e.g. certificate_revoked) will be sent to 1350 * the peer. See the source code of the internal function 1351 * ssl3_SendAlertForCertError for the current mapping of error to alert. This 1352 * mapping may change in future versions of libssl. 1353 * 1354 * This function will not complete the entire handshake. The application must 1355 * call SSL_ForceHandshake, PR_Recv, PR_Send, etc. after calling this function 1356 * to force the handshake to complete. 1357 * 1358 * On the first handshake of a connection, libssl will wait for the peer's 1359 * certificate to be authenticated before calling the handshake callback, 1360 * sending a client certificate, sending any application data, or returning 1361 * any application data to the application. On subsequent (renegotiation) 1362 * handshakes, libssl will block the handshake unconditionally while the 1363 * certificate is being validated. 1364 * 1365 * libssl may send and receive handshake messages while waiting for the 1366 * application to call SSL_AuthCertificateComplete, and it may call other 1367 * callbacks (e.g, the client auth data hook) before 1368 * SSL_AuthCertificateComplete has been called. 1369 * 1370 * An application that uses this asynchronous mechanism will usually have lower 1371 * handshake latency if it has to do public key operations on the certificate 1372 * chain and/or CRL/OCSP/cert fetching during the authentication, especially if 1373 * it does so in parallel on another thread. However, if the application can 1374 * authenticate the peer's certificate quickly then it may be more efficient 1375 * to use the synchronous mechanism (i.e. returning SECFailure/SECSuccess 1376 * instead of SECWouldBlock from the authenticate certificate hook). 1377 * 1378 * Be careful about converting an application from synchronous cert validation 1379 * to asynchronous certificate validation. A naive conversion is likely to 1380 * result in deadlocks; e.g. the application will wait in PR_Poll for network 1381 * I/O on the connection while all network I/O on the connection is blocked 1382 * waiting for this function to be called. 1383 * 1384 * Returns SECFailure on failure, SECSuccess on success. Never returns 1385 * SECWouldBlock. Note that SSL_AuthCertificateComplete will (usually) return 1386 * SECSuccess; do not interpret the return value of SSL_AuthCertificateComplete 1387 * as an indicator of whether it is OK to continue using the connection. For 1388 * example, SSL_AuthCertificateComplete(fd, SEC_ERROR_REVOKED_CERTIFICATE) will 1389 * return SECSuccess (normally), but that does not mean that the application 1390 * should continue using the connection. If the application passes a non-zero 1391 * value for second argument (error), or if SSL_AuthCertificateComplete returns 1392 * anything other than SECSuccess, then the application should close the 1393 * connection. 1394 */ 1395 SSL_IMPORT SECStatus SSL_AuthCertificateComplete(PRFileDesc *fd, 1396 PRErrorCode error); 1397 1398 /* 1399 * This is used to access experimental APIs. Don't call this directly. This is 1400 * used to enable the experimental APIs that are defined in "sslexp.h". 1401 */ 1402 SSL_IMPORT void *SSL_GetExperimentalAPI(const char *name); 1403 1404 SEC_END_PROTOS 1405 1406 #endif /* __ssl_h_ */ 1407