HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: //usr/local/openssl/man/man3/SSL_set_tmp_rsa_callback.3
.\" -*- mode: troff; coding: utf-8 -*-
.\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
.ie n \{\
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds C`
.    ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
.    if \nF \{\
.        de IX
.        tm Index:\\$1\t\\n%\t"\\$2"
..
.        if !\nF==2 \{\
.            nr % 0
.            nr F 2
.        \}
.    \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "SSL_CTX_set_tmp_rsa_callback 3"
.TH SSL_CTX_set_tmp_rsa_callback 3 2019-12-20 1.0.2u OpenSSL
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH NAME
SSL_CTX_set_tmp_rsa_callback, SSL_CTX_set_tmp_rsa, SSL_CTX_need_tmp_rsa, SSL_set_tmp_rsa_callback, SSL_set_tmp_rsa, SSL_need_tmp_rsa \- handle RSA keys for ephemeral key exchange
.SH SYNOPSIS
.IX Header "SYNOPSIS"
.Vb 1
\& #include <openssl/ssl.h>
\&
\& void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,
\&            RSA *(*tmp_rsa_callback)(SSL *ssl, int is_export, int keylength));
\& long SSL_CTX_set_tmp_rsa(SSL_CTX *ctx, RSA *rsa);
\& long SSL_CTX_need_tmp_rsa(SSL_CTX *ctx);
\&
\& void SSL_set_tmp_rsa_callback(SSL_CTX *ctx,
\&            RSA *(*tmp_rsa_callback)(SSL *ssl, int is_export, int keylength));
\& long SSL_set_tmp_rsa(SSL *ssl, RSA *rsa)
\& long SSL_need_tmp_rsa(SSL *ssl)
\&
\& RSA *(*tmp_rsa_callback)(SSL *ssl, int is_export, int keylength);
.Ve
.SH DESCRIPTION
.IX Header "DESCRIPTION"
\&\fBSSL_CTX_set_tmp_rsa_callback()\fR sets the callback function for \fBctx\fR to be
used when a temporary/ephemeral RSA key is required to \fBtmp_rsa_callback\fR.
The callback is inherited by all SSL objects newly created from \fBctx\fR
with <\fBSSL_new\fR\|(3)|\fBSSL_new\fR\|(3)>. Already created SSL objects are not affected.
.PP
\&\fBSSL_CTX_set_tmp_rsa()\fR sets the temporary/ephemeral RSA key to be used to be
\&\fBrsa\fR. The key is inherited by all SSL objects newly created from \fBctx\fR
with <\fBSSL_new\fR\|(3)|\fBSSL_new\fR\|(3)>. Already created SSL objects are not affected.
.PP
\&\fBSSL_CTX_need_tmp_rsa()\fR returns 1, if a temporary/ephemeral RSA key is needed
for RSA-based strength-limited 'exportable' ciphersuites because a RSA key
with a keysize larger than 512 bits is installed.
.PP
\&\fBSSL_set_tmp_rsa_callback()\fR sets the callback only for \fBssl\fR.
.PP
\&\fBSSL_set_tmp_rsa()\fR sets the key only for \fBssl\fR.
.PP
\&\fBSSL_need_tmp_rsa()\fR returns 1, if a temporary/ephemeral RSA key is needed,
for RSA-based strength-limited 'exportable' ciphersuites because a RSA key
with a keysize larger than 512 bits is installed.
.PP
These functions apply to SSL/TLS servers only.
.SH NOTES
.IX Header "NOTES"
When using a cipher with RSA authentication, an ephemeral RSA key exchange
can take place. In this case the session data are negotiated using the
ephemeral/temporary RSA key and the RSA key supplied and certified
by the certificate chain is only used for signing.
.PP
Under previous export restrictions, ciphers with RSA keys shorter (512 bits)
than the usual key length of 1024 bits were created. To use these ciphers
with RSA keys of usual length, an ephemeral key exchange must be performed,
as the normal (certified) key cannot be directly used.
.PP
Using ephemeral RSA key exchange yields forward secrecy, as the connection
can only be decrypted, when the RSA key is known. By generating a temporary
RSA key inside the server application that is lost when the application
is left, it becomes impossible for an attacker to decrypt past sessions,
even if he gets hold of the normal (certified) RSA key, as this key was
used for signing only. The downside is that creating a RSA key is
computationally expensive.
.PP
Additionally, the use of ephemeral RSA key exchange is only allowed in
the TLS standard, when the RSA key can be used for signing only, that is
for export ciphers. Using ephemeral RSA key exchange for other purposes
violates the standard and can break interoperability with clients.
It is therefore strongly recommended to not use ephemeral RSA key
exchange and use DHE (Ephemeral Diffie-Hellman) key exchange instead
in order to achieve forward secrecy (see
\&\fBSSL_CTX_set_tmp_dh_callback\fR\|(3)).
.PP
An application may either directly specify the key or can supply the key via a
callback function. The callback approach has the advantage, that the callback
may generate the key only in case it is actually needed. As the generation of a
RSA key is however costly, it will lead to a significant delay in the handshake
procedure.  Another advantage of the callback function is that it can supply
keys of different size while the explicit setting of the key is only useful for
key size of 512 bits to satisfy the export restricted ciphers and does give
away key length if a longer key would be allowed.
.PP
The \fBtmp_rsa_callback\fR is called with the \fBkeylength\fR needed and
the \fBis_export\fR information. The \fBis_export\fR flag is set, when the
ephemeral RSA key exchange is performed with an export cipher.
.SH EXAMPLES
.IX Header "EXAMPLES"
Generate temporary RSA keys to prepare ephemeral RSA key exchange. As the
generation of a RSA key costs a lot of computer time, they saved for later
reuse. For demonstration purposes, two keys for 512 bits and 1024 bits
respectively are generated.
.PP
.Vb 4
\& ...
\& /* Set up ephemeral RSA stuff */
\& RSA *rsa_512 = NULL;
\& RSA *rsa_1024 = NULL;
\&
\& rsa_512 = RSA_generate_key(512,RSA_F4,NULL,NULL);
\& if (rsa_512 == NULL)
\&     evaluate_error_queue();
\&
\& rsa_1024 = RSA_generate_key(1024,RSA_F4,NULL,NULL);
\& if (rsa_1024 == NULL)
\&   evaluate_error_queue();
\&
\& ...
\&
\& RSA *tmp_rsa_callback(SSL *s, int is_export, int keylength)
\& {
\&    RSA *rsa_tmp=NULL;
\&
\&    switch (keylength) {
\&    case 512:
\&      if (rsa_512)
\&        rsa_tmp = rsa_512;
\&      else { /* generate on the fly, should not happen in this example */
\&        rsa_tmp = RSA_generate_key(keylength,RSA_F4,NULL,NULL);
\&        rsa_512 = rsa_tmp; /* Remember for later reuse */
\&      }
\&      break;
\&    case 1024:
\&      if (rsa_1024)
\&        rsa_tmp=rsa_1024;
\&      else
\&        should_not_happen_in_this_example();
\&      break;
\&    default:
\&      /* Generating a key on the fly is very costly, so use what is there */
\&      if (rsa_1024)
\&        rsa_tmp=rsa_1024;
\&      else
\&        rsa_tmp=rsa_512; /* Use at least a shorter key */
\&    }
\&    return(rsa_tmp);
\& }
.Ve
.SH "RETURN VALUES"
.IX Header "RETURN VALUES"
\&\fBSSL_CTX_set_tmp_rsa_callback()\fR and \fBSSL_set_tmp_rsa_callback()\fR do not return
diagnostic output.
.PP
\&\fBSSL_CTX_set_tmp_rsa()\fR and \fBSSL_set_tmp_rsa()\fR do return 1 on success and 0
on failure. Check the error queue to find out the reason of failure.
.PP
\&\fBSSL_CTX_need_tmp_rsa()\fR and \fBSSL_need_tmp_rsa()\fR return 1 if a temporary
RSA key is needed and 0 otherwise.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
\&\fBssl\fR\|(3), \fBSSL_CTX_set_cipher_list\fR\|(3),
\&\fBSSL_CTX_set_options\fR\|(3),
\&\fBSSL_CTX_set_tmp_dh_callback\fR\|(3),
\&\fBSSL_new\fR\|(3), \fBciphers\fR\|(1)