PeerConnector.h
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#ifndef SQUID_SRC_SECURITY_PEERCONNECTOR_H
10#define SQUID_SRC_SECURITY_PEERCONNECTOR_H
11
12#include "acl/Acl.h"
13#include "acl/ChecklistFiller.h"
14#include "base/AsyncCallbacks.h"
15#include "base/AsyncJob.h"
16#include "base/JobWait.h"
17#include "CommCalls.h"
18#include "http/forward.h"
20#include "security/forward.h"
21#include "security/KeyLogger.h"
22#if USE_OPENSSL
23#include "ssl/support.h"
24#endif
25
26#include <iosfwd>
27#include <queue>
28
29class Downloader;
31class AccessLogEntry;
33
34namespace Security
35{
36
37class IoResult;
39
48class PeerConnector: virtual public AsyncJob, public Acl::ChecklistFiller
49{
51
52public:
54
55 PeerConnector(const Comm::ConnectionPointer &aServerConn,
57 const AccessLogEntryPointer &alp,
58 const time_t timeout = 0);
59 ~PeerConnector() override;
60
63
64protected:
65 // AsyncJob API
66 void start() override;
67 bool doneAll() const override;
68 void swanSong() override;
69 const char *status() const override;
70
71 /* Acl::ChecklistFiller API */
72 void fillChecklist(ACLFilledChecklist &) const override;
73
76
78 void commCloseHandler(const CommCloseCbParams &params);
79
82
85 void negotiate();
86
90 bool sslFinalized();
91
94
98 void noteWantRead();
99
101 bool isSuspended() const { return static_cast<bool>(suspendedError_); }
102
103#if USE_OPENSSL
106 void suspendNegotiation(const Security::IoResult &lastError);
107
109 void resumeNegotiation();
110
112 void handleMissingCertificates(const Security::IoResult &lastError);
113
115 void startCertDownloading(SBuf &url);
116
119#endif
120
123 virtual void noteWantWrite();
124
127
132
136
139
141 void bail(ErrorState *error);
142
144 void sendSuccess();
145
147 void callBack();
148
150 void disconnect();
151
154
157
161
164
168
171
172private:
173 PeerConnector(const PeerConnector &); // not implemented
174 PeerConnector &operator =(const PeerConnector &); // not implemented
175
176#if USE_OPENSSL
177 unsigned int certDownloadNestingLevel() const;
178
181
184
186#endif
187
188 static void NegotiateSsl(int fd, void *data);
189 void negotiateSsl();
190
192 static const unsigned int MaxCertsDownloads = 10;
193
195 static const unsigned int MaxNestedDownloads = 3;
196
199
202 time_t startTime;
205 std::queue<SBuf> urlsOfMissingCerts;
206 unsigned int certsDownloads;
207
208#if USE_OPENSSL
211#endif
212
215
217};
218
219} // namespace Security
220
221#endif /* SQUID_SRC_SECURITY_PEERCONNECTOR_H */
222
RefCount< AccessLogEntry > AccessLogEntryPointer
Definition: PeerConnector.h:32
void error(char *format,...)
an interface for those capable of configuring an ACLFilledChecklist object
a smart AsyncCall pointer for delivery of future results
download result
Definition: Downloader.h:28
Definition: SBuf.h:94
a summary a TLS I/O operation outcome
Definition: Io.h:19
manages collecting and logging secrets of a TLS connection to tls_key_log
Definition: KeyLogger.h:24
virtual void noteNegotiationDone(ErrorState *)
CbcPointer< PeerConnector > Pointer
Definition: PeerConnector.h:53
Ssl::X509_STACK_Pointer downloadedCerts
successfully downloaded intermediate certificates (omitted by the peer)
void negotiateSsl()
Comm::SetSelect() callback. Direct calls tickle/resume negotiations.
void commCloseHandler(const CommCloseCbParams &params)
The comm_close callback handler.
void sslCrtvdHandleReply(Ssl::CertValidationResponsePointer &)
Process response from cert validator helper.
time_t startTime
when the peer connector negotiation started
AsyncCall::Pointer closeHandler
we call this when the connection closed
void startCertDownloading(SBuf &url)
Start downloading procedure for the given URL.
void swanSong() override
virtual bool initialize(Security::SessionPointer &)
bool noteFwdPconnUse
hack: whether the connection requires fwdPconnPool->noteUses()
Definition: PeerConnector.h:62
PeerConnector(const Comm::ConnectionPointer &aServerConn, const AsyncCallback< EncryptorAnswer > &, const AccessLogEntryPointer &alp, const time_t timeout=0)
JobWait< Downloader > certDownloadWait
waits for the missing certificate to be downloaded
void countFailingConnection(const ErrorState *)
updates connection usage history before the connection is closed
virtual Security::ContextPointer getTlsContext()=0
void bail(ErrorState *error)
sends the given error to the initiator
virtual void noteNegotiationError(const Security::ErrorDetailPointer &)
Called when the SSL_connect function aborts with an SSL negotiation error.
EncryptorAnswer & answer()
convenience method to get to the answer fields
virtual void noteWantWrite()
bool computeMissingCertificateUrls(const Connection &)
finds URLs of (some) missing intermediate certificates or returns false
void handleMissingCertificates(const Security::IoResult &lastError)
Either initiates fetching of missing certificates or bails with an error.
std::queue< SBuf > urlsOfMissingCerts
The list of URLs where missing certificates should be downloaded.
HttpRequestPointer request
peer connection trigger or cause
PeerConnector & operator=(const PeerConnector &)
Security::IoResultPointer suspendedError_
outcome of the last (failed and) suspended negotiation attempt (or nil)
time_t negotiationTimeout
the SSL connection timeout to use
void resumeNegotiation()
Resumes TLS negotiation paused by suspendNegotiation()
static const unsigned int MaxNestedDownloads
The maximum number of inter-dependent Downloader jobs a worker may initiate.
void start() override
Preps connection and SSL state. Calls negotiate().
PeerConnector(const PeerConnector &)
Comm::ConnectionPointer const & serverConnection() const
mimics FwdState to minimize changes to FwdState::initiate/negotiateSsl
void handleNegotiationResult(const Security::IoResult &)
Called after each negotiation step to handle the result.
void commTimeoutHandler(const CommTimeoutCbParams &)
The connection read timeout callback handler.
void bypassCertValidator()
If called the certificates validator will not used.
void fillChecklist(ACLFilledChecklist &) const override
configure the given checklist (to reflect the current transaction state)
bool doneAll() const override
whether positive goal has been reached
Security::KeyLogger keyLogger
managers logging of the being-established TLS connection secrets
AccessLogEntryPointer al
info for the future access.log entry
static void NegotiateSsl(int fd, void *data)
A wrapper for Comm::SetSelect() notifications.
void disconnect()
a bail(), sendSuccess() helper: stops monitoring the connection
unsigned int certsDownloads
the number of downloaded missing certificates
AsyncCallback< EncryptorAnswer > callback
answer destination
bool isSuspended() const
Whether TLS negotiation has been paused and not yet resumed.
void sendSuccess()
sends the encrypted connection to the initiator
void certDownloadingDone(DownloaderAnswer &)
Called by Downloader after a certificate object downloaded.
unsigned int certDownloadNestingLevel() const
the number of concurrent PeerConnector jobs waiting for us
void callBack()
a bail(), sendSuccess() helper: sends results to the initiator
static const unsigned int MaxCertsDownloads
The maximum number of missing certificates a single PeerConnector may download.
Comm::ConnectionPointer serverConn
TCP connection to the peer.
void suspendNegotiation(const Security::IoResult &lastError)
const char * status() const override
internal cleanup; do not call directly
Security::CertErrors * sslCrtvdCheckForErrors(Ssl::CertValidationResponse const &, ErrorDetailPointer &)
Check SSL errors returned from cert validator against sslproxy_cert_error access list.
Network/connection security abstraction layer.
Definition: Connection.h:34
RefCount< IoResult > IoResultPointer
Definition: PeerConnector.h:38
std::shared_ptr< SSL_CTX > ContextPointer
Definition: Context.h:29
SSL Connection
Definition: Session.h:45
std::shared_ptr< SSL > SessionPointer
Definition: Session.h:49
std::unique_ptr< STACK_OF(X509), sk_X509_free_wrapper > X509_STACK_Pointer
Definition: gadgets.h:50

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors