Background Step 1: SSL Version Selection and Certificate Preparation

98

5.1.2.1 Background

We need to examine three relevant object types: SSL_METHOD , SSL_CTX , and SSL . An SSL_METHOD represents an implementation of SSL functionality. In other words, it specifies a protocol version. OpenSSL provides populated SSL_METHOD objects and some accessor methods for them. They are listed in Table 5-1 . The extent of our interaction with this type of object will be to select the protocol version we wish to support by making a function call from the table. Table 5-1. Functions to retrieve pointers to SSL_METHOD objects Function Comments SSLv2_method Returns a pointer to SSL_METHOD for generic SSL Version 2 SSLv2_client_method Returns a pointer to SSL_METHOD for an SSL Version 2 client SSLv2_server_method Returns a pointer to SSL_METHOD for an SSL Version 2 server SSLv3_method Returns a pointer to SSL_METHOD for generic SSL Version 3 SSLv3_client_method Returns a pointer to SSL_METHOD for an SSL Version 3 client SSLv3_server_method Returns a pointer to SSL_METHOD for an SSL Version 3 server TLSv1_method Returns a pointer to SSL_METHOD for generic TLS Version 1 TLSv1_client_method Returns a pointer to SSL_METHOD for a TLS Version 1 client TLSv1_server_method Returns a pointer to SSL_METHOD for a TLS Version 1 server SSLv23_method Returns a pointer to SSL_METHOD for generic SSLTLS SSLv23_client_method Returns a pointer to SSL_METHOD for an SSLTLS client SSLv23_server_method Returns a pointer to SSL_METHOD for an SSLTLS server OpenSSL provides implementations for SSL Version 2, SSL Version 3, and TLS Version 1. Also, some SSLv23 functions dont indicate a specific protocol version but rather a compatibility mode. In such a mode, a connection will report that it can handle any of the three SSLTLS protocol versions. To reiterate, applications should not use SSLv2, since this protocol is known to have security flaws. Using an SSL_METHOD object retrieved by one of the functions in Table 5-1 , we create an SSL_CTX object. How would we create an application that supports both SSLv3 and TLSv1? If we are to create a server that needs to communicate with both SSLv3 and TLSv1 clients, using either SSLv3_method or TLSv1_method will prevent one kind of client from connecting properly. Since we do not want to use SSL Version 2 it is insecure, it would seem that the compatibility implementation SSLv23_method is also not an option. This isnt actually true. We can use the compatibility mode and set an option in the SSL_CTX object to have it remove SSLv2 from the acceptable protocols. The function to do this is SSL_CTX_set_options , and the relevant details for doing this are in Step 3. An SSL_CTX object will be a factory for producing SSL connection objects. This context allows us to set connection configuration parameters before the connection is made, such as protocol version, certificate information, and verification requirements. It is easiest to think of SSL_CTX objects as the containers for default values for the SSL connections to be made by a program. Objects of this type are created with the function SSL_CTX_new . This function takes only one argument, generally supplied from the return value of one of the functions in Table 5-1 . 99 In general, an application will create just one SSL_CTX object for all of the connections it makes. From this SSL_CTX object, an SSL type object can be created with the SSL_new function. This function causes the newly created SSL object to inherit all of the parameters set forth in the context. Even though most of the settings are copied to the SSL object on invocation of SSL_new , the order in which calls are made to OpenSSL functions can cause unexpected behavior if were not careful. Applications should set up an SSL_CTX completely, with all connection invariant settings, before creating SSL objects from it. In other words, after calling SSL_new with a particular context object, no more calls operating on that SSL_CTX object should be made until all produced SSL objects are no longer in use. The reason is simple. Modifying a context can sometimes affect the SSL connections that have already been created i.e.., a function we examine later, SSL_CTX_set_default_passwd_cb , changes the callback in the context and in all connections that were already created from this context. To avoid any unpredictability, never modify the context after connection creation has begun. If there are any connection-specific parameters that we do need to set, most SSL_CTX functions have SSL counterparts that act on SSL -type objects.

5.1.2.2 Certificate preparation