Skip to content

Commit 27a13b2

Browse files
Merge pull request #51 from awslabs/NoDepUUID
Removed UUID dependencies and just implemented it manually.
2 parents 8e5fd89 + 3f6771e commit 27a13b2

File tree

11 files changed

+57
-146
lines changed

11 files changed

+57
-146
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ cmake_policy(SET CMP0056 NEW)
8989

9090
project("aws-cpp-sdk-all" VERSION "${PROJECT_VERSION}" LANGUAGES CXX)
9191

92-
# http client, encryption, zlib, uuid
92+
# http client, encryption, zlib
9393
include(external_dependencies)
9494

9595
if(COMMAND apply_post_project_platform_settings)

aws-cpp-sdk-core-tests/aws/auth/AWSCredentialsProviderTest.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ TEST(ProfileConfigFileAWSCredentialsProviderTest, TestDefaultConfig)
4646

4747
Aws::String configFileName = ProfileConfigFileAWSCredentialsProvider::GetCredentialsProfileFilename();
4848
Aws::String tempFileName = configFileName + "_tempMv";
49-
std::cout << tempFileName << std::endl;
5049
Aws::FileSystem::RelocateFileOrDirectory(configFileName.c_str(), tempFileName.c_str());
5150

5251
Aws::OFStream configFile(configFileName.c_str(), Aws::OFStream::out | Aws::OFStream::trunc);

aws-cpp-sdk-core-tests/utils/UUIDTest.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ TEST(UUIDTest, TestPlatformGeneratesUUID)
2626
for(size_t i = 0u; i < 1000u; ++i)
2727
{
2828
UUID uuid = UUID::RandomUUID();
29-
Aws::String uuidStr = uuid;
29+
Aws::String uuidStr = uuid;
3030
ASSERT_EQ(36u, uuidStr.length());
3131
ByteBuffer rawUUID = uuid;
3232
ASSERT_EQ(16u, rawUUID.GetLength());
33+
ASSERT_EQ(0x40u, 0x40u & rawUUID[6]);
34+
ASSERT_EQ(0x80u, 0x80u & rawUUID[8]);
3335

3436
ASSERT_EQ(generatedUUids.end(), generatedUUids.find(uuidStr));
3537
generatedUUids.insert(uuidStr);
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
/*
2-
* Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License").
5-
* You may not use this file except in compliance with the License.
6-
* A copy of the License is located at
7-
*
8-
* http://aws.amazon.com/apache2.0
9-
*
10-
* or in the "license" file accompanying this file. This file is distributed
11-
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12-
* express or implied. See the License for the specific language governing
13-
* permissions and limitations under the License.
14-
*/
15-
16-
#define AWS_SDK_VERSION_STRING "1.0.35"
1+
/*
2+
* Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
#define AWS_SDK_VERSION_STRING "1.0.35"

aws-cpp-sdk-core/nuget/aws-cpp-sdk-core.autopkg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ nuget {
152152
Libraries += wininet.lib;
153153
Libraries += bcrypt.lib;
154154
Libraries += userenv.lib;
155-
Libraries += Rpcrt4.lib;
156155
Libraries += Version.lib;
157156
}
158157
}

aws-cpp-sdk-core/source/platform/android/UUID_Impl.cpp

Lines changed: 0 additions & 38 deletions
This file was deleted.

aws-cpp-sdk-core/source/platform/linux-shared/UUID_Impl.cpp

Lines changed: 0 additions & 30 deletions
This file was deleted.

aws-cpp-sdk-core/source/platform/windows/UUID_Impl.cpp

Lines changed: 0 additions & 36 deletions
This file was deleted.

aws-cpp-sdk-core/source/utils/UUID.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,21 @@
1616
#include <aws/core/utils/UUID.h>
1717
#include <aws/core/utils/HashingUtils.h>
1818
#include <aws/core/utils/StringUtils.h>
19+
#include <aws/core/utils/crypto/Factories.h>
20+
#include <aws/core/utils/crypto/SecureRandom.h>
1921
#include <iomanip>
2022

2123
namespace Aws
2224
{
2325
namespace Utils
2426
{
27+
static const size_t VERSION_LOCATION = 0x06u;
28+
static const size_t VARIANT_LOCATION = 0x08u;
29+
static const unsigned char VERSION = 0x40u;
30+
static const unsigned char VERSION_MASK = 0x0Fu;
31+
static const unsigned char VARIANT = 0x80u;
32+
static const unsigned char VARIANT_MASK = 0x3Fu;
33+
2534
void WriteRangeOutToStream(Aws::StringStream& ss, unsigned char* toWrite, size_t min, size_t max)
2635
{
2736
for (size_t i = min; i < max; ++i)
@@ -66,6 +75,24 @@ namespace Aws
6675
WriteRangeOutToStream(ss, m_uuid, 10, 16);
6776

6877
return ss.str();
69-
}
78+
}
79+
80+
UUID UUID::RandomUUID()
81+
{
82+
auto secureRandom = Crypto::CreateSecureRandomBytesImplementation();
83+
assert(secureRandom);
84+
85+
unsigned char randomBytes[UUID_BINARY_SIZE];
86+
memset(randomBytes, 0, UUID_BINARY_SIZE);
87+
secureRandom->GetBytes(randomBytes, UUID_BINARY_SIZE);
88+
//Set version bits to 0100
89+
//https://tools.ietf.org/html/rfc4122#section-4.1.3
90+
randomBytes[VERSION_LOCATION] = (randomBytes[VERSION_LOCATION] & VERSION_MASK) | VERSION;
91+
//set variant bits to 10
92+
//https://tools.ietf.org/html/rfc4122#section-4.1.1
93+
randomBytes[VARIANT_LOCATION] = (randomBytes[VARIANT_LOCATION] & VARIANT_MASK) | VARIANT;
94+
95+
return UUID(randomBytes);
96+
}
7097
}
7198
}

aws-cpp-sdk-core/source/utils/crypto/factory/Factories.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <aws/core/utils/crypto/Factories.h>
1818
#include <aws/core/utils/crypto/Hash.h>
1919
#include <aws/core/utils/crypto/HMAC.h>
20+
#include <atomic>
2021

2122
#if ENABLE_BCRYPT_ENCRYPTION
2223
#include <aws/core/utils/crypto/bcrypt/CryptoImpl.h>
@@ -49,6 +50,7 @@ static std::shared_ptr<SymmetricCipherFactory> s_AES_GCMFactory(nullptr);
4950
static std::shared_ptr<SymmetricCipherFactory> s_AES_KeyWrapFactory(nullptr);
5051

5152
static std::shared_ptr<SecureRandomFactory> s_SecureRandomFactory(nullptr);
53+
static std::shared_ptr<SecureRandomBytes> s_SecureRandom(nullptr);
5254

5355
static bool s_InitCleanupOpenSSLFlag(false);
5456

@@ -691,6 +693,7 @@ void Aws::Utils::Crypto::CleanupCrypto()
691693

692694
if(s_SecureRandomFactory)
693695
{
696+
s_SecureRandom = nullptr;
694697
s_SecureRandomFactory->CleanupStaticState();
695698
s_SecureRandomFactory = nullptr;
696699
}
@@ -842,5 +845,10 @@ std::shared_ptr<SymmetricCipher> Aws::Utils::Crypto::CreateAES_KeyWrapImplementa
842845

843846
std::shared_ptr<SecureRandomBytes> Aws::Utils::Crypto::CreateSecureRandomBytesImplementation()
844847
{
845-
return s_SecureRandomFactory->CreateImplementation();
848+
if (!std::atomic_load(&s_SecureRandom))
849+
{
850+
std::atomic_store(&s_SecureRandom, s_SecureRandomFactory->CreateImplementation());
851+
}
852+
853+
return s_SecureRandom;
846854
}

cmake/external_dependencies.cmake

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -113,23 +113,3 @@ if(NOT NO_HTTP_CLIENT)
113113
else()
114114
message(STATUS "You will need to inject an http client implementation before making any http requests!")
115115
endif()
116-
117-
# UUID headers
118-
if(NOT PLATFORM_WINDOWS AND NOT PLATFORM_ANDROID AND NOT PLATFORM_CUSTOM)
119-
message(STATUS "Finding uuid")
120-
121-
find_path(UUID_INCLUDE_DIR uuid/uuid.h)
122-
if(NOT PLATFORM_APPLE)
123-
find_library(UUID_LIBRARIES uuid)
124-
endif()
125-
126-
if("${UUID_INCLUDE_DIR}" STREQUAL "UUID_INCLUDE_DIR-NOTFOUND" OR "${UUID_LIBRARIES}" STREQUAL "UUID_LIBRARIES-NOTFOUND")
127-
message(FATAL_ERROR "Could not find uuid components")
128-
else()
129-
message(STATUS " Uuid include directory: ${UUID_INCLUDE_DIR}")
130-
message(STATUS " Uuid library: ${UUID_LIBRARIES}")
131-
endif()
132-
133-
include_directories(${UUID_INCLUDE_DIR})
134-
endif()
135-

0 commit comments

Comments
 (0)