ErrorDetail.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_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
19 #include "ssl/ErrorDetailManager.h"
20 #endif
21 
22 #if USE_OPENSSL
23 #include <optional>
24 #endif
25 
26 namespace Security {
27 
40 {
42 
43 public:
45 
48  ErrorDetail(ErrorCode err_no, const CertPointer &peer, const CertPointer &broken, const char *aReason = nullptr);
49 
50 #if USE_OPENSSL
51  ErrorDetail(ErrorCode anErrorCode, int anIoErrorNo, int aSysErrorNo);
55 #elif HAVE_LIBGNUTLS
56  ErrorDetail(ErrorCode anErrorCode, LibErrorCode aLibErrorNo, int aSysErrorNo);
60 #endif
61 
62  /* ErrorDetail API */
63  SBuf brief() const override;
64  SBuf verbose(const HttpRequestPointer &) const override;
65 
67  ErrorCode errorNo() const { return error_no; }
68 
70  int sysError() const { return sysErrorNo; }
71 
72  /* Certificate manipulation API. TODO: Add GnuTLS implementations, users. */
73 
75  Certificate *peerCert() { return peer_cert.get(); }
76 
79 
82  void setPeerCertificate(const CertPointer &);
83 
84 private:
85  ErrorDetail(ErrorCode err, int aSysErrorNo);
86 
87  /* methods for formatting error details using admin-configurable %codes */
88  void printSubject(std::ostream &os) const;
89  void printCaName(std::ostream &os) const;
90  void printCommonName(std::ostream &os) const;
91  void printNotBefore(std::ostream &os) const;
92  void printNotAfter(std::ostream &os) const;
93  void printErrorCode(std::ostream &os) const;
94  void printErrorDescription(std::ostream &os) const;
95  void printErrorLibError(std::ostream &os) const;
96  size_t convertErrorCodeToDescription(const char *code, std::ostream &os) const;
97 
100 
103 
106 
108  int sysErrorNo = 0;
109 
110 #if USE_OPENSSL
111  int ioErrorNo = 0;
116 
118  mutable std::optional<ErrorDetailEntry> detailEntry;
119 #else
120  // other TLS libraries do not use custom ErrorDetail members
121 #endif
122 
124 };
125 
127 ErrorCode ErrorCodeFromName(const char *name);
128 
131 const char *ErrorNameFromCode(ErrorCode err, bool prefixRawCode = false);
132 
137 inline std::ostream &
138 operator <<(std::ostream &os, const ErrorDetail::Pointer &p)
139 {
140  return operator <<(os, ::ErrorDetail::Pointer(p));
141 }
142 
143 } // namespace Security
144 
145 #endif /* SQUID_SRC_SECURITY_ERRORDETAIL_H */
146 
ErrorCode ErrorCodeFromName(const char *name)
Definition: ErrorDetail.cc:410
void printSubject(std::ostream &os) const
textual representation of the subject of the broken certificate
Definition: ErrorDetail.cc:561
int ErrorCode
Squid-defined error code (<0), an error code returned by X.509 API, or zero.
Definition: forward.h:131
SBuf verbose(const HttpRequestPointer &) const override
Definition: ErrorDetail.cc:534
Certificate * peerCert()
the peer certificate (or nil)
Definition: ErrorDetail.h:75
void printCommonName(std::ostream &os) const
a list of the broken certificates CN and alternate names
Definition: ErrorDetail.cc:628
Definition: SBuf.h:93
MEMPROXY_CLASS(Security::ErrorDetail)
void printNotBefore(std::ostream &os) const
textual representation of the "not before" field of the broken certificate
Definition: ErrorDetail.cc:659
std::optional< ErrorDetailEntry > detailEntry
Definition: ErrorDetail.h:118
CertPointer broken_cert
A pointer to the broken certificate (peer or intermediate)
Definition: ErrorDetail.h:99
SBuf brief() const override
Definition: ErrorDetail.cc:500
int sysError() const
Definition: ErrorDetail.h:70
void printNotAfter(std::ostream &os) const
textual representation of the "not after" field of the broken certificate
Definition: ErrorDetail.cc:677
ErrorDetailPointer Pointer
Definition: ErrorDetail.h:44
void setPeerCertificate(const CertPointer &)
Definition: ErrorDetail.cc:490
ErrorDetail(ErrorCode err_no, const CertPointer &peer, const CertPointer &broken, const char *aReason=nullptr)
Definition: ErrorDetail.cc:466
std::ostream & operator<<(std::ostream &, const EncryptorAnswer &)
void printErrorLibError(std::ostream &os) const
textual representation of lib_error_no
Definition: ErrorDetail.cc:728
Certificate * brokenCert()
peer or intermediate certificate that failed validation (or nil)
Definition: ErrorDetail.h:78
void printCaName(std::ostream &os) const
the issuer of the broken certificate
Definition: ErrorDetail.cc:643
void printErrorDescription(std::ostream &os) const
short description of error_no
Definition: ErrorDetail.cc:709
const char * ErrorNameFromCode(ErrorCode err, bool prefixRawCode=false)
Definition: ErrorDetail.cc:430
int sysErrorNo
errno(3); system call failure code or zero
Definition: ErrorDetail.h:108
int code
Definition: smb-errors.c:145
X509 Certificate
Definition: forward.h:79
ErrorCode errorNo() const
Definition: ErrorDetail.h:67
ErrorCode error_no
Squid-discovered error, validation error, or zero;.
Definition: ErrorDetail.h:102
String errReason
a custom reason for the error
Definition: ErrorDetail.h:123
void printErrorCode(std::ostream &os) const
textual representation of error_no
Definition: ErrorDetail.cc:695
size_t convertErrorCodeToDescription(const char *code, std::ostream &os) const
Definition: ErrorDetail.cc:757
CertPointer peer_cert
A pointer to the peer certificate.
Definition: ErrorDetail.h:98
Network/connection security abstraction layer.
Definition: Connection.h:33
LibErrorCode lib_error_no
TLS library-reported non-validation error or zero;.
Definition: ErrorDetail.h:105
T * get() const
Returns raw and possibly nullptr pointer.
unsigned long LibErrorCode
TLS library-reported non-validation error.
Definition: forward.h:141

 

Introduction

Documentation

Support

Miscellaneous