tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ssl.h (75673B)


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