From 2d56830c3e8fa5ee0afb4e494e82c211acb6b2a8 Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Tue, 1 Aug 2023 20:36:30 +0000 Subject: [PATCH] CodeGen from PR 25088 in Azure/azure-rest-api-specs Merge 70092bbac05c025eb4b7d3c9f66b5bc99a0db101 into 0b18643d5c21cb1ddb57cbb1503f1d9269c337a7 --- .../Azure.CodeSigning/Azure.CodeSigning.sln | 56 ++ .../Azure.CodeSigning/CHANGELOG.md | 11 + .../Azure.CodeSigning/Directory.Build.props | 6 + sdk/codesigning/Azure.CodeSigning/README.md | 86 +++ .../src/Azure.CodeSigning.csproj | 20 + .../CodeSignOperationStatus.Serialization.cs | 52 ++ .../src/Generated/CodeSignOperationStatus.cs | 40 ++ .../Generated/CodeSignResult.Serialization.cs | 63 +++ .../src/Generated/CodeSignResult.cs | 78 +++ .../src/Generated/CodeSigningClient.cs | 515 ++++++++++++++++++ .../CodeSigningClientBuilderExtensions.cs | 34 ++ .../src/Generated/CodeSigningClientOptions.cs | 37 ++ .../src/Generated/CodeSigningModelFactory.cs | 50 ++ ...eSigningSubmissionOptions.Serialization.cs | 63 +++ .../Generated/CodeSigningSubmissionOptions.cs | 126 +++++ .../src/Generated/Docs/CodeSigningClient.xml | 259 +++++++++ .../ExtendedKeyUsage.Serialization.cs | 48 ++ .../src/Generated/ExtendedKeyUsage.cs | 38 ++ .../src/Generated/OperationState.cs | 57 ++ ...cateProfileCodeSignOperationStatusError.cs | 51 ++ .../src/Generated/SignatureAlgorithm.cs | 75 +++ .../src/Properties/AssemblyInfo.cs | 11 + .../tests/Azure.CodeSigning.Tests.csproj | 29 + .../Samples/Samples_CodeSigningClient.cs | 285 ++++++++++ .../Azure.CodeSigning/tsp-location.yaml | 5 + sdk/codesigning/ci.yml | 35 ++ 26 files changed, 2130 insertions(+) create mode 100644 sdk/codesigning/Azure.CodeSigning/Azure.CodeSigning.sln create mode 100644 sdk/codesigning/Azure.CodeSigning/CHANGELOG.md create mode 100644 sdk/codesigning/Azure.CodeSigning/Directory.Build.props create mode 100644 sdk/codesigning/Azure.CodeSigning/README.md create mode 100644 sdk/codesigning/Azure.CodeSigning/src/Azure.CodeSigning.csproj create mode 100644 sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSignOperationStatus.Serialization.cs create mode 100644 sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSignOperationStatus.cs create mode 100644 sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSignResult.Serialization.cs create mode 100644 sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSignResult.cs create mode 100644 sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningClient.cs create mode 100644 sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningClientBuilderExtensions.cs create mode 100644 sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningClientOptions.cs create mode 100644 sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningModelFactory.cs create mode 100644 sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningSubmissionOptions.Serialization.cs create mode 100644 sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningSubmissionOptions.cs create mode 100644 sdk/codesigning/Azure.CodeSigning/src/Generated/Docs/CodeSigningClient.xml create mode 100644 sdk/codesigning/Azure.CodeSigning/src/Generated/ExtendedKeyUsage.Serialization.cs create mode 100644 sdk/codesigning/Azure.CodeSigning/src/Generated/ExtendedKeyUsage.cs create mode 100644 sdk/codesigning/Azure.CodeSigning/src/Generated/OperationState.cs create mode 100644 sdk/codesigning/Azure.CodeSigning/src/Generated/ResourceOperationStatusCertificateProfileCodeSignOperationStatusError.cs create mode 100644 sdk/codesigning/Azure.CodeSigning/src/Generated/SignatureAlgorithm.cs create mode 100644 sdk/codesigning/Azure.CodeSigning/src/Properties/AssemblyInfo.cs create mode 100644 sdk/codesigning/Azure.CodeSigning/tests/Azure.CodeSigning.Tests.csproj create mode 100644 sdk/codesigning/Azure.CodeSigning/tests/Generated/Samples/Samples_CodeSigningClient.cs create mode 100644 sdk/codesigning/Azure.CodeSigning/tsp-location.yaml create mode 100644 sdk/codesigning/ci.yml diff --git a/sdk/codesigning/Azure.CodeSigning/Azure.CodeSigning.sln b/sdk/codesigning/Azure.CodeSigning/Azure.CodeSigning.sln new file mode 100644 index 000000000000..0273963030b8 --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/Azure.CodeSigning.sln @@ -0,0 +1,56 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29709.97 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Core.TestFramework", "..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj", "{ECC730C1-4AEA-420C-916A-66B19B79E4DC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.CodeSigning", "src\Azure.CodeSigning.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.CodeSigning.Tests", "tests\Azure.CodeSigning.Tests.csproj", "{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.Build.0 = Release|Any CPU + {8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.Build.0 = Release|Any CPU + {ECC730C1-4AEA-420C-916A-66B19B79E4DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ECC730C1-4AEA-420C-916A-66B19B79E4DC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ECC730C1-4AEA-420C-916A-66B19B79E4DC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ECC730C1-4AEA-420C-916A-66B19B79E4DC}.Release|Any CPU.Build.0 = Release|Any CPU + {A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.Build.0 = Release|Any CPU + {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.Build.0 = Release|Any CPU + {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.Build.0 = Release|Any CPU + {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.Build.0 = Debug|Any CPU + {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.ActiveCfg = Release|Any CPU + {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.Build.0 = Release|Any CPU + {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE} + EndGlobalSection +EndGlobal diff --git a/sdk/codesigning/Azure.CodeSigning/CHANGELOG.md b/sdk/codesigning/Azure.CodeSigning/CHANGELOG.md new file mode 100644 index 000000000000..13dd08af78ab --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/CHANGELOG.md @@ -0,0 +1,11 @@ +# Release History + +## 1.0.0-beta.1 (Unreleased) + +### Features Added + +### Breaking Changes + +### Bugs Fixed + +### Other Changes diff --git a/sdk/codesigning/Azure.CodeSigning/Directory.Build.props b/sdk/codesigning/Azure.CodeSigning/Directory.Build.props new file mode 100644 index 000000000000..63bd836ad44b --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/Directory.Build.props @@ -0,0 +1,6 @@ + + + + diff --git a/sdk/codesigning/Azure.CodeSigning/README.md b/sdk/codesigning/Azure.CodeSigning/README.md new file mode 100644 index 000000000000..5cffa40a5688 --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/README.md @@ -0,0 +1,86 @@ +# Azure.CodeSigning client library for .NET + +Azure.CodeSigning is a managed service that helps developers get secret simply and securely. + +Use the client library for to: + +* [Get secret](https://docs.microsoft.com/azure) + +[Source code][source_root] | [Package (NuGet)][package] | [API reference documentation][reference_docs] | [Product documentation][azconfig_docs] | [Samples][source_samples] + + [Source code](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/codesigning/Azure.CodeSigning/src) | [Package (NuGet)](https://www.nuget.org/packages) | [API reference documentation](https://azure.github.io/azure-sdk-for-net) | [Product documentation](https://docs.microsoft.com/azure) + +## Getting started + +This section should include everything a developer needs to do to install and create their first client connection *very quickly*. + +### Install the package + +First, provide instruction for obtaining and installing the package or library. This section might include only a single line of code, like `dotnet add package package-name`, but should enable a developer to successfully install the package from NuGet, npm, or even cloning a GitHub repository. + +Install the client library for .NET with [NuGet](https://www.nuget.org/ ): + +```dotnetcli +dotnet add package Azure.CodeSigning --prerelease +``` + +### Prerequisites + +Include a section after the install command that details any requirements that must be satisfied before a developer can [authenticate](#authenticate-the-client) and test all of the snippets in the [Examples](#examples) section. For example, for Cosmos DB: + +> You must have an [Azure subscription](https://azure.microsoft.com/free/dotnet/) and [Cosmos DB account](https://docs.microsoft.com/azure/cosmos-db/account-overview) (SQL API). In order to take advantage of the C# 8.0 syntax, it is recommended that you compile using the [.NET Core SDK](https://dotnet.microsoft.com/download) 3.0 or higher with a [language version](https://docs.microsoft.com/dotnet/csharp/language-reference/configure-language-version#override-a-default) of `latest`. It is also possible to compile with the .NET Core SDK 2.1.x using a language version of `preview`. + +### Authenticate the client + +If your library requires authentication for use, such as for Azure services, include instructions and example code needed for initializing and authenticating. + +For example, include details on obtaining an account key and endpoint URI, setting environment variables for each, and initializing the client object. + +## Key concepts + +The *Key concepts* section should describe the functionality of the main classes. Point out the most important and useful classes in the package (with links to their reference pages) and explain how those classes work together. Feel free to use bulleted lists, tables, code blocks, or even diagrams for clarity. + +Include the *Thread safety* and *Additional concepts* sections below at the end of your *Key concepts* section. You may remove or add links depending on what your library makes use of: + +### Thread safety + +We guarantee that all client instance methods are thread-safe and independent of each other ([guideline](https://azure.github.io/azure-sdk/dotnet_introduction.html#dotnet-service-methods-thread-safety)). This ensures that the recommendation of reusing client instances is always safe, even across threads. + +### Additional concepts + +[Client options](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/README.md#configuring-service-clients-using-clientoptions) | +[Accessing the response](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/README.md#accessing-http-response-details-using-responset) | +[Long-running operations](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/README.md#consuming-long-running-operations-using-operationt) | +[Handling failures](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/README.md#reporting-errors-requestfailedexception) | +[Diagnostics](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/Diagnostics.md) | +[Mocking](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/README.md#mocking) | +[Client lifetime](https://devblogs.microsoft.com/azure-sdk/lifetime-management-and-thread-safety-guarantees-of-azure-sdk-net-clients/) + + +## Examples + +You can familiarize yourself with different APIs using [Samples](https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/codesigning/Azure.CodeSigning/samples). + +## Troubleshooting + +Describe common errors and exceptions, how to "unpack" them if necessary, and include guidance for graceful handling and recovery. + +Provide information to help developers avoid throttling or other service-enforced errors they might encounter. For example, provide guidance and examples for using retry or connection policies in the API. + +If the package or a related package supports it, include tips for logging or enabling instrumentation to help them debug their code. + +## Next steps + +* Provide a link to additional code examples, ideally to those sitting alongside the README in the package's `/samples` directory. +* If appropriate, point users to other packages that might be useful. +* If you think there's a good chance that developers might stumble across your package in error (because they're searching for specific functionality and mistakenly think the package provides that functionality), point them to the packages they might be looking for. + +## Contributing + +This is a template, but your SDK readme should include details on how to contribute code to the repo/package. + + +[style-guide-msft]: https://docs.microsoft.com/style-guide/capitalization +[style-guide-cloud]: https://aka.ms/azsdk/cloud-style-guide + +![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-net/sdk/codesigning/Azure.CodeSigning/README.png) diff --git a/sdk/codesigning/Azure.CodeSigning/src/Azure.CodeSigning.csproj b/sdk/codesigning/Azure.CodeSigning/src/Azure.CodeSigning.csproj new file mode 100644 index 000000000000..e0a33628b67c --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/src/Azure.CodeSigning.csproj @@ -0,0 +1,20 @@ + + + This is the Azure.CodeSigning client library for developing .NET applications with rich experience. + Azure SDK Code Generation Azure.CodeSigning for Azure Data Plane + 1.0.0-beta.1 + Azure.CodeSigning + $(RequiredTargetFrameworks) + true + + + + + + + + + + + + diff --git a/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSignOperationStatus.Serialization.cs b/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSignOperationStatus.Serialization.cs new file mode 100644 index 000000000000..43d58b22ea5a --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSignOperationStatus.Serialization.cs @@ -0,0 +1,52 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.CodeSigning +{ + public partial class CodeSignOperationStatus + { + internal static CodeSignOperationStatus DeserializeCodeSignOperationStatus(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + Optional signResult = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("signResult"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + signResult = CodeSignResult.DeserializeCodeSignResult(property.Value); + continue; + } + } + return new CodeSignOperationStatus(id, signResult.Value); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static CodeSignOperationStatus FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeCodeSignOperationStatus(document.RootElement); + } + } +} diff --git a/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSignOperationStatus.cs b/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSignOperationStatus.cs new file mode 100644 index 000000000000..1cf4e4ebe359 --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSignOperationStatus.cs @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.CodeSigning +{ + /// The codesign operation status response. + public partial class CodeSignOperationStatus + { + /// Initializes a new instance of CodeSignOperationStatus. + /// Unique Id of the operation. + /// is null. + internal CodeSignOperationStatus(string id) + { + Argument.AssertNotNull(id, nameof(id)); + + Id = id; + } + + /// Initializes a new instance of CodeSignOperationStatus. + /// Unique Id of the operation. + /// The result of the codesign operation including the signature and signing certificate. + internal CodeSignOperationStatus(string id, CodeSignResult signResult) + { + Id = id; + SignResult = signResult; + } + + /// Unique Id of the operation. + public string Id { get; } + /// The result of the codesign operation including the signature and signing certificate. + public CodeSignResult SignResult { get; } + } +} diff --git a/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSignResult.Serialization.cs b/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSignResult.Serialization.cs new file mode 100644 index 000000000000..e02898789c0a --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSignResult.Serialization.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.CodeSigning +{ + public partial class CodeSignResult + { + internal static CodeSignResult DeserializeCodeSignResult(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string operationId = default; + Optional signature = default; + Optional signingCertificate = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("operationId"u8)) + { + operationId = property.Value.GetString(); + continue; + } + if (property.NameEquals("signature"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + signature = BinaryData.FromBytes(property.Value.GetBytesFromBase64("D")); + continue; + } + if (property.NameEquals("signingCertificate"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + signingCertificate = BinaryData.FromBytes(property.Value.GetBytesFromBase64("D")); + continue; + } + } + return new CodeSignResult(operationId, signature.Value, signingCertificate.Value); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static CodeSignResult FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeCodeSignResult(document.RootElement); + } + } +} diff --git a/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSignResult.cs b/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSignResult.cs new file mode 100644 index 000000000000..cdae8ea87420 --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSignResult.cs @@ -0,0 +1,78 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.CodeSigning +{ + /// The sign status model. + public partial class CodeSignResult + { + /// Initializes a new instance of CodeSignResult. + /// Response Id of the codesign operation. + /// is null. + internal CodeSignResult(string operationId) + { + Argument.AssertNotNull(operationId, nameof(operationId)); + + OperationId = operationId; + } + + /// Initializes a new instance of CodeSignResult. + /// Response Id of the codesign operation. + /// Digital signature of the requested content digest. + /// + /// Signing certificate corresponding to the private key used to codesign the requested + /// digest. + /// + internal CodeSignResult(string operationId, BinaryData signature, BinaryData signingCertificate) + { + OperationId = operationId; + Signature = signature; + SigningCertificate = signingCertificate; + } + + /// Response Id of the codesign operation. + public string OperationId { get; } + /// + /// Digital signature of the requested content digest. + /// + /// To assign a byte[] to this property use . + /// The byte[] will be serialized to a Base64 encoded string. + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromBytes(new byte[] { 1, 2, 3 }) + /// Creates a payload of "AQID". + /// + /// + /// + /// + public BinaryData Signature { get; } + /// + /// Signing certificate corresponding to the private key used to codesign the requested + /// digest. + /// + /// To assign a byte[] to this property use . + /// The byte[] will be serialized to a Base64 encoded string. + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromBytes(new byte[] { 1, 2, 3 }) + /// Creates a payload of "AQID". + /// + /// + /// + /// + public BinaryData SigningCertificate { get; } + } +} diff --git a/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningClient.cs b/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningClient.cs new file mode 100644 index 000000000000..202b7fb9f4ec --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningClient.cs @@ -0,0 +1,515 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Azure.CodeSigning +{ + // Data plane generated client. + /// The CodeSigning service client. + public partial class CodeSigningClient + { + private static readonly string[] AuthorizationScopes = new string[] { "https://codesigning.azure.net/.default" }; + private readonly TokenCredential _tokenCredential; + private readonly HttpPipeline _pipeline; + private readonly string _region; + private readonly string _apiVersion; + + /// The ClientDiagnostics is used to provide tracing support for the client library. + internal ClientDiagnostics ClientDiagnostics { get; } + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual HttpPipeline Pipeline => _pipeline; + + /// Initializes a new instance of CodeSigningClient for mocking. + protected CodeSigningClient() + { + } + + /// Initializes a new instance of CodeSigningClient. + /// The Azure region wherein requests for signing will be sent. + /// A credential used to authenticate to an Azure Service. + /// or is null. + /// is an empty string, and was expected to be non-empty. + public CodeSigningClient(string region, TokenCredential credential) : this(region, credential, new CodeSigningClientOptions()) + { + } + + /// Initializes a new instance of CodeSigningClient. + /// The Azure region wherein requests for signing will be sent. + /// A credential used to authenticate to an Azure Service. + /// The options for configuring the client. + /// or is null. + /// is an empty string, and was expected to be non-empty. + public CodeSigningClient(string region, TokenCredential credential, CodeSigningClientOptions options) + { + Argument.AssertNotNullOrEmpty(region, nameof(region)); + Argument.AssertNotNull(credential, nameof(credential)); + options ??= new CodeSigningClientOptions(); + + ClientDiagnostics = new ClientDiagnostics(options, true); + _tokenCredential = credential; + _pipeline = HttpPipelineBuilder.Build(options, Array.Empty(), new HttpPipelinePolicy[] { new BearerTokenAuthenticationPolicy(_tokenCredential, AuthorizationScopes) }, new ResponseClassifier()); + _region = region; + _apiVersion = options.Version; + } + + /// Gets the codesigning root certificate on the certificate chain for that account and profile name. + /// CodeSigning account name. + /// Certificate profile name. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// The root certificate is generated as part of the initial account creation and it is used to sign the bits for the profile provided. + /// + public virtual async Task> GetSignRootCertificateAsync(string codeSigningAccountName, string certificateProfileName, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(codeSigningAccountName, nameof(codeSigningAccountName)); + Argument.AssertNotNullOrEmpty(certificateProfileName, nameof(certificateProfileName)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await GetSignRootCertificateAsync(codeSigningAccountName, certificateProfileName, context).ConfigureAwait(false); + return Response.FromValue(response.Content.ToObjectFromJson(), response); + } + + /// Gets the codesigning root certificate on the certificate chain for that account and profile name. + /// CodeSigning account name. + /// Certificate profile name. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// The root certificate is generated as part of the initial account creation and it is used to sign the bits for the profile provided. + /// + public virtual Response GetSignRootCertificate(string codeSigningAccountName, string certificateProfileName, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(codeSigningAccountName, nameof(codeSigningAccountName)); + Argument.AssertNotNullOrEmpty(certificateProfileName, nameof(certificateProfileName)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = GetSignRootCertificate(codeSigningAccountName, certificateProfileName, context); + return Response.FromValue(response.Content.ToObjectFromJson(), response); + } + + /// + /// [Protocol Method] Gets the codesigning root certificate on the certificate chain for that account and profile name. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// CodeSigning account name. + /// Certificate profile name. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual async Task GetSignRootCertificateAsync(string codeSigningAccountName, string certificateProfileName, RequestContext context) + { + Argument.AssertNotNullOrEmpty(codeSigningAccountName, nameof(codeSigningAccountName)); + Argument.AssertNotNullOrEmpty(certificateProfileName, nameof(certificateProfileName)); + + using var scope = ClientDiagnostics.CreateScope("CodeSigningClient.GetSignRootCertificate"); + scope.Start(); + try + { + using HttpMessage message = CreateGetSignRootCertificateRequest(codeSigningAccountName, certificateProfileName, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Gets the codesigning root certificate on the certificate chain for that account and profile name. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// CodeSigning account name. + /// Certificate profile name. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual Response GetSignRootCertificate(string codeSigningAccountName, string certificateProfileName, RequestContext context) + { + Argument.AssertNotNullOrEmpty(codeSigningAccountName, nameof(codeSigningAccountName)); + Argument.AssertNotNullOrEmpty(certificateProfileName, nameof(certificateProfileName)); + + using var scope = ClientDiagnostics.CreateScope("CodeSigningClient.GetSignRootCertificate"); + scope.Start(); + try + { + using HttpMessage message = CreateGetSignRootCertificateRequest(codeSigningAccountName, certificateProfileName, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Gets a list of extended key usage object identifiers that are allowed for this account and profile combination. + /// Azure CodeSigning account name. + /// Azure Codesigning certificate profile name under a codesign account. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// The list of extended key usages are used to determine the purpose of the certificate usage as part of the codesigning operation. + /// + public virtual AsyncPageable GetSignEkusAsync(string codeSigningAccountName, string certificateProfileName, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(codeSigningAccountName, nameof(codeSigningAccountName)); + Argument.AssertNotNullOrEmpty(certificateProfileName, nameof(certificateProfileName)); + + RequestContext context = cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null; + HttpMessage FirstPageRequest(int? pageSizeHint) => CreateGetSignEkusRequest(codeSigningAccountName, certificateProfileName, context); + HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => CreateGetSignEkusNextPageRequest(nextLink, codeSigningAccountName, certificateProfileName, context); + return PageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, ExtendedKeyUsage.DeserializeExtendedKeyUsage, ClientDiagnostics, _pipeline, "CodeSigningClient.GetSignEkus", "value", "nextLink", context); + } + + /// Gets a list of extended key usage object identifiers that are allowed for this account and profile combination. + /// Azure CodeSigning account name. + /// Azure Codesigning certificate profile name under a codesign account. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// The list of extended key usages are used to determine the purpose of the certificate usage as part of the codesigning operation. + /// + public virtual Pageable GetSignEkus(string codeSigningAccountName, string certificateProfileName, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(codeSigningAccountName, nameof(codeSigningAccountName)); + Argument.AssertNotNullOrEmpty(certificateProfileName, nameof(certificateProfileName)); + + RequestContext context = cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null; + HttpMessage FirstPageRequest(int? pageSizeHint) => CreateGetSignEkusRequest(codeSigningAccountName, certificateProfileName, context); + HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => CreateGetSignEkusNextPageRequest(nextLink, codeSigningAccountName, certificateProfileName, context); + return PageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, ExtendedKeyUsage.DeserializeExtendedKeyUsage, ClientDiagnostics, _pipeline, "CodeSigningClient.GetSignEkus", "value", "nextLink", context); + } + + /// + /// [Protocol Method] Gets a list of extended key usage object identifiers that are allowed for this account and profile combination. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// Azure CodeSigning account name. + /// Azure Codesigning certificate profile name under a codesign account. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The from the service containing a list of objects. Details of the body schema for each item in the collection are in the Remarks section below. + /// + public virtual AsyncPageable GetSignEkusAsync(string codeSigningAccountName, string certificateProfileName, RequestContext context) + { + Argument.AssertNotNullOrEmpty(codeSigningAccountName, nameof(codeSigningAccountName)); + Argument.AssertNotNullOrEmpty(certificateProfileName, nameof(certificateProfileName)); + + HttpMessage FirstPageRequest(int? pageSizeHint) => CreateGetSignEkusRequest(codeSigningAccountName, certificateProfileName, context); + HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => CreateGetSignEkusNextPageRequest(nextLink, codeSigningAccountName, certificateProfileName, context); + return PageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => BinaryData.FromString(e.GetRawText()), ClientDiagnostics, _pipeline, "CodeSigningClient.GetSignEkus", "value", "nextLink", context); + } + + /// + /// [Protocol Method] Gets a list of extended key usage object identifiers that are allowed for this account and profile combination. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// Azure CodeSigning account name. + /// Azure Codesigning certificate profile name under a codesign account. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The from the service containing a list of objects. Details of the body schema for each item in the collection are in the Remarks section below. + /// + public virtual Pageable GetSignEkus(string codeSigningAccountName, string certificateProfileName, RequestContext context) + { + Argument.AssertNotNullOrEmpty(codeSigningAccountName, nameof(codeSigningAccountName)); + Argument.AssertNotNullOrEmpty(certificateProfileName, nameof(certificateProfileName)); + + HttpMessage FirstPageRequest(int? pageSizeHint) => CreateGetSignEkusRequest(codeSigningAccountName, certificateProfileName, context); + HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => CreateGetSignEkusNextPageRequest(nextLink, codeSigningAccountName, certificateProfileName, context); + return PageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => BinaryData.FromString(e.GetRawText()), ClientDiagnostics, _pipeline, "CodeSigningClient.GetSignEkus", "value", "nextLink", context); + } + + /// Submit a codesign operation. + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// Azure CodeSigning account name. + /// Azure Codesigning certificate profile name under a codesign account. + /// The codesign request information to be signed by the service. + /// The cancellation token to use. + /// , or is null. + /// or is an empty string, and was expected to be non-empty. + /// Submit a codesign operation under the created codesign account and profile name provided. + /// + public virtual async Task> SignAsync(WaitUntil waitUntil, string codeSigningAccountName, string certificateProfileName, CodeSigningSubmissionOptions codeSigningSubmissionOptions, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(codeSigningAccountName, nameof(codeSigningAccountName)); + Argument.AssertNotNullOrEmpty(certificateProfileName, nameof(certificateProfileName)); + Argument.AssertNotNull(codeSigningSubmissionOptions, nameof(codeSigningSubmissionOptions)); + + RequestContext context = FromCancellationToken(cancellationToken); + Operation response = await SignAsync(waitUntil, codeSigningAccountName, certificateProfileName, codeSigningSubmissionOptions.ToRequestContent(), context).ConfigureAwait(false); + return ProtocolOperationHelpers.Convert(response, ResourceOperationStatusCertificateProfileCodeSignOperationStatusError.FromResponse, ClientDiagnostics, "CodeSigningClient.Sign"); + } + + /// Submit a codesign operation. + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// Azure CodeSigning account name. + /// Azure Codesigning certificate profile name under a codesign account. + /// The codesign request information to be signed by the service. + /// The cancellation token to use. + /// , or is null. + /// or is an empty string, and was expected to be non-empty. + /// Submit a codesign operation under the created codesign account and profile name provided. + /// + public virtual Operation Sign(WaitUntil waitUntil, string codeSigningAccountName, string certificateProfileName, CodeSigningSubmissionOptions codeSigningSubmissionOptions, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(codeSigningAccountName, nameof(codeSigningAccountName)); + Argument.AssertNotNullOrEmpty(certificateProfileName, nameof(certificateProfileName)); + Argument.AssertNotNull(codeSigningSubmissionOptions, nameof(codeSigningSubmissionOptions)); + + RequestContext context = FromCancellationToken(cancellationToken); + Operation response = Sign(waitUntil, codeSigningAccountName, certificateProfileName, codeSigningSubmissionOptions.ToRequestContent(), context); + return ProtocolOperationHelpers.Convert(response, ResourceOperationStatusCertificateProfileCodeSignOperationStatusError.FromResponse, ClientDiagnostics, "CodeSigningClient.Sign"); + } + + /// + /// [Protocol Method] Submit a codesign operation. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// Azure CodeSigning account name. + /// Azure Codesigning certificate profile name under a codesign account. + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// , or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The representing an asynchronous operation on the service. + /// + public virtual async Task> SignAsync(WaitUntil waitUntil, string codeSigningAccountName, string certificateProfileName, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(codeSigningAccountName, nameof(codeSigningAccountName)); + Argument.AssertNotNullOrEmpty(certificateProfileName, nameof(certificateProfileName)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("CodeSigningClient.Sign"); + scope.Start(); + try + { + using HttpMessage message = CreateSignRequest(codeSigningAccountName, certificateProfileName, content, context); + return await ProtocolOperationHelpers.ProcessMessageAsync(_pipeline, message, ClientDiagnostics, "CodeSigningClient.Sign", OperationFinalStateVia.Location, context, waitUntil).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Submit a codesign operation. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// Azure CodeSigning account name. + /// Azure Codesigning certificate profile name under a codesign account. + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// , or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The representing an asynchronous operation on the service. + /// + public virtual Operation Sign(WaitUntil waitUntil, string codeSigningAccountName, string certificateProfileName, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(codeSigningAccountName, nameof(codeSigningAccountName)); + Argument.AssertNotNullOrEmpty(certificateProfileName, nameof(certificateProfileName)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("CodeSigningClient.Sign"); + scope.Start(); + try + { + using HttpMessage message = CreateSignRequest(codeSigningAccountName, certificateProfileName, content, context); + return ProtocolOperationHelpers.ProcessMessage(_pipeline, message, ClientDiagnostics, "CodeSigningClient.Sign", OperationFinalStateVia.Location, context, waitUntil); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateGetSignRootCertificateRequest(string codeSigningAccountName, string certificateProfileName, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw("https://", false); + uri.AppendRaw(_region, true); + uri.AppendRaw(".codesigning.azure.net/", false); + uri.AppendPath("/codesigningaccounts/", false); + uri.AppendPath(codeSigningAccountName, true); + uri.AppendPath("/certificateprofiles/", false); + uri.AppendPath(certificateProfileName, true); + uri.AppendPath("/sign/rootcert", false); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateGetSignEkusRequest(string codeSigningAccountName, string certificateProfileName, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw("https://", false); + uri.AppendRaw(_region, true); + uri.AppendRaw(".codesigning.azure.net/", false); + uri.AppendPath("/codesigningaccounts/", false); + uri.AppendPath(codeSigningAccountName, true); + uri.AppendPath("/certificateprofiles/", false); + uri.AppendPath(certificateProfileName, true); + uri.AppendPath("/sign/eku", false); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateSignRequest(string codeSigningAccountName, string certificateProfileName, RequestContent content, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier202); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw("https://", false); + uri.AppendRaw(_region, true); + uri.AppendRaw(".codesigning.azure.net/", false); + uri.AppendPath("/codesigningaccounts/", false); + uri.AppendPath(codeSigningAccountName, true); + uri.AppendPath("/certificateprofiles/", false); + uri.AppendPath(certificateProfileName, true); + uri.AppendPath(":sign", false); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + request.Headers.Add("Content-Type", "application/json"); + request.Content = content; + return message; + } + + internal HttpMessage CreateGetSignEkusNextPageRequest(string nextLink, string codeSigningAccountName, string certificateProfileName, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw("https://", false); + uri.AppendRaw(_region, true); + uri.AppendRaw(".codesigning.azure.net/", false); + uri.AppendRawNextLink(nextLink, false); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + private static RequestContext DefaultRequestContext = new RequestContext(); + internal static RequestContext FromCancellationToken(CancellationToken cancellationToken = default) + { + if (!cancellationToken.CanBeCanceled) + { + return DefaultRequestContext; + } + + return new RequestContext() { CancellationToken = cancellationToken }; + } + + private static ResponseClassifier _responseClassifier200; + private static ResponseClassifier ResponseClassifier200 => _responseClassifier200 ??= new StatusCodeClassifier(stackalloc ushort[] { 200 }); + private static ResponseClassifier _responseClassifier202; + private static ResponseClassifier ResponseClassifier202 => _responseClassifier202 ??= new StatusCodeClassifier(stackalloc ushort[] { 202 }); + } +} diff --git a/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningClientBuilderExtensions.cs b/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningClientBuilderExtensions.cs new file mode 100644 index 000000000000..0455138e8fc8 --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningClientBuilderExtensions.cs @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure.CodeSigning; +using Azure.Core.Extensions; + +namespace Microsoft.Extensions.Azure +{ + /// Extension methods to add to client builder. + public static partial class CodeSigningClientBuilderExtensions + { + /// Registers a instance. + /// The builder to register with. + /// The Azure region wherein requests for signing will be sent. + public static IAzureClientBuilder AddCodeSigningClient(this TBuilder builder, string region) + where TBuilder : IAzureClientFactoryBuilderWithCredential + { + return builder.RegisterClientFactory((options, cred) => new CodeSigningClient(region, cred, options)); + } + + /// Registers a instance. + /// The builder to register with. + /// The configuration values. + public static IAzureClientBuilder AddCodeSigningClient(this TBuilder builder, TConfiguration configuration) + where TBuilder : IAzureClientFactoryBuilderWithConfiguration + { + return builder.RegisterClientFactory(configuration); + } + } +} diff --git a/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningClientOptions.cs b/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningClientOptions.cs new file mode 100644 index 000000000000..bc823064445d --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningClientOptions.cs @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Azure.CodeSigning +{ + /// Client options for CodeSigningClient. + public partial class CodeSigningClientOptions : ClientOptions + { + private const ServiceVersion LatestVersion = ServiceVersion.V2023_06_15_Preview; + + /// The version of the service to use. + public enum ServiceVersion + { + /// Service version "2023-06-15-preview". + V2023_06_15_Preview = 1, + } + + internal string Version { get; } + + /// Initializes new instance of CodeSigningClientOptions. + public CodeSigningClientOptions(ServiceVersion version = LatestVersion) + { + Version = version switch + { + ServiceVersion.V2023_06_15_Preview => "2023-06-15-preview", + _ => throw new NotSupportedException() + }; + } + } +} diff --git a/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningModelFactory.cs b/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningModelFactory.cs new file mode 100644 index 000000000000..cd7a67959eab --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningModelFactory.cs @@ -0,0 +1,50 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure; + +namespace Azure.CodeSigning +{ + /// Model factory for models. + public static partial class CodeSigningModelFactory + { + /// Initializes a new instance of ExtendedKeyUsage. + /// An element of ekus. + /// A new instance for mocking. + public static ExtendedKeyUsage ExtendedKeyUsage(IEnumerable ekus = null) + { + ekus ??= new List(); + + return new ExtendedKeyUsage(ekus?.ToList()); + } + + /// Initializes a new instance of CodeSignOperationStatus. + /// Unique Id of the operation. + /// The result of the codesign operation including the signature and signing certificate. + /// A new instance for mocking. + public static CodeSignOperationStatus CodeSignOperationStatus(string id = null, CodeSignResult signResult = null) + { + return new CodeSignOperationStatus(id, signResult); + } + + /// Initializes a new instance of CodeSignResult. + /// Response Id of the codesign operation. + /// Digital signature of the requested content digest. + /// + /// Signing certificate corresponding to the private key used to codesign the requested + /// digest. + /// + /// A new instance for mocking. + public static CodeSignResult CodeSignResult(string operationId = null, BinaryData signature = null, BinaryData signingCertificate = null) + { + return new CodeSignResult(operationId, signature, signingCertificate); + } + } +} diff --git a/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningSubmissionOptions.Serialization.cs b/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningSubmissionOptions.Serialization.cs new file mode 100644 index 000000000000..a2117c95049a --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningSubmissionOptions.Serialization.cs @@ -0,0 +1,63 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.CodeSigning +{ + public partial class CodeSigningSubmissionOptions : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("signatureAlgorithm"u8); + writer.WriteStringValue(SignatureAlgorithm.ToString()); + writer.WritePropertyName("digest"u8); + writer.WriteBase64StringValue(Digest.ToArray(), "D"); + if (Optional.IsCollectionDefined(FileHashList)) + { + writer.WritePropertyName("fileHashList"u8); + writer.WriteStartArray(); + foreach (var item in FileHashList) + { + if (item == null) + { + writer.WriteNullValue(); + continue; + } + writer.WriteBase64StringValue(item.ToArray(), "D"); + } + writer.WriteEndArray(); + } + if (Optional.IsCollectionDefined(AuthenticodeHashList)) + { + writer.WritePropertyName("authenticodeHashList"u8); + writer.WriteStartArray(); + foreach (var item in AuthenticodeHashList) + { + if (item == null) + { + writer.WriteNullValue(); + continue; + } + writer.WriteBase64StringValue(item.ToArray(), "D"); + } + writer.WriteEndArray(); + } + writer.WriteEndObject(); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningSubmissionOptions.cs b/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningSubmissionOptions.cs new file mode 100644 index 000000000000..0b05a96b0846 --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/src/Generated/CodeSigningSubmissionOptions.cs @@ -0,0 +1,126 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; + +namespace Azure.CodeSigning +{ + /// The codesign request information to be signed by the service. + public partial class CodeSigningSubmissionOptions + { + /// Initializes a new instance of CodeSigningSubmissionOptions. + /// The supported signature algorithm identifiers. + /// Content digest to codesign. + /// is null. + public CodeSigningSubmissionOptions(SignatureAlgorithm signatureAlgorithm, BinaryData digest) + { + Argument.AssertNotNull(digest, nameof(digest)); + + SignatureAlgorithm = signatureAlgorithm; + Digest = digest; + FileHashList = new ChangeTrackingList(); + AuthenticodeHashList = new ChangeTrackingList(); + } + + /// Initializes a new instance of CodeSigningSubmissionOptions. + /// The supported signature algorithm identifiers. + /// Content digest to codesign. + /// List of full file digital signatures. + /// List of authenticode digital signatures. + internal CodeSigningSubmissionOptions(SignatureAlgorithm signatureAlgorithm, BinaryData digest, IList fileHashList, IList authenticodeHashList) + { + SignatureAlgorithm = signatureAlgorithm; + Digest = digest; + FileHashList = fileHashList; + AuthenticodeHashList = authenticodeHashList; + } + + /// The supported signature algorithm identifiers. + public SignatureAlgorithm SignatureAlgorithm { get; } + /// + /// Content digest to codesign. + /// + /// To assign a byte[] to this property use . + /// The byte[] will be serialized to a Base64 encoded string. + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromBytes(new byte[] { 1, 2, 3 }) + /// Creates a payload of "AQID". + /// + /// + /// + /// + public BinaryData Digest { get; } + /// + /// List of full file digital signatures. + /// + /// To assign an object to the element of this property use . + /// + /// + /// To assign an already formated json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + public IList FileHashList { get; } + /// + /// List of authenticode digital signatures. + /// + /// To assign an object to the element of this property use . + /// + /// + /// To assign an already formated json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + public IList AuthenticodeHashList { get; } + } +} diff --git a/sdk/codesigning/Azure.CodeSigning/src/Generated/Docs/CodeSigningClient.xml b/sdk/codesigning/Azure.CodeSigning/src/Generated/Docs/CodeSigningClient.xml new file mode 100644 index 000000000000..5206bc202243 --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/src/Generated/Docs/CodeSigningClient.xml @@ -0,0 +1,259 @@ + + + + + +This sample shows how to call GetSignRootCertificateAsync with required parameters. +", credential); + +var result = await client.GetSignRootCertificateAsync("", ""); +]]> + + + + +This sample shows how to call GetSignRootCertificate with required parameters. +", credential); + +var result = client.GetSignRootCertificate("", ""); +]]> + + + + +This sample shows how to call GetSignRootCertificateAsync with required parameters and parse the result. +", credential); + +Response response = await client.GetSignRootCertificateAsync("", "", new RequestContext()); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.ToString()); +]]> + + + + +This sample shows how to call GetSignRootCertificate with required parameters and parse the result. +", credential); + +Response response = client.GetSignRootCertificate("", "", new RequestContext()); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.ToString()); +]]> + + + + +This sample shows how to call GetSignEkusAsync with required parameters. +", credential); + +await foreach (var item in client.GetSignEkusAsync("", "")) +{ +} +]]> + + + + +This sample shows how to call GetSignEkus with required parameters. +", credential); + +foreach (var item in client.GetSignEkus("", "")) +{ +} +]]> + + + + +This sample shows how to call GetSignEkusAsync with required parameters and parse the result. +", credential); + +await foreach (var item in client.GetSignEkusAsync("", "", new RequestContext())) +{ + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("ekus")[0].ToString()); +} +]]> + + + + +This sample shows how to call GetSignEkus with required parameters and parse the result. +", credential); + +foreach (var item in client.GetSignEkus("", "", new RequestContext())) +{ + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("ekus")[0].ToString()); +} +]]> + + + + +This sample shows how to call SignAsync with required parameters. +", credential); + +var codeSigningSubmissionOptions = new CodeSigningSubmissionOptions(SignatureAlgorithm.RS256, BinaryData.FromString("")) +{ + FileHashList = +{ + BinaryData.FromString("") + }, + AuthenticodeHashList = +{ + BinaryData.FromString("") + }, +}; +var operation = await client.SignAsync(WaitUntil.Completed, "", "", codeSigningSubmissionOptions); +]]> + + + + +This sample shows how to call Sign with required parameters. +", credential); + +var codeSigningSubmissionOptions = new CodeSigningSubmissionOptions(SignatureAlgorithm.RS256, BinaryData.FromString("")) +{ + FileHashList = +{ + BinaryData.FromString("") + }, + AuthenticodeHashList = +{ + BinaryData.FromString("") + }, +}; +var operation = client.Sign(WaitUntil.Completed, "", "", codeSigningSubmissionOptions); +]]> + + + + +This sample shows how to call SignAsync with required parameters and request content, and how to parse the result. +", credential); + +var data = new { + signatureAlgorithm = "RS256", + digest = new {}, +}; + +var operation = await client.SignAsync(WaitUntil.Completed, "", "", RequestContent.Create(data)); + +BinaryData responseData = operation.Value; +JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; +Console.WriteLine(result.GetProperty("id").ToString()); +Console.WriteLine(result.GetProperty("status").ToString()); +]]> +This sample shows how to call SignAsync with all parameters and request content, and how to parse the result. +", credential); + +var data = new { + signatureAlgorithm = "RS256", + digest = new {}, + fileHashList = new[] { + new {} + }, + authenticodeHashList = new[] { + new {} + }, +}; + +var operation = await client.SignAsync(WaitUntil.Completed, "", "", RequestContent.Create(data)); + +BinaryData responseData = operation.Value; +JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; +Console.WriteLine(result.GetProperty("id").ToString()); +Console.WriteLine(result.GetProperty("status").ToString()); +Console.WriteLine(result.GetProperty("error").GetProperty("code").ToString()); +Console.WriteLine(result.GetProperty("error").GetProperty("message").ToString()); +Console.WriteLine(result.GetProperty("error").GetProperty("target").ToString()); +Console.WriteLine(result.GetProperty("error").GetProperty("innererror").GetProperty("code").ToString()); +Console.WriteLine(result.GetProperty("result").GetProperty("id").ToString()); +Console.WriteLine(result.GetProperty("result").GetProperty("signResult").GetProperty("operationId").ToString()); +Console.WriteLine(result.GetProperty("result").GetProperty("signResult").GetProperty("signature").ToString()); +Console.WriteLine(result.GetProperty("result").GetProperty("signResult").GetProperty("signingCertificate").ToString()); +]]> + + + + +This sample shows how to call Sign with required parameters and request content, and how to parse the result. +", credential); + +var data = new { + signatureAlgorithm = "RS256", + digest = new {}, +}; + +var operation = client.Sign(WaitUntil.Completed, "", "", RequestContent.Create(data)); + +BinaryData responseData = operation.Value; +JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; +Console.WriteLine(result.GetProperty("id").ToString()); +Console.WriteLine(result.GetProperty("status").ToString()); +]]> +This sample shows how to call Sign with all parameters and request content, and how to parse the result. +", credential); + +var data = new { + signatureAlgorithm = "RS256", + digest = new {}, + fileHashList = new[] { + new {} + }, + authenticodeHashList = new[] { + new {} + }, +}; + +var operation = client.Sign(WaitUntil.Completed, "", "", RequestContent.Create(data)); + +BinaryData responseData = operation.Value; +JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; +Console.WriteLine(result.GetProperty("id").ToString()); +Console.WriteLine(result.GetProperty("status").ToString()); +Console.WriteLine(result.GetProperty("error").GetProperty("code").ToString()); +Console.WriteLine(result.GetProperty("error").GetProperty("message").ToString()); +Console.WriteLine(result.GetProperty("error").GetProperty("target").ToString()); +Console.WriteLine(result.GetProperty("error").GetProperty("innererror").GetProperty("code").ToString()); +Console.WriteLine(result.GetProperty("result").GetProperty("id").ToString()); +Console.WriteLine(result.GetProperty("result").GetProperty("signResult").GetProperty("operationId").ToString()); +Console.WriteLine(result.GetProperty("result").GetProperty("signResult").GetProperty("signature").ToString()); +Console.WriteLine(result.GetProperty("result").GetProperty("signResult").GetProperty("signingCertificate").ToString()); +]]> + + + + \ No newline at end of file diff --git a/sdk/codesigning/Azure.CodeSigning/src/Generated/ExtendedKeyUsage.Serialization.cs b/sdk/codesigning/Azure.CodeSigning/src/Generated/ExtendedKeyUsage.Serialization.cs new file mode 100644 index 000000000000..6efc26c65dd6 --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/src/Generated/ExtendedKeyUsage.Serialization.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Azure.CodeSigning +{ + public partial class ExtendedKeyUsage + { + internal static ExtendedKeyUsage DeserializeExtendedKeyUsage(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IReadOnlyList ekus = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("ekus"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + ekus = array; + continue; + } + } + return new ExtendedKeyUsage(ekus); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static ExtendedKeyUsage FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeExtendedKeyUsage(document.RootElement); + } + } +} diff --git a/sdk/codesigning/Azure.CodeSigning/src/Generated/ExtendedKeyUsage.cs b/sdk/codesigning/Azure.CodeSigning/src/Generated/ExtendedKeyUsage.cs new file mode 100644 index 000000000000..1ca66d1271f4 --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/src/Generated/ExtendedKeyUsage.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.Core; + +namespace Azure.CodeSigning +{ + /// Extended key usage object identifier that are allowed. + public partial class ExtendedKeyUsage + { + /// Initializes a new instance of ExtendedKeyUsage. + /// An element of ekus. + /// is null. + internal ExtendedKeyUsage(IEnumerable ekus) + { + Argument.AssertNotNull(ekus, nameof(ekus)); + + Ekus = ekus.ToList(); + } + + /// Initializes a new instance of ExtendedKeyUsage. + /// An element of ekus. + internal ExtendedKeyUsage(IReadOnlyList ekus) + { + Ekus = ekus; + } + + /// An element of ekus. + public IReadOnlyList Ekus { get; } + } +} diff --git a/sdk/codesigning/Azure.CodeSigning/src/Generated/OperationState.cs b/sdk/codesigning/Azure.CodeSigning/src/Generated/OperationState.cs new file mode 100644 index 000000000000..bc5403b92417 --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/src/Generated/OperationState.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.CodeSigning +{ + /// Enum describing allowed operation states. + public readonly partial struct OperationState : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public OperationState(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string InProgressValue = "InProgress"; + private const string SucceededValue = "Succeeded"; + private const string FailedValue = "Failed"; + private const string CanceledValue = "Canceled"; + + /// The operation is in progress. + public static OperationState InProgress { get; } = new OperationState(InProgressValue); + /// The operation has completed successfully. + public static OperationState Succeeded { get; } = new OperationState(SucceededValue); + /// The operation has failed. + public static OperationState Failed { get; } = new OperationState(FailedValue); + /// The operation has been canceled by the user. + public static OperationState Canceled { get; } = new OperationState(CanceledValue); + /// Determines if two values are the same. + public static bool operator ==(OperationState left, OperationState right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(OperationState left, OperationState right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator OperationState(string value) => new OperationState(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is OperationState other && Equals(other); + /// + public bool Equals(OperationState other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/codesigning/Azure.CodeSigning/src/Generated/ResourceOperationStatusCertificateProfileCodeSignOperationStatusError.cs b/sdk/codesigning/Azure.CodeSigning/src/Generated/ResourceOperationStatusCertificateProfileCodeSignOperationStatusError.cs new file mode 100644 index 000000000000..fe9ab31bb86d --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/src/Generated/ResourceOperationStatusCertificateProfileCodeSignOperationStatusError.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure; +using Azure.Core; + +namespace Azure.CodeSigning +{ + /// Provides status details for long running operations. + public partial class ResourceOperationStatusCertificateProfileCodeSignOperationStatusError + { + /// Initializes a new instance of ResourceOperationStatusCertificateProfileCodeSignOperationStatusError. + /// The unique ID of the operation. + /// The status of the operation. + /// is null. + internal ResourceOperationStatusCertificateProfileCodeSignOperationStatusError(string id, OperationState status) + { + Argument.AssertNotNull(id, nameof(id)); + + Id = id; + Status = status; + } + + /// Initializes a new instance of ResourceOperationStatusCertificateProfileCodeSignOperationStatusError. + /// The unique ID of the operation. + /// The status of the operation. + /// Error object that describes the error when status is "Failed". + /// The result of the operation. + internal ResourceOperationStatusCertificateProfileCodeSignOperationStatusError(string id, OperationState status, ResponseError error, CodeSignOperationStatus result) + { + Id = id; + Status = status; + Error = error; + Result = result; + } + + /// The unique ID of the operation. + public string Id { get; } + /// The status of the operation. + public OperationState Status { get; } + /// Error object that describes the error when status is "Failed". + public ResponseError Error { get; } + /// The result of the operation. + public CodeSignOperationStatus Result { get; } + } +} diff --git a/sdk/codesigning/Azure.CodeSigning/src/Generated/SignatureAlgorithm.cs b/sdk/codesigning/Azure.CodeSigning/src/Generated/SignatureAlgorithm.cs new file mode 100644 index 000000000000..3e6feb46f8c8 --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/src/Generated/SignatureAlgorithm.cs @@ -0,0 +1,75 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.CodeSigning +{ + /// Algorithms supported for signing. + public readonly partial struct SignatureAlgorithm : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public SignatureAlgorithm(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string RS256Value = "RS256"; + private const string RS384Value = "RS384"; + private const string RS512Value = "RS512"; + private const string PS256Value = "PS256"; + private const string PS384Value = "PS384"; + private const string PS512Value = "PS512"; + private const string ES256Value = "ES256"; + private const string ES384Value = "ES384"; + private const string ES512Value = "ES512"; + private const string ES256KValue = "ES256K"; + + /// RSASSA-PKCS1-v1_5 using SHA-256 hash algorithm. + public static SignatureAlgorithm RS256 { get; } = new SignatureAlgorithm(RS256Value); + /// RSASSA-PKCS1-v1_5 using SHA-384 hash algorithm. + public static SignatureAlgorithm RS384 { get; } = new SignatureAlgorithm(RS384Value); + /// RSASSA-PKCS1-v1_5 using SHA-512 hash algorithm. + public static SignatureAlgorithm RS512 { get; } = new SignatureAlgorithm(RS512Value); + /// RSASSA-PSS using SHA-256 hash algorithm. + public static SignatureAlgorithm PS256 { get; } = new SignatureAlgorithm(PS256Value); + /// RSASSA-PSS using SHA-384 hash algorithm. + public static SignatureAlgorithm PS384 { get; } = new SignatureAlgorithm(PS384Value); + /// RSASSA-PSS using SHA-512 hash algorithm. + public static SignatureAlgorithm PS512 { get; } = new SignatureAlgorithm(PS512Value); + /// ECDSA using P-256 and SHA-256 hash algorithm. + public static SignatureAlgorithm ES256 { get; } = new SignatureAlgorithm(ES256Value); + /// ECDSA using P-384 and SHA-384 hash algorithm. + public static SignatureAlgorithm ES384 { get; } = new SignatureAlgorithm(ES384Value); + /// ECDSA using P-521 and SHA-512 hash algorithm. + public static SignatureAlgorithm ES512 { get; } = new SignatureAlgorithm(ES512Value); + /// ECDSA using secp256k1 and SHA-256 hash algorithm. + public static SignatureAlgorithm ES256K { get; } = new SignatureAlgorithm(ES256KValue); + /// Determines if two values are the same. + public static bool operator ==(SignatureAlgorithm left, SignatureAlgorithm right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(SignatureAlgorithm left, SignatureAlgorithm right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator SignatureAlgorithm(string value) => new SignatureAlgorithm(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is SignatureAlgorithm other && Equals(other); + /// + public bool Equals(SignatureAlgorithm other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value?.GetHashCode() ?? 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/codesigning/Azure.CodeSigning/src/Properties/AssemblyInfo.cs b/sdk/codesigning/Azure.CodeSigning/src/Properties/AssemblyInfo.cs new file mode 100644 index 000000000000..7ecf1360ae16 --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/src/Properties/AssemblyInfo.cs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Azure.CodeSigning.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d15ddcb29688295338af4b7686603fe614abd555e09efba8fb88ee09e1f7b1ccaeed2e8f823fa9eef3fdd60217fc012ea67d2479751a0b8c087a4185541b851bd8b16f8d91b840e51b1cb0ba6fe647997e57429265e85ef62d565db50a69ae1647d54d7bd855e4db3d8a91510e5bcbd0edfbbecaa20a7bd9ae74593daa7b11b4")] + +// Replace Microsoft.Test with the correct resource provider namepace for your service and uncomment. +// See https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/azure-services-resource-providers +// for the list of possible values. +[assembly: Azure.Core.AzureResourceProviderNamespace("Microsoft.Template")] diff --git a/sdk/codesigning/Azure.CodeSigning/tests/Azure.CodeSigning.Tests.csproj b/sdk/codesigning/Azure.CodeSigning/tests/Azure.CodeSigning.Tests.csproj new file mode 100644 index 000000000000..73494b1bd983 --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/tests/Azure.CodeSigning.Tests.csproj @@ -0,0 +1,29 @@ + + + $(RequiredTargetFrameworks) + + + $(NoWarn);CS1591 + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sdk/codesigning/Azure.CodeSigning/tests/Generated/Samples/Samples_CodeSigningClient.cs b/sdk/codesigning/Azure.CodeSigning/tests/Generated/Samples/Samples_CodeSigningClient.cs new file mode 100644 index 000000000000..036fcdf073cf --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/tests/Generated/Samples/Samples_CodeSigningClient.cs @@ -0,0 +1,285 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.IO; +using System.Text.Json; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using NUnit.Framework; + +namespace Azure.CodeSigning.Samples +{ + public class Samples_CodeSigningClient + { + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_GetSignRootCertificate() + { + var credential = new DefaultAzureCredential(); + var client = new CodeSigningClient("", credential); + + Response response = client.GetSignRootCertificate("", "", new RequestContext()); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_GetSignRootCertificate_AllParameters() + { + var credential = new DefaultAzureCredential(); + var client = new CodeSigningClient("", credential); + + Response response = client.GetSignRootCertificate("", "", new RequestContext()); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_GetSignRootCertificate_Async() + { + var credential = new DefaultAzureCredential(); + var client = new CodeSigningClient("", credential); + + Response response = await client.GetSignRootCertificateAsync("", "", new RequestContext()); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_GetSignRootCertificate_AllParameters_Async() + { + var credential = new DefaultAzureCredential(); + var client = new CodeSigningClient("", credential); + + Response response = await client.GetSignRootCertificateAsync("", "", new RequestContext()); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_GetSignRootCertificate_Convenience_Async() + { + var credential = new DefaultAzureCredential(); + var client = new CodeSigningClient("", credential); + + var result = await client.GetSignRootCertificateAsync("", ""); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_GetSignEkus() + { + var credential = new DefaultAzureCredential(); + var client = new CodeSigningClient("", credential); + + foreach (var item in client.GetSignEkus("", "", new RequestContext())) + { + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("ekus")[0].ToString()); + } + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_GetSignEkus_AllParameters() + { + var credential = new DefaultAzureCredential(); + var client = new CodeSigningClient("", credential); + + foreach (var item in client.GetSignEkus("", "", new RequestContext())) + { + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("ekus")[0].ToString()); + } + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_GetSignEkus_Async() + { + var credential = new DefaultAzureCredential(); + var client = new CodeSigningClient("", credential); + + await foreach (var item in client.GetSignEkusAsync("", "", new RequestContext())) + { + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("ekus")[0].ToString()); + } + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_GetSignEkus_AllParameters_Async() + { + var credential = new DefaultAzureCredential(); + var client = new CodeSigningClient("", credential); + + await foreach (var item in client.GetSignEkusAsync("", "", new RequestContext())) + { + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("ekus")[0].ToString()); + } + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_GetSignEkus_Convenience_Async() + { + var credential = new DefaultAzureCredential(); + var client = new CodeSigningClient("", credential); + + await foreach (var item in client.GetSignEkusAsync("", "")) + { + } + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_Sign() + { + var credential = new DefaultAzureCredential(); + var client = new CodeSigningClient("", credential); + + var data = new + { + signatureAlgorithm = "RS256", + digest = new { }, + }; + + var operation = client.Sign(WaitUntil.Completed, "", "", RequestContent.Create(data)); + + BinaryData responseData = operation.Value; + JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("id").ToString()); + Console.WriteLine(result.GetProperty("status").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_Sign_AllParameters() + { + var credential = new DefaultAzureCredential(); + var client = new CodeSigningClient("", credential); + + var data = new + { + signatureAlgorithm = "RS256", + digest = new { }, + fileHashList = new[] { + new {} + }, + authenticodeHashList = new[] { + new {} + }, + }; + + var operation = client.Sign(WaitUntil.Completed, "", "", RequestContent.Create(data)); + + BinaryData responseData = operation.Value; + JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("id").ToString()); + Console.WriteLine(result.GetProperty("status").ToString()); + Console.WriteLine(result.GetProperty("error").GetProperty("code").ToString()); + Console.WriteLine(result.GetProperty("error").GetProperty("message").ToString()); + Console.WriteLine(result.GetProperty("error").GetProperty("target").ToString()); + Console.WriteLine(result.GetProperty("error").GetProperty("innererror").GetProperty("code").ToString()); + Console.WriteLine(result.GetProperty("result").GetProperty("id").ToString()); + Console.WriteLine(result.GetProperty("result").GetProperty("signResult").GetProperty("operationId").ToString()); + Console.WriteLine(result.GetProperty("result").GetProperty("signResult").GetProperty("signature").ToString()); + Console.WriteLine(result.GetProperty("result").GetProperty("signResult").GetProperty("signingCertificate").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_Sign_Async() + { + var credential = new DefaultAzureCredential(); + var client = new CodeSigningClient("", credential); + + var data = new + { + signatureAlgorithm = "RS256", + digest = new { }, + }; + + var operation = await client.SignAsync(WaitUntil.Completed, "", "", RequestContent.Create(data)); + + BinaryData responseData = operation.Value; + JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("id").ToString()); + Console.WriteLine(result.GetProperty("status").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_Sign_AllParameters_Async() + { + var credential = new DefaultAzureCredential(); + var client = new CodeSigningClient("", credential); + + var data = new + { + signatureAlgorithm = "RS256", + digest = new { }, + fileHashList = new[] { + new {} + }, + authenticodeHashList = new[] { + new {} + }, + }; + + var operation = await client.SignAsync(WaitUntil.Completed, "", "", RequestContent.Create(data)); + + BinaryData responseData = operation.Value; + JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("id").ToString()); + Console.WriteLine(result.GetProperty("status").ToString()); + Console.WriteLine(result.GetProperty("error").GetProperty("code").ToString()); + Console.WriteLine(result.GetProperty("error").GetProperty("message").ToString()); + Console.WriteLine(result.GetProperty("error").GetProperty("target").ToString()); + Console.WriteLine(result.GetProperty("error").GetProperty("innererror").GetProperty("code").ToString()); + Console.WriteLine(result.GetProperty("result").GetProperty("id").ToString()); + Console.WriteLine(result.GetProperty("result").GetProperty("signResult").GetProperty("operationId").ToString()); + Console.WriteLine(result.GetProperty("result").GetProperty("signResult").GetProperty("signature").ToString()); + Console.WriteLine(result.GetProperty("result").GetProperty("signResult").GetProperty("signingCertificate").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_Sign_Convenience_Async() + { + var credential = new DefaultAzureCredential(); + var client = new CodeSigningClient("", credential); + + var codeSigningSubmissionOptions = new CodeSigningSubmissionOptions(SignatureAlgorithm.RS256, BinaryData.FromString("")) + { + FileHashList = +{ + BinaryData.FromString("") + }, + AuthenticodeHashList = +{ + BinaryData.FromString("") + }, + }; + var operation = await client.SignAsync(WaitUntil.Completed, "", "", codeSigningSubmissionOptions); + } + } +} diff --git a/sdk/codesigning/Azure.CodeSigning/tsp-location.yaml b/sdk/codesigning/Azure.CodeSigning/tsp-location.yaml new file mode 100644 index 000000000000..5f362c17517d --- /dev/null +++ b/sdk/codesigning/Azure.CodeSigning/tsp-location.yaml @@ -0,0 +1,5 @@ +commit: 9d171f5580576db60b1ea835a3f0b90fd453464e +directory: specification/codesigning/CodeSigning +additionalDirectories: [] +repo: Azure/azure-rest-api-specs + diff --git a/sdk/codesigning/ci.yml b/sdk/codesigning/ci.yml new file mode 100644 index 000000000000..24c43a460afb --- /dev/null +++ b/sdk/codesigning/ci.yml @@ -0,0 +1,35 @@ +# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file. + +trigger: + branches: + include: + - main + - hotfix/* + - release/* + paths: + include: + - sdk/codesigning + - sdk/codesigning/ci.yml + - sdk/codesigning/Azure.CodeSigning + +pr: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/codesigning + - sdk/codesigning/ci.yml + - sdk/codesigning/Azure.CodeSigning + +extends: + template: /eng/pipelines/templates/stages/archetype-sdk-client.yml + parameters: + ServiceDirectory: codesigning + ArtifactName: packages + Artifacts: + - name: Azure.CodeSigning + safeName: AzureCodeSigning