]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ssl/cert_validate_message.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / ssl / cert_validate_message.h
1 /*
2 * Copyright (C) 1996-2017 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_SSL_CERT_VALIDATE_MESSAGE_H
10 #define SQUID_SSL_CERT_VALIDATE_MESSAGE_H
11
12 #include "base/RefCount.h"
13 #include "helper/ResultCode.h"
14 #include "ssl/crtd_message.h"
15 #include "ssl/support.h"
16
17 #include <vector>
18
19 namespace Ssl
20 {
21
22 /**
23 * This class is used to hold the required informations to build
24 * a request message for the certificate validator helper
25 */
26 class CertValidationRequest
27 {
28 public:
29 SSL *ssl;
30 Security::CertErrors *errors; ///< The list of errors detected
31 std::string domainName; ///< The server name
32 CertValidationRequest() : ssl(NULL), errors(NULL) {}
33 };
34
35 /**
36 * This class is used to store informations found in certificate validation
37 * response messages read from certificate validator helper
38 */
39 class CertValidationResponse: public RefCountable
40 {
41 public:
42 typedef RefCount<CertValidationResponse> Pointer;
43
44 /**
45 * This class used to hold error informations returned from
46 * cert validator helper.
47 */
48 class RecvdError
49 {
50 public:
51 RecvdError(): id(0), error_no(SSL_ERROR_NONE), cert(NULL), error_depth(-1) {}
52 RecvdError(const RecvdError &);
53 RecvdError & operator =(const RecvdError &);
54 void setCert(X509 *); ///< Sets cert to the given certificate
55 int id; ///< The id of the error
56 Security::ErrorCode error_no; ///< The OpenSSL error code
57 std::string error_reason; ///< A string describing the error
58 Security::CertPointer cert; ///< The broken certificate
59 int error_depth; ///< The error depth
60 };
61
62 typedef std::vector<RecvdError> RecvdErrors;
63
64 /// Search in errors list for the error item with id=errorId.
65 /// If none found a new RecvdError item added with the given id;
66 RecvdError &getError(int errorId);
67 RecvdErrors errors; ///< The list of parsed errors
68 Helper::ResultCode resultCode; ///< The helper result code
69 };
70
71 /**
72 * This class is responsible for composing or parsing messages destined to
73 * or comming from a cert validator helper.
74 * The messages format is:
75 * response/request-code SP body-length SP [key=value ...] \x01
76 */
77 class CertValidationMsg : public CrtdMessage
78 {
79 private:
80 /**
81 * This class used to hold the certId/cert pairs found
82 * in cert validation messages.
83 */
84 class CertItem
85 {
86 public:
87 std::string name; ///< The certificate Id to use
88 Security::CertPointer cert; ///< A pointer to certificate
89 CertItem(): cert(NULL) {}
90 CertItem(const CertItem &);
91 CertItem & operator =(const CertItem &);
92 void setCert(X509 *); ///< Sets cert to the given certificate
93 };
94
95 public:
96 CertValidationMsg(MessageKind kind): CrtdMessage(kind) {}
97
98 /// Build a request message for the cert validation helper
99 /// using informations provided by vcert object
100 void composeRequest(CertValidationRequest const &vcert);
101
102 /// Parse a response message and fill the resp object with parsed informations
103 bool parseResponse(CertValidationResponse &resp, STACK_OF(X509) *peerCerts, std::string &error);
104
105 /// Search a CertItems list for the certificate with ID "name"
106 X509 *getCertByName(std::vector<CertItem> const &, std::string const & name);
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;
112 /// Parameter name for passing SSL certificates
113 static const std::string param_cert;
114 /// Parameter name for passing the major SSL error
115 static const std::string param_error_name;
116 /// Parameter name for passing the error reason
117 static const std::string param_error_reason;
118 /// Parameter name for passing the error cert ID
119 static const std::string param_error_cert;
120 /// Parameter name for passing the error depth
121 static const std::string param_error_depth;
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;
126 };
127
128 }//namespace Ssl
129
130 #endif // SQUID_SSL_CERT_VALIDATE_MESSAGE_H
131