SSL_CTX_set_tmp_rsa_callback.pod 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. =pod
  2. =head1 NAME
  3. 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
  4. =head1 SYNOPSIS
  5. #include <openssl/ssl.h>
  6. void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,
  7. RSA *(*tmp_rsa_callback)(SSL *ssl, int is_export, int keylength));
  8. long SSL_CTX_set_tmp_rsa(SSL_CTX *ctx, RSA *rsa);
  9. long SSL_CTX_need_tmp_rsa(SSL_CTX *ctx);
  10. void SSL_set_tmp_rsa_callback(SSL_CTX *ctx,
  11. RSA *(*tmp_rsa_callback)(SSL *ssl, int is_export, int keylength));
  12. long SSL_set_tmp_rsa(SSL *ssl, RSA *rsa)
  13. long SSL_need_tmp_rsa(SSL *ssl)
  14. RSA *(*tmp_rsa_callback)(SSL *ssl, int is_export, int keylength);
  15. =head1 DESCRIPTION
  16. SSL_CTX_set_tmp_rsa_callback() sets the callback function for B<ctx> to be
  17. used when a temporary/ephemeral RSA key is required to B<tmp_rsa_callback>.
  18. The callback is inherited by all SSL objects newly created from B<ctx>
  19. with <SSL_new(3)|SSL_new(3)>. Already created SSL objects are not affected.
  20. SSL_CTX_set_tmp_rsa() sets the temporary/ephemeral RSA key to be used to be
  21. B<rsa>. The key is inherited by all SSL objects newly created from B<ctx>
  22. with <SSL_new(3)|SSL_new(3)>. Already created SSL objects are not affected.
  23. SSL_CTX_need_tmp_rsa() returns 1, if a temporary/ephemeral RSA key is needed
  24. for RSA-based strength-limited 'exportable' ciphersuites because a RSA key
  25. with a keysize larger than 512 bits is installed.
  26. SSL_set_tmp_rsa_callback() sets the callback only for B<ssl>.
  27. SSL_set_tmp_rsa() sets the key only for B<ssl>.
  28. SSL_need_tmp_rsa() returns 1, if a temporary/ephemeral RSA key is needed,
  29. for RSA-based strength-limited 'exportable' ciphersuites because a RSA key
  30. with a keysize larger than 512 bits is installed.
  31. These functions apply to SSL/TLS servers only.
  32. =head1 NOTES
  33. When using a cipher with RSA authentication, an ephemeral RSA key exchange
  34. can take place. In this case the session data are negotiated using the
  35. ephemeral/temporary RSA key and the RSA key supplied and certified
  36. by the certificate chain is only used for signing.
  37. Under previous export restrictions, ciphers with RSA keys shorter (512 bits)
  38. than the usual key length of 1024 bits were created. To use these ciphers
  39. with RSA keys of usual length, an ephemeral key exchange must be performed,
  40. as the normal (certified) key cannot be directly used.
  41. Using ephemeral RSA key exchange yields forward secrecy, as the connection
  42. can only be decrypted, when the RSA key is known. By generating a temporary
  43. RSA key inside the server application that is lost when the application
  44. is left, it becomes impossible for an attacker to decrypt past sessions,
  45. even if he gets hold of the normal (certified) RSA key, as this key was
  46. used for signing only. The downside is that creating a RSA key is
  47. computationally expensive.
  48. Additionally, the use of ephemeral RSA key exchange is only allowed in
  49. the TLS standard, when the RSA key can be used for signing only, that is
  50. for export ciphers. Using ephemeral RSA key exchange for other purposes
  51. violates the standard and can break interoperability with clients.
  52. It is therefore strongly recommended to not use ephemeral RSA key
  53. exchange and use EDH (Ephemeral Diffie-Hellman) key exchange instead
  54. in order to achieve forward secrecy (see
  55. L<SSL_CTX_set_tmp_dh_callback(3)|SSL_CTX_set_tmp_dh_callback(3)>).
  56. An application may either directly specify the key or can supply the key via a
  57. callback function. The callback approach has the advantage, that the callback
  58. may generate the key only in case it is actually needed. As the generation of a
  59. RSA key is however costly, it will lead to a significant delay in the handshake
  60. procedure. Another advantage of the callback function is that it can supply
  61. keys of different size while the explicit setting of the key is only useful for
  62. key size of 512 bits to satisfy the export restricted ciphers and does give
  63. away key length if a longer key would be allowed.
  64. The B<tmp_rsa_callback> is called with the B<keylength> needed and
  65. the B<is_export> information. The B<is_export> flag is set, when the
  66. ephemeral RSA key exchange is performed with an export cipher.
  67. =head1 EXAMPLES
  68. Generate temporary RSA keys to prepare ephemeral RSA key exchange. As the
  69. generation of a RSA key costs a lot of computer time, they saved for later
  70. reuse. For demonstration purposes, two keys for 512 bits and 1024 bits
  71. respectively are generated.
  72. ...
  73. /* Set up ephemeral RSA stuff */
  74. RSA *rsa_512 = NULL;
  75. RSA *rsa_1024 = NULL;
  76. rsa_512 = RSA_generate_key(512,RSA_F4,NULL,NULL);
  77. if (rsa_512 == NULL)
  78. evaluate_error_queue();
  79. rsa_1024 = RSA_generate_key(1024,RSA_F4,NULL,NULL);
  80. if (rsa_1024 == NULL)
  81. evaluate_error_queue();
  82. ...
  83. RSA *tmp_rsa_callback(SSL *s, int is_export, int keylength)
  84. {
  85. RSA *rsa_tmp=NULL;
  86. switch (keylength) {
  87. case 512:
  88. if (rsa_512)
  89. rsa_tmp = rsa_512;
  90. else { /* generate on the fly, should not happen in this example */
  91. rsa_tmp = RSA_generate_key(keylength,RSA_F4,NULL,NULL);
  92. rsa_512 = rsa_tmp; /* Remember for later reuse */
  93. }
  94. break;
  95. case 1024:
  96. if (rsa_1024)
  97. rsa_tmp=rsa_1024;
  98. else
  99. should_not_happen_in_this_example();
  100. break;
  101. default:
  102. /* Generating a key on the fly is very costly, so use what is there */
  103. if (rsa_1024)
  104. rsa_tmp=rsa_1024;
  105. else
  106. rsa_tmp=rsa_512; /* Use at least a shorter key */
  107. }
  108. return(rsa_tmp);
  109. }
  110. =head1 RETURN VALUES
  111. SSL_CTX_set_tmp_rsa_callback() and SSL_set_tmp_rsa_callback() do not return
  112. diagnostic output.
  113. SSL_CTX_set_tmp_rsa() and SSL_set_tmp_rsa() do return 1 on success and 0
  114. on failure. Check the error queue to find out the reason of failure.
  115. SSL_CTX_need_tmp_rsa() and SSL_need_tmp_rsa() return 1 if a temporary
  116. RSA key is needed and 0 otherwise.
  117. =head1 SEE ALSO
  118. L<ssl(3)|ssl(3)>, L<SSL_CTX_set_cipher_list(3)|SSL_CTX_set_cipher_list(3)>,
  119. L<SSL_CTX_set_options(3)|SSL_CTX_set_options(3)>,
  120. L<SSL_CTX_set_tmp_dh_callback(3)|SSL_CTX_set_tmp_dh_callback(3)>,
  121. L<SSL_new(3)|SSL_new(3)>, L<ciphers(1)|ciphers(1)>
  122. =cut