use policy for both clients

This commit is contained in:
Victor Vazquez 2022-04-14 01:26:49 -07:00
parent 2a4f62d88f
commit a8f63c7e6e
4 changed files with 43 additions and 28 deletions

View File

@ -57,6 +57,11 @@ AttestationAdministrationClient::AttestationAdministrationClient(
m_apiVersion = options.Version.ToString();
std::vector<std::unique_ptr<HttpPolicy>> perCallpolicies;
#if defined(BUILD_TRANSPORT_WINHTTP_ADAPTER)
// This configuration will make winHTTP to disable client certificate for all attestation requests
perCallpolicies.emplace_back(std::make_unique<SetNoClientCertificatePolicy>());
#endif
m_pipeline = std::make_shared<Azure::Core::Http::_internal::HttpPipeline>(
options,
"Attestation",

View File

@ -26,33 +26,6 @@ using namespace Azure::Core::Http::Policies;
using namespace Azure::Core::Http::Policies::_internal;
using namespace Azure::Core::Http::_internal;
#if defined(BUILD_TRANSPORT_WINHTTP_ADAPTER)
// Whenever winHTTP transport is built, create a policy to make request with no client certificate
// for attestation requests
#include "azure/core/http/win_http_transport.hpp"
namespace {
class SetNoClientCertificatePolicy : public Azure::Core::Http::Policies::HttpPolicy {
public:
std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy> Clone() const override
{
return std::make_unique<SetNoClientCertificatePolicy>();
}
std::unique_ptr<Azure::Core::Http::RawResponse> Send(
Azure::Core::Http::Request& request,
Azure::Core::Http::Policies::NextHttpPolicy nextHttpPolicy,
const Azure::Core::Context& ctx) const override
{
return nextHttpPolicy.Send(
request,
Azure::Core::Http::_internal::WinHttpTransportContextProvider::
GetNoClientCertificateContext(ctx));
}
};
} // namespace
#endif
AttestationClient::AttestationClient(
std::string const& endpoint,
std::shared_ptr<Core::Credentials::TokenCredential const> credential,

View File

@ -8,6 +8,7 @@
*
*/
#include "attestation_client_models_private.hpp"
#include "attestation_client_private.hpp"
#include "crypto/inc/crypto.hpp"
#include <azure/core/internal/json/json.hpp>
#include <chrono>
@ -18,8 +19,21 @@
using namespace Azure::Security::Attestation::_detail;
namespace Azure { namespace Security { namespace Attestation { namespace _detail {
#if defined(BUILD_TRANSPORT_WINHTTP_ADAPTER)
}}}} // namespace Azure::Security::Attestation::_detail
std::unique_ptr<Azure::Core::Http::RawResponse> SetNoClientCertificatePolicy::Send(
Azure::Core::Http::Request& request,
Azure::Core::Http::Policies::NextHttpPolicy nextHttpPolicy,
const Azure::Core::Context& ctx) const
{
return nextHttpPolicy.Send(
request,
Azure::Core::Http::_internal::WinHttpTransportContextProvider::
GetNoClientCertificateContext(ctx));
}
};
#endif
}}} // namespace Azure::Security::Attestation::_detail
namespace Azure {
namespace Security {

View File

@ -26,6 +26,12 @@
#include <string>
#include <vector>
#if defined(BUILD_TRANSPORT_WINHTTP_ADAPTER)
// Whenever winHTTP transport is built, create a policy to make request with no client certificate
// for attestation requests
#include "azure/core/http/win_http_transport.hpp"
#endif
namespace Azure { namespace Security { namespace Attestation { namespace _detail {
template <class T> class EmptyDeserializer {
@ -448,4 +454,21 @@ namespace Azure { namespace Security { namespace Attestation { namespace _detail
*/
operator Models::AttestationToken<T> const &() const { return m_token; }
};
#if defined(BUILD_TRANSPORT_WINHTTP_ADAPTER)
class SetNoClientCertificatePolicy : public Azure::Core::Http::Policies::HttpPolicy {
public:
std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy> Clone() const override
{
return std::make_unique<SetNoClientCertificatePolicy>();
}
std::unique_ptr<Azure::Core::Http::RawResponse> Send(
Azure::Core::Http::Request& request,
Azure::Core::Http::Policies::NextHttpPolicy nextHttpPolicy,
const Azure::Core::Context& ctx) const override;
};
#endif
}}}} // namespace Azure::Security::Attestation::_detail