34 return SSL_get_peer_cert_chain(ssl.get());
43 if (
const char *sslVersion = SSL_get_version(vcert.
ssl.get()))
46 if (
const char *cipherName = SSL_CIPHER_get_name(SSL_get_current_cipher(vcert.
ssl.get())))
49 STACK_OF(X509) *peerCerts = PeerValidationCertificatesChain(vcert.
ssl);
52 for (
int i = 0; i < sk_X509_num(peerCerts); ++i) {
53 X509 *cert = sk_X509_value(peerCerts, i);
54 PEM_write_bio_X509(bio.get(), cert);
57 long len = BIO_get_mem_data(bio.get(), &ptr);
58 body.append(ptr, (ptr[len-1] ==
'\n' ? len - 1 : len));
59 if (!BIO_reset(bio.get())) {
70 int errorCertPos = -1;
71 if (err->element.cert.get())
72 errorCertPos = sk_X509_find(peerCerts, err->element.cert.get());
73 if (errorCertPos < 0) {
75 debugs(83, 4,
"WARNING: wrong cert in cert validator request");
86 const char *e = label + len -1;
87 while (e != label &&
xisdigit(*e)) --e;
89 return strtol(e,
nullptr, 10);
96 tryParsingResponse(resp);
111 std::vector<CertItem> certs;
113 const STACK_OF(X509) *peerCerts = PeerValidationCertificatesChain(resp.
ssl);
115 const char *param = body.c_str();
121 size_t param_len = strcspn(param,
"=\r\n");
122 if (param[param_len] !=
'=') {
125 const char *value=param+param_len+1;
127 if (param_len > param_cert.length() &&
128 strncmp(param, param_cert.c_str(), param_cert.length()) == 0) {
130 ci.
name.assign(param, param_len);
135 const char *b = strstr(value,
"-----END CERTIFICATE-----");
139 b += strlen(
"-----END CERTIFICATE-----");
144 size_t value_len = strcspn(value,
"\r\n");
145 std::string v(value, value_len);
147 debugs(83, 5,
"Returned value: " << std::string(param, param_len).c_str() <<
": " <<
153 if (param_len > param_error_name.length() &&
154 strncmp(param, param_error_name.c_str(), param_error_name.length()) == 0) {
156 if (currentItem.
error_no == SSL_ERROR_NONE) {
159 }
else if (param_len > param_error_reason.length() &&
160 strncmp(param, param_error_reason.c_str(), param_error_reason.length()) == 0) {
162 }
else if (param_len > param_error_cert.length() &&
163 strncmp(param, param_error_cert.c_str(), param_error_cert.length()) == 0) {
165 if (X509 *cert = getCertByName(certs, v)) {
166 debugs(83, 6,
"The certificate with id \"" << v <<
"\" found.");
174 debugs(83, 6,
"Cert index in peer certificates list:" << certId);
176 currentItem.
setCert(sk_X509_value(peerCerts, certId));
178 }
else if (param_len > param_error_depth.length() &&
179 strncmp(param, param_error_depth.c_str(), param_error_depth.length()) == 0 &&
180 std::all_of(v.begin(), v.end(), isdigit)) {
186 param = value + value_len;
190 typedef Ssl::CertValidationResponse::RecvdErrors::const_iterator SVCRECI;
191 for (SVCRECI i = resp.
errors.begin(); i != resp.
errors.end(); ++i) {
192 if (i->error_no == SSL_ERROR_NONE) {
201 typedef std::vector<CertItem>::const_iterator SVCI;
202 for (SVCI ci = certs.begin(); ci != certs.end(); ++ci) {
203 if (ci->name.compare(name) == 0)
204 return ci->cert.get();
219 typedef Ssl::CertValidationResponse::RecvdErrors::iterator SVCREI;
220 for (SVCREI i = errors.begin(); i != errors.end(); ++i) {
221 if (i->id == errorId)
225 errItem.
id = errorId;
226 errors.push_back(errItem);
227 return errors.back();
233 cert.resetAndLock(aCert);
239 cert.resetAndLock(aCert);
#define Here()
source code location of the caller
std::ostream & CurrentException(std::ostream &os)
prints active (i.e., thrown but not yet handled) exception
static STACK_OF(X509) *PeerValidationCertificatesChain(const Security
static int get_error_id(const char *label, size_t len)
static std::ostream & Extra(std::ostream &)
std::string name
The certificate Id to use.
void setCert(X509 *)
Sets cert to the given certificate.
static const std::string param_domain
Parameter name for passing intended domain name.
static const std::string param_proto_version
Parameter name for SSL version.
static const std::string param_error_name
Parameter name for passing the major SSL error.
static const std::string param_error_depth
Parameter name for passing the error depth.
static const std::string param_error_cert
Parameter name for passing the error cert ID.
void composeRequest(CertValidationRequest const &vcert)
static const std::string param_cipher
Parameter name for SSL cipher.
static const std::string param_cert
Parameter name for passing SSL certificates.
bool parseResponse(CertValidationResponse &resp)
Parse a response message and fill the resp object with parsed information.
X509 * getCertByName(std::vector< CertItem > const &, std::string const &name)
Search a CertItems list for the certificate with ID "name".
static const std::string param_error_reason
Parameter name for passing the error reason.
static const std::string code_cert_validate
String code for "cert_validate" messages.
void tryParsingResponse(CertValidationResponse &)
Security::SessionPointer ssl
Security::CertErrors * errors
The list of errors detected.
std::string domainName
The server name.
Security::ErrorCode error_no
The OpenSSL error code.
int id
The id of the error.
std::string error_reason
A string describing the error.
int error_depth
The error depth.
void setCert(X509 *)
Sets cert to the given certificate.
static uint64_t MemoryUsedByResponse(const CertValidationResponse::Pointer &)
Security::SessionPointer ssl
RecvdError & getError(int errorId)
RecvdErrors errors
The list of parsed errors.
static const std::string param_host
Parameter name for passing hostname.
std::string body
Current body.
an std::runtime_error with thrower location info
#define debugs(SECTION, LEVEL, CONTENT)
int ssl_ex_index_ssl_cert_chain
std::shared_ptr< SSL > SessionPointer
Security::ErrorCode GetErrorCode(const char *name)
The Security::ErrorCode code of the error described by "name".
std::unique_ptr< BIO, HardFun< void, BIO *, &BIO_vfree > > BIO_Pointer
Security::CertPointer ReadCertificate(const BIO_Pointer &)
BIO_Pointer ReadOnlyBioTiedTo(const char *)
const char * GetErrorName(const Security::ErrorCode code, const bool prefixRawCode=false)
STACK_OF(X509) *X509_STORE_CTX_get0_untrusted(X509_STORE_CTX *ctx)
SBuf ToSBuf(Args &&... args)
slowly stream-prints all arguments into a freshly allocated SBuf
const char * xitoa(int num)