Skip to content

Commit

Permalink
linux: invoke the certificate chain callback only once
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrik Fiedler authored and atbagga committed Oct 26, 2021
1 parent a694f50 commit 68c40a7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Release/include/cpprest/certificate_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ namespace web { namespace http { namespace client {

struct certificate_info
{
CertificateChain certificate_chain;
std::string host_name;
CertificateChain certificate_chain;
long certificate_error{ 0 };
bool verified{ false };

certificate_info(const std::string host) : host_name(host) {};
certificate_info(const std::string host, CertificateChain chain, long error = 0) : host_name(host), certificate_chain(chain), certificate_error(error) {};
certificate_info(const std::string host) : host_name(host) {}
certificate_info(const std::string host, CertificateChain chain, long error = 0) : host_name(host), certificate_chain(chain), certificate_error(error) {}
};

using CertificateChainFunction = std::function<bool(const std::shared_ptr<certificate_info> certificate_Info)>;

}}}
}}}
1 change: 1 addition & 0 deletions Release/include/cpprest/ws_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ class websocket_client_config
}

private:
http::client::CertificateChainFunction m_certificate_chain_callback;
web::web_proxy m_proxy;
web::credentials m_credentials;
web::http::http_headers m_headers;
Expand Down
6 changes: 6 additions & 0 deletions Release/src/http/client/http_client_asio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,12 @@ class asio_context final : public request_context, public std::enable_shared_fro
auto info = std::make_shared<certificate_info>(host, get_X509_cert_chain_encoded_data(verifyCtx));
info->verified = true;

if (!is_end_certificate_in_chain(verifyCtx))
{
// Continue until we get the end certificate.
return true;
}

return m_http_client->client_config().invoke_certificate_chain_callback(info);
}

Expand Down
2 changes: 1 addition & 1 deletion Release/src/http/client/x509_cert_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,4 +641,4 @@ bool verify_X509_cert_chain(const std::vector<std::string>& certChain,
} // namespace http
} // namespace web

#endif
#endif

0 comments on commit 68c40a7

Please sign in to comment.