blob: 3db5a26b11acf67d99764177151a5f6c512a7e3a [file] [log] [blame]
Nick Mathewson858618e2015-05-25 17:12:49 -04001=pod
2
3=head1 NAME
4
5SSL_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 Caswelld9f1c632015-05-28 16:36:51 +010011 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 Mathewson858618e2015-05-25 17:12:49 -040014
15=head1 DESCRIPTION
16
17SSL_get_client_random() extracts the random value sent from the client
Nick Mathewson7470cef2015-05-26 09:55:06 -040018to the server during the initial SSL/TLS handshake. It copies as many
19bytes as it can of this value into the buffer provided in B<out>,
20which must have at least B<outlen> bytes available. It returns the
Matt Caswelld9f1c632015-05-28 16:36:51 +010021total number of bytes that were actually copied. If B<outlen> is
22zero, SSL_get_client_random() copies nothing, and returns the
Nick Mathewson7470cef2015-05-26 09:55:06 -040023total size of the client_random value.
Nick Mathewson858618e2015-05-25 17:12:49 -040024
25SSL_get_server_random() behaves the same, but extracts the random value
26sent from the server to the client during the initial SSL/TLS handshake.
27
28SSL_SESSION_get_master_key() behaves the same, but extracts the master
29secret used to guarantee the security of the SSL/TLS session. This one
30can be dangerous if misused; see NOTES below.
31
32
33=head1 NOTES
34
35You probably shouldn't use these functions.
36
37These functions expose internal values from the TLS handshake, for
38use in low-level protocols. You probably should not use them, unless
39you are implementing something that needs access to the internal protocol
40details.
41
42Despite the names of SSL_get_client_random() and SSL_get_server_random(), they
43ARE NOT random number generators. Instead, they return the mostly-random values that
44were already generated and used in the TLS protoccol. Using them
45in place of RAND_bytes() would be grossly foolish.
46
47The security of your TLS session depends on keeping the master key secret:
48do not expose it, or any information about it, to anybody.
49If you need to calculate another secret value that depends on the master
50secret, you should probably use SSL_export_keying_material() instead, and
51forget that you ever saw these functions.
52
Nick Mathewson7470cef2015-05-26 09:55:06 -040053In current versions of the TLS protocols, the length of client_random
54(and also server_random) is always SSL3_RANDOM_SIZE bytes. Support for
55other outlen arguments to the SSL_get_*_random() functions is provided
56in case of the unlikely event that a future version or variant of TLS
57uses some other length there.
58
Nick Mathewson858618e2015-05-25 17:12:49 -040059Finally, though the "client_random" and "server_random" values are called
60"random", many TLS implementations will generate four bytes of those
61values based on their view of the current time.
62
63
64=head1 RETURN VALUES
65
Matt Caswelld9f1c632015-05-28 16:36:51 +010066If B<outlen> is greater than 0, these functions return the number of bytes
Nick Mathewson858618e2015-05-25 17:12:49 -040067actually copied, which will be less than or equal to B<outlen>.
68
Matt Caswelld9f1c632015-05-28 16:36:51 +010069If B<outlen> is 0, these functions return the maximum number
Nick Mathewson858618e2015-05-25 17:12:49 -040070of bytes they would copy--that is, the length of the underlying field.
71
72=head1 SEE ALSO
73
Rich Salz9b869742015-08-17 15:21:33 -040074L<ssl(3)>,
75L<RAND_bytes(3)>,
76L<SSL_export_keying_material(3)>
Nick Mathewson858618e2015-05-25 17:12:49 -040077
78
79=cut