ssl_key_logging.h
Go to the documentation of this file.
1 // Copyright 2021 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GRPC_CORE_TSI_SSL_KEY_LOGGING_SSL_KEY_LOGGING_H
16 #define GRPC_CORE_TSI_SSL_KEY_LOGGING_SSL_KEY_LOGGING_H
17 
19 
20 #include <iostream>
21 #include <map>
22 
23 #include <openssl/ssl.h>
24 
25 #include "absl/base/thread_annotations.h"
26 
27 #include <grpc/grpc_security.h>
28 #include <grpc/slice.h>
29 #include <grpc/support/sync.h>
30 
34 
35 namespace tsi {
36 
38  : public grpc_core::RefCounted<TlsSessionKeyLoggerCache> {
39  public:
41  ~TlsSessionKeyLoggerCache() override;
42 
43  // A helper class which facilitates appending Tls session keys into a file.
44  // The instance is bound to a file meaning only one instance of this object
45  // can ever exist for a given file path.
47  : public grpc_core::RefCounted<TlsSessionKeyLogger> {
48  public:
49  // Instantiates a TlsSessionKeyLogger instance bound to a specific path.
51  std::string tls_session_key_log_file_path,
53  ~TlsSessionKeyLogger() override;
54 
55  // Not copyable nor assignable.
58  // Writes session keys into the file in the NSS key logging format.
59  // This is called upon completion of a handshake. The associated ssl_context
60  // is also provided here to support future extensions such as logging
61  // keys only when connections are made by certain IPs etc.
62  void LogSessionKeys(SSL_CTX* ssl_context,
63  const std::string& session_keys_info);
64 
65  private:
66  grpc_core::Mutex lock_; // protects appends to file
70  };
71  // Creates and returns a TlsSessionKeyLogger instance.
73  std::string tls_session_key_log_file_path);
74 
75  private:
76  std::map<std::string, TlsSessionKeyLogger*> tls_session_key_logger_map_;
77 };
78 
79 } // namespace tsi
80 
81 #endif // GRPC_CORE_TSI_SSL_KEY_LOGGING_SSL_KEY_LOGGING_H
tsi::TlsSessionKeyLoggerCache::TlsSessionKeyLogger::ABSL_GUARDED_BY
FILE *fd_ ABSL_GUARDED_BY(lock_)
tsi::TlsSessionKeyLoggerCache
Definition: ssl_key_logging.h:37
slice.h
tsi::TlsSessionKeyLoggerCache::~TlsSessionKeyLoggerCache
~TlsSessionKeyLoggerCache() override
Definition: ssl_key_logging.cc:104
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc_security.h
ssl_ctx_st
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3404
tsi::TlsSessionKeyLoggerCache::TlsSessionKeyLogger::cache_
grpc_core::RefCountedPtr< TlsSessionKeyLoggerCache > cache_
Definition: ssl_key_logging.h:69
memory.h
grpc_core::RefCountedPtr
Definition: ref_counted_ptr.h:35
tsi::TlsSessionKeyLoggerCache::TlsSessionKeyLogger::TlsSessionKeyLogger
TlsSessionKeyLogger(std::string tls_session_key_log_file_path, grpc_core::RefCountedPtr< TlsSessionKeyLoggerCache > cache)
Definition: ssl_key_logging.cc:45
tsi::TlsSessionKeyLoggerCache::TlsSessionKeyLogger::operator=
TlsSessionKeyLogger & operator=(const TlsSessionKeyLogger &)=delete
grpc_core::RefCounted
Definition: ref_counted.h:280
tsi::TlsSessionKeyLoggerCache::Get
static grpc_core::RefCountedPtr< TlsSessionKeyLogger > Get(std::string tls_session_key_log_file_path)
Definition: ssl_key_logging.cc:109
ssl.h
tsi::TlsSessionKeyLoggerCache::TlsSessionKeyLogger::tls_session_key_log_file_path_
std::string tls_session_key_log_file_path_
Definition: ssl_key_logging.h:68
tsi::TlsSessionKeyLoggerCache::TlsSessionKeyLogger::LogSessionKeys
void LogSessionKeys(SSL_CTX *ssl_context, const std::string &session_keys_info)
Definition: ssl_key_logging.cc:79
tsi::TlsSessionKeyLoggerCache::TlsSessionKeyLogger::~TlsSessionKeyLogger
~TlsSessionKeyLogger() override
Definition: ssl_key_logging.cc:64
grpc_core::Mutex
Definition: src/core/lib/gprpp/sync.h:61
benchmark.FILE
FILE
Definition: benchmark.py:21
ref_counted.h
tsi
Definition: ssl_key_logging.cc:29
tsi::TlsSessionKeyLoggerCache::TlsSessionKeyLogger::lock_
grpc_core::Mutex lock_
Definition: ssl_key_logging.h:66
tsi::TlsSessionKeyLoggerCache::TlsSessionKeyLogger
Definition: ssl_key_logging.h:46
tsi::TlsSessionKeyLoggerCache::tls_session_key_logger_map_
std::map< std::string, TlsSessionKeyLogger * > tls_session_key_logger_map_
Definition: ssl_key_logging.h:76
tsi::TlsSessionKeyLoggerCache::TlsSessionKeyLoggerCache
TlsSessionKeyLoggerCache()
Definition: ssl_key_logging.cc:99
sync.h
sync.h
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:20