Overview of an SSL Application
Functions Used by Callbacks
Cleanup Although the details differ somewhat for client and server applications, the concepts and many of the functions are the same for both.
WARNING: Some of the SSL header files provided as part of NSS 2.0 include both public APIs documented in the NSS 2.0 documentation set and private APIs intended for internal use by the NSS implementation of SSL. You should use only the SSL APIs (and related certificate, key, and PKCS #11 APIs) that are described in this document, the SSL Reference. Other APIs that may be exposed in the header files are not supported for application use.Initialization includes setting up configuration files, setting global defaults, and setting up callback functions. Functions used in the initialization part of an application can include the following:
PR_Init. Initializes NSPR. Must be called before any other NSS functions.
PK11_SetPasswordFunc. Sets the global callback function to obtain passwords for PKCS #11 modules. Required.
NSS_Init. Sets up configuration files and performs other tasks required to run Network Security Services.
NSS_Initis not idempotent, so call it only once. Required.
SSL_OptionSetDefault. Changes default values for all subsequently opened sockets as long as the application is running (compare with
SSL_SetURLwhich only configures the socket that is currently open). This function must be called once for each default value that needs to be changed. Optional.
SSL_CipherPolicySet. These functions tell the library which cipher suites are permitted by policy (for example, to comply with export restrictions). Cipher suites disabled by policy cannot be enabled by user preference. One of these functions must be called before any cryptographic operations can be performed with NSS.
SSL_CipherPrefSetDefault. Enables all ciphers chosen by user preference. Optional.
SSL_ClearSessionCache. If an application will use SSL sockets that handshake as a server, you must specifically create and configure a server cache, using either
SSL_ConfigMPServerSIDCache. The server cache is used for all sessions where the program handshakes as an SSL server.
SSL_ClearSessionCache. Clears all sessions from the client session cache. Optional.
SSL_ConfigServerSessionIDCache. Sets up parameters for a server session cache for a single-process application. Required for single-process server applications.
SSL_ConfigMPServerSIDCache. Sets up parameters for a server cache for a multi-process application. Required for multi-process server applications. You can use either this function or
SSL_ConfigServerSessionIDCache, not both.
PR_NewTCPSocket. Opens a new socket. A legal NSPR socket is required to be passed to
SSL_ImportFD, whether it is created with this function or by another method.
SSL_ImportFD. Makes an NSPR socket into an SSL socket. Required. Brings an ordinary NSPR socket into the SSL library, returning a new NSPR socket that can be used to make SSL calls. You can pass this function a model file descriptor to create the new SSL socket with the same configuration state as the model.
SSL_ImportFDand perform any additional configuration that has not already been determined by the model file descriptor. Configuration functions control the configuration of an individual socket.
PR_GetSocketOption. Retrieves the socket options currently set for a specified socket. Optional.
PR_SetSocketOption. Sets the socket options for a specified socket., including making it blocking or nonblocking. Optional.
SSL_OptionSet. Sets a single configuration parameter of a specified socket. This function must be called once for each parameter whose settings you want to change from those established with
SSL_ConfigSecureServer. For servers only. Configures the socket with the information needed to handshake as an SSL server. Required for servers.
SSL_SetURL. For clients only. Records the target server URL for comparison with the URL specified by the server certificate. Required for clients.
SSL_SetPKCS11PinArg. Sets the argument passed to the PKCS #11 password callback function. Required.
SSL_AuthCertificateHook. Specifies a callback function used to authenticate an incoming certificate (optional for servers, necessary for clients to avoid "man-in-the-middle" attacks). Optional. If not specified, SSL uses the default callback function,
SSL_BadCertHook. Specifies a callback function to deal with a situation where authentication has failed. Optional.
SSL_GetClientAuthDataHook. Specifies a callback function for SSL to use when the server asks for client authentication information. This callback is required if you want to do client authentication. You can set the callback function to a standard one that is provided,
SSL_HandshakeCallback. Specifies a callback function that will be used by SSL to inform either a client application or a server application when the SSL handshake is completed. Optional.
SSL_ForceHandshakeor repeat it explicitly with
SSL_ReHandshake. Once the SSL sockets have been configured, authentication and encryption happen automatically whenever you use the communication functions from the NSPR library. A server application typically uses these functions to establish a connection:
PR_BindA client application typically uses these functions to establish a connection:
PR_GetConnectStatusWhen an application imports a socket into SSL after the TCP connection on that socket has already been established, it must call
to determine whether SSL should behave like an SSL client or an SSL server. Note that this step would not be necessary if the socket weren't already connected. For an SSL socket that is configured before it is connected, SSL figures this out when the application calls
PR_Accept. If the socket is already connected before SSL gets involved, you must provide this extra hint. Functions that can be used by both clients and servers during communication include the following:
SSL_InvalidateSessionAfter establishing a connection, an application first calls
SSL_ForceHandshaketo initiate the handshake. The application's protocol (for example, HTTP) determines which end has responsibility to talk first. The end that has to talk first should call
PR_Write, and the other end should call
SSL_ForceHandshakewhen the socket has been prepared for a handshake but neither end has anything to say immediately. This occurs, for example, when an HTTPS server has received a request and determines that before it can answer the request, it needs to request an authentication certificate from the client. At the HTTP protocol level, nothing more is being said (that is, no HTTP request or response is being sent), so the server first uses
SSL_ReHandshaketo begin a new handshake and then call
SSL_ForceHandshaketo drive the handshake to completion. An SSL application typically provides one or more callback functions that are called by the SSL or PKCS #11 library code under certain circumstances. Numerous functions provided by the NSS libraries are useful for such application callback functions, including these:
This portion of an SSL-enabled application consists primarily of closing the socket and freeing memory. After these tasks have been performed, call
NSS_Shutdownto close the certificate and key databases opened by
PR_Cleanupto coordinate a graceful shutdown of NSPR.
Table of Contents | Previous | Next | Index
Last Updated: 10/18/00 09:17:41