SSL_GET_CLIENT_RANDOM(3ossl)

✨ SSL_GET_CLIENT_RANDOM ✨ (the 3ossl manual, bestie)

okay so bestie, we're in the OpenSSL docs today and this one is like... a whole vibe. it's giving "here are the internal secrets of the TLS handshake, please be normal about them." spoiler: the page itself says don't. πŸ’…


🌸 NAME 🌸

SSL_get_client_random, SSL_get_server_random, SSL_SESSION_get_master_key, SSL_SESSION_set1_master_key β€” get internal TLS/SSL random values and get/set master key


πŸŽ€ SYNOPSIS πŸŽ€

#include <openssl/ssl.h>

size_t SSL_get_client_random(const SSL *ssl, unsigned char *out, size_t outlen);
size_t SSL_get_server_random(const SSL *ssl, unsigned char *out, size_t outlen);
size_t SSL_SESSION_get_master_key(const SSL_SESSION *session,
                                  unsigned char *out, size_t outlen);
int SSL_SESSION_set1_master_key(SSL_SESSION *sess, const unsigned char *in,
                                size_t len);

πŸ¦‹ DESCRIPTION πŸ¦‹

so. SSL_get_client_random() extracts the random value that the client sent over to the server during the initial SSL/TLS handshake. it copies as many bytes as it can of that value into the buffer you passed in out, which β€” heads up β€” needs at least outlen bytes available. it returns the total number of bytes that were actually copied. and if outlen is zero, SSL_get_client_random() copies nothing and just returns the total size of the client_random value. slay, no cap.

SSL_get_server_random() behaves the same way, but it extracts the random value sent from the server to the client during the initial SSL/TLS handshake. same energy, different direction.

SSL_SESSION_get_master_key() also behaves the same, but it extracts the master secret used to guarantee the security of the SSL/TLS session. ⚠️ and this one can be dangerous if you misuse it β€” see NOTES below, bestie, i'm not kidding.

SSL_SESSION_set1_master_key() sets the master key value associated with the SSL_SESSION sess. for example, this could be used to set up a session based PSK (peep SSL_CTX_set_psk_use_session_callback(3)). the master key of length len should be provided at in. the supplied master key is copied by the function, so the caller is responsible for freeing and cleaning any memory associated with in. and the caller must ensure that the length of the key is suitable for the ciphersuite associated with the SSL_SESSION. πŸ‘‘


πŸ’€ NOTES πŸ’€

you probably shouldn't use these functions.

fr fr. putting that front and center because it's the whole point.

these functions expose internal values from the TLS handshake, for use in low-level protocols. you probably should not use them, unless you are implementing something that needs access to the internal protocol details.

and now the part where i need you to lock in. despite the names of SSL_get_client_random() and SSL_get_server_random(), they ARE NOT random number generators. not even a little. instead, they return the mostly-random values that were already generated and used in the TLS protocol. using them in place of RAND_bytes() would be grossly foolish. like, don't. i'm begging. πŸ™ˆ

the security of your TLS session depends on keeping the master key secret: do not expose it, or any information about it, to anybody. if you need to calculate another secret value that depends on the master secret, you should probably use SSL_export_keying_material() instead, and forget that you ever saw these functions. (iconic line, honestly.)

in current versions of the TLS protocols, the length of client_random (and also server_random) is always SSL3_RANDOM_SIZE bytes. support for other outlen arguments to the SSL_get_*_random() functions is provided in case of the unlikely event that a future version or variant of TLS uses some other length there. so like, future-proofing, but don't hold your breath. πŸ’…

finally β€” and this is my favorite lil fun fact β€” even though the "client_random" and "server_random" values are called "random", many TLS implementations will generate four bytes of those values based on their view of the current time. so it's giving random but make it clock-coded. ⏰


🌈 RETURN VALUES 🌈

SSL_SESSION_set1_master_key() returns 1 on success or 0 on failure.

for the other functions: if outlen is greater than 0 then these functions return the number of bytes actually copied, which will be less than or equal to outlen. if outlen is 0 then these functions return the maximum number of bytes they would copy β€” that is, the length of the underlying field. cute lil "how big is it really" mode. 🫢


πŸ”₯ SEE ALSO πŸ”₯


Copyright 2015-2017 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


and that's the page, bestie!! this one's from version 3.5.9, dated 2026-09-29, and it lives under the SSL_GET_CLIENT_RANDOM(3ossl) name. now go forth and please not use these functions unless you truly have to. mwah. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from