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
+ /*
44
+ * Wrapper around the configuration structure specific to the AWS
45
+ * Sigv4 signing process
46
+ */
47
+ class AWS_CRT_CPP_API AwsSigningConfig : public ISigningConfig
48
+ {
49
+ public:
50
+ AwsSigningConfig (Allocator *allocator = DefaultAllocator());
51
+ virtual ~AwsSigningConfig ();
52
+
53
+ virtual SigningConfigType GetType (void ) const noexcept override { return SigningConfigType::Aws; }
54
+
55
+ /*
56
+ * Credentials to sign the request with
57
+ */
58
+ std::shared_ptr<Credentials> GetCredentials () const noexcept ;
59
+ void SetCredentials (const std::shared_ptr<Credentials> &credentials) noexcept ;
60
+
61
+ /*
62
+ * What signing process do we want to invoke
63
+ */
64
+ SigningAlgorithm GetSigningAlgorithm () const noexcept ;
65
+ void SetSigningAlgorithm (SigningAlgorithm algorithm) noexcept ;
66
+
67
+ /*
68
+ * The region to sign against
69
+ */
70
+ ByteCursor GetRegion () const noexcept ;
71
+ void SetRegion (ByteCursor region) noexcept ;
72
+
73
+ /*
74
+ * name of service to sign a request for
75
+ */
76
+ ByteCursor GetService () const noexcept ;
77
+ void SetService (ByteCursor service) noexcept ;
78
+
79
+ /*
80
+ * Timestamp to use during the signing process.
81
+ */
82
+ DateTime GetDate () const noexcept ;
83
+ void SetDate (const DateTime &date) noexcept ;
84
+
85
+ /*
86
+ * We assume the uri will be encoded once in preparation for transmission. Certain services
87
+ * do not decode before checking signature, requiring us to actually double-encode the uri in the
88
+ * canonical request in order to pass a signature check.
89
+ */
90
+ bool GetUseDoubleUriEncode () const noexcept ;
91
+ void SetUseDoubleUriEncode (bool useDoubleUriEncode) noexcept ;
92
+
93
+ /*
94
+ * Controls whether or not the uri paths should be normalized when building the canonical request
95
+ */
96
+ bool GetShouldNormalizeUriPath () const noexcept ;
97
+ void SetShouldNormalizeUriPath (bool shouldNormalizeUriPath) noexcept ;
98
+
99
+ /*
100
+ * If true adds the x-amz-content-sha256 header (with appropriate value) to the canonical request,
101
+ * otherwise does nothing
102
+ */
103
+ bool GetSignBody () const noexcept ;
104
+ void SetSignBody (bool signBody) noexcept ;
105
+
106
+ private:
107
+ Allocator *m_allocator;
108
+
109
+ std::shared_ptr<Credentials> m_credentials;
110
+
111
+ struct aws_signing_config_aws *m_config;
112
+ };
113
+
114
+ /*
115
+ * Http request signer that wraps any aws-c-* signer implementation
116
+ */
117
+ class AWS_CRT_CPP_API AwsHttpRequestSigner : public IHttpRequestSigner
118
+ {
119
+ public:
120
+ AwsHttpRequestSigner (aws_signer *signer, Allocator *allocator = DefaultAllocator());
121
+ virtual ~AwsHttpRequestSigner ();
122
+
123
+ virtual operator bool () const override { return m_signer != nullptr ; }
124
+
125
+ protected:
126
+ Allocator *m_allocator;
127
+
128
+ aws_signer *m_signer;
129
+ };
130
+
131
+ /*
132
+ * Http request signer that performs Aws Sigv4 signing
133
+ */
134
+ class AWS_CRT_CPP_API Sigv4HttpRequestSigner : public AwsHttpRequestSigner
135
+ {
136
+ public:
137
+ Sigv4HttpRequestSigner (Allocator *allocator = DefaultAllocator());
138
+ virtual ~Sigv4HttpRequestSigner () = default ;
139
+
140
+ virtual bool SignRequest (Aws::Crt::Http::HttpRequest &request, const ISigningConfig *config) override ;
141
+ };
142
+
143
+ /*
144
+ * Signing pipeline that performs Aws Sigv4 signing with credentials sourced from
145
+ * an internally referenced credentials provider
146
+ */
147
+ class AWS_CRT_CPP_API Sigv4HttpRequestSigningPipeline : public IHttpRequestSigningPipeline
148
+ {
149
+ public:
150
+ Sigv4HttpRequestSigningPipeline (
151
+ const std::shared_ptr<ICredentialsProvider> &credentialsProvider,
152
+ Allocator *allocator = DefaultAllocator());
153
+
154
+ virtual ~Sigv4HttpRequestSigningPipeline ();
155
+
156
+ virtual void SignRequest (
157
+ const std::shared_ptr<Aws::Crt::Http::HttpRequest> &request,
158
+ const std::shared_ptr<ISigningConfig> &config,
159
+ const OnHttpRequestSigningComplete &completionCallback) override ;
160
+
161
+ virtual operator bool () const override
162
+ {
163
+ return m_signer != nullptr && m_credentialsProvider != nullptr ;
164
+ }
165
+
166
+ private:
167
+ std::shared_ptr<Sigv4HttpRequestSigner> m_signer;
168
+ std::shared_ptr<ICredentialsProvider> m_credentialsProvider;
169
+ };
170
+ } // namespace Auth
171
+ } // namespace Crt
172
+ } // namespace Aws
0 commit comments