michael@0: /* michael@0: * This file contains prototypes for the public SSL functions. michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef __ssl_h_ michael@0: #define __ssl_h_ michael@0: michael@0: #include "prtypes.h" michael@0: #include "prerror.h" michael@0: #include "prio.h" michael@0: #include "seccomon.h" michael@0: #include "cert.h" michael@0: #include "keyt.h" michael@0: michael@0: #include "sslt.h" /* public ssl data types */ michael@0: michael@0: #if defined(_WIN32) && !defined(IN_LIBSSL) && !defined(NSS_USE_STATIC_LIBS) michael@0: #define SSL_IMPORT extern __declspec(dllimport) michael@0: #else michael@0: #define SSL_IMPORT extern michael@0: #endif michael@0: michael@0: SEC_BEGIN_PROTOS michael@0: michael@0: /* constant table enumerating all implemented SSL 2 and 3 cipher suites. */ michael@0: SSL_IMPORT const PRUint16 SSL_ImplementedCiphers[]; michael@0: michael@0: /* the same as the above, but is a function */ michael@0: SSL_IMPORT const PRUint16 *SSL_GetImplementedCiphers(void); michael@0: michael@0: /* number of entries in the above table. */ michael@0: SSL_IMPORT const PRUint16 SSL_NumImplementedCiphers; michael@0: michael@0: /* the same as the above, but is a function */ michael@0: SSL_IMPORT PRUint16 SSL_GetNumImplementedCiphers(void); michael@0: michael@0: /* Macro to tell which ciphers in table are SSL2 vs SSL3/TLS. */ michael@0: #define SSL_IS_SSL2_CIPHER(which) (((which) & 0xfff0) == 0xff00) michael@0: michael@0: /* michael@0: ** Imports fd into SSL, returning a new socket. Copies SSL configuration michael@0: ** from model. michael@0: */ michael@0: SSL_IMPORT PRFileDesc *SSL_ImportFD(PRFileDesc *model, PRFileDesc *fd); michael@0: michael@0: /* michael@0: ** Imports fd into DTLS, returning a new socket. Copies DTLS configuration michael@0: ** from model. michael@0: */ michael@0: SSL_IMPORT PRFileDesc *DTLS_ImportFD(PRFileDesc *model, PRFileDesc *fd); michael@0: michael@0: /* michael@0: ** Enable/disable an ssl mode michael@0: ** michael@0: ** SSL_SECURITY: michael@0: ** enable/disable use of SSL security protocol before connect michael@0: ** michael@0: ** SSL_SOCKS: michael@0: ** enable/disable use of socks before connect michael@0: ** (No longer supported). michael@0: ** michael@0: ** SSL_REQUEST_CERTIFICATE: michael@0: ** require a certificate during secure connect michael@0: */ michael@0: /* options */ michael@0: #define SSL_SECURITY 1 /* (on by default) */ michael@0: #define SSL_SOCKS 2 /* (off by default) */ michael@0: #define SSL_REQUEST_CERTIFICATE 3 /* (off by default) */ michael@0: #define SSL_HANDSHAKE_AS_CLIENT 5 /* force accept to hs as client */ michael@0: /* (off by default) */ michael@0: #define SSL_HANDSHAKE_AS_SERVER 6 /* force connect to hs as server */ michael@0: /* (off by default) */ michael@0: michael@0: /* OBSOLETE: SSL v2 is obsolete and may be removed soon. */ michael@0: #define SSL_ENABLE_SSL2 7 /* enable ssl v2 (off by default) */ michael@0: michael@0: /* OBSOLETE: See "SSL Version Range API" below for the replacement and a michael@0: ** description of the non-obvious semantics of using SSL_ENABLE_SSL3. michael@0: */ michael@0: #define SSL_ENABLE_SSL3 8 /* enable ssl v3 (on by default) */ michael@0: michael@0: #define SSL_NO_CACHE 9 /* don't use the session cache */ michael@0: /* (off by default) */ michael@0: #define SSL_REQUIRE_CERTIFICATE 10 /* (SSL_REQUIRE_FIRST_HANDSHAKE */ michael@0: /* by default) */ michael@0: #define SSL_ENABLE_FDX 11 /* permit simultaneous read/write */ michael@0: /* (off by default) */ michael@0: michael@0: /* OBSOLETE: SSL v2 compatible hellos are not accepted by some TLS servers michael@0: ** and cannot negotiate extensions. SSL v2 is obsolete. This option may be michael@0: ** removed soon. michael@0: */ michael@0: #define SSL_V2_COMPATIBLE_HELLO 12 /* send v3 client hello in v2 fmt */ michael@0: /* (off by default) */ michael@0: michael@0: /* OBSOLETE: See "SSL Version Range API" below for the replacement and a michael@0: ** description of the non-obvious semantics of using SSL_ENABLE_TLS. michael@0: */ michael@0: #define SSL_ENABLE_TLS 13 /* enable TLS (on by default) */ michael@0: michael@0: #define SSL_ROLLBACK_DETECTION 14 /* for compatibility, default: on */ michael@0: #define SSL_NO_STEP_DOWN 15 /* Disable export cipher suites */ michael@0: /* if step-down keys are needed. */ michael@0: /* default: off, generate */ michael@0: /* step-down keys if needed. */ michael@0: #define SSL_BYPASS_PKCS11 16 /* use PKCS#11 for pub key only */ michael@0: #define SSL_NO_LOCKS 17 /* Don't use locks for protection */ michael@0: #define SSL_ENABLE_SESSION_TICKETS 18 /* Enable TLS SessionTicket */ michael@0: /* extension (off by default) */ michael@0: #define SSL_ENABLE_DEFLATE 19 /* Enable TLS compression with */ michael@0: /* DEFLATE (off by default) */ michael@0: #define SSL_ENABLE_RENEGOTIATION 20 /* Values below (default: never) */ michael@0: #define SSL_REQUIRE_SAFE_NEGOTIATION 21 /* Peer must send Signaling */ michael@0: /* Cipher Suite Value (SCSV) or */ michael@0: /* Renegotiation Info (RI) */ michael@0: /* extension in ALL handshakes. */ michael@0: /* default: off */ michael@0: #define SSL_ENABLE_FALSE_START 22 /* Enable SSL false start (off by */ michael@0: /* default, applies only to */ michael@0: /* clients). False start is a */ michael@0: /* mode where an SSL client will start sending application data before michael@0: * verifying the server's Finished message. This means that we could end up michael@0: * sending data to an imposter. However, the data will be encrypted and michael@0: * only the true server can derive the session key. Thus, so long as the michael@0: * cipher isn't broken this is safe. The advantage of false start is that michael@0: * it saves a round trip for client-speaks-first protocols when performing a michael@0: * full handshake. michael@0: * michael@0: * In addition to enabling this option, the application must register a michael@0: * callback using the SSL_SetCanFalseStartCallback function. michael@0: */ michael@0: michael@0: /* For SSL 3.0 and TLS 1.0, by default we prevent chosen plaintext attacks michael@0: * on SSL CBC mode cipher suites (see RFC 4346 Section F.3) by splitting michael@0: * non-empty application_data records into two records; the first record has michael@0: * only the first byte of plaintext, and the second has the rest. michael@0: * michael@0: * This only prevents the attack in the sending direction; the connection may michael@0: * still be vulnerable to such attacks if the peer does not implement a similar michael@0: * countermeasure. michael@0: * michael@0: * This protection mechanism is on by default; the default can be overridden by michael@0: * setting NSS_SSL_CBC_RANDOM_IV=0 in the environment prior to execution, michael@0: * and/or by the application setting the option SSL_CBC_RANDOM_IV to PR_FALSE. michael@0: * michael@0: * The per-record IV in TLS 1.1 and later adds one block of overhead per michael@0: * record, whereas this hack will add at least two blocks of overhead per michael@0: * record, so TLS 1.1+ will always be more efficient. michael@0: * michael@0: * Other implementations (e.g. some versions of OpenSSL, in some michael@0: * configurations) prevent the same attack by prepending an empty michael@0: * application_data record to every application_data record they send; we do michael@0: * not do that because some implementations cannot handle empty michael@0: * application_data records. Also, we only split application_data records and michael@0: * not other types of records, because some implementations will not accept michael@0: * fragmented records of some other types (e.g. some versions of NSS do not michael@0: * accept fragmented alerts). michael@0: */ michael@0: #define SSL_CBC_RANDOM_IV 23 michael@0: #define SSL_ENABLE_OCSP_STAPLING 24 /* Request OCSP stapling (client) */ michael@0: michael@0: /* SSL_ENABLE_NPN controls whether the NPN extension is enabled for the initial michael@0: * handshake when application layer protocol negotiation is used. michael@0: * SSL_SetNextProtoCallback or SSL_SetNextProtoNego must be used to control the michael@0: * application layer protocol negotiation; otherwise, the NPN extension will michael@0: * not be negotiated. SSL_ENABLE_NPN is currently enabled by default but this michael@0: * may change in future versions. michael@0: */ michael@0: #define SSL_ENABLE_NPN 25 michael@0: michael@0: /* SSL_ENABLE_ALPN controls whether the ALPN extension is enabled for the michael@0: * initial handshake when application layer protocol negotiation is used. michael@0: * SSL_SetNextProtoNego (not SSL_SetNextProtoCallback) must be used to control michael@0: * the application layer protocol negotiation; otherwise, the ALPN extension michael@0: * will not be negotiated. ALPN is not negotiated for renegotiation handshakes, michael@0: * even though the ALPN specification defines a way to use ALPN during michael@0: * renegotiations. SSL_ENABLE_ALPN is currently disabled by default, but this michael@0: * may change in future versions. michael@0: */ michael@0: #define SSL_ENABLE_ALPN 26 michael@0: michael@0: #define SSL_ENABLE_FALLBACK_SCSV 28 /* Send fallback SCSV in michael@0: * handshakes. */ michael@0: michael@0: #ifdef SSL_DEPRECATED_FUNCTION michael@0: /* Old deprecated function names */ michael@0: SSL_IMPORT SECStatus SSL_Enable(PRFileDesc *fd, int option, PRBool on); michael@0: SSL_IMPORT SECStatus SSL_EnableDefault(int option, PRBool on); michael@0: #endif michael@0: michael@0: /* New function names */ michael@0: SSL_IMPORT SECStatus SSL_OptionSet(PRFileDesc *fd, PRInt32 option, PRBool on); michael@0: SSL_IMPORT SECStatus SSL_OptionGet(PRFileDesc *fd, PRInt32 option, PRBool *on); michael@0: SSL_IMPORT SECStatus SSL_OptionSetDefault(PRInt32 option, PRBool on); michael@0: SSL_IMPORT SECStatus SSL_OptionGetDefault(PRInt32 option, PRBool *on); michael@0: SSL_IMPORT SECStatus SSL_CertDBHandleSet(PRFileDesc *fd, CERTCertDBHandle *dbHandle); michael@0: michael@0: /* SSLNextProtoCallback is called during the handshake for the client, when a michael@0: * Next Protocol Negotiation (NPN) extension has been received from the server. michael@0: * |protos| and |protosLen| define a buffer which contains the server's michael@0: * advertisement. This data is guaranteed to be well formed per the NPN spec. michael@0: * |protoOut| is a buffer provided by the caller, of length 255 (the maximum michael@0: * allowed by the protocol). On successful return, the protocol to be announced michael@0: * to the server will be in |protoOut| and its length in |*protoOutLen|. michael@0: * michael@0: * The callback must return SECFailure or SECSuccess (not SECWouldBlock). michael@0: */ michael@0: typedef SECStatus (PR_CALLBACK *SSLNextProtoCallback)( michael@0: void *arg, michael@0: PRFileDesc *fd, michael@0: const unsigned char* protos, michael@0: unsigned int protosLen, michael@0: unsigned char* protoOut, michael@0: unsigned int* protoOutLen, michael@0: unsigned int protoMaxOut); michael@0: michael@0: /* SSL_SetNextProtoCallback sets a callback function to handle Next Protocol michael@0: * Negotiation. It causes a client to advertise NPN. */ michael@0: SSL_IMPORT SECStatus SSL_SetNextProtoCallback(PRFileDesc *fd, michael@0: SSLNextProtoCallback callback, michael@0: void *arg); michael@0: michael@0: /* SSL_SetNextProtoNego can be used as an alternative to michael@0: * SSL_SetNextProtoCallback. It also causes a client to advertise NPN and michael@0: * installs a default callback function which selects the first supported michael@0: * protocol in server-preference order. If no matching protocol is found it michael@0: * selects the first supported protocol. michael@0: * michael@0: * Using this function also allows the client to transparently support ALPN. michael@0: * The same set of protocols will be advertised via ALPN and, if the server michael@0: * uses ALPN to select a protocol, SSL_GetNextProto will return michael@0: * SSL_NEXT_PROTO_SELECTED as the state. michael@0: * michael@0: * Since NPN uses the first protocol as the fallback protocol, when sending an michael@0: * ALPN extension, the first protocol is moved to the end of the list. This michael@0: * indicates that the fallback protocol is the least preferred. The other michael@0: * protocols should be in preference order. michael@0: * michael@0: * The supported protocols are specified in |data| in wire-format (8-bit michael@0: * length-prefixed). For example: "\010http/1.1\006spdy/2". */ michael@0: SSL_IMPORT SECStatus SSL_SetNextProtoNego(PRFileDesc *fd, michael@0: const unsigned char *data, michael@0: unsigned int length); michael@0: michael@0: typedef enum SSLNextProtoState { michael@0: SSL_NEXT_PROTO_NO_SUPPORT = 0, /* No peer support */ michael@0: SSL_NEXT_PROTO_NEGOTIATED = 1, /* Mutual agreement */ michael@0: SSL_NEXT_PROTO_NO_OVERLAP = 2, /* No protocol overlap found */ michael@0: SSL_NEXT_PROTO_SELECTED = 3 /* Server selected proto (ALPN) */ michael@0: } SSLNextProtoState; michael@0: michael@0: /* SSL_GetNextProto can be used in the HandshakeCallback or any time after michael@0: * a handshake to retrieve the result of the Next Protocol negotiation. michael@0: * michael@0: * The length of the negotiated protocol, if any, is written into *bufLen. michael@0: * If the negotiated protocol is longer than bufLenMax, then SECFailure is michael@0: * returned. Otherwise, the negotiated protocol, if any, is written into buf, michael@0: * and SECSuccess is returned. */ michael@0: SSL_IMPORT SECStatus SSL_GetNextProto(PRFileDesc *fd, michael@0: SSLNextProtoState *state, michael@0: unsigned char *buf, michael@0: unsigned int *bufLen, michael@0: unsigned int bufLenMax); michael@0: michael@0: /* michael@0: ** Control ciphers that SSL uses. If on is non-zero then the named cipher michael@0: ** is enabled, otherwise it is disabled. michael@0: ** The "cipher" values are defined in sslproto.h (the SSL_EN_* values). michael@0: ** EnableCipher records user preferences. michael@0: ** SetPolicy sets the policy according to the policy module. michael@0: */ michael@0: #ifdef SSL_DEPRECATED_FUNCTION michael@0: /* Old deprecated function names */ michael@0: SSL_IMPORT SECStatus SSL_EnableCipher(long which, PRBool enabled); michael@0: SSL_IMPORT SECStatus SSL_SetPolicy(long which, int policy); michael@0: #endif michael@0: michael@0: /* New function names */ michael@0: SSL_IMPORT SECStatus SSL_CipherPrefSet(PRFileDesc *fd, PRInt32 cipher, PRBool enabled); michael@0: SSL_IMPORT SECStatus SSL_CipherPrefGet(PRFileDesc *fd, PRInt32 cipher, PRBool *enabled); michael@0: SSL_IMPORT SECStatus SSL_CipherPrefSetDefault(PRInt32 cipher, PRBool enabled); michael@0: SSL_IMPORT SECStatus SSL_CipherPrefGetDefault(PRInt32 cipher, PRBool *enabled); michael@0: SSL_IMPORT SECStatus SSL_CipherPolicySet(PRInt32 cipher, PRInt32 policy); michael@0: SSL_IMPORT SECStatus SSL_CipherPolicyGet(PRInt32 cipher, PRInt32 *policy); michael@0: michael@0: /* SSL Version Range API michael@0: ** michael@0: ** This API should be used to control SSL 3.0 & TLS support instead of the michael@0: ** older SSL_Option* API; however, the SSL_Option* API MUST still be used to michael@0: ** control SSL 2.0 support. In this version of libssl, SSL 3.0 and TLS 1.0 are michael@0: ** enabled by default. Future versions of libssl may change which versions of michael@0: ** the protocol are enabled by default. michael@0: ** michael@0: ** The SSLProtocolVariant enum indicates whether the protocol is of type michael@0: ** stream or datagram. This must be provided to the functions that do not michael@0: ** take an fd. Functions which take an fd will get the variant from the fd, michael@0: ** which is typed. michael@0: ** michael@0: ** Using the new version range API in conjunction with the older michael@0: ** SSL_OptionSet-based API for controlling the enabled protocol versions may michael@0: ** cause unexpected results. Going forward, we guarantee only the following: michael@0: ** michael@0: ** SSL_OptionGet(SSL_ENABLE_TLS) will return PR_TRUE if *ANY* versions of TLS michael@0: ** are enabled. michael@0: ** michael@0: ** SSL_OptionSet(SSL_ENABLE_TLS, PR_FALSE) will disable *ALL* versions of TLS, michael@0: ** including TLS 1.0 and later. michael@0: ** michael@0: ** The above two properties provide compatibility for applications that use michael@0: ** SSL_OptionSet to implement the insecure fallback from TLS 1.x to SSL 3.0. michael@0: ** michael@0: ** SSL_OptionSet(SSL_ENABLE_TLS, PR_TRUE) will enable TLS 1.0, and may also michael@0: ** enable some later versions of TLS, if it is necessary to do so in order to michael@0: ** keep the set of enabled versions contiguous. For example, if TLS 1.2 is michael@0: ** enabled, then after SSL_OptionSet(SSL_ENABLE_TLS, PR_TRUE), TLS 1.0, michael@0: ** TLS 1.1, and TLS 1.2 will be enabled, and the call will have no effect on michael@0: ** whether SSL 3.0 is enabled. If no later versions of TLS are enabled at the michael@0: ** time SSL_OptionSet(SSL_ENABLE_TLS, PR_TRUE) is called, then no later michael@0: ** versions of TLS will be enabled by the call. michael@0: ** michael@0: ** SSL_OptionSet(SSL_ENABLE_SSL3, PR_FALSE) will disable SSL 3.0, and will not michael@0: ** change the set of TLS versions that are enabled. michael@0: ** michael@0: ** SSL_OptionSet(SSL_ENABLE_SSL3, PR_TRUE) will enable SSL 3.0, and may also michael@0: ** enable some versions of TLS if TLS 1.1 or later is enabled at the time of michael@0: ** the call, the same way SSL_OptionSet(SSL_ENABLE_TLS, PR_TRUE) works, in michael@0: ** order to keep the set of enabled versions contiguous. michael@0: */ michael@0: michael@0: /* Returns, in |*vrange|, the range of SSL3/TLS versions supported for the michael@0: ** given protocol variant by the version of libssl linked-to at runtime. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_VersionRangeGetSupported( michael@0: SSLProtocolVariant protocolVariant, SSLVersionRange *vrange); michael@0: michael@0: /* Returns, in |*vrange|, the range of SSL3/TLS versions enabled by default michael@0: ** for the given protocol variant. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_VersionRangeGetDefault( michael@0: SSLProtocolVariant protocolVariant, SSLVersionRange *vrange); michael@0: michael@0: /* Sets the range of enabled-by-default SSL3/TLS versions for the given michael@0: ** protocol variant to |*vrange|. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_VersionRangeSetDefault( michael@0: SSLProtocolVariant protocolVariant, const SSLVersionRange *vrange); michael@0: michael@0: /* Returns, in |*vrange|, the range of enabled SSL3/TLS versions for |fd|. */ michael@0: SSL_IMPORT SECStatus SSL_VersionRangeGet(PRFileDesc *fd, michael@0: SSLVersionRange *vrange); michael@0: michael@0: /* Sets the range of enabled SSL3/TLS versions for |fd| to |*vrange|. */ michael@0: SSL_IMPORT SECStatus SSL_VersionRangeSet(PRFileDesc *fd, michael@0: const SSLVersionRange *vrange); michael@0: michael@0: michael@0: /* Values for "policy" argument to SSL_CipherPolicySet */ michael@0: /* Values returned by SSL_CipherPolicyGet. */ michael@0: #define SSL_NOT_ALLOWED 0 /* or invalid or unimplemented */ michael@0: #define SSL_ALLOWED 1 michael@0: #define SSL_RESTRICTED 2 /* only with "Step-Up" certs. */ michael@0: michael@0: /* Values for "on" with SSL_REQUIRE_CERTIFICATE. */ michael@0: #define SSL_REQUIRE_NEVER ((PRBool)0) michael@0: #define SSL_REQUIRE_ALWAYS ((PRBool)1) michael@0: #define SSL_REQUIRE_FIRST_HANDSHAKE ((PRBool)2) michael@0: #define SSL_REQUIRE_NO_ERROR ((PRBool)3) michael@0: michael@0: /* Values for "on" with SSL_ENABLE_RENEGOTIATION */ michael@0: /* Never renegotiate at all. */ michael@0: #define SSL_RENEGOTIATE_NEVER ((PRBool)0) michael@0: /* Renegotiate without restriction, whether or not the peer's client hello */ michael@0: /* bears the renegotiation info extension. Vulnerable, as in the past. */ michael@0: #define SSL_RENEGOTIATE_UNRESTRICTED ((PRBool)1) michael@0: /* Only renegotiate if the peer's hello bears the TLS renegotiation_info */ michael@0: /* extension. This is safe renegotiation. */ michael@0: #define SSL_RENEGOTIATE_REQUIRES_XTN ((PRBool)2) michael@0: /* Disallow unsafe renegotiation in server sockets only, but allow clients */ michael@0: /* to continue to renegotiate with vulnerable servers. */ michael@0: /* This value should only be used during the transition period when few */ michael@0: /* servers have been upgraded. */ michael@0: #define SSL_RENEGOTIATE_TRANSITIONAL ((PRBool)3) michael@0: michael@0: /* michael@0: ** Reset the handshake state for fd. This will make the complete SSL michael@0: ** handshake protocol execute from the ground up on the next i/o michael@0: ** operation. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_ResetHandshake(PRFileDesc *fd, PRBool asServer); michael@0: michael@0: /* michael@0: ** Force the handshake for fd to complete immediately. This blocks until michael@0: ** the complete SSL handshake protocol is finished. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_ForceHandshake(PRFileDesc *fd); michael@0: michael@0: /* michael@0: ** Same as above, but with an I/O timeout. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_ForceHandshakeWithTimeout(PRFileDesc *fd, michael@0: PRIntervalTime timeout); michael@0: michael@0: /* michael@0: ** Query security status of socket. *on is set to one if security is michael@0: ** enabled. *keySize will contain the stream key size used. *issuer will michael@0: ** contain the RFC1485 verison of the name of the issuer of the michael@0: ** certificate at the other end of the connection. For a client, this is michael@0: ** the issuer of the server's certificate; for a server, this is the michael@0: ** issuer of the client's certificate (if any). Subject is the subject of michael@0: ** the other end's certificate. The pointers can be zero if the desired michael@0: ** data is not needed. All strings returned by this function are owned michael@0: ** by the caller, and need to be freed with PORT_Free. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_SecurityStatus(PRFileDesc *fd, int *on, char **cipher, michael@0: int *keySize, int *secretKeySize, michael@0: char **issuer, char **subject); michael@0: michael@0: /* Values for "on" */ michael@0: #define SSL_SECURITY_STATUS_NOOPT -1 michael@0: #define SSL_SECURITY_STATUS_OFF 0 michael@0: #define SSL_SECURITY_STATUS_ON_HIGH 1 michael@0: #define SSL_SECURITY_STATUS_ON_LOW 2 michael@0: #define SSL_SECURITY_STATUS_FORTEZZA 3 /* NO LONGER SUPPORTED */ michael@0: michael@0: /* michael@0: ** Return the certificate for our SSL peer. If the client calls this michael@0: ** it will always return the server's certificate. If the server calls michael@0: ** this, it may return NULL if client authentication is not enabled or michael@0: ** if the client had no certificate when asked. michael@0: ** "fd" the socket "file" descriptor michael@0: */ michael@0: SSL_IMPORT CERTCertificate *SSL_PeerCertificate(PRFileDesc *fd); michael@0: michael@0: /* michael@0: ** Return the certificates presented by the SSL peer. If the SSL peer michael@0: ** did not present certificates, return NULL with the michael@0: ** SSL_ERROR_NO_CERTIFICATE error. On failure, return NULL with an error michael@0: ** code other than SSL_ERROR_NO_CERTIFICATE. michael@0: ** "fd" the socket "file" descriptor michael@0: */ michael@0: SSL_IMPORT CERTCertList *SSL_PeerCertificateChain(PRFileDesc *fd); michael@0: michael@0: /* SSL_PeerStapledOCSPResponses returns the OCSP responses that were provided michael@0: * by the TLS server. The return value is a pointer to an internal SECItemArray michael@0: * that contains the returned OCSP responses; it is only valid until the michael@0: * callback function that calls SSL_PeerStapledOCSPResponses returns. michael@0: * michael@0: * If no OCSP responses were given by the server then the result will be empty. michael@0: * If there was an error, then the result will be NULL. michael@0: * michael@0: * You must set the SSL_ENABLE_OCSP_STAPLING option to enable OCSP stapling. michael@0: * to be provided by a server. michael@0: * michael@0: * libssl does not do any validation of the OCSP response itself; the michael@0: * authenticate certificate hook is responsible for doing so. The default michael@0: * authenticate certificate hook, SSL_AuthCertificate, does not implement michael@0: * any OCSP stapling funtionality, but this may change in future versions. michael@0: */ michael@0: SSL_IMPORT const SECItemArray * SSL_PeerStapledOCSPResponses(PRFileDesc *fd); michael@0: michael@0: /* SSL_SetStapledOCSPResponses stores an array of one or multiple OCSP responses michael@0: * in the fd's data, which may be sent as part of a server side cert_status michael@0: * handshake message. Parameter |responses| is for the server certificate of michael@0: * the key exchange type |kea|. michael@0: * The function will duplicate the responses array. michael@0: */ michael@0: SSL_IMPORT SECStatus michael@0: SSL_SetStapledOCSPResponses(PRFileDesc *fd, const SECItemArray *responses, michael@0: SSLKEAType kea); michael@0: michael@0: /* michael@0: ** Authenticate certificate hook. Called when a certificate comes in michael@0: ** (because of SSL_REQUIRE_CERTIFICATE in SSL_Enable) to authenticate the michael@0: ** certificate. michael@0: ** michael@0: ** The authenticate certificate hook must return SECSuccess to indicate the michael@0: ** certificate is valid, SECFailure to indicate the certificate is invalid, michael@0: ** or SECWouldBlock if the application will authenticate the certificate michael@0: ** asynchronously. SECWouldBlock is only supported for non-blocking sockets. michael@0: ** michael@0: ** If the authenticate certificate hook returns SECFailure, then the bad cert michael@0: ** hook will be called. The bad cert handler is NEVER called if the michael@0: ** authenticate certificate hook returns SECWouldBlock. If the application michael@0: ** needs to handle and/or override a bad cert, it should do so before it michael@0: ** calls SSL_AuthCertificateComplete (modifying the error it passes to michael@0: ** SSL_AuthCertificateComplete as needed). michael@0: ** michael@0: ** See the documentation for SSL_AuthCertificateComplete for more information michael@0: ** about the asynchronous behavior that occurs when the authenticate michael@0: ** certificate hook returns SECWouldBlock. michael@0: ** michael@0: ** RFC 6066 says that clients should send the bad_certificate_status_response michael@0: ** alert when they encounter an error processing the stapled OCSP response. michael@0: ** libssl does not provide a way for the authenticate certificate hook to michael@0: ** indicate that an OCSP error (SEC_ERROR_OCSP_*) that it returns is an error michael@0: ** in the stapled OCSP response or an error in some other OCSP response. michael@0: ** Further, NSS does not provide a convenient way to control or determine michael@0: ** which OCSP response(s) were used to validate a certificate chain. michael@0: ** Consequently, the current version of libssl does not ever send the michael@0: ** bad_certificate_status_response alert. This may change in future releases. michael@0: */ michael@0: typedef SECStatus (PR_CALLBACK *SSLAuthCertificate)(void *arg, PRFileDesc *fd, michael@0: PRBool checkSig, michael@0: PRBool isServer); michael@0: michael@0: SSL_IMPORT SECStatus SSL_AuthCertificateHook(PRFileDesc *fd, michael@0: SSLAuthCertificate f, michael@0: void *arg); michael@0: michael@0: /* An implementation of the certificate authentication hook */ michael@0: SSL_IMPORT SECStatus SSL_AuthCertificate(void *arg, PRFileDesc *fd, michael@0: PRBool checkSig, PRBool isServer); michael@0: michael@0: /* michael@0: * Prototype for SSL callback to get client auth data from the application. michael@0: * arg - application passed argument michael@0: * caNames - pointer to distinguished names of CAs that the server likes michael@0: * pRetCert - pointer to pointer to cert, for return of cert michael@0: * pRetKey - pointer to key pointer, for return of key michael@0: */ michael@0: typedef SECStatus (PR_CALLBACK *SSLGetClientAuthData)(void *arg, michael@0: PRFileDesc *fd, michael@0: CERTDistNames *caNames, michael@0: CERTCertificate **pRetCert,/*return */ michael@0: SECKEYPrivateKey **pRetKey);/* return */ michael@0: michael@0: /* michael@0: * Set the client side callback for SSL to retrieve user's private key michael@0: * and certificate. michael@0: * fd - the file descriptor for the connection in question michael@0: * f - the application's callback that delivers the key and cert michael@0: * a - application specific data michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_GetClientAuthDataHook(PRFileDesc *fd, michael@0: SSLGetClientAuthData f, void *a); michael@0: michael@0: michael@0: /* michael@0: ** SNI extension processing callback function. michael@0: ** It is called when SSL socket receives SNI extension in ClientHello message. michael@0: ** Upon this callback invocation, application is responsible to reconfigure the michael@0: ** socket with the data for a particular server name. michael@0: ** There are three potential outcomes of this function invocation: michael@0: ** * application does not recognize the name or the type and wants the michael@0: ** "unrecognized_name" alert be sent to the client. In this case the callback michael@0: ** function must return SSL_SNI_SEND_ALERT status. michael@0: ** * application does not recognize the name, but wants to continue with michael@0: ** the handshake using the current socket configuration. In this case, michael@0: ** no socket reconfiguration is needed and the function should return michael@0: ** SSL_SNI_CURRENT_CONFIG_IS_USED. michael@0: ** * application recognizes the name and reconfigures the socket with michael@0: ** appropriate certs, key, etc. There are many ways to reconfigure. NSS michael@0: ** provides SSL_ReconfigFD function that can be used to update the socket michael@0: ** data from model socket. To continue with the rest of the handshake, the michael@0: ** implementation function should return an index of a name it has chosen. michael@0: ** LibSSL will ignore any SNI extension received in a ClientHello message michael@0: ** if application does not register a SSLSNISocketConfig callback. michael@0: ** Each type field of SECItem indicates the name type. michael@0: ** NOTE: currently RFC3546 defines only one name type: sni_host_name. michael@0: ** Client is allowed to send only one name per known type. LibSSL will michael@0: ** send an "unrecognized_name" alert if SNI extension name list contains more michael@0: ** then one name of a type. michael@0: */ michael@0: typedef PRInt32 (PR_CALLBACK *SSLSNISocketConfig)(PRFileDesc *fd, michael@0: const SECItem *srvNameArr, michael@0: PRUint32 srvNameArrSize, michael@0: void *arg); michael@0: michael@0: /* michael@0: ** SSLSNISocketConfig should return an index within 0 and srvNameArrSize-1 michael@0: ** when it has reconfigured the socket fd to use certs and keys, etc michael@0: ** for a specific name. There are two other allowed return values. One michael@0: ** tells libSSL to use the default cert and key. The other tells libSSL michael@0: ** to send the "unrecognized_name" alert. These values are: michael@0: **/ michael@0: #define SSL_SNI_CURRENT_CONFIG_IS_USED -1 michael@0: #define SSL_SNI_SEND_ALERT -2 michael@0: michael@0: /* michael@0: ** Set application implemented SNISocketConfig callback. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_SNISocketConfigHook(PRFileDesc *fd, michael@0: SSLSNISocketConfig f, michael@0: void *arg); michael@0: michael@0: /* michael@0: ** Reconfigure fd SSL socket with model socket parameters. Sets michael@0: ** server certs and keys, list of trust anchor, socket options michael@0: ** and all SSL socket call backs and parameters. michael@0: */ michael@0: SSL_IMPORT PRFileDesc *SSL_ReconfigFD(PRFileDesc *model, PRFileDesc *fd); michael@0: michael@0: /* michael@0: * Set the client side argument for SSL to retrieve PKCS #11 pin. michael@0: * fd - the file descriptor for the connection in question michael@0: * a - pkcs11 application specific data michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_SetPKCS11PinArg(PRFileDesc *fd, void *a); michael@0: michael@0: /* michael@0: ** This is a callback for dealing with server certs that are not authenticated michael@0: ** by the client. The client app can decide that it actually likes the michael@0: ** cert by some external means and restart the connection. michael@0: ** michael@0: ** The bad cert hook must return SECSuccess to override the result of the michael@0: ** authenticate certificate hook, SECFailure if the certificate should still be michael@0: ** considered invalid, or SECWouldBlock if the application will authenticate michael@0: ** the certificate asynchronously. SECWouldBlock is only supported for michael@0: ** non-blocking sockets. michael@0: ** michael@0: ** See the documentation for SSL_AuthCertificateComplete for more information michael@0: ** about the asynchronous behavior that occurs when the bad cert hook returns michael@0: ** SECWouldBlock. michael@0: */ michael@0: typedef SECStatus (PR_CALLBACK *SSLBadCertHandler)(void *arg, PRFileDesc *fd); michael@0: SSL_IMPORT SECStatus SSL_BadCertHook(PRFileDesc *fd, SSLBadCertHandler f, michael@0: void *arg); michael@0: michael@0: /* michael@0: ** Configure SSL socket for running a secure server. Needs the michael@0: ** certificate for the server and the servers private key. The arguments michael@0: ** are copied. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_ConfigSecureServer( michael@0: PRFileDesc *fd, CERTCertificate *cert, michael@0: SECKEYPrivateKey *key, SSLKEAType kea); michael@0: michael@0: /* michael@0: ** Allows SSL socket configuration with caller-supplied certificate chain. michael@0: ** If certChainOpt is NULL, tries to find one. michael@0: */ michael@0: SSL_IMPORT SECStatus michael@0: SSL_ConfigSecureServerWithCertChain(PRFileDesc *fd, CERTCertificate *cert, michael@0: const CERTCertificateList *certChainOpt, michael@0: SECKEYPrivateKey *key, SSLKEAType kea); michael@0: michael@0: /* michael@0: ** Configure a secure server's session-id cache. Define the maximum number michael@0: ** of entries in the cache, the longevity of the entires, and the directory michael@0: ** where the cache files will be placed. These values can be zero, and michael@0: ** if so, the implementation will choose defaults. michael@0: ** This version of the function is for use in applications that have only one michael@0: ** process that uses the cache (even if that process has multiple threads). michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_ConfigServerSessionIDCache(int maxCacheEntries, michael@0: PRUint32 timeout, michael@0: PRUint32 ssl3_timeout, michael@0: const char * directory); michael@0: michael@0: /* Configure a secure server's session-id cache. Depends on value of michael@0: * enableMPCache, configures malti-proc or single proc cache. */ michael@0: SSL_IMPORT SECStatus SSL_ConfigServerSessionIDCacheWithOpt( michael@0: PRUint32 timeout, michael@0: PRUint32 ssl3_timeout, michael@0: const char * directory, michael@0: int maxCacheEntries, michael@0: int maxCertCacheEntries, michael@0: int maxSrvNameCacheEntries, michael@0: PRBool enableMPCache); michael@0: michael@0: /* michael@0: ** Like SSL_ConfigServerSessionIDCache, with one important difference. michael@0: ** If the application will run multiple processes (as opposed to, or in michael@0: ** addition to multiple threads), then it must call this function, instead michael@0: ** of calling SSL_ConfigServerSessionIDCache(). michael@0: ** This has nothing to do with the number of processORs, only processEs. michael@0: ** This function sets up a Server Session ID (SID) cache that is safe for michael@0: ** access by multiple processes on the same system. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_ConfigMPServerSIDCache(int maxCacheEntries, michael@0: PRUint32 timeout, michael@0: PRUint32 ssl3_timeout, michael@0: const char * directory); michael@0: michael@0: /* Get and set the configured maximum number of mutexes used for the michael@0: ** server's store of SSL sessions. This value is used by the server michael@0: ** session ID cache initialization functions shown above. Note that on michael@0: ** some platforms, these mutexes are actually implemented with POSIX michael@0: ** semaphores, or with unnamed pipes. The default value varies by platform. michael@0: ** An attempt to set a too-low maximum will return an error and the michael@0: ** configured value will not be changed. michael@0: */ michael@0: SSL_IMPORT PRUint32 SSL_GetMaxServerCacheLocks(void); michael@0: SSL_IMPORT SECStatus SSL_SetMaxServerCacheLocks(PRUint32 maxLocks); michael@0: michael@0: /* environment variable set by SSL_ConfigMPServerSIDCache, and queried by michael@0: * SSL_InheritMPServerSIDCache when envString is NULL. michael@0: */ michael@0: #define SSL_ENV_VAR_NAME "SSL_INHERITANCE" michael@0: michael@0: /* called in child to inherit SID Cache variables. michael@0: * If envString is NULL, this function will use the value of the environment michael@0: * variable "SSL_INHERITANCE", otherwise the string value passed in will be michael@0: * used. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_InheritMPServerSIDCache(const char * envString); michael@0: michael@0: /* michael@0: ** Set the callback that gets called when a TLS handshake is complete. The michael@0: ** handshake callback is called after verifying the peer's Finished message and michael@0: ** before processing incoming application data. michael@0: ** michael@0: ** For the initial handshake: If the handshake false started (see michael@0: ** SSL_ENABLE_FALSE_START), then application data may already have been sent michael@0: ** before the handshake callback is called. If we did not false start then the michael@0: ** callback will get called before any application data is sent. michael@0: */ michael@0: typedef void (PR_CALLBACK *SSLHandshakeCallback)(PRFileDesc *fd, michael@0: void *client_data); michael@0: SSL_IMPORT SECStatus SSL_HandshakeCallback(PRFileDesc *fd, michael@0: SSLHandshakeCallback cb, void *client_data); michael@0: michael@0: /* Applications that wish to enable TLS false start must set this callback michael@0: ** function. NSS will invoke the functon to determine if a particular michael@0: ** connection should use false start or not. SECSuccess indicates that the michael@0: ** callback completed successfully, and if so *canFalseStart indicates if false michael@0: ** start can be used. If the callback does not return SECSuccess then the michael@0: ** handshake will be canceled. NSS's recommended criteria can be evaluated by michael@0: ** calling SSL_RecommendedCanFalseStart. michael@0: ** michael@0: ** If no false start callback is registered then false start will never be michael@0: ** done, even if the SSL_ENABLE_FALSE_START option is enabled. michael@0: **/ michael@0: typedef SECStatus (PR_CALLBACK *SSLCanFalseStartCallback)( michael@0: PRFileDesc *fd, void *arg, PRBool *canFalseStart); michael@0: michael@0: SSL_IMPORT SECStatus SSL_SetCanFalseStartCallback( michael@0: PRFileDesc *fd, SSLCanFalseStartCallback callback, void *arg); michael@0: michael@0: /* This function sets *canFalseStart according to the recommended criteria for michael@0: ** false start. These criteria may change from release to release and may depend michael@0: ** on which handshake features have been negotiated and/or properties of the michael@0: ** certifciates/keys used on the connection. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_RecommendedCanFalseStart(PRFileDesc *fd, michael@0: PRBool *canFalseStart); michael@0: michael@0: /* michael@0: ** For the server, request a new handshake. For the client, begin a new michael@0: ** handshake. If flushCache is non-zero, the SSL3 cache entry will be michael@0: ** flushed first, ensuring that a full SSL handshake will be done. michael@0: ** If flushCache is zero, and an SSL connection is established, it will michael@0: ** do the much faster session restart handshake. This will change the michael@0: ** session keys without doing another private key operation. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_ReHandshake(PRFileDesc *fd, PRBool flushCache); michael@0: michael@0: /* michael@0: ** Same as above, but with an I/O timeout. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_ReHandshakeWithTimeout(PRFileDesc *fd, michael@0: PRBool flushCache, michael@0: PRIntervalTime timeout); michael@0: michael@0: michael@0: #ifdef SSL_DEPRECATED_FUNCTION michael@0: /* deprecated! michael@0: ** For the server, request a new handshake. For the client, begin a new michael@0: ** handshake. Flushes SSL3 session cache entry first, ensuring that a michael@0: ** full handshake will be done. michael@0: ** This call is equivalent to SSL_ReHandshake(fd, PR_TRUE) michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_RedoHandshake(PRFileDesc *fd); michael@0: #endif michael@0: michael@0: /* michael@0: * Allow the application to pass a URL or hostname into the SSL library. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_SetURL(PRFileDesc *fd, const char *url); michael@0: michael@0: /* michael@0: * Allow an application to define a set of trust anchors for peer michael@0: * cert validation. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_SetTrustAnchors(PRFileDesc *fd, CERTCertList *list); michael@0: michael@0: /* michael@0: ** Return the number of bytes that SSL has waiting in internal buffers. michael@0: ** Return 0 if security is not enabled. michael@0: */ michael@0: SSL_IMPORT int SSL_DataPending(PRFileDesc *fd); michael@0: michael@0: /* michael@0: ** Invalidate the SSL session associated with fd. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_InvalidateSession(PRFileDesc *fd); michael@0: michael@0: /* michael@0: ** Return a SECItem containing the SSL session ID associated with the fd. michael@0: */ michael@0: SSL_IMPORT SECItem *SSL_GetSessionID(PRFileDesc *fd); michael@0: michael@0: /* michael@0: ** Clear out the client's SSL session cache, not the server's session cache. michael@0: */ michael@0: SSL_IMPORT void SSL_ClearSessionCache(void); michael@0: michael@0: /* michael@0: ** Close the server's SSL session cache. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_ShutdownServerSessionIDCache(void); michael@0: michael@0: /* michael@0: ** Set peer information so we can correctly look up SSL session later. michael@0: ** You only have to do this if you're tunneling through a proxy. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_SetSockPeerID(PRFileDesc *fd, const char *peerID); michael@0: michael@0: /* michael@0: ** Reveal the security information for the peer. michael@0: */ michael@0: SSL_IMPORT CERTCertificate * SSL_RevealCert(PRFileDesc * socket); michael@0: SSL_IMPORT void * SSL_RevealPinArg(PRFileDesc * socket); michael@0: SSL_IMPORT char * SSL_RevealURL(PRFileDesc * socket); michael@0: michael@0: /* This callback may be passed to the SSL library via a call to michael@0: * SSL_GetClientAuthDataHook() for each SSL client socket. michael@0: * It will be invoked when SSL needs to know what certificate and private key michael@0: * (if any) to use to respond to a request for client authentication. michael@0: * If arg is non-NULL, it is a pointer to a NULL-terminated string containing michael@0: * the nickname of the cert/key pair to use. michael@0: * If arg is NULL, this function will search the cert and key databases for michael@0: * a suitable match and send it if one is found. michael@0: */ michael@0: SSL_IMPORT SECStatus michael@0: NSS_GetClientAuthData(void * arg, michael@0: PRFileDesc * socket, michael@0: struct CERTDistNamesStr * caNames, michael@0: struct CERTCertificateStr ** pRetCert, michael@0: struct SECKEYPrivateKeyStr **pRetKey); michael@0: michael@0: /* michael@0: ** Configure DTLS-SRTP (RFC 5764) cipher suite preferences. michael@0: ** Input is a list of ciphers in descending preference order and a length michael@0: ** of the list. As a side effect, this causes the use_srtp extension to be michael@0: ** negotiated. michael@0: ** michael@0: ** Invalid or unimplemented cipher suites in |ciphers| are ignored. If at michael@0: ** least one cipher suite in |ciphers| is implemented, returns SECSuccess. michael@0: ** Otherwise returns SECFailure. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_SetSRTPCiphers(PRFileDesc *fd, michael@0: const PRUint16 *ciphers, michael@0: unsigned int numCiphers); michael@0: michael@0: /* michael@0: ** Get the selected DTLS-SRTP cipher suite (if any). michael@0: ** To be called after the handshake completes. michael@0: ** Returns SECFailure if not negotiated. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_GetSRTPCipher(PRFileDesc *fd, michael@0: PRUint16 *cipher); michael@0: michael@0: /* michael@0: * Look to see if any of the signers in the cert chain for "cert" are found michael@0: * in the list of caNames. michael@0: * Returns SECSuccess if so, SECFailure if not. michael@0: * Used by NSS_GetClientAuthData. May be used by other callback functions. michael@0: */ michael@0: SSL_IMPORT SECStatus NSS_CmpCertChainWCANames(CERTCertificate *cert, michael@0: CERTDistNames *caNames); michael@0: michael@0: /* michael@0: * Returns key exchange type of the keys in an SSL server certificate. michael@0: */ michael@0: SSL_IMPORT SSLKEAType NSS_FindCertKEAType(CERTCertificate * cert); michael@0: michael@0: /* Set cipher policies to a predefined Domestic (U.S.A.) policy. michael@0: * This essentially allows all supported ciphers. michael@0: */ michael@0: SSL_IMPORT SECStatus NSS_SetDomesticPolicy(void); michael@0: michael@0: /* Set cipher policies to a predefined Policy that is exportable from the USA michael@0: * according to present U.S. policies as we understand them. michael@0: * It is the same as NSS_SetDomesticPolicy now. michael@0: */ michael@0: SSL_IMPORT SECStatus NSS_SetExportPolicy(void); michael@0: michael@0: /* Set cipher policies to a predefined Policy that is exportable from the USA michael@0: * according to present U.S. policies as we understand them, and that the michael@0: * nation of France will permit to be imported into their country. michael@0: * It is the same as NSS_SetDomesticPolicy now. michael@0: */ michael@0: SSL_IMPORT SECStatus NSS_SetFrancePolicy(void); michael@0: michael@0: SSL_IMPORT SSL3Statistics * SSL_GetStatistics(void); michael@0: michael@0: /* Report more information than SSL_SecurityStatus. michael@0: ** Caller supplies the info struct. Function fills it in. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_GetChannelInfo(PRFileDesc *fd, SSLChannelInfo *info, michael@0: PRUintn len); michael@0: SSL_IMPORT SECStatus SSL_GetCipherSuiteInfo(PRUint16 cipherSuite, michael@0: SSLCipherSuiteInfo *info, PRUintn len); michael@0: michael@0: /* Returnes negotiated through SNI host info. */ michael@0: SSL_IMPORT SECItem *SSL_GetNegotiatedHostInfo(PRFileDesc *fd); michael@0: michael@0: /* Export keying material according to RFC 5705. michael@0: ** fd must correspond to a TLS 1.0 or higher socket and out must michael@0: ** already be allocated. If hasContext is false, it uses the no-context michael@0: ** construction from the RFC and ignores the context and contextLen michael@0: ** arguments. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_ExportKeyingMaterial(PRFileDesc *fd, michael@0: const char *label, michael@0: unsigned int labelLen, michael@0: PRBool hasContext, michael@0: const unsigned char *context, michael@0: unsigned int contextLen, michael@0: unsigned char *out, michael@0: unsigned int outLen); michael@0: michael@0: /* michael@0: ** Return a new reference to the certificate that was most recently sent michael@0: ** to the peer on this SSL/TLS connection, or NULL if none has been sent. michael@0: */ michael@0: SSL_IMPORT CERTCertificate * SSL_LocalCertificate(PRFileDesc *fd); michael@0: michael@0: /* Test an SSL configuration to see if SSL_BYPASS_PKCS11 can be turned on. michael@0: ** Check the key exchange algorithm for each cipher in the list to see if michael@0: ** a master secret key can be extracted after being derived with the mechanism michael@0: ** required by the protocolmask argument. If the KEA will use keys from the michael@0: ** specified cert make sure the extract operation is attempted from the slot michael@0: ** where the private key resides. michael@0: ** If MS can be extracted for all ciphers, (*pcanbypass) is set to TRUE and michael@0: ** SECSuccess is returned. In all other cases but one (*pcanbypass) is michael@0: ** set to FALSE and SECFailure is returned. michael@0: ** In that last case Derive() has been called successfully but the MS is null, michael@0: ** CanBypass sets (*pcanbypass) to FALSE and returns SECSuccess indicating the michael@0: ** arguments were all valid but the slot cannot be bypassed. michael@0: ** michael@0: ** Note: A TRUE return code from CanBypass means "Your configuration will perform michael@0: ** NO WORSE with the bypass enabled than without"; it does NOT mean that every michael@0: ** cipher suite listed will work properly with the selected protocols. michael@0: ** michael@0: ** Caveat: If export cipher suites are included in the argument list Canbypass michael@0: ** will return FALSE. michael@0: **/ michael@0: michael@0: /* protocol mask bits */ michael@0: #define SSL_CBP_SSL3 0x0001 /* test SSL v3 mechanisms */ michael@0: #define SSL_CBP_TLS1_0 0x0002 /* test TLS v1.0 mechanisms */ michael@0: michael@0: SSL_IMPORT SECStatus SSL_CanBypass(CERTCertificate *cert, michael@0: SECKEYPrivateKey *privKey, michael@0: PRUint32 protocolmask, michael@0: PRUint16 *ciphers, int nciphers, michael@0: PRBool *pcanbypass, void *pwArg); michael@0: michael@0: /* michael@0: ** Did the handshake with the peer negotiate the given extension? michael@0: ** Output parameter valid only if function returns SECSuccess michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_HandshakeNegotiatedExtension(PRFileDesc * socket, michael@0: SSLExtensionType extId, michael@0: PRBool *yes); michael@0: michael@0: /* michael@0: ** How long should we wait before retransmitting the next flight of michael@0: ** the DTLS handshake? Returns SECFailure if not DTLS or not in a michael@0: ** handshake. michael@0: */ michael@0: SSL_IMPORT SECStatus DTLS_GetHandshakeTimeout(PRFileDesc *socket, michael@0: PRIntervalTime *timeout); michael@0: michael@0: /* michael@0: * Return a boolean that indicates whether the underlying library michael@0: * will perform as the caller expects. michael@0: * michael@0: * The only argument is a string, which should be the version michael@0: * identifier of the NSS library. That string will be compared michael@0: * against a string that represents the actual build version of michael@0: * the SSL library. michael@0: */ michael@0: extern PRBool NSSSSL_VersionCheck(const char *importedVersion); michael@0: michael@0: /* michael@0: * Returns a const string of the SSL library version. michael@0: */ michael@0: extern const char *NSSSSL_GetVersion(void); michael@0: michael@0: /* Restart an SSL connection that was paused to do asynchronous certificate michael@0: * chain validation (when the auth certificate hook or bad cert handler michael@0: * returned SECWouldBlock). michael@0: * michael@0: * This function only works for non-blocking sockets; Do not use it for michael@0: * blocking sockets. Currently, this function works only for the client role of michael@0: * a connection; it does not work for the server role. michael@0: * michael@0: * The application must call SSL_AuthCertificateComplete with 0 as the value of michael@0: * the error parameter after it has successfully validated the peer's michael@0: * certificate, in order to continue the SSL handshake. michael@0: * michael@0: * The application may call SSL_AuthCertificateComplete with a non-zero value michael@0: * for error (e.g. SEC_ERROR_REVOKED_CERTIFICATE) when certificate validation michael@0: * fails, before it closes the connection. If the application does so, an michael@0: * alert corresponding to the error (e.g. certificate_revoked) will be sent to michael@0: * the peer. See the source code of the internal function michael@0: * ssl3_SendAlertForCertError for the current mapping of error to alert. This michael@0: * mapping may change in future versions of libssl. michael@0: * michael@0: * This function will not complete the entire handshake. The application must michael@0: * call SSL_ForceHandshake, PR_Recv, PR_Send, etc. after calling this function michael@0: * to force the handshake to complete. michael@0: * michael@0: * On the first handshake of a connection, libssl will wait for the peer's michael@0: * certificate to be authenticated before calling the handshake callback, michael@0: * sending a client certificate, sending any application data, or returning michael@0: * any application data to the application. On subsequent (renegotiation) michael@0: * handshakes, libssl will block the handshake unconditionally while the michael@0: * certificate is being validated. michael@0: * michael@0: * libssl may send and receive handshake messages while waiting for the michael@0: * application to call SSL_AuthCertificateComplete, and it may call other michael@0: * callbacks (e.g, the client auth data hook) before michael@0: * SSL_AuthCertificateComplete has been called. michael@0: * michael@0: * An application that uses this asynchronous mechanism will usually have lower michael@0: * handshake latency if it has to do public key operations on the certificate michael@0: * chain and/or CRL/OCSP/cert fetching during the authentication, especially if michael@0: * it does so in parallel on another thread. However, if the application can michael@0: * authenticate the peer's certificate quickly then it may be more efficient michael@0: * to use the synchronous mechanism (i.e. returning SECFailure/SECSuccess michael@0: * instead of SECWouldBlock from the authenticate certificate hook). michael@0: * michael@0: * Be careful about converting an application from synchronous cert validation michael@0: * to asynchronous certificate validation. A naive conversion is likely to michael@0: * result in deadlocks; e.g. the application will wait in PR_Poll for network michael@0: * I/O on the connection while all network I/O on the connection is blocked michael@0: * waiting for this function to be called. michael@0: * michael@0: * Returns SECFailure on failure, SECSuccess on success. Never returns michael@0: * SECWouldBlock. Note that SSL_AuthCertificateComplete will (usually) return michael@0: * SECSuccess; do not interpret the return value of SSL_AuthCertificateComplete michael@0: * as an indicator of whether it is OK to continue using the connection. For michael@0: * example, SSL_AuthCertificateComplete(fd, SEC_ERROR_REVOKED_CERTIFICATE) will michael@0: * return SECSuccess (normally), but that does not mean that the application michael@0: * should continue using the connection. If the application passes a non-zero michael@0: * value for second argument (error), or if SSL_AuthCertificateComplete returns michael@0: * anything other than SECSuccess, then the application should close the michael@0: * connection. michael@0: */ michael@0: SSL_IMPORT SECStatus SSL_AuthCertificateComplete(PRFileDesc *fd, michael@0: PRErrorCode error); michael@0: SEC_END_PROTOS michael@0: michael@0: #endif /* __ssl_h_ */