diff --git a/aws-encryption-sdk-net/Source/AWSEncryptionSDK.csproj b/aws-encryption-sdk-net/Source/AWSEncryptionSDK.csproj index 8781bacd5..8eeb979fb 100644 --- a/aws-encryption-sdk-net/Source/AWSEncryptionSDK.csproj +++ b/aws-encryption-sdk-net/Source/AWSEncryptionSDK.csproj @@ -1,13 +1,15 @@ - Library netstandard2.1;net452 7.3 false true + + 3.0.0 + AWS.EncryptionSDK AWS.EncryptionSDK AWS Encryption SDK for .NET diff --git a/aws-encryption-sdk-net/Source/AssemblyInfo.cs b/aws-encryption-sdk-net/Source/AssemblyInfo.cs new file mode 100644 index 000000000..8ba964b29 --- /dev/null +++ b/aws-encryption-sdk-net/Source/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System.Reflection; + +[assembly: AssemblyTitle("AWS.EncryptionSDK")] + +// This should be kept in sync with the version number in AWSEncryptionSDK.csproj +[assembly: AssemblyVersion("3.0.0")] diff --git a/aws-encryption-sdk-net/Source/Extern/DefaultClientSupplier.cs b/aws-encryption-sdk-net/Source/Extern/DefaultClientSupplier.cs index b0b68d735..908b9dc17 100644 --- a/aws-encryption-sdk-net/Source/Extern/DefaultClientSupplier.cs +++ b/aws-encryption-sdk-net/Source/Extern/DefaultClientSupplier.cs @@ -1,9 +1,12 @@ // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +using System.Threading.Tasks; using Amazon; using Amazon.KeyManagementService; using Amazon.Runtime; +using Amazon.Runtime.Internal; +using Amazon.Util; // ReSharper disable once RedundantUsingDirective using AWS.EncryptionSDK.Core; @@ -24,16 +27,14 @@ public partial class DefaultClientSupplier : Dafny.Aws.EncryptionSdk.Core.IClien AWS.EncryptionSDK.Core.TypeConversion.FromDafny_N3_aws__N13_encryptionSdk__N4_core__S14_GetClientInput(input); try { - IAmazonKeyManagementService client; - if (convertedInput.Region != "") + var regionEndpoint = string.IsNullOrEmpty(convertedInput.Region) + ? null + : RegionEndpoint.GetBySystemName(convertedInput.Region); + var clientConfig = new AmazonKeyManagementServiceConfig { - var regionEndpoint = RegionEndpoint.GetBySystemName(convertedInput.Region); - client = new AmazonKeyManagementServiceClient(regionEndpoint); - } - else - { - client = new AmazonKeyManagementServiceClient(); - } + RegionEndpoint = regionEndpoint + }; + var client = new DefaultKmsClient(clientConfig); // ReSharper disable once RedundantNameQualifier return Wrappers_Compile.Result + /// A KMS client that adds the Encryption SDK version to the user agent. + /// + internal class DefaultKmsClient : AmazonKeyManagementServiceClient + { + public DefaultKmsClient(AmazonKeyManagementServiceConfig config) : base(config) + { + } + + protected override void CustomizeRuntimePipeline(RuntimePipeline pipeline) + { + base.CustomizeRuntimePipeline(pipeline); + pipeline.AddHandlerAfter(new UserAgentHandler()); + } + } + + /// + /// Adds the Encryption SDK version to the user agent. + /// + internal class UserAgentHandler : PipelineHandler + { + private static readonly string UserAgentSuffix; + + static UserAgentHandler() + { + var version = typeof(UserAgentHandler).Assembly.GetName().Version; + var semver = $"{version.Major}.{version.Minor}.{version.Build}"; + UserAgentSuffix = $" AwsEncryptionSdkNet/{semver}"; + } + + /// + public override void InvokeSync(IExecutionContext executionContext) + { + AddUserAgent(executionContext); + base.InvokeSync(executionContext); + } + + /// + public override Task InvokeAsync(IExecutionContext executionContext) + { + AddUserAgent(executionContext); + return base.InvokeAsync(executionContext); + } + + private static void AddUserAgent(IExecutionContext executionContext) + { + var request = executionContext.RequestContext.Request; + request.Headers[AWSSDKUtils.UserAgentHeader] += UserAgentSuffix; + } + } }