PeerConnector.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2025 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 
29 class Downloader;
30 class DownloaderAnswer;
33 
34 namespace Security
35 {
36 
37 class IoResult;
39 
48 class PeerConnector: virtual public AsyncJob, public Acl::ChecklistFiller
49 {
51 
52 public:
54 
55  PeerConnector(const Comm::ConnectionPointer &aServerConn,
57  const AccessLogEntryPointer &alp,
58  const time_t timeout = 0);
59  ~PeerConnector() override;
60 
63 
64 protected:
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 
81  virtual bool initialize(Security::SessionPointer &);
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
104  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 
131  virtual void noteNegotiationDone(ErrorState *) {}
132 
135  virtual FuturePeerContext *peerContext() const = 0;
136 
139 
141  void bail(ErrorState *error);
142 
144  void sendSuccess();
145 
147  void callBack();
148 
150  void disconnect();
151 
153  void countFailingConnection();
154 
157 
161 
164 
168 
171 
172 private:
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;
204  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 
AsyncCallback< EncryptorAnswer > callback
answer destination
time_t startTime
when the peer connector negotiation started
virtual bool initialize(Security::SessionPointer &)
PeerConnector(const Comm::ConnectionPointer &aServerConn, const AsyncCallback< EncryptorAnswer > &, const AccessLogEntryPointer &alp, const time_t timeout=0)
EncryptorAnswer & answer()
convenience method to get to the answer fields
static void NegotiateSsl(int fd, void *data)
A wrapper for Comm::SetSelect() notifications.
static const unsigned int MaxNestedDownloads
The maximum number of inter-dependent Downloader jobs a worker may initiate.
void callBack()
a bail(), sendSuccess() helper: sends results to the initiator
Comm::ConnectionPointer serverConn
TCP connection to the peer.
void sslCrtvdHandleReply(Ssl::CertValidationResponsePointer &)
Process response from cert validator helper.
Security::IoResultPointer suspendedError_
outcome of the last (failed and) suspended negotiation attempt (or nil)
HttpRequestPointer request
peer connection trigger or cause
unsigned int certsDownloads
the number of downloaded missing certificates
void commTimeoutHandler(const CommTimeoutCbParams &)
The connection read timeout callback handler.
void error(char *format,...)
Definition: SBuf.h:93
std::unique_ptr< STACK_OF(X509), sk_X509_free_wrapper > X509_STACK_Pointer
Definition: gadgets.h:53
a smart AsyncCall pointer for delivery of future results
unsigned int certDownloadNestingLevel() const
the number of concurrent PeerConnector jobs waiting for us
void swanSong() override
JobWait< Downloader > certDownloadWait
waits for the missing certificate to be downloaded
a summary a TLS I/O operation outcome
Definition: Io.h:19
PeerConnector & operator=(const PeerConnector &)
A combination of PeerOptions and the corresponding Context.
Definition: PeerOptions.h:154
bool isSuspended() const
Whether TLS negotiation has been paused and not yet resumed.
virtual FuturePeerContext * peerContext() const =0
void bypassCertValidator()
If called the certificates validator will not used.
AsyncCall::Pointer closeHandler
we call this when the connection closed
void bail(ErrorState *error)
sends the given error to the initiator
virtual void noteNegotiationDone(ErrorState *)
const char * status() const override
internal cleanup; do not call directly
void disconnect()
a bail(), sendSuccess() helper: stops monitoring the connection
time_t negotiationTimeout
the SSL connection timeout to use
void handleMissingCertificates(const Security::IoResult &lastError)
Either initiates fetching of missing certificates or bails with an error.
void certDownloadingDone(DownloaderAnswer &)
Called by Downloader after a certificate object downloaded.
Ssl::X509_STACK_Pointer downloadedCerts
successfully downloaded intermediate certificates (omitted by the peer)
void suspendNegotiation(const Security::IoResult &lastError)
virtual void noteNegotiationError(const Security::ErrorDetailPointer &)
Called when the SSL_connect function aborts with an SSL negotiation error.
static const unsigned int MaxCertsDownloads
The maximum number of missing certificates a single PeerConnector may download.
manages collecting and logging secrets of a TLS connection to tls_key_log
Definition: KeyLogger.h:23
void countFailingConnection()
updates connection usage history before the connection is closed
SSL Connection
Definition: Session.h:49
Security::CertErrors * sslCrtvdCheckForErrors(Ssl::CertValidationResponse const &, ErrorDetailPointer &)
Check SSL errors returned from cert validator against sslproxy_cert_error access list.
void negotiateSsl()
Comm::SetSelect() callback. Direct calls tickle/resume negotiations.
RefCount< IoResult > IoResultPointer
Definition: PeerConnector.h:37
bool doneAll() const override
whether positive goal has been reached
RefCount< AccessLogEntry > AccessLogEntryPointer
Definition: PeerConnector.h:31
std::queue< SBuf > urlsOfMissingCerts
The list of URLs where missing certificates should be downloaded.
Security::KeyLogger keyLogger
managers logging of the being-established TLS connection secrets
void start() override
Preps connection and SSL state. Calls negotiate().
std::shared_ptr< SSL > SessionPointer
Definition: Session.h:53
void handleNegotiationResult(const Security::IoResult &)
Called after each negotiation step to handle the result.
CbcPointer< PeerConnector > Pointer
Definition: PeerConnector.h:53
void resumeNegotiation()
Resumes TLS negotiation paused by suspendNegotiation()
void fillChecklist(ACLFilledChecklist &) const override
configure the given checklist (to reflect the current transaction state)
AccessLogEntryPointer al
info for the future access.log entry
void commCloseHandler(const CommCloseCbParams &params)
The comm_close callback handler.
bool computeMissingCertificateUrls(const Connection &)
finds URLs of (some) missing intermediate certificates or returns false
bool noteFwdPconnUse
hack: whether the connection requires fwdPconnPool->noteUses()
Definition: PeerConnector.h:62
Network/connection security abstraction layer.
Definition: Connection.h:33
virtual void noteWantWrite()
an interface for those capable of configuring an ACLFilledChecklist object
const Comm::ConnectionPointer & serverConnection() const
mimics FwdState to minimize changes to FwdState::initiate/negotiateSsl
void sendSuccess()
sends the encrypted connection to the initiator
download result
Definition: Downloader.h:28
void startCertDownloading(SBuf &url)
Start downloading procedure for the given URL.

 

Introduction

Documentation

Support

Miscellaneous