Skip to content

Commit 6262664

Browse files
authored
H1b (aws#54)
* Update APIs to match H1B revision * Revert io, http, auth snapshots to standard releases
1 parent 13123e5 commit 6262664

18 files changed

+930
-196
lines changed

aws-common-runtime/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ if (UNIX AND NOT APPLE)
2727
endif()
2828

2929
set(AWS_C_IO_URL "https://github.com/awslabs/aws-c-io.git")
30-
set(AWS_C_IO_SHA "v0.4.1")
30+
set(AWS_C_IO_SHA "v0.4.4")
3131
include(BuildAwsCIO)
3232

3333
set(AWS_C_COMPRESSION_URL "https://github.com/awslabs/aws-c-compression.git")
3434
set(AWS_C_COMPRESSION_SHA "v0.2.2")
3535
include(BuildAwsCCompression)
3636

3737
set(AWS_C_HTTP_URL "https://github.com/awslabs/aws-c-http.git")
38-
set(AWS_C_HTTP_SHA "v0.3.2")
38+
set(AWS_C_HTTP_SHA "v0.4.0")
3939
include(BuildAwsCHttp)
4040

4141
set(AWS_C_MQTT_URL "https://github.com/awslabs/aws-c-mqtt.git")
@@ -47,7 +47,7 @@ set(AWS_C_CAL_SHA "v0.1.5")
4747
include(BuildAwsCCal)
4848

4949
set(AWS_C_AUTH_URL "https://github.com/awslabs/aws-c-auth.git")
50-
set(AWS_C_AUTH_SHA "v0.1.1")
50+
set(AWS_C_AUTH_SHA "v0.2.0")
5151
include(BuildAwsCAuth)
5252

5353
add_dependencies(AwsCCompression AwsCCommon)

include/aws/crt/Types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <aws/io/socket.h>
2222
#include <aws/mqtt/mqtt.h>
2323

24+
#include <functional>
2425
#include <list>
2526
#include <map>
2627
#include <sstream>
@@ -104,5 +105,7 @@ namespace Aws
104105
return std::shared_ptr<T>(t, [allocator](T *obj) { Delete(obj, allocator); });
105106
}
106107

108+
template <typename T> using ScopedResource = std::unique_ptr<T, std::function<void(T *)>>;
109+
107110
} // namespace Crt
108111
} // namespace Aws

include/aws/crt/auth/Credentials.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace Aws
6262

6363
operator bool() const noexcept;
6464

65-
aws_credentials *GetUnderlyingHandle() const noexcept;
65+
aws_credentials *GetUnderlyingHandle() const noexcept { return m_credentials; }
6666

6767
private:
6868
aws_credentials *m_credentials;

include/aws/crt/auth/Signing.h

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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/auth/signing_config.h>
20+
21+
#include <functional>
22+
#include <memory>
23+
24+
namespace Aws
25+
{
26+
namespace Crt
27+
{
28+
namespace Http
29+
{
30+
class HttpRequest;
31+
}
32+
33+
namespace Auth
34+
{
35+
enum class SigningConfigType
36+
{
37+
Aws = AWS_SIGNING_CONFIG_AWS
38+
};
39+
40+
/*
41+
* Base class for all different signing configurations. Type functions as a
42+
* primitive RTTI for downcasting.
43+
*/
44+
class AWS_CRT_CPP_API ISigningConfig
45+
{
46+
public:
47+
ISigningConfig() = default;
48+
ISigningConfig(const ISigningConfig &) = delete;
49+
ISigningConfig(ISigningConfig &&) = delete;
50+
ISigningConfig &operator=(const ISigningConfig &) = delete;
51+
ISigningConfig &operator=(ISigningConfig &&) = delete;
52+
53+
virtual ~ISigningConfig() = default;
54+
55+
virtual SigningConfigType GetType(void) const = 0;
56+
};
57+
58+
/*
59+
* Abstract base for all http request signers. Synchronous interface. Intended to
60+
* be a tight wrapper around aws-c-* signer implementations.
61+
*/
62+
class AWS_CRT_CPP_API IHttpRequestSigner
63+
{
64+
public:
65+
IHttpRequestSigner() = default;
66+
IHttpRequestSigner(const IHttpRequestSigner &) = delete;
67+
IHttpRequestSigner(IHttpRequestSigner &&) = delete;
68+
IHttpRequestSigner &operator=(const IHttpRequestSigner &) = delete;
69+
IHttpRequestSigner &operator=(IHttpRequestSigner &&) = delete;
70+
71+
virtual ~IHttpRequestSigner() = default;
72+
73+
virtual bool SignRequest(Aws::Crt::Http::HttpRequest &request, const ISigningConfig *config) = 0;
74+
75+
virtual operator bool() const = 0;
76+
};
77+
78+
/*
79+
* Signing pipeline callback. The second parameter is an aws error code, The signing was successful
80+
* iff the error code is AWS_ERROR_SUCCESS.
81+
*/
82+
using OnHttpRequestSigningComplete =
83+
std::function<void(const std::shared_ptr<Aws::Crt::Http::HttpRequest> &, int)>;
84+
85+
/*
86+
* Abstract base for a complete signing process. While the primary difference between this
87+
* and IHttpRequestSigner is one of async vs. sync, the intent of this interface is to encapsulate an
88+
* entire signing process that may involve multiple asynchronous steps (Sigv4 with credentials fetch, OAuth,
89+
* etc...)
90+
*/
91+
class AWS_CRT_CPP_API IHttpRequestSigningPipeline
92+
{
93+
public:
94+
IHttpRequestSigningPipeline() = default;
95+
IHttpRequestSigningPipeline(const IHttpRequestSigningPipeline &) = delete;
96+
IHttpRequestSigningPipeline(IHttpRequestSigningPipeline &&) = delete;
97+
IHttpRequestSigningPipeline &operator=(const IHttpRequestSigningPipeline &) = delete;
98+
IHttpRequestSigningPipeline &operator=(IHttpRequestSigningPipeline &&) = delete;
99+
100+
virtual ~IHttpRequestSigningPipeline() = default;
101+
102+
virtual void SignRequest(
103+
const std::shared_ptr<Aws::Crt::Http::HttpRequest> &request,
104+
const std::shared_ptr<ISigningConfig> &config,
105+
const OnHttpRequestSigningComplete &completionCallback) = 0;
106+
107+
virtual operator bool() const = 0;
108+
};
109+
110+
} // namespace Auth
111+
} // namespace Crt
112+
} // namespace Aws

include/aws/crt/auth/Sigv4Signing.h

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
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

Comments
 (0)