]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ssl/cert_validate_message.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / ssl / cert_validate_message.h
CommitLineData
bbc27441 1/*
4ac4a490 2 * Copyright (C) 1996-2017 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
a1f04d64
AR
9#ifndef SQUID_SSL_CERT_VALIDATE_MESSAGE_H
10#define SQUID_SSL_CERT_VALIDATE_MESSAGE_H
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
CT
22/**
23 * This class is used to hold the required informations to build
24 * a request message for the certificate validator helper
25 */
22636a68
CT
26class CertValidationRequest
27{
a1f04d64 28public:
14798e73 29 SSL *ssl;
92e3827b 30 Security::CertErrors *errors; ///< The list of errors detected
b56756cb 31 std::string domainName; ///< The server name
14798e73 32 CertValidationRequest() : ssl(NULL), errors(NULL) {}
a1f04d64
AR
33};
34
b56756cb
CT
35/**
36 * This class is used to store informations found in certificate validation
37 * response messages read from certificate validator helper
38 */
0e208dad 39class CertValidationResponse: public RefCountable
22636a68 40{
a1f04d64 41public:
0e208dad
CT
42 typedef RefCount<CertValidationResponse> Pointer;
43
b56756cb
CT
44 /**
45 * This class used to hold error informations returned from
46 * cert validator helper.
47 */
22636a68
CT
48 class RecvdError
49 {
a1f04d64 50 public:
b4e6a8d4 51 RecvdError(): id(0), error_no(SSL_ERROR_NONE), cert(NULL), error_depth(-1) {}
b56756cb 52 RecvdError(const RecvdError &);
d6d0eb11 53 RecvdError & operator =(const RecvdError &);
b56756cb 54 void setCert(X509 *); ///< Sets cert to the given certificate
3a7d782f 55 int id; ///< The id of the error
13cd7dee 56 Security::ErrorCode error_no; ///< The OpenSSL error code
3a7d782f 57 std::string error_reason; ///< A string describing the error
f97700a0 58 Security::CertPointer cert; ///< The broken certificate
b4e6a8d4 59 int error_depth; ///< The error depth
a1f04d64
AR
60 };
61
b56756cb 62 typedef std::vector<RecvdError> RecvdErrors;
3a7d782f 63
b56756cb
CT
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
24438ec5 68 Helper::ResultCode resultCode; ///< The helper result code
3a7d782f
CT
69};
70
b56756cb
CT
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:
d6d0eb11 75 * response/request-code SP body-length SP [key=value ...] \x01
b56756cb 76 */
d6d0eb11 77class CertValidationMsg : public CrtdMessage
22636a68 78{
3a7d782f 79private:
b56756cb
CT
80 /**
81 * This class used to hold the certId/cert pairs found
82 * in cert validation messages.
83 */
22636a68
CT
84 class CertItem
85 {
a1f04d64 86 public:
b56756cb 87 std::string name; ///< The certificate Id to use
f97700a0 88 Security::CertPointer cert; ///< A pointer to certificate
a1f04d64
AR
89 CertItem(): cert(NULL) {}
90 CertItem(const CertItem &);
d6d0eb11 91 CertItem & operator =(const CertItem &);
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
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);
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;
a1f04d64
AR
126};
127
128}//namespace Ssl
d6d0eb11 129
a1f04d64 130#endif // SQUID_SSL_CERT_VALIDATE_MESSAGE_H
f53969cc 131