namespace folly {
namespace ssl {
+bool OpenSSLUtils::getTLSMasterKey(
+ const SSL_SESSION* session,
+ MutableByteRange keyOut) {
+#if OPENSSL_IS_101 || OPENSSL_IS_102
+ if (session &&
+ session->master_key_length == static_cast<int>(keyOut.size())) {
+ auto masterKey = session->master_key;
+ std::copy(
+ masterKey, masterKey + session->master_key_length, keyOut.begin());
+ return true;
+ }
+#endif
+ return false;
+}
+
+bool OpenSSLUtils::getTLSClientRandom(
+ const SSL* ssl,
+ MutableByteRange randomOut) {
+#if OPENSSL_IS_101 || OPENSSL_IS_102
+ if ((SSL_version(ssl) >> 8) == TLS1_VERSION_MAJOR && ssl->s3 &&
+ randomOut.size() == SSL3_RANDOM_SIZE) {
+ auto clientRandom = ssl->s3->client_random;
+ std::copy(clientRandom, clientRandom + SSL3_RANDOM_SIZE, randomOut.begin());
+ return true;
+ }
+#endif
+ return false;
+}
+
bool OpenSSLUtils::getPeerAddressFromX509StoreCtx(X509_STORE_CTX* ctx,
sockaddr_storage* addrStorage,
socklen_t* addrLen) {
*/
#pragma once
+#include <folly/Range.h>
#include <folly/portability/Sockets.h>
+#include <openssl/ssl.h>
#include <openssl/x509v3.h>
namespace folly {
class OpenSSLUtils {
public:
+ /*
+ * Get the TLS Session Master Key used to generate the TLS key material
+ *
+ * @param session ssl session
+ * @param keyOut destination for the master key, the buffer must be at least
+ * 48 bytes
+ * @return true if the master key is available (>= TLS1) and the output buffer
+ * large enough
+ */
+ static bool getTLSMasterKey(
+ const SSL_SESSION* session,
+ MutableByteRange keyOut);
+
+ /*
+ * Get the TLS Client Random used to generate the TLS key material
+ *
+ * @param ssl
+ * @param randomOut destination for the client random, the buffer must be at
+ * least 32 bytes
+ * @return true if the client random is available (>= TLS1) and the output
+ * buffer large enough
+ */
+ static bool getTLSClientRandom(const SSL* ssl, MutableByteRange randomOut);
+
/**
* Validate that the peer certificate's common name or subject alt names
* match what we expect. Currently this only checks for IPs within