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_DETAIL_H
10#define SQUID_SRC_SECURITY_DETAIL_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
48 ErrorDetail(ErrorCode err_no, const CertPointer &peer, const CertPointer &broken, const char *aReason = nullptr);
49
50#if USE_OPENSSL
54 ErrorDetail(ErrorCode anErrorCode, int anIoErrorNo, int aSysErrorNo);
55#elif USE_GNUTLS
59 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
76
79
82 void setPeerCertificate(const CertPointer &);
83
84private:
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
115 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
127ErrorCode ErrorCodeFromName(const char *name);
128
131const char *ErrorNameFromCode(ErrorCode err, bool prefixRawCode = false);
132
137inline std::ostream &
138operator <<(std::ostream &os, const ErrorDetail::Pointer &p)
139{
140 return operator <<(os, ::ErrorDetail::Pointer(p));
141}
142
143} // namespace Security
144
145#endif
146
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
Definition: ErrorDetail.h:108
Certificate * peerCert()
the peer certificate (or nil)
Definition: ErrorDetail.h:75
ErrorCode error_no
Squid-discovered error, validation error, or zero;.
Definition: ErrorDetail.h:102
void printErrorCode(std::ostream &os) const
textual representation of error_no
Definition: ErrorDetail.cc:690
SBuf verbose(const HttpRequestPointer &) const override
Definition: ErrorDetail.cc:534
void printCommonName(std::ostream &os) const
a list of the broken certificates CN and alternate names
Definition: ErrorDetail.cc:623
LibErrorCode lib_error_no
TLS library-reported non-validation error or zero;.
Definition: ErrorDetail.h:105
ErrorDetail(ErrorCode err_no, const CertPointer &peer, const CertPointer &broken, const char *aReason=nullptr)
Definition: ErrorDetail.cc:466
CertPointer broken_cert
A pointer to the broken certificate (peer or intermediate)
Definition: ErrorDetail.h:99
void printSubject(std::ostream &os) const
textual representation of the subject of the broken certificate
Definition: ErrorDetail.cc:561
size_t convertErrorCodeToDescription(const char *code, std::ostream &os) const
Definition: ErrorDetail.cc:752
ErrorCode errorNo() const
Definition: ErrorDetail.h:67
void printErrorLibError(std::ostream &os) const
textual representation of lib_error_no
Definition: ErrorDetail.cc:723
ErrorDetailPointer Pointer
Definition: ErrorDetail.h:44
void printErrorDescription(std::ostream &os) const
short description of error_no
Definition: ErrorDetail.cc:704
String errReason
a custom reason for the error
Definition: ErrorDetail.h:123
void setPeerCertificate(const CertPointer &)
Definition: ErrorDetail.cc:490
std::optional< ErrorDetailEntry > detailEntry
Definition: ErrorDetail.h:118
SBuf brief() const override
Definition: ErrorDetail.cc:500
void printNotBefore(std::ostream &os) const
textual representation of the "not before" field of the broken certificate
Definition: ErrorDetail.cc:654
Certificate * brokenCert()
peer or intermediate certificate that failed validation (or nil)
Definition: ErrorDetail.h:78
int sysError() const
Definition: ErrorDetail.h:70
void printCaName(std::ostream &os) const
the issuer of the broken certificate
Definition: ErrorDetail.cc:638
void printNotAfter(std::ostream &os) const
textual representation of the "not after" field of the broken certificate
Definition: ErrorDetail.cc:672
CertPointer peer_cert
A pointer to the peer certificate.
Definition: ErrorDetail.h:98
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:132
const char * ErrorNameFromCode(ErrorCode err, bool prefixRawCode=false)
Definition: ErrorDetail.cc:430
unsigned long LibErrorCode
TLS library-reported non-validation error.
Definition: forward.h:139
X509 Certificate
Definition: forward.h:77
ErrorCode ErrorCodeFromName(const char *name)
Definition: ErrorDetail.cc:410
std::ostream & operator<<(std::ostream &, const EncryptorAnswer &)
int code
Definition: smb-errors.c:145

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors