1SSL_CTX_set_tmp_rsa_callback(3)     OpenSSL    SSL_CTX_set_tmp_rsa_callback(3)
2
3
4

NAME

6       SSL_CTX_set_tmp_rsa_callback, SSL_CTX_set_tmp_rsa,
7       SSL_CTX_need_tmp_rsa, SSL_set_tmp_rsa_callback, SSL_set_tmp_rsa,
8       SSL_need_tmp_rsa - handle RSA keys for ephemeral key exchange
9

SYNOPSIS

11        #include <openssl/ssl.h>
12
13        void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,
14                   RSA *(*tmp_rsa_callback)(SSL *ssl, int is_export, int keylength));
15        long SSL_CTX_set_tmp_rsa(SSL_CTX *ctx, RSA *rsa);
16        long SSL_CTX_need_tmp_rsa(SSL_CTX *ctx);
17
18        void SSL_set_tmp_rsa_callback(SSL_CTX *ctx,
19                   RSA *(*tmp_rsa_callback)(SSL *ssl, int is_export, int keylength));
20        long SSL_set_tmp_rsa(SSL *ssl, RSA *rsa)
21        long SSL_need_tmp_rsa(SSL *ssl)
22
23        RSA *(*tmp_rsa_callback)(SSL *ssl, int is_export, int keylength));
24

DESCRIPTION

26       SSL_CTX_set_tmp_rsa_callback() sets the callback function for ctx to be
27       used when a temporary/ephemeral RSA key is required to tmp_rsa_call‐
28       back.  The callback is inherited by all SSL objects newly created from
29       ctx with <SSL_new(3)⎪SSL_new(3)>. Already created SSL objects are not
30       affected.
31
32       SSL_CTX_set_tmp_rsa() sets the temporary/ephemeral RSA key to be used
33       to be rsa. The key is inherited by all SSL objects newly created from
34       ctx with <SSL_new(3)⎪SSL_new(3)>. Already created SSL objects are not
35       affected.
36
37       SSL_CTX_need_tmp_rsa() returns 1, if a temporary/ephemeral RSA key is
38       needed for RSA-based strength-limited 'exportable' ciphersuites because
39       a RSA key with a keysize larger than 512 bits is installed.
40
41       SSL_set_tmp_rsa_callback() sets the callback only for ssl.
42
43       SSL_set_tmp_rsa() sets the key only for ssl.
44
45       SSL_need_tmp_rsa() returns 1, if a temporary/ephemeral RSA key is
46       needed, for RSA-based strength-limited 'exportable' ciphersuites
47       because a RSA key with a keysize larger than 512 bits is installed.
48
49       These functions apply to SSL/TLS servers only.
50

NOTES

52       When using a cipher with RSA authentication, an ephemeral RSA key
53       exchange can take place. In this case the session data are negotiated
54       using the ephemeral/temporary RSA key and the RSA key supplied and cer‐
55       tified by the certificate chain is only used for signing.
56
57       Under previous export restrictions, ciphers with RSA keys shorter (512
58       bits) than the usual key length of 1024 bits were created. To use these
59       ciphers with RSA keys of usual length, an ephemeral key exchange must
60       be performed, as the normal (certified) key cannot be directly used.
61
62       Using ephemeral RSA key exchange yields forward secrecy, as the connec‐
63       tion can only be decrypted, when the RSA key is known. By generating a
64       temporary RSA key inside the server application that is lost when the
65       application is left, it becomes impossible for an attacker to decrypt
66       past sessions, even if he gets hold of the normal (certified) RSA key,
67       as this key was used for signing only. The downside is that creating a
68       RSA key is computationally expensive.
69
70       Additionally, the use of ephemeral RSA key exchange is only allowed in
71       the TLS standard, when the RSA key can be used for signing only, that
72       is for export ciphers. Using ephemeral RSA key exchange for other pur‐
73       poses violates the standard and can break interoperability with
74       clients.  It is therefore strongly recommended to not use ephemeral RSA
75       key exchange and use EDH (Ephemeral Diffie-Hellman) key exchange
76       instead in order to achieve forward secrecy (see
77       SSL_CTX_set_tmp_dh_callback(3)).
78
79       On OpenSSL servers ephemeral RSA key exchange is therefore disabled by
80       default and must be explicitly enabled  using the SSL_OP_EPHEMERAL_RSA
81       option of SSL_CTX_set_options(3), violating the TLS/SSL standard. When
82       ephemeral RSA key exchange is required for export ciphers, it will
83       automatically be used without this option!
84
85       An application may either directly specify the key or can supply the
86       key via a callback function. The callback approach has the advantage,
87       that the callback may generate the key only in case it is actually
88       needed. As the generation of a RSA key is however costly, it will lead
89       to a significant delay in the handshake procedure.  Another advantage
90       of the callback function is that it can supply keys of different size
91       (e.g. for SSL_OP_EPHEMERAL_RSA usage) while the explicit setting of the
92       key is only useful for key size of 512 bits to satisfy the export
93       restricted ciphers and does give away key length if a longer key would
94       be allowed.
95
96       The tmp_rsa_callback is called with the keylength needed and the
97       is_export information. The is_export flag is set, when the ephemeral
98       RSA key exchange is performed with an export cipher.
99

EXAMPLES

101       Generate temporary RSA keys to prepare ephemeral RSA key exchange. As
102       the generation of a RSA key costs a lot of computer time, they saved
103       for later reuse. For demonstration purposes, two keys for 512 bits and
104       1024 bits respectively are generated.
105
106        ...
107        /* Set up ephemeral RSA stuff */
108        RSA *rsa_512 = NULL;
109        RSA *rsa_1024 = NULL;
110
111        rsa_512 = RSA_generate_key(512,RSA_F4,NULL,NULL);
112        if (rsa_512 == NULL)
113            evaluate_error_queue();
114
115        rsa_1024 = RSA_generate_key(1024,RSA_F4,NULL,NULL);
116        if (rsa_1024 == NULL)
117          evaluate_error_queue();
118
119        ...
120
121        RSA *tmp_rsa_callback(SSL *s, int is_export, int keylength)
122        {
123           RSA *rsa_tmp=NULL;
124
125           switch (keylength) {
126           case 512:
127             if (rsa_512)
128               rsa_tmp = rsa_512;
129             else { /* generate on the fly, should not happen in this example */
130               rsa_tmp = RSA_generate_key(keylength,RSA_F4,NULL,NULL);
131               rsa_512 = rsa_tmp; /* Remember for later reuse */
132             }
133             break;
134           case 1024:
135             if (rsa_1024)
136               rsa_tmp=rsa_1024;
137             else
138               should_not_happen_in_this_example();
139             break;
140           default:
141             /* Generating a key on the fly is very costly, so use what is there */
142             if (rsa_1024)
143               rsa_tmp=rsa_1024;
144             else
145               rsa_tmp=rsa_512; /* Use at least a shorter key */
146           }
147           return(rsa_tmp);
148        }
149

RETURN VALUES

151       SSL_CTX_set_tmp_rsa_callback() and SSL_set_tmp_rsa_callback() do not
152       return diagnostic output.
153
154       SSL_CTX_set_tmp_rsa() and SSL_set_tmp_rsa() do return 1 on success and
155       0 on failure. Check the error queue to find out the reason of failure.
156
157       SSL_CTX_need_tmp_rsa() and SSL_need_tmp_rsa() return 1 if a temporary
158       RSA key is needed and 0 otherwise.
159

SEE ALSO

161       ssl(3), SSL_CTX_set_cipher_list(3), SSL_CTX_set_options(3),
162       SSL_CTX_set_tmp_dh_callback(3), SSL_new(3), ciphers(1)
163
164
165
1660.9.8b                            2001-09-07   SSL_CTX_set_tmp_rsa_callback(3)
Impressum