diff options
Diffstat (limited to 'src/lib/libssl/doc/SSL_CTX_set_tmp_dh_callback.3')
| -rw-r--r-- | src/lib/libssl/doc/SSL_CTX_set_tmp_dh_callback.3 | 233 |
1 files changed, 233 insertions, 0 deletions
diff --git a/src/lib/libssl/doc/SSL_CTX_set_tmp_dh_callback.3 b/src/lib/libssl/doc/SSL_CTX_set_tmp_dh_callback.3 new file mode 100644 index 0000000000..f28d083f45 --- /dev/null +++ b/src/lib/libssl/doc/SSL_CTX_set_tmp_dh_callback.3 | |||
| @@ -0,0 +1,233 @@ | |||
| 1 | .Dd $Mdocdate: October 12 2014 $ | ||
| 2 | .Dt SSL_CTX_SET_TMP_DH_CALLBACK 3 | ||
| 3 | .Os | ||
| 4 | .Sh NAME | ||
| 5 | .Nm SSL_CTX_set_tmp_dh_callback , | ||
| 6 | .Nm SSL_CTX_set_tmp_dh , | ||
| 7 | .Nm SSL_set_tmp_dh_callback , | ||
| 8 | .Nm SSL_set_tmp_dh | ||
| 9 | .Nd handle DH keys for ephemeral key exchange | ||
| 10 | .Sh SYNOPSIS | ||
| 11 | .In openssl/ssl.h | ||
| 12 | .Ft void | ||
| 13 | .Fo SSL_CTX_set_tmp_dh_callback | ||
| 14 | .Fa "SSL_CTX *ctx" | ||
| 15 | .Fa "DH *(*tmp_dh_callback)(SSL *ssl, int is_export, int keylength)" | ||
| 16 | .Fc | ||
| 17 | .Ft long | ||
| 18 | .Fn SSL_CTX_set_tmp_dh "SSL_CTX *ctx" "DH *dh" | ||
| 19 | .Ft void | ||
| 20 | .Fo SSL_set_tmp_dh_callback | ||
| 21 | .Fa "SSL *ssl" | ||
| 22 | .Fa "DH *(*tmp_dh_callback)(SSL *ssl, int is_export, int keylength" | ||
| 23 | .Fc | ||
| 24 | .Ft long | ||
| 25 | .Fn SSL_set_tmp_dh "SSL *ssl" "DH *dh" | ||
| 26 | .Sh DESCRIPTION | ||
| 27 | .Fn SSL_CTX_set_tmp_dh_callback | ||
| 28 | sets the callback function for | ||
| 29 | .Fa ctx | ||
| 30 | to be used when a DH parameters are required to | ||
| 31 | .Fa tmp_dh_callback . | ||
| 32 | The callback is inherited by all | ||
| 33 | .Vt ssl | ||
| 34 | objects created from | ||
| 35 | .Fa ctx . | ||
| 36 | .Pp | ||
| 37 | .Fn SSL_CTX_set_tmp_dh | ||
| 38 | sets DH parameters to be used to be | ||
| 39 | .Sy dh Ns . | ||
| 40 | The key is inherited by all | ||
| 41 | .Fa ssl | ||
| 42 | objects created from | ||
| 43 | .Fa ctx . | ||
| 44 | .Pp | ||
| 45 | .Fn SSL_set_tmp_dh_callback | ||
| 46 | sets the callback only for | ||
| 47 | .Fa ssl . | ||
| 48 | .Pp | ||
| 49 | .Fn SSL_set_tmp_dh | ||
| 50 | sets the parameters only for | ||
| 51 | .Fa ssl . | ||
| 52 | .Pp | ||
| 53 | These functions apply to SSL/TLS servers only. | ||
| 54 | .Sh NOTES | ||
| 55 | When using a cipher with RSA authentication, | ||
| 56 | an ephemeral DH key exchange can take place. | ||
| 57 | Ciphers with DSA keys always use ephemeral DH keys as well. | ||
| 58 | In these cases, the session data are negotiated using the ephemeral/temporary | ||
| 59 | DH key and the key supplied and certified by the certificate chain is only used | ||
| 60 | for signing. | ||
| 61 | Anonymous ciphers (without a permanent server key) also use ephemeral DH keys. | ||
| 62 | .Pp | ||
| 63 | Using ephemeral DH key exchange yields forward secrecy, | ||
| 64 | as the connection can only be decrypted when the DH key is known. | ||
| 65 | By generating a temporary DH key inside the server application that is lost | ||
| 66 | when the application is left, it becomes impossible for an attacker to decrypt | ||
| 67 | past sessions, even if he gets hold of the normal (certified) key, | ||
| 68 | as this key was only used for signing. | ||
| 69 | .Pp | ||
| 70 | In order to perform a DH key exchange the server must use a DH group | ||
| 71 | (DH parameters) and generate a DH key. | ||
| 72 | The server will always generate a new DH key during the negotiation, | ||
| 73 | when the DH parameters are supplied via callback and/or when the | ||
| 74 | .Dv SSL_OP_SINGLE_DH_USE | ||
| 75 | option of | ||
| 76 | .Xr SSL_CTX_set_options 3 | ||
| 77 | is set. | ||
| 78 | It will immediately create a DH key, when DH parameters are supplied via | ||
| 79 | .Fn SSL_CTX_set_tmp_dh | ||
| 80 | and | ||
| 81 | .Dv SSL_OP_SINGLE_DH_USE | ||
| 82 | is not set. | ||
| 83 | In this case, it may happen that a key is generated on initialization without | ||
| 84 | later being needed, while on the other hand the computer time during the | ||
| 85 | negotiation is being saved. | ||
| 86 | .Pp | ||
| 87 | If | ||
| 88 | .Dq strong | ||
| 89 | primes were used to generate the DH parameters, it is not strictly necessary to | ||
| 90 | generate a new key for each handshake but it does improve forward secrecy. | ||
| 91 | If it is not assured that | ||
| 92 | .Dq strong | ||
| 93 | primes were used (see especially the section about DSA parameters below), | ||
| 94 | .Dv SSL_OP_SINGLE_DH_USE | ||
| 95 | must be used in order to prevent small subgroup attacks. | ||
| 96 | Always using | ||
| 97 | .Dv SSL_OP_SINGLE_DH_USE | ||
| 98 | has an impact on the computer time needed during negotiation, | ||
| 99 | but it is not very large, | ||
| 100 | so application authors/users should consider always enabling this option. | ||
| 101 | .Pp | ||
| 102 | As generating DH parameters is extremely time consuming, an application should | ||
| 103 | not generate the parameters on the fly but supply the parameters. | ||
| 104 | DH parameters can be reused, | ||
| 105 | as the actual key is newly generated during the negotiation. | ||
| 106 | The risk in reusing DH parameters is that an attacker may specialize on a very | ||
| 107 | often used DH group. | ||
| 108 | Applications should therefore generate their own DH parameters during the | ||
| 109 | installation process using the openssl | ||
| 110 | .Xr dhparam 1 | ||
| 111 | application. | ||
| 112 | In order to reduce the computer time needed for this generation, | ||
| 113 | it is possible to use DSA parameters instead (see | ||
| 114 | .Xr dhparam 1 ) , | ||
| 115 | but in this case | ||
| 116 | .Dv SSL_OP_SINGLE_DH_USE | ||
| 117 | is mandatory. | ||
| 118 | .Pp | ||
| 119 | Application authors may compile in DH parameters. | ||
| 120 | Files | ||
| 121 | .Pa dh512.pem , | ||
| 122 | .Pa dh1024.pem , | ||
| 123 | .Pa dh2048.pem , | ||
| 124 | and | ||
| 125 | .Pa dh4096.pem | ||
| 126 | in the | ||
| 127 | .Pa apps | ||
| 128 | directory of the current version of the OpenSSL distribution contain the | ||
| 129 | .Sq SKIP | ||
| 130 | DH parameters, | ||
| 131 | which use safe primes and were generated verifiably pseudo-randomly. | ||
| 132 | These files can be converted into C code using the | ||
| 133 | .Fl C | ||
| 134 | option of the | ||
| 135 | .Xr dhparam 1 | ||
| 136 | application. | ||
| 137 | Authors may also generate their own set of parameters using | ||
| 138 | .Xr dhparam 1 , | ||
| 139 | but a user may not be sure how the parameters were generated. | ||
| 140 | The generation of DH parameters during installation is therefore recommended. | ||
| 141 | .Pp | ||
| 142 | An application may either directly specify the DH parameters or can supply the | ||
| 143 | DH parameters via a callback function. | ||
| 144 | The callback approach has the advantage that the callback may supply DH | ||
| 145 | parameters for different key lengths. | ||
| 146 | .Pp | ||
| 147 | The | ||
| 148 | .Fa tmp_dh_callback | ||
| 149 | is called with the | ||
| 150 | .Fa keylength | ||
| 151 | needed and the | ||
| 152 | .Fa is_export | ||
| 153 | information. | ||
| 154 | The | ||
| 155 | .Fa is_export | ||
| 156 | flag is set when the ephemeral DH key exchange is performed with an export | ||
| 157 | cipher. | ||
| 158 | .Sh RETURN VALUES | ||
| 159 | .Fn SSL_CTX_set_tmp_dh_callback | ||
| 160 | and | ||
| 161 | .Fn SSL_set_tmp_dh_callback | ||
| 162 | do not return diagnostic output. | ||
| 163 | .Pp | ||
| 164 | .Fn SSL_CTX_set_tmp_dh | ||
| 165 | and | ||
| 166 | .Fn SSL_set_tmp_dh | ||
| 167 | do return 1 on success and 0 on failure. | ||
| 168 | Check the error queue to find out the reason of failure. | ||
| 169 | .Sh EXAMPLES | ||
| 170 | Handle DH parameters for key lengths of 512 and 1024 bits. | ||
| 171 | (Error handling partly left out.) | ||
| 172 | .Bd -literal | ||
| 173 | \&... | ||
| 174 | /* Set up ephemeral DH stuff */ | ||
| 175 | DH *dh_512 = NULL; | ||
| 176 | DH *dh_1024 = NULL; | ||
| 177 | FILE *paramfile; | ||
| 178 | |||
| 179 | \&... | ||
| 180 | |||
| 181 | /* "openssl dhparam -out dh_param_512.pem -2 512" */ | ||
| 182 | paramfile = fopen("dh_param_512.pem", "r"); | ||
| 183 | if (paramfile) { | ||
| 184 | dh_512 = PEM_read_DHparams(paramfile, NULL, NULL, NULL); | ||
| 185 | fclose(paramfile); | ||
| 186 | } | ||
| 187 | /* "openssl dhparam -out dh_param_1024.pem -2 1024" */ | ||
| 188 | paramfile = fopen("dh_param_1024.pem", "r"); | ||
| 189 | if (paramfile) { | ||
| 190 | dh_1024 = PEM_read_DHparams(paramfile, NULL, NULL, NULL); | ||
| 191 | fclose(paramfile); | ||
| 192 | } | ||
| 193 | |||
| 194 | \&... | ||
| 195 | |||
| 196 | /* "openssl dhparam -C -2 512" etc... */ | ||
| 197 | DH *get_dh512() { ... } | ||
| 198 | DH *get_dh1024() { ... } | ||
| 199 | |||
| 200 | DH * | ||
| 201 | tmp_dh_callback(SSL *s, int is_export, int keylength) | ||
| 202 | { | ||
| 203 | DH *dh_tmp=NULL; | ||
| 204 | |||
| 205 | switch (keylength) { | ||
| 206 | case 512: | ||
| 207 | if (!dh_512) | ||
| 208 | dh_512 = get_dh512(); | ||
| 209 | dh_tmp = dh_512; | ||
| 210 | break; | ||
| 211 | case 1024: | ||
| 212 | if (!dh_1024) | ||
| 213 | dh_1024 = get_dh1024(); | ||
| 214 | dh_tmp = dh_1024; | ||
| 215 | break; | ||
| 216 | default: | ||
| 217 | /* | ||
| 218 | * Generating a key on the fly is very costly, | ||
| 219 | * so use what is there | ||
| 220 | */ | ||
| 221 | setup_dh_parameters_like_above(); | ||
| 222 | } | ||
| 223 | |||
| 224 | return(dh_tmp); | ||
| 225 | } | ||
| 226 | .Ed | ||
| 227 | .Sh SEE ALSO | ||
| 228 | .Xr ciphers 1 , | ||
| 229 | .Xr dhparam 1 , | ||
| 230 | .Xr ssl 3 , | ||
| 231 | .Xr SSL_CTX_set_cipher_list 3 , | ||
| 232 | .Xr SSL_CTX_set_options 3 , | ||
| 233 | .Xr SSL_CTX_set_tmp_rsa_callback 3 | ||
