Squid Web Cache master
Loading...
Searching...
No Matches
ErrorDetail.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2026 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_ERRORDETAIL_H
10#define SQUID_SRC_SECURITY_ERRORDETAIL_H
11
12#include "base/RefCount.h"
13#include "error/Detail.h"
14#include "http/forward.h"
15#include "security/forward.h"
16#include "SquidString.h"
17
18#if USE_OPENSSL
20#endif
21
22#if USE_OPENSSL
23#include <optional>
24#endif
25
26namespace Security {
27
40{
42
43public:
45
51 ErrorDetail(ErrorCode err_no, const CertPointer &peer, const CertPointer &broken, const char *aReason = nullptr);
52
53#if USE_OPENSSL
57 ErrorDetail(ErrorCode anErrorCode, int anIoErrorNo, int aSysErrorNo);
58#elif HAVE_LIBGNUTLS
62 ErrorDetail(ErrorCode anErrorCode, LibErrorCode aLibErrorNo, int aSysErrorNo);
63#endif
64
65 /* ErrorDetail API */
66 SBuf brief() const override;
67 SBuf verbose(const HttpRequestPointer &) const override;
68
70 ErrorCode errorNo() const { return error_no; }
71
73 int sysError() const { return sysErrorNo; }
74
75 /* Certificate manipulation API. TODO: Add GnuTLS implementations, users. */
76
79
82
85 void setPeerCertificate(const CertPointer &);
86
87private:
88 ErrorDetail(ErrorCode err, int aSysErrorNo);
89
90 /* methods for formatting error details using admin-configurable %codes */
91 void printSubject(std::ostream &os) const;
92 void printCaName(std::ostream &os) const;
93 void printCommonName(std::ostream &os) const;
94 void printNotBefore(std::ostream &os) const;
95 void printNotAfter(std::ostream &os) const;
96 void printErrorCode(std::ostream &os) const;
97 void printErrorDescription(std::ostream &os) const;
98 void printErrorLibError(std::ostream &os) const;
99 size_t convertErrorCodeToDescription(const char *code, std::ostream &os) const;
100
104
107
110
113
115 int sysErrorNo = 0;
116
117#if USE_OPENSSL
122 int ioErrorNo = 0;
123
125 mutable std::optional<ErrorDetailEntry> detailEntry;
126#else
127 // other TLS libraries do not use custom ErrorDetail members
128#endif
129
131};
132
134ErrorCode ErrorCodeFromName(const char *name);
135
138const char *ErrorNameFromCode(ErrorCode err, bool prefixRawCode = false);
139
144inline std::ostream &
145operator <<(std::ostream &os, const ErrorDetail::Pointer &p)
146{
147 return operator <<(os, ::ErrorDetail::Pointer(p));
148}
149
150} // namespace Security
151
152#endif /* SQUID_SRC_SECURITY_ERRORDETAIL_H */
153
interface for supplying additional information about a transaction failure
Definition Detail.h:21
Definition SBuf.h:94
MEMPROXY_CLASS(Security::ErrorDetail)
int sysErrorNo
errno(3); system call failure code or zero
Certificate * peerCert()
the peer certificate (or nil)
Definition ErrorDetail.h:78
ErrorCode error_no
Squid-discovered error, validation error, or zero;.
void printErrorCode(std::ostream &os) const
textual representation of error_no
SBuf verbose(const HttpRequestPointer &) const override
void printCommonName(std::ostream &os) const
a list of the broken certificates CN and alternate names
LibErrorCode lib_error_no
TLS library-reported non-validation error or zero;.
CertPointer broken_cert
A pointer to the broken certificate (peer or intermediate)
void printSubject(std::ostream &os) const
textual representation of the subject of the broken certificate
size_t convertErrorCodeToDescription(const char *code, std::ostream &os) const
ErrorCode errorNo() const
Definition ErrorDetail.h:70
void printErrorLibError(std::ostream &os) const
textual representation of lib_error_no
ErrorDetailPointer Pointer
Definition ErrorDetail.h:44
void printErrorDescription(std::ostream &os) const
short description of error_no
String errReason
a custom reason for the error
void setPeerCertificate(const CertPointer &)
std::optional< ErrorDetailEntry > detailEntry
SBuf brief() const override
void printNotBefore(std::ostream &os) const
textual representation of the "not before" field of the broken certificate
Certificate * brokenCert()
peer or intermediate certificate that failed validation (or nil)
Definition ErrorDetail.h:81
Certificate * certificateToReport() const
void printCaName(std::ostream &os) const
the issuer of the broken certificate
void printNotAfter(std::ostream &os) const
textual representation of the "not after" field of the broken certificate
CertPointer peer_cert
A pointer to the peer certificate.
T * get() const
Returns raw and possibly nullptr pointer.
Network/connection security abstraction layer.
Definition Connection.h:34
int ErrorCode
Squid-defined error code (<0), an error code returned by X.509 API, or zero.
Definition forward.h:134
const char * ErrorNameFromCode(ErrorCode err, bool prefixRawCode=false)
unsigned long LibErrorCode
TLS library-reported non-validation error.
Definition forward.h:141
X509 Certificate
Definition forward.h:79
ErrorCode ErrorCodeFromName(const char *name)
std::ostream & operator<<(std::ostream &, const EncryptorAnswer &)