From 8045aec2237898d468c391e63d40c0fccf6ce461 Mon Sep 17 00:00:00 2001 From: Avery Kuo Date: Mon, 16 Nov 2026 13:39:28 -0500 Subject: [PATCH 1/3] Remove the deprecated S3 encryption clients and unused core code Remove S3EncryptionClient, S3EncryptionClientV2 and CryptoConfigurationV2, and make S3EncryptionClientBase's constructors protected so the base can't be built directly with legacy encryption settings. The V1/V2-write, V3-read integration tests now write legacy objects through a test-only subclass of the base. Remove Aws::Utils::GetTheLights, AWSMultiMap.h and CommonCryptorSPI.h, which nothing used. Aws::MultiMap stays in AWSMap.h because URI.h uses it. The credential provider removals are held back: ProfileCredentialsProvider does not yet return the account ID from the credentials file or credential_process, so it cannot replace them. --- ...ing-change-remove-s3-encryption-v1-v2.json | 6 + ...eaking-change-remove-unused-core-code.json | 6 + .../aws/core/external/CommonCryptorSPI.h | 480 ---------- .../include/aws/core/utils/GetTheLights.h | 35 - .../aws/core/utils/memory/stl/AWSMultiMap.h | 19 - .../source/utils/GetTheLights.cpp | 36 - .../SUPPORT_POLICY.rst | 6 +- .../aws/s3-encryption/CryptoConfiguration.h | 24 - .../aws/s3-encryption/S3EncryptionClient.h | 109 +-- .../s3-encryption/CryptoConfiguration.cpp | 16 - .../s3-encryption/S3EncryptionClient.cpp | 18 - .../utils/GetTheLightsTest.cpp | 37 - .../LiveClientTests.cpp | 866 +----------------- 13 files changed, 29 insertions(+), 1629 deletions(-) create mode 100644 .changelog/breaking-change-remove-s3-encryption-v1-v2.json create mode 100644 .changelog/breaking-change-remove-unused-core-code.json delete mode 100644 src/aws-cpp-sdk-core/include/aws/core/external/CommonCryptorSPI.h delete mode 100644 src/aws-cpp-sdk-core/include/aws/core/utils/GetTheLights.h delete mode 100644 src/aws-cpp-sdk-core/include/aws/core/utils/memory/stl/AWSMultiMap.h delete mode 100644 src/aws-cpp-sdk-core/source/utils/GetTheLights.cpp delete mode 100644 tests/aws-cpp-sdk-core-tests/utils/GetTheLightsTest.cpp diff --git a/.changelog/breaking-change-remove-s3-encryption-v1-v2.json b/.changelog/breaking-change-remove-s3-encryption-v1-v2.json new file mode 100644 index 000000000000..00a689026a7a --- /dev/null +++ b/.changelog/breaking-change-remove-s3-encryption-v1-v2.json @@ -0,0 +1,6 @@ +{ + "type": "breaking-change", + "category": "aws-cpp-sdk-s3-encryption", + "contributor": "averyk22", + "description": "Remove the deprecated S3EncryptionClient and S3EncryptionClientV2, along with CryptoConfigurationV2. Use S3EncryptionClientV3 with CryptoConfigurationV3; call AllowLegacy() on the configuration to keep reading objects the older clients wrote. S3EncryptionClientBase's constructors are now protected, so the base client can no longer be built directly with legacy encryption settings." +} diff --git a/.changelog/breaking-change-remove-unused-core-code.json b/.changelog/breaking-change-remove-unused-core-code.json new file mode 100644 index 000000000000..1ffb657a495c --- /dev/null +++ b/.changelog/breaking-change-remove-unused-core-code.json @@ -0,0 +1,6 @@ +{ + "type": "breaking-change", + "category": "aws-cpp-sdk-core", + "contributor": "averyk22", + "description": "Remove code the SDK never used: Aws::Utils::GetTheLights, the aws/core/utils/memory/stl/AWSMultiMap.h header and aws/core/external/CommonCryptorSPI.h. Aws::MultiMap is still available from aws/core/utils/memory/stl/AWSMap.h." +} diff --git a/src/aws-cpp-sdk-core/include/aws/core/external/CommonCryptorSPI.h b/src/aws-cpp-sdk-core/include/aws/core/external/CommonCryptorSPI.h deleted file mode 100644 index e2aaf27fda53..000000000000 --- a/src/aws-cpp-sdk-core/include/aws/core/external/CommonCryptorSPI.h +++ /dev/null @@ -1,480 +0,0 @@ -/* - * Copyright (c) 2010 Apple Inc. All Rights Reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ - -#ifndef _CC_CryptorSPI_H_ -#define _CC_CryptorSPI_H_ - -#include -#include - -#include -#include -#include - -#include - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(_WIN32) - int timingsafe_bcmp(const void *b1, const void *b2, size_t n); -#endif -/* - This is an SPI header. It includes some work in progress implementation notes that - will be removed when this is promoted to an API set. -*/ - -/* - Private Ciphers - */ - -/* Lion SPI name for no padding. Defining for compatibility. Is now - ccNoPadding in CommonCryptor.h - */ - -enum { - ccDefaultPadding = 0, -}; - - -enum { - kCCAlgorithmAES128NoHardware = 20, - kCCAlgorithmAES128WithHardware = 21 -}; - -/* - Private Modes - */ -enum { - kCCModeGCM = 11, - kCCModeCCM = 12, -}; - -/* - Private Paddings - */ -enum { - ccCBCCTS1 = 10, - ccCBCCTS2 = 11, - ccCBCCTS3 = 12, -}; - -/* - Private Cryptor direction (op) - */ -enum { - kCCBoth = 3, -}; - - - - -/* - Supports a mode call of - int mode_setup(int cipher, const unsigned char *IV, const unsigned char *key, int keylen, - const unsigned char *tweak, int tweaklen, int num_rounds, int options, mode_context *ctx); -*/ - -/* User supplied space for the CryptorRef */ - -CCCryptorStatus CCCryptorCreateFromDataWithMode( - CCOperation op, /* kCCEncrypt, kCCEncrypt, kCCBoth (default for BlockMode) */ - CCMode mode, - CCAlgorithm alg, - CCPadding padding, - const void *iv, /* optional initialization vector */ - const void *key, /* raw key material */ - size_t keyLength, - const void *tweak, /* raw tweak material */ - size_t tweakLength, - int numRounds, - CCModeOptions options, - const void *data, /* caller-supplied memory */ - size_t dataLength, /* length of data in bytes */ - CCCryptorRef *cryptorRef, /* RETURNED */ - size_t *dataUsed) /* optional, RETURNED */ -API_AVAILABLE(macos(10.7), ios(5.0)); - - -/* - Assuming we can use existing CCCryptorCreateFromData for all modes serviced by these: - int mode_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, mode_context *ctx); - int mode_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, mode_context *ctx); -*/ - -/* - Block mode encrypt and decrypt interfaces for IV tweaked blocks (XTS and CBC) - - int mode_encrypt_tweaked(const unsigned char *pt, unsigned long len, unsigned char *ct, const unsigned char *tweak, mode_context *ctx); - int mode_decrypt_tweaked(const unsigned char *ct, unsigned long len, unsigned char *pt, const unsigned char *tweak, mode_context *ctx); -*/ - -CCCryptorStatus CCCryptorEncryptDataBlock( - CCCryptorRef cryptorRef, - const void *iv, - const void *dataIn, - size_t dataInLength, - void *dataOut) -API_AVAILABLE(macos(10.7), ios(5.0)); - - -CCCryptorStatus CCCryptorDecryptDataBlock( - CCCryptorRef cryptorRef, - const void *iv, - const void *dataIn, - size_t dataInLength, - void *dataOut) -API_AVAILABLE(macos(10.7), ios(5.0)); - - -/*! - @function CCCryptorReset_binary_compatibility - @abstract Do not call this function. Reinitializes an existing CCCryptorRef with a (possibly) - new initialization vector. The CCCryptorRef's key is - unchanged. Preserves compatibility for Sdks prior to - macOS 10.13, iOS 11, watchOS 4 and tvOS 11. It is used - internally in CommonCrypto. See CCCryptorReset for more information. - - @result The only possible error is kCCParamError. - -*/ -CCCryptorStatus CCCryptorReset_binary_compatibility(CCCryptorRef cryptorRef, const void *iv) - API_DEPRECATED_WITH_REPLACEMENT("CCCryptorReset", macos(10.4, 10.13), ios(2.0, 11.0)); - -/* - Assuming we can use the existing CCCryptorRelease() interface for - int mode_done(mode_context *ctx); -*/ - -/* - Not surfacing these other than with CCCryptorReset() - - int mode_setIV(const unsigned char *IV, unsigned long len, mode_context *ctx); - int mode_getIV(const unsigned char *IV, unsigned long *len, mode_context *ctx); -*/ - -/* - * returns a cipher blocksize length iv in the provided iv buffer. - */ - -CCCryptorStatus -CCCryptorGetIV(CCCryptorRef cryptorRef, void *iv) -API_AVAILABLE(macos(10.7), ios(5.0)); - -/* - GCM Support Interfaces - - Use CCCryptorCreateWithMode() with the kCCModeGCM selector to initialize - a CryptoRef. Only kCCAlgorithmAES128 can be used with GCM and these - functions. IV Setting etc will be ignored from CCCryptorCreateWithMode(). - Use the CCCryptorGCMAddIV() routine below for IV setup. -*/ - -/* - Deprecated. Use CCCryptorGCMSetIV() instead. - This adds the initial vector octets from iv of length ivLen to the GCM - CCCryptorRef. You can call this function as many times as required to - process the entire IV. -*/ - -CCCryptorStatus -CCCryptorGCMAddIV(CCCryptorRef cryptorRef, - const void *iv, size_t ivLen) -API_DEPRECATED_WITH_REPLACEMENT("CCCryptorGCMSetIV", macos(10.8, 10.13), ios(5.0, 11.0)); - - -/* - This adds the initial vector octets from iv of length ivLen to the GCM - CCCryptorRef. The input iv cannot be NULL and ivLen must be between 12 - to 16 bytes inclusive. CCRandomGenerateBytes() can be used to generate random IVs -*/ - -CCCryptorStatus -CCCryptorGCMSetIV(CCCryptorRef cryptorRef, - const void *iv, size_t ivLen) -API_AVAILABLE(macos(10.13), ios(11.0)); -/* - Additional Authentication Data - After the entire IV has been processed, the additional authentication - data can be processed. Unlike the IV, a packet/session does not require - additional authentication data (AAD) for security. The AAD is meant to - be used as side channel data you want to be authenticated with the packet. - Note: once you begin adding AAD to the GCM CCCryptorRef you cannot return - to adding IV data until the state has been reset. -*/ - -CCCryptorStatus -CCCryptorGCMAddAAD(CCCryptorRef cryptorRef, - const void *aData, - size_t aDataLen) -API_AVAILABLE(macos(10.8), ios(6.0)); - - -// This is for old iOS5 clients -CCCryptorStatus -CCCryptorGCMAddADD(CCCryptorRef cryptorRef, - const void *aData, - size_t aDataLen) -API_AVAILABLE(macos(10.8), ios(5.0)); - - -CCCryptorStatus CCCryptorGCMEncrypt( - CCCryptorRef cryptorRef, - const void *dataIn, - size_t dataInLength, - void *dataOut) -API_AVAILABLE(macos(10.8), ios(5.0)); - - -CCCryptorStatus CCCryptorGCMDecrypt( - CCCryptorRef cryptorRef, - const void *dataIn, - size_t dataInLength, - void *dataOut) -API_AVAILABLE(macos(10.8), ios(5.0)); - -/* - This finalizes the GCM state gcm and stores the tag in tag of length - taglen octets. - - The tag must be verified by comparing the computed and expected values - using timingsafe_bcmp. Other comparison functions (e.g. memcmp) - must not be used as they may be vulnerable to practical timing attacks, - leading to tag forgery. - -*/ - -CCCryptorStatus CCCryptorGCMFinal( - CCCryptorRef cryptorRef, - void *tagOut, - size_t *tagLength) -API_DEPRECATED_WITH_REPLACEMENT("CCCryptorGCMFinalize", macos(10.8, 10.13), ios(5.0, 11.0)); - -/* - This finalizes the GCM state gcm. - - On encryption, the computed tag is returned in tagOut. - - On decryption, the provided tag is securely compared to the expected tag, and - error is returned if the tags do not match. The tag buffer content is not modified on decryption. - is not updated on decryption. -*/ -CCCryptorStatus CCCryptorGCMFinalize( - CCCryptorRef cryptorRef, - void *tag, - size_t tagLength) -API_AVAILABLE(macos(10.13), ios(11.0)); - -/* - This will reset the GCM CCCryptorRef to the state that CCCryptorCreateWithMode() - left it. The user would then call CCCryptorGCMAddIV(), CCCryptorGCMAddAAD(), etc. -*/ - -CCCryptorStatus CCCryptorGCMReset( - CCCryptorRef cryptorRef) -API_AVAILABLE(macos(10.8), ios(5.0)); - -/* - Deprecated. Use CCCryptorGCMOneshotEncrypt() or CCCryptorGCMOneshotDecrypt() instead. - - This will initialize the GCM state with the given key, IV and AAD value - then proceed to encrypt or decrypt the message text and store the final - message tag. The definition of the variables is the same as it is for all - the manual functions. If you are processing many packets under the same - key you shouldn't use this function as it invokes the pre-computation - with each call. - - The tag must be verified by comparing the computed and expected values - using timingsafe_bcmp. Other comparison functions (e.g. memcmp) - must not be used as they may be vulnerable to practical timing attacks, - leading to tag forgery. -*/ - -CCCryptorStatus CCCryptorGCM( - CCOperation op, /* kCCEncrypt, kCCDecrypt */ - CCAlgorithm alg, - const void *key, /* raw key material */ - size_t keyLength, - const void *iv, - size_t ivLen, - const void *aData, - size_t aDataLen, - const void *dataIn, - size_t dataInLength, - void *dataOut, - void *tagOut, - size_t *tagLength) -API_DEPRECATED_WITH_REPLACEMENT("CCCryptorGCMOneshotEncrypt or CCCryptorGCMOneshotDecrypt", macos(10.8, 10.13), ios(6.0, 11.0)); - - /*! - @function CCCryptorGCMOneshotDecrypt - @abstract Encrypts using AES-GCM and outputs encrypted data and an authentication tag - @param alg It can only be kCCAlgorithmAES - @param key Key for the underlying AES blockcipher. It must be 16 bytes. ***** - @param keyLength Length of the key in bytes - - @param iv Initialization vector, must be at least 12 bytes - @param ivLength Length of the IV in bytes - - @param aData Additional data to authenticate. It can be NULL, if there is no additional data to be authenticated. - @param aDataLength Length of the additional data in bytes. It can be zero. - - @param dataIn Input plaintext - @param dataInLength Length of the input plaintext data in bytes - - @param cipherOut Output ciphertext - @param tagLength Length of the output authentication tag in bytes. It is minimum 8 bytes and maximum 16 bytes. - @param tagOut the output authentication tag - - @result kccSuccess if successful. - - @discussion It is a one-shot AESGCM encryption and in-place encryption is supported. - - @warning The key-IV pair must be unique per encryption. The IV must be nonzero in length. - - In stateful protocols, if each packet exposes a guaranteed-unique value, it is recommended to format this as a 12-byte value for use as the IV. - - In stateless protocols, it is recommended to choose a 16-byte value using a cryptographically-secure pseudorandom number generator (e.g. @p ccrng). - */ - -CCCryptorStatus CCCryptorGCMOneshotEncrypt(CCAlgorithm alg, const void *key, size_t keyLength, /* raw key material */ - const void *iv, size_t ivLength, - const void *aData, size_t aDataLength, - const void *dataIn, size_t dataInLength, - void *cipherOut, - void *tagOut, size_t tagLength) __attribute__((__warn_unused_result__)) -API_AVAILABLE(macos(10.13), ios(11.0)); - - /*! - @function CCCryptorGCMOneshotDecrypt - @abstract Decrypts using AES-GCM, compares the computed tag of the decrypted message to the input tag and returns error is authentication fails. - - @discussion CCCryptorGCMOneshotDecrypt() works similar to the CCCryptorGCMOneshotEncrypt(). CCCryptorGCMOneshotDecrypt() does not return the tag of the decrypted message. It compated the computed tag with inout tag and outputs error if authentication of the decrypted message fails. - */ - -CCCryptorStatus CCCryptorGCMOneshotDecrypt(CCAlgorithm alg, const void *key, size_t keyLength, - const void *iv, size_t ivLen, - const void *aData, size_t aDataLen, - const void *dataIn, size_t dataInLength, - void *dataOut, - const void *tagIn, size_t tagLength) __attribute__((__warn_unused_result__)) - API_AVAILABLE(macos(10.13), ios(11.0)); - -void CC_RC4_set_key(void *ctx, int len, const unsigned char *data) -API_AVAILABLE(macos(10.4), ios(5.0)); - -void CC_RC4(void *ctx, unsigned long len, const unsigned char *indata, - unsigned char *outdata) -API_AVAILABLE(macos(10.4), ios(5.0)); - -/* -GCM interface can then be easily bolt on the rest of standard CCCryptor interface; typically following sequence can be used: - -CCCryptorCreateWithMode(mode = kCCModeGCM) -0..Nx: CCCryptorAddParameter(kCCParameterIV, iv) -0..Nx: CCCryptorAddParameter(kCCParameterAuthData, data) -0..Nx: CCCryptorUpdate(inData, outData) -0..1: CCCryptorFinal(outData) -0..1: CCCryptorGetParameter(kCCParameterAuthTag, tag) -CCCryptorRelease() - -*/ - -enum { - /* - Initialization vector - cryptor input parameter, typically - needs to have the same length as block size, but in some cases - (GCM) it can be arbitrarily long and even might be called - multiple times. - */ - kCCParameterIV, - - /* - Authentication data - cryptor input parameter, input for - authenticating encryption modes like GCM. If supported, can - be called multiple times before encryption starts. - */ - kCCParameterAuthData, - - /* - Mac Size - cryptor input parameter, input for - authenticating encryption modes like CCM. Specifies the size of - the AuthTag the algorithm is expected to produce. - */ - kCCMacSize, - - /* - Data Size - cryptor input parameter, input for - authenticating encryption modes like CCM. Specifies the amount of - data the algorithm is expected to process. - */ - kCCDataSize, - - /* - Authentication tag - cryptor output parameter, output from - authenticating encryption modes like GCM. If supported, - should be retrieved after the encryption finishes. - */ - kCCParameterAuthTag, -}; -typedef uint32_t CCParameter; - -/* - Sets or adds some other cryptor input parameter. According to the - cryptor type and state, parameter can be either accepted or - refused with kCCUnimplemented (when given parameter is not - supported for this type of cryptor at all) or kCCParamError (bad - data length or format). -*/ - -CCCryptorStatus CCCryptorAddParameter( - CCCryptorRef cryptorRef, - CCParameter parameter, - const void *data, - size_t dataSize); - - -/* - Gets value of output cryptor parameter. According to the cryptor - type state, the request can be either accepted or refused with - kCCUnimplemented (when given parameter is not supported for this - type of cryptor) or kCCBufferTooSmall (in this case, *dataSize - argument is set to the requested size of data). -*/ - -CCCryptorStatus CCCryptorGetParameter( - CCCryptorRef cryptorRef, - CCParameter parameter, - void *data, - size_t *dataSize); - - -#ifdef __cplusplus -} -#endif - -#endif /* _CC_CryptorSPI_H_ */ diff --git a/src/aws-cpp-sdk-core/include/aws/core/utils/GetTheLights.h b/src/aws-cpp-sdk-core/include/aws/core/utils/GetTheLights.h deleted file mode 100644 index f42475c8e4f9..000000000000 --- a/src/aws-cpp-sdk-core/include/aws/core/utils/GetTheLights.h +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -#pragma once - -#include -#include -#include -#include - -namespace Aws -{ - namespace Utils - { - /** - * Make initialization and cleanup of shared resources less painful. - * If you have this problem. Create a static instance of GetTheLights, - * have each actor call Enter the room with your callable. - * - * When you are finished with the shared resources call LeaveRoom(). The last caller will - * have its callable executed. - */ - class AWS_CORE_API GetTheLights - { - public: - GetTheLights(); - void EnterRoom(std::function&&); - void LeaveRoom(std::function&&); - private: - std::atomic m_value; - }; - } -} \ No newline at end of file diff --git a/src/aws-cpp-sdk-core/include/aws/core/utils/memory/stl/AWSMultiMap.h b/src/aws-cpp-sdk-core/include/aws/core/utils/memory/stl/AWSMultiMap.h deleted file mode 100644 index 169738237b50..000000000000 --- a/src/aws-cpp-sdk-core/include/aws/core/utils/memory/stl/AWSMultiMap.h +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -#pragma once - -#include - -#include - -#include - -namespace Aws -{ - -template< typename K, typename V > using MultiMap = std::multimap< K, V, std::less< K >, Aws::Allocator< std::pair< const K, V > > >; - -} // namespace Aws diff --git a/src/aws-cpp-sdk-core/source/utils/GetTheLights.cpp b/src/aws-cpp-sdk-core/source/utils/GetTheLights.cpp deleted file mode 100644 index 6e78b546ab58..000000000000 --- a/src/aws-cpp-sdk-core/source/utils/GetTheLights.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ -#include -#include - -namespace Aws -{ - namespace Utils - { - GetTheLights::GetTheLights() : m_value(0) - { - } - - void GetTheLights::EnterRoom(std::function &&callable) - { - int cpy = ++m_value; - assert(cpy > 0); - if(cpy == 1) - { - callable(); - } - } - - void GetTheLights::LeaveRoom(std::function &&callable) - { - int cpy = --m_value; - assert(cpy >= 0); - if(cpy == 0) - { - callable(); - } - } - } -} \ No newline at end of file diff --git a/src/aws-cpp-sdk-s3-encryption/SUPPORT_POLICY.rst b/src/aws-cpp-sdk-s3-encryption/SUPPORT_POLICY.rst index c88528667b98..d0e8ec84a991 100644 --- a/src/aws-cpp-sdk-s3-encryption/SUPPORT_POLICY.rst +++ b/src/aws-cpp-sdk-s3-encryption/SUPPORT_POLICY.rst @@ -22,11 +22,11 @@ This table describes the current support status of each major version of the S3E - Current status - Next status * - S3EncryptionClient - - End Of Support + - Removed in 1.12 - * - S3EncryptionClientV2 - - Maintenance - - End Of Support + - Removed in 1.12 + - * - S3EncryptionClientV3 - Generally Available - diff --git a/src/aws-cpp-sdk-s3-encryption/include/aws/s3-encryption/CryptoConfiguration.h b/src/aws-cpp-sdk-s3-encryption/include/aws/s3-encryption/CryptoConfiguration.h index 661f980afdde..cd2f21baf708 100644 --- a/src/aws-cpp-sdk-s3-encryption/include/aws/s3-encryption/CryptoConfiguration.h +++ b/src/aws-cpp-sdk-s3-encryption/include/aws/s3-encryption/CryptoConfiguration.h @@ -11,8 +11,6 @@ namespace Aws { namespace S3Encryption { - class S3EncryptionClient; - enum class StorageMethod { METADATA, @@ -158,31 +156,9 @@ namespace Aws CommitmentPolicy m_commitmentPolicy; friend class S3EncryptionClientBase; - friend class S3EncryptionClientV2; friend class S3EncryptionClientV3; }; - class AWS_S3ENCRYPTION_API CryptoConfigurationV2 - { - public: - CryptoConfigurationV2(const std::shared_ptr& materials); - CryptoConfigurationV2(const std::shared_ptr& materials); - - inline void SetSecurityProfile(SecurityProfile profile) { m_securityProfile = profile; } - inline void SetUnAuthenticatedRangeGet(RangeGetMode mode) { m_unAuthenticatedRangeGet = mode; } - inline void SetStorageMethod(StorageMethod storageMethod) { m_storageMethod = storageMethod; } - - inline SecurityProfile GetSecurityProfile() const { return m_securityProfile; } - inline RangeGetMode GetUnAuthenticatedRangeGet() const { return m_unAuthenticatedRangeGet; } - inline StorageMethod GetStorageMethod() const { return m_storageMethod; } - std::shared_ptr GetEncryptionMaterials() const { return m_encryptionMaterials; } - private: - StorageMethod m_storageMethod; - RangeGetMode m_unAuthenticatedRangeGet; - SecurityProfile m_securityProfile; - std::shared_ptr m_encryptionMaterials; - }; - //= ../specification/s3-encryption/client.md#aws-sdk-compatibility //= type=implication //# The S3EC MUST provide a different set of configuration options than the conventional S3 client. diff --git a/src/aws-cpp-sdk-s3-encryption/include/aws/s3-encryption/S3EncryptionClient.h b/src/aws-cpp-sdk-s3-encryption/include/aws/s3-encryption/S3EncryptionClient.h index bfe4a69d9ff1..e194ead62d77 100644 --- a/src/aws-cpp-sdk-s3-encryption/include/aws/s3-encryption/S3EncryptionClient.h +++ b/src/aws-cpp-sdk-s3-encryption/include/aws/s3-encryption/S3EncryptionClient.h @@ -44,7 +44,8 @@ namespace Aws class AWS_S3ENCRYPTION_API S3EncryptionClientBase { - public: + // Only subclasses construct the base; the constructors accept legacy CryptoConfiguration settings. + protected: /* * Initialize the S3EncryptionClientBase with encryption materials, crypto configuration, and a client configuration. If no client configuration is supplied, * the default client configuration will be used. @@ -74,6 +75,7 @@ namespace Aws const Aws::S3Encryption::CryptoConfiguration& cryptoConfig, const std::function ()>& s3ClientFactory); + public: S3EncryptionClientBase(const S3EncryptionClientBase&) = delete; S3EncryptionClientBase& operator=(const S3EncryptionClientBase&) = delete; @@ -133,111 +135,6 @@ namespace Aws Aws::String m_error; }; - /** - * @deprecated This class is in the maintenance mode, no new updates will be released, use S3EncryptionClientV3. - */ - class - AWS_DEPRECATED("This class is in the maintenance mode, no new updates will be released, use S3EncryptionClientV3. Please see https://docs.aws.amazon.com/general/latest/gr/aws_sdk_cryptography.html for more information.") - AWS_S3ENCRYPTION_API S3EncryptionClient : public S3EncryptionClientBase - { - public: - /* - * Initialize the S3 Encryption Client with encryption materials, crypto configuration, and a client configuration. If no client configuration is supplied, - * the default client configuration will be used. - */ - S3EncryptionClient(const std::shared_ptr& encryptionMaterials, const Aws::S3Encryption::CryptoConfiguration& cryptoConfig, - const Aws::S3::S3ClientConfiguration& clientConfiguration = Aws::S3::S3ClientConfiguration()) - : S3EncryptionClientBase(encryptionMaterials, cryptoConfig, clientConfiguration) - {} - - /* - * Initialize the S3 Encryption Client with encryption materials, crypto configuration, AWS credentials and a client configuration. If no client configuration is supplied, - * the default client configuration will be used. - */ - S3EncryptionClient(const std::shared_ptr& encryptionMaterials, const Aws::S3Encryption::CryptoConfiguration& cryptoConfig, - const Aws::Auth::AWSCredentials& credentials, const Aws::S3::S3ClientConfiguration& clientConfiguration = Aws::S3::S3ClientConfiguration()) - : S3EncryptionClientBase(encryptionMaterials, cryptoConfig, credentials, clientConfiguration) - {} - - /* - * Initialize the S3 Encryption Client with encryption materials, crypto configuration, AWS credentials provider and a client configuration. If no client configuration is supplied, - * the default client configuration will be used. - */ - S3EncryptionClient(const std::shared_ptr& encryptionMaterials, const Aws::S3Encryption::CryptoConfiguration& cryptoConfig, - const std::shared_ptr& credentialsProvider, const Aws::S3::S3ClientConfiguration& clientConfiguration = Aws::S3::S3ClientConfiguration()) - : S3EncryptionClientBase(encryptionMaterials, cryptoConfig, credentialsProvider, clientConfiguration) - {} - - /* - * Function to put an object encrypted to S3. - */ - S3EncryptionPutObjectOutcome PutObject(const Aws::S3::Model::PutObjectRequest& request) const { return S3EncryptionClientBase::PutObject(request, {}); } - }; - - /** - * S3EncryptionClientV2 enforce the secure postures for customers. See https://docs.aws.amazon.com/general/latest/gr/aws_sdk_cryptography.html - * Examples: https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/cpp/example_code/s3encryption/s3Encryption.cpp - */ - /** - * @deprecated This class is in the maintenance mode, no new updates will be released, use S3EncryptionClientV3. - */ - class - AWS_DEPRECATED("This class is in the maintenance mode, no new updates will be released, use S3EncryptionClientV3. Please see https://docs.aws.amazon.com/general/latest/gr/aws_sdk_cryptography.html for more information.") - AWS_S3ENCRYPTION_API S3EncryptionClientV2 : public S3EncryptionClientBase - { - public: - /* - * Initialize the S3 Encryption Client V2 with crypto configuration v2, and a client configuration. If no client configuration is supplied, - * the default client configuration will be used. - */ - S3EncryptionClientV2(const Aws::S3Encryption::CryptoConfigurationV2& cryptoConfig, - const Aws::S3::S3ClientConfiguration& clientConfig = Aws::S3::S3ClientConfiguration()) - : S3EncryptionClientBase(cryptoConfig.GetEncryptionMaterials(), CryptoConfiguration(), clientConfig) - { - Init(cryptoConfig); - } - - - /* - * Initialize the S3 Encryption Client V2 with crypto configuration v2, AWS credentials and a client configuration. If no client configuration is supplied, - * the default client configuration will be used. - */ - S3EncryptionClientV2(const Aws::S3Encryption::CryptoConfigurationV2& cryptoConfig, const Aws::Auth::AWSCredentials& credentials, - const Aws::S3::S3ClientConfiguration& clientConfig = Aws::S3::S3ClientConfiguration()) - : S3EncryptionClientBase(cryptoConfig.GetEncryptionMaterials(), CryptoConfiguration(), credentials, clientConfig) - { - Init(cryptoConfig); - } - - /* - * Initialize the S3 Encryption Client V2 with crypto configuration v2, AWS credentials provider and a client configuration. If no client configuration is supplied, - * the default client configuration will be used. - */ - S3EncryptionClientV2(const Aws::S3Encryption::CryptoConfigurationV2& cryptoConfig, const std::shared_ptr& credentialsProvider, - const Aws::S3::S3ClientConfiguration& clientConfig = Aws::S3::S3ClientConfiguration()) - : S3EncryptionClientBase(cryptoConfig.GetEncryptionMaterials(), CryptoConfiguration(), credentialsProvider, clientConfig) - { - Init(cryptoConfig); - } - - /* - * Initialize the S3 Encryption Client V2 with crypto configuration v2, and a s3 client factory. - * The factory will be used to create the underlying S3 Client. - */ - S3EncryptionClientV2(const Aws::S3Encryption::CryptoConfigurationV2& cryptoConfig, - const std::function ()>& s3ClientFactory) - : S3EncryptionClientBase(cryptoConfig.GetEncryptionMaterials(), CryptoConfiguration(), s3ClientFactory) - { - Init(cryptoConfig); - } - - S3EncryptionClientV2(const S3EncryptionClientV2&) = delete; - S3EncryptionClientV2& operator=(const S3EncryptionClientV2&) = delete; - - private: - void Init(const Aws::S3Encryption::CryptoConfigurationV2& cryptoConfig); - }; - class AWS_S3ENCRYPTION_API S3EncryptionClientV3 : public S3EncryptionClientBase { public: diff --git a/src/aws-cpp-sdk-s3-encryption/source/s3-encryption/CryptoConfiguration.cpp b/src/aws-cpp-sdk-s3-encryption/source/s3-encryption/CryptoConfiguration.cpp index 5747ab96a840..01dc84ddf1ec 100644 --- a/src/aws-cpp-sdk-s3-encryption/source/s3-encryption/CryptoConfiguration.cpp +++ b/src/aws-cpp-sdk-s3-encryption/source/s3-encryption/CryptoConfiguration.cpp @@ -49,22 +49,6 @@ namespace Aws { } - CryptoConfigurationV2::CryptoConfigurationV2(const std::shared_ptr& materials) : - m_storageMethod(StorageMethod::METADATA), - m_unAuthenticatedRangeGet(RangeGetMode::DISABLED), - m_securityProfile(SecurityProfile::V2), - m_encryptionMaterials(materials) - { - } - - CryptoConfigurationV2::CryptoConfigurationV2(const std::shared_ptr& materials) : - m_storageMethod(StorageMethod::METADATA), - m_unAuthenticatedRangeGet(RangeGetMode::DISABLED), - m_securityProfile(SecurityProfile::V2), - m_encryptionMaterials(materials) - { - } - CryptoConfigurationV3::CryptoConfigurationV3(const std::shared_ptr& materials) : m_storageMethod(StorageMethod::METADATA), m_unAuthenticatedRangeGet(RangeGetMode::DISABLED), diff --git a/src/aws-cpp-sdk-s3-encryption/source/s3-encryption/S3EncryptionClient.cpp b/src/aws-cpp-sdk-s3-encryption/source/s3-encryption/S3EncryptionClient.cpp index 1180bf479946..efdcbb098fc8 100644 --- a/src/aws-cpp-sdk-s3-encryption/source/s3-encryption/S3EncryptionClient.cpp +++ b/src/aws-cpp-sdk-s3-encryption/source/s3-encryption/S3EncryptionClient.cpp @@ -294,24 +294,6 @@ namespace Aws return instructionOutcome; } - void S3EncryptionClientV2::Init(const Aws::S3Encryption::CryptoConfigurationV2& cryptoConfig) - { - // This validation could be, in a bizarre set of circumstances, a breaking change - // if (ValidateStorageMethod(cryptoConfig.GetStorageMethod())) return; - // if (ValidateRangeGetMode(cryptoConfig.GetUnAuthenticatedRangeGet())) return; - // if (ValidateSecurityProfile(cryptoConfig.GetSecurityProfile())) return; - - m_cryptoConfig.SetSecurityProfile(cryptoConfig.GetSecurityProfile()); - m_cryptoConfig.SetUnAuthenticatedRangeGet(cryptoConfig.GetUnAuthenticatedRangeGet()); - m_cryptoConfig.SetCommitmentPolicy(CommitmentPolicy::FORBID_ENCRYPT_ALLOW_DECRYPT); - m_cryptoConfig.SetEncryptionAlgorithm(AlgorithmSuite::AES_GCM); - m_cryptoConfig.SetStorageMethod(cryptoConfig.GetStorageMethod()); - - m_s3Client->AppendToUserAgent("ft/S3CryptoV2"); - if (cryptoConfig.GetSecurityProfile() == SecurityProfile::V2_AND_LEGACY) { - AWS_LOGSTREAM_WARN(ALLOCATION_TAG, "The S3 Encryption Client is configured to read encrypted data with legacy encryption modes. If you don't have objects encrypted with these legacy modes, you should disable support for them to enhance security. See https://docs.aws.amazon.com/general/latest/gr/aws_sdk_cryptography.html"); - } - } void S3EncryptionClientV3::Init(const Aws::S3Encryption::CryptoConfigurationV3& cryptoConfig) { if (ValidateStorageMethod(cryptoConfig.GetStorageMethod())) return; diff --git a/tests/aws-cpp-sdk-core-tests/utils/GetTheLightsTest.cpp b/tests/aws-cpp-sdk-core-tests/utils/GetTheLightsTest.cpp deleted file mode 100644 index 9ed72265c3c7..000000000000 --- a/tests/aws-cpp-sdk-core-tests/utils/GetTheLightsTest.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -#include -#include - -using namespace Aws::Utils; - -class GetTheLightsTest : public Aws::Testing::AwsCppSdkGTestSuite -{ -}; - -TEST_F(GetTheLightsTest, Test_Lights_TurnOff) -{ - GetTheLights getTheLights; - - bool firstInGotTheLights(false); - getTheLights.EnterRoom([&]{ firstInGotTheLights = true; }); - getTheLights.EnterRoom([]{ ASSERT_TRUE(false); }); - getTheLights.EnterRoom([]{ ASSERT_TRUE(false); }); - getTheLights.EnterRoom([]{ ASSERT_TRUE(false); }); - getTheLights.EnterRoom([]{ ASSERT_TRUE(false); }); - - ASSERT_TRUE(firstInGotTheLights); - - getTheLights.LeaveRoom([]{ ASSERT_TRUE(false); }); - getTheLights.LeaveRoom([]{ ASSERT_TRUE(false); }); - getTheLights.LeaveRoom([]{ ASSERT_TRUE(false); }); - getTheLights.LeaveRoom([]{ ASSERT_TRUE(false); }); - - bool lastOutGotTheLights(false); - getTheLights.LeaveRoom([&]{lastOutGotTheLights = true; }); - - ASSERT_TRUE(lastOutGotTheLights); -} \ No newline at end of file diff --git a/tests/aws-cpp-sdk-s3-encryption-integration-tests/LiveClientTests.cpp b/tests/aws-cpp-sdk-s3-encryption-integration-tests/LiveClientTests.cpp index c0c499eda596..61eb1cbb17e0 100644 --- a/tests/aws-cpp-sdk-s3-encryption-integration-tests/LiveClientTests.cpp +++ b/tests/aws-cpp-sdk-s3-encryption-integration-tests/LiveClientTests.cpp @@ -47,10 +47,6 @@ using namespace Aws::Utils::Crypto; using namespace Aws::Region; using namespace Aws::Utils::Json; -// Public key owned by CryptoTools -// Needed for EncryptionContext tests, that need KMS materials -static const char * KMS_KEY = "arn:aws:kms:us-west-2:658956600833:key/b3537ef1-d8dc-4780-9f5a-55776cbb2f7f"; - static const char* ENCRYPTED_BUCKET_TEST_NAME = "awsnativesdks3encotest"; static const char* ALLOCATION_TAG = "LiveClientTest"; static const char TEST_STRING[] = "This is a test string. It is meant to test AES CBC, AES CTR, and AES GCM modes of operation with the Aws S3 Encryption Client"; @@ -58,9 +54,6 @@ static const char TEST_STRING[] = "This is a test string. It is meant to test AE static const char* RANGE_GET_STR = "bytes=38-75"; static const char RANGE_GET_TEST_STRING[] = "test AES CBC, AES CTR, and AES GCM mod"; -static const char* OVERFLOW_RANGE_GET_STR = "bytes=38-1000000000"; -static const char OVERFLOW_RANGE_GET_TEST_STRING[] = "test AES CBC, AES CTR, and AES GCM modes of operation with the Aws S3 Encryption Client"; - static const char* TEST_BUCKET_TAG = "IntegrationTestResource"; class LiveClientTest : public ::testing::Test @@ -123,207 +116,15 @@ std::string LiveClientTest::TimeStamp; std::string LiveClientTest::BucketName; std::shared_ptr LiveClientTest::StandardClient(nullptr); -TEST_F(LiveClientTest, TestEOMode) -{ - CryptoConfiguration configuration; - configuration.SetCryptoMode(CryptoMode::ENCRYPTION_ONLY); - configuration.SetStorageMethod(StorageMethod::METADATA); - - Aws::S3::S3ClientConfiguration s3ClientConfig; - s3ClientConfig.region = AWS_TEST_REGION; - - auto key = SymmetricCipher::GenerateKey(); - auto simpleEncryptionMaterials = Aws::MakeShared(ALLOCATION_TAG, key); - - static const char* objectKey = "TestEOKey"; - - S3EncryptionClient client(simpleEncryptionMaterials, configuration, s3ClientConfig); - - Model::PutObjectRequest putObjectRequest; - putObjectRequest.WithBucket(BucketName.c_str()) - .WithKey(objectKey); - - auto ss = Aws::MakeShared(ALLOCATION_TAG); - *ss << TEST_STRING; - ss->flush(); - - putObjectRequest.SetBody(ss); - - auto putObjectResult = client.PutObject(putObjectRequest); - AWS_ASSERT_SUCCESS(putObjectResult); - - Model::GetObjectRequest getObjectRequest; - getObjectRequest.WithBucket(BucketName.c_str()).WithKey(objectKey); - - auto getObjectResult = client.GetObject(getObjectRequest); - AWS_EXPECT_SUCCESS(getObjectResult); - - Aws::StringStream responseStringStream; - responseStringStream << getObjectResult.GetResult().GetBody().rdbuf(); - - EXPECT_STREQ(TEST_STRING, responseStringStream.str().c_str()); - - auto metadata = getObjectResult.GetResult().GetMetadata(); - auto ivStr = metadata["x-amz-iv"]; - auto cekStr = metadata["x-amz-key-v2"]; - auto aad = metadata["x-amz-cek-alg"]; - EXPECT_FALSE(ivStr.empty()); - EXPECT_FALSE(cekStr.empty()); - EXPECT_FALSE(aad.empty()); - - ContentCryptoMaterial cryptoMaterial(ContentCryptoScheme::CBC); - cryptoMaterial.SetFinalCEK(HashingUtils::Base64Decode(cekStr)); - cryptoMaterial.SetKeyWrapAlgorithm(KeyWrapAlgorithm::AES_GCM); - cryptoMaterial.SetGCMAAD(CryptoBuffer((const unsigned char*)aad.c_str(), aad.size())); - simpleEncryptionMaterials->DecryptCEK(cryptoMaterial); - - auto cbcCipher = CreateAES_CBCImplementation(cryptoMaterial.GetContentEncryptionKey(), HashingUtils::Base64Decode(ivStr)); - - Aws::StringStream comparisonStream; - Crypto::SymmetricCryptoStream cryptoStream((Aws::OStream&)comparisonStream, CipherMode::Encrypt, *cbcCipher); - - Model::GetObjectRequest getUnencryptedObjectRequest; - getUnencryptedObjectRequest.WithBucket(BucketName.c_str()).WithKey(objectKey); - auto standardGetObjectResult = StandardClient->GetObject(getUnencryptedObjectRequest); - - AWS_EXPECT_SUCCESS(standardGetObjectResult); - ByteBuffer rawData(static_cast< size_t >(standardGetObjectResult.GetResult().GetContentLength())); - memset(rawData.GetUnderlyingData(), 0, rawData.GetLength()); - standardGetObjectResult.GetResult().GetBody().read((char*)rawData.GetUnderlyingData(), rawData.GetLength()); - - cryptoStream << TEST_STRING; - cryptoStream.Finalize(); - - ByteBuffer comparisonResult((unsigned char*)comparisonStream.str().c_str(), comparisonStream.str().length()); - EXPECT_STREQ(HashingUtils::HexEncode(comparisonResult).c_str(), HashingUtils::HexEncode(rawData).c_str()); - - Model::DeleteObjectRequest deleteObject; - deleteObject.WithBucket(BucketName.c_str()).WithKey(objectKey); - - auto deleteResult = StandardClient->DeleteObject(deleteObject); - AWS_EXPECT_SUCCESS(deleteResult); -} - -TEST_F(LiveClientTest, TestEncryptionContextEmpty) -{ - Aws::S3::S3ClientConfiguration s3ClientConfig; - s3ClientConfig.region = AWS_TEST_REGION; - - auto key = SymmetricCipher::GenerateKey(); - auto simpleEncryptionMaterials = Aws::MakeShared(ALLOCATION_TAG, key); - CryptoConfigurationV2 configuration(simpleEncryptionMaterials); - - static const char* objectKey = "TestEncryptionContextEmptyKey"; - - S3EncryptionClientV2 client(configuration, s3ClientConfig); - - Model::PutObjectRequest putObjectRequest; - putObjectRequest.WithBucket(BucketName.c_str()) - .WithKey(objectKey); - - auto ss = Aws::MakeShared(ALLOCATION_TAG); - *ss << TEST_STRING; - ss->flush(); - - putObjectRequest.SetBody(ss); - - auto putObjectResult = client.PutObject(putObjectRequest, {}); - AWS_ASSERT_SUCCESS(putObjectResult); - - Model::GetObjectRequest getObjectRequest; - getObjectRequest.WithBucket(BucketName.c_str()).WithKey(objectKey); - - auto getObjectResult = client.GetObject(getObjectRequest); - AWS_EXPECT_SUCCESS(getObjectResult); - getObjectResult = client.GetObject(getObjectRequest, {}); - AWS_EXPECT_SUCCESS(getObjectResult); - getObjectResult = client.GetObject(getObjectRequest, {{"foo", "bar"}}); - EXPECT_FALSE(getObjectResult.IsSuccess()); -} - -TEST_F(LiveClientTest, TestV2EncryptionContextEmptyKms) -{ - auto materials = std::make_shared(KMS_KEY); - CryptoConfigurationV2 configuration(materials); - - Aws::S3::S3ClientConfiguration s3ClientConfig; - s3ClientConfig.region = AWS_TEST_REGION; - - static const char* objectKey = "TestEncryptionContextKms"; - - S3EncryptionClientV2 client(configuration, s3ClientConfig); - - Model::PutObjectRequest putObjectRequest; - putObjectRequest.WithBucket(BucketName.c_str()) - .WithKey(objectKey); - - auto ss = Aws::MakeShared(ALLOCATION_TAG); - *ss << TEST_STRING; - ss->flush(); - - putObjectRequest.SetBody(ss); - - auto putObjectResult = client.PutObject(putObjectRequest, {}); - AWS_ASSERT_SUCCESS(putObjectResult); - - Model::GetObjectRequest getObjectRequest; - getObjectRequest.WithBucket(BucketName.c_str()).WithKey(objectKey); - - auto getObjectResult = client.GetObject(getObjectRequest); - AWS_EXPECT_SUCCESS(getObjectResult); - getObjectResult = client.GetObject(getObjectRequest, {}); - AWS_EXPECT_SUCCESS(getObjectResult); - getObjectResult = client.GetObject(getObjectRequest, {{"foo", "bar"}}); - EXPECT_FALSE(getObjectResult.IsSuccess()); -} - -TEST_F(LiveClientTest, TestV2EncryptionContextFullKms) +// The V1 and V2 clients are gone, but objects they wrote are still in S3. This writes the same +// format through the base client so the tests can check that V3 still reads them. +class LegacyEncryptionClient : public S3EncryptionClientBase { - auto materials = std::make_shared(KMS_KEY); - CryptoConfigurationV2 configuration(materials); - - Aws::S3::S3ClientConfiguration s3ClientConfig; - s3ClientConfig.region = AWS_TEST_REGION; - - static const char* objectKey = "TestEncryptionContextKms"; - - S3EncryptionClientV2 client(configuration, s3ClientConfig); - - Model::PutObjectRequest putObjectRequest; - putObjectRequest.WithBucket(BucketName.c_str()) - .WithKey(objectKey); - - auto ss = Aws::MakeShared(ALLOCATION_TAG); - *ss << TEST_STRING; - ss->flush(); - - putObjectRequest.SetBody(ss); - - // PUT with non-empty EC - auto putObjectResult = client.PutObject(putObjectRequest, {{"foo", "bar"}}); - AWS_ASSERT_SUCCESS(putObjectResult); - - Model::GetObjectRequest getObjectRequest; - getObjectRequest.WithBucket(BucketName.c_str()).WithKey(objectKey); - - auto getObjectResult = client.GetObject(getObjectRequest); - AWS_EXPECT_SUCCESS(getObjectResult); - - getObjectResult = client.GetObject(getObjectRequest, {}); - EXPECT_FALSE(getObjectResult.IsSuccess()); - - getObjectResult = client.GetObject(getObjectRequest, {{"foo", "bar"}}); - AWS_EXPECT_SUCCESS(getObjectResult); - - getObjectResult = client.GetObject(getObjectRequest, {{"foo", "baz"}}); - EXPECT_FALSE(getObjectResult.IsSuccess()); - - getObjectResult = client.GetObject(getObjectRequest, {{"boo", "bar"}}); - EXPECT_FALSE(getObjectResult.IsSuccess()); - - getObjectResult = client.GetObject(getObjectRequest, {{"foo", "bar"}, {"foo2", "bar"}}); - EXPECT_FALSE(getObjectResult.IsSuccess()); -} +public: + LegacyEncryptionClient(const std::shared_ptr& materials, const CryptoConfiguration& cryptoConfig, + const Aws::S3::S3ClientConfiguration& clientConfig) + : S3EncryptionClientBase(materials, cryptoConfig, clientConfig) {} +}; //= ../specification/s3-encryption/key-commitment.md#commitment-policy //= type=test @@ -347,14 +148,13 @@ TEST_F(LiveClientTest, TestWriteV2ReadV3) { auto key = SymmetricCipher::GenerateKey(); auto materials = Aws::MakeShared(ALLOCATION_TAG, key); - CryptoConfigurationV2 v2_configuration(materials); Aws::S3::S3ClientConfiguration s3ClientConfig; s3ClientConfig.region = AWS_TEST_REGION; static const char* objectKey = "TestWriteV2ReadV3"; - S3EncryptionClientV2 v2_client(v2_configuration, s3ClientConfig); + LegacyEncryptionClient v2_client(materials, CryptoConfiguration(), s3ClientConfig); Model::PutObjectRequest putObjectRequest; putObjectRequest.WithBucket(BucketName.c_str()) @@ -423,7 +223,7 @@ TEST_F(LiveClientTest, TestWriteV1ReadV3) static const char* objectKey = "TestWriteV1ReadV3"; - S3EncryptionClient client(materials, configuration, s3ClientConfig); + LegacyEncryptionClient client(materials, configuration, s3ClientConfig); Model::PutObjectRequest putObjectRequest; putObjectRequest.WithBucket(BucketName.c_str()) @@ -435,7 +235,7 @@ TEST_F(LiveClientTest, TestWriteV1ReadV3) putObjectRequest.SetBody(ss); - auto putObjectResult = client.PutObject(putObjectRequest); + auto putObjectResult = client.PutObject(putObjectRequest, {}); AWS_ASSERT_SUCCESS(putObjectResult); Model::GetObjectRequest getObjectRequest; @@ -461,43 +261,6 @@ TEST_F(LiveClientTest, TestWriteV1ReadV3) AWS_EXPECT_SUCCESS(getObjectResult); } -TEST_F(LiveClientTest, TestWriteV3ReadV2) -{ - auto key = SymmetricCipher::GenerateKey(); - auto materials = Aws::MakeShared(ALLOCATION_TAG, key); - CryptoConfigurationV3 v3_configuration(materials); - v3_configuration.SetCommitmentPolicy(CommitmentPolicy::FORBID_ENCRYPT_ALLOW_DECRYPT); - - Aws::S3::S3ClientConfiguration s3ClientConfig; - s3ClientConfig.region = AWS_TEST_REGION; - - static const char* objectKey = "TestWriteV2ReadV3"; - - S3EncryptionClientV3 v3_client(v3_configuration, s3ClientConfig); - - Model::PutObjectRequest putObjectRequest; - putObjectRequest.WithBucket(BucketName.c_str()) - .WithKey(objectKey); - - auto ss = Aws::MakeShared(ALLOCATION_TAG); - *ss << TEST_STRING; - ss->flush(); - - putObjectRequest.SetBody(ss); - - auto putObjectResult = v3_client.PutObject(putObjectRequest, {}); - AWS_ASSERT_SUCCESS(putObjectResult); - - Model::GetObjectRequest getObjectRequest; - getObjectRequest.WithBucket(BucketName.c_str()).WithKey(objectKey); - - CryptoConfigurationV2 v2_configuration(materials); - S3EncryptionClientV2 v2_client(v2_configuration, s3ClientConfig); - - auto getObjectResult = v2_client.GetObject(getObjectRequest); - AWS_EXPECT_SUCCESS(getObjectResult); -} - //= ../specification/s3-encryption/key-commitment.md#commitment-policy //= type=test //# When the commitment policy is REQUIRE_ENCRYPT_ALLOW_DECRYPT, the S3EC MUST only encrypt using an algorithm suite which supports key commitment. @@ -565,66 +328,6 @@ static Aws::Map DeserializeMap(const Aws::String& json } } -TEST_F(LiveClientTest, TestWriteV2Instruction) -{ - auto key = SymmetricCipher::GenerateKey(); - auto materials = Aws::MakeShared(ALLOCATION_TAG, key); - CryptoConfigurationV2 configuration(materials); - configuration.SetStorageMethod(StorageMethod::INSTRUCTION_FILE); - - Aws::S3::S3ClientConfiguration s3ClientConfig; - s3ClientConfig.region = AWS_TEST_REGION; - - static const char* objectKey = "TestWriteV2Instruction"; - static const char* objectKeyInst = "TestWriteV2Instruction.instruction"; - - S3EncryptionClientV2 client(configuration, s3ClientConfig); - - Model::PutObjectRequest putObjectRequest; - putObjectRequest.WithBucket(BucketName.c_str()) - .WithKey(objectKey); - - auto ss = Aws::MakeShared(ALLOCATION_TAG); - *ss << TEST_STRING; - ss->flush(); - - putObjectRequest.SetBody(ss); - - auto putObjectResult = client.PutObject(putObjectRequest, {}); - AWS_ASSERT_SUCCESS(putObjectResult); - - Model::GetObjectRequest getObjectRequest; - getObjectRequest.WithBucket(BucketName.c_str()).WithKey(objectKey); - - auto getObjectResult = client.GetObject(getObjectRequest); - AWS_ASSERT_SUCCESS(getObjectResult); - - //= ../specification/s3-encryption/data-format/metadata-strategy.md#v1-v2-instruction-files - //= type=test - //# In the V1/V2 message format, all of the content metadata MUST be stored in the Instruction File. - auto metadata = getObjectResult.GetResult().GetMetadata(); - EXPECT_TRUE(metadata.empty()); - - getObjectRequest.WithKey(objectKeyInst); - Aws::S3::S3Client s3Client(s3ClientConfig); - - getObjectResult = s3Client.GetObject(getObjectRequest); - AWS_ASSERT_SUCCESS(getObjectResult); - - metadata = getObjectResult.GetResult().GetMetadata(); - EXPECT_TRUE(metadata.size() == 1); - EXPECT_STREQ("default instruction file header", metadata["x-amz-crypto-instr-file"].c_str()); - - //= ../specification/s3-encryption/data-format/metadata-strategy.md#instruction-file - //= type=test - //# The content metadata stored in the Instruction File MUST be serialized to a JSON string. - //# The serialized JSON string MUST be the only contents of the Instruction File. - Aws::StringStream responseStringStream; - responseStringStream << getObjectResult.GetResult().GetBody().rdbuf(); - auto jsonString = responseStringStream.str(); - auto inst_metadata = DeserializeMap(jsonString); -} - static bool contains(Aws::Map& m, const char * str) { return m.find(str) != m.end(); @@ -711,180 +414,6 @@ TEST_F(LiveClientTest, TestWriteV3Instruction) EXPECT_TRUE(contains(inst_metadata, "x-amz-w" )); } -TEST_F(LiveClientTest, TestAEMode) -{ - CryptoConfiguration configuration; - configuration.SetCryptoMode(CryptoMode::AUTHENTICATED_ENCRYPTION); - configuration.SetStorageMethod(StorageMethod::METADATA); - - Aws::S3::S3ClientConfiguration s3ClientConfig; - s3ClientConfig.region = AWS_TEST_REGION; - - auto key = SymmetricCipher::GenerateKey(); - auto simpleEncryptionMaterials = Aws::MakeShared(ALLOCATION_TAG, key); - - static const char* objectKey = "TestAEKey"; - - S3EncryptionClient client(simpleEncryptionMaterials, configuration, s3ClientConfig); - - Model::PutObjectRequest putObjectRequest; - putObjectRequest.WithBucket(BucketName.c_str()) - .WithKey(objectKey); - - auto ss = Aws::MakeShared(ALLOCATION_TAG); - *ss << TEST_STRING; - ss->flush(); - - putObjectRequest.SetBody(ss); - - auto putObjectResult = client.PutObject(putObjectRequest); - AWS_ASSERT_SUCCESS(putObjectResult); - - Model::GetObjectRequest getObjectRequest; - getObjectRequest.WithBucket(BucketName.c_str()).WithKey(objectKey); - - auto getObjectResult = client.GetObject(getObjectRequest); - AWS_EXPECT_SUCCESS(getObjectResult); - - Aws::StringStream responseStringStream; - responseStringStream << getObjectResult.GetResult().GetBody().rdbuf(); - - EXPECT_STREQ(TEST_STRING, responseStringStream.str().c_str()); - - auto metadata = getObjectResult.GetResult().GetMetadata(); - auto ivStr = metadata["x-amz-iv"]; - auto cekStr = metadata["x-amz-key-v2"]; - auto tagLenStr = metadata["x-amz-tag-len"]; - auto aad = metadata["x-amz-cek-alg"]; - EXPECT_FALSE(ivStr.empty()); - EXPECT_FALSE(cekStr.empty()); - EXPECT_FALSE(tagLenStr.empty()); - EXPECT_STREQ("128", tagLenStr.c_str()); - EXPECT_FALSE(aad.empty()); - - ContentCryptoMaterial cryptoMaterial(ContentCryptoScheme::GCM); - cryptoMaterial.SetFinalCEK(HashingUtils::Base64Decode(cekStr)); - cryptoMaterial.SetKeyWrapAlgorithm(KeyWrapAlgorithm::AES_GCM); - cryptoMaterial.SetGCMAAD(CryptoBuffer((const unsigned char*)aad.c_str(), aad.size())); - cryptoMaterial.SetCryptoTagLength(static_cast(StringUtils::ConvertToInt64(tagLenStr.c_str()))); - simpleEncryptionMaterials->DecryptCEK(cryptoMaterial); - - auto gcmCipher = CreateAES_GCMImplementation(cryptoMaterial.GetContentEncryptionKey(), HashingUtils::Base64Decode(ivStr)); - - Aws::StringStream comparisonStream; - Crypto::SymmetricCryptoStream cryptoStream((Aws::OStream&)comparisonStream, CipherMode::Encrypt, *gcmCipher); - - Model::GetObjectRequest getUnencryptedObjectRequest; - getUnencryptedObjectRequest.WithBucket(BucketName.c_str()).WithKey(objectKey); - auto standardGetObjectResult = StandardClient->GetObject(getUnencryptedObjectRequest); - - AWS_EXPECT_SUCCESS(standardGetObjectResult); - EXPECT_EQ((cryptoMaterial.GetCryptoTagLength() / 8) + sizeof(TEST_STRING) - 1, static_cast(standardGetObjectResult.GetResult().GetContentLength())); - - ByteBuffer rawData(static_cast< size_t >(standardGetObjectResult.GetResult().GetContentLength()) - (cryptoMaterial.GetCryptoTagLength() / 8)); - memset(rawData.GetUnderlyingData(), 0, rawData.GetLength()); - standardGetObjectResult.GetResult().GetBody().read((char*)rawData.GetUnderlyingData(), rawData.GetLength()); - - cryptoStream << TEST_STRING; - cryptoStream.Finalize(); - - ByteBuffer comparisonResult((unsigned char*)comparisonStream.str().c_str(), comparisonStream.str().length()); - EXPECT_STREQ(HashingUtils::HexEncode(comparisonResult).c_str(), HashingUtils::HexEncode(rawData).c_str()); - - Model::DeleteObjectRequest deleteObject; - deleteObject.WithBucket(BucketName.c_str()).WithKey(objectKey); - - auto deleteResult = StandardClient->DeleteObject(deleteObject); - AWS_EXPECT_SUCCESS(deleteResult); -} - -TEST_F(LiveClientTest, TestAEModeRangeGet) -{ - CryptoConfiguration configuration; - configuration.SetCryptoMode(CryptoMode::AUTHENTICATED_ENCRYPTION); - configuration.SetStorageMethod(StorageMethod::METADATA); - - Aws::S3::S3ClientConfiguration s3ClientConfig; - s3ClientConfig.region = AWS_TEST_REGION; - - auto key = SymmetricCipher::GenerateKey(); - auto simpleEncryptionMaterials = Aws::MakeShared(ALLOCATION_TAG, key); - - static const char* objectKey = "TestAERangeGetKey"; - - S3EncryptionClient client(simpleEncryptionMaterials, configuration, s3ClientConfig); - - Model::PutObjectRequest putObjectRequest; - putObjectRequest.WithBucket(BucketName.c_str()) - .WithKey(objectKey); - - auto ss = Aws::MakeShared(ALLOCATION_TAG); - *ss << TEST_STRING; - ss->flush(); - - putObjectRequest.SetBody(ss); - - auto putObjectResult = client.PutObject(putObjectRequest); - AWS_ASSERT_SUCCESS(putObjectResult); - - Model::GetObjectRequest getObjectRequest; - getObjectRequest.WithBucket(BucketName.c_str()).WithKey(objectKey).WithRange(RANGE_GET_STR); - - auto getObjectResult = client.GetObject(getObjectRequest); - AWS_EXPECT_SUCCESS(getObjectResult); - - Aws::StringStream responseStringStream; - responseStringStream << getObjectResult.GetResult().GetBody().rdbuf(); - - EXPECT_STREQ(RANGE_GET_TEST_STRING, responseStringStream.str().c_str()); - - auto metadata = getObjectResult.GetResult().GetMetadata(); - auto ivStr = metadata["x-amz-iv"]; - auto cekStr = metadata["x-amz-key-v2"]; - auto tagLenStr = metadata["x-amz-tag-len"]; - auto aad = metadata["x-amz-cek-alg"]; - EXPECT_FALSE(ivStr.empty()); - EXPECT_FALSE(cekStr.empty()); - EXPECT_FALSE(tagLenStr.empty()); - EXPECT_STREQ("128", tagLenStr.c_str()); - EXPECT_FALSE(aad.empty()); - - ContentCryptoMaterial cryptoMaterial(ContentCryptoScheme::GCM); - cryptoMaterial.SetFinalCEK(HashingUtils::Base64Decode(cekStr)); - cryptoMaterial.SetKeyWrapAlgorithm(KeyWrapAlgorithm::AES_GCM); - cryptoMaterial.SetGCMAAD(CryptoBuffer((const unsigned char*)aad.c_str(), aad.size())); - cryptoMaterial.SetCryptoTagLength(static_cast(StringUtils::ConvertToInt64(tagLenStr.c_str()))); - simpleEncryptionMaterials->DecryptCEK(cryptoMaterial); - - auto gcmCipher = CreateAES_GCMImplementation(cryptoMaterial.GetContentEncryptionKey(), HashingUtils::Base64Decode(ivStr)); - - Aws::StringStream comparisonStream; - Crypto::SymmetricCryptoStream cryptoStream((Aws::OStream&)comparisonStream, CipherMode::Encrypt, *gcmCipher); - - Model::GetObjectRequest getUnencryptedObjectRequest; - getUnencryptedObjectRequest.WithBucket(BucketName.c_str()).WithKey(objectKey).WithRange(RANGE_GET_STR); - auto standardGetObjectResult = StandardClient->GetObject(getUnencryptedObjectRequest); - - AWS_EXPECT_SUCCESS(standardGetObjectResult); - EXPECT_EQ(sizeof(RANGE_GET_TEST_STRING) - 1, static_cast(standardGetObjectResult.GetResult().GetContentLength())); - - ByteBuffer rawData(static_cast< size_t >(standardGetObjectResult.GetResult().GetContentLength())); - memset(rawData.GetUnderlyingData(), 0, rawData.GetLength()); - standardGetObjectResult.GetResult().GetBody().read((char*)rawData.GetUnderlyingData(), rawData.GetLength()); - - cryptoStream << TEST_STRING; - cryptoStream.Finalize(); - - //we just want to compare the actual range we fetched. range was bytes=38-75 - ByteBuffer comparisonResult((unsigned char*)comparisonStream.str().c_str() + 38, 75 - 38 + 1); - EXPECT_STREQ(HashingUtils::HexEncode(comparisonResult).c_str(), HashingUtils::HexEncode(rawData).c_str()); - - Model::DeleteObjectRequest deleteObject; - deleteObject.WithBucket(BucketName.c_str()).WithKey(objectKey); - - auto deleteResult = StandardClient->DeleteObject(deleteObject); - AWS_EXPECT_SUCCESS(deleteResult); -} //= ../specification/s3-encryption/client.md#enable-delayed-authentication //= type=test @@ -966,376 +495,3 @@ TEST_F(LiveClientTest, TestGcmModeRangeGet) ASSERT_FALSE(getObjectResult.IsSuccess()); } -TEST_F(LiveClientTest, TestS3EncryptionError) -{ - Aws::S3::S3ClientConfiguration s3ClientConfig; - s3ClientConfig.region = AWS_TEST_REGION; - - auto kmsMaterials = Aws::MakeShared("s3Encryption", "badKey"); - Aws::S3Encryption::CryptoConfiguration cryptoConfiguration(Aws::S3Encryption::StorageMethod::METADATA, Aws::S3Encryption::CryptoMode::ENCRYPTION_ONLY); - auto credentials = Aws::MakeShared("s3Encryption"); - Aws::S3Encryption::S3EncryptionClient encryptionClient(kmsMaterials, cryptoConfiguration, credentials, s3ClientConfig); - - Model::PutObjectRequest putObjectRequest; - putObjectRequest.WithBucket("badBucket").WithKey("badKey"); - - auto ss = Aws::MakeShared(ALLOCATION_TAG); - *ss << TEST_STRING; - ss->flush(); - - putObjectRequest.SetBody(ss); - - auto putObjectOutcome = encryptionClient.PutObject(putObjectRequest); - ASSERT_FALSE(putObjectOutcome.IsSuccess()); - ASSERT_TRUE(putObjectOutcome.GetError().GetErrorType().IsCryptoError()); - ASSERT_FALSE(putObjectOutcome.GetError().GetErrorType().IsS3Error()); - ASSERT_EQ(CryptoErrors::GENERATE_CONTENT_ENCRYPTION_KEY_FAILED, putObjectOutcome.GetError().GetErrorType().cryptoError); - - Model::GetObjectRequest getObjectRequest; - getObjectRequest.WithBucket("badBucket").WithKey("badKey"); - auto getObjectOutcome = encryptionClient.GetObject(getObjectRequest); - ASSERT_FALSE(getObjectOutcome.IsSuccess()); - ASSERT_FALSE(getObjectOutcome.GetError().GetErrorType().IsCryptoError()); - ASSERT_TRUE(getObjectOutcome.GetError().GetErrorType().IsS3Error()); - ASSERT_EQ(Aws::Http::HttpResponseCode::NOT_FOUND, getObjectOutcome.GetError().GetResponseCode()); -} - -TEST_F(LiveClientTest, TestV2AEMode) -{ - Aws::S3::S3ClientConfiguration s3ClientConfig; - s3ClientConfig.region = AWS_TEST_REGION; - - auto key = SymmetricCipher::GenerateKey(); - auto simpleEncryptionMaterials = Aws::MakeShared(ALLOCATION_TAG, key); - CryptoConfigurationV2 configuration(simpleEncryptionMaterials); - - static const char* objectKey = "TestV2AEKey"; - - S3EncryptionClientV2 client(configuration, s3ClientConfig); - - Model::PutObjectRequest putObjectRequest; - putObjectRequest.WithBucket(BucketName.c_str()) - .WithKey(objectKey); - - auto ss = Aws::MakeShared(ALLOCATION_TAG); - *ss << TEST_STRING; - ss->flush(); - - putObjectRequest.SetBody(ss); - - auto putObjectResult = client.PutObject(putObjectRequest, {}); - AWS_ASSERT_SUCCESS(putObjectResult); - - Model::GetObjectRequest getObjectRequest; - getObjectRequest.WithBucket(BucketName.c_str()).WithKey(objectKey); - - auto getObjectResult = client.GetObject(getObjectRequest); - AWS_EXPECT_SUCCESS(getObjectResult); - - Aws::StringStream responseStringStream; - responseStringStream << getObjectResult.GetResult().GetBody().rdbuf(); - - EXPECT_STREQ(TEST_STRING, responseStringStream.str().c_str()); - - auto metadata = getObjectResult.GetResult().GetMetadata(); - - //= ../specification/s3-encryption/data-format/content-metadata.md#content-metadata-mapkeys - //= type=test - //# - The mapkey "x-amz-key-v2" MUST be present for V2 format objects. - //# - The mapkey "x-amz-matdesc" MUST be present for V2 format objects. - //# - The mapkey "x-amz-iv" MUST be present for V2 format objects. - //# - The mapkey "x-amz-wrap-alg" MUST be present for V2 format objects. - //# - The mapkey "x-amz-cek-alg" MUST be present for V2 format objects. - //# - The mapkey "x-amz-tag-len" MUST be present for V2 format objects. - - auto cekStr = metadata["x-amz-key-v2"]; - auto matdesc = metadata["x-amz-matdesc"]; - auto ivStr = metadata["x-amz-iv"]; - auto alg = metadata["x-amz-wrap-alg"]; - auto aad = metadata["x-amz-cek-alg"]; - auto tagLenStr = metadata["x-amz-tag-len"]; - EXPECT_FALSE(cekStr.empty()); - EXPECT_STREQ("{}", matdesc.c_str()); - EXPECT_FALSE(ivStr.empty()); - EXPECT_STREQ("AES/GCM", alg.c_str()); - EXPECT_STREQ("AES/GCM/NoPadding", aad.c_str()); - EXPECT_FALSE(aad.empty()); - EXPECT_STREQ("128", tagLenStr.c_str()); - - ContentCryptoMaterial cryptoMaterial(ContentCryptoScheme::GCM); - cryptoMaterial.SetFinalCEK(HashingUtils::Base64Decode(cekStr)); - cryptoMaterial.SetKeyWrapAlgorithm(KeyWrapAlgorithm::AES_GCM); - cryptoMaterial.SetGCMAAD(CryptoBuffer((const unsigned char*)aad.c_str(), aad.size())); - cryptoMaterial.SetCryptoTagLength(static_cast(StringUtils::ConvertToInt64(tagLenStr.c_str()))); - simpleEncryptionMaterials->DecryptCEK(cryptoMaterial); - - auto gcmCipher = CreateAES_GCMImplementation(cryptoMaterial.GetContentEncryptionKey(), HashingUtils::Base64Decode(ivStr)); - - Aws::StringStream comparisonStream; - Crypto::SymmetricCryptoStream cryptoStream((Aws::OStream&)comparisonStream, CipherMode::Encrypt, *gcmCipher); - - Model::GetObjectRequest getUnencryptedObjectRequest; - getUnencryptedObjectRequest.WithBucket(BucketName.c_str()).WithKey(objectKey); - auto standardGetObjectResult = StandardClient->GetObject(getUnencryptedObjectRequest); - - AWS_EXPECT_SUCCESS(standardGetObjectResult); - EXPECT_EQ((cryptoMaterial.GetCryptoTagLength() / 8) + sizeof(TEST_STRING) - 1, static_cast(standardGetObjectResult.GetResult().GetContentLength())); - - ByteBuffer rawData(static_cast< size_t >(standardGetObjectResult.GetResult().GetContentLength()) - (cryptoMaterial.GetCryptoTagLength() / 8)); - memset(rawData.GetUnderlyingData(), 0, rawData.GetLength()); - standardGetObjectResult.GetResult().GetBody().read((char*)rawData.GetUnderlyingData(), rawData.GetLength()); - - cryptoStream << TEST_STRING; - cryptoStream.Finalize(); - - ByteBuffer comparisonResult((unsigned char*)comparisonStream.str().c_str(), comparisonStream.str().length()); - EXPECT_STREQ(HashingUtils::HexEncode(comparisonResult).c_str(), HashingUtils::HexEncode(rawData).c_str()); - - Model::DeleteObjectRequest deleteObject; - deleteObject.WithBucket(BucketName.c_str()).WithKey(objectKey); - - auto deleteResult = StandardClient->DeleteObject(deleteObject); - AWS_EXPECT_SUCCESS(deleteResult); -} - -TEST_F(LiveClientTest, TestV2AEModeRangeGetPass) -{ - Aws::S3::S3ClientConfiguration s3ClientConfig; - s3ClientConfig.region = AWS_TEST_REGION; - - auto key = SymmetricCipher::GenerateKey(); - auto simpleEncryptionMaterials = Aws::MakeShared(ALLOCATION_TAG, key); - CryptoConfigurationV2 configuration(simpleEncryptionMaterials); - configuration.SetUnAuthenticatedRangeGet(RangeGetMode::ALL); - S3EncryptionClientV2 client(configuration, s3ClientConfig); - - static const char* objectKey = "TestV2AERangeGetKey"; - - Model::PutObjectRequest putObjectRequest; - putObjectRequest.WithBucket(BucketName.c_str()) - .WithKey(objectKey); - - auto ss = Aws::MakeShared(ALLOCATION_TAG); - *ss << TEST_STRING; - ss->flush(); - - putObjectRequest.SetBody(ss); - - auto putObjectResult = client.PutObject(putObjectRequest, {}); - AWS_ASSERT_SUCCESS(putObjectResult); - - Model::GetObjectRequest getObjectRequest; - getObjectRequest.WithBucket(BucketName.c_str()).WithKey(objectKey).WithRange(RANGE_GET_STR); - - auto getObjectResult = client.GetObject(getObjectRequest); - AWS_EXPECT_SUCCESS(getObjectResult); - - Aws::StringStream responseStringStream; - responseStringStream << getObjectResult.GetResult().GetBody().rdbuf(); - - EXPECT_STREQ(RANGE_GET_TEST_STRING, responseStringStream.str().c_str()); - - auto metadata = getObjectResult.GetResult().GetMetadata(); - auto ivStr = metadata["x-amz-iv"]; - auto cekStr = metadata["x-amz-key-v2"]; - auto tagLenStr = metadata["x-amz-tag-len"]; - auto aad = metadata["x-amz-cek-alg"]; - EXPECT_FALSE(ivStr.empty()); - EXPECT_FALSE(cekStr.empty()); - EXPECT_FALSE(tagLenStr.empty()); - EXPECT_STREQ("128", tagLenStr.c_str()); - EXPECT_FALSE(aad.empty()); - - ContentCryptoMaterial cryptoMaterial(ContentCryptoScheme::GCM); - cryptoMaterial.SetFinalCEK(HashingUtils::Base64Decode(cekStr)); - cryptoMaterial.SetKeyWrapAlgorithm(KeyWrapAlgorithm::AES_GCM); - cryptoMaterial.SetGCMAAD(CryptoBuffer((const unsigned char*)aad.c_str(), aad.size())); - cryptoMaterial.SetCryptoTagLength(static_cast(StringUtils::ConvertToInt64(tagLenStr.c_str()))); - simpleEncryptionMaterials->DecryptCEK(cryptoMaterial); - - auto gcmCipher = CreateAES_GCMImplementation(cryptoMaterial.GetContentEncryptionKey(), HashingUtils::Base64Decode(ivStr)); - - Aws::StringStream comparisonStream; - Crypto::SymmetricCryptoStream cryptoStream((Aws::OStream&)comparisonStream, CipherMode::Encrypt, *gcmCipher); - - Model::GetObjectRequest getUnencryptedObjectRequest; - getUnencryptedObjectRequest.WithBucket(BucketName.c_str()).WithKey(objectKey).WithRange(RANGE_GET_STR); - auto standardGetObjectResult = StandardClient->GetObject(getUnencryptedObjectRequest); - - AWS_EXPECT_SUCCESS(standardGetObjectResult); - EXPECT_EQ(sizeof(RANGE_GET_TEST_STRING) - 1, static_cast(standardGetObjectResult.GetResult().GetContentLength())); - - ByteBuffer rawData(static_cast< size_t >(standardGetObjectResult.GetResult().GetContentLength())); - memset(rawData.GetUnderlyingData(), 0, rawData.GetLength()); - standardGetObjectResult.GetResult().GetBody().read((char*)rawData.GetUnderlyingData(), rawData.GetLength()); - - cryptoStream << TEST_STRING; - cryptoStream.Finalize(); - - //we just want to compare the actual range we fetched. range was bytes=38-75 - ByteBuffer comparisonResult((unsigned char*)comparisonStream.str().c_str() + 38, 75 - 38 + 1); - EXPECT_STREQ(HashingUtils::HexEncode(comparisonResult).c_str(), HashingUtils::HexEncode(rawData).c_str()); - - Model::DeleteObjectRequest deleteObject; - deleteObject.WithBucket(BucketName.c_str()).WithKey(objectKey); - - auto deleteResult = StandardClient->DeleteObject(deleteObject); - AWS_EXPECT_SUCCESS(deleteResult); -} - -TEST_F(LiveClientTest, TestV2AEModeRangeGetFailWithoutSetting) -{ - Aws::S3::S3ClientConfiguration s3ClientConfig; - s3ClientConfig.region = AWS_TEST_REGION; - - auto key = SymmetricCipher::GenerateKey(); - auto simpleEncryptionMaterials = Aws::MakeShared(ALLOCATION_TAG, key); - CryptoConfigurationV2 configuration(simpleEncryptionMaterials); - S3EncryptionClientV2 client(configuration, s3ClientConfig); - - static const char* objectKey = "TestV2AERangeGetKeyFail"; - - Model::PutObjectRequest putObjectRequest; - putObjectRequest.WithBucket(BucketName.c_str()) - .WithKey(objectKey); - - auto ss = Aws::MakeShared(ALLOCATION_TAG); - *ss << TEST_STRING; - ss->flush(); - - putObjectRequest.SetBody(ss); - - auto putObjectResult = client.PutObject(putObjectRequest, {}); - AWS_ASSERT_SUCCESS(putObjectResult); - - Model::GetObjectRequest getObjectRequest; - getObjectRequest.WithBucket(BucketName.c_str()).WithKey(objectKey).WithRange(RANGE_GET_STR); - - auto getObjectResult = client.GetObject(getObjectRequest); - EXPECT_FALSE(getObjectResult.IsSuccess()); - - Model::DeleteObjectRequest deleteObject; - deleteObject.WithBucket(BucketName.c_str()).WithKey(objectKey); - - auto deleteResult = StandardClient->DeleteObject(deleteObject); - AWS_EXPECT_SUCCESS(deleteResult); -} - -TEST_F(LiveClientTest, TestV2AEModeRangeGetPassWithRangeUpperBoundOverflow) -{ - Aws::S3::S3ClientConfiguration s3ClientConfig; - s3ClientConfig.region = AWS_TEST_REGION; - - auto key = SymmetricCipher::GenerateKey(); - auto simpleEncryptionMaterials = Aws::MakeShared(ALLOCATION_TAG, key); - CryptoConfigurationV2 configuration(simpleEncryptionMaterials); - configuration.SetUnAuthenticatedRangeGet(RangeGetMode::ALL); - S3EncryptionClientV2 client(configuration, s3ClientConfig); - - static const char* objectKey = "TestAERangeGetKey"; - - Model::PutObjectRequest putObjectRequest; - putObjectRequest.WithBucket(BucketName.c_str()) - .WithKey(objectKey); - - auto ss = Aws::MakeShared(ALLOCATION_TAG); - *ss << TEST_STRING; - ss->flush(); - - putObjectRequest.SetBody(ss); - - auto putObjectResult = client.PutObject(putObjectRequest, {}); - AWS_ASSERT_SUCCESS(putObjectResult); - - Model::GetObjectRequest getObjectRequest; - getObjectRequest.WithBucket(BucketName.c_str()).WithKey(objectKey).WithRange(OVERFLOW_RANGE_GET_STR); - - auto getObjectResult = client.GetObject(getObjectRequest); - AWS_EXPECT_SUCCESS(getObjectResult); - - Aws::StringStream responseStringStream; - responseStringStream << getObjectResult.GetResult().GetBody().rdbuf(); - - EXPECT_STREQ(OVERFLOW_RANGE_GET_TEST_STRING, responseStringStream.str().c_str()); - - auto metadata = getObjectResult.GetResult().GetMetadata(); - auto ivStr = metadata["x-amz-iv"]; - auto cekStr = metadata["x-amz-key-v2"]; - auto tagLenStr = metadata["x-amz-tag-len"]; - auto aad = metadata["x-amz-cek-alg"]; - EXPECT_FALSE(ivStr.empty()); - EXPECT_FALSE(cekStr.empty()); - EXPECT_FALSE(tagLenStr.empty()); - EXPECT_STREQ("128", tagLenStr.c_str()); - EXPECT_FALSE(aad.empty()); - - ContentCryptoMaterial cryptoMaterial(ContentCryptoScheme::GCM); - cryptoMaterial.SetFinalCEK(HashingUtils::Base64Decode(cekStr)); - cryptoMaterial.SetKeyWrapAlgorithm(KeyWrapAlgorithm::AES_GCM); - cryptoMaterial.SetGCMAAD(CryptoBuffer((const unsigned char*)aad.c_str(), aad.size())); - cryptoMaterial.SetCryptoTagLength(static_cast(StringUtils::ConvertToInt64(tagLenStr.c_str()))); - simpleEncryptionMaterials->DecryptCEK(cryptoMaterial); - - auto gcmCipher = CreateAES_GCMImplementation(cryptoMaterial.GetContentEncryptionKey(), HashingUtils::Base64Decode(ivStr)); - - Aws::StringStream comparisonStream; - Crypto::SymmetricCryptoStream cryptoStream((Aws::OStream&)comparisonStream, CipherMode::Encrypt, *gcmCipher); - - Model::GetObjectRequest getUnencryptedObjectRequest; - getUnencryptedObjectRequest.WithBucket(BucketName.c_str()).WithKey(objectKey).WithRange(RANGE_GET_STR); - auto standardGetObjectResult = StandardClient->GetObject(getUnencryptedObjectRequest); - - AWS_EXPECT_SUCCESS(standardGetObjectResult); - EXPECT_EQ(sizeof(RANGE_GET_TEST_STRING) - 1, static_cast(standardGetObjectResult.GetResult().GetContentLength())); - - ByteBuffer rawData(static_cast< size_t >(standardGetObjectResult.GetResult().GetContentLength())); - memset(rawData.GetUnderlyingData(), 0, rawData.GetLength()); - standardGetObjectResult.GetResult().GetBody().read((char*)rawData.GetUnderlyingData(), rawData.GetLength()); - - cryptoStream << TEST_STRING; - cryptoStream.Finalize(); - - //we just want to compare the actual range we fetched. range was bytes=38-75 - ByteBuffer comparisonResult((unsigned char*)comparisonStream.str().c_str() + 38, 75 - 38 + 1); - EXPECT_STREQ(HashingUtils::HexEncode(comparisonResult).c_str(), HashingUtils::HexEncode(rawData).c_str()); - - Model::DeleteObjectRequest deleteObject; - deleteObject.WithBucket(BucketName.c_str()).WithKey(objectKey); - - auto deleteResult = StandardClient->DeleteObject(deleteObject); - AWS_EXPECT_SUCCESS(deleteResult); -} - -TEST_F(LiveClientTest, TestV2S3EncryptionError) -{ - Aws::S3::S3ClientConfiguration s3ClientConfig; - s3ClientConfig.region = AWS_TEST_REGION; - - auto kmsMaterials = Aws::MakeShared("s3Encryption", "badKey"); - Aws::S3Encryption::CryptoConfigurationV2 cryptoConfiguration(kmsMaterials); - auto credentials = Aws::MakeShared("s3Encryption"); - Aws::S3Encryption::S3EncryptionClientV2 encryptionClient(cryptoConfiguration, credentials, s3ClientConfig); - - Model::PutObjectRequest putObjectRequest; - putObjectRequest.WithBucket("badBucket").WithKey("badKey"); - - auto ss = Aws::MakeShared(ALLOCATION_TAG); - *ss << TEST_STRING; - ss->flush(); - - putObjectRequest.SetBody(ss); - - auto putObjectOutcome = encryptionClient.PutObject(putObjectRequest, {}); - ASSERT_FALSE(putObjectOutcome.IsSuccess()); - ASSERT_TRUE(putObjectOutcome.GetError().GetErrorType().IsCryptoError()); - ASSERT_FALSE(putObjectOutcome.GetError().GetErrorType().IsS3Error()); - ASSERT_EQ(CryptoErrors::GENERATE_CONTENT_ENCRYPTION_KEY_FAILED, putObjectOutcome.GetError().GetErrorType().cryptoError); - - Model::GetObjectRequest getObjectRequest; - getObjectRequest.WithBucket("badBucket").WithKey("badKey"); - auto getObjectOutcome = encryptionClient.GetObject(getObjectRequest); - ASSERT_FALSE(getObjectOutcome.IsSuccess()); - ASSERT_FALSE(getObjectOutcome.GetError().GetErrorType().IsCryptoError()); - ASSERT_TRUE(getObjectOutcome.GetError().GetErrorType().IsS3Error()); - ASSERT_EQ(Aws::Http::HttpResponseCode::NOT_FOUND, getObjectOutcome.GetError().GetResponseCode()); -} From 9e5044a6f587570e309dc3c73eb749348cb26f5a Mon Sep 17 00:00:00 2001 From: Avery Kuo Date: Mon, 16 Nov 2026 14:58:37 -0500 Subject: [PATCH 2/3] Fix account ID and AWS_DEFAULT_PROFILE in ProfileCredentialsProvider CrtCredentialsProvider::ExtractCredentialsFromCrt never copied the CRT's account ID, so every CRT-backed provider, including ProfileCredentialsProvider in the default chain, dropped aws_account_id from the profile and AccountId from credential_process output. DynamoDB then fell back from account-based endpoints to the regional endpoint, and accountIdEndpointMode=required failed. ProfileCredentialsProvider's default constructor let the CRT pick the profile from AWS_PROFILE alone, while the rest of the SDK, and its own configuration constructor, use GetConfigProfileName(), which checks AWS_DEFAULT_PROFILE first. It now uses GetConfigProfileName() too. Document that ProfileCredentialsProvider reads the files once and ignores refreshRateMs. --- .../bugfix-crt-credentials-account-id.json | 6 +++ ...-profile-provider-aws-default-profile.json | 6 +++ .../core/auth/ProfileCredentialsProvider.h | 10 ++-- .../source/auth/CrtCredentialsProvider.cpp | 6 ++- .../auth/ProfileCredentialsProvider.cpp | 5 +- .../auth/ProfileCredentialsProviderTests.cpp | 54 +++++++++++++++++++ 6 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 .changelog/bugfix-crt-credentials-account-id.json create mode 100644 .changelog/bugfix-profile-provider-aws-default-profile.json diff --git a/.changelog/bugfix-crt-credentials-account-id.json b/.changelog/bugfix-crt-credentials-account-id.json new file mode 100644 index 000000000000..d790e31854b1 --- /dev/null +++ b/.changelog/bugfix-crt-credentials-account-id.json @@ -0,0 +1,6 @@ +{ + "type": "bugfix", + "category": "aws-cpp-sdk-core", + "contributor": "averyk22", + "description": "CRT-backed credentials providers, including ProfileCredentialsProvider in the default chain, now return the account ID from aws_account_id in the profile and AccountId in credential_process output. Without it, DynamoDB fell back from account-based endpoints to the regional endpoint, and accountIdEndpointMode=required failed." +} diff --git a/.changelog/bugfix-profile-provider-aws-default-profile.json b/.changelog/bugfix-profile-provider-aws-default-profile.json new file mode 100644 index 000000000000..f74f7621f0c7 --- /dev/null +++ b/.changelog/bugfix-profile-provider-aws-default-profile.json @@ -0,0 +1,6 @@ +{ + "type": "bugfix", + "category": "aws-cpp-sdk-core", + "contributor": "averyk22", + "description": "ProfileCredentialsProvider's default constructor, used by the default credentials chain, now picks its profile the same way as the rest of the SDK: AWS_DEFAULT_PROFILE, then AWS_PROFILE, then default. It previously ignored AWS_DEFAULT_PROFILE, so credentials and settings like the region could come from different profiles." +} diff --git a/src/aws-cpp-sdk-core/include/aws/core/auth/ProfileCredentialsProvider.h b/src/aws-cpp-sdk-core/include/aws/core/auth/ProfileCredentialsProvider.h index daaf9e8d17a2..fbaddbaed383 100644 --- a/src/aws-cpp-sdk-core/include/aws/core/auth/ProfileCredentialsProvider.h +++ b/src/aws-cpp-sdk-core/include/aws/core/auth/ProfileCredentialsProvider.h @@ -12,22 +12,26 @@ namespace Auth { /** * CRT-based credentials provider that sources credentials from config files with full SEP compliance. * Supports assume role, credential_source, role chaining, and all SEP scenarios. + * + * The config and credentials files are read once, when the provider is created. Credentials that expire, such as + * from assume role or credential_process, are refreshed from those settings, but later changes to the files, such + * as rotated keys, are only picked up by a new provider. refreshRateMs is ignored. */ class AWS_CORE_API ProfileCredentialsProvider : public AWSCredentialsProvider { public: /** - * Initializes with refreshRateMs as the frequency at which the file is reparsed in milliseconds. Defaults to 5 minutes. + * Initializes with the profile from AWS_DEFAULT_PROFILE, then AWS_PROFILE, then "default". refreshRateMs is ignored. */ ProfileCredentialsProvider(long refreshRateMs = REFRESH_THRESHOLD); /** - * Initializes with a profile override and - * refreshRateMs as the frequency at which the file is reparsed in milliseconds. Defaults to 5 minutes. + * Initializes with a profile override. refreshRateMs is ignored. */ ProfileCredentialsProvider(const char* profile, long refreshRateMs = REFRESH_THRESHOLD); /** * Initializes from a CredentialProviderConfiguration so settings such as allowSystemProxy can flow through. + * refreshRateMs is ignored. */ ProfileCredentialsProvider(const Aws::Client::ClientConfiguration::CredentialProviderConfiguration& config, long refreshRateMs = REFRESH_THRESHOLD); diff --git a/src/aws-cpp-sdk-core/source/auth/CrtCredentialsProvider.cpp b/src/aws-cpp-sdk-core/source/auth/CrtCredentialsProvider.cpp index 5bdbe83f3e59..49a066efd884 100644 --- a/src/aws-cpp-sdk-core/source/auth/CrtCredentialsProvider.cpp +++ b/src/aws-cpp-sdk-core/source/auth/CrtCredentialsProvider.cpp @@ -95,13 +95,15 @@ void CrtCredentialsProvider::RefreshIfExpired() { AWSCredentials CrtCredentialsProvider::ExtractCredentialsFromCrt(const Aws::Crt::Auth::Credentials& crtCredentials) { AWSCredentials credentials{}; - const auto accountIdCursor = crtCredentials.GetAccessKeyId(); - credentials.SetAWSAccessKeyId({reinterpret_cast(accountIdCursor.ptr), accountIdCursor.len}); + const auto accessKeyIdCursor = crtCredentials.GetAccessKeyId(); + credentials.SetAWSAccessKeyId({reinterpret_cast(accessKeyIdCursor.ptr), accessKeyIdCursor.len}); const auto secretKeyCursor = crtCredentials.GetSecretAccessKey(); credentials.SetAWSSecretKey({reinterpret_cast(secretKeyCursor.ptr), secretKeyCursor.len}); const uint64_t expiration = crtCredentials.GetExpirationTimepointInSeconds(); credentials.SetExpiration(DateTime{expiration}); const auto sessionTokenCursor = crtCredentials.GetSessionToken(); credentials.SetSessionToken({reinterpret_cast(sessionTokenCursor.ptr), sessionTokenCursor.len}); + const auto accountIdCursor = crtCredentials.GetAccountId(); + credentials.SetAccountId({reinterpret_cast(accountIdCursor.ptr), accountIdCursor.len}); return credentials; } \ No newline at end of file diff --git a/src/aws-cpp-sdk-core/source/auth/ProfileCredentialsProvider.cpp b/src/aws-cpp-sdk-core/source/auth/ProfileCredentialsProvider.cpp index b37ead67edda..6e9a63db9658 100644 --- a/src/aws-cpp-sdk-core/source/auth/ProfileCredentialsProvider.cpp +++ b/src/aws-cpp-sdk-core/source/auth/ProfileCredentialsProvider.cpp @@ -53,8 +53,9 @@ class ProfileCredentialsProvider::ProfileCredentialsProviderImp : public CrtCred ProfileCredentialsProviderImp() : CrtCredentialsProvider( []() -> std::shared_ptr { - CredentialsProviderProfileConfig config; - return CredentialsProvider::CreateCredentialsProviderProfile(config); + Aws::Client::ClientConfiguration::CredentialProviderConfiguration credentialsConfig{}; + credentialsConfig.profile = Aws::Auth::GetConfigProfileName(); + return GetProfileCrtProvider(credentialsConfig); }, std::chrono::milliseconds(DEFAULT_REFRESH_RATE_MS), UserAgentFeature::CREDENTIALS_PROFILE, "ProfileCredentialsProvider") {} diff --git a/tests/aws-cpp-sdk-core-tests/aws/auth/ProfileCredentialsProviderTests.cpp b/tests/aws-cpp-sdk-core-tests/aws/auth/ProfileCredentialsProviderTests.cpp index 1802cca4b3fe..cb523a7eb69a 100644 --- a/tests/aws-cpp-sdk-core-tests/aws/auth/ProfileCredentialsProviderTests.cpp +++ b/tests/aws-cpp-sdk-core-tests/aws/auth/ProfileCredentialsProviderTests.cpp @@ -24,6 +24,7 @@ class ProfileCredentialsProviderTests : public Aws::Testing::AwsCppSdkGTestSuite SaveEnv("AWS_CONFIG_FILE"); SaveEnv("AWS_SHARED_CREDENTIALS_FILE"); SaveEnv("AWS_PROFILE"); + SaveEnv("AWS_DEFAULT_PROFILE"); Aws::FileSystem::CreateDirectoryIfNotExists(GetTestDir().c_str()); m_configFile = GetTestDir() + "/config"; @@ -31,6 +32,7 @@ class ProfileCredentialsProviderTests : public Aws::Testing::AwsCppSdkGTestSuite Aws::Environment::SetEnv("AWS_CONFIG_FILE", m_configFile.c_str(), 1); Aws::Environment::SetEnv("AWS_SHARED_CREDENTIALS_FILE", m_credsFile.c_str(), 1); + Aws::Environment::UnSetEnv("AWS_DEFAULT_PROFILE"); } void TearDown() override { @@ -74,6 +76,45 @@ TEST_F(ProfileCredentialsProviderTests, LoadStaticCredentials) { EXPECT_STREQ("SecretKey456", credentials.GetAWSSecretKey().c_str()); } +TEST_F(ProfileCredentialsProviderTests, AwsDefaultProfileTakesPrecedenceOverAwsProfile) { + std::ofstream creds(m_credsFile.c_str()); + creds << "[default]\n"; + creds << "aws_access_key_id = DefaultKey\n"; + creds << "aws_secret_access_key = DefaultSecret\n"; + creds << "[profile_a]\n"; + creds << "aws_access_key_id = ProfileKey\n"; + creds << "aws_secret_access_key = ProfileSecret\n"; + creds << "[legacy]\n"; + creds << "aws_access_key_id = LegacyKey\n"; + creds << "aws_secret_access_key = LegacySecret\n"; + creds.close(); + + Aws::Environment::SetEnv("AWS_PROFILE", "profile_a", 1); + Aws::Environment::SetEnv("AWS_DEFAULT_PROFILE", "legacy", 1); + + // Matches Aws::Auth::GetConfigProfileName(), which the rest of the SDK uses to pick a profile. + ProfileCredentialsProvider provider; + auto credentials = provider.GetAWSCredentials(); + + EXPECT_STREQ("LegacyKey", credentials.GetAWSAccessKeyId().c_str()); + EXPECT_STREQ("LegacySecret", credentials.GetAWSSecretKey().c_str()); +} + +TEST_F(ProfileCredentialsProviderTests, LoadAccountIdFromCredentialsFile) { + std::ofstream creds(m_credsFile.c_str()); + creds << "[default]\n"; + creds << "aws_access_key_id = AKIATEST123\n"; + creds << "aws_secret_access_key = SecretKey456\n"; + creds << "aws_account_id = 111122223333\n"; + creds.close(); + + ProfileCredentialsProvider provider; + auto credentials = provider.GetAWSCredentials(); + + EXPECT_STREQ("AKIATEST123", credentials.GetAWSAccessKeyId().c_str()); + EXPECT_STREQ("111122223333", credentials.GetAccountId().c_str()); +} + TEST_F(ProfileCredentialsProviderTests, LoadNamedProfile) { std::ofstream creds(m_credsFile.c_str()); creds << "[default]\n"; @@ -133,3 +174,16 @@ TEST_F(ProfileCredentialsProviderTests, ProcessCredentials) { EXPECT_STREQ("ProcessKey", credentials.GetAWSAccessKeyId().c_str()); EXPECT_STREQ("ProcessSecret", credentials.GetAWSSecretKey().c_str()); } + +TEST_F(ProfileCredentialsProviderTests, ProcessCredentialsAccountId) { + std::ofstream config(m_configFile.c_str()); + config << "[default]\n"; + config << "credential_process = echo " << WrapEchoStringWithSingleQuoteForUnixShell("{\"Version\": 1, \"AccessKeyId\": \"ProcessKey\", \"SecretAccessKey\": \"ProcessSecret\", \"AccountId\": \"444455556666\"}") << "\n"; + config.close(); + + ProfileCredentialsProvider provider; + auto credentials = provider.GetAWSCredentials(); + + EXPECT_STREQ("ProcessKey", credentials.GetAWSAccessKeyId().c_str()); + EXPECT_STREQ("444455556666", credentials.GetAccountId().c_str()); +} From 4fdc3244e069a13d379b120f365c30c860cbfa3f Mon Sep 17 00:00:00 2001 From: Avery Kuo Date: Mon, 16 Nov 2026 14:58:46 -0500 Subject: [PATCH 3/3] Remove the replaced credentials providers Remove ProcessCredentialsProvider and the original ProfileConfigFileAWSCredentialsProvider. The default chain stopped using them once the CRT-backed ProfileCredentialsProvider took over their work, and with the account ID and AWS_DEFAULT_PROFILE fixes it now covers what they did, apart from re-reading the files on refreshRateMs. ProfileConfigFileAWSCredentialsProvider stays as a deprecated alias of ProfileCredentialsProvider. GetCredentialsFromProcess stays, since STSProfileCredentialsProvider uses it. Drop the GeneralHTTPCredentialsProvider.h include that AWSCredentialsProvider.h kept for 1.11 compatibility. Move the tests to ProfileCredentialsProvider: remove leading whitespace that the shared config format reads as a continuation line, drop the reload check and the ProcessCredentialsProvider tests, and point the credential_process tests at an empty credentials file so a local [default] can't take over. --- ...remove-replaced-credentials-providers.json | 6 + .../aws/core/auth/AWSCredentialsProvider.h | 98 +---------- .../core/auth/AWSCredentialsProviderChain.h | 8 +- .../core/auth/ProfileCredentialsProvider.h | 2 + .../source/auth/AWSCredentialsProvider.cpp | 146 ---------------- .../auth/AWSCredentialsProviderChain.cpp | 1 + .../aws/auth/AWSCredentialsProviderTest.cpp | 157 ++++-------------- .../aws/auth/CredentialTrackingTest.cpp | 15 +- .../DynamoDBUnitTests.cpp | 13 +- 9 files changed, 65 insertions(+), 381 deletions(-) create mode 100644 .changelog/breaking-change-remove-replaced-credentials-providers.json diff --git a/.changelog/breaking-change-remove-replaced-credentials-providers.json b/.changelog/breaking-change-remove-replaced-credentials-providers.json new file mode 100644 index 000000000000..123fb56eb47e --- /dev/null +++ b/.changelog/breaking-change-remove-replaced-credentials-providers.json @@ -0,0 +1,6 @@ +{ + "type": "breaking-change", + "category": "aws-cpp-sdk-core", + "contributor": "averyk22", + "description": "Remove ProcessCredentialsProvider and the original ProfileConfigFileAWSCredentialsProvider, which the default chain stopped using once the CRT-backed ProfileCredentialsProvider took over their work. ProfileConfigFileAWSCredentialsProvider still compiles as a deprecated alias of ProfileCredentialsProvider; use ProfileCredentialsProvider for credential_process too. Unlike the old provider, ProfileCredentialsProvider reads the config and credentials files once when it is created; its refreshRateMs is ignored, so keys rotated in the files are picked up only by a new provider. It also follows the shared config file format strictly: a line that starts with whitespace continues the previous property, so a profile line indented by mistake can stop the file from loading. Requests using credential_process now report the profile credentials feature in the user agent instead of the process credentials feature. AWSCredentialsProvider.h no longer includes GeneralHTTPCredentialsProvider.h; include it directly to use GeneralHTTPCredentialsProvider or TaskRoleCredentialsProvider." +} diff --git a/src/aws-cpp-sdk-core/include/aws/core/auth/AWSCredentialsProvider.h b/src/aws-cpp-sdk-core/include/aws/core/auth/AWSCredentialsProvider.h index a3371ccdab24..b247bb4951f6 100644 --- a/src/aws-cpp-sdk-core/include/aws/core/auth/AWSCredentialsProvider.h +++ b/src/aws-cpp-sdk-core/include/aws/core/auth/AWSCredentialsProvider.h @@ -146,58 +146,6 @@ namespace Aws AWSCredentials GetAWSCredentials() override; }; - /** - * Reads credentials profile from the default Profile Config File. Refreshes at set interval for credential rotation. - * Looks for environment variables AWS_SHARED_CREDENTIALS_FILE and AWS_PROFILE. If they aren't found, then it defaults - * to the default profile in ~/.aws/credentials. - * Optionally a user can specify the profile and it will override the environment variable - * and defaults. To alter the file this pulls from, then the user should alter the AWS_SHARED_CREDENTIALS_FILE variable. - */ - // class AWS_DEPRECATED("This class is in the maintenance mode, no new updates will be released, use S3EncryptionClientV3. Please see https://docs.aws.amazon.com/general/latest/gr/aws_sdk_cryptography.html for more information.") AWS_CORE_API ProfileConfigFileAWSCredentialsProvider : public AWSCredentialsProvider - class AWS_CORE_API ProfileConfigFileAWSCredentialsProvider : public AWSCredentialsProvider - { - public: - - /** - * Initializes with refreshRateMs as the frequency at which the file is reparsed in milliseconds. Defaults to 5 minutes. - */ - ProfileConfigFileAWSCredentialsProvider(long refreshRateMs = REFRESH_THRESHOLD); - - /** - * Initializes with a profile override and - * refreshRateMs as the frequency at which the file is reparsed in milliseconds. Defaults to 5 minutes. - */ - ProfileConfigFileAWSCredentialsProvider(const char* profile, long refreshRateMs = REFRESH_THRESHOLD); - - /** - * Retrieves the credentials if found, otherwise returns empty credential set. - */ - AWSCredentials GetAWSCredentials() override; - - /** - * Returns the fullpath of the calculated credentials profile file - */ - static Aws::String GetCredentialsProfileFilename(); - - /** - * Returns the directory storing the profile file. - */ - static Aws::String GetProfileDirectory(); - - protected: - void Reload() override; - private: - - /** - * Checks to see if the refresh interval has expired and reparses the file if it has. - */ - void RefreshIfExpired(); - - Aws::String m_profileToUse; - Aws::Config::AWSConfigFileProfileConfigLoader m_credentialsFileLoader; - long m_loadFrequencyMs; - }; - /** * Credentials provider implementation that loads credentials from the Amazon * EC2 Instance Metadata Service. @@ -237,51 +185,7 @@ namespace Aws std::shared_ptr m_ec2MetadataConfigLoader; long m_loadFrequencyMs; }; - - /** - * Process credentials provider that loads credentials by running another command (or program) configured in config file - * The configuration format is as following: - * credential_process = command_path - * Each time the credentials needs to be refreshed, this command will be executed with configured arguments. - * The default profile name to look up this configuration is "default", same as normal aws credentials configuration and other configurations. - * The expected valid output of the command is a Json doc output to stdout: - * {"Version": 1, "AccessKeyId": "AccessKey123", "SecretAccessKey": "SecretKey321", "SessionToken": "Token123", "Expiration": "1970-01-01T00:00:01Z"} - * The Version key specifies the version of the JSON payload and must be set to 1 for now (as an integer type). - * If the Version key is bumped to 2, SDKs would support both versions of the returned payload. - * Value of Expiration field should be an valid ISO8601 formatted date string as above example. - * The expected error message of the command is a string to output to stderr. - */ - class AWS_CORE_API ProcessCredentialsProvider : public AWSCredentialsProvider - { - public: - /** - * Initializes the provider by checking default profile - */ - ProcessCredentialsProvider(); - - /** - * Initializes the provider by checking specified profile - * @param profile which profile in config file to use. - */ - ProcessCredentialsProvider(const Aws::String& profile); - - /** - * Retrieves the credentials if found, otherwise returns empty credential set. - */ - AWSCredentials GetAWSCredentials() override; - - protected: - void Reload() override; - private: - void RefreshIfExpired(); - - private: - Aws::String m_profileToUse; - Aws::Auth::AWSCredentials m_credentials; - }; } // namespace Auth } // namespace Aws -// TODO: remove on a next minor API bump from 1.11.x -#endif // !defined(AWS_CLIENT_H) -#include \ No newline at end of file +#endif // !defined(AWS_CREDENTIALS_PROVIDER) diff --git a/src/aws-cpp-sdk-core/include/aws/core/auth/AWSCredentialsProviderChain.h b/src/aws-cpp-sdk-core/include/aws/core/auth/AWSCredentialsProviderChain.h index 98efd8bcaab1..5bdf60a4ea71 100644 --- a/src/aws-cpp-sdk-core/include/aws/core/auth/AWSCredentialsProviderChain.h +++ b/src/aws-cpp-sdk-core/include/aws/core/auth/AWSCredentialsProviderChain.h @@ -53,15 +53,15 @@ namespace Aws }; /** - * Creates an AWSCredentialsProviderChain which uses in order EnvironmentAWSCredentialsProvider, ProfileConfigFileAWSCredentialsProvider, - * ProcessCredentialsProvider, STSAssumeRoleWebIdentityCredentialsProvider and SSOCredentialsProvider. + * Creates an AWSCredentialsProviderChain which uses in order EnvironmentAWSCredentialsProvider, ProfileCredentialsProvider, + * STSAssumeRoleWebIdentityCredentialsProvider and SSOCredentialsProvider. */ class AWS_CORE_API DefaultAWSCredentialsProviderChain : public AWSCredentialsProviderChain { public: /** - * Initializes the provider chain with EnvironmentAWSCredentialsProvider, ProfileConfigFileAWSCredentialsProvider, - * ProcessCredentialsProvider, STSAssumeRoleWebIdentityCredentialsProvider and SSOCredentialsProvider in that order. + * Initializes the provider chain with EnvironmentAWSCredentialsProvider, ProfileCredentialsProvider, + * STSAssumeRoleWebIdentityCredentialsProvider and SSOCredentialsProvider in that order. */ DefaultAWSCredentialsProviderChain(); diff --git a/src/aws-cpp-sdk-core/include/aws/core/auth/ProfileCredentialsProvider.h b/src/aws-cpp-sdk-core/include/aws/core/auth/ProfileCredentialsProvider.h index fbaddbaed383..824a9ae7777a 100644 --- a/src/aws-cpp-sdk-core/include/aws/core/auth/ProfileCredentialsProvider.h +++ b/src/aws-cpp-sdk-core/include/aws/core/auth/ProfileCredentialsProvider.h @@ -58,5 +58,7 @@ class AWS_CORE_API ProfileCredentialsProvider : public AWSCredentialsProvider { class ProfileCredentialsProviderImp; std::shared_ptr m_impl; }; + +using ProfileConfigFileAWSCredentialsProvider [[deprecated("Use ProfileCredentialsProvider")]] = ProfileCredentialsProvider; } // namespace Auth } // namespace Aws diff --git a/src/aws-cpp-sdk-core/source/auth/AWSCredentialsProvider.cpp b/src/aws-cpp-sdk-core/source/auth/AWSCredentialsProvider.cpp index e009b64c98df..95fa4db89a6f 100644 --- a/src/aws-cpp-sdk-core/source/auth/AWSCredentialsProvider.cpp +++ b/src/aws-cpp-sdk-core/source/auth/AWSCredentialsProvider.cpp @@ -43,11 +43,9 @@ static const char DEFAULT_PROFILE[] = "default"; static const char AWS_PROFILE_ENV_VAR[] = "AWS_PROFILE"; static const char AWS_PROFILE_DEFAULT_ENV_VAR[] = "AWS_DEFAULT_PROFILE"; -static const char AWS_CREDENTIALS_FILE[] = "AWS_SHARED_CREDENTIALS_FILE"; extern const char AWS_CONFIG_FILE[] = "AWS_CONFIG_FILE"; extern const char PROFILE_DIRECTORY[] = ".aws"; -static const char DEFAULT_CREDENTIALS_FILE[] = "credentials"; extern const char DEFAULT_CONFIG_FILE[] = "config"; @@ -144,97 +142,6 @@ Aws::String Aws::Auth::GetConfigProfileName() static const char* PROFILE_LOG_TAG = "ProfileConfigFileAWSCredentialsProvider"; -Aws::String ProfileConfigFileAWSCredentialsProvider::GetCredentialsProfileFilename() -{ - auto credentialsFileNameFromVar = Aws::Environment::GetEnv(AWS_CREDENTIALS_FILE); - - if (credentialsFileNameFromVar.empty()) - { - return Aws::FileSystem::GetHomeDirectory() + PROFILE_DIRECTORY + PATH_DELIM + DEFAULT_CREDENTIALS_FILE; - } - else - { - return credentialsFileNameFromVar; - } -} - -Aws::String ProfileConfigFileAWSCredentialsProvider::GetProfileDirectory() -{ - Aws::String credentialsFileName = GetCredentialsProfileFilename(); - auto lastSeparator = credentialsFileName.find_last_of(PATH_DELIM); - if (lastSeparator != std::string::npos) - { - return credentialsFileName.substr(0, lastSeparator); - } - else - { - return {}; - } -} - -ProfileConfigFileAWSCredentialsProvider::ProfileConfigFileAWSCredentialsProvider(long refreshRateMs) : - m_profileToUse(Aws::Auth::GetConfigProfileName()), - m_credentialsFileLoader(GetCredentialsProfileFilename()), - m_loadFrequencyMs(refreshRateMs) -{ - AWS_LOGSTREAM_INFO(PROFILE_LOG_TAG, "Setting provider to read credentials from " << GetCredentialsProfileFilename() << " for credentials file" - << " and " << GetConfigProfileFilename() << " for the config file " - << ", for use with profile " << m_profileToUse); -} - -ProfileConfigFileAWSCredentialsProvider::ProfileConfigFileAWSCredentialsProvider(const char* profile, long refreshRateMs) : - m_profileToUse(profile), - m_credentialsFileLoader(GetCredentialsProfileFilename()), - m_loadFrequencyMs(refreshRateMs) -{ - AWS_LOGSTREAM_INFO(PROFILE_LOG_TAG, "Setting provider to read credentials from " << GetCredentialsProfileFilename() << " for credentials file" - << " and " << GetConfigProfileFilename() << " for the config file " - << ", for use with profile " << m_profileToUse); -} - -AWSCredentials ProfileConfigFileAWSCredentialsProvider::GetAWSCredentials() -{ - RefreshIfExpired(); - ReaderLockGuard guard(m_reloadLock); - const Aws::Map& profiles = m_credentialsFileLoader.GetProfiles(); - auto credsFileProfileIter = profiles.find(m_profileToUse); - - if(credsFileProfileIter != profiles.end()) - { - AWSCredentials credentials = credsFileProfileIter->second.GetCredentials(); - if (!credentials.IsEmpty()) { - credentials.AddUserAgentFeature(UserAgentFeature::CREDENTIALS_PROFILE); - } - return credentials; - } - - return AWSCredentials(); -} - - -void ProfileConfigFileAWSCredentialsProvider::Reload() -{ - m_credentialsFileLoader.Load(); - AWSCredentialsProvider::Reload(); -} - -void ProfileConfigFileAWSCredentialsProvider::RefreshIfExpired() -{ - ReaderLockGuard guard(m_reloadLock); - if (!IsTimeToRefresh(m_loadFrequencyMs)) - { - return; - } - - guard.UpgradeToWriterLock(); - if (!IsTimeToRefresh(m_loadFrequencyMs)) // double-checked lock to avoid refreshing twice - { - return; - } - - Reload(); -} - static const char* INSTANCE_LOG_TAG = "InstanceProfileCredentialsProvider"; InstanceProfileCredentialsProvider::InstanceProfileCredentialsProvider(long refreshRateMs) : @@ -334,59 +241,6 @@ void InstanceProfileCredentialsProvider::RefreshIfExpired() Reload(); } -static const char PROCESS_LOG_TAG[] = "ProcessCredentialsProvider"; -ProcessCredentialsProvider::ProcessCredentialsProvider() : - m_profileToUse(Aws::Auth::GetConfigProfileName()) -{ - AWS_LOGSTREAM_INFO(PROCESS_LOG_TAG, "Setting process credentials provider to read config from " << m_profileToUse); -} - -ProcessCredentialsProvider::ProcessCredentialsProvider(const Aws::String& profile) : - m_profileToUse(profile) -{ - AWS_LOGSTREAM_INFO(PROCESS_LOG_TAG, "Setting process credentials provider to read config from " << m_profileToUse); -} - -AWSCredentials ProcessCredentialsProvider::GetAWSCredentials() -{ - RefreshIfExpired(); - ReaderLockGuard guard(m_reloadLock); - return m_credentials; -} - - -void ProcessCredentialsProvider::Reload() -{ - auto profile = Aws::Config::GetCachedConfigProfile(m_profileToUse); - const Aws::String &command = profile.GetCredentialProcess(); - if (command.empty()) - { - AWS_LOGSTREAM_INFO(PROCESS_LOG_TAG, "Failed to find credential process's profile: " << m_profileToUse); - return; - } - m_credentials = GetCredentialsFromProcess(command); - if (!m_credentials.IsEmpty()) { - m_credentials.AddUserAgentFeature(UserAgentFeature::CREDENTIALS_PROFILE_PROCESS); - } -} - -void ProcessCredentialsProvider::RefreshIfExpired() -{ - ReaderLockGuard guard(m_reloadLock); - if (!m_credentials.IsExpiredOrEmpty()) - { - return; - } - - guard.UpgradeToWriterLock(); - if (!m_credentials.IsExpiredOrEmpty()) // double-checked lock to avoid refreshing twice - { - return; - } - - Reload(); -} - AWSCredentials Aws::Auth::GetCredentialsFromProcess(const Aws::String& process) { Aws::String command = process; diff --git a/src/aws-cpp-sdk-core/source/auth/AWSCredentialsProviderChain.cpp b/src/aws-cpp-sdk-core/source/auth/AWSCredentialsProviderChain.cpp index d2ea774faf8b..a721abcdb143 100644 --- a/src/aws-cpp-sdk-core/source/auth/AWSCredentialsProviderChain.cpp +++ b/src/aws-cpp-sdk-core/source/auth/AWSCredentialsProviderChain.cpp @@ -4,6 +4,7 @@ */ #include +#include #include #include #include diff --git a/tests/aws-cpp-sdk-core-tests/aws/auth/AWSCredentialsProviderTest.cpp b/tests/aws-cpp-sdk-core-tests/aws/auth/AWSCredentialsProviderTest.cpp index 5e1e4409b3b5..a780bfd66d5a 100644 --- a/tests/aws-cpp-sdk-core-tests/aws/auth/AWSCredentialsProviderTest.cpp +++ b/tests/aws-cpp-sdk-core-tests/aws/auth/AWSCredentialsProviderTest.cpp @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -33,7 +34,7 @@ using namespace Aws::FileSystem; using namespace Aws::Http; using namespace Aws::Http::Standard; -class ProfileConfigFileAWSCredentialsProviderTest : public Aws::Testing::AwsCppSdkGTestSuite +class ProfileCredentialsProviderFileTest : public Aws::Testing::AwsCppSdkGTestSuite { public: void SetUp() @@ -42,9 +43,9 @@ class ProfileConfigFileAWSCredentialsProviderTest : public Aws::Testing::AwsCppS SaveEnvironmentVariable("AWS_DEFAULT_PROFILE"); SaveEnvironmentVariable("AWS_PROFILE"); - Aws::FileSystem::CreateDirectoryIfNotExists(ProfileConfigFileAWSCredentialsProvider::GetProfileDirectory().c_str()); + Aws::FileSystem::CreateDirectoryIfNotExists(ProfileCredentialsProvider::GetProfileDirectory().c_str()); Aws::StringStream ss; - ss << ProfileConfigFileAWSCredentialsProvider::GetCredentialsProfileFilename() << "_blah" << std::this_thread::get_id(); + ss << ProfileCredentialsProvider::GetCredentialsProfileFilename() << "_blah" << std::this_thread::get_id(); m_credsFileName = ss.str(); Aws::Environment::SetEnv("AWS_SHARED_CREDENTIALS_FILE", m_credsFileName.c_str(), 1); @@ -81,16 +82,8 @@ class ProfileConfigFileAWSCredentialsProviderTest : public Aws::Testing::AwsCppS Aws::String m_credsFileName; }; -TEST_F(ProfileConfigFileAWSCredentialsProviderTest, TestDefaultConfig) +TEST_F(ProfileCredentialsProviderFileTest, TestDefaultConfig) { - struct ReloadableProfileConfigProvider : ProfileConfigFileAWSCredentialsProvider - { - void ReloadNow() - { - Reload(); - } - }; - Aws::OFStream credsFile(m_credsFileName.c_str(), Aws::OFStream::out | Aws::OFStream::trunc); credsFile << std::endl; @@ -105,22 +98,20 @@ TEST_F(ProfileConfigFileAWSCredentialsProviderTest, TestDefaultConfig) credsFile << "aws_session_token=DefaultSessionToken" << std::endl; credsFile << "aws_account_id=111111111111" << std::endl; credsFile << std::endl; - credsFile << " [Somebody Else Again]" << std::endl; + credsFile << "[Somebody Else Again]" << std::endl; credsFile << "aws_secret_access_key = SomebodyElseAgainAccessId" << std::endl; - credsFile << " aws_secret_access_key=SomebodyElseAgainSecretKey" << std::endl; + credsFile << "aws_secret_access_key=SomebodyElseAgainSecretKey" << std::endl; credsFile << "aws_session_token=SomebodyElseAgainSessionToken" << std::endl; credsFile << "aws_account_id=333333333333" << std::endl; credsFile.close(); - ReloadableProfileConfigProvider provider; + ProfileCredentialsProvider provider; EXPECT_STREQ("DefaultAccessKey", provider.GetAWSCredentials().GetAWSAccessKeyId().c_str()); EXPECT_STREQ("DefaultSecretKey", provider.GetAWSCredentials().GetAWSSecretKey().c_str()); EXPECT_STREQ("111111111111", provider.GetAWSCredentials().GetAccountId().c_str()); + // ProfileCredentialsProvider reads the files once, when it is created, so removing the file doesn't clear its credentials. Aws::FileSystem::RemoveFileIfExists(m_credsFileName.c_str()); - provider.ReloadNow(); - EXPECT_STREQ("", provider.GetAWSCredentials().GetAWSAccessKeyId().c_str()); - EXPECT_STREQ("", provider.GetAWSCredentials().GetAWSSecretKey().c_str()); } class EnvironmentModifyingTest : public Aws::Testing::AwsCppSdkGTestSuite @@ -129,9 +120,9 @@ class EnvironmentModifyingTest : public Aws::Testing::AwsCppSdkGTestSuite void SetUp() { - Aws::FileSystem::CreateDirectoryIfNotExists(ProfileConfigFileAWSCredentialsProvider::GetProfileDirectory().c_str()); + Aws::FileSystem::CreateDirectoryIfNotExists(ProfileCredentialsProvider::GetProfileDirectory().c_str()); Aws::StringStream ss; - ss << ProfileConfigFileAWSCredentialsProvider::GetCredentialsProfileFilename() << "_blah" << std::this_thread::get_id(); + ss << ProfileCredentialsProvider::GetCredentialsProfileFilename() << "_blah" << std::this_thread::get_id(); m_credsFileName = ss.str(); Aws::Environment::SetEnv("AWS_SHARED_CREDENTIALS_FILE", m_credsFileName.c_str(), 1); @@ -156,17 +147,17 @@ TEST_F(EnvironmentModifyingTest, TestOrderOfAwsDefaultProfileAndAwsProfile) Aws::OFStream credsFile(m_credsFileName.c_str(), Aws::OFStream::out | Aws::OFStream::trunc); credsFile << "[default_profile]" << std::endl; - credsFile << " aws_access_key_id = DefaultProfileAccessKey " << std::endl; + credsFile << "aws_access_key_id = DefaultProfileAccessKey " << std::endl; credsFile << "aws_secret_access_key= DefaultProfileSecretKey" << std::endl; credsFile << std::endl; credsFile << "[default]" << std::endl; - credsFile << " aws_access_key_id = DefaultAccessKey " << std::endl; + credsFile << "aws_access_key_id = DefaultAccessKey " << std::endl; credsFile << "aws_secret_access_key= DefaultSecretKey" << std::endl; credsFile << std::endl; credsFile << "[profile]" << std::endl; - credsFile << " aws_access_key_id = ProfileAccessKey " << std::endl; + credsFile << "aws_access_key_id = ProfileAccessKey " << std::endl; credsFile << "aws_secret_access_key =ProfileSecretKey" << std::endl; credsFile << std::endl; @@ -180,19 +171,19 @@ TEST_F(EnvironmentModifyingTest, TestOrderOfAwsDefaultProfileAndAwsProfile) Aws::Environment::SetEnv("AWS_DEFAULT_PROFILE", "default_profile", 1/*override*/); Aws::Environment::SetEnv("AWS_PROFILE", "profile", 1/*override*/); - ProfileConfigFileAWSCredentialsProvider providerDefaultProfile(10); + ProfileCredentialsProvider providerDefaultProfile(10); EXPECT_STREQ("DefaultProfileAccessKey", providerDefaultProfile.GetAWSCredentials().GetAWSAccessKeyId().c_str()); EXPECT_STREQ("DefaultProfileSecretKey", providerDefaultProfile.GetAWSCredentials().GetAWSSecretKey().c_str()); Aws::Environment::SetEnv("AWS_DEFAULT_PROFILE", "", 1/*override*/); Aws::Environment::SetEnv("AWS_PROFILE", "profile", 1/*override*/); - ProfileConfigFileAWSCredentialsProvider providerProfile(10); + ProfileCredentialsProvider providerProfile(10); EXPECT_STREQ("ProfileAccessKey", providerProfile.GetAWSCredentials().GetAWSAccessKeyId().c_str()); EXPECT_STREQ("ProfileSecretKey", providerProfile.GetAWSCredentials().GetAWSSecretKey().c_str()); Aws::Environment::SetEnv("AWS_DEFAULT_PROFILE", "", 1/*override*/); Aws::Environment::SetEnv("AWS_PROFILE", "", 1/*override*/); - ProfileConfigFileAWSCredentialsProvider providerDefault(10); + ProfileCredentialsProvider providerDefault(10); EXPECT_STREQ("DefaultAccessKey", providerDefault.GetAWSCredentials().GetAWSAccessKeyId().c_str()); EXPECT_STREQ("DefaultSecretKey", providerDefault.GetAWSCredentials().GetAWSSecretKey().c_str()); @@ -208,13 +199,13 @@ TEST_F(EnvironmentModifyingTest, ProfileConfigTestWithEnvVars) Aws::OFStream credsFile(m_credsFileName.c_str(), Aws::OFStream::out | Aws::OFStream::trunc); credsFile << "[ someProfile]" << std::endl; - credsFile << " aws_access_key_id = SomeProfileAccessKey " << std::endl; + credsFile << "aws_access_key_id = SomeProfileAccessKey " << std::endl; credsFile << "aws_secret_access_key =SomeProfileSecretKey" << std::endl; credsFile << "aws_session_token=SomeProfileSessionToken " << std::endl; credsFile << std::endl; credsFile.close(); - ProfileConfigFileAWSCredentialsProvider provider(10); + ProfileCredentialsProvider provider(10); EXPECT_STREQ("SomeProfileAccessKey", provider.GetAWSCredentials().GetAWSAccessKeyId().c_str()); EXPECT_STREQ("SomeProfileSecretKey", provider.GetAWSCredentials().GetAWSSecretKey().c_str()); @@ -229,19 +220,19 @@ TEST_F(EnvironmentModifyingTest, ProfileConfigTestWithEnvVarsButSpecifiedProfile Aws::Environment::SetEnv("AWS_DEFAULT_PROFILE", "someProfile", 1); Aws::OFStream credsFile(m_credsFileName.c_str(), Aws::OFStream::out | Aws::OFStream::trunc); - credsFile << " [ someProfile]" << std::endl; - credsFile << " aws_access_key_id = SomeProfileAccessKey" << std::endl; + credsFile << "[ someProfile]" << std::endl; + credsFile << "aws_access_key_id = SomeProfileAccessKey" << std::endl; credsFile << "aws_secret_access_key=SomeProfileSecretKey " << std::endl; credsFile << "aws_session_token= SomeProfileSessionToken" << std::endl; credsFile << std::endl; credsFile << "[customProfile]" << std::endl; credsFile << "aws_access_key_id =customProfileAccessKey" << std::endl; credsFile << "aws_secret_access_key=customProfileSecretKey " << std::endl; - credsFile << " aws_session_token=customProfileSessionToken" << std::endl; + credsFile << "aws_session_token=customProfileSessionToken" << std::endl; credsFile << std::endl; credsFile.close(); - ProfileConfigFileAWSCredentialsProvider provider("customProfile", 10); + ProfileCredentialsProvider provider("customProfile", 10); EXPECT_STREQ("customProfileAccessKey", provider.GetAWSCredentials().GetAWSAccessKeyId().c_str()); EXPECT_STREQ("customProfileSecretKey", provider.GetAWSCredentials().GetAWSSecretKey().c_str()); @@ -257,7 +248,7 @@ TEST_F(EnvironmentModifyingTest, ProfileConfigTestNotSetup) //This is to prevent when user actually sets .aws/credentials with Keys, this test would fail. Aws::Environment::SetEnv("AWS_DEFAULT_PROFILE", "SomeUnknownProfileThatDoesNotExist", 1); - ProfileConfigFileAWSCredentialsProvider provider; + ProfileCredentialsProvider provider; EXPECT_STREQ("", provider.GetAWSCredentials().GetAWSAccessKeyId().c_str()); EXPECT_STREQ("", provider.GetAWSCredentials().GetAWSSecretKey().c_str()); } @@ -448,7 +439,7 @@ static Aws::String WrapEchoStringWithSingleQuoteForUnixShell(Aws::String str) return str; } -class ProcessCredentialsProviderTest : public Aws::Testing::AwsCppSdkGTestSuite +class ConfigFileTest : public Aws::Testing::AwsCppSdkGTestSuite { public: void SetUp() @@ -464,7 +455,7 @@ class ProcessCredentialsProviderTest : public Aws::Testing::AwsCppSdkGTestSuite Aws::Environment::UnSetEnv("AWS_DEFAULT_PROFILE"); Aws::Environment::UnSetEnv("AWS_PROFILE"); - auto profileDirectory = ProfileConfigFileAWSCredentialsProvider::GetProfileDirectory(); + auto profileDirectory = ProfileCredentialsProvider::GetProfileDirectory(); Aws::FileSystem::CreateDirectoryIfNotExists(profileDirectory.c_str()); } @@ -497,95 +488,7 @@ class ProcessCredentialsProviderTest : public Aws::Testing::AwsCppSdkGTestSuite Aws::String m_configFileName; }; -TEST_F(ProcessCredentialsProviderTest, TestProcessCredentialsProviderExpiredThenRefreshed) -{ - Aws::OFStream configFile(m_configFileName.c_str(), Aws::OFStream::out | Aws::OFStream::trunc); - configFile << "[default]" << std::endl; - configFile << "credential_process = echo " << WrapEchoStringWithSingleQuoteForUnixShell("{\"Version\": 1, \"AccessKeyId\": \"AccessKey123\", \"SecretAccessKey\": \"SecretKey321\", \"Expiration\": \"1970-01-01T00:00:01Z\"}") << std::endl; - configFile.close(); - - Aws::Config::ReloadCachedConfigFile(); - ProcessCredentialsProvider provider; - Aws::Auth::AWSCredentials credsOne = provider.GetAWSCredentials(); - EXPECT_TRUE(credsOne.IsExpired()); - - Aws::OFStream configFileNew(m_configFileName.c_str(), Aws::OFStream::out | Aws::OFStream::trunc); - configFileNew << "[default]" << std::endl; - configFileNew << "credential_process = echo " << WrapEchoStringWithSingleQuoteForUnixShell("{\"Version\": 1, \"AccessKeyId\": \"AccessKey321\", \"SecretAccessKey\": \"SecretKey123\", \"AccountId\": \"123456789012\"}") << std::endl; - configFileNew.close(); - - Aws::Config::ReloadCachedConfigFile(); - Aws::Auth::AWSCredentials credsTwo = provider.GetAWSCredentials(); - EXPECT_NE(credsOne, credsTwo); - EXPECT_FALSE(credsTwo.IsEmpty()); - EXPECT_STREQ("AccessKey321", credsTwo.GetAWSAccessKeyId().c_str()); - EXPECT_STREQ("SecretKey123", credsTwo.GetAWSSecretKey().c_str()); - EXPECT_STREQ("123456789012", credsTwo.GetAccountId().c_str()); - - Aws::FileSystem::RemoveFileIfExists(m_configFileName.c_str()); -} - -TEST_F(ProcessCredentialsProviderTest, TestProcessCredentialsProviderNonSupportedVersion) -{ - Aws::OFStream configFileNew(m_configFileName.c_str(), Aws::OFStream::out | Aws::OFStream::trunc); - configFileNew << "[default]" << std::endl; - configFileNew << "credential_process = echo " << WrapEchoStringWithSingleQuoteForUnixShell("{\"Version\": 2, \"AccessKeyId\": \"AccessKey321\", \"SecretAccessKey\": \"SecretKey123\"}") << std::endl; - configFileNew.close(); - Aws::Config::ReloadCachedConfigFile(); - - ProcessCredentialsProvider provider; - EXPECT_TRUE(provider.GetAWSCredentials().IsEmpty()); - - Aws::FileSystem::RemoveFileIfExists(m_configFileName.c_str()); -} - -TEST_F(ProcessCredentialsProviderTest, TestProcessCredentialsProviderDoNotRefresh) -{ - Aws::OFStream configFile(m_configFileName.c_str(), Aws::OFStream::out | Aws::OFStream::trunc); - - configFile << "[default]" << std::endl; - configFile << "credential_process = echo " << WrapEchoStringWithSingleQuoteForUnixShell("{\"Version\": 1, \"AccessKeyId\": \"AccessKey456\", \"SecretAccessKey\": \"SecretKey654\"}") << std::endl; - configFile.close(); - Aws::Config::ReloadCachedConfigFile(); - - ProcessCredentialsProvider provider; - Aws::Auth::AWSCredentials credsOne = provider.GetAWSCredentials(); - EXPECT_STREQ("AccessKey456", credsOne.GetAWSAccessKeyId().c_str()); - EXPECT_STREQ("SecretKey654", credsOne.GetAWSSecretKey().c_str()); - - Aws::OFStream configFileNew(m_configFileName.c_str(), Aws::OFStream::out | Aws::OFStream::trunc); - - configFileNew << "[default]" << std::endl; - configFileNew << "credential_process = echo " << WrapEchoStringWithSingleQuoteForUnixShell("{\"Version\": 1, \"AccessKeyId\": \"AccessKey789\", \"SecretAccessKey\": \"SecretKey987\"}") << std::endl; - configFileNew.close(); - Aws::Config::ReloadCachedConfigFile(); - - Aws::Auth::AWSCredentials credsTwo = provider.GetAWSCredentials(); - EXPECT_EQ(credsOne, credsTwo); - EXPECT_FALSE(credsTwo.IsEmpty()); - EXPECT_STREQ("AccessKey456", credsTwo.GetAWSAccessKeyId().c_str()); - EXPECT_STREQ("SecretKey654", credsTwo.GetAWSSecretKey().c_str()); - - Aws::FileSystem::RemoveFileIfExists(m_configFileName.c_str()); -} - -TEST_F(ProcessCredentialsProviderTest, TestProcessCredentialsProviderCaptureInvalidOutput) -{ - Aws::OFStream configFile(m_configFileName.c_str(), Aws::OFStream::out | Aws::OFStream::trunc); - - configFile << "[default]" << std::endl; - configFile << "credential_process = echo 'Error: Failed to retrieve credentials'" << std::endl; - configFile << std::endl; - configFile.close(); - Aws::Config::ReloadCachedConfigFile(); - - ProcessCredentialsProvider provider; - EXPECT_TRUE(provider.GetAWSCredentials().IsEmpty()); - - Aws::FileSystem::RemoveFileIfExists(m_configFileName.c_str()); -} - -class SSOCredentialsProviderTest :public ProcessCredentialsProviderTest +class SSOCredentialsProviderTest :public ConfigFileTest { public: void SetUp() @@ -604,7 +507,7 @@ class SSOCredentialsProviderTest :public ProcessCredentialsProviderTest // avoid reading region environment var when testing get correct region from config file Aws::Environment::UnSetEnv("AWS_DEFAULT_REGION"); - auto profileDirectory = ProfileConfigFileAWSCredentialsProvider::GetProfileDirectory(); + auto profileDirectory = ProfileCredentialsProvider::GetProfileDirectory(); Aws::FileSystem::CreateDirectoryIfNotExists(profileDirectory.c_str()); Aws::StringStream ssCachedTokenDirectory; ssCachedTokenDirectory << profileDirectory << PATH_DELIM << "sso"; @@ -1322,7 +1225,7 @@ TEST_F(EnvironmentModifyingTest, TestChainWithProcessCredentials) DefaultAWSCredentialsProviderChain chain; auto creds = chain.GetAWSCredentials(); - // Should get credentials from ProcessCredentialsProvider in the chain + // Should get credentials from ProfileCredentialsProvider in the chain EXPECT_STREQ("ProcessAccessKey", creds.GetAWSAccessKeyId().c_str()); EXPECT_STREQ("ProcessSecretKey", creds.GetAWSSecretKey().c_str()); @@ -1481,7 +1384,7 @@ TEST_F(EnvironmentModifyingTest, TestChainOrderWithMultipleValidProviders) credsFile << "aws_secret_access_key = ProfileSecretKey" << std::endl; credsFile.close(); - // Create config with credential_process (third in chain via ProcessCredentialsProvider) + // Create config with credential_process (via ProfileCredentialsProvider in the chain) Aws::StringStream ss; ss << Aws::Auth::GetConfigProfileFilename() + "_blah" << std::this_thread::get_id(); auto configFileName = ss.str(); diff --git a/tests/aws-cpp-sdk-core-tests/aws/auth/CredentialTrackingTest.cpp b/tests/aws-cpp-sdk-core-tests/aws/auth/CredentialTrackingTest.cpp index 5bf0e1445cdf..4c288f348fb7 100644 --- a/tests/aws-cpp-sdk-core-tests/aws/auth/CredentialTrackingTest.cpp +++ b/tests/aws-cpp-sdk-core-tests/aws/auth/CredentialTrackingTest.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -178,7 +179,7 @@ TEST_F(CredentialTrackingTest, TestProfileCredentialsTracking) }}; Aws::Config::ReloadCachedCredentialsFile(); - auto credsProvider = Aws::MakeShared(TEST_LOG_TAG); + auto credsProvider = Aws::MakeShared(TEST_LOG_TAG); RunTestWithCredentialsProvider(std::move(credsProvider), "n"); } @@ -191,16 +192,24 @@ TEST_F(CredentialTrackingTest, TestProfileProcessCredentialsTracking) configFile << "credential_process = echo " << WrapEchoStringWithSingleQuoteForUnixShell("{\"Version\": 1, \"AccessKeyId\": \"test-process-key\", \"SecretAccessKey\": \"test-process-secret\"}") << std::endl; configFile.close(); + // ProfileCredentialsProvider also reads the credentials file, so point it at an empty one to keep a local [default] from taking over. + Aws::Utils::TempFile credentialsFile(std::ios_base::out | std::ios_base::trunc); + ASSERT_TRUE(credentialsFile.good()); + credentialsFile.close(); + // Set environment to use our test config file Aws::Environment::EnvironmentRAII testEnvironment{{ {"AWS_CONFIG_FILE", configFile.GetFileName().c_str()}, + {"AWS_SHARED_CREDENTIALS_FILE", credentialsFile.GetFileName().c_str()}, }}; // Force reload config file after setting environment variable Aws::Config::ReloadCachedConfigFile(); - auto credsProvider = Aws::MakeShared(TEST_LOG_TAG); - RunTestWithCredentialsProvider(std::move(credsProvider), "v"); + auto credsProvider = Aws::MakeShared(TEST_LOG_TAG); + ASSERT_STREQ("test-process-key", credsProvider->GetAWSCredentials().GetAWSAccessKeyId().c_str()); + // TODO: ProfileCredentialsProvider reports CREDENTIALS_PROFILE ("n") even when credentials come from credential_process; restore "v" once it reports the source. + RunTestWithCredentialsProvider(std::move(credsProvider), "n"); } TEST_F(CredentialTrackingTest, TestInstanceProfileCredentialsTracking) diff --git a/tests/aws-cpp-sdk-dynamodb-unit-tests/DynamoDBUnitTests.cpp b/tests/aws-cpp-sdk-dynamodb-unit-tests/DynamoDBUnitTests.cpp index e2f376302b2e..3ef3e097653a 100644 --- a/tests/aws-cpp-sdk-dynamodb-unit-tests/DynamoDBUnitTests.cpp +++ b/tests/aws-cpp-sdk-dynamodb-unit-tests/DynamoDBUnitTests.cpp @@ -479,7 +479,7 @@ TEST_F(DynamoDBUnitTest, ShouldUseAccountIDEndpointFromCredentialsFile) DynamoDBClientConfiguration configuration; configuration.region = "us-east-1"; - auto credsProvider = Aws::MakeShared(LOG_TAG); + auto credsProvider = Aws::MakeShared(LOG_TAG); const auto accountIdClient = Aws::MakeShared(LOG_TAG, std::move(credsProvider), nullptr, configuration); @@ -545,7 +545,7 @@ TEST_F(DynamoDBUnitTest, ShouldUseAccountIDEndpointFromEnviornmentCredentialsPro EXPECT_TRUE(std::find(features.begin(), features.end(), "T") != features.end()); } -TEST_F(DynamoDBUnitTest, ShouldUseAccountIDEndpointFromProcessCredentialsProvider) +TEST_F(DynamoDBUnitTest, ShouldUseAccountIDEndpointFromCredentialProcess) { // create configruation file with process credentials provider with account id Utils::TempFile configFile(std::ios_base::out | std::ios_base::trunc); @@ -553,13 +553,18 @@ TEST_F(DynamoDBUnitTest, ShouldUseAccountIDEndpointFromProcessCredentialsProvide configFile << "[default]" << std::endl; configFile << "credential_process = echo " << WrapEchoStringWithSingleQuoteForUnixShell("{\"Version\": 1, \"AccessKeyId\": \"honky\", \"SecretAccessKey\": \"tonk\", \"SecretAccessKey\": \"woman\", \"AccountId\": \"faye\"}") << std::endl; configFile.close(); - Environment::EnvironmentRAII envVars{{{CONFIGURATION_FILE_ENV_VAR, configFile.GetFileName().c_str()}}}; + // ProfileCredentialsProvider also reads the credentials file, so point it at an empty one to keep a local [default] from taking over. + Utils::TempFile credsFile(std::ios_base::out | std::ios_base::trunc); + ASSERT_TRUE(credsFile.good()); + credsFile.close(); + Environment::EnvironmentRAII envVars{{{CONFIGURATION_FILE_ENV_VAR, configFile.GetFileName().c_str()}, + {CREDS_FILE_ENV_VAR, credsFile.GetFileName().c_str()}}}; Aws::Config::ReloadCachedConfigFile(); DynamoDBClientConfiguration configuration; configuration.region = "us-east-1"; - auto credsProvider = Aws::MakeShared(LOG_TAG); + auto credsProvider = Aws::MakeShared(LOG_TAG); const auto accountIdClient = Aws::MakeShared(LOG_TAG, std::move(credsProvider), nullptr, configuration);