KeyLog.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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);
35}
36
37void
39{
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
58void
59Security::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
70void
72{
73 if (Config.Log.tlsKeys)
75}
76
77void
79{
80 if (Config.Log.tlsKeys)
82}
83
84void
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.
95namespace Configuration {
96
97template <>
100{
101 return new Security::KeyLog(parser);
102}
103
104template <>
105void
107{
108 assert(keyLog);
109 keyLog->dump(os);
110}
111
112template <>
113void
115{
116 delete keyLog;
117}
118
119} // namespace Configuration
120
#define SQUIDSBUFPH
Definition: SBuf.h:31
#define SQUIDSBUFPRINT(s)
Definition: SBuf.h:32
class SquidConfig Config
Definition: SquidConfig.cc:12
#define assert(EX)
Definition: assert.h:17
static const Pointer & Current()
Definition: CodeContext.cc:33
Acl::Tree * optionalAclList()
parses an [if [!]<acl>...] construct
SBuf token(const char *expectedTokenDescription)
extracts and returns a required token
static void Free(T)
destroys Parse() result
static T Parse(ConfigParser &)
creates a new T instance using the given parser; never returns nil
static void Print(std::ostream &, const T &)
reports the current T instance configuration in squid.conf format
Log::Format::log_type type
log record template ID
Definition: FormattedLog.h:67
char * filename
logging destination
Definition: FormattedLog.h:58
void close()
stop recording entries
void open()
prepare for recording entries
Format::Format * logFormat
custom log record template for type == Log::Format::CLF_CUSTOM
Definition: FormattedLog.h:64
void rotate()
handle the log rotation request
void parseOptions(ConfigParser &, const char *defaultFormat)
Definition: FormattedLog.cc:36
ACLList * aclList
restrict logging to matching transactions
Definition: FormattedLog.h:61
SBuf buf()
bytes written so far
Definition: Stream.h:41
const char * c_str()
Definition: SBuf.cc:516
void record(std::ostream &) const
logs all known secrets using a (multiline) SSLKEYLOGFILE format
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
KeyLog(ConfigParser &)
Definition: KeyLog.cc:25
void record(const CommunicationSecrets &)
writes a single (but multi-line) key log entry
Definition: KeyLog.cc:38
Security::KeyLog * tlsKeys
one optional tls_key_log
Definition: SquidConfig.h:190
struct SquidConfig::@98 Log
static FILE * logfile
void logfileLineEnd(Logfile *lf)
Definition: File.cc:132
void logfileLineStart(Logfile *lf)
Definition: File.cc:126
void logfilePrintf(Logfile *lf, const char *fmt,...)
Definition: File.cc:114
const char * AllowOrDeny(const Answer &action)
Definition: Tree.h:53
@ CLF_NONE
Definition: Formats.h:37
void OpenLogs()
opens logs enabled in the current configuration
Definition: KeyLog.cc:71
void CloseLogs()
closes logs opened by OpenLogs()
Definition: KeyLog.cc:85
void RotateLogs()
rotates logs opened by OpenLogs()
Definition: KeyLog.cc:78
#define xstrdup

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors