From 60d5ee586945aed7f6f2c4c7b5e62787a78d878a Mon Sep 17 00:00:00 2001 From: Peter Song Date: Fri, 9 Aug 2024 14:25:27 -0700 Subject: [PATCH] refactor: remove third party bouncy castle from core and move cloudfront signers and ec2 decrypt password to extension packages --- buildtools/build.proj | 17 +- .../SDKDocGeneratorLib/SdkDocGenerator.cs | 4 +- extensions/AWSSDK.Extensions.NetFramework.sln | 76 ++ extensions/AWSSDK.Extensions.sln | 42 ++ ...ons.CloudFront.Signers.NetFramework.csproj | 45 ++ ...ions.CloudFront.Signers.NetStandard.csproj | 49 ++ ...WSSDK.Extensions.CloudFront.Signers.nuspec | 38 + .../AmazonCloudFrontCookieSigner.cs | 1 - .../AmazonCloudFrontUrlSigner.cs | 13 +- ...ensions.CrtIntegration.NetFramework.csproj | 2 - .../AWSSDK.Extensions.CrtIntegration.nuspec | 8 +- ...ns.EC2.DecryptPassword.NetFramework.csproj | 42 ++ ...ons.EC2.DecryptPassword.NetStandard.csproj | 45 ++ ...SSDK.Extensions.EC2.DecryptPassword.nuspec | 35 + .../AWSSDK.Extensions.EC2.DecryptPassword.sln | 37 + .../GetPasswordDataResponseExtensions.cs | 19 +- ...oudFront.Signers.Tests.NetFramework.csproj | 34 + ...loudFront.Signers.Tests.NetStandard.csproj | 33 + .../CloudFrontTests.cs | 14 +- .../CookieSignerTest.cs | 67 +- .../sample.rsa.private.key.txt | 0 .../CloudFront.SignersTests}/URLSignerTest.cs | 67 +- .../EC2.DecryptPassword.NetFramework.csproj | 30 + .../EC2.DecryptPassword.NetStandard.csproj | 30 + .../EC2.DecryptPasswordTests}/PasswordTest.cs | 10 +- generator/ServiceModels/_manifest.json | 1 - .../BouncyCastle/Asn1/Asn1Encodable.cs | 30 - .../BouncyCastle/Asn1/Asn1EncodableVector.cs | 104 --- .../BouncyCastle/Asn1/Asn1InputStream.cs | 262 ------- .../BouncyCastle/Asn1/Asn1Object.cs | 70 -- .../BouncyCastle/Asn1/Asn1Sequence.cs | 99 --- .../BouncyCastle/Asn1/DerInteger.cs | 71 -- .../BouncyCastle/Asn1/DerSequence.cs | 79 -- .../Asn1/Utilities/FilterStream.cs | 88 --- .../BouncyCastle/Asn1/Utilities/Platform.cs | 34 - .../BouncyCastle/Math/BigInteger.cs | 695 ------------------ .../BouncyCastle/OpenSsl/PEMReader.cs | 104 --- .../OpenSsl/pem/PemGenerationException.cs | 50 -- .../BouncyCastle/OpenSsl/pem/PemHeader.cs | 76 -- .../BouncyCastle/OpenSsl/pem/PemObject.cs | 68 -- .../OpenSsl/pem/PemObjectGenerator.cs | 34 - .../OpenSsl/pem/PemObjectParser.cs | 38 - .../BouncyCastle/OpenSsl/pem/PemReader.cs | 113 --- .../Custom/Util/Message.cs | 47 +- .../UnitTests/Services/CloudFrontUnitTests.cs | 43 -- ...K.UnitTests.CloudFront.NetFramework.csproj | 3 - ...WSSDK.UnitTests.Custom.NetFramework.csproj | 1 - .../AWSSDK.UnitTests.NetFramework.csproj | 1 - 48 files changed, 703 insertions(+), 2166 deletions(-) create mode 100644 extensions/AWSSDK.Extensions.NetFramework.sln create mode 100644 extensions/src/AWSSDK.Extensions.CloudFront.Signers/AWSSDK.Extensions.CloudFront.Signers.NetFramework.csproj create mode 100644 extensions/src/AWSSDK.Extensions.CloudFront.Signers/AWSSDK.Extensions.CloudFront.Signers.NetStandard.csproj create mode 100644 extensions/src/AWSSDK.Extensions.CloudFront.Signers/AWSSDK.Extensions.CloudFront.Signers.nuspec rename {sdk/src/Services/CloudFront/Custom => extensions/src/AWSSDK.Extensions.CloudFront.Signers}/AmazonCloudFrontCookieSigner.cs (99%) rename {sdk/src/Services/CloudFront/Custom => extensions/src/AWSSDK.Extensions.CloudFront.Signers}/AmazonCloudFrontUrlSigner.cs (98%) create mode 100644 extensions/src/AWSSDK.Extensions.EC2.DecryptPassword/AWSSDK.Extensions.EC2.DecryptPassword.NetFramework.csproj create mode 100644 extensions/src/AWSSDK.Extensions.EC2.DecryptPassword/AWSSDK.Extensions.EC2.DecryptPassword.NetStandard.csproj create mode 100644 extensions/src/AWSSDK.Extensions.EC2.DecryptPassword/AWSSDK.Extensions.EC2.DecryptPassword.nuspec create mode 100644 extensions/src/AWSSDK.Extensions.EC2.DecryptPassword/AWSSDK.Extensions.EC2.DecryptPassword.sln rename sdk/src/Services/EC2/Custom/Model/GetPasswordDataResponse.Extensions.cs => extensions/src/AWSSDK.Extensions.EC2.DecryptPassword/GetPasswordDataResponseExtensions.cs (65%) create mode 100644 extensions/test/CloudFront.SignersTests/CloudFront.Signers.Tests.NetFramework.csproj create mode 100644 extensions/test/CloudFront.SignersTests/CloudFront.Signers.Tests.NetStandard.csproj rename {sdk/test/Services/CloudFront/UnitTests/Custom => extensions/test/CloudFront.SignersTests}/CloudFrontTests.cs (74%) rename {sdk/test/Services/CloudFront/UnitTests/Custom => extensions/test/CloudFront.SignersTests}/CookieSignerTest.cs (69%) rename {sdk/test/Services/CloudFront/UnitTests/Custom => extensions/test/CloudFront.SignersTests}/EmbeddedResource/sample.rsa.private.key.txt (100%) rename {sdk/test/Services/CloudFront/UnitTests/Custom => extensions/test/CloudFront.SignersTests}/URLSignerTest.cs (70%) create mode 100644 extensions/test/EC2.DecryptPasswordTests/EC2.DecryptPassword.NetFramework.csproj create mode 100644 extensions/test/EC2.DecryptPasswordTests/EC2.DecryptPassword.NetStandard.csproj rename {sdk/test/Services/EC2/UnitTests/Custom => extensions/test/EC2.DecryptPasswordTests}/PasswordTest.cs (92%) delete mode 100644 sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Asn1Encodable.cs delete mode 100644 sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Asn1EncodableVector.cs delete mode 100644 sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Asn1InputStream.cs delete mode 100644 sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Asn1Object.cs delete mode 100644 sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Asn1Sequence.cs delete mode 100644 sdk/src/Core/ThirdParty/BouncyCastle/Asn1/DerInteger.cs delete mode 100644 sdk/src/Core/ThirdParty/BouncyCastle/Asn1/DerSequence.cs delete mode 100644 sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Utilities/FilterStream.cs delete mode 100644 sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Utilities/Platform.cs delete mode 100644 sdk/src/Core/ThirdParty/BouncyCastle/Math/BigInteger.cs delete mode 100644 sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/PEMReader.cs delete mode 100644 sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemGenerationException.cs delete mode 100644 sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemHeader.cs delete mode 100644 sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemObject.cs delete mode 100644 sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemObjectGenerator.cs delete mode 100644 sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemObjectParser.cs delete mode 100644 sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemReader.cs delete mode 100644 sdk/test/NetStandard/UnitTests/Services/CloudFrontUnitTests.cs diff --git a/buildtools/build.proj b/buildtools/build.proj index bf909c79ab0c..4248da74fdf2 100644 --- a/buildtools/build.proj +++ b/buildtools/build.proj @@ -32,6 +32,8 @@ build-test-wrapper;build-test-project build-extensions build-extensions + build-extensions + build-extensions build-tools copy-dependencies copy-license-and-notice @@ -495,6 +497,16 @@ + + + + + + + + + + @@ -571,9 +583,10 @@ - + + @@ -588,7 +601,7 @@ - + diff --git a/docgenerator/SDKDocGeneratorLib/SdkDocGenerator.cs b/docgenerator/SDKDocGeneratorLib/SdkDocGenerator.cs index cf08fefe9c1b..8199a6941ecb 100644 --- a/docgenerator/SDKDocGeneratorLib/SdkDocGenerator.cs +++ b/docgenerator/SDKDocGeneratorLib/SdkDocGenerator.cs @@ -18,7 +18,9 @@ public class SdkDocGenerator private static readonly IEnumerable _assembliesToSkip = new HashSet { "AWSSDK.Extensions.CrtIntegration.dll", - "AWSSDK.Extensions.NETCore.Setup.dll" + "AWSSDK.Extensions.NETCore.Setup.dll", + "AWSSDK.Extensions.CloudFront.Signers.dll", + "AWSSDK.Extensions.EC2.DecryptPassword.dll" }; public GeneratorOptions Options { get; private set; } diff --git a/extensions/AWSSDK.Extensions.NetFramework.sln b/extensions/AWSSDK.Extensions.NetFramework.sln new file mode 100644 index 000000000000..0272eecf9451 --- /dev/null +++ b/extensions/AWSSDK.Extensions.NetFramework.sln @@ -0,0 +1,76 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.35122.118 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sdk", "sdk", "{C7DC5CC7-4224-4006-97BE-A3795235132B}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0EFB912F-50E5-4FDF-B0C6-EBE235D338BD}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D445C9DA-311F-4935-B399-173055FA4775}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.Core.NetFramework", "..\sdk\src\Core\AWSSDK.Core.NetFramework.csproj", "{1ED1E9CC-29A6-4F3B-A5B1-E5959C9AAAE2}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.CloudFront.NetFramework", "..\sdk\src\Services\CloudFront\AWSSDK.CloudFront.NetFramework.csproj", "{2F93E709-B9D2-4BFD-989C-885F6DBF7B27}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.EC2.NetFramework", "..\sdk\src\Services\EC2\AWSSDK.EC2.NetFramework.csproj", "{03F1146F-09D6-43D4-91A9-1F2727F8655C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.Extensions.CloudFront.Signers.NetFramework", "src\AWSSDK.Extensions.CloudFront.Signers\AWSSDK.Extensions.CloudFront.Signers.NetFramework.csproj", "{E4433950-BB21-45E3-BB12-337C9CB167F3}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.Extensions.EC2.DecryptPassword.NetFramework", "src\AWSSDK.Extensions.EC2.DecryptPassword\AWSSDK.Extensions.EC2.DecryptPassword.NetFramework.csproj", "{0982F05F-A776-4C57-88CD-3102F6BAF8F0}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CloudFront.Signers.Tests.NetFramework", "test\CloudFront.SignersTests\CloudFront.Signers.Tests.NetFramework.csproj", "{051DEB5D-4435-4FDF-98DE-6483897F93A7}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EC2.DecryptPassword.NetFramework", "test\EC2.DecryptPasswordTests\EC2.DecryptPassword.NetFramework.csproj", "{E11F54E7-52C1-4BDC-8AAF-B605C9B98505}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1ED1E9CC-29A6-4F3B-A5B1-E5959C9AAAE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1ED1E9CC-29A6-4F3B-A5B1-E5959C9AAAE2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1ED1E9CC-29A6-4F3B-A5B1-E5959C9AAAE2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1ED1E9CC-29A6-4F3B-A5B1-E5959C9AAAE2}.Release|Any CPU.Build.0 = Release|Any CPU + {2F93E709-B9D2-4BFD-989C-885F6DBF7B27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2F93E709-B9D2-4BFD-989C-885F6DBF7B27}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2F93E709-B9D2-4BFD-989C-885F6DBF7B27}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2F93E709-B9D2-4BFD-989C-885F6DBF7B27}.Release|Any CPU.Build.0 = Release|Any CPU + {03F1146F-09D6-43D4-91A9-1F2727F8655C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {03F1146F-09D6-43D4-91A9-1F2727F8655C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {03F1146F-09D6-43D4-91A9-1F2727F8655C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {03F1146F-09D6-43D4-91A9-1F2727F8655C}.Release|Any CPU.Build.0 = Release|Any CPU + {E4433950-BB21-45E3-BB12-337C9CB167F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E4433950-BB21-45E3-BB12-337C9CB167F3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E4433950-BB21-45E3-BB12-337C9CB167F3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E4433950-BB21-45E3-BB12-337C9CB167F3}.Release|Any CPU.Build.0 = Release|Any CPU + {0982F05F-A776-4C57-88CD-3102F6BAF8F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0982F05F-A776-4C57-88CD-3102F6BAF8F0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0982F05F-A776-4C57-88CD-3102F6BAF8F0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0982F05F-A776-4C57-88CD-3102F6BAF8F0}.Release|Any CPU.Build.0 = Release|Any CPU + {051DEB5D-4435-4FDF-98DE-6483897F93A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {051DEB5D-4435-4FDF-98DE-6483897F93A7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {051DEB5D-4435-4FDF-98DE-6483897F93A7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {051DEB5D-4435-4FDF-98DE-6483897F93A7}.Release|Any CPU.Build.0 = Release|Any CPU + {E11F54E7-52C1-4BDC-8AAF-B605C9B98505}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E11F54E7-52C1-4BDC-8AAF-B605C9B98505}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E11F54E7-52C1-4BDC-8AAF-B605C9B98505}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E11F54E7-52C1-4BDC-8AAF-B605C9B98505}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {1ED1E9CC-29A6-4F3B-A5B1-E5959C9AAAE2} = {C7DC5CC7-4224-4006-97BE-A3795235132B} + {2F93E709-B9D2-4BFD-989C-885F6DBF7B27} = {C7DC5CC7-4224-4006-97BE-A3795235132B} + {03F1146F-09D6-43D4-91A9-1F2727F8655C} = {C7DC5CC7-4224-4006-97BE-A3795235132B} + {E4433950-BB21-45E3-BB12-337C9CB167F3} = {0EFB912F-50E5-4FDF-B0C6-EBE235D338BD} + {0982F05F-A776-4C57-88CD-3102F6BAF8F0} = {0EFB912F-50E5-4FDF-B0C6-EBE235D338BD} + {051DEB5D-4435-4FDF-98DE-6483897F93A7} = {D445C9DA-311F-4935-B399-173055FA4775} + {E11F54E7-52C1-4BDC-8AAF-B605C9B98505} = {D445C9DA-311F-4935-B399-173055FA4775} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {31DDD4FF-8E79-4861-9D38-1F259E4ACBAF} + EndGlobalSection +EndGlobal diff --git a/extensions/AWSSDK.Extensions.sln b/extensions/AWSSDK.Extensions.sln index fd8bdf1ed0b1..9c6dcdc08c09 100644 --- a/extensions/AWSSDK.Extensions.sln +++ b/extensions/AWSSDK.Extensions.sln @@ -28,6 +28,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.Extensions.CrtIntegr EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.S3.NetStandard", "..\sdk\src\Services\S3\AWSSDK.S3.NetStandard.csproj", "{331C9F91-2F44-47CC-822C-D4F58B57F4EF}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.Extensions.CloudFront.Signers.NetStandard", "src\AWSSDK.Extensions.CloudFront.Signers\AWSSDK.Extensions.CloudFront.Signers.NetStandard.csproj", "{DAE9714C-3BE5-4740-970C-94F96F7835C6}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.Extensions.EC2.DecryptPassword.NetStandard", "src\AWSSDK.Extensions.EC2.DecryptPassword\AWSSDK.Extensions.EC2.DecryptPassword.NetStandard.csproj", "{C8A027AB-282C-400E-893D-971A5D55DB17}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CloudFront.Signers.Tests.NetStandard", "test\CloudFront.SignersTests\CloudFront.Signers.Tests.NetStandard.csproj", "{A552BA51-D17C-4594-BF0A-DF7F53EA688D}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EC2.DecryptPassword.NetStandard", "test\EC2.DecryptPasswordTests\EC2.DecryptPassword.NetStandard.csproj", "{EA6EEC77-E69B-4D42-B9F2-BADCEEE5A32B}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.CloudFront.NetStandard", "..\sdk\src\Services\CloudFront\AWSSDK.CloudFront.NetStandard.csproj", "{280223DF-ECB0-4B38-A3A6-B80B46D48475}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.EC2.NetStandard", "..\sdk\src\Services\EC2\AWSSDK.EC2.NetStandard.csproj", "{FC70CF98-BA7E-4F9F-A5DB-966973284091}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -66,6 +78,30 @@ Global {331C9F91-2F44-47CC-822C-D4F58B57F4EF}.Debug|Any CPU.Build.0 = Debug|Any CPU {331C9F91-2F44-47CC-822C-D4F58B57F4EF}.Release|Any CPU.ActiveCfg = Release|Any CPU {331C9F91-2F44-47CC-822C-D4F58B57F4EF}.Release|Any CPU.Build.0 = Release|Any CPU + {DAE9714C-3BE5-4740-970C-94F96F7835C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DAE9714C-3BE5-4740-970C-94F96F7835C6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DAE9714C-3BE5-4740-970C-94F96F7835C6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DAE9714C-3BE5-4740-970C-94F96F7835C6}.Release|Any CPU.Build.0 = Release|Any CPU + {C8A027AB-282C-400E-893D-971A5D55DB17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C8A027AB-282C-400E-893D-971A5D55DB17}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C8A027AB-282C-400E-893D-971A5D55DB17}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C8A027AB-282C-400E-893D-971A5D55DB17}.Release|Any CPU.Build.0 = Release|Any CPU + {A552BA51-D17C-4594-BF0A-DF7F53EA688D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A552BA51-D17C-4594-BF0A-DF7F53EA688D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A552BA51-D17C-4594-BF0A-DF7F53EA688D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A552BA51-D17C-4594-BF0A-DF7F53EA688D}.Release|Any CPU.Build.0 = Release|Any CPU + {EA6EEC77-E69B-4D42-B9F2-BADCEEE5A32B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EA6EEC77-E69B-4D42-B9F2-BADCEEE5A32B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EA6EEC77-E69B-4D42-B9F2-BADCEEE5A32B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EA6EEC77-E69B-4D42-B9F2-BADCEEE5A32B}.Release|Any CPU.Build.0 = Release|Any CPU + {280223DF-ECB0-4B38-A3A6-B80B46D48475}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {280223DF-ECB0-4B38-A3A6-B80B46D48475}.Debug|Any CPU.Build.0 = Debug|Any CPU + {280223DF-ECB0-4B38-A3A6-B80B46D48475}.Release|Any CPU.ActiveCfg = Release|Any CPU + {280223DF-ECB0-4B38-A3A6-B80B46D48475}.Release|Any CPU.Build.0 = Release|Any CPU + {FC70CF98-BA7E-4F9F-A5DB-966973284091}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FC70CF98-BA7E-4F9F-A5DB-966973284091}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FC70CF98-BA7E-4F9F-A5DB-966973284091}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FC70CF98-BA7E-4F9F-A5DB-966973284091}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -79,6 +115,12 @@ Global {FFE9C5B6-F508-4CB6-ADB7-7602CB437B75} = {3D822DC2-ED2E-4434-BC4F-CE7FCD846B02} {4C0F4D67-3519-46F1-BD60-AA71FBA1CA2D} = {3D822DC2-ED2E-4434-BC4F-CE7FCD846B02} {331C9F91-2F44-47CC-822C-D4F58B57F4EF} = {0BA39F07-84D6-420B-82D3-6DC3AF016C65} + {DAE9714C-3BE5-4740-970C-94F96F7835C6} = {3D822DC2-ED2E-4434-BC4F-CE7FCD846B02} + {C8A027AB-282C-400E-893D-971A5D55DB17} = {3D822DC2-ED2E-4434-BC4F-CE7FCD846B02} + {A552BA51-D17C-4594-BF0A-DF7F53EA688D} = {A960D001-40B3-4B1A-A890-D1049FB7586E} + {EA6EEC77-E69B-4D42-B9F2-BADCEEE5A32B} = {A960D001-40B3-4B1A-A890-D1049FB7586E} + {280223DF-ECB0-4B38-A3A6-B80B46D48475} = {0BA39F07-84D6-420B-82D3-6DC3AF016C65} + {FC70CF98-BA7E-4F9F-A5DB-966973284091} = {0BA39F07-84D6-420B-82D3-6DC3AF016C65} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {949367A4-5683-4FD3-93F4-A2CEA6EECB21} diff --git a/extensions/src/AWSSDK.Extensions.CloudFront.Signers/AWSSDK.Extensions.CloudFront.Signers.NetFramework.csproj b/extensions/src/AWSSDK.Extensions.CloudFront.Signers/AWSSDK.Extensions.CloudFront.Signers.NetFramework.csproj new file mode 100644 index 000000000000..5cba9aaec3fa --- /dev/null +++ b/extensions/src/AWSSDK.Extensions.CloudFront.Signers/AWSSDK.Extensions.CloudFront.Signers.NetFramework.csproj @@ -0,0 +1,45 @@ + + + net472 + AWSSDK.Extensions.CloudFront.Signers + AWSSDK.Extensions.CloudFront.Signers + 4.0.0.0-preview + AWSSDK.Extensions.Cloudfront.Signers + + This package contains extension methods for creating signed URLs for Amazon CloudFront distributions and + for creating signed cookies for Amazon CloudFront distributions using canned or custom policies. + + false + false + false + false + false + false + false + false + true + + + + + + + + ..\..\..\sdk\awssdk.dll.snk + + + + + $(AWSKeyFile) + + + + + + + + + + + + diff --git a/extensions/src/AWSSDK.Extensions.CloudFront.Signers/AWSSDK.Extensions.CloudFront.Signers.NetStandard.csproj b/extensions/src/AWSSDK.Extensions.CloudFront.Signers/AWSSDK.Extensions.CloudFront.Signers.NetStandard.csproj new file mode 100644 index 000000000000..e4b369bb2118 --- /dev/null +++ b/extensions/src/AWSSDK.Extensions.CloudFront.Signers/AWSSDK.Extensions.CloudFront.Signers.NetStandard.csproj @@ -0,0 +1,49 @@ + + + netstandard2.0;netcoreapp3.1;net8.0 + AWSSDK.Extensions.CloudFront.Signers + AWSSDK.Extensions.CloudFront.Signers + 4.0.0.0-preview + AWSSDK.Extensions.Cloudfront.Signers + + This package contains extension methods for creating signed URLs for Amazon CloudFront distributions and + for creating signed cookies for Amazon CloudFront distributions using canned or custom policies. + + $(DefineConstants);NETSTANDARD;AWS_ASYNC_API + $(DefineConstants);NETSTANDARD20;AWS_ASYNC_ENUMERABLES_API + $(DefineConstants);AWS_ASYNC_ENUMERABLES_API + $(DefineConstants);AWS_ASYNC_ENUMERABLES_API + false + false + false + false + false + false + false + false + true + + + + + + + + ..\..\..\sdk\awssdk.dll.snk + + + + + $(AWSKeyFile) + + + + + + + + + + + + diff --git a/extensions/src/AWSSDK.Extensions.CloudFront.Signers/AWSSDK.Extensions.CloudFront.Signers.nuspec b/extensions/src/AWSSDK.Extensions.CloudFront.Signers/AWSSDK.Extensions.CloudFront.Signers.nuspec new file mode 100644 index 000000000000..590bce951f6c --- /dev/null +++ b/extensions/src/AWSSDK.Extensions.CloudFront.Signers/AWSSDK.Extensions.CloudFront.Signers.nuspec @@ -0,0 +1,38 @@ + + + + AWSSDK.Extensions.CloudFront.Signers + AWSSDK - Extensions for AWS CloudFront + 4.0.0-preview + Amazon Web Services + + This package contains extension methods for creating signed URLs for Amazon CloudFront distributions and + for creating signed cookies for Amazon CloudFront distributions using canned or custom policies. + + en-US + Apache-2.0 + https://github.com/aws/aws-sdk-net/ + AWS Amazon aws-sdk-v4 + images\AWSLogo.png + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sdk/src/Services/CloudFront/Custom/AmazonCloudFrontCookieSigner.cs b/extensions/src/AWSSDK.Extensions.CloudFront.Signers/AmazonCloudFrontCookieSigner.cs similarity index 99% rename from sdk/src/Services/CloudFront/Custom/AmazonCloudFrontCookieSigner.cs rename to extensions/src/AWSSDK.Extensions.CloudFront.Signers/AmazonCloudFrontCookieSigner.cs index 35294d6b6390..31073b9e0b45 100644 --- a/sdk/src/Services/CloudFront/Custom/AmazonCloudFrontCookieSigner.cs +++ b/extensions/src/AWSSDK.Extensions.CloudFront.Signers/AmazonCloudFrontCookieSigner.cs @@ -22,7 +22,6 @@ using Amazon.Runtime; using Amazon.Util; -using ThirdParty.BouncyCastle.OpenSsl; using System.Globalization; namespace Amazon.CloudFront diff --git a/sdk/src/Services/CloudFront/Custom/AmazonCloudFrontUrlSigner.cs b/extensions/src/AWSSDK.Extensions.CloudFront.Signers/AmazonCloudFrontUrlSigner.cs similarity index 98% rename from sdk/src/Services/CloudFront/Custom/AmazonCloudFrontUrlSigner.cs rename to extensions/src/AWSSDK.Extensions.CloudFront.Signers/AmazonCloudFrontUrlSigner.cs index ed25d483ef50..ed1d82f23ee8 100644 --- a/sdk/src/Services/CloudFront/Custom/AmazonCloudFrontUrlSigner.cs +++ b/extensions/src/AWSSDK.Extensions.CloudFront.Signers/AmazonCloudFrontUrlSigner.cs @@ -17,13 +17,14 @@ using System.IO; using System.Security.Cryptography; using System.Text; - using Amazon.CloudFront.Model; using Amazon.Runtime; using Amazon.Util; - -using ThirdParty.BouncyCastle.OpenSsl; +using Org.BouncyCastle.OpenSsl; using System.Globalization; +using Org.BouncyCastle.Crypto; +using Org.BouncyCastle.Crypto.Parameters; +using Org.BouncyCastle.Security; #pragma warning disable 1591 @@ -519,7 +520,11 @@ internal static RSAParameters ConvertPEMToRSAParameters(TextReader privateKeyRea RSAParameters rsaParams; try { - rsaParams = new PemReader(privateKeyReader).ReadPrivatekey(); + var pemReader = new PemReader(privateKeyReader); + var keyPair = pemReader.ReadObject() as AsymmetricCipherKeyPair; + var privateKey = keyPair.Private as RsaPrivateCrtKeyParameters; + rsaParams = DotNetUtilities.ToRSAParameters(privateKey); + } catch (Exception e) { diff --git a/extensions/src/AWSSDK.Extensions.CrtIntegration/AWSSDK.Extensions.CrtIntegration.NetFramework.csproj b/extensions/src/AWSSDK.Extensions.CrtIntegration/AWSSDK.Extensions.CrtIntegration.NetFramework.csproj index 69449a4de124..8cfc1ebcdce1 100644 --- a/extensions/src/AWSSDK.Extensions.CrtIntegration/AWSSDK.Extensions.CrtIntegration.NetFramework.csproj +++ b/extensions/src/AWSSDK.Extensions.CrtIntegration/AWSSDK.Extensions.CrtIntegration.NetFramework.csproj @@ -13,11 +13,9 @@ false false - - diff --git a/extensions/src/AWSSDK.Extensions.CrtIntegration/AWSSDK.Extensions.CrtIntegration.nuspec b/extensions/src/AWSSDK.Extensions.CrtIntegration/AWSSDK.Extensions.CrtIntegration.nuspec index 29b4596cca4c..a1517088d68b 100644 --- a/extensions/src/AWSSDK.Extensions.CrtIntegration/AWSSDK.Extensions.CrtIntegration.nuspec +++ b/extensions/src/AWSSDK.Extensions.CrtIntegration/AWSSDK.Extensions.CrtIntegration.nuspec @@ -14,13 +14,11 @@ - - + - - - + + diff --git a/extensions/src/AWSSDK.Extensions.EC2.DecryptPassword/AWSSDK.Extensions.EC2.DecryptPassword.NetFramework.csproj b/extensions/src/AWSSDK.Extensions.EC2.DecryptPassword/AWSSDK.Extensions.EC2.DecryptPassword.NetFramework.csproj new file mode 100644 index 000000000000..e70462308649 --- /dev/null +++ b/extensions/src/AWSSDK.Extensions.EC2.DecryptPassword/AWSSDK.Extensions.EC2.DecryptPassword.NetFramework.csproj @@ -0,0 +1,42 @@ + + + net472 + AWSSDK.Extensions.EC2.DecryptPassword + AWSSDK.Extensions.EC2.DecryptPassword + 4.0.0.0-preview + AWSSDK.Extensions.EC2.DecryptPassword + $(DefineConstants);BCL;AWS_ASYNC_API;CODE_ANALYSIS + false + false + false + false + false + false + false + false + true + + + + + + + + ..\..\..\sdk\awssdk.dll.snk + + + + + $(AWSKeyFile) + + + + + + + + + + + + diff --git a/extensions/src/AWSSDK.Extensions.EC2.DecryptPassword/AWSSDK.Extensions.EC2.DecryptPassword.NetStandard.csproj b/extensions/src/AWSSDK.Extensions.EC2.DecryptPassword/AWSSDK.Extensions.EC2.DecryptPassword.NetStandard.csproj new file mode 100644 index 000000000000..bcbad3d011ab --- /dev/null +++ b/extensions/src/AWSSDK.Extensions.EC2.DecryptPassword/AWSSDK.Extensions.EC2.DecryptPassword.NetStandard.csproj @@ -0,0 +1,45 @@ + + + netstandard2.0;netcoreapp3.1;net8.0 + AWSSDK.Extensions.EC2.DecryptPassword + AWSSDK.Extensions.EC2.DecryptPassword + 4.0.0.0-preview + AWSSDK.Extensions.EC2.DecryptPassword + $(DefineConstants);NETSTANDARD;AWS_ASYNC_API + $(DefineConstants);NETSTANDARD20;AWS_ASYNC_ENUMERABLES_API + $(DefineConstants);AWS_ASYNC_ENUMERABLES_API + $(DefineConstants);AWS_ASYNC_ENUMERABLES_API + false + false + false + false + false + false + false + false + true + + + + + + + + ..\..\..\sdk\awssdk.dll.snk + + + + + $(AWSKeyFile) + + + + + + + + + + + + diff --git a/extensions/src/AWSSDK.Extensions.EC2.DecryptPassword/AWSSDK.Extensions.EC2.DecryptPassword.nuspec b/extensions/src/AWSSDK.Extensions.EC2.DecryptPassword/AWSSDK.Extensions.EC2.DecryptPassword.nuspec new file mode 100644 index 000000000000..f04b9b8ab5d9 --- /dev/null +++ b/extensions/src/AWSSDK.Extensions.EC2.DecryptPassword/AWSSDK.Extensions.EC2.DecryptPassword.nuspec @@ -0,0 +1,35 @@ + + + + AWSSDK.Extensions.EC2.DecryptPassword + AWSSDK - Extensions for AWS EC2 + 4.0.0-preview + Amazon Web Services + Extensions for the AWS EC2 to get the decrypted password for an EC2 instance. + en-US + Apache-2.0 + https://github.com/aws/aws-sdk-net/ + AWS Amazon aws-sdk-v4 + images\AWSLogo.png + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/extensions/src/AWSSDK.Extensions.EC2.DecryptPassword/AWSSDK.Extensions.EC2.DecryptPassword.sln b/extensions/src/AWSSDK.Extensions.EC2.DecryptPassword/AWSSDK.Extensions.EC2.DecryptPassword.sln new file mode 100644 index 000000000000..2d818922ffa3 --- /dev/null +++ b/extensions/src/AWSSDK.Extensions.EC2.DecryptPassword/AWSSDK.Extensions.EC2.DecryptPassword.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.002.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.Extensions.Ec2.DecryptPassword.NetStandard", "AWSSDK.Extensions.Ec2.DecryptPassword.NetStandard.csproj", "{79C3BD47-E485-48EE-9440-7C2E6F727147}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.Extensions.EC2.DecryptPassword.NetFramework", "AWSSDK.Extensions.EC2.DecryptPassword.NetFramework.csproj", "{71276C16-3287-4FEC-92F0-72EE7C3BE8DA}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EC2.DecryptPassword.NetFramework", "..\..\test\EC2.DecryptPasswordTests\EC2.DecryptPassword.NetFramework.csproj", "{4659595E-2C55-4EA7-9023-02C7A0786634}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {79C3BD47-E485-48EE-9440-7C2E6F727147}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {79C3BD47-E485-48EE-9440-7C2E6F727147}.Debug|Any CPU.Build.0 = Debug|Any CPU + {79C3BD47-E485-48EE-9440-7C2E6F727147}.Release|Any CPU.ActiveCfg = Release|Any CPU + {79C3BD47-E485-48EE-9440-7C2E6F727147}.Release|Any CPU.Build.0 = Release|Any CPU + {71276C16-3287-4FEC-92F0-72EE7C3BE8DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {71276C16-3287-4FEC-92F0-72EE7C3BE8DA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {71276C16-3287-4FEC-92F0-72EE7C3BE8DA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {71276C16-3287-4FEC-92F0-72EE7C3BE8DA}.Release|Any CPU.Build.0 = Release|Any CPU + {4659595E-2C55-4EA7-9023-02C7A0786634}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4659595E-2C55-4EA7-9023-02C7A0786634}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4659595E-2C55-4EA7-9023-02C7A0786634}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4659595E-2C55-4EA7-9023-02C7A0786634}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {4E922C0B-567A-4525-BA1F-89160EC54342} + EndGlobalSection +EndGlobal diff --git a/sdk/src/Services/EC2/Custom/Model/GetPasswordDataResponse.Extensions.cs b/extensions/src/AWSSDK.Extensions.EC2.DecryptPassword/GetPasswordDataResponseExtensions.cs similarity index 65% rename from sdk/src/Services/EC2/Custom/Model/GetPasswordDataResponse.Extensions.cs rename to extensions/src/AWSSDK.Extensions.EC2.DecryptPassword/GetPasswordDataResponseExtensions.cs index 6d07da1df8a5..46f8aaf6ae43 100644 --- a/sdk/src/Services/EC2/Custom/Model/GetPasswordDataResponse.Extensions.cs +++ b/extensions/src/AWSSDK.Extensions.EC2.DecryptPassword/GetPasswordDataResponseExtensions.cs @@ -21,11 +21,15 @@ using Amazon.Runtime; using System.IO; using System.Security.Cryptography; -using ThirdParty.BouncyCastle.OpenSsl; - +using Org.BouncyCastle.OpenSsl; +using Org.BouncyCastle.Crypto; +using Org.BouncyCastle.Crypto.Parameters; +using System.Runtime.CompilerServices; +using System.Diagnostics; +using Org.BouncyCastle.Security; namespace Amazon.EC2.Model { - public partial class GetPasswordDataResponse : AmazonWebServiceResponse + public static class GetPasswordDataResponseExtensions { /// /// Gets the decrypted password using the RSA private key which can be found in the @@ -33,12 +37,15 @@ public partial class GetPasswordDataResponse : AmazonWebServiceResponse /// /// The RSA private key from the PEM file /// The decrypted password - public string GetDecryptedPassword(string rsaPrivateKey) + public static string GetDecryptedPassword(this GetPasswordDataResponse getPasswordDataResponse, string rsaPrivateKey) { RSAParameters rsaParams; try { - rsaParams = new PemReader(new StringReader(rsaPrivateKey.Trim())).ReadPrivatekey(); + //rsaParams = new PemReader(new StringReader(rsaPrivateKey.Trim())).ReadPrivatekey(); + var keyPair = new Org.BouncyCastle.OpenSsl.PemReader(new StringReader(rsaPrivateKey.Trim())).ReadObject() as AsymmetricCipherKeyPair; + var privateKey = keyPair.Private as RsaPrivateCrtKeyParameters; + rsaParams = DotNetUtilities.ToRSAParameters(privateKey); } catch (Exception e) { @@ -48,7 +55,7 @@ public string GetDecryptedPassword(string rsaPrivateKey) RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); rsa.ImportParameters(rsaParams); - byte[] encryptedBytes = Convert.FromBase64String(this.PasswordData); + byte[] encryptedBytes = Convert.FromBase64String(getPasswordDataResponse.PasswordData); var decryptedBytes = rsa.Decrypt(encryptedBytes, false); string decrypted = Encoding.UTF8.GetString(decryptedBytes); diff --git a/extensions/test/CloudFront.SignersTests/CloudFront.Signers.Tests.NetFramework.csproj b/extensions/test/CloudFront.SignersTests/CloudFront.Signers.Tests.NetFramework.csproj new file mode 100644 index 000000000000..e977e49fc517 --- /dev/null +++ b/extensions/test/CloudFront.SignersTests/CloudFront.Signers.Tests.NetFramework.csproj @@ -0,0 +1,34 @@ + + + net472 + CloudFront.SignersTests + CloudFront.SignersTests + false + false + false + false + false + false + false + false + true + + + + + + + + + + + + + + + + + Always + + + diff --git a/extensions/test/CloudFront.SignersTests/CloudFront.Signers.Tests.NetStandard.csproj b/extensions/test/CloudFront.SignersTests/CloudFront.Signers.Tests.NetStandard.csproj new file mode 100644 index 000000000000..de05395137f2 --- /dev/null +++ b/extensions/test/CloudFront.SignersTests/CloudFront.Signers.Tests.NetStandard.csproj @@ -0,0 +1,33 @@ + + + netcoreapp3.1;net8.0 + CloudFront.SignersTests + CloudFront.SignersTests + false + false + false + false + false + false + false + false + + + + + + + + + + + + + + + + + Always + + + diff --git a/sdk/test/Services/CloudFront/UnitTests/Custom/CloudFrontTests.cs b/extensions/test/CloudFront.SignersTests/CloudFrontTests.cs similarity index 74% rename from sdk/test/Services/CloudFront/UnitTests/Custom/CloudFrontTests.cs rename to extensions/test/CloudFront.SignersTests/CloudFrontTests.cs index 44ac49fe45da..d9f8fa3a6df0 100644 --- a/sdk/test/Services/CloudFront/UnitTests/Custom/CloudFrontTests.cs +++ b/extensions/test/CloudFront.SignersTests/CloudFrontTests.cs @@ -1,29 +1,27 @@ using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; using Amazon.CloudFront; -using Json.LitJson; using System.IO; +using Xunit; namespace AWSSDK_DotNet.UnitTests { - [TestClass] public class CloudFrontTests { /// /// Test to verify fix for misconfigured AmazonCloudFrontCookieSigner.Protocols flags enum. /// - [TestMethod] - [TestCategory("CloudFront")] + [Fact] + [Trait("Category","CloudFront")] public void TestProtocolEnum() { var http = AmazonCloudFrontCookieSigner.Protocols.Http; var https = AmazonCloudFrontCookieSigner.Protocols.Https; var httpAndHttps = AmazonCloudFrontCookieSigner.Protocols.Http | AmazonCloudFrontCookieSigner.Protocols.Https; - Assert.IsTrue(Evaluate(httpAndHttps)); - Assert.IsFalse(Evaluate(http)); - Assert.IsFalse(Evaluate(https)); + Assert.True(Evaluate(httpAndHttps)); + Assert.False(Evaluate(http)); + Assert.False(Evaluate(https)); } private static bool Evaluate(AmazonCloudFrontCookieSigner.Protocols protocol) diff --git a/sdk/test/Services/CloudFront/UnitTests/Custom/CookieSignerTest.cs b/extensions/test/CloudFront.SignersTests/CookieSignerTest.cs similarity index 69% rename from sdk/test/Services/CloudFront/UnitTests/Custom/CookieSignerTest.cs rename to extensions/test/CloudFront.SignersTests/CookieSignerTest.cs index 4da1f2b6e1f3..6be77bc1d3aa 100644 --- a/sdk/test/Services/CloudFront/UnitTests/Custom/CookieSignerTest.cs +++ b/extensions/test/CloudFront.SignersTests/CookieSignerTest.cs @@ -2,24 +2,28 @@ using System.IO; using System.Text; using Amazon.CloudFront; -using Json.LitJson; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using ThirdParty.Json.LitJson; +using Xunit; namespace AWSSDK_DotNet.UnitTests { - [TestClass] public class CookieSignerTest { private static StreamReader privateRSAKeyStreamReader = null; - [TestInitialize] - public void Initialize() + public CookieSignerTest() { - privateRSAKeyStreamReader = new StreamReader(Utils.GetResourceStream("sample.rsa.private.key.txt")); + Initialize(); + } + private void Initialize() + { + var resourceDirectory = Path.Combine(Environment.CurrentDirectory,"EmbeddedResource"); + var privateKeyTxtPath = Path.Combine(resourceDirectory, "sample.rsa.private.key.txt"); + privateRSAKeyStreamReader = new StreamReader(privateKeyTxtPath); } - [TestMethod] - [TestCategory("CloudFront")] + [Fact] + [Trait("Category", "CloudFront")] public void CannedPolicyValidation() { string expectedSignature = @@ -32,20 +36,21 @@ public void CannedPolicyValidation() privateRSAKeyStreamReader, new DateTime(2024, 1, 1, 12, 0, 0, DateTimeKind.Utc) ); - Assert.IsNotNull(cookies); + Assert.NotNull(cookies); - Assert.AreEqual("CloudFront-Expires", cookies.Expires.Key); - Assert.AreEqual("1704110400", cookies.Expires.Value); + Assert.Equal("CloudFront-Expires", cookies.Expires.Key); + Assert.Equal("1704110400", cookies.Expires.Value); - Assert.AreEqual("CloudFront-Signature", cookies.Signature.Key); - Assert.AreEqual(expectedSignature, cookies.Signature.Value); + Assert.Equal("CloudFront-Signature", cookies.Signature.Key); + Assert.Equal(expectedSignature, cookies.Signature.Value); - Assert.AreEqual("CloudFront-Key-Pair-Id", cookies.KeyPairId.Key); - Assert.AreEqual(expectedKeyPair, cookies.KeyPairId.Value); + Assert.Equal("CloudFront-Key-Pair-Id", cookies.KeyPairId.Key); + Assert.Equal(expectedKeyPair, cookies.KeyPairId.Value); } - [TestMethod] - [TestCategory("CloudFront")] + + [Fact] + [Trait("Category", "CloudFront")] public void CustomPolicyValidation() { // This is the base64 representation of the IAM policy: @@ -65,20 +70,20 @@ public void CustomPolicyValidation() new DateTime(2024, 1, 1, 12, 0, 0, DateTimeKind.Utc), "192.0.2.0/24" ); - Assert.IsNotNull(cookies); + Assert.NotNull(cookies); - Assert.AreEqual("CloudFront-Policy", cookies.Policy.Key); - Assert.AreEqual(expectedPolicy, cookies.Policy.Value); + Assert.Equal("CloudFront-Policy", cookies.Policy.Key); + Assert.Equal(expectedPolicy, cookies.Policy.Value); - Assert.AreEqual("CloudFront-Signature", cookies.Signature.Key); - Assert.AreEqual(expectedSignature, cookies.Signature.Value); + Assert.Equal("CloudFront-Signature", cookies.Signature.Key); + Assert.Equal(expectedSignature, cookies.Signature.Value); - Assert.AreEqual("CloudFront-Key-Pair-Id", cookies.KeyPairId.Key); - Assert.AreEqual(expectedKeyPair, cookies.KeyPairId.Value); + Assert.Equal("CloudFront-Key-Pair-Id", cookies.KeyPairId.Key); + Assert.Equal(expectedKeyPair, cookies.KeyPairId.Value); } - - [TestMethod] - [TestCategory("CloudFront")] + + [Fact] + [Trait("Category", "CloudFront")] public void CustomPolicyResourceValidation_WhenPassingResourceWithLeadingSlash() { // This is the base64 representation of the IAM policy: @@ -99,10 +104,10 @@ public void CustomPolicyResourceValidation_WhenPassingResourceWithLeadingSlash() new DateTime(2024, 1, 1, 12, 0, 0, DateTimeKind.Utc), "192.0.2.0/24" ); - Assert.IsNotNull(cookies); + Assert.NotNull(cookies); - Assert.AreEqual("CloudFront-Policy", cookies.Policy.Key); - Assert.AreEqual(expectedPolicy, cookies.Policy.Value); + Assert.Equal("CloudFront-Policy", cookies.Policy.Key); + Assert.Equal(expectedPolicy, cookies.Policy.Value); string policyJson = Encoding.UTF8.GetString( Convert.FromBase64String(cookies.Policy.Value.Replace('-', '+').Replace('_', '=').Replace('~', '/'))); @@ -110,7 +115,7 @@ public void CustomPolicyResourceValidation_WhenPassingResourceWithLeadingSlash() var policyData = JsonMapper.ToObject(policyJson); var actualResourceUrl = policyData["Statement"][0]["Resource"].ToString(); - Assert.AreEqual(expectedResourceUrl, actualResourceUrl); + Assert.Equal(expectedResourceUrl, actualResourceUrl); } } } diff --git a/sdk/test/Services/CloudFront/UnitTests/Custom/EmbeddedResource/sample.rsa.private.key.txt b/extensions/test/CloudFront.SignersTests/EmbeddedResource/sample.rsa.private.key.txt similarity index 100% rename from sdk/test/Services/CloudFront/UnitTests/Custom/EmbeddedResource/sample.rsa.private.key.txt rename to extensions/test/CloudFront.SignersTests/EmbeddedResource/sample.rsa.private.key.txt diff --git a/sdk/test/Services/CloudFront/UnitTests/Custom/URLSignerTest.cs b/extensions/test/CloudFront.SignersTests/URLSignerTest.cs similarity index 70% rename from sdk/test/Services/CloudFront/UnitTests/Custom/URLSignerTest.cs rename to extensions/test/CloudFront.SignersTests/URLSignerTest.cs index 16577057ba44..71b75c4bd0dc 100644 --- a/sdk/test/Services/CloudFront/UnitTests/Custom/URLSignerTest.cs +++ b/extensions/test/CloudFront.SignersTests/URLSignerTest.cs @@ -1,26 +1,29 @@ using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; using System.IO; using Amazon.CloudFront; using ThirdParty.Json.LitJson; using System.Collections.Generic; - +using Xunit; namespace AWSSDK_DotNet.UnitTests { - [TestClass] public class URLSignerTest { - private static string privateRSAKeyResourceName = @"sample.rsa.private.key.txt"; private static StreamReader privateRSAKeyStreamReader = null; + public URLSignerTest() + { + + Initialize(); + } - [TestInitialize] - public void Initialize() + private void Initialize() { - privateRSAKeyStreamReader = new StreamReader(Utils.GetResourceStream(privateRSAKeyResourceName)); + var resourceDirectory = Path.Combine(Environment.CurrentDirectory, "EmbeddedResource"); + var privateKeyTxtPath = Path.Combine(resourceDirectory, "sample.rsa.private.key.txt"); + privateRSAKeyStreamReader = new StreamReader(privateKeyTxtPath); } - [TestMethod] - [TestCategory("CloudFront")] + [Fact] + [Trait("Category","CloudFront")] public void SignURLValidation() { string expectedSignedURL = @"http://awesome.dot.com/amazing/uri/?Policy=U2VjcmV0UG9saWN5" @@ -28,11 +31,11 @@ public void SignURLValidation() + @"&Key-Pair-Id=amazingKeyPairId"; string signedURL = AmazonCloudFrontUrlSigner.SignUrl("http://awesome.dot.com/amazing/uri/", "amazingKeyPairId", privateRSAKeyStreamReader, "SecretPolicy"); - Assert.AreEqual(expectedSignedURL, signedURL); + Assert.Equal(expectedSignedURL, signedURL); } - [TestMethod] - [TestCategory("CloudFront")] + [Fact] + [Trait("Category", "CloudFront")] public void SignURLCannedValidation() { string expectedSignedURL = @"http://awesome.dot.com/amazing/uri/?Expires=1492153200" + @@ -42,11 +45,11 @@ public void SignURLCannedValidation() string signedURL = AmazonCloudFrontUrlSigner.SignUrlCanned("http://awesome.dot.com/amazing/uri/", "amazingKeyPairId", privateRSAKeyStreamReader, new DateTime(2017, 4, 14, 7, 0, 0, DateTimeKind.Utc)); - Assert.AreEqual(expectedSignedURL, signedURL); + Assert.Equal(expectedSignedURL, signedURL); } - [TestMethod] - [TestCategory("CloudFront")] + [Fact] + [Trait("Category", "CloudFront")] public void PolicyStatementWithNoAddress() { var resourcePath = "http://d111111abcdef8.cloudfront.net/game_download.zip"; @@ -61,35 +64,35 @@ public void PolicyStatementWithNoAddress() dateTime, null); - Assert.AreEqual(policyWithEmptyString, policyWithNull); + Assert.Equal(policyWithEmptyString, policyWithNull); foreach(var policy in new List { policyWithEmptyString, policyWithNull }) { var jsonObject = JsonMapper.ToObject(policy); var statementList = jsonObject["Statement"]; - Assert.IsTrue(statementList.IsArray); + Assert.True(statementList.IsArray); var statement = statementList[0]; - Assert.IsNotNull(statement); + Assert.NotNull(statement); var resource = statement["Resource"]; - Assert.AreEqual(resource.ToString(), resourcePath); + Assert.Equal(resource.ToString(), resourcePath); var condition = statement["Condition"]; - Assert.IsNotNull(condition); - Assert.IsTrue(condition.IsObject); + Assert.NotNull(condition); + Assert.True(condition.IsObject); var IpAddress = condition["IpAddress"]; - Assert.IsNull(IpAddress); + Assert.Null(IpAddress); var epochTime = condition["DateLessThan"]["AWS:EpochTime"]; - Assert.AreEqual(1357034400, long.Parse(epochTime.ToString())); + Assert.Equal(1357034400, long.Parse(epochTime.ToString())); } } - [TestMethod] - [TestCategory("CloudFront")] + [Fact] + [Trait("Category", "CloudFront")] public void PolicyStatementWithAddress() { var resourcePath = "http://*"; @@ -103,23 +106,23 @@ public void PolicyStatementWithAddress() var jsonObject = JsonMapper.ToObject(policyDocument); var statementList = jsonObject["Statement"]; - Assert.IsTrue(statementList.IsArray); + Assert.True(statementList.IsArray); var statement = statementList[0]; - Assert.IsNotNull(statement); + Assert.NotNull(statement); var resource = statement["Resource"]; - Assert.AreEqual(resource.ToString(), resourcePath); + Assert.Equal(resource.ToString(), resourcePath); var condition = statement["Condition"]; - Assert.IsNotNull(condition); - Assert.IsTrue(condition.IsObject); + Assert.NotNull(condition); + Assert.True(condition.IsObject); var sourceIp = condition["IpAddress"]["AWS:SourceIp"]; - Assert.AreEqual(ipRange, sourceIp.ToString()); + Assert.Equal(ipRange, sourceIp.ToString()); var epochTime = condition["DateLessThan"]["AWS:EpochTime"]; - Assert.AreEqual(1357034400, long.Parse(epochTime.ToString())); + Assert.Equal(1357034400, long.Parse(epochTime.ToString())); } } } diff --git a/extensions/test/EC2.DecryptPasswordTests/EC2.DecryptPassword.NetFramework.csproj b/extensions/test/EC2.DecryptPasswordTests/EC2.DecryptPassword.NetFramework.csproj new file mode 100644 index 000000000000..26612243ae7a --- /dev/null +++ b/extensions/test/EC2.DecryptPasswordTests/EC2.DecryptPassword.NetFramework.csproj @@ -0,0 +1,30 @@ + + + net472 + EC2.DecryptPasswordTests + EC2.DecryptPasswordTests + false + false + false + false + false + false + false + false + true + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/extensions/test/EC2.DecryptPasswordTests/EC2.DecryptPassword.NetStandard.csproj b/extensions/test/EC2.DecryptPasswordTests/EC2.DecryptPassword.NetStandard.csproj new file mode 100644 index 000000000000..3f47981490da --- /dev/null +++ b/extensions/test/EC2.DecryptPasswordTests/EC2.DecryptPassword.NetStandard.csproj @@ -0,0 +1,30 @@ + + + netcoreapp3.1;net8.0 + EC2.DecryptPasswordTests + EC2.DecryptPasswordTests + false + false + false + false + false + false + false + false + true + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sdk/test/Services/EC2/UnitTests/Custom/PasswordTest.cs b/extensions/test/EC2.DecryptPasswordTests/PasswordTest.cs similarity index 92% rename from sdk/test/Services/EC2/UnitTests/Custom/PasswordTest.cs rename to extensions/test/EC2.DecryptPasswordTests/PasswordTest.cs index 39d29a78c27d..c16c018e154b 100644 --- a/sdk/test/Services/EC2/UnitTests/Custom/PasswordTest.cs +++ b/extensions/test/EC2.DecryptPasswordTests/PasswordTest.cs @@ -1,18 +1,16 @@ using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using Amazon.EC2.Model; namespace AWSSDK_DotNet.UnitTests.EC2 { - [TestClass] public class PasswordTest { // Test an issue with certain combination of private key and encrypted passwords that were causing a encoding issue while decrypting the password. - [TestMethod] - [TestCategory("UnitTest")] - [TestCategory("EC2")] + [Fact] + [Trait("UnitTest", "EC2")] public void TestMissingLeadingZeroIssue() { string encryptedPassword = "Oxaop1Qz5TWS3U4J82qZSVX9WHrA7zaheUugP/Fsa2iq/9XjEPzAWRcnYCZ4icBeS/az/adyOb3b5nLYVMcr2yFANnEYNPWTtypISbuXfrBdqalG6+E45T/yu+Ti3iJo3zaMXvtcR3qQwQ2bFdt8Xo7W9wXwwTjisQbUKe7dHMfjYa/c6knEz+nVj4qyOG5QaLGhkbH7XBnekd/xpatuH4wtgfdvcOlYWeBnxWCmFigaKdhkEXmZavIU05sV5CIvsgiW79LorLpeat3i+pyrJ/x7349f6SyFSS2uOnbDei1nr1JiO4erkJjN6py6RxSsKmNzBCUo8q0+EXTVg5g6SA=="; @@ -20,7 +18,7 @@ public void TestMissingLeadingZeroIssue() GetPasswordDataResponse response = new GetPasswordDataResponse { PasswordData = encryptedPassword }; string decryptedPassword = response.GetDecryptedPassword(privateKey); - Assert.IsNotNull(decryptedPassword); + Assert.NotNull(decryptedPassword); } } } diff --git a/generator/ServiceModels/_manifest.json b/generator/ServiceModels/_manifest.json index 2c74d47b9bec..be5112a4f6be 100644 --- a/generator/ServiceModels/_manifest.json +++ b/generator/ServiceModels/_manifest.json @@ -61,7 +61,6 @@ "Custom\\Runtime\\EventStreams\\test_vectors\\*", "Custom\\Runtime\\TestEndpoints\\*.json", "Custom\\TestTools\\ComparerTest.json", - "..\\Services\\CloudFront\\UnitTests\\Custom\\EmbeddedResource\\sample.rsa.private.key.txt" ], "packageReferences": [ { diff --git a/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Asn1Encodable.cs b/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Asn1Encodable.cs deleted file mode 100644 index 7ab617aaf4df..000000000000 --- a/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Asn1Encodable.cs +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2000 - 2011 The Legion Of The Bouncy Castle (http://www.bouncycastle.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the "Software"), to deal in the - * Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies - * or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - */ -using System.IO; - -namespace ThirdParty.BouncyCastle.Asn1 -{ - public abstract class Asn1Encodable - { - public abstract Asn1Object ToAsn1Object(); - } -} diff --git a/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Asn1EncodableVector.cs b/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Asn1EncodableVector.cs deleted file mode 100644 index 7e7656056335..000000000000 --- a/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Asn1EncodableVector.cs +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2000 - 2011 The Legion Of The Bouncy Castle (http://www.bouncycastle.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the "Software"), to deal in the - * Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies - * or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - */ -using System; -using System.Collections; - -using ThirdParty.BouncyCastle.Utilities; - -namespace ThirdParty.BouncyCastle.Asn1 -{ - public class Asn1EncodableVector - : IEnumerable - { - private IList v = Platform.CreateArrayList(); - - public static Asn1EncodableVector FromEnumerable( - IEnumerable e) - { - Asn1EncodableVector v = new Asn1EncodableVector(); - foreach (Asn1Encodable obj in e) - { - v.Add(obj); - } - return v; - } - - public Asn1EncodableVector( - params Asn1Encodable[] v) - { - Add(v); - } - - public void Add( - params Asn1Encodable[] objs) - { - foreach (Asn1Encodable obj in objs) - { - v.Add(obj); - } - } - - public void AddOptional( - params Asn1Encodable[] objs) - { - if (objs != null) - { - foreach (Asn1Encodable obj in objs) - { - if (obj != null) - { - v.Add(obj); - } - } - } - } - - public Asn1Encodable this[ - int index] - { - get { return (Asn1Encodable) v[index]; } - } - - [Obsolete("Use 'object[index]' syntax instead")] - public Asn1Encodable Get( - int index) - { - return this[index]; - } - - [Obsolete("Use 'Count' property instead")] - public int Size - { - get { return v.Count; } - } - - public int Count - { - get { return v.Count; } - } - - public IEnumerator GetEnumerator() - { - return v.GetEnumerator(); - } - } -} diff --git a/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Asn1InputStream.cs b/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Asn1InputStream.cs deleted file mode 100644 index b9c23022ddbf..000000000000 --- a/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Asn1InputStream.cs +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (c) 2000 - 2011 The Legion Of The Bouncy Castle (http://www.bouncycastle.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the "Software"), to deal in the - * Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies - * or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - */ -using System; -using System.Diagnostics; -using System.IO; - -using ThirdParty.BouncyCastle.Asn1.Utilities; -using ThirdParty.BouncyCastle.Utilities.IO; - -namespace ThirdParty.BouncyCastle.Asn1 -{ - /** - * a general purpose ASN.1 decoder - note: this class differs from the - * others in that it returns null after it has read the last object in - * the stream. If an ASN.1 Null is encountered a Der/BER Null object is - * returned. - */ - public class Asn1InputStream - : FilterStream - { - public const int Constructed = 0x20; - public const int Integer = 0x02; - - private readonly int limit; - - internal static int FindLimit(Stream input) - { - if (input is MemoryStream) - { - MemoryStream mem = (MemoryStream)input; - return (int)(mem.Length - mem.Position); - } - - return int.MaxValue; - } - - public Asn1InputStream( - Stream inputStream) - : this(inputStream, FindLimit(inputStream)) - { - } - - /** - * Create an ASN1InputStream where no DER object will be longer than limit. - * - * @param input stream containing ASN.1 encoded data. - * @param limit maximum size of a DER encoded object. - */ - public Asn1InputStream( - Stream inputStream, - int limit) - : base(inputStream) - { - this.limit = limit; - } - - /** - * Create an ASN1InputStream based on the input byte array. The length of DER objects in - * the stream is automatically limited to the length of the input array. - * - * @param input array containing ASN.1 encoded data. - */ - public Asn1InputStream( - byte[] input) - : this(new MemoryStream(input, false), input.Length) - { - } - - /** - * build an object given its tag and the number of bytes to construct it from. - */ - private Asn1Object BuildObject( - int tag, - int tagNo, - int length) - { - bool isConstructed = (tag & Constructed) != 0; - - if (isConstructed) - { - return CreateDerSequence(this); - } - else - { - byte[] bytes = new byte[length]; - this.Read(bytes, 0, bytes.Length); - return CreatePrimitiveDerObject(tagNo, bytes); - } - } - - internal Asn1EncodableVector BuildEncodableVector() - { - Asn1EncodableVector v = new Asn1EncodableVector(); - - Asn1Object o; - while ((o = ReadObject()) != null) - { - v.Add(o); - } - - return v; - } - - internal virtual Asn1EncodableVector BuildDerEncodableVector( - Stream dIn) - { - return new Asn1InputStream(dIn).BuildEncodableVector(); - } - - internal virtual DerSequence CreateDerSequence( - Stream dIn) - { - return DerSequence.FromVector(BuildDerEncodableVector(dIn)); - } - - - public Asn1Object ReadObject() - { - int tag = ReadByte(); - if (tag <= 0) - { - if (tag == 0) - throw new IOException("unexpected end-of-contents marker"); - - return null; - } - - // - // calculate tag number - // - int tagNo = ReadTagNumber(this, tag); - - bool isConstructed = (tag & Constructed) != 0; - - // - // calculate length - // - int length = ReadLength(this, limit); - - - try - { - return BuildObject(tag, tagNo, length); - } - catch (ArgumentException e) - { - throw new Exception("corrupted stream detected", e); - } - } - - internal static int ReadTagNumber( - Stream s, - int tag) - { - int tagNo = tag & 0x1f; - - // - // with tagged object tag number is bottom 5 bits, or stored at the start of the content - // - if (tagNo == 0x1f) - { - tagNo = 0; - - int b = s.ReadByte(); - - // X.690-0207 8.1.2.4.2 - // "c) bits 7 to 1 of the first subsequent octet shall not all be zero." - if ((b & 0x7f) == 0) // Note: -1 will pass - { - throw new IOException("Corrupted stream - invalid high tag number found"); - } - - while ((b >= 0) && ((b & 0x80) != 0)) - { - tagNo |= (b & 0x7f); - tagNo <<= 7; - b = s.ReadByte(); - } - - if (b < 0) - throw new EndOfStreamException("EOF found inside tag value."); - - tagNo |= (b & 0x7f); - } - - return tagNo; - } - - internal static int ReadLength( - Stream s, - int limit) - { - int length = s.ReadByte(); - if (length < 0) - throw new EndOfStreamException("EOF found when length expected"); - - if (length == 0x80) - return -1; // indefinite-length encoding - - if (length > 127) - { - int size = length & 0x7f; - - // Note: The invalid long form "0xff" (see X.690 8.1.3.5c) will be caught here - if (size > 4) - throw new IOException("DER length more than 4 bytes: " + size); - - length = 0; - for (int i = 0; i < size; i++) - { - int next = s.ReadByte(); - - if (next < 0) - throw new EndOfStreamException("EOF found reading length"); - - length = (length << 8) + next; - } - - if (length < 0) - throw new IOException("Corrupted stream - negative length found"); - - if (length >= limit) // after all we must have read at least 1 byte - throw new IOException("Corrupted stream - out of bounds length found"); - } - - return length; - } - - internal static Asn1Object CreatePrimitiveDerObject( - int tagNo, - byte[] bytes) - { - - switch (tagNo) - { - case Integer: - return new DerInteger(bytes); - default: - throw new Exception("Unknown primitive tag"); - } - } - } -} diff --git a/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Asn1Object.cs b/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Asn1Object.cs deleted file mode 100644 index 5639cc8b2d5d..000000000000 --- a/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Asn1Object.cs +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2000 - 2011 The Legion Of The Bouncy Castle (http://www.bouncycastle.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the "Software"), to deal in the - * Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies - * or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - */ -using System; -using System.IO; - -namespace ThirdParty.BouncyCastle.Asn1 -{ - public abstract class Asn1Object - : Asn1Encodable - { - /// Create a base ASN.1 object from a byte array. - /// The byte array to parse. - /// The base ASN.1 object represented by the byte array. - /// If there is a problem parsing the data. - public static Asn1Object FromByteArray( - byte[] data) - { - try - { - return new Asn1InputStream(data).ReadObject(); - } - catch (InvalidCastException) - { - throw new IOException("cannot recognise object in stream"); - } - } - - /// Read a base ASN.1 object from a stream. - /// The stream to parse. - /// The base ASN.1 object represented by the byte array. - /// If there is a problem parsing the data. - public static Asn1Object FromStream( - Stream inStr) - { - try - { - return new Asn1InputStream(inStr).ReadObject(); - } - catch (InvalidCastException) - { - throw new IOException("cannot recognise object in stream"); - } - } - - public sealed override Asn1Object ToAsn1Object() - { - return this; - } - - } -} diff --git a/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Asn1Sequence.cs b/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Asn1Sequence.cs deleted file mode 100644 index e80a45e59040..000000000000 --- a/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Asn1Sequence.cs +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2000 - 2011 The Legion Of The Bouncy Castle (http://www.bouncycastle.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the "Software"), to deal in the - * Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies - * or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - */ -using System; -using System.Collections; -using System.IO; - -using ThirdParty.BouncyCastle.Utilities; - -namespace ThirdParty.BouncyCastle.Asn1 -{ - public abstract class Asn1Sequence - : Asn1Object, IEnumerable - { - private readonly IList seq; - - - - - protected internal Asn1Sequence( - int capacity) - { - seq = Platform.CreateArrayList(capacity); - } - - public virtual IEnumerator GetEnumerator() - { - return seq.GetEnumerator(); - } - - [Obsolete("Use GetEnumerator() instead")] - public IEnumerator GetObjects() - { - return GetEnumerator(); - } - - - - /** - * return the object at the sequence position indicated by index. - * - * @param index the sequence number (starting at zero) of the object - * @return the object at the sequence position indicated by index. - */ - public virtual Asn1Encodable this[int index] - { - get { return (Asn1Encodable) seq[index]; } - } - - [Obsolete("Use 'object[index]' syntax instead")] - public Asn1Encodable GetObjectAt( - int index) - { - return this[index]; - } - - [Obsolete("Use 'Count' property instead")] - public int Size - { - get { return Count; } - } - - public virtual int Count - { - get { return seq.Count; } - } - - - private Asn1Encodable GetCurrent(IEnumerator e) - { - Asn1Encodable encObj = (Asn1Encodable)e.Current; - return encObj; - } - - protected internal void AddObject( - Asn1Encodable obj) - { - seq.Add(obj); - } - } -} diff --git a/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/DerInteger.cs b/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/DerInteger.cs deleted file mode 100644 index 09c4c2d00fbd..000000000000 --- a/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/DerInteger.cs +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2000 - 2011 The Legion Of The Bouncy Castle (http://www.bouncycastle.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the "Software"), to deal in the - * Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies - * or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - */ -using System; - -using ThirdParty.BouncyCastle.Math; -using ThirdParty.BouncyCastle.Utilities; - -namespace ThirdParty.BouncyCastle.Asn1 -{ - public class DerInteger - : Asn1Object - { - private readonly byte[] bytes; - - - public DerInteger( - int value) - { - bytes = BigInteger.ValueOf(value).ToByteArray(); - } - - public DerInteger( - BigInteger value) - { - if (value == null) - throw new ArgumentNullException("value"); - - bytes = value.ToByteArray(); - } - - public DerInteger( - byte[] bytes) - { - this.bytes = bytes; - } - - public byte[] Bytes - { - get { return this.bytes; } - } - - public BigInteger Value - { - get { return new BigInteger(bytes); } - } - - public override string ToString() - { - return Value.ToString(); - } - } -} diff --git a/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/DerSequence.cs b/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/DerSequence.cs deleted file mode 100644 index e474104147b2..000000000000 --- a/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/DerSequence.cs +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2000 - 2011 The Legion Of The Bouncy Castle (http://www.bouncycastle.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the "Software"), to deal in the - * Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies - * or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - */ -using System.Collections; -using System.IO; - -namespace ThirdParty.BouncyCastle.Asn1 -{ - public class DerSequence - : Asn1Sequence - { - public static readonly DerSequence Empty = new DerSequence(); - - public static DerSequence FromVector( - Asn1EncodableVector v) - { - return v.Count < 1 ? Empty : new DerSequence(v); - } - - /** - * create an empty sequence - */ - public DerSequence() - : base(0) - { - } - - /** - * create a sequence containing one object - */ - public DerSequence( - Asn1Encodable obj) - : base(1) - { - AddObject(obj); - } - - public DerSequence( - params Asn1Encodable[] v) - : base(v.Length) - { - foreach (Asn1Encodable ae in v) - { - AddObject(ae); - } - } - - /** - * create a sequence containing a vector of objects. - */ - public DerSequence( - Asn1EncodableVector v) - : base(v.Count) - { - foreach (Asn1Encodable ae in v) - { - AddObject(ae); - } - } - } -} diff --git a/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Utilities/FilterStream.cs b/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Utilities/FilterStream.cs deleted file mode 100644 index 4a31ed167d0c..000000000000 --- a/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Utilities/FilterStream.cs +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2000 - 2011 The Legion Of The Bouncy Castle (http://www.bouncycastle.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the "Software"), to deal in the - * Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies - * or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - */ -using System; -using System.IO; - -namespace ThirdParty.BouncyCastle.Asn1.Utilities -{ - public class FilterStream : Stream - { - public FilterStream(Stream s) - { - this.s = s; - } - public override bool CanRead - { - get { return s.CanRead; } - } - public override bool CanSeek - { - get { return s.CanSeek; } - } - public override bool CanWrite - { - get { return s.CanWrite; } - } - public override long Length - { - get { return s.Length; } - } - public override long Position - { - get { return s.Position; } - set { s.Position = value; } - } - public override void Close() - { - s.Close(); - } - public override void Flush() - { - s.Flush(); - } - public override long Seek(long offset, SeekOrigin origin) - { - return s.Seek(offset, origin); - } - public override void SetLength(long value) - { - s.SetLength(value); - } - public override int Read(byte[] buffer, int offset, int count) - { - return s.Read(buffer, offset, count); - } - public override int ReadByte() - { - return s.ReadByte(); - } - public override void Write(byte[] buffer, int offset, int count) - { - s.Write(buffer, offset, count); - } - public override void WriteByte(byte value) - { - s.WriteByte(value); - } - protected readonly Stream s; - } -} diff --git a/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Utilities/Platform.cs b/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Utilities/Platform.cs deleted file mode 100644 index 3ab69cbfa835..000000000000 --- a/sdk/src/Core/ThirdParty/BouncyCastle/Asn1/Utilities/Platform.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Collections.Generic; - -namespace ThirdParty.BouncyCastle.Utilities -{ - internal abstract class Platform - { - internal static System.Collections.IList CreateArrayList() - { - return new List(); - } - internal static System.Collections.IList CreateArrayList(int capacity) - { - return new List(capacity); - } - internal static System.Collections.IList CreateArrayList(System.Collections.ICollection collection) - { - System.Collections.IList result = new List(collection.Count); - foreach (object o in collection) - { - result.Add(o); - } - return result; - } - internal static System.Collections.IList CreateArrayList(System.Collections.IEnumerable collection) - { - System.Collections.IList result = new List(); - foreach (object o in collection) - { - result.Add(o); - } - return result; - } - } -} \ No newline at end of file diff --git a/sdk/src/Core/ThirdParty/BouncyCastle/Math/BigInteger.cs b/sdk/src/Core/ThirdParty/BouncyCastle/Math/BigInteger.cs deleted file mode 100644 index b1de01cbe622..000000000000 --- a/sdk/src/Core/ThirdParty/BouncyCastle/Math/BigInteger.cs +++ /dev/null @@ -1,695 +0,0 @@ -/* - * Copyright (c) 2000 - 2011 The Legion Of The Bouncy Castle (http://www.bouncycastle.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the "Software"), to deal in the - * Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies - * or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - */ -using System; -using System.Collections; -using System.Diagnostics; -using System.Globalization; -using System.Text; - -using ThirdParty.BouncyCastle.Utilities; - -namespace ThirdParty.BouncyCastle.Math -{ - - public class BigInteger - { - private const long IMASK = 0xffffffffL; - - private static readonly int[] ZeroMagnitude = new int[0]; - private static readonly byte[] ZeroEncoding = new byte[0]; - - public static readonly BigInteger Zero = new BigInteger(0, ZeroMagnitude, false); - public static readonly BigInteger One = createUValueOf(1); - public static readonly BigInteger Two = createUValueOf(2); - public static readonly BigInteger Three = createUValueOf(3); - public static readonly BigInteger Ten = createUValueOf(10); - - private static readonly Random RandomSource = new Random(); - - private const int BitsPerByte = 8; - private const int BitsPerInt = 32; - private const int BytesPerInt = 4; - - - private int sign; // -1 means -ve; +1 means +ve; 0 means 0; - private int[] magnitude; // array of ints with [0] being the most significant - private int nBitLength = -1; // cache calcBitLength() value - - private static int GetByteLength( - int nBits) - { - return (nBits + BitsPerByte - 1) / BitsPerByte; - } - - private BigInteger() - { - } - - private BigInteger( - int signum, - int[] mag, - bool checkMag) - { - if (checkMag) - { - int i = 0; - while (i < mag.Length && mag[i] == 0) - { - ++i; - } - - if (i == mag.Length) - { -// this.sign = 0; - this.magnitude = ZeroMagnitude; - } - else - { - this.sign = signum; - - if (i == 0) - { - this.magnitude = mag; - } - else - { - // strip leading 0 words - this.magnitude = new int[mag.Length - i]; - Array.Copy(mag, i, this.magnitude, 0, this.magnitude.Length); - } - } - } - else - { - this.sign = signum; - this.magnitude = mag; - } - } - - public BigInteger( - byte[] bytes) - : this(bytes, 0, bytes.Length) - { - } - - public BigInteger( - byte[] bytes, - int offset, - int length) - { - if (length == 0) - throw new FormatException("Zero length BigInteger"); - - // TODO Move this processing into MakeMagnitude (provide sign argument) - if ((sbyte)bytes[offset] < 0) - { - this.sign = -1; - - int end = offset + length; - - int iBval; - // strip leading sign bytes - for (iBval = offset; iBval < end && ((sbyte)bytes[iBval] == -1); iBval++) - { - } - - if (iBval >= end) - { - this.magnitude = One.magnitude; - } - else - { - int numBytes = end - iBval; - byte[] inverse = new byte[numBytes]; - - int index = 0; - while (index < numBytes) - { - inverse[index++] = (byte)~bytes[iBval++]; - } - - while (inverse[--index] == byte.MaxValue) - { - inverse[index] = byte.MinValue; - } - - inverse[index]++; - - this.magnitude = MakeMagnitude(inverse, 0, inverse.Length); - } - } - else - { - // strip leading zero bytes and return magnitude bytes - this.magnitude = MakeMagnitude(bytes, offset, length); - this.sign = this.magnitude.Length > 0 ? 1 : 0; - } - } - - private static int[] MakeMagnitude( - byte[] bytes, - int offset, - int length) - { - int end = offset + length; - - // strip leading zeros - int firstSignificant; - for (firstSignificant = offset; firstSignificant < end - && bytes[firstSignificant] == 0; firstSignificant++) - { - } - - if (firstSignificant >= end) - { - return ZeroMagnitude; - } - - int nInts = (end - firstSignificant + 3) / BytesPerInt; - int bCount = (end - firstSignificant) % BytesPerInt; - if (bCount == 0) - { - bCount = BytesPerInt; - } - - if (nInts < 1) - { - return ZeroMagnitude; - } - - int[] mag = new int[nInts]; - - int v = 0; - int magnitudeIndex = 0; - for (int i = firstSignificant; i < end; ++i) - { - v <<= 8; - v |= bytes[i] & 0xff; - bCount--; - if (bCount <= 0) - { - mag[magnitudeIndex] = v; - magnitudeIndex++; - bCount = BytesPerInt; - v = 0; - } - } - - if (magnitudeIndex < mag.Length) - { - mag[magnitudeIndex] = v; - } - - return mag; - } - - private static readonly byte[] rndMask = { 255, 127, 63, 31, 15, 7, 3, 1 }; - - - - /** - * return a = a + b - b preserved. - */ - private static int[] AddMagnitudes( - int[] a, - int[] b) - { - int tI = a.Length - 1; - int vI = b.Length - 1; - long m = 0; - - while (vI >= 0) - { - m += ((long)(uint)a[tI] + (long)(uint)b[vI--]); - a[tI--] = (int)m; - m = (long)((ulong)m >> 32); - } - - if (m != 0) - { - while (tI >= 0 && ++a[tI--] == 0) - { - } - } - - return a; - } - - - - private BigInteger AddToMagnitude( - int[] magToAdd) - { - int[] big, small; - if (this.magnitude.Length < magToAdd.Length) - { - big = magToAdd; - small = this.magnitude; - } - else - { - big = this.magnitude; - small = magToAdd; - } - - // Conservatively avoid over-allocation when no overflow possible - uint limit = uint.MaxValue; - if (big.Length == small.Length) - limit -= (uint) small[0]; - - bool possibleOverflow = (uint) big[0] >= limit; - - int[] bigCopy; - if (possibleOverflow) - { - bigCopy = new int[big.Length + 1]; - big.CopyTo(bigCopy, 1); - } - else - { - bigCopy = (int[]) big.Clone(); - } - - bigCopy = AddMagnitudes(bigCopy, small); - - return new BigInteger(this.sign, bigCopy, possibleOverflow); - } - - private int calcBitLength( - int indx, - int[] mag) - { - for (;;) - { - if (indx >= mag.Length) - return 0; - - if (mag[indx] != 0) - break; - - ++indx; - } - - // bit length for everything after the first int - int bitLength = 32 * ((mag.Length - indx) - 1); - - // and determine bitlength of first int - int firstMag = mag[indx]; - bitLength += BitLen(firstMag); - - // Check for negative powers of two - if (sign < 0 && ((firstMag & -firstMag) == firstMag)) - { - do - { - if (++indx >= mag.Length) - { - --bitLength; - break; - } - } - while (mag[indx] == 0); - } - - return bitLength; - } - - public int BitLength - { - get - { - if (nBitLength == -1) - { - nBitLength = sign == 0 - ? 0 - : calcBitLength(0, magnitude); - } - - return nBitLength; - } - } - - // - // BitLen(value) is the number of bits in value. - // - private static int BitLen( - int w) - { - // Binary search - decision tree (5 tests, rarely 6) - return (w < 1 << 15 ? (w < 1 << 7 - ? (w < 1 << 3 ? (w < 1 << 1 - ? (w < 1 << 0 ? (w < 0 ? 32 : 0) : 1) - : (w < 1 << 2 ? 2 : 3)) : (w < 1 << 5 - ? (w < 1 << 4 ? 4 : 5) - : (w < 1 << 6 ? 6 : 7))) - : (w < 1 << 11 - ? (w < 1 << 9 ? (w < 1 << 8 ? 8 : 9) : (w < 1 << 10 ? 10 : 11)) - : (w < 1 << 13 ? (w < 1 << 12 ? 12 : 13) : (w < 1 << 14 ? 14 : 15)))) : (w < 1 << 23 ? (w < 1 << 19 - ? (w < 1 << 17 ? (w < 1 << 16 ? 16 : 17) : (w < 1 << 18 ? 18 : 19)) - : (w < 1 << 21 ? (w < 1 << 20 ? 20 : 21) : (w < 1 << 22 ? 22 : 23))) : (w < 1 << 27 - ? (w < 1 << 25 ? (w < 1 << 24 ? 24 : 25) : (w < 1 << 26 ? 26 : 27)) - : (w < 1 << 29 ? (w < 1 << 28 ? 28 : 29) : (w < 1 << 30 ? 30 : 31))))); - } - - public int CompareTo( - object obj) - { - return CompareTo((BigInteger)obj); - } - - /** - * unsigned comparison on two arrays - note the arrays may - * start with leading zeros. - */ - private static int CompareTo( - int xIndx, - int[] x, - int yIndx, - int[] y) - { - while (xIndx != x.Length && x[xIndx] == 0) - { - xIndx++; - } - - while (yIndx != y.Length && y[yIndx] == 0) - { - yIndx++; - } - - return CompareNoLeadingZeroes(xIndx, x, yIndx, y); - } - - private static int CompareNoLeadingZeroes( - int xIndx, - int[] x, - int yIndx, - int[] y) - { - int diff = (x.Length - y.Length) - (xIndx - yIndx); - - if (diff != 0) - { - return diff < 0 ? -1 : 1; - } - - // lengths of magnitudes the same, test the magnitude values - - while (xIndx < x.Length) - { - uint v1 = (uint)x[xIndx++]; - uint v2 = (uint)y[yIndx++]; - - if (v1 != v2) - return v1 < v2 ? -1 : 1; - } - - return 0; - } - - public int CompareTo( - BigInteger value) - { - return sign < value.sign ? -1 - : sign > value.sign ? 1 - : sign == 0 ? 0 - : sign * CompareNoLeadingZeroes(0, magnitude, 0, value.magnitude); - } - - - - public override bool Equals( - object obj) - { - if (obj == this) - return true; - - BigInteger biggie = obj as BigInteger; - if (biggie == null) - return false; - - if (biggie.sign != sign || biggie.magnitude.Length != magnitude.Length) - return false; - - for (int i = 0; i < magnitude.Length; i++) - { - if (biggie.magnitude[i] != magnitude[i]) - { - return false; - } - } - - return true; - } - - public override int GetHashCode() - { - int hc = magnitude.Length; - if (magnitude.Length > 0) - { - hc ^= magnitude[0]; - - if (magnitude.Length > 1) - { - hc ^= magnitude[magnitude.Length - 1]; - } - } - - return sign < 0 ? ~hc : hc; - } - - // TODO Make public? - private BigInteger Inc() - { - if (this.sign == 0) - return One; - - if (this.sign < 0) - return new BigInteger(-1, doSubBigLil(this.magnitude, One.magnitude), true); - - return AddToMagnitude(One.magnitude); - } - - - public BigInteger Negate() - { - if (sign == 0) - return this; - - return new BigInteger(-sign, magnitude, false); - } - - public BigInteger Not() - { - return Inc().Negate(); - } - - - /** - * returns x = x - y - we assume x is >= y - */ - private static int[] Subtract( - int xStart, - int[] x, - int yStart, - int[] y) - { - int iT = x.Length; - int iV = y.Length; - long m; - int borrow = 0; - - do - { - m = (x[--iT] & IMASK) - (y[--iV] & IMASK) + borrow; - x[iT] = (int) m; - -// borrow = (m < 0) ? -1 : 0; - borrow = (int)(m >> 63); - } - while (iV > yStart); - - if (borrow != 0) - { - while (--x[--iT] == -1) - { - } - } - - return x; - } - - private static int[] doSubBigLil( - int[] bigMag, - int[] lilMag) - { - int[] res = (int[]) bigMag.Clone(); - - return Subtract(0, res, 0, lilMag); - } - - public byte[] ToByteArray() - { - return ToByteArray(false); - } - - public byte[] ToByteArrayUnsigned() - { - return ToByteArray(true); - } - - private byte[] ToByteArray( - bool unsigned) - { - unchecked { - - if (sign == 0) - return unsigned ? ZeroEncoding : new byte[1]; - - int nBits = (unsigned && sign > 0) - ? BitLength - : BitLength + 1; - - int nBytes = GetByteLength(nBits); - byte[] bytes = new byte[nBytes]; - - int magIndex = magnitude.Length; - int bytesIndex = bytes.Length; - - if (sign > 0) - { - while (magIndex > 1) - { - uint mag = (uint) magnitude[--magIndex]; - bytes[--bytesIndex] = (byte) mag; - bytes[--bytesIndex] = (byte)(mag >> 8); - bytes[--bytesIndex] = (byte)(mag >> 16); - bytes[--bytesIndex] = (byte)(mag >> 24); - } - - uint lastMag = (uint) magnitude[0]; - while (lastMag > byte.MaxValue) - { - bytes[--bytesIndex] = (byte) lastMag; - lastMag >>= 8; - } - - bytes[--bytesIndex] = (byte) lastMag; - } - else // sign < 0 - { - bool carry = true; - - while (magIndex > 1) - { - uint mag = ~((uint) magnitude[--magIndex]); - - if (carry) - { - carry = (++mag == uint.MinValue); - } - - bytes[--bytesIndex] = (byte) mag; - bytes[--bytesIndex] = (byte)(mag >> 8); - bytes[--bytesIndex] = (byte)(mag >> 16); - bytes[--bytesIndex] = (byte)(mag >> 24); - } - - uint lastMag = (uint) magnitude[0]; - - if (carry) - { - // Never wraps because magnitude[0] != 0 - --lastMag; - } - - while (lastMag > byte.MaxValue) - { - bytes[--bytesIndex] = (byte) ~lastMag; - lastMag >>= 8; - } - - bytes[--bytesIndex] = (byte) ~lastMag; - - if (bytesIndex > 0) - { - bytes[--bytesIndex] = byte.MaxValue; - } - } - - return bytes; - } - } - - private static BigInteger createUValueOf( - ulong value) - { - int msw = (int)(value >> 32); - int lsw = (int)value; - - if (msw != 0) - return new BigInteger(1, new int[] { msw, lsw }, false); - - if (lsw != 0) - { - BigInteger n = new BigInteger(1, new int[] { lsw }, false); - return n; - } - - return Zero; - } - - private static BigInteger createValueOf( - long value) - { - if (value < 0) - { - if (value == long.MinValue) - return createValueOf(~value).Not(); - - return createValueOf(-value).Negate(); - } - - return createUValueOf((ulong)value); - } - - public static BigInteger ValueOf( - long value) - { - switch (value) - { - case 0: - return Zero; - case 1: - return One; - case 2: - return Two; - case 3: - return Three; - case 10: - return Ten; - } - - return createValueOf(value); - } - } -} diff --git a/sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/PEMReader.cs b/sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/PEMReader.cs deleted file mode 100644 index 76ae5d495d68..000000000000 --- a/sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/PEMReader.cs +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2000 - 2011 The Legion Of The Bouncy Castle (http://www.bouncycastle.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the "Software"), to deal in the - * Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies - * or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - */ -using System; -using System.Collections; -using System.Diagnostics; -using System.IO; -using System.Text; -using System.Security.Cryptography; - -using ThirdParty.BouncyCastle.Asn1; -using ThirdParty.BouncyCastle.Utilities; -using ThirdParty.BouncyCastle.Utilities.IO.Pem; - -namespace ThirdParty.BouncyCastle.OpenSsl -{ - - public class PemReader - : ThirdParty.BouncyCastle.Utilities.IO.Pem.PemReader - { - - public PemReader( - TextReader reader) - : base(reader) - { - } - - public RSAParameters ReadPrivatekey() - { - PemObject pemObject = ReadPemObject(); - - string type = pemObject.Type.Substring(0, pemObject.Type.Length - "PRIVATE KEY".Length).Trim(); - byte[] keyBytes = pemObject.Content; - Asn1Sequence seq = (Asn1Sequence)Asn1Object.FromByteArray(keyBytes); - - if (seq.Count != 9) - throw new Exception("malformed sequence in RSA private key"); - - return convertSequenceToRSAParameters(seq); - } - - RSAParameters convertSequenceToRSAParameters(Asn1Sequence seq) - { - var rsaParams = new RSAParameters(); - - var modules = ((DerInteger)seq[1]).Value.ToByteArrayUnsigned(); - var alignmentValue = GetAlignmentValue(modules); - - rsaParams.Modulus = FixAlignment(modules, alignmentValue); - rsaParams.Exponent = ((DerInteger)seq[2]).Value.ToByteArrayUnsigned(); - rsaParams.D = FixAlignment(((DerInteger)seq[3]).Value.ToByteArrayUnsigned(), alignmentValue); - rsaParams.P = FixAlignment(((DerInteger)seq[4]).Value.ToByteArrayUnsigned(), alignmentValue / 2); - rsaParams.Q = FixAlignment(((DerInteger)seq[5]).Value.ToByteArrayUnsigned(), alignmentValue / 2); - rsaParams.DP = FixAlignment(((DerInteger)seq[6]).Value.ToByteArrayUnsigned(), alignmentValue / 2); - rsaParams.DQ = FixAlignment(((DerInteger)seq[7]).Value.ToByteArrayUnsigned(), alignmentValue / 2); - rsaParams.InverseQ = FixAlignment(((DerInteger)seq[8]).Value.ToByteArrayUnsigned(), alignmentValue / 2); - - return rsaParams; - } - - private int GetAlignmentValue(Byte[] modules) - { - int bits = modules.Length * 8; - double logbase = System.Math.Log(bits, 2); - if (logbase != (int)logbase) - { - bits = (int)(logbase + 1.0); - bits = (int)(System.Math.Pow(2, bits)); - } - - return bits / 8; - } - - public static byte[] FixAlignment(byte[] inputBytes, int alignment) - { - if (inputBytes.Length == alignment) - return inputBytes; - - byte[] buf = new byte[alignment]; - - System.Array.Copy(inputBytes, 0, buf, alignment - inputBytes.Length, inputBytes.Length); - - return buf; - } - } -} diff --git a/sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemGenerationException.cs b/sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemGenerationException.cs deleted file mode 100644 index 710c2eed0d88..000000000000 --- a/sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemGenerationException.cs +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2000 - 2011 The Legion Of The Bouncy Castle (http://www.bouncycastle.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the "Software"), to deal in the - * Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies - * or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - */ -using System; - -namespace ThirdParty.BouncyCastle.Utilities.IO.Pem -{ -#if !NETSTANDARD - [Serializable] -#endif - public class PemGenerationException - : Exception - { - public PemGenerationException() - : base() - { - } - - public PemGenerationException( - string message) - : base(message) - { - } - - public PemGenerationException( - string message, - Exception exception) - : base(message, exception) - { - } - } -} diff --git a/sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemHeader.cs b/sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemHeader.cs deleted file mode 100644 index f658fd26a105..000000000000 --- a/sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemHeader.cs +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2000 - 2011 The Legion Of The Bouncy Castle (http://www.bouncycastle.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the "Software"), to deal in the - * Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies - * or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - */ -using System; - -namespace ThirdParty.BouncyCastle.Utilities.IO.Pem -{ - public class PemHeader - { - private string name; - private string val; - - public PemHeader(string name, string val) - { - this.name = name; - this.val = val; - } - - public virtual string Name - { - get { return name; } - } - - public virtual string Value - { - get { return val; } - } - - public override int GetHashCode() - { - return GetHashCode(this.name) + 31 * GetHashCode(this.val); - } - - public override bool Equals(object obj) - { - if (obj == this) - return true; - - if (!(obj is PemHeader)) - return false; - - PemHeader other = (PemHeader)obj; - - return string.Equals(this.name, other.name) - && string.Equals(this.val, other.val); - } - - private int GetHashCode(string s) - { - if (s == null) - { - return 1; - } - - return s.GetHashCode(); - } - } -} diff --git a/sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemObject.cs b/sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemObject.cs deleted file mode 100644 index 8d5b095d73b3..000000000000 --- a/sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemObject.cs +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2000 - 2011 The Legion Of The Bouncy Castle (http://www.bouncycastle.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the "Software"), to deal in the - * Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies - * or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - */ -using System; -using System.Collections; - - - -namespace ThirdParty.BouncyCastle.Utilities.IO.Pem -{ - public class PemObject - : PemObjectGenerator - { - private string type; - private IList headers; - private byte[] content; - - public PemObject(string type, byte[] content) - : this(type, Platform.CreateArrayList(), content) - { - } - - public PemObject(String type, IList headers, byte[] content) - { - this.type = type; - this.headers = Platform.CreateArrayList(headers); - this.content = content; - } - - public string Type - { - get { return type; } - } - - public IList Headers - { - get { return headers; } - } - - public byte[] Content - { - get { return content; } - } - - public PemObject Generate() - { - return this; - } - } -} diff --git a/sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemObjectGenerator.cs b/sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemObjectGenerator.cs deleted file mode 100644 index 6adb46b191f7..000000000000 --- a/sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemObjectGenerator.cs +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2000 - 2011 The Legion Of The Bouncy Castle (http://www.bouncycastle.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the "Software"), to deal in the - * Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies - * or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - */ -using System; - -namespace ThirdParty.BouncyCastle.Utilities.IO.Pem -{ - public interface PemObjectGenerator - { - /// - /// A - /// - /// - PemObject Generate(); - } -} diff --git a/sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemObjectParser.cs b/sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemObjectParser.cs deleted file mode 100644 index 95a64c8714e3..000000000000 --- a/sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemObjectParser.cs +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2000 - 2011 The Legion Of The Bouncy Castle (http://www.bouncycastle.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the "Software"), to deal in the - * Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies - * or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - */ -using System; -using System.IO; - -namespace ThirdParty.BouncyCastle.Utilities.IO.Pem -{ - public interface PemObjectParser - { - /// - /// A - /// - /// - /// A - /// - /// - object ParseObject(PemObject obj); - } -} diff --git a/sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemReader.cs b/sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemReader.cs deleted file mode 100644 index 0f2c32b0d2fe..000000000000 --- a/sdk/src/Core/ThirdParty/BouncyCastle/OpenSsl/pem/PemReader.cs +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2000 - 2011 The Legion Of The Bouncy Castle (http://www.bouncycastle.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the "Software"), to deal in the - * Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies - * or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - */ -using System; -using System.Collections; -using System.IO; -using System.Text; - -namespace ThirdParty.BouncyCastle.Utilities.IO.Pem -{ - public class PemReader - { - private const string BeginString = "-----BEGIN "; - private const string EndString = "-----END "; - - private readonly TextReader reader; - - public PemReader(TextReader reader) - { - if (reader == null) - throw new ArgumentNullException("reader"); - - this.reader = reader; - } - - public TextReader Reader - { - get { return reader; } - } - - /// - /// A - /// - /// - public PemObject ReadPemObject() - { - string line = reader.ReadLine(); - - if (line != null && line.StartsWith(BeginString)) - { - line = line.Substring(BeginString.Length); - int index = line.IndexOf('-'); - string type = line.Substring(0, index); - - if (index > 0) - return LoadObject(type); - } - - return null; - } - - private PemObject LoadObject(string type) - { - string endMarker = EndString + type; - IList headers = Platform.CreateArrayList(); - StringBuilder buf = new StringBuilder(); - - string line; - while ((line = reader.ReadLine()) != null - && line.IndexOf(endMarker) == -1) - { - int colonPos = line.IndexOf(':'); - - if (colonPos == -1) - { - buf.Append(line.Trim()); - } - else - { - // Process field - string fieldName = line.Substring(0, colonPos).Trim(); - - if (fieldName.StartsWith("X-")) - fieldName = fieldName.Substring(2); - - string fieldValue = line.Substring(colonPos + 1).Trim(); - - headers.Add(new PemHeader(fieldName, fieldValue)); - } - } - - if (line == null) - { - throw new IOException(endMarker + " not found"); - } - - if (buf.Length % 4 != 0) - { - throw new IOException("base64 data appears to be truncated"); - } - - return new PemObject(type, headers, Convert.FromBase64String(buf.ToString())); - } - } -} diff --git a/sdk/src/Services/SimpleNotificationService/Custom/Util/Message.cs b/sdk/src/Services/SimpleNotificationService/Custom/Util/Message.cs index c861bc0d2692..069f523d63b2 100644 --- a/sdk/src/Services/SimpleNotificationService/Custom/Util/Message.cs +++ b/sdk/src/Services/SimpleNotificationService/Custom/Util/Message.cs @@ -15,8 +15,6 @@ using Amazon.Runtime.Internal.Util; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; -using ThirdParty.BouncyCastle.OpenSsl; - namespace Amazon.SimpleNotificationService.Util { @@ -286,6 +284,47 @@ private static string ValidateSignatureVersion(string signatureVersion) return signatureVersion; } + private byte[] ParsePemContent(string content) + { + const string beginString = "-----BEGIN "; + const string endString = "-----END "; + + var buffer = new StringBuilder(); + var lines = content.Split('\n'); + + if (!lines[0].StartsWith(beginString)) + { + throw new AmazonClientException("PEM file missing begin marker"); + } + + bool endMarkerFound = false; + for (var i = 1; i < lines.Length; i++) + { + if (lines[i].StartsWith(endString)) + { + endMarkerFound = true; + break; + } + + if (lines[i].IndexOf(':') == -1) + { + buffer.Append(lines[i].Trim()); + } + } + + if (!endMarkerFound) + { + throw new AmazonClientException("PEM file missing end marker"); + } + + if (buffer.Length % 4 != 0) + { + throw new IOException("The base64 data appears in PEM file is truncated"); + } + + return Convert.FromBase64String(buffer.ToString()); + } + #region Message Verification /// /// Verifies the authenticity of a message sent by Amazon SNS. This is done by computing a signature from the fields in the message and then comparing @@ -438,10 +477,10 @@ private X509Certificate2 GetX509Certificate() #endif using (var reader = new StreamReader(response.GetResponseStream())) { + var content = reader.ReadToEnd().Trim(); - var pemObject = new PemReader(new StringReader(content)).ReadPemObject(); - X509Certificate2 certificate = new X509Certificate2(pemObject.Content); + X509Certificate2 certificate = new X509Certificate2(ParsePemContent(content)); certificateCache[this.SigningCertURL] = certificate; return certificate; } diff --git a/sdk/test/NetStandard/UnitTests/Services/CloudFrontUnitTests.cs b/sdk/test/NetStandard/UnitTests/Services/CloudFrontUnitTests.cs deleted file mode 100644 index 57c76786dcf1..000000000000 --- a/sdk/test/NetStandard/UnitTests/Services/CloudFrontUnitTests.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.IO; -using Amazon.CloudFront; -using System; -using Xunit; -namespace AWSSDK_NetStandard.UnitTests -{ - public class CloudFrontTests - { - private static string privateRSAKeyResourceName = @"UnitTests.NetStandard.sample.rsa.private.key.txt"; - private static StreamReader privateRSAKeyStreamReader = null; - - public CloudFrontTests() - { - privateRSAKeyStreamReader = new StreamReader(Utils.GetAssemblyResourceStream(privateRSAKeyResourceName)); - } - - [Fact] - [Trait("Category", "CloudFront")] - public void SignURLValidation() - { - string expectedSignedURL = @"http://awesome.dot.com/amazing/uri/?Policy=U2VjcmV0UG9saWN5" - + @"&Signature=nmwKvD6cFoniNsMZeuxrzooEt73MtzS78g3u0Pym835Ty1cfV0sWK1sGnPpafaMw95kGNv7eHE3eivEosdXenrYMnz8EtobPOLyx4SQ4RvDrBfrjiNTGGgAowORLYc6sztZ8AKEQiQ9KVaOVNJ8DR5e2TQ7S~bNU91c0PEfrrcA_" - + @"&Key-Pair-Id=amazingKeyPairId"; - string signedURL = AmazonCloudFrontUrlSigner.SignUrl("http://awesome.dot.com/amazing/uri/", "amazingKeyPairId", privateRSAKeyStreamReader, "SecretPolicy"); - - Assert.Equal(expectedSignedURL, signedURL); - } - - [Fact] - [Trait("Category", "CloudFront")] - public void SignURLCannedValidation() - { - string expectedSignedURL = @"http://awesome.dot.com/amazing/uri/?Expires=1492153200" + - @"&Signature=XSFtfQPkZ3SgEulXvGpBH7L~Bfh3wv4kPtrYHkFA2yubVZ9tibq0Cz4HDaA-TVkuPOw0ipC4AmzOX8tjrtoD1U1N" + - @"MsnnA3H4SQJI4Pe9AXjJwARrbFegGmCLoMmun2FxbOZqo2zb1ltBMOx7HtXBF5lQVkdukQsam4B6g3Mm9ec_&Key-Pair-Id=amazingKeyPairId"; - - string signedURL = AmazonCloudFrontUrlSigner.SignUrlCanned("http://awesome.dot.com/amazing/uri/", - "amazingKeyPairId", privateRSAKeyStreamReader, new DateTime(2017, 4, 14, 7, 0, 0, DateTimeKind.Utc)); - - Assert.Equal(expectedSignedURL, signedURL); - } - } -} diff --git a/sdk/test/Services/CloudFront/UnitTests/AWSSDK.UnitTests.CloudFront.NetFramework.csproj b/sdk/test/Services/CloudFront/UnitTests/AWSSDK.UnitTests.CloudFront.NetFramework.csproj index 125f82a21905..a8317f516cd2 100644 --- a/sdk/test/Services/CloudFront/UnitTests/AWSSDK.UnitTests.CloudFront.NetFramework.csproj +++ b/sdk/test/Services/CloudFront/UnitTests/AWSSDK.UnitTests.CloudFront.NetFramework.csproj @@ -62,8 +62,5 @@ - - - \ No newline at end of file diff --git a/sdk/test/UnitTests/AWSSDK.UnitTests.Custom.NetFramework.csproj b/sdk/test/UnitTests/AWSSDK.UnitTests.Custom.NetFramework.csproj index bd5db3e194e3..733ae3aee9d1 100644 --- a/sdk/test/UnitTests/AWSSDK.UnitTests.Custom.NetFramework.csproj +++ b/sdk/test/UnitTests/AWSSDK.UnitTests.Custom.NetFramework.csproj @@ -86,7 +86,6 @@ This project file should not be used as part of a release pipeline. - diff --git a/sdk/test/UnitTests/AWSSDK.UnitTests.NetFramework.csproj b/sdk/test/UnitTests/AWSSDK.UnitTests.NetFramework.csproj index 1ab7d332c5a1..5d1c7e6f8ba0 100644 --- a/sdk/test/UnitTests/AWSSDK.UnitTests.NetFramework.csproj +++ b/sdk/test/UnitTests/AWSSDK.UnitTests.NetFramework.csproj @@ -84,7 +84,6 @@ - \ No newline at end of file