SSL_CTX_set_tmp_rsa_callback.pod 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. On OpenSSL servers ephemeral RSA key exchange is therefore disabled by default
  57. and must be explicitly enabled using the SSL_OP_EPHEMERAL_RSA option of
  58. L<SSL_CTX_set_options(3)|SSL_CTX_set_options(3)>, violating the TLS/SSL
  59. standard. When ephemeral RSA key exchange is required for export ciphers,
  60. it will automatically be used without this option!
  61. An application may either directly specify the key or can supply the key via
  62. a callback function. The callback approach has the advantage, that the
  63. callback may generate the key only in case it is actually needed. As the
  64. generation of a RSA key is however costly, it will lead to a significant
  65. delay in the handshake procedure. Another advantage of the callback function
  66. is that it can supply keys of different size (e.g. for SSL_OP_EPHEMERAL_RSA
  67. usage) while the explicit setting of the key is only useful for key size of
  68. 512 bits to satisfy the export restricted ciphers and does give away key length
  69. if a longer key would be allowed.
  70. The B<tmp_rsa_callback> is called with the B<keylength> needed and
  71. the B<is_export> information. The B<is_export> flag is set, when the
  72. ephemeral RSA key exchange is performed with an export cipher.
  73. =head1 EXAMPLES
  74. Generate temporary RSA keys to prepare ephemeral RSA key exchange. As the
  75. generation of a RSA key costs a lot of computer time, they saved for later
  76. reuse. For demonstration purposes, two keys for 512 bits and 1024 bits
  77. respectively are generated.
  78. ...
  79. /* Set up ephemeral RSA stuff */
  80. RSA *rsa_512 = NULL;
  81. RSA *rsa_1024 = NULL;
  82. rsa_512 = RSA_generate_key(512,RSA_F4,NULL,NULL);
  83. if (rsa_512 == NULL)
  84. evaluate_error_queue();
  85. rsa_1024 = RSA_generate_key(1024,RSA_F4,NULL,NULL);
  86. if (rsa_1024 == NULL)
  87. evaluate_error_queue();
  88. ...
  89. RSA *tmp_rsa_callback(SSL *s, int is_export, int keylength)
  90. {
  91. RSA *rsa_tmp=NULL;
  92. switch (keylength) {
  93. case 512:
  94. if (rsa_512)
  95. rsa_tmp = rsa_512;
  96. else { /* generate on the fly, should not happen in this example */
  97. rsa_tmp = RSA_generate_key(keylength,RSA_F4,NULL,NULL);
  98. rsa_512 = rsa_tmp; /* Remember for later reuse */
  99. }
  100. break;
  101. case 1024:
  102. if (rsa_1024)
  103. rsa_tmp=rsa_1024;
  104. else
  105. should_not_happen_in_this_example();
  106. break;
  107. default:
  108. /* Generating a key on the fly is very costly, so use what is there */
  109. if (rsa_1024)
  110. rsa_tmp=rsa_1024;
  111. else
  112. rsa_tmp=rsa_512; /* Use at least a shorter key */
  113. }
  114. return(rsa_tmp);
  115. }
  116. =head1 RETURN VALUES
  117. SSL_CTX_set_tmp_rsa_callback() and SSL_set_tmp_rsa_callback() do not return
  118. diagnostic output.
  119. SSL_CTX_set_tmp_rsa() and SSL_set_tmp_rsa() do return 1 on success and 0
  120. on failure. Check the error queue to find out the reason of failure.
  121. SSL_CTX_need_tmp_rsa() and SSL_need_tmp_rsa() return 1 if a temporary
  122. RSA key is needed and 0 otherwise.
  123. =head1 SEE ALSO
  124. L<ssl(3)|ssl(3)>, L<SSL_CTX_set_cipher_list(3)|SSL_CTX_set_cipher_list(3)>,
  125. L<SSL_CTX_set_options(3)|SSL_CTX_set_options(3)>,
  126. L<SSL_CTX_set_tmp_dh_callback(3)|SSL_CTX_set_tmp_dh_callback(3)>,
  127. L<SSL_new(3)|SSL_new(3)>, L<ciphers(1)|ciphers(1)>
  128. =cut