]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ssl/cert_validate_message.h
Simplify appending SBuf to String (#2108)
[thirdparty/squid.git] / src / ssl / cert_validate_message.h
CommitLineData
bbc27441 1/*
1f7b830e 2 * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
bbc27441
AJ
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
ff9d9458
FC
9#ifndef SQUID_SRC_SSL_CERT_VALIDATE_MESSAGE_H
10#define SQUID_SRC_SSL_CERT_VALIDATE_MESSAGE_H
a1f04d64 11
0e208dad 12#include "base/RefCount.h"
24438ec5 13#include "helper/ResultCode.h"
a1f04d64 14#include "ssl/crtd_message.h"
602d9612 15#include "ssl/support.h"
d6d0eb11 16
a1f04d64
AR
17#include <vector>
18
22636a68 19namespace Ssl
a1f04d64
AR
20{
21
b56756cb 22/**
2f8abb64 23 * This class is used to hold the required information to build
b56756cb
CT
24 * a request message for the certificate validator helper
25 */
22636a68
CT
26class CertValidationRequest
27{
a1f04d64 28public:
0b168d25
AJ
29 Security::SessionPointer ssl;
30 Security::CertErrors *errors = nullptr; ///< The list of errors detected
b56756cb 31 std::string domainName; ///< The server name
a1f04d64
AR
32};
33
b56756cb 34/**
2f8abb64 35 * This class is used to store information found in certificate validation
b56756cb
CT
36 * response messages read from certificate validator helper
37 */
0e208dad 38class CertValidationResponse: public RefCountable
22636a68 39{
a1f04d64 40public:
0e208dad
CT
41 typedef RefCount<CertValidationResponse> Pointer;
42
b56756cb 43 /**
2f8abb64 44 * This class used to hold error information returned from
b56756cb
CT
45 * cert validator helper.
46 */
22636a68
CT
47 class RecvdError
48 {
a1f04d64 49 public:
b56756cb 50 void setCert(X509 *); ///< Sets cert to the given certificate
83b053a0
CT
51 int id = 0; ///< The id of the error
52 Security::ErrorCode error_no = 0; ///< The OpenSSL error code
3a7d782f 53 std::string error_reason; ///< A string describing the error
f97700a0 54 Security::CertPointer cert; ///< The broken certificate
83b053a0 55 int error_depth = -1; ///< The error depth
a1f04d64
AR
56 };
57
b56756cb 58 typedef std::vector<RecvdError> RecvdErrors;
8fe1a85a 59 explicit CertValidationResponse(const Security::SessionPointer &aSession) : ssl(aSession) {}
72247610
AJ
60
61 static uint64_t MemoryUsedByResponse(const CertValidationResponse::Pointer &);
62
b56756cb
CT
63 /// Search in errors list for the error item with id=errorId.
64 /// If none found a new RecvdError item added with the given id;
65 RecvdError &getError(int errorId);
66 RecvdErrors errors; ///< The list of parsed errors
4224ea13 67 Helper::ResultCode resultCode = Helper::Unknown; ///< The helper result code
8fe1a85a 68 Security::SessionPointer ssl;
3a7d782f
CT
69};
70
b56756cb
CT
71/**
72 * This class is responsible for composing or parsing messages destined to
2f8abb64 73 * or coming from a certificate validation helper.
b56756cb 74 * The messages format is:
f439fbd2
AJ
75\verbatim
76 response/request-code SP body-length SP [key=value ...] EOL
77\endverbatim
78 * \note EOL for this interface is character 0x01
b56756cb 79 */
d6d0eb11 80class CertValidationMsg : public CrtdMessage
22636a68 81{
3a7d782f 82private:
b56756cb
CT
83 /**
84 * This class used to hold the certId/cert pairs found
85 * in cert validation messages.
86 */
22636a68
CT
87 class CertItem
88 {
a1f04d64 89 public:
b56756cb 90 std::string name; ///< The certificate Id to use
f97700a0 91 Security::CertPointer cert; ///< A pointer to certificate
b56756cb 92 void setCert(X509 *); ///< Sets cert to the given certificate
a1f04d64 93 };
b56756cb 94
a1f04d64 95public:
53251bc3 96 CertValidationMsg(MessageKind kind): CrtdMessage(kind) {}
b56756cb
CT
97
98 /// Build a request message for the cert validation helper
2f8abb64 99 /// using information provided by vcert object
b56756cb
CT
100 void composeRequest(CertValidationRequest const &vcert);
101
2f8abb64 102 /// Parse a response message and fill the resp object with parsed information
8b082ed9 103 bool parseResponse(CertValidationResponse &resp);
b56756cb
CT
104
105 /// Search a CertItems list for the certificate with ID "name"
106 X509 *getCertByName(std::vector<CertItem> const &, std::string const & name);
a1f04d64
AR
107
108 /// String code for "cert_validate" messages
109 static const std::string code_cert_validate;
110 /// Parameter name for passing intended domain name
111 static const std::string param_domain;
a1f04d64 112 /// Parameter name for passing SSL certificates
22636a68 113 static const std::string param_cert;
a1f04d64 114 /// Parameter name for passing the major SSL error
22636a68 115 static const std::string param_error_name;
a1f04d64 116 /// Parameter name for passing the error reason
22636a68 117 static const std::string param_error_reason;
a1f04d64
AR
118 /// Parameter name for passing the error cert ID
119 static const std::string param_error_cert;
b4e6a8d4
CT
120 /// Parameter name for passing the error depth
121 static const std::string param_error_depth;
6e325882
CT
122 /// Parameter name for SSL version
123 static const std::string param_proto_version;
124 /// Parameter name for SSL cipher
125 static const std::string param_cipher;
ac1b16b5
AR
126
127private:
128 void tryParsingResponse(CertValidationResponse &);
a1f04d64
AR
129};
130
131}//namespace Ssl
d6d0eb11 132
ff9d9458 133#endif /* SQUID_SRC_SSL_CERT_VALIDATE_MESSAGE_H */
f53969cc 134