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 SSL 2 and 3 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 /* Disable export cipher suites */ 106 /* if step-down keys are needed. */ 107 /* default: off, generate */ 108 /* step-down keys if needed. */ 109 #define SSL_BYPASS_PKCS11 16 /* use PKCS#11 for pub key only */ 110 #define SSL_NO_LOCKS 17 /* Don't use locks for protection */ 111 #define SSL_ENABLE_SESSION_TICKETS 18 /* Enable TLS SessionTicket */ 112 /* extension (off by default) */ 113 #define SSL_ENABLE_DEFLATE 19 /* Enable TLS compression with */ 114 /* DEFLATE (off by default) */ 115 #define SSL_ENABLE_RENEGOTIATION 20 /* Values below (default: never) */ 116 #define SSL_REQUIRE_SAFE_NEGOTIATION 21 /* Peer must send Signaling */ 117 /* Cipher Suite Value (SCSV) or */ 118 /* Renegotiation Info (RI) */ 119 /* extension in ALL handshakes. */ 120 /* default: off */ 121 #define SSL_ENABLE_FALSE_START 22 /* Enable SSL false start (off by */ 122 /* default, applies only to */ 123 /* clients). False start is a */ 124 /* mode where an SSL client will start sending application data before 125 * verifying the server's Finished message. This means that we could end up 126 * sending data to an imposter. However, the data will be encrypted and 127 * only the true server can derive the session key. Thus, so long as the 128 * cipher isn't broken this is safe. The advantage of false start is that 129 * it saves a round trip for client-speaks-first protocols when performing a 130 * full handshake. 131 * 132 * In addition to enabling this option, the application must register a 133 * callback using the SSL_SetCanFalseStartCallback function. 134 */ 135 136 /* For SSL 3.0 and TLS 1.0, by default we prevent chosen plaintext attacks 137 * on SSL CBC mode cipher suites (see RFC 4346 Section F.3) by splitting 138 * non-empty application_data records into two records; the first record has 139 * only the first byte of plaintext, and the second has the rest. 140 * 141 * This only prevents the attack in the sending direction; the connection may 142 * still be vulnerable to such attacks if the peer does not implement a similar 143 * countermeasure. 144 * 145 * This protection mechanism is on by default; the default can be overridden by 146 * setting NSS_SSL_CBC_RANDOM_IV=0 in the environment prior to execution, 147 * and/or by the application setting the option SSL_CBC_RANDOM_IV to PR_FALSE. 148 * 149 * The per-record IV in TLS 1.1 and later adds one block of overhead per 150 * record, whereas this hack will add at least two blocks of overhead per 151 * record, so TLS 1.1+ will always be more efficient. 152 * 153 * Other implementations (e.g. some versions of OpenSSL, in some 154 * configurations) prevent the same attack by prepending an empty 155 * application_data record to every application_data record they send; we do 156 * not do that because some implementations cannot handle empty 157 * application_data records. Also, we only split application_data records and 158 * not other types of records, because some implementations will not accept 159 * fragmented records of some other types (e.g. some versions of NSS do not 160 * accept fragmented alerts). 161 */ 162 #define SSL_CBC_RANDOM_IV 23 163 #define SSL_ENABLE_OCSP_STAPLING 24 /* Request OCSP stapling (client) */ 164 /* Request Signed Certificate Timestamps via TLS extension (client) */ 165 #define SSL_ENABLE_SIGNED_CERT_TIMESTAMPS 25 166 #define SSL_ENABLE_FALLBACK_SCSV 26 /* Send fallback SCSV in 167 * handshakes. */ 168 169 #ifdef SSL_DEPRECATED_FUNCTION 170 /* Old deprecated function names */ 171 SSL_IMPORT SECStatus SSL_Enable(PRFileDesc *fd, int option, PRBool on); 172 SSL_IMPORT SECStatus SSL_EnableDefault(int option, PRBool on); 173 #endif 174 175 /* New function names */ 176 SSL_IMPORT SECStatus SSL_OptionSet(PRFileDesc *fd, PRInt32 option, PRBool on); 177 SSL_IMPORT SECStatus SSL_OptionGet(PRFileDesc *fd, PRInt32 option, PRBool *on); 178 SSL_IMPORT SECStatus SSL_OptionSetDefault(PRInt32 option, PRBool on); 179 SSL_IMPORT SECStatus SSL_OptionGetDefault(PRInt32 option, PRBool *on); 180 SSL_IMPORT SECStatus SSL_CertDBHandleSet(PRFileDesc *fd, CERTCertDBHandle *dbHandle); 181 182 /* SSLNextProtoCallback is called during the handshake for the client, when a 183 * Next Protocol Negotiation (NPN) extension has been received from the server. 184 * |protos| and |protosLen| define a buffer which contains the server's 185 * advertisement. This data is guaranteed to be well formed per the NPN spec. 186 * |protoOut| is a buffer provided by the caller, of length 255 (the maximum 187 * allowed by the protocol). On successful return, the protocol to be announced 188 * to the server will be in |protoOut| and its length in |*protoOutLen|. 189 * 190 * The callback must return SECFailure or SECSuccess (not SECWouldBlock). 191 */ 192 typedef SECStatus (PR_CALLBACK *SSLNextProtoCallback)( 193 void *arg, 194 PRFileDesc *fd, 195 const unsigned char* protos, 196 unsigned int protosLen, 197 unsigned char* protoOut, 198 unsigned int* protoOutLen, 199 unsigned int protoMaxOut); 200 201 /* SSL_SetNextProtoCallback sets a callback function to handle Next Protocol 202 * Negotiation. It causes a client to advertise NPN. */ 203 SSL_IMPORT SECStatus SSL_SetNextProtoCallback(PRFileDesc *fd, 204 SSLNextProtoCallback callback, 205 void *arg); 206 207 /* SSL_SetNextProtoNego can be used as an alternative to 208 * SSL_SetNextProtoCallback. It also causes a client to advertise NPN and 209 * installs a default callback function which selects the first supported 210 * protocol in server-preference order. If no matching protocol is found it 211 * selects the first supported protocol. 212 * 213 * Using this function also allows the client to transparently support ALPN. 214 * The same set of protocols will be advertised via ALPN and, if the server 215 * uses ALPN to select a protocol, SSL_GetNextProto will return 216 * SSL_NEXT_PROTO_SELECTED as the state. 217 * 218 * Since NPN uses the first protocol as the fallback protocol, when sending an 219 * ALPN extension, the first protocol is moved to the end of the list. This 220 * indicates that the fallback protocol is the least preferred. The other 221 * protocols should be in preference order. 222 * 223 * The supported protocols are specified in |data| in wire-format (8-bit 224 * length-prefixed). For example: "\010http/1.1\006spdy/2". */ 225 SSL_IMPORT SECStatus SSL_SetNextProtoNego(PRFileDesc *fd, 226 const unsigned char *data, 227 unsigned int length); 228 229 typedef enum SSLNextProtoState { 230 SSL_NEXT_PROTO_NO_SUPPORT = 0, /* No peer support */ 231 SSL_NEXT_PROTO_NEGOTIATED = 1, /* Mutual agreement */ 232 SSL_NEXT_PROTO_NO_OVERLAP = 2, /* No protocol overlap found */ 233 SSL_NEXT_PROTO_SELECTED = 3 /* Server selected proto (ALPN) */ 234 } SSLNextProtoState; 235 236 /* SSL_GetNextProto can be used in the HandshakeCallback or any time after 237 * a handshake to retrieve the result of the Next Protocol negotiation. 238 * 239 * The length of the negotiated protocol, if any, is written into *bufLen. 240 * If the negotiated protocol is longer than bufLenMax, then SECFailure is 241 * returned. Otherwise, the negotiated protocol, if any, is written into buf, 242 * and SECSuccess is returned. */ 243 SSL_IMPORT SECStatus SSL_GetNextProto(PRFileDesc *fd, 244 SSLNextProtoState *state, 245 unsigned char *buf, 246 unsigned int *bufLen, 247 unsigned int bufLenMax); 248 249 /* 250 ** Control ciphers that SSL uses. If on is non-zero then the named cipher 251 ** is enabled, otherwise it is disabled. 252 ** The "cipher" values are defined in sslproto.h (the SSL_EN_* values). 253 ** EnableCipher records user preferences. 254 ** SetPolicy sets the policy according to the policy module. 255 */ 256 #ifdef SSL_DEPRECATED_FUNCTION 257 /* Old deprecated function names */ 258 SSL_IMPORT SECStatus SSL_EnableCipher(long which, PRBool enabled); 259 SSL_IMPORT SECStatus SSL_SetPolicy(long which, int policy); 260 #endif 261 262 /* New function names */ 263 SSL_IMPORT SECStatus SSL_CipherPrefSet(PRFileDesc *fd, PRInt32 cipher, PRBool enabled); 264 SSL_IMPORT SECStatus SSL_CipherPrefGet(PRFileDesc *fd, PRInt32 cipher, PRBool *enabled); 265 SSL_IMPORT SECStatus SSL_CipherPrefSetDefault(PRInt32 cipher, PRBool enabled); 266 SSL_IMPORT SECStatus SSL_CipherPrefGetDefault(PRInt32 cipher, PRBool *enabled); 267 SSL_IMPORT SECStatus SSL_CipherPolicySet(PRInt32 cipher, PRInt32 policy); 268 SSL_IMPORT SECStatus SSL_CipherPolicyGet(PRInt32 cipher, PRInt32 *policy); 269 270 /* SSL_CipherOrderSet sets the cipher suite preference order from |ciphers|, 271 * which must be an array of cipher suite ids of length |len|. All the given 272 * cipher suite ids must appear in the array that is returned by 273 * |SSL_GetImplementedCiphers| and may only appear once, at most. */ 274 SSL_IMPORT SECStatus SSL_CipherOrderSet(PRFileDesc *fd, const PRUint16 *ciphers, 275 unsigned int len); 276 277 /* SSLChannelBindingType enumerates the types of supported channel binding 278 * values. See RFC 5929. */ 279 typedef enum SSLChannelBindingType { 280 SSL_CHANNEL_BINDING_TLS_UNIQUE = 1, 281 } SSLChannelBindingType; 282 283 /* SSL_GetChannelBinding copies the requested channel binding value, as defined 284 * in RFC 5929, into |out|. The full length of the binding value is written 285 * into |*outLen|. 286 * 287 * At most |outLenMax| bytes of data are copied. If |outLenMax| is 288 * insufficient then the function returns SECFailure and sets the error to 289 * SEC_ERROR_OUTPUT_LEN, but |*outLen| is still set. 290 * 291 * This call will fail if made during a renegotiation. */ 292 SSL_IMPORT SECStatus SSL_GetChannelBinding(PRFileDesc *fd, 293 SSLChannelBindingType binding_type, 294 unsigned char *out, 295 unsigned int *outLen, 296 unsigned int outLenMax); 297 298 /* SSL Version Range API 299 ** 300 ** This API should be used to control SSL 3.0 & TLS support instead of the 301 ** older SSL_Option* API; however, the SSL_Option* API MUST still be used to 302 ** control SSL 2.0 support. In this version of libssl, SSL 3.0 and TLS 1.0 are 303 ** enabled by default. Future versions of libssl may change which versions of 304 ** the protocol are enabled by default. 305 ** 306 ** The SSLProtocolVariant enum indicates whether the protocol is of type 307 ** stream or datagram. This must be provided to the functions that do not 308 ** take an fd. Functions which take an fd will get the variant from the fd, 309 ** which is typed. 310 ** 311 ** Using the new version range API in conjunction with the older 312 ** SSL_OptionSet-based API for controlling the enabled protocol versions may 313 ** cause unexpected results. Going forward, we guarantee only the following: 314 ** 315 ** SSL_OptionGet(SSL_ENABLE_TLS) will return PR_TRUE if *ANY* versions of TLS 316 ** are enabled. 317 ** 318 ** SSL_OptionSet(SSL_ENABLE_TLS, PR_FALSE) will disable *ALL* versions of TLS, 319 ** including TLS 1.0 and later. 320 ** 321 ** The above two properties provide compatibility for applications that use 322 ** SSL_OptionSet to implement the insecure fallback from TLS 1.x to SSL 3.0. 323 ** 324 ** SSL_OptionSet(SSL_ENABLE_TLS, PR_TRUE) will enable TLS 1.0, and may also 325 ** enable some later versions of TLS, if it is necessary to do so in order to 326 ** keep the set of enabled versions contiguous. For example, if TLS 1.2 is 327 ** enabled, then after SSL_OptionSet(SSL_ENABLE_TLS, PR_TRUE), TLS 1.0, 328 ** TLS 1.1, and TLS 1.2 will be enabled, and the call will have no effect on 329 ** whether SSL 3.0 is enabled. If no later versions of TLS are enabled at the 330 ** time SSL_OptionSet(SSL_ENABLE_TLS, PR_TRUE) is called, then no later 331 ** versions of TLS will be enabled by the call. 332 ** 333 ** SSL_OptionSet(SSL_ENABLE_SSL3, PR_FALSE) will disable SSL 3.0, and will not 334 ** change the set of TLS versions that are enabled. 335 ** 336 ** SSL_OptionSet(SSL_ENABLE_SSL3, PR_TRUE) will enable SSL 3.0, and may also 337 ** enable some versions of TLS if TLS 1.1 or later is enabled at the time of 338 ** the call, the same way SSL_OptionSet(SSL_ENABLE_TLS, PR_TRUE) works, in 339 ** order to keep the set of enabled versions contiguous. 340 */ 341 342 /* Returns, in |*vrange|, the range of SSL3/TLS versions supported for the 343 ** given protocol variant by the version of libssl linked-to at runtime. 344 */ 345 SSL_IMPORT SECStatus SSL_VersionRangeGetSupported( 346 SSLProtocolVariant protocolVariant, SSLVersionRange *vrange); 347 348 /* Returns, in |*vrange|, the range of SSL3/TLS versions enabled by default 349 ** for the given protocol variant. 350 */ 351 SSL_IMPORT SECStatus SSL_VersionRangeGetDefault( 352 SSLProtocolVariant protocolVariant, SSLVersionRange *vrange); 353 354 /* Sets the range of enabled-by-default SSL3/TLS versions for the given 355 ** protocol variant to |*vrange|. 356 */ 357 SSL_IMPORT SECStatus SSL_VersionRangeSetDefault( 358 SSLProtocolVariant protocolVariant, const SSLVersionRange *vrange); 359 360 /* Returns, in |*vrange|, the range of enabled SSL3/TLS versions for |fd|. */ 361 SSL_IMPORT SECStatus SSL_VersionRangeGet(PRFileDesc *fd, 362 SSLVersionRange *vrange); 363 364 /* Sets the range of enabled SSL3/TLS versions for |fd| to |*vrange|. */ 365 SSL_IMPORT SECStatus SSL_VersionRangeSet(PRFileDesc *fd, 366 const SSLVersionRange *vrange); 367 368 369 /* Values for "policy" argument to SSL_PolicySet */ 370 /* Values returned by SSL_CipherPolicyGet. */ 371 #define SSL_NOT_ALLOWED 0 /* or invalid or unimplemented */ 372 #define SSL_ALLOWED 1 373 #define SSL_RESTRICTED 2 /* only with "Step-Up" certs. */ 374 375 /* Values for "on" with SSL_REQUIRE_CERTIFICATE. */ 376 #define SSL_REQUIRE_NEVER ((PRBool)0) 377 #define SSL_REQUIRE_ALWAYS ((PRBool)1) 378 #define SSL_REQUIRE_FIRST_HANDSHAKE ((PRBool)2) 379 #define SSL_REQUIRE_NO_ERROR ((PRBool)3) 380 381 /* Values for "on" with SSL_ENABLE_RENEGOTIATION */ 382 /* Never renegotiate at all. */ 383 #define SSL_RENEGOTIATE_NEVER ((PRBool)0) 384 /* Renegotiate without restriction, whether or not the peer's client hello */ 385 /* bears the renegotiation info extension. Vulnerable, as in the past. */ 386 #define SSL_RENEGOTIATE_UNRESTRICTED ((PRBool)1) 387 /* Only renegotiate if the peer's hello bears the TLS renegotiation_info */ 388 /* extension. This is safe renegotiation. */ 389 #define SSL_RENEGOTIATE_REQUIRES_XTN ((PRBool)2) 390 /* Disallow unsafe renegotiation in server sockets only, but allow clients */ 391 /* to continue to renegotiate with vulnerable servers. */ 392 /* This value should only be used during the transition period when few */ 393 /* servers have been upgraded. */ 394 #define SSL_RENEGOTIATE_TRANSITIONAL ((PRBool)3) 395 396 /* 397 ** Reset the handshake state for fd. This will make the complete SSL 398 ** handshake protocol execute from the ground up on the next i/o 399 ** operation. 400 */ 401 SSL_IMPORT SECStatus SSL_ResetHandshake(PRFileDesc *fd, PRBool asServer); 402 403 /* 404 ** Force the handshake for fd to complete immediately. This blocks until 405 ** the complete SSL handshake protocol is finished. 406 */ 407 SSL_IMPORT SECStatus SSL_ForceHandshake(PRFileDesc *fd); 408 409 /* 410 ** Same as above, but with an I/O timeout. 411 */ 412 SSL_IMPORT SECStatus SSL_ForceHandshakeWithTimeout(PRFileDesc *fd, 413 PRIntervalTime timeout); 414 415 SSL_IMPORT SECStatus SSL_RestartHandshakeAfterCertReq(PRFileDesc *fd, 416 CERTCertificate *cert, 417 SECKEYPrivateKey *key, 418 CERTCertificateList *certChain); 419 420 /* 421 ** Query security status of socket. *on is set to one if security is 422 ** enabled. *keySize will contain the stream key size used. *issuer will 423 ** contain the RFC1485 verison of the name of the issuer of the 424 ** certificate at the other end of the connection. For a client, this is 425 ** the issuer of the server's certificate; for a server, this is the 426 ** issuer of the client's certificate (if any). Subject is the subject of 427 ** the other end's certificate. The pointers can be zero if the desired 428 ** data is not needed. All strings returned by this function are owned 429 ** by the caller, and need to be freed with PORT_Free. 430 */ 431 SSL_IMPORT SECStatus SSL_SecurityStatus(PRFileDesc *fd, int *on, char **cipher, 432 int *keySize, int *secretKeySize, 433 char **issuer, char **subject); 434 435 /* Values for "on" */ 436 #define SSL_SECURITY_STATUS_NOOPT -1 437 #define SSL_SECURITY_STATUS_OFF 0 438 #define SSL_SECURITY_STATUS_ON_HIGH 1 439 #define SSL_SECURITY_STATUS_ON_LOW 2 440 #define SSL_SECURITY_STATUS_FORTEZZA 3 /* NO LONGER SUPPORTED */ 441 442 /* 443 ** Return the certificate for our SSL peer. If the client calls this 444 ** it will always return the server's certificate. If the server calls 445 ** this, it may return NULL if client authentication is not enabled or 446 ** if the client had no certificate when asked. 447 ** "fd" the socket "file" descriptor 448 */ 449 SSL_IMPORT CERTCertificate *SSL_PeerCertificate(PRFileDesc *fd); 450 451 /* 452 ** Return the certificates presented by the SSL peer. If the SSL peer 453 ** did not present certificates, return NULL with the 454 ** SSL_ERROR_NO_CERTIFICATE error. On failure, return NULL with an error 455 ** code other than SSL_ERROR_NO_CERTIFICATE. 456 ** "fd" the socket "file" descriptor 457 */ 458 SSL_IMPORT CERTCertList *SSL_PeerCertificateChain(PRFileDesc *fd); 459 460 /* SSL_PeerStapledOCSPResponses returns the OCSP responses that were provided 461 * by the TLS server. The return value is a pointer to an internal SECItemArray 462 * that contains the returned OCSP responses; it is only valid until the 463 * callback function that calls SSL_PeerStapledOCSPResponses returns. 464 * 465 * If no OCSP responses were given by the server then the result will be empty. 466 * If there was an error, then the result will be NULL. 467 * 468 * You must set the SSL_ENABLE_OCSP_STAPLING option to enable OCSP stapling. 469 * to be provided by a server. 470 * 471 * libssl does not do any validation of the OCSP response itself; the 472 * authenticate certificate hook is responsible for doing so. The default 473 * authenticate certificate hook, SSL_AuthCertificate, does not implement 474 * any OCSP stapling funtionality, but this may change in future versions. 475 */ 476 SSL_IMPORT const SECItemArray * SSL_PeerStapledOCSPResponses(PRFileDesc *fd); 477 478 /* SSL_PeerSignedCertTimestamps returns the signed_certificate_timestamp 479 * extension data provided by the TLS server. The return value is a pointer 480 * to an internal SECItem that contains the returned response (as a serialized 481 * SignedCertificateTimestampList, see RFC 6962). The returned pointer is only 482 * valid until the callback function that calls SSL_PeerSignedCertTimestamps 483 * (e.g. the authenticate certificate hook, or the handshake callback) returns. 484 * 485 * If no Signed Certificate Timestamps were given by the server then the result 486 * will be empty. If there was an error, then the result will be NULL. 487 * 488 * You must set the SSL_ENABLE_SIGNED_CERT_TIMESTAMPS option to indicate support 489 * for Signed Certificate Timestamps to a server. 490 * 491 * libssl does not do any parsing or validation of the response itself. 492 */ 493 SSL_IMPORT const SECItem * SSL_PeerSignedCertTimestamps(PRFileDesc *fd); 494 495 /* SSL_SetStapledOCSPResponses stores an array of one or multiple OCSP responses 496 * in the fd's data, which may be sent as part of a server side cert_status 497 * handshake message. Parameter |responses| is for the server certificate of 498 * the key exchange type |kea|. 499 * The function will duplicate the responses array. 500 */ 501 SSL_IMPORT SECStatus 502 SSL_SetStapledOCSPResponses(PRFileDesc *fd, const SECItemArray *responses, 503 SSLKEAType kea); 504 505 /* 506 ** Authenticate certificate hook. Called when a certificate comes in 507 ** (because of SSL_REQUIRE_CERTIFICATE in SSL_Enable) to authenticate the 508 ** certificate. 509 ** 510 ** The authenticate certificate hook must return SECSuccess to indicate the 511 ** certificate is valid, SECFailure to indicate the certificate is invalid, 512 ** or SECWouldBlock if the application will authenticate the certificate 513 ** asynchronously. SECWouldBlock is only supported for non-blocking sockets. 514 ** 515 ** If the authenticate certificate hook returns SECFailure, then the bad cert 516 ** hook will be called. The bad cert handler is NEVER called if the 517 ** authenticate certificate hook returns SECWouldBlock. If the application 518 ** needs to handle and/or override a bad cert, it should do so before it 519 ** calls SSL_AuthCertificateComplete (modifying the error it passes to 520 ** SSL_AuthCertificateComplete as needed). 521 ** 522 ** See the documentation for SSL_AuthCertificateComplete for more information 523 ** about the asynchronous behavior that occurs when the authenticate 524 ** certificate hook returns SECWouldBlock. 525 ** 526 ** RFC 6066 says that clients should send the bad_certificate_status_response 527 ** alert when they encounter an error processing the stapled OCSP response. 528 ** libssl does not provide a way for the authenticate certificate hook to 529 ** indicate that an OCSP error (SEC_ERROR_OCSP_*) that it returns is an error 530 ** in the stapled OCSP response or an error in some other OCSP response. 531 ** Further, NSS does not provide a convenient way to control or determine 532 ** which OCSP response(s) were used to validate a certificate chain. 533 ** Consequently, the current version of libssl does not ever send the 534 ** bad_certificate_status_response alert. This may change in future releases. 535 */ 536 typedef SECStatus (PR_CALLBACK *SSLAuthCertificate)(void *arg, PRFileDesc *fd, 537 PRBool checkSig, 538 PRBool isServer); 539 540 SSL_IMPORT SECStatus SSL_AuthCertificateHook(PRFileDesc *fd, 541 SSLAuthCertificate f, 542 void *arg); 543 544 /* An implementation of the certificate authentication hook */ 545 SSL_IMPORT SECStatus SSL_AuthCertificate(void *arg, PRFileDesc *fd, 546 PRBool checkSig, PRBool isServer); 547 548 /* 549 * Prototype for SSL callback to get client auth data from the application. 550 * arg - application passed argument 551 * caNames - pointer to distinguished names of CAs that the server likes 552 * pRetCert - pointer to pointer to cert, for return of cert 553 * pRetKey - pointer to key pointer, for return of key 554 */ 555 typedef SECStatus (PR_CALLBACK *SSLGetClientAuthData)(void *arg, 556 PRFileDesc *fd, 557 CERTDistNames *caNames, 558 CERTCertificate **pRetCert,/*return */ 559 SECKEYPrivateKey **pRetKey);/* return */ 560 561 /* 562 * Set the client side callback for SSL to retrieve user's private key 563 * and certificate. 564 * fd - the file descriptor for the connection in question 565 * f - the application's callback that delivers the key and cert 566 * a - application specific data 567 */ 568 SSL_IMPORT SECStatus SSL_GetClientAuthDataHook(PRFileDesc *fd, 569 SSLGetClientAuthData f, void *a); 570 571 /* 572 * Prototype for SSL callback to get client auth data from the application, 573 * optionally using the underlying platform's cryptographic primitives. 574 * To use the platform cryptographic primitives, caNames and pRetCerts 575 * should be set. To use NSS, pRetNSSCert and pRetNSSKey should be set. 576 * Returning SECFailure will cause the socket to send no client certificate. 577 * arg - application passed argument 578 * caNames - pointer to distinguished names of CAs that the server likes 579 * pRetCerts - pointer to pointer to list of certs, with the first being 580 * the client cert, and any following being used for chain 581 * building 582 * pRetKey - pointer to native key pointer, for return of key 583 * - Windows: A pointer to a PCERT_KEY_CONTEXT that was allocated 584 * via PORT_Alloc(). Ownership of the PCERT_KEY_CONTEXT 585 * is transferred to NSS, which will free via 586 * PORT_Free(). 587 * - Mac OS X: A pointer to a SecKeyRef. Ownership is 588 * transferred to NSS, which will free via CFRelease(). 589 * pRetNSSCert - pointer to pointer to NSS cert, for return of cert. 590 * pRetNSSKey - pointer to NSS key pointer, for return of key. 591 */ 592 typedef SECStatus (PR_CALLBACK *SSLGetPlatformClientAuthData)(void *arg, 593 PRFileDesc *fd, 594 CERTDistNames *caNames, 595 CERTCertList **pRetCerts,/*return */ 596 void **pRetKey,/* return */ 597 CERTCertificate **pRetNSSCert,/*return */ 598 SECKEYPrivateKey **pRetNSSKey);/* return */ 599 600 /* 601 * Set the client side callback for SSL to retrieve user's private key 602 * and certificate. 603 * Note: If a platform client auth callback is set, the callback configured by 604 * SSL_GetClientAuthDataHook, if any, will not be called. 605 * 606 * fd - the file descriptor for the connection in question 607 * f - the application's callback that delivers the key and cert 608 * a - application specific data 609 */ 610 SSL_IMPORT SECStatus 611 SSL_GetPlatformClientAuthDataHook(PRFileDesc *fd, 612 SSLGetPlatformClientAuthData f, void *a); 613 614 /* 615 ** SNI extension processing callback function. 616 ** It is called when SSL socket receives SNI extension in ClientHello message. 617 ** Upon this callback invocation, application is responsible to reconfigure the 618 ** socket with the data for a particular server name. 619 ** There are three potential outcomes of this function invocation: 620 ** * application does not recognize the name or the type and wants the 621 ** "unrecognized_name" alert be sent to the client. In this case the callback 622 ** function must return SSL_SNI_SEND_ALERT status. 623 ** * application does not recognize the name, but wants to continue with 624 ** the handshake using the current socket configuration. In this case, 625 ** no socket reconfiguration is needed and the function should return 626 ** SSL_SNI_CURRENT_CONFIG_IS_USED. 627 ** * application recognizes the name and reconfigures the socket with 628 ** appropriate certs, key, etc. There are many ways to reconfigure. NSS 629 ** provides SSL_ReconfigFD function that can be used to update the socket 630 ** data from model socket. To continue with the rest of the handshake, the 631 ** implementation function should return an index of a name it has chosen. 632 ** LibSSL will ignore any SNI extension received in a ClientHello message 633 ** if application does not register a SSLSNISocketConfig callback. 634 ** Each type field of SECItem indicates the name type. 635 ** NOTE: currently RFC3546 defines only one name type: sni_host_name. 636 ** Client is allowed to send only one name per known type. LibSSL will 637 ** send an "unrecognized_name" alert if SNI extension name list contains more 638 ** then one name of a type. 639 */ 640 typedef PRInt32 (PR_CALLBACK *SSLSNISocketConfig)(PRFileDesc *fd, 641 const SECItem *srvNameArr, 642 PRUint32 srvNameArrSize, 643 void *arg); 644 645 /* 646 ** SSLSNISocketConfig should return an index within 0 and srvNameArrSize-1 647 ** when it has reconfigured the socket fd to use certs and keys, etc 648 ** for a specific name. There are two other allowed return values. One 649 ** tells libSSL to use the default cert and key. The other tells libSSL 650 ** to send the "unrecognized_name" alert. These values are: 651 **/ 652 #define SSL_SNI_CURRENT_CONFIG_IS_USED -1 653 #define SSL_SNI_SEND_ALERT -2 654 655 /* 656 ** Set application implemented SNISocketConfig callback. 657 */ 658 SSL_IMPORT SECStatus SSL_SNISocketConfigHook(PRFileDesc *fd, 659 SSLSNISocketConfig f, 660 void *arg); 661 662 /* 663 ** Reconfigure fd SSL socket with model socket parameters. Sets 664 ** server certs and keys, list of trust anchor, socket options 665 ** and all SSL socket call backs and parameters. 666 */ 667 SSL_IMPORT PRFileDesc *SSL_ReconfigFD(PRFileDesc *model, PRFileDesc *fd); 668 669 /* 670 * Set the client side argument for SSL to retrieve PKCS #11 pin. 671 * fd - the file descriptor for the connection in question 672 * a - pkcs11 application specific data 673 */ 674 SSL_IMPORT SECStatus SSL_SetPKCS11PinArg(PRFileDesc *fd, void *a); 675 676 /* 677 ** This is a callback for dealing with server certs that are not authenticated 678 ** by the client. The client app can decide that it actually likes the 679 ** cert by some external means and restart the connection. 680 ** 681 ** The bad cert hook must return SECSuccess to override the result of the 682 ** authenticate certificate hook, SECFailure if the certificate should still be 683 ** considered invalid, or SECWouldBlock if the application will authenticate 684 ** the certificate asynchronously. SECWouldBlock is only supported for 685 ** non-blocking sockets. 686 ** 687 ** See the documentation for SSL_AuthCertificateComplete for more information 688 ** about the asynchronous behavior that occurs when the bad cert hook returns 689 ** SECWouldBlock. 690 */ 691 typedef SECStatus (PR_CALLBACK *SSLBadCertHandler)(void *arg, PRFileDesc *fd); 692 SSL_IMPORT SECStatus SSL_BadCertHook(PRFileDesc *fd, SSLBadCertHandler f, 693 void *arg); 694 695 /* 696 ** Configure SSL socket for running a secure server. Needs the 697 ** certificate for the server and the servers private key. The arguments 698 ** are copied. 699 */ 700 SSL_IMPORT SECStatus SSL_ConfigSecureServer( 701 PRFileDesc *fd, CERTCertificate *cert, 702 SECKEYPrivateKey *key, SSLKEAType kea); 703 704 /* 705 ** Allows SSL socket configuration with caller-supplied certificate chain. 706 ** If certChainOpt is NULL, tries to find one. 707 */ 708 SSL_IMPORT SECStatus 709 SSL_ConfigSecureServerWithCertChain(PRFileDesc *fd, CERTCertificate *cert, 710 const CERTCertificateList *certChainOpt, 711 SECKEYPrivateKey *key, SSLKEAType kea); 712 713 /* 714 ** Configure a secure server's session-id cache. Define the maximum number 715 ** of entries in the cache, the longevity of the entires, and the directory 716 ** where the cache files will be placed. These values can be zero, and 717 ** if so, the implementation will choose defaults. 718 ** This version of the function is for use in applications that have only one 719 ** process that uses the cache (even if that process has multiple threads). 720 */ 721 SSL_IMPORT SECStatus SSL_ConfigServerSessionIDCache(int maxCacheEntries, 722 PRUint32 timeout, 723 PRUint32 ssl3_timeout, 724 const char * directory); 725 726 /* Configure a secure server's session-id cache. Depends on value of 727 * enableMPCache, configures malti-proc or single proc cache. */ 728 SSL_IMPORT SECStatus SSL_ConfigServerSessionIDCacheWithOpt( 729 PRUint32 timeout, 730 PRUint32 ssl3_timeout, 731 const char * directory, 732 int maxCacheEntries, 733 int maxCertCacheEntries, 734 int maxSrvNameCacheEntries, 735 PRBool enableMPCache); 736 737 /* 738 ** Like SSL_ConfigServerSessionIDCache, with one important difference. 739 ** If the application will run multiple processes (as opposed to, or in 740 ** addition to multiple threads), then it must call this function, instead 741 ** of calling SSL_ConfigServerSessionIDCache(). 742 ** This has nothing to do with the number of processORs, only processEs. 743 ** This function sets up a Server Session ID (SID) cache that is safe for 744 ** access by multiple processes on the same system. 745 */ 746 SSL_IMPORT SECStatus SSL_ConfigMPServerSIDCache(int maxCacheEntries, 747 PRUint32 timeout, 748 PRUint32 ssl3_timeout, 749 const char * directory); 750 751 /* Get and set the configured maximum number of mutexes used for the 752 ** server's store of SSL sessions. This value is used by the server 753 ** session ID cache initialization functions shown above. Note that on 754 ** some platforms, these mutexes are actually implemented with POSIX 755 ** semaphores, or with unnamed pipes. The default value varies by platform. 756 ** An attempt to set a too-low maximum will return an error and the 757 ** configured value will not be changed. 758 */ 759 SSL_IMPORT PRUint32 SSL_GetMaxServerCacheLocks(void); 760 SSL_IMPORT SECStatus SSL_SetMaxServerCacheLocks(PRUint32 maxLocks); 761 762 /* environment variable set by SSL_ConfigMPServerSIDCache, and queried by 763 * SSL_InheritMPServerSIDCache when envString is NULL. 764 */ 765 #define SSL_ENV_VAR_NAME "SSL_INHERITANCE" 766 767 /* called in child to inherit SID Cache variables. 768 * If envString is NULL, this function will use the value of the environment 769 * variable "SSL_INHERITANCE", otherwise the string value passed in will be 770 * used. 771 */ 772 SSL_IMPORT SECStatus SSL_InheritMPServerSIDCache(const char * envString); 773 774 /* 775 ** Set the callback that gets called when a TLS handshake is complete. The 776 ** handshake callback is called after verifying the peer's Finished message and 777 ** before processing incoming application data. 778 ** 779 ** For the initial handshake: If the handshake false started (see 780 ** SSL_ENABLE_FALSE_START), then application data may already have been sent 781 ** before the handshake callback is called. If we did not false start then the 782 ** callback will get called before any application data is sent. 783 */ 784 typedef void (PR_CALLBACK *SSLHandshakeCallback)(PRFileDesc *fd, 785 void *client_data); 786 SSL_IMPORT SECStatus SSL_HandshakeCallback(PRFileDesc *fd, 787 SSLHandshakeCallback cb, void *client_data); 788 789 /* Applications that wish to enable TLS false start must set this callback 790 ** function. NSS will invoke the functon to determine if a particular 791 ** connection should use false start or not. SECSuccess indicates that the 792 ** callback completed successfully, and if so *canFalseStart indicates if false 793 ** start can be used. If the callback does not return SECSuccess then the 794 ** handshake will be canceled. NSS's recommended criteria can be evaluated by 795 ** calling SSL_RecommendedCanFalseStart. 796 ** 797 ** If no false start callback is registered then false start will never be 798 ** done, even if the SSL_ENABLE_FALSE_START option is enabled. 799 **/ 800 typedef SECStatus (PR_CALLBACK *SSLCanFalseStartCallback)( 801 PRFileDesc *fd, void *arg, PRBool *canFalseStart); 802 803 SSL_IMPORT SECStatus SSL_SetCanFalseStartCallback( 804 PRFileDesc *fd, SSLCanFalseStartCallback callback, void *arg); 805 806 /* This function sets *canFalseStart according to the recommended criteria for 807 ** false start. These criteria may change from release to release and may depend 808 ** on which handshake features have been negotiated and/or properties of the 809 ** certifciates/keys used on the connection. 810 */ 811 SSL_IMPORT SECStatus SSL_RecommendedCanFalseStart(PRFileDesc *fd, 812 PRBool *canFalseStart); 813 814 /* 815 ** For the server, request a new handshake. For the client, begin a new 816 ** handshake. If flushCache is non-zero, the SSL3 cache entry will be 817 ** flushed first, ensuring that a full SSL handshake will be done. 818 ** If flushCache is zero, and an SSL connection is established, it will 819 ** do the much faster session restart handshake. This will change the 820 ** session keys without doing another private key operation. 821 */ 822 SSL_IMPORT SECStatus SSL_ReHandshake(PRFileDesc *fd, PRBool flushCache); 823 824 /* 825 ** Same as above, but with an I/O timeout. 826 */ 827 SSL_IMPORT SECStatus SSL_ReHandshakeWithTimeout(PRFileDesc *fd, 828 PRBool flushCache, 829 PRIntervalTime timeout); 830 831 /* Returns a SECItem containing the certificate_types field of the 832 ** CertificateRequest message. Each byte of the data is a TLS 833 ** ClientCertificateType value, and they are ordered from most preferred to 834 ** least. This function should only be called from the 835 ** SSL_GetClientAuthDataHook callback, and will return NULL if called at any 836 ** other time. The returned value is valid only until the callback returns, and 837 ** should not be freed. 838 */ 839 SSL_IMPORT const SECItem * 840 SSL_GetRequestedClientCertificateTypes(PRFileDesc *fd); 841 842 #ifdef SSL_DEPRECATED_FUNCTION 843 /* deprecated! 844 ** For the server, request a new handshake. For the client, begin a new 845 ** handshake. Flushes SSL3 session cache entry first, ensuring that a 846 ** full handshake will be done. 847 ** This call is equivalent to SSL_ReHandshake(fd, PR_TRUE) 848 */ 849 SSL_IMPORT SECStatus SSL_RedoHandshake(PRFileDesc *fd); 850 #endif 851 852 /* 853 * Allow the application to pass a URL or hostname into the SSL library. 854 */ 855 SSL_IMPORT SECStatus SSL_SetURL(PRFileDesc *fd, const char *url); 856 857 /* 858 * Allow an application to define a set of trust anchors for peer 859 * cert validation. 860 */ 861 SSL_IMPORT SECStatus SSL_SetTrustAnchors(PRFileDesc *fd, CERTCertList *list); 862 863 /* 864 ** Return the number of bytes that SSL has waiting in internal buffers. 865 ** Return 0 if security is not enabled. 866 */ 867 SSL_IMPORT int SSL_DataPending(PRFileDesc *fd); 868 869 /* 870 ** Invalidate the SSL session associated with fd. 871 */ 872 SSL_IMPORT SECStatus SSL_InvalidateSession(PRFileDesc *fd); 873 874 /* 875 ** Cache the SSL session associated with fd, if it has not already been cached. 876 */ 877 SSL_IMPORT SECStatus SSL_CacheSession(PRFileDesc *fd); 878 879 /* 880 ** Cache the SSL session associated with fd, if it has not already been cached. 881 ** This function may only be called when processing within a callback assigned 882 ** via SSL_HandshakeCallback 883 */ 884 SSL_IMPORT SECStatus SSL_CacheSessionUnlocked(PRFileDesc *fd); 885 886 /* 887 ** Return a SECItem containing the SSL session ID associated with the fd. 888 */ 889 SSL_IMPORT SECItem *SSL_GetSessionID(PRFileDesc *fd); 890 891 /* 892 ** Clear out the client's SSL session cache, not the server's session cache. 893 */ 894 SSL_IMPORT void SSL_ClearSessionCache(void); 895 896 /* 897 ** Close the server's SSL session cache. 898 */ 899 SSL_IMPORT SECStatus SSL_ShutdownServerSessionIDCache(void); 900 901 /* 902 ** Set peer information so we can correctly look up SSL session later. 903 ** You only have to do this if you're tunneling through a proxy. 904 */ 905 SSL_IMPORT SECStatus SSL_SetSockPeerID(PRFileDesc *fd, const char *peerID); 906 907 /* 908 ** Reveal the security information for the peer. 909 */ 910 SSL_IMPORT CERTCertificate * SSL_RevealCert(PRFileDesc * socket); 911 SSL_IMPORT void * SSL_RevealPinArg(PRFileDesc * socket); 912 SSL_IMPORT char * SSL_RevealURL(PRFileDesc * socket); 913 914 /* This callback may be passed to the SSL library via a call to 915 * SSL_GetClientAuthDataHook() for each SSL client socket. 916 * It will be invoked when SSL needs to know what certificate and private key 917 * (if any) to use to respond to a request for client authentication. 918 * If arg is non-NULL, it is a pointer to a NULL-terminated string containing 919 * the nickname of the cert/key pair to use. 920 * If arg is NULL, this function will search the cert and key databases for 921 * a suitable match and send it if one is found. 922 */ 923 SSL_IMPORT SECStatus 924 NSS_GetClientAuthData(void * arg, 925 PRFileDesc * socket, 926 struct CERTDistNamesStr * caNames, 927 struct CERTCertificateStr ** pRetCert, 928 struct SECKEYPrivateKeyStr **pRetKey); 929 930 /* 931 ** Configure DTLS-SRTP (RFC 5764) cipher suite preferences. 932 ** Input is a list of ciphers in descending preference order and a length 933 ** of the list. As a side effect, this causes the use_srtp extension to be 934 ** negotiated. 935 ** 936 ** Invalid or unimplemented cipher suites in |ciphers| are ignored. If at 937 ** least one cipher suite in |ciphers| is implemented, returns SECSuccess. 938 ** Otherwise returns SECFailure. 939 */ 940 SSL_IMPORT SECStatus SSL_SetSRTPCiphers(PRFileDesc *fd, 941 const PRUint16 *ciphers, 942 unsigned int numCiphers); 943 944 /* 945 ** Get the selected DTLS-SRTP cipher suite (if any). 946 ** To be called after the handshake completes. 947 ** Returns SECFailure if not negotiated. 948 */ 949 SSL_IMPORT SECStatus SSL_GetSRTPCipher(PRFileDesc *fd, 950 PRUint16 *cipher); 951 952 /* 953 * Look to see if any of the signers in the cert chain for "cert" are found 954 * in the list of caNames. 955 * Returns SECSuccess if so, SECFailure if not. 956 * Used by NSS_GetClientAuthData. May be used by other callback functions. 957 */ 958 SSL_IMPORT SECStatus NSS_CmpCertChainWCANames(CERTCertificate *cert, 959 CERTDistNames *caNames); 960 961 /* 962 * Returns key exchange type of the keys in an SSL server certificate. 963 */ 964 SSL_IMPORT SSLKEAType NSS_FindCertKEAType(CERTCertificate * cert); 965 966 /* Set cipher policies to a predefined Domestic (U.S.A.) policy. 967 * This essentially enables all supported ciphers. 968 */ 969 SSL_IMPORT SECStatus NSS_SetDomesticPolicy(void); 970 971 /* Set cipher policies to a predefined Policy that is exportable from the USA 972 * according to present U.S. policies as we understand them. 973 * See documentation for the list. 974 * Note that your particular application program may be able to obtain 975 * an export license with more or fewer capabilities than those allowed 976 * by this function. In that case, you should use SSL_SetPolicy() 977 * to explicitly allow those ciphers you may legally export. 978 */ 979 SSL_IMPORT SECStatus NSS_SetExportPolicy(void); 980 981 /* Set cipher policies to a predefined Policy that is exportable from the USA 982 * according to present U.S. policies as we understand them, and that the 983 * nation of France will permit to be imported into their country. 984 * See documentation for the list. 985 */ 986 SSL_IMPORT SECStatus NSS_SetFrancePolicy(void); 987 988 SSL_IMPORT SSL3Statistics * SSL_GetStatistics(void); 989 990 /* Report more information than SSL_SecurityStatus. 991 ** Caller supplies the info struct. Function fills it in. 992 */ 993 SSL_IMPORT SECStatus SSL_GetChannelInfo(PRFileDesc *fd, SSLChannelInfo *info, 994 PRUintn len); 995 SSL_IMPORT SECStatus SSL_GetCipherSuiteInfo(PRUint16 cipherSuite, 996 SSLCipherSuiteInfo *info, PRUintn len); 997 998 /* Returnes negotiated through SNI host info. */ 999 SSL_IMPORT SECItem *SSL_GetNegotiatedHostInfo(PRFileDesc *fd); 1000 1001 /* Export keying material according to RFC 5705. 1002 ** fd must correspond to a TLS 1.0 or higher socket and out must 1003 ** already be allocated. If hasContext is false, it uses the no-context 1004 ** construction from the RFC and ignores the context and contextLen 1005 ** arguments. 1006 */ 1007 SSL_IMPORT SECStatus SSL_ExportKeyingMaterial(PRFileDesc *fd, 1008 const char *label, 1009 unsigned int labelLen, 1010 PRBool hasContext, 1011 const unsigned char *context, 1012 unsigned int contextLen, 1013 unsigned char *out, 1014 unsigned int outLen); 1015 1016 /* 1017 ** Return a new reference to the certificate that was most recently sent 1018 ** to the peer on this SSL/TLS connection, or NULL if none has been sent. 1019 */ 1020 SSL_IMPORT CERTCertificate * SSL_LocalCertificate(PRFileDesc *fd); 1021 1022 /* Test an SSL configuration to see if SSL_BYPASS_PKCS11 can be turned on. 1023 ** Check the key exchange algorithm for each cipher in the list to see if 1024 ** a master secret key can be extracted after being derived with the mechanism 1025 ** required by the protocolmask argument. If the KEA will use keys from the 1026 ** specified cert make sure the extract operation is attempted from the slot 1027 ** where the private key resides. 1028 ** If MS can be extracted for all ciphers, (*pcanbypass) is set to TRUE and 1029 ** SECSuccess is returned. In all other cases but one (*pcanbypass) is 1030 ** set to FALSE and SECFailure is returned. 1031 ** In that last case Derive() has been called successfully but the MS is null, 1032 ** CanBypass sets (*pcanbypass) to FALSE and returns SECSuccess indicating the 1033 ** arguments were all valid but the slot cannot be bypassed. 1034 ** 1035 ** Note: A TRUE return code from CanBypass means "Your configuration will perform 1036 ** NO WORSE with the bypass enabled than without"; it does NOT mean that every 1037 ** cipher suite listed will work properly with the selected protocols. 1038 ** 1039 ** Caveat: If export cipher suites are included in the argument list Canbypass 1040 ** will return FALSE. 1041 **/ 1042 1043 /* protocol mask bits */ 1044 #define SSL_CBP_SSL3 0x0001 /* test SSL v3 mechanisms */ 1045 #define SSL_CBP_TLS1_0 0x0002 /* test TLS v1.0 mechanisms */ 1046 1047 SSL_IMPORT SECStatus SSL_CanBypass(CERTCertificate *cert, 1048 SECKEYPrivateKey *privKey, 1049 PRUint32 protocolmask, 1050 PRUint16 *ciphers, int nciphers, 1051 PRBool *pcanbypass, void *pwArg); 1052 1053 /* 1054 ** Did the handshake with the peer negotiate the given extension? 1055 ** Output parameter valid only if function returns SECSuccess 1056 */ 1057 SSL_IMPORT SECStatus SSL_HandshakeNegotiatedExtension(PRFileDesc * socket, 1058 SSLExtensionType extId, 1059 PRBool *yes); 1060 1061 SSL_IMPORT SECStatus SSL_HandshakeResumedSession(PRFileDesc *fd, 1062 PRBool *last_handshake_resumed); 1063 1064 /* See SSL_SetClientChannelIDCallback for usage. If the callback returns 1065 * SECWouldBlock then SSL_RestartHandshakeAfterChannelIDReq should be called in 1066 * the future to restart the handshake. On SECSuccess, the callback must have 1067 * written a P-256, EC key pair to |*out_public_key| and |*out_private_key|. */ 1068 typedef SECStatus (PR_CALLBACK *SSLClientChannelIDCallback)( 1069 void *arg, 1070 PRFileDesc *fd, 1071 SECKEYPublicKey **out_public_key, 1072 SECKEYPrivateKey **out_private_key); 1073 1074 /* SSL_RestartHandshakeAfterChannelIDReq attempts to restart the handshake 1075 * after a ChannelID callback returned SECWouldBlock. 1076 * 1077 * This function takes ownership of |channelIDPub| and |channelID|. */ 1078 SSL_IMPORT SECStatus SSL_RestartHandshakeAfterChannelIDReq( 1079 PRFileDesc *fd, 1080 SECKEYPublicKey *channelIDPub, 1081 SECKEYPrivateKey *channelID); 1082 1083 /* SSL_SetClientChannelIDCallback sets a callback function that will be called 1084 * once the server's ServerHello has been processed. This is only applicable to 1085 * a client socket and setting this callback causes the TLS Channel ID 1086 * extension to be advertised. */ 1087 SSL_IMPORT SECStatus SSL_SetClientChannelIDCallback( 1088 PRFileDesc *fd, 1089 SSLClientChannelIDCallback callback, 1090 void *arg); 1091 1092 /* 1093 ** How long should we wait before retransmitting the next flight of 1094 ** the DTLS handshake? Returns SECFailure if not DTLS or not in a 1095 ** handshake. 1096 */ 1097 SSL_IMPORT SECStatus DTLS_GetHandshakeTimeout(PRFileDesc *socket, 1098 PRIntervalTime *timeout); 1099 1100 /* 1101 * Return a boolean that indicates whether the underlying library 1102 * will perform as the caller expects. 1103 * 1104 * The only argument is a string, which should be the version 1105 * identifier of the NSS library. That string will be compared 1106 * against a string that represents the actual build version of 1107 * the SSL library. 1108 */ 1109 extern PRBool NSSSSL_VersionCheck(const char *importedVersion); 1110 1111 /* 1112 * Returns a const string of the SSL library version. 1113 */ 1114 extern const char *NSSSSL_GetVersion(void); 1115 1116 /* Restart an SSL connection that was paused to do asynchronous certificate 1117 * chain validation (when the auth certificate hook or bad cert handler 1118 * returned SECWouldBlock). 1119 * 1120 * This function only works for non-blocking sockets; Do not use it for 1121 * blocking sockets. Currently, this function works only for the client role of 1122 * a connection; it does not work for the server role. 1123 * 1124 * The application must call SSL_AuthCertificateComplete with 0 as the value of 1125 * the error parameter after it has successfully validated the peer's 1126 * certificate, in order to continue the SSL handshake. 1127 * 1128 * The application may call SSL_AuthCertificateComplete with a non-zero value 1129 * for error (e.g. SEC_ERROR_REVOKED_CERTIFICATE) when certificate validation 1130 * fails, before it closes the connection. If the application does so, an 1131 * alert corresponding to the error (e.g. certificate_revoked) will be sent to 1132 * the peer. See the source code of the internal function 1133 * ssl3_SendAlertForCertError for the current mapping of error to alert. This 1134 * mapping may change in future versions of libssl. 1135 * 1136 * This function will not complete the entire handshake. The application must 1137 * call SSL_ForceHandshake, PR_Recv, PR_Send, etc. after calling this function 1138 * to force the handshake to complete. 1139 * 1140 * On the first handshake of a connection, libssl will wait for the peer's 1141 * certificate to be authenticated before calling the handshake callback, 1142 * sending a client certificate, sending any application data, or returning 1143 * any application data to the application. On subsequent (renegotiation) 1144 * handshakes, libssl will block the handshake unconditionally while the 1145 * certificate is being validated. 1146 * 1147 * libssl may send and receive handshake messages while waiting for the 1148 * application to call SSL_AuthCertificateComplete, and it may call other 1149 * callbacks (e.g, the client auth data hook) before 1150 * SSL_AuthCertificateComplete has been called. 1151 * 1152 * An application that uses this asynchronous mechanism will usually have lower 1153 * handshake latency if it has to do public key operations on the certificate 1154 * chain and/or CRL/OCSP/cert fetching during the authentication, especially if 1155 * it does so in parallel on another thread. However, if the application can 1156 * authenticate the peer's certificate quickly then it may be more efficient 1157 * to use the synchronous mechanism (i.e. returning SECFailure/SECSuccess 1158 * instead of SECWouldBlock from the authenticate certificate hook). 1159 * 1160 * Be careful about converting an application from synchronous cert validation 1161 * to asynchronous certificate validation. A naive conversion is likely to 1162 * result in deadlocks; e.g. the application will wait in PR_Poll for network 1163 * I/O on the connection while all network I/O on the connection is blocked 1164 * waiting for this function to be called. 1165 * 1166 * Returns SECFailure on failure, SECSuccess on success. Never returns 1167 * SECWouldBlock. Note that SSL_AuthCertificateComplete will (usually) return 1168 * SECSuccess; do not interpret the return value of SSL_AuthCertificateComplete 1169 * as an indicator of whether it is OK to continue using the connection. For 1170 * example, SSL_AuthCertificateComplete(fd, SEC_ERROR_REVOKED_CERTIFICATE) will 1171 * return SECSuccess (normally), but that does not mean that the application 1172 * should continue using the connection. If the application passes a non-zero 1173 * value for second argument (error), or if SSL_AuthCertificateComplete returns 1174 * anything other than SECSuccess, then the application should close the 1175 * connection. 1176 */ 1177 SSL_IMPORT SECStatus SSL_AuthCertificateComplete(PRFileDesc *fd, 1178 PRErrorCode error); 1179 SEC_END_PROTOS 1180 1181 #endif /* __ssl_h_ */ 1182