Nick Mathewson | 858618e | 2015-05-25 17:12:49 -0400 | [diff] [blame] | 1 | =pod |
| 2 | |
| 3 | =head1 NAME |
| 4 | |
| 5 | SSL_get_client_random, SSL_get_server_random, SSL_SESSION_get_master_key - retrieve internal TLS/SSL random values and master key |
| 6 | |
| 7 | =head1 SYNOPSIS |
| 8 | |
| 9 | #include <openssl/ssl.h> |
| 10 | |
Matt Caswell | d9f1c63 | 2015-05-28 16:36:51 +0100 | [diff] [blame] | 11 | size_t SSL_get_client_random(const SSL *ssl, unsigned char *out, size_t outlen); |
| 12 | size_t SSL_get_server_random(const SSL *ssl, unsigned char *out, size_t outlen); |
| 13 | size_t SSL_SESSION_get_master_key(const SSL_SESSION *session, unsigned char *out, size_t outlen); |
Nick Mathewson | 858618e | 2015-05-25 17:12:49 -0400 | [diff] [blame] | 14 | |
| 15 | =head1 DESCRIPTION |
| 16 | |
| 17 | SSL_get_client_random() extracts the random value sent from the client |
Nick Mathewson | 7470cef | 2015-05-26 09:55:06 -0400 | [diff] [blame] | 18 | to the server during the initial SSL/TLS handshake. It copies as many |
| 19 | bytes as it can of this value into the buffer provided in B<out>, |
| 20 | which must have at least B<outlen> bytes available. It returns the |
Matt Caswell | d9f1c63 | 2015-05-28 16:36:51 +0100 | [diff] [blame] | 21 | total number of bytes that were actually copied. If B<outlen> is |
| 22 | zero, SSL_get_client_random() copies nothing, and returns the |
Nick Mathewson | 7470cef | 2015-05-26 09:55:06 -0400 | [diff] [blame] | 23 | total size of the client_random value. |
Nick Mathewson | 858618e | 2015-05-25 17:12:49 -0400 | [diff] [blame] | 24 | |
| 25 | SSL_get_server_random() behaves the same, but extracts the random value |
| 26 | sent from the server to the client during the initial SSL/TLS handshake. |
| 27 | |
| 28 | SSL_SESSION_get_master_key() behaves the same, but extracts the master |
| 29 | secret used to guarantee the security of the SSL/TLS session. This one |
| 30 | can be dangerous if misused; see NOTES below. |
| 31 | |
| 32 | |
| 33 | =head1 NOTES |
| 34 | |
| 35 | You probably shouldn't use these functions. |
| 36 | |
| 37 | These functions expose internal values from the TLS handshake, for |
| 38 | use in low-level protocols. You probably should not use them, unless |
| 39 | you are implementing something that needs access to the internal protocol |
| 40 | details. |
| 41 | |
| 42 | Despite the names of SSL_get_client_random() and SSL_get_server_random(), they |
| 43 | ARE NOT random number generators. Instead, they return the mostly-random values that |
| 44 | were already generated and used in the TLS protoccol. Using them |
| 45 | in place of RAND_bytes() would be grossly foolish. |
| 46 | |
| 47 | The security of your TLS session depends on keeping the master key secret: |
| 48 | do not expose it, or any information about it, to anybody. |
| 49 | If you need to calculate another secret value that depends on the master |
| 50 | secret, you should probably use SSL_export_keying_material() instead, and |
| 51 | forget that you ever saw these functions. |
| 52 | |
Nick Mathewson | 7470cef | 2015-05-26 09:55:06 -0400 | [diff] [blame] | 53 | In current versions of the TLS protocols, the length of client_random |
| 54 | (and also server_random) is always SSL3_RANDOM_SIZE bytes. Support for |
| 55 | other outlen arguments to the SSL_get_*_random() functions is provided |
| 56 | in case of the unlikely event that a future version or variant of TLS |
| 57 | uses some other length there. |
| 58 | |
Nick Mathewson | 858618e | 2015-05-25 17:12:49 -0400 | [diff] [blame] | 59 | Finally, though the "client_random" and "server_random" values are called |
| 60 | "random", many TLS implementations will generate four bytes of those |
| 61 | values based on their view of the current time. |
| 62 | |
| 63 | |
| 64 | =head1 RETURN VALUES |
| 65 | |
Matt Caswell | d9f1c63 | 2015-05-28 16:36:51 +0100 | [diff] [blame] | 66 | If B<outlen> is greater than 0, these functions return the number of bytes |
Nick Mathewson | 858618e | 2015-05-25 17:12:49 -0400 | [diff] [blame] | 67 | actually copied, which will be less than or equal to B<outlen>. |
| 68 | |
Matt Caswell | d9f1c63 | 2015-05-28 16:36:51 +0100 | [diff] [blame] | 69 | If B<outlen> is 0, these functions return the maximum number |
Nick Mathewson | 858618e | 2015-05-25 17:12:49 -0400 | [diff] [blame] | 70 | of bytes they would copy--that is, the length of the underlying field. |
| 71 | |
| 72 | =head1 SEE ALSO |
| 73 | |
Rich Salz | 9b86974 | 2015-08-17 15:21:33 -0400 | [diff] [blame] | 74 | L<ssl(3)>, |
| 75 | L<RAND_bytes(3)>, |
| 76 | L<SSL_export_keying_material(3)> |
Nick Mathewson | 858618e | 2015-05-25 17:12:49 -0400 | [diff] [blame] | 77 | |
| 78 | |
| 79 | =cut |