From d923a2d24168ed8ea36465503884d078cee4c6c3 Mon Sep 17 00:00:00 2001 From: Soumava Bera Date: Wed, 15 Jan 2025 11:44:54 -0500 Subject: [PATCH 1/8] add tests --- src/aws-cpp-sdk-core/source/utils/DNS.cpp | 7 ++++++- tests/aws-cpp-sdk-core-tests/utils/DNSTest.cpp | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/aws-cpp-sdk-core/source/utils/DNS.cpp b/src/aws-cpp-sdk-core/source/utils/DNS.cpp index ce588150e2f..8e926d5eb04 100644 --- a/src/aws-cpp-sdk-core/source/utils/DNS.cpp +++ b/src/aws-cpp-sdk-core/source/utils/DNS.cpp @@ -46,7 +46,12 @@ namespace Aws auto labels = StringUtils::Split(host, '.'); if (labels.empty()) { - return false; + //check for ipv6 + labels = StringUtils::Split(host, ':'); + if(labels.empty()) + { + return false; + } } return !std::any_of(labels.begin(), labels.end(), [](const Aws::String& label){ return !IsValidDnsLabel(label); }); diff --git a/tests/aws-cpp-sdk-core-tests/utils/DNSTest.cpp b/tests/aws-cpp-sdk-core-tests/utils/DNSTest.cpp index f35429211c0..0aa287cdd02 100644 --- a/tests/aws-cpp-sdk-core-tests/utils/DNSTest.cpp +++ b/tests/aws-cpp-sdk-core-tests/utils/DNSTest.cpp @@ -61,3 +61,17 @@ TEST_F(DnsTest, TestHost) ASSERT_FALSE(IsValidHost("0123456789012345678901234567890123456789012345678901234567890123.com")); // 64 characters } + +TEST_F(DnsTest, TestIPV6) +{ + Aws::Vector inputs{ + "2001:0db8:85a3:0000:0000:8a2e:0370:7334", + "2001:DB8:85A3::8A2E:370:7334", + "::ffff", + "::", + "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", + "2001:db8:85a3:0:0:8a2e:370:7334" + } + bool IsValidHost(const Aws::String& host) + +} \ No newline at end of file From f05c5f557fbfb2991914f9bf706441713559052d Mon Sep 17 00:00:00 2001 From: Soumava Bera Date: Wed, 15 Jan 2025 15:27:47 -0500 Subject: [PATCH 2/8] changes --- src/aws-cpp-sdk-core/source/utils/DNS.cpp | 63 +++++++++++++++++-- tests/aws-cpp-sdk-core-tests/CMakeLists.txt | 10 +-- .../aws-cpp-sdk-core-tests/utils/DNSTest.cpp | 21 ++++--- 3 files changed, 75 insertions(+), 19 deletions(-) diff --git a/src/aws-cpp-sdk-core/source/utils/DNS.cpp b/src/aws-cpp-sdk-core/source/utils/DNS.cpp index 8e926d5eb04..484c665da06 100644 --- a/src/aws-cpp-sdk-core/source/utils/DNS.cpp +++ b/src/aws-cpp-sdk-core/source/utils/DNS.cpp @@ -5,7 +5,7 @@ #include #include - +#include namespace Aws { namespace Utils @@ -40,18 +40,69 @@ namespace Aws return true; } + + bool isValidIpv6Host(const Aws::String& host) + { + std::cout<<"isValidIpv6Host:"< - ARGS "--gtest_shuffle" "--gtest_repeat=3" "--gtest_brief=1") -endif() +#if (AUTORUN_UNIT_TESTS) +# ADD_CUSTOM_COMMAND( TARGET ${PROJECT_NAME} POST_BUILD +# COMMAND ${CMAKE_COMMAND} -E env LD_LIBRARY_PATH=${AWS_AUTORUN_LD_LIBRARY_PATH}:$ENV{LD_LIBRARY_PATH} $ +# ARGS "--gtest_shuffle" "--gtest_repeat=3" "--gtest_brief=1") +#endif() if(NOT CMAKE_CROSSCOMPILING) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME}) diff --git a/tests/aws-cpp-sdk-core-tests/utils/DNSTest.cpp b/tests/aws-cpp-sdk-core-tests/utils/DNSTest.cpp index 0aa287cdd02..bfda96c38d7 100644 --- a/tests/aws-cpp-sdk-core-tests/utils/DNSTest.cpp +++ b/tests/aws-cpp-sdk-core-tests/utils/DNSTest.cpp @@ -64,14 +64,19 @@ TEST_F(DnsTest, TestHost) TEST_F(DnsTest, TestIPV6) { - Aws::Vector inputs{ - "2001:0db8:85a3:0000:0000:8a2e:0370:7334", - "2001:DB8:85A3::8A2E:370:7334", - "::ffff", - "::", - "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", - "2001:db8:85a3:0:0:8a2e:370:7334" + Aws::Vector< std::pair > inputs = { + {"2001:0db8:85a3:0000:0000:8a2e:0370:7334", true}, + {"2001:DB8:85A3::8A2E:370:7334", true}, + {"::ffff", true}, + {"::", true}, + {"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",true}, + {"2001:db8:85a3:0:0:8a2e:370:7334",true} + }; + + for(auto t : inputs) + { + std::cout<<"test for "< Date: Wed, 15 Jan 2025 16:19:30 -0500 Subject: [PATCH 3/8] changes to support ipv6 in domain --- src/aws-cpp-sdk-core/source/utils/DNS.cpp | 40 +++++++++++-------- tests/aws-cpp-sdk-core-tests/CMakeLists.txt | 10 ++--- .../aws-cpp-sdk-core-tests/utils/DNSTest.cpp | 11 ++++- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/src/aws-cpp-sdk-core/source/utils/DNS.cpp b/src/aws-cpp-sdk-core/source/utils/DNS.cpp index 484c665da06..1238b93ca8b 100644 --- a/src/aws-cpp-sdk-core/source/utils/DNS.cpp +++ b/src/aws-cpp-sdk-core/source/utils/DNS.cpp @@ -41,15 +41,27 @@ namespace Aws } + bool isHexChar(char c) { + return (c >= '0' && c <= '9') || + (c >= 'a' && c <= 'f') || + (c >= 'A' && c <= 'F'); + } + + bool isValidIPv6Segment(const std::string& segment) { + if (segment.empty() || segment.length() > 4){ + return false; + } + return std::all_of(segment.begin(), segment.end(), isHexChar); + } + + //The assumption is this is only called with the domain part of uri bool isValidIpv6Host(const Aws::String& host) { - std::cout<<"isValidIpv6Host:"< -# ARGS "--gtest_shuffle" "--gtest_repeat=3" "--gtest_brief=1") -#endif() +if (AUTORUN_UNIT_TESTS) + ADD_CUSTOM_COMMAND( TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E env LD_LIBRARY_PATH=${AWS_AUTORUN_LD_LIBRARY_PATH}:$ENV{LD_LIBRARY_PATH} $ + ARGS "--gtest_shuffle" "--gtest_repeat=3" "--gtest_brief=1") +endif() if(NOT CMAKE_CROSSCOMPILING) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME}) diff --git a/tests/aws-cpp-sdk-core-tests/utils/DNSTest.cpp b/tests/aws-cpp-sdk-core-tests/utils/DNSTest.cpp index bfda96c38d7..5a3d0ef9e16 100644 --- a/tests/aws-cpp-sdk-core-tests/utils/DNSTest.cpp +++ b/tests/aws-cpp-sdk-core-tests/utils/DNSTest.cpp @@ -70,12 +70,19 @@ TEST_F(DnsTest, TestIPV6) {"::ffff", true}, {"::", true}, {"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",true}, - {"2001:db8:85a3:0:0:8a2e:370:7334",true} + {"2001:db8:85a3:0:0:8a2e:370:7334",true}, + {"2001:db8:85a3:0000:0000:8a2e:0370:7334:1", false}, + {"2001:db8:85a3:0000", false}, + {"2001:0db8:85a3:0000:0000:8a2e:0370:7334:", false}, + {"g001:0db8:85a3:0000:0000:8a2e:0370:7334", false}, + {"2001:db8::85a3::1", false}, + {":2001:db8:85a3:0000:0000:8a2e:0370:7334", false}, + {"0:0:0:0:0:0:0:0", true}, + {"2001:db8::", true} }; for(auto t : inputs) { - std::cout<<"test for "< Date: Wed, 15 Jan 2025 16:20:48 -0500 Subject: [PATCH 4/8] remove unused header --- src/aws-cpp-sdk-core/source/utils/DNS.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/aws-cpp-sdk-core/source/utils/DNS.cpp b/src/aws-cpp-sdk-core/source/utils/DNS.cpp index 1238b93ca8b..5a6da044173 100644 --- a/src/aws-cpp-sdk-core/source/utils/DNS.cpp +++ b/src/aws-cpp-sdk-core/source/utils/DNS.cpp @@ -5,7 +5,6 @@ #include #include -#include namespace Aws { namespace Utils From 51ce91b46c3941fece2724cd428b7445c9cd607f Mon Sep 17 00:00:00 2001 From: Soumava Bera Date: Wed, 15 Jan 2025 16:21:32 -0500 Subject: [PATCH 5/8] consistent style --- src/aws-cpp-sdk-core/source/utils/DNS.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/aws-cpp-sdk-core/source/utils/DNS.cpp b/src/aws-cpp-sdk-core/source/utils/DNS.cpp index 5a6da044173..fd00b583333 100644 --- a/src/aws-cpp-sdk-core/source/utils/DNS.cpp +++ b/src/aws-cpp-sdk-core/source/utils/DNS.cpp @@ -97,7 +97,9 @@ namespace Aws // Handle last segment if(labelStart < host.length()) { - if(!isValidIPv6Segment(host.substr(labelStart))) return false; + if(!isValidIPv6Segment(host.substr(labelStart))){ + return false; + } } // Check if we have 8 segments or less with one double colon return (doubleColonFound && segmentCount < 8) || (!doubleColonFound && segmentCount == 8); From 05074c2a60298e686ea73695d73e00b84a0d7d84 Mon Sep 17 00:00:00 2001 From: Soumava Bera Date: Wed, 15 Jan 2025 16:26:03 -0500 Subject: [PATCH 6/8] replace with helper --- src/aws-cpp-sdk-core/source/utils/DNS.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/aws-cpp-sdk-core/source/utils/DNS.cpp b/src/aws-cpp-sdk-core/source/utils/DNS.cpp index fd00b583333..35b43a54aae 100644 --- a/src/aws-cpp-sdk-core/source/utils/DNS.cpp +++ b/src/aws-cpp-sdk-core/source/utils/DNS.cpp @@ -5,6 +5,7 @@ #include #include +#include namespace Aws { namespace Utils @@ -39,18 +40,11 @@ namespace Aws return true; } - - bool isHexChar(char c) { - return (c >= '0' && c <= '9') || - (c >= 'a' && c <= 'f') || - (c >= 'A' && c <= 'F'); - } - bool isValidIPv6Segment(const std::string& segment) { if (segment.empty() || segment.length() > 4){ return false; } - return std::all_of(segment.begin(), segment.end(), isHexChar); + return std::all_of(segment.begin(), segment.end(), isxdigit); } //The assumption is this is only called with the domain part of uri From 6444ccce73f63e1711b7b3842be7d7f2644b69ce Mon Sep 17 00:00:00 2001 From: Soumava Bera Date: Thu, 16 Jan 2025 11:17:00 -0500 Subject: [PATCH 7/8] fix corner case --- src/aws-cpp-sdk-core/source/utils/DNS.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/aws-cpp-sdk-core/source/utils/DNS.cpp b/src/aws-cpp-sdk-core/source/utils/DNS.cpp index 35b43a54aae..c2579884de6 100644 --- a/src/aws-cpp-sdk-core/source/utils/DNS.cpp +++ b/src/aws-cpp-sdk-core/source/utils/DNS.cpp @@ -6,6 +6,7 @@ #include #include #include + namespace Aws { namespace Utils @@ -44,7 +45,8 @@ namespace Aws if (segment.empty() || segment.length() > 4){ return false; } - return std::all_of(segment.begin(), segment.end(), isxdigit); + return std::all_of(segment.begin(), segment.end(), [](unsigned char ch) { + return std::isxdigit(ch);}); } //The assumption is this is only called with the domain part of uri From d921d3865e5c0f368bf6f7d76a86bf236ea8a4d6 Mon Sep 17 00:00:00 2001 From: Soumava Bera Date: Tue, 28 Jan 2025 11:29:00 -0500 Subject: [PATCH 8/8] pick crt update --- src/aws-cpp-sdk-core/source/utils/DNS.cpp | 63 +---------------------- 1 file changed, 2 insertions(+), 61 deletions(-) diff --git a/src/aws-cpp-sdk-core/source/utils/DNS.cpp b/src/aws-cpp-sdk-core/source/utils/DNS.cpp index c2579884de6..e96f2db8c99 100644 --- a/src/aws-cpp-sdk-core/source/utils/DNS.cpp +++ b/src/aws-cpp-sdk-core/source/utils/DNS.cpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace Aws { @@ -41,66 +42,6 @@ namespace Aws return true; } - bool isValidIPv6Segment(const std::string& segment) { - if (segment.empty() || segment.length() > 4){ - return false; - } - return std::all_of(segment.begin(), segment.end(), [](unsigned char ch) { - return std::isxdigit(ch);}); - } - - //The assumption is this is only called with the domain part of uri - bool isValidIpv6Host(const Aws::String& host) - { - if(host.empty()) - { - return false; - } - size_t segmentCount = 1; - bool doubleColonFound = false; - size_t labelStart = 0; - - for(size_t i = 0; i < host.length(); ++i) - { - if(host[i] == ':') - { - // double colon check - if(i + 1 < host.length() && host[i+1] == ':') - { - if(doubleColonFound) { - return false; - } - doubleColonFound = true; - ++i; - } - // single colon segment - else - { - if(!isValidIPv6Segment(host.substr(labelStart, i - labelStart))) { - return false; - } - ++segmentCount; - } - labelStart = i + 1; - } - // no dots in ipv6 - else if(host[i] == '.') - { - return false; - } - } - - // Handle last segment - if(labelStart < host.length()) - { - if(!isValidIPv6Segment(host.substr(labelStart))){ - return false; - } - } - // Check if we have 8 segments or less with one double colon - return (doubleColonFound && segmentCount < 8) || (!doubleColonFound && segmentCount == 8); - } - bool IsValidHost(const Aws::String& host) { // Valid DNS hostnames are composed of valid DNS labels separated by a period. @@ -110,7 +51,7 @@ namespace Aws return false; } - return !std::any_of(labels.begin(), labels.end(), [](const Aws::String& label){ return !IsValidDnsLabel(label); }) || isValidIpv6Host(host); + return !std::any_of(labels.begin(), labels.end(), [](const Aws::String& label){ return !IsValidDnsLabel(label); }) || aws_host_utils_is_ipv6(aws_byte_cursor_from_c_str(host.c_str()), false); } } }