Skip to content

Commit

Permalink
H1b (#54)
Browse files Browse the repository at this point in the history
* Update APIs to match H1B revision
* Revert io, http, auth snapshots to standard releases
  • Loading branch information
bretambrose authored Aug 19, 2019
1 parent 13123e5 commit 6262664
Show file tree
Hide file tree
Showing 18 changed files with 930 additions and 196 deletions.
6 changes: 3 additions & 3 deletions aws-common-runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ if (UNIX AND NOT APPLE)
endif()

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

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

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

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

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

add_dependencies(AwsCCompression AwsCCommon)
Expand Down
3 changes: 3 additions & 0 deletions include/aws/crt/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <aws/io/socket.h>
#include <aws/mqtt/mqtt.h>

#include <functional>
#include <list>
#include <map>
#include <sstream>
Expand Down Expand Up @@ -104,5 +105,7 @@ namespace Aws
return std::shared_ptr<T>(t, [allocator](T *obj) { Delete(obj, allocator); });
}

template <typename T> using ScopedResource = std::unique_ptr<T, std::function<void(T *)>>;

} // namespace Crt
} // namespace Aws
2 changes: 1 addition & 1 deletion include/aws/crt/auth/Credentials.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace Aws

operator bool() const noexcept;

aws_credentials *GetUnderlyingHandle() const noexcept;
aws_credentials *GetUnderlyingHandle() const noexcept { return m_credentials; }

private:
aws_credentials *m_credentials;
Expand Down
112 changes: 112 additions & 0 deletions include/aws/crt/auth/Signing.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#pragma once
/*
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

#include <aws/crt/Exports.h>

#include <aws/auth/signing_config.h>

#include <functional>
#include <memory>

namespace Aws
{
namespace Crt
{
namespace Http
{
class HttpRequest;
}

namespace Auth
{
enum class SigningConfigType
{
Aws = AWS_SIGNING_CONFIG_AWS
};

/*
* Base class for all different signing configurations. Type functions as a
* primitive RTTI for downcasting.
*/
class AWS_CRT_CPP_API ISigningConfig
{
public:
ISigningConfig() = default;
ISigningConfig(const ISigningConfig &) = delete;
ISigningConfig(ISigningConfig &&) = delete;
ISigningConfig &operator=(const ISigningConfig &) = delete;
ISigningConfig &operator=(ISigningConfig &&) = delete;

virtual ~ISigningConfig() = default;

virtual SigningConfigType GetType(void) const = 0;
};

/*
* Abstract base for all http request signers. Synchronous interface. Intended to
* be a tight wrapper around aws-c-* signer implementations.
*/
class AWS_CRT_CPP_API IHttpRequestSigner
{
public:
IHttpRequestSigner() = default;
IHttpRequestSigner(const IHttpRequestSigner &) = delete;
IHttpRequestSigner(IHttpRequestSigner &&) = delete;
IHttpRequestSigner &operator=(const IHttpRequestSigner &) = delete;
IHttpRequestSigner &operator=(IHttpRequestSigner &&) = delete;

virtual ~IHttpRequestSigner() = default;

virtual bool SignRequest(Aws::Crt::Http::HttpRequest &request, const ISigningConfig *config) = 0;

virtual operator bool() const = 0;
};

/*
* Signing pipeline callback. The second parameter is an aws error code, The signing was successful
* iff the error code is AWS_ERROR_SUCCESS.
*/
using OnHttpRequestSigningComplete =
std::function<void(const std::shared_ptr<Aws::Crt::Http::HttpRequest> &, int)>;

/*
* Abstract base for a complete signing process. While the primary difference between this
* and IHttpRequestSigner is one of async vs. sync, the intent of this interface is to encapsulate an
* entire signing process that may involve multiple asynchronous steps (Sigv4 with credentials fetch, OAuth,
* etc...)
*/
class AWS_CRT_CPP_API IHttpRequestSigningPipeline
{
public:
IHttpRequestSigningPipeline() = default;
IHttpRequestSigningPipeline(const IHttpRequestSigningPipeline &) = delete;
IHttpRequestSigningPipeline(IHttpRequestSigningPipeline &&) = delete;
IHttpRequestSigningPipeline &operator=(const IHttpRequestSigningPipeline &) = delete;
IHttpRequestSigningPipeline &operator=(IHttpRequestSigningPipeline &&) = delete;

virtual ~IHttpRequestSigningPipeline() = default;

virtual void SignRequest(
const std::shared_ptr<Aws::Crt::Http::HttpRequest> &request,
const std::shared_ptr<ISigningConfig> &config,
const OnHttpRequestSigningComplete &completionCallback) = 0;

virtual operator bool() const = 0;
};

} // namespace Auth
} // namespace Crt
} // namespace Aws
172 changes: 172 additions & 0 deletions include/aws/crt/auth/Sigv4Signing.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#pragma once
/*
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

#include <aws/crt/Exports.h>

#include <aws/crt/DateTime.h>
#include <aws/crt/Types.h>
#include <aws/crt/auth/Signing.h>

struct aws_signer;
struct aws_signing_config_aws;

namespace Aws
{
namespace Crt
{
namespace Auth
{
class Credentials;
class ICredentialsProvider;

enum class SigningAlgorithm
{
SigV4Header = AWS_SIGNING_ALGORITHM_SIG_V4_HEADER,
SigV4QueryParam = AWS_SIGNING_ALGORITHM_SIG_V4_QUERY_PARAM,

Count = AWS_SIGNING_ALGORITHM_COUNT
};

/*
* Wrapper around the configuration structure specific to the AWS
* Sigv4 signing process
*/
class AWS_CRT_CPP_API AwsSigningConfig : public ISigningConfig
{
public:
AwsSigningConfig(Allocator *allocator = DefaultAllocator());
virtual ~AwsSigningConfig();

virtual SigningConfigType GetType(void) const noexcept override { return SigningConfigType::Aws; }

/*
* Credentials to sign the request with
*/
std::shared_ptr<Credentials> GetCredentials() const noexcept;
void SetCredentials(const std::shared_ptr<Credentials> &credentials) noexcept;

/*
* What signing process do we want to invoke
*/
SigningAlgorithm GetSigningAlgorithm() const noexcept;
void SetSigningAlgorithm(SigningAlgorithm algorithm) noexcept;

/*
* The region to sign against
*/
ByteCursor GetRegion() const noexcept;
void SetRegion(ByteCursor region) noexcept;

/*
* name of service to sign a request for
*/
ByteCursor GetService() const noexcept;
void SetService(ByteCursor service) noexcept;

/*
* Timestamp to use during the signing process.
*/
DateTime GetDate() const noexcept;
void SetDate(const DateTime &date) noexcept;

/*
* We assume the uri will be encoded once in preparation for transmission. Certain services
* do not decode before checking signature, requiring us to actually double-encode the uri in the
* canonical request in order to pass a signature check.
*/
bool GetUseDoubleUriEncode() const noexcept;
void SetUseDoubleUriEncode(bool useDoubleUriEncode) noexcept;

/*
* Controls whether or not the uri paths should be normalized when building the canonical request
*/
bool GetShouldNormalizeUriPath() const noexcept;
void SetShouldNormalizeUriPath(bool shouldNormalizeUriPath) noexcept;

/*
* If true adds the x-amz-content-sha256 header (with appropriate value) to the canonical request,
* otherwise does nothing
*/
bool GetSignBody() const noexcept;
void SetSignBody(bool signBody) noexcept;

private:
Allocator *m_allocator;

std::shared_ptr<Credentials> m_credentials;

struct aws_signing_config_aws *m_config;
};

/*
* Http request signer that wraps any aws-c-* signer implementation
*/
class AWS_CRT_CPP_API AwsHttpRequestSigner : public IHttpRequestSigner
{
public:
AwsHttpRequestSigner(aws_signer *signer, Allocator *allocator = DefaultAllocator());
virtual ~AwsHttpRequestSigner();

virtual operator bool() const override { return m_signer != nullptr; }

protected:
Allocator *m_allocator;

aws_signer *m_signer;
};

/*
* Http request signer that performs Aws Sigv4 signing
*/
class AWS_CRT_CPP_API Sigv4HttpRequestSigner : public AwsHttpRequestSigner
{
public:
Sigv4HttpRequestSigner(Allocator *allocator = DefaultAllocator());
virtual ~Sigv4HttpRequestSigner() = default;

virtual bool SignRequest(Aws::Crt::Http::HttpRequest &request, const ISigningConfig *config) override;
};

/*
* Signing pipeline that performs Aws Sigv4 signing with credentials sourced from
* an internally referenced credentials provider
*/
class AWS_CRT_CPP_API Sigv4HttpRequestSigningPipeline : public IHttpRequestSigningPipeline
{
public:
Sigv4HttpRequestSigningPipeline(
const std::shared_ptr<ICredentialsProvider> &credentialsProvider,
Allocator *allocator = DefaultAllocator());

virtual ~Sigv4HttpRequestSigningPipeline();

virtual void SignRequest(
const std::shared_ptr<Aws::Crt::Http::HttpRequest> &request,
const std::shared_ptr<ISigningConfig> &config,
const OnHttpRequestSigningComplete &completionCallback) override;

virtual operator bool() const override
{
return m_signer != nullptr && m_credentialsProvider != nullptr;
}

private:
std::shared_ptr<Sigv4HttpRequestSigner> m_signer;
std::shared_ptr<ICredentialsProvider> m_credentialsProvider;
};
} // namespace Auth
} // namespace Crt
} // namespace Aws
Loading

0 comments on commit 6262664

Please sign in to comment.