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
28       tmp_rsa_callback.  The callback is inherited by all SSL objects newly
29       created from ctx with <SSL_new(3)|SSL_new(3)>. Already created SSL
30       objects are not 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
55       certified 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
63       connection can only be decrypted, when the RSA key is known. By
64       generating a temporary RSA key inside the server application that is
65       lost when the application is left, it becomes impossible for an
66       attacker to decrypt past sessions, even if he gets hold of the normal
67       (certified) RSA key, as this key was used for signing only. The
68       downside is that creating a 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
73       purposes 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 DHE (Ephemeral Diffie-Hellman) key exchange
76       instead in order to achieve forward secrecy (see
77       SSL_CTX_set_tmp_dh_callback(3)).
78
79       An application may either directly specify the key or can supply the
80       key via a callback function. The callback approach has the advantage,
81       that the callback may generate the key only in case it is actually
82       needed. As the generation of a RSA key is however costly, it will lead
83       to a significant delay in the handshake procedure.  Another advantage
84       of the callback function is that it can supply keys of different size
85       while the explicit setting of the key is only useful for key size of
86       512 bits to satisfy the export restricted ciphers and does give away
87       key length if a longer key would be allowed.
88
89       The tmp_rsa_callback is called with the keylength needed and the
90       is_export information. The is_export flag is set, when the ephemeral
91       RSA key exchange is performed with an export cipher.
92

EXAMPLES

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

RETURN VALUES

144       SSL_CTX_set_tmp_rsa_callback() and SSL_set_tmp_rsa_callback() do not
145       return diagnostic output.
146
147       SSL_CTX_set_tmp_rsa() and SSL_set_tmp_rsa() do return 1 on success and
148       0 on failure. Check the error queue to find out the reason of failure.
149
150       SSL_CTX_need_tmp_rsa() and SSL_need_tmp_rsa() return 1 if a temporary
151       RSA key is needed and 0 otherwise.
152

SEE ALSO

154       ssl(3), SSL_CTX_set_cipher_list(3), SSL_CTX_set_options(3),
155       SSL_CTX_set_tmp_dh_callback(3), SSL_new(3), ciphers(1)
156
157
158
1591.0.2o                            2018-03-27   SSL_CTX_set_tmp_rsa_callback(3)
Impressum