aws-crt-cpp
Sigv4Signing.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License").
6  * You may not use this file except in compliance with the License.
7  * A copy of the License is located at
8  *
9  * http://aws.amazon.com/apache2.0
10  *
11  * or in the "license" file accompanying this file. This file is distributed
12  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16 
17 #include <aws/crt/Exports.h>
18 
19 #include <aws/crt/DateTime.h>
20 #include <aws/crt/Types.h>
21 #include <aws/crt/auth/Signing.h>
22 
23 struct aws_signer;
24 struct aws_signing_config_aws;
25 
26 namespace Aws
27 {
28  namespace Crt
29  {
30  namespace Auth
31  {
32  class Credentials;
33  class ICredentialsProvider;
34 
35  enum class SigningAlgorithm
36  {
37  SigV4Header = AWS_SIGNING_ALGORITHM_SIG_V4_HEADER,
38  SigV4QueryParam = AWS_SIGNING_ALGORITHM_SIG_V4_QUERY_PARAM,
39 
40  Count = AWS_SIGNING_ALGORITHM_COUNT
41  };
42 
43  enum class BodySigningType
44  {
45  NoSigning = AWS_BODY_SIGNING_OFF,
46  SignBody = AWS_BODY_SIGNING_ON,
47  UnsignedPayload = AWS_BODY_SIGNING_UNSIGNED_PAYLOAD
48  };
49 
50  using ShouldSignParameterCb = bool (*)(const Crt::ByteCursor *, void *);
51 
57  {
58  public:
60  virtual ~AwsSigningConfig();
61 
62  virtual SigningConfigType GetType() const noexcept override { return SigningConfigType::Aws; }
63 
67  SigningAlgorithm GetSigningAlgorithm() const noexcept;
68 
72  void SetSigningAlgorithm(SigningAlgorithm algorithm) noexcept;
73 
77  const Crt::String &GetRegion() const noexcept;
78 
82  void SetRegion(const Crt::String &region) noexcept;
83 
87  const Crt::String &GetService() const noexcept;
88 
92  void SetService(const Crt::String &service) noexcept;
93 
97  DateTime GetSigningTimepoint() const noexcept;
98 
102  void SetSigningTimepoint(const DateTime &date) noexcept;
103 
104  /*
105  * We assume the uri will be encoded once in preparation for transmission. Certain services
106  * do not decode before checking signature, requiring us to actually double-encode the uri in the
107  * canonical request in order to pass a signature check.
108  */
109 
114  bool GetUseDoubleUriEncode() const noexcept;
115 
120  void SetUseDoubleUriEncode(bool useDoubleUriEncode) noexcept;
121 
125  bool GetShouldNormalizeUriPath() const noexcept;
126 
130  void SetShouldNormalizeUriPath(bool shouldNormalizeUriPath) noexcept;
131 
135  ShouldSignParameterCb GetShouldSignParameterCallback() const noexcept;
136 
141  void SetShouldSignHeadersCallback(ShouldSignParameterCb shouldSignParameterCb) noexcept;
142 
147  BodySigningType GetBodySigningType() const noexcept;
148 
153  void SetBodySigningType(BodySigningType bodysigningType) noexcept;
154 
158  const std::shared_ptr<ICredentialsProvider> &GetCredentialsProvider() const noexcept;
159 
163  void SetCredentialsProvider(const std::shared_ptr<ICredentialsProvider> &credsProvider) noexcept;
164 
166  const struct aws_signing_config_aws *GetUnderlyingHandle() const noexcept;
167 
168  private:
169  Allocator *m_allocator;
170  std::shared_ptr<ICredentialsProvider> m_credentials;
171  struct aws_signing_config_aws m_config;
172  Crt::String m_signingRegion;
173  Crt::String m_serviceName;
174  };
175 
180  {
181  public:
183  virtual ~Sigv4HttpRequestSigner() = default;
184 
185  bool IsValid() const override { return true; }
189  virtual bool SignRequest(
190  const std::shared_ptr<Aws::Crt::Http::HttpRequest> &request,
191  const ISigningConfig &config,
192  const OnHttpRequestSigningComplete &completionCallback) override;
193 
194  private:
195  Allocator *m_allocator;
196  };
197  } // namespace Auth
198  } // namespace Crt
199 } // namespace Aws
Aws::Crt::Allocator
aws_allocator Allocator
Definition: StlAllocator.h:25
Aws::Crt::Auth::SigningAlgorithm::Count
@ Count
Aws::Crt::Auth::SigningAlgorithm
SigningAlgorithm
Definition: Sigv4Signing.h:36
Aws::Crt::Auth::SigningAlgorithm::SigV4Header
@ SigV4Header
Types.h
AWS_CRT_CPP_API
#define AWS_CRT_CPP_API
Definition: Exports.h:34
Aws::Crt::Auth::ISigningConfig
Definition: Signing.h:52
Aws::Crt::Auth::SigningAlgorithm::SigV4QueryParam
@ SigV4QueryParam
DateTime.h
Aws::Crt::Auth::SigningConfigType
SigningConfigType
Definition: Signing.h:36
Aws::Crt::Auth::Sigv4HttpRequestSigner::~Sigv4HttpRequestSigner
virtual ~Sigv4HttpRequestSigner()=default
Aws::Crt::ByteCursor
aws_byte_cursor ByteCursor
Definition: Types.h:44
Aws::Crt::Auth::BodySigningType::SignBody
@ SignBody
Aws::Crt::Auth::Sigv4HttpRequestSigner
Definition: Sigv4Signing.h:180
Aws::Crt::Auth::BodySigningType::NoSigning
@ NoSigning
Aws::Crt::g_allocator
Allocator * g_allocator
Definition: Api.cpp:28
Aws::Crt::Auth::ShouldSignParameterCb
bool(*)(const Crt::ByteCursor *, void *) ShouldSignParameterCb
Definition: Sigv4Signing.h:50
Aws::Crt::Auth::IHttpRequestSigner
Definition: Signing.h:73
Aws::Crt::Auth::ICredentialsProvider
Definition: Credentials.h:97
Aws::Crt::Auth::AwsSigningConfig
Definition: Sigv4Signing.h:57
Aws::Crt::Auth::Sigv4HttpRequestSigner::IsValid
bool IsValid() const override
Definition: Sigv4Signing.h:185
Aws::Crt::Auth::AwsSigningConfig::GetType
virtual SigningConfigType GetType() const noexcept override
Definition: Sigv4Signing.h:62
Aws
Definition: Api.h:25
Aws::Crt::Auth::BodySigningType
BodySigningType
Definition: Sigv4Signing.h:44
Exports.h
Aws::Crt::Auth::OnHttpRequestSigningComplete
std::function< void(const std::shared_ptr< Aws::Crt::Http::HttpRequest > &, int)> OnHttpRequestSigningComplete
Definition: Signing.h:45
Aws::Crt::Auth::BodySigningType::UnsignedPayload
@ UnsignedPayload
Aws::Crt::Auth::SigningConfigType::Aws
@ Aws
Signing.h
Aws::Crt::String
std::basic_string< char, std::char_traits< char >, StlAllocator< char > > String
Definition: Types.h:58
Aws::Crt::DateTime
Definition: DateTime.h:63