KeyLog.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #include "squid.h"
10 #include "acl/FilledChecklist.h"
11 #include "acl/Gadgets.h"
12 #include "acl/Tree.h"
13 #include "base/CharacterSet.h"
14 #include "base/CodeContext.h"
15 #include "ConfigOption.h"
16 #include "HttpReply.h"
17 #include "log/File.h"
18 #include "Parsing.h"
19 #include "sbuf/Stream.h"
21 #include "security/KeyLog.h"
22 #include "security/Session.h"
23 #include "SquidConfig.h"
24 
26 {
27  filename = xstrdup(parser.token("destination").c_str());
28  parseOptions(parser, nullptr);
29  aclList = parser.optionalAclList();
30 
31  // we use a built-in format that does not have/need a dedicated enum value
32  assert(!type);
33  assert(!logFormat);
35 }
36 
37 void
39 {
40  assert(logfile);
41 
42  SBufStream os;
43 
44  // report current context to ease small-scale triage of logging problems
45  os << "# " << logfile->sequence_number;
46  if (const auto &ctx = CodeContext::Current())
47  os << ' ' << *ctx;
48  os << '\n';
49 
50  secrets.record(os);
51  const auto buf = os.buf();
52 
56 }
57 
58 void
59 Security::KeyLog::dump(std::ostream &os) const
60 {
61  os << filename;
62  dumpOptions(os);
63  if (aclList) {
64  // TODO: Use Acl::dump() after fixing the XXX in dump_acl_list().
65  for (const auto &acl: aclList->treeDump("if", &Acl::AllowOrDeny))
66  os << ' ' << acl;
67  }
68 }
69 
70 void
72 {
73  if (Config.Log.tlsKeys)
75 }
76 
77 void
79 {
80  if (Config.Log.tlsKeys)
82 }
83 
84 void
86 {
87  if (Config.Log.tlsKeys)
89 }
90 
91 // GCC v6 requires "reopening" of the namespace here, instead of the usual
92 // definitions like Configuration::Component<T>::Parse():
93 // error: specialization of Configuration::Component... in different namespace
94 // TODO: Refactor to use the usual style after we stop GCC v6 support.
95 namespace Configuration {
96 
97 template <>
100 {
101  return new Security::KeyLog(parser);
102 }
103 
104 template <>
105 void
107 {
108  assert(keyLog);
109  keyLog->dump(os);
110 }
111 
112 template <>
113 void
115 {
116  delete keyLog;
117 }
118 
119 } // namespace Configuration
120 
static T Parse(ConfigParser &)
creates a new T instance using the given parser; never returns nil
void record(std::ostream &) const
logs all known secrets using a (multiline) SSLKEYLOGFILE format
void open()
prepare for recording entries
void OpenLogs()
opens logs enabled in the current configuration
Definition: KeyLog.cc:71
#define xstrdup
char * filename
logging destination
Definition: FormattedLog.h:58
void logfilePrintf(Logfile *lf, const char *fmt,...)
Definition: File.cc:114
const char * AllowOrDeny(const Answer &action)
Definition: Tree.h:53
static FILE * logfile
KeyLog(ConfigParser &)
Definition: KeyLog.cc:25
static void Print(std::ostream &, const T &)
reports the current T instance configuration in squid.conf format
static void Free(T)
destroys Parse() result
Log::Format::log_type type
log record template ID
Definition: FormattedLog.h:67
void RotateLogs()
rotates logs opened by OpenLogs()
Definition: KeyLog.cc:78
#define SQUIDSBUFPRINT(s)
Definition: SBuf.h:32
void logfileLineStart(Logfile *lf)
Definition: File.cc:126
SBuf token(const char *expectedTokenDescription)
extracts and returns a required token
struct SquidConfig::@102 Log
#define assert(EX)
Definition: assert.h:19
void rotate()
handle the log rotation request
SBuf buf()
Retrieve a copy of the current stream status.
Definition: Stream.h:105
const char * c_str()
Definition: SBuf.cc:516
ACLList * aclList
restrict logging to matching transactions
Definition: FormattedLog.h:61
static const Pointer & Current()
Definition: CodeContext.cc:33
void record(const CommunicationSecrets &)
writes a single (but multi-line) key log entry
Definition: KeyLog.cc:38
void CloseLogs()
closes logs opened by OpenLogs()
Definition: KeyLog.cc:85
void parseOptions(ConfigParser &, const char *defaultFormat)
Definition: FormattedLog.cc:36
a single tls_key_log directive configuration and logging handler
Definition: KeyLog.h:21
void dump(std::ostream &) const
reproduces explicitly-configured squid.conf settings
Definition: KeyLog.cc:59
void logfileLineEnd(Logfile *lf)
Definition: File.cc:132
void close()
stop recording entries
Format::Format * logFormat
custom log record template for type == Log::Format::CLF_CUSTOM
Definition: FormattedLog.h:64
@ CLF_NONE
Definition: Formats.h:37
Security::KeyLog * tlsKeys
one optional tls_key_log
Definition: SquidConfig.h:188
#define SQUIDSBUFPH
Definition: SBuf.h:31
class SquidConfig Config
Definition: SquidConfig.cc:12
Acl::Tree * optionalAclList()
parses an [if [!]<acl>...] construct

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors