From 37e4b115847fa6fdc1dcf36d525e58c604b07e1b Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Thu, 12 Oct 2023 16:59:23 +0000 Subject: [PATCH] CodeGen from PR 26197 in Azure/azure-rest-api-specs Merge 646dfc20708c7a926239bb42a50e42947d0cc7fc into e2832fd41d29088536cdf6cccc1b2deaa8488d8a --- .../Azure.Developer.Signing.sln | 56 ++ .../Azure.Developer.Signing/CHANGELOG.md | 11 + .../Directory.Build.props | 6 + .../Azure.Developer.Signing/README.md | 86 +++ .../src/Azure.Developer.Signing.csproj | 20 + ...DeveloperSigningClientBuilderExtensions.cs | 34 ++ .../Generated/DeveloperSigningModelFactory.cs | 49 ++ .../src/Generated/Docs/SigningClient.xml | 329 +++++++++++ .../ExtendedKeyUsage.Serialization.cs | 41 ++ .../src/Generated/ExtendedKeyUsage.cs | 28 + .../src/Generated/OperationState.cs | 57 ++ ...rofileNameSignResultError.Serialization.cs | 68 +++ ...usCertificateProfileNameSignResultError.cs | 51 ++ .../src/Generated/SignResult.Serialization.cs | 57 ++ .../src/Generated/SignResult.cs | 68 +++ .../src/Generated/SignatureAlgorithm.cs | 75 +++ .../src/Generated/SigningClient.cs | 518 ++++++++++++++++++ .../src/Generated/SigningClientOptions.cs | 37 ++ .../SigningPayloadOptions.Serialization.cs | 63 +++ .../src/Generated/SigningPayloadOptions.cs | 98 ++++ .../src/Properties/AssemblyInfo.cs | 11 + .../Azure.Developer.Signing.Tests.csproj | 29 + .../Samples/Samples_SigningClient.cs | 381 +++++++++++++ .../Azure.Developer.Signing/tsp-location.yaml | 5 + sdk/codesigning/ci.yml | 35 ++ 25 files changed, 2213 insertions(+) create mode 100644 sdk/codesigning/Azure.Developer.Signing/Azure.Developer.Signing.sln create mode 100644 sdk/codesigning/Azure.Developer.Signing/CHANGELOG.md create mode 100644 sdk/codesigning/Azure.Developer.Signing/Directory.Build.props create mode 100644 sdk/codesigning/Azure.Developer.Signing/README.md create mode 100644 sdk/codesigning/Azure.Developer.Signing/src/Azure.Developer.Signing.csproj create mode 100644 sdk/codesigning/Azure.Developer.Signing/src/Generated/DeveloperSigningClientBuilderExtensions.cs create mode 100644 sdk/codesigning/Azure.Developer.Signing/src/Generated/DeveloperSigningModelFactory.cs create mode 100644 sdk/codesigning/Azure.Developer.Signing/src/Generated/Docs/SigningClient.xml create mode 100644 sdk/codesigning/Azure.Developer.Signing/src/Generated/ExtendedKeyUsage.Serialization.cs create mode 100644 sdk/codesigning/Azure.Developer.Signing/src/Generated/ExtendedKeyUsage.cs create mode 100644 sdk/codesigning/Azure.Developer.Signing/src/Generated/OperationState.cs create mode 100644 sdk/codesigning/Azure.Developer.Signing/src/Generated/ResourceOperationStatusCertificateProfileNameSignResultError.Serialization.cs create mode 100644 sdk/codesigning/Azure.Developer.Signing/src/Generated/ResourceOperationStatusCertificateProfileNameSignResultError.cs create mode 100644 sdk/codesigning/Azure.Developer.Signing/src/Generated/SignResult.Serialization.cs create mode 100644 sdk/codesigning/Azure.Developer.Signing/src/Generated/SignResult.cs create mode 100644 sdk/codesigning/Azure.Developer.Signing/src/Generated/SignatureAlgorithm.cs create mode 100644 sdk/codesigning/Azure.Developer.Signing/src/Generated/SigningClient.cs create mode 100644 sdk/codesigning/Azure.Developer.Signing/src/Generated/SigningClientOptions.cs create mode 100644 sdk/codesigning/Azure.Developer.Signing/src/Generated/SigningPayloadOptions.Serialization.cs create mode 100644 sdk/codesigning/Azure.Developer.Signing/src/Generated/SigningPayloadOptions.cs create mode 100644 sdk/codesigning/Azure.Developer.Signing/src/Properties/AssemblyInfo.cs create mode 100644 sdk/codesigning/Azure.Developer.Signing/tests/Azure.Developer.Signing.Tests.csproj create mode 100644 sdk/codesigning/Azure.Developer.Signing/tests/Generated/Samples/Samples_SigningClient.cs create mode 100644 sdk/codesigning/Azure.Developer.Signing/tsp-location.yaml create mode 100644 sdk/codesigning/ci.yml diff --git a/sdk/codesigning/Azure.Developer.Signing/Azure.Developer.Signing.sln b/sdk/codesigning/Azure.Developer.Signing/Azure.Developer.Signing.sln new file mode 100644 index 000000000000..640e86661754 --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/Azure.Developer.Signing.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.Developer.Signing", "src\Azure.Developer.Signing.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Developer.Signing.Tests", "tests\Azure.Developer.Signing.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.Developer.Signing/CHANGELOG.md b/sdk/codesigning/Azure.Developer.Signing/CHANGELOG.md new file mode 100644 index 000000000000..13dd08af78ab --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/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.Developer.Signing/Directory.Build.props b/sdk/codesigning/Azure.Developer.Signing/Directory.Build.props new file mode 100644 index 000000000000..63bd836ad44b --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/Directory.Build.props @@ -0,0 +1,6 @@ + + + + diff --git a/sdk/codesigning/Azure.Developer.Signing/README.md b/sdk/codesigning/Azure.Developer.Signing/README.md new file mode 100644 index 000000000000..bf168fd5e7d2 --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/README.md @@ -0,0 +1,86 @@ +# Azure.Developer.Signing client library for .NET + +Azure.Developer.Signing 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.Developer.Signing/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.Developer.Signing --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.Developer.Signing/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.Developer.Signing/README.png) diff --git a/sdk/codesigning/Azure.Developer.Signing/src/Azure.Developer.Signing.csproj b/sdk/codesigning/Azure.Developer.Signing/src/Azure.Developer.Signing.csproj new file mode 100644 index 000000000000..32322937c617 --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/src/Azure.Developer.Signing.csproj @@ -0,0 +1,20 @@ + + + This is the Azure.Developer.Signing client library for developing .NET applications with rich experience. + Azure SDK Code Generation Azure.Developer.Signing for Azure Data Plane + 1.0.0-beta.1 + Azure.Developer.Signing + $(RequiredTargetFrameworks) + true + + + + + + + + + + + + diff --git a/sdk/codesigning/Azure.Developer.Signing/src/Generated/DeveloperSigningClientBuilderExtensions.cs b/sdk/codesigning/Azure.Developer.Signing/src/Generated/DeveloperSigningClientBuilderExtensions.cs new file mode 100644 index 000000000000..65cde707bc2a --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/src/Generated/DeveloperSigningClientBuilderExtensions.cs @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure.Core.Extensions; +using Azure.Developer.Signing; + +namespace Microsoft.Extensions.Azure +{ + /// Extension methods to add to client builder. + public static partial class DeveloperSigningClientBuilderExtensions + { + /// Registers a instance. + /// The builder to register with. + /// The Azure region wherein requests for signing will be sent. + public static IAzureClientBuilder AddSigningClient(this TBuilder builder, string region) + where TBuilder : IAzureClientFactoryBuilderWithCredential + { + return builder.RegisterClientFactory((options, cred) => new SigningClient(region, cred, options)); + } + + /// Registers a instance. + /// The builder to register with. + /// The configuration values. + public static IAzureClientBuilder AddSigningClient(this TBuilder builder, TConfiguration configuration) + where TBuilder : IAzureClientFactoryBuilderWithConfiguration + { + return builder.RegisterClientFactory(configuration); + } + } +} diff --git a/sdk/codesigning/Azure.Developer.Signing/src/Generated/DeveloperSigningModelFactory.cs b/sdk/codesigning/Azure.Developer.Signing/src/Generated/DeveloperSigningModelFactory.cs new file mode 100644 index 000000000000..db24edabe8d9 --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/src/Generated/DeveloperSigningModelFactory.cs @@ -0,0 +1,49 @@ +// 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.Developer.Signing +{ + /// Model factory for models. + public static partial class DeveloperSigningModelFactory + { + /// Initializes a new instance of ExtendedKeyUsage. + /// An oid string that represents an eku. + /// A new instance for mocking. + public static ExtendedKeyUsage ExtendedKeyUsage(string eku = null) + { + return new ExtendedKeyUsage(eku); + } + + /// Initializes a new instance of ResourceOperationStatusCertificateProfileNameSignResultError. + /// 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. + /// A new instance for mocking. + public static ResourceOperationStatusCertificateProfileNameSignResultError ResourceOperationStatusCertificateProfileNameSignResultError(string id = null, OperationState status = default, ResponseError error = null, SignResult result = null) + { + return new ResourceOperationStatusCertificateProfileNameSignResultError(id, status, error, result); + } + + /// Initializes a new instance of SignResult. + /// Digital signature of the requested content digest. + /// + /// Signing certificate corresponding to the private key used to sign the requested + /// digest. + /// + /// A new instance for mocking. + public static SignResult SignResult(BinaryData signature = null, BinaryData signingCertificate = null) + { + return new SignResult(signature, signingCertificate); + } + } +} diff --git a/sdk/codesigning/Azure.Developer.Signing/src/Generated/Docs/SigningClient.xml b/sdk/codesigning/Azure.Developer.Signing/src/Generated/Docs/SigningClient.xml new file mode 100644 index 000000000000..a01f2e2cef3b --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/src/Generated/Docs/SigningClient.xml @@ -0,0 +1,329 @@ + + + + + +This sample shows how to call GetSignRootCertificateAsync. +", credential); + +Response response = await client.GetSignRootCertificateAsync("", ""); +]]> +This sample shows how to call GetSignRootCertificateAsync with all parameters. +", credential); + +Response response = await client.GetSignRootCertificateAsync("", ""); +]]> + + + +This sample shows how to call GetSignRootCertificate. +", credential); + +Response response = client.GetSignRootCertificate("", ""); +]]> +This sample shows how to call GetSignRootCertificate with all parameters. +", credential); + +Response response = client.GetSignRootCertificate("", ""); +]]> + + + +This sample shows how to call GetSignRootCertificateAsync and parse the result. +", credential); + +Response response = await client.GetSignRootCertificateAsync("", "", null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.ToString()); +]]> +This sample shows how to call GetSignRootCertificateAsync with all parameters and parse the result. +", credential); + +Response response = await client.GetSignRootCertificateAsync("", "", null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.ToString()); +]]> + + + +This sample shows how to call GetSignRootCertificate and parse the result. +", credential); + +Response response = client.GetSignRootCertificate("", "", null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.ToString()); +]]> +This sample shows how to call GetSignRootCertificate with all parameters and parse the result. +", credential); + +Response response = client.GetSignRootCertificate("", "", null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.ToString()); +]]> + + + +This sample shows how to call GetExtendedKeyUsagesAsync. +", credential); + +await foreach (ExtendedKeyUsage item in client.GetExtendedKeyUsagesAsync("", "")) +{ +} +]]> +This sample shows how to call GetExtendedKeyUsagesAsync with all parameters. +", credential); + +await foreach (ExtendedKeyUsage item in client.GetExtendedKeyUsagesAsync("", "")) +{ +} +]]> + + + +This sample shows how to call GetExtendedKeyUsages. +", credential); + +foreach (ExtendedKeyUsage item in client.GetExtendedKeyUsages("", "")) +{ +} +]]> +This sample shows how to call GetExtendedKeyUsages with all parameters. +", credential); + +foreach (ExtendedKeyUsage item in client.GetExtendedKeyUsages("", "")) +{ +} +]]> + + + +This sample shows how to call GetExtendedKeyUsagesAsync and parse the result. +", credential); + +await foreach (BinaryData item in client.GetExtendedKeyUsagesAsync("", "", null)) +{ + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("eku").ToString()); +} +]]> +This sample shows how to call GetExtendedKeyUsagesAsync with all parameters and parse the result. +", credential); + +await foreach (BinaryData item in client.GetExtendedKeyUsagesAsync("", "", null)) +{ + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("eku").ToString()); +} +]]> + + + +This sample shows how to call GetExtendedKeyUsages and parse the result. +", credential); + +foreach (BinaryData item in client.GetExtendedKeyUsages("", "", null)) +{ + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("eku").ToString()); +} +]]> +This sample shows how to call GetExtendedKeyUsages with all parameters and parse the result. +", credential); + +foreach (BinaryData item in client.GetExtendedKeyUsages("", "", null)) +{ + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("eku").ToString()); +} +]]> + + + +This sample shows how to call SignAsync. +", credential); + +SigningPayloadOptions signingPayloadOptions = new SigningPayloadOptions(SignatureAlgorithm.RS256, BinaryData.FromObjectAsJson(new object())); +Operation operation = await client.SignAsync(WaitUntil.Completed, "", "", signingPayloadOptions); +ResourceOperationStatusCertificateProfileNameSignResultError responseData = operation.Value; +]]> +This sample shows how to call SignAsync with all parameters. +", credential); + +SigningPayloadOptions signingPayloadOptions = new SigningPayloadOptions(SignatureAlgorithm.RS256, BinaryData.FromObjectAsJson(new object())) +{ + FileHashList = { BinaryData.FromObjectAsJson(new object()) }, + AuthenticodeHashList = { BinaryData.FromObjectAsJson(new object()) }, +}; +Operation operation = await client.SignAsync(WaitUntil.Completed, "", "", signingPayloadOptions); +ResourceOperationStatusCertificateProfileNameSignResultError responseData = operation.Value; +]]> + + + +This sample shows how to call Sign. +", credential); + +SigningPayloadOptions signingPayloadOptions = new SigningPayloadOptions(SignatureAlgorithm.RS256, BinaryData.FromObjectAsJson(new object())); +Operation operation = client.Sign(WaitUntil.Completed, "", "", signingPayloadOptions); +ResourceOperationStatusCertificateProfileNameSignResultError responseData = operation.Value; +]]> +This sample shows how to call Sign with all parameters. +", credential); + +SigningPayloadOptions signingPayloadOptions = new SigningPayloadOptions(SignatureAlgorithm.RS256, BinaryData.FromObjectAsJson(new object())) +{ + FileHashList = { BinaryData.FromObjectAsJson(new object()) }, + AuthenticodeHashList = { BinaryData.FromObjectAsJson(new object()) }, +}; +Operation operation = client.Sign(WaitUntil.Completed, "", "", signingPayloadOptions); +ResourceOperationStatusCertificateProfileNameSignResultError responseData = operation.Value; +]]> + + + +This sample shows how to call SignAsync and parse the result. +", credential); + +using RequestContent content = RequestContent.Create(new +{ + signatureAlgorithm = "RS256", + digest = new object(), +}); +Operation operation = await client.SignAsync(WaitUntil.Completed, "", "", content); +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 parse the result. +", credential); + +using RequestContent content = RequestContent.Create(new +{ + signatureAlgorithm = "RS256", + digest = new object(), + fileHashList = new object[] + { + new object() + }, + authenticodeHashList = new object[] + { + new object() + }, +}); +Operation operation = await client.SignAsync(WaitUntil.Completed, "", "", content); +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("signature").ToString()); +Console.WriteLine(result.GetProperty("result").GetProperty("signingCertificate").ToString()); +]]> + + + +This sample shows how to call Sign and parse the result. +", credential); + +using RequestContent content = RequestContent.Create(new +{ + signatureAlgorithm = "RS256", + digest = new object(), +}); +Operation operation = client.Sign(WaitUntil.Completed, "", "", content); +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 parse the result. +", credential); + +using RequestContent content = RequestContent.Create(new +{ + signatureAlgorithm = "RS256", + digest = new object(), + fileHashList = new object[] + { + new object() + }, + authenticodeHashList = new object[] + { + new object() + }, +}); +Operation operation = client.Sign(WaitUntil.Completed, "", "", content); +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("signature").ToString()); +Console.WriteLine(result.GetProperty("result").GetProperty("signingCertificate").ToString()); +]]> + + + \ No newline at end of file diff --git a/sdk/codesigning/Azure.Developer.Signing/src/Generated/ExtendedKeyUsage.Serialization.cs b/sdk/codesigning/Azure.Developer.Signing/src/Generated/ExtendedKeyUsage.Serialization.cs new file mode 100644 index 000000000000..96885535ad02 --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/src/Generated/ExtendedKeyUsage.Serialization.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; + +namespace Azure.Developer.Signing +{ + public partial class ExtendedKeyUsage + { + internal static ExtendedKeyUsage DeserializeExtendedKeyUsage(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string eku = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("eku"u8)) + { + eku = property.Value.GetString(); + continue; + } + } + return new ExtendedKeyUsage(eku); + } + + /// 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.Developer.Signing/src/Generated/ExtendedKeyUsage.cs b/sdk/codesigning/Azure.Developer.Signing/src/Generated/ExtendedKeyUsage.cs new file mode 100644 index 000000000000..a4f76747bdca --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/src/Generated/ExtendedKeyUsage.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace Azure.Developer.Signing +{ + /// Extended key usage object identifier that are allowable. + public partial class ExtendedKeyUsage + { + /// Initializes a new instance of ExtendedKeyUsage. + internal ExtendedKeyUsage() + { + } + + /// Initializes a new instance of ExtendedKeyUsage. + /// An oid string that represents an eku. + internal ExtendedKeyUsage(string eku) + { + Eku = eku; + } + + /// An oid string that represents an eku. + public string Eku { get; } + } +} diff --git a/sdk/codesigning/Azure.Developer.Signing/src/Generated/OperationState.cs b/sdk/codesigning/Azure.Developer.Signing/src/Generated/OperationState.cs new file mode 100644 index 000000000000..1362bf1e81aa --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/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.Developer.Signing +{ + /// 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.Developer.Signing/src/Generated/ResourceOperationStatusCertificateProfileNameSignResultError.Serialization.cs b/sdk/codesigning/Azure.Developer.Signing/src/Generated/ResourceOperationStatusCertificateProfileNameSignResultError.Serialization.cs new file mode 100644 index 000000000000..4fb5eea61272 --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/src/Generated/ResourceOperationStatusCertificateProfileNameSignResultError.Serialization.cs @@ -0,0 +1,68 @@ +// 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.Developer.Signing +{ + public partial class ResourceOperationStatusCertificateProfileNameSignResultError + { + internal static ResourceOperationStatusCertificateProfileNameSignResultError DeserializeResourceOperationStatusCertificateProfileNameSignResultError(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + OperationState status = default; + Optional error = default; + Optional result = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("status"u8)) + { + status = new OperationState(property.Value.GetString()); + continue; + } + if (property.NameEquals("error"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + error = JsonSerializer.Deserialize(property.Value.GetRawText()); + continue; + } + if (property.NameEquals("result"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + result = SignResult.DeserializeSignResult(property.Value); + continue; + } + } + return new ResourceOperationStatusCertificateProfileNameSignResultError(id, status, error.Value, result.Value); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static ResourceOperationStatusCertificateProfileNameSignResultError FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeResourceOperationStatusCertificateProfileNameSignResultError(document.RootElement); + } + } +} diff --git a/sdk/codesigning/Azure.Developer.Signing/src/Generated/ResourceOperationStatusCertificateProfileNameSignResultError.cs b/sdk/codesigning/Azure.Developer.Signing/src/Generated/ResourceOperationStatusCertificateProfileNameSignResultError.cs new file mode 100644 index 000000000000..d32281512328 --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/src/Generated/ResourceOperationStatusCertificateProfileNameSignResultError.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.Developer.Signing +{ + /// Provides status details for long running operations. + public partial class ResourceOperationStatusCertificateProfileNameSignResultError + { + /// Initializes a new instance of ResourceOperationStatusCertificateProfileNameSignResultError. + /// The unique ID of the operation. + /// The status of the operation. + /// is null. + internal ResourceOperationStatusCertificateProfileNameSignResultError(string id, OperationState status) + { + Argument.AssertNotNull(id, nameof(id)); + + Id = id; + Status = status; + } + + /// Initializes a new instance of ResourceOperationStatusCertificateProfileNameSignResultError. + /// 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 ResourceOperationStatusCertificateProfileNameSignResultError(string id, OperationState status, ResponseError error, SignResult 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 SignResult Result { get; } + } +} diff --git a/sdk/codesigning/Azure.Developer.Signing/src/Generated/SignResult.Serialization.cs b/sdk/codesigning/Azure.Developer.Signing/src/Generated/SignResult.Serialization.cs new file mode 100644 index 000000000000..5db72a5c491d --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/src/Generated/SignResult.Serialization.cs @@ -0,0 +1,57 @@ +// 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.Developer.Signing +{ + public partial class SignResult + { + internal static SignResult DeserializeSignResult(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Optional signature = default; + Optional signingCertificate = default; + foreach (var property in element.EnumerateObject()) + { + 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 SignResult(signature.Value, signingCertificate.Value); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static SignResult FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeSignResult(document.RootElement); + } + } +} diff --git a/sdk/codesigning/Azure.Developer.Signing/src/Generated/SignResult.cs b/sdk/codesigning/Azure.Developer.Signing/src/Generated/SignResult.cs new file mode 100644 index 000000000000..3a9dafe3306e --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/src/Generated/SignResult.cs @@ -0,0 +1,68 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Azure.Developer.Signing +{ + /// The sign status model. + public partial class SignResult + { + /// Initializes a new instance of SignResult. + internal SignResult() + { + } + + /// Initializes a new instance of SignResult. + /// Digital signature of the requested content digest. + /// + /// Signing certificate corresponding to the private key used to sign the requested + /// digest. + /// + internal SignResult(BinaryData signature, BinaryData signingCertificate) + { + Signature = signature; + SigningCertificate = signingCertificate; + } + + /// + /// 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 sign 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.Developer.Signing/src/Generated/SignatureAlgorithm.cs b/sdk/codesigning/Azure.Developer.Signing/src/Generated/SignatureAlgorithm.cs new file mode 100644 index 000000000000..bb26b5478429 --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/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.Developer.Signing +{ + /// 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.Developer.Signing/src/Generated/SigningClient.cs b/sdk/codesigning/Azure.Developer.Signing/src/Generated/SigningClient.cs new file mode 100644 index 000000000000..8b407dd67fe0 --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/src/Generated/SigningClient.cs @@ -0,0 +1,518 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using Autorest.CSharp.Core; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Azure.Developer.Signing +{ + // Data plane generated client. + /// The Signing service client. + public partial class SigningClient + { + 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 SigningClient for mocking. + protected SigningClient() + { + } + + /// Initializes a new instance of SigningClient. + /// 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 SigningClient(string region, TokenCredential credential) : this(region, credential, new SigningClientOptions()) + { + } + + /// Initializes a new instance of SigningClient. + /// 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 SigningClient(string region, TokenCredential credential, SigningClientOptions options) + { + Argument.AssertNotNullOrEmpty(region, nameof(region)); + Argument.AssertNotNull(credential, nameof(credential)); + options ??= new SigningClientOptions(); + + 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 signing root certificate on the certificate chain for that account and profile name. + /// Signing account name. + /// Signing 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 accountName, string certificateProfile, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(accountName, nameof(accountName)); + Argument.AssertNotNullOrEmpty(certificateProfile, nameof(certificateProfile)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await GetSignRootCertificateAsync(accountName, certificateProfile, context).ConfigureAwait(false); + return Response.FromValue(response.Content, response); + } + + /// Gets the signing root certificate on the certificate chain for that account and profile name. + /// Signing account name. + /// Signing 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 accountName, string certificateProfile, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(accountName, nameof(accountName)); + Argument.AssertNotNullOrEmpty(certificateProfile, nameof(certificateProfile)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = GetSignRootCertificate(accountName, certificateProfile, context); + return Response.FromValue(response.Content, response); + } + + /// + /// [Protocol Method] Gets the signing 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. + /// + /// + /// + /// + /// Signing account name. + /// Signing 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 accountName, string certificateProfile, RequestContext context) + { + Argument.AssertNotNullOrEmpty(accountName, nameof(accountName)); + Argument.AssertNotNullOrEmpty(certificateProfile, nameof(certificateProfile)); + + using var scope = ClientDiagnostics.CreateScope("SigningClient.GetSignRootCertificate"); + scope.Start(); + try + { + using HttpMessage message = CreateGetSignRootCertificateRequest(accountName, certificateProfile, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Gets the signing 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. + /// + /// + /// + /// + /// Signing account name. + /// Signing 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 accountName, string certificateProfile, RequestContext context) + { + Argument.AssertNotNullOrEmpty(accountName, nameof(accountName)); + Argument.AssertNotNullOrEmpty(certificateProfile, nameof(certificateProfile)); + + using var scope = ClientDiagnostics.CreateScope("SigningClient.GetSignRootCertificate"); + scope.Start(); + try + { + using HttpMessage message = CreateGetSignRootCertificateRequest(accountName, certificateProfile, 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 Developer Signing account name. + /// Azure Developer Signing certificate profile name under an 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 signing operation. + /// + public virtual AsyncPageable GetExtendedKeyUsagesAsync(string accountName, string certificateProfile, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(accountName, nameof(accountName)); + Argument.AssertNotNullOrEmpty(certificateProfile, nameof(certificateProfile)); + + RequestContext context = cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null; + HttpMessage FirstPageRequest(int? pageSizeHint) => CreateGetExtendedKeyUsagesRequest(accountName, certificateProfile, context); + HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => CreateGetExtendedKeyUsagesNextPageRequest(nextLink, accountName, certificateProfile, context); + return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, ExtendedKeyUsage.DeserializeExtendedKeyUsage, ClientDiagnostics, _pipeline, "SigningClient.GetExtendedKeyUsages", "value", "nextLink", context); + } + + /// Gets a list of extended key usage object identifiers that are allowed for this account and profile combination. + /// Azure Developer Signing account name. + /// Azure Developer Signing certificate profile name under an 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 signing operation. + /// + public virtual Pageable GetExtendedKeyUsages(string accountName, string certificateProfile, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(accountName, nameof(accountName)); + Argument.AssertNotNullOrEmpty(certificateProfile, nameof(certificateProfile)); + + RequestContext context = cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null; + HttpMessage FirstPageRequest(int? pageSizeHint) => CreateGetExtendedKeyUsagesRequest(accountName, certificateProfile, context); + HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => CreateGetExtendedKeyUsagesNextPageRequest(nextLink, accountName, certificateProfile, context); + return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, ExtendedKeyUsage.DeserializeExtendedKeyUsage, ClientDiagnostics, _pipeline, "SigningClient.GetExtendedKeyUsages", "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 Developer Signing account name. + /// Azure Developer Signing certificate profile name under an 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 GetExtendedKeyUsagesAsync(string accountName, string certificateProfile, RequestContext context) + { + Argument.AssertNotNullOrEmpty(accountName, nameof(accountName)); + Argument.AssertNotNullOrEmpty(certificateProfile, nameof(certificateProfile)); + + HttpMessage FirstPageRequest(int? pageSizeHint) => CreateGetExtendedKeyUsagesRequest(accountName, certificateProfile, context); + HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => CreateGetExtendedKeyUsagesNextPageRequest(nextLink, accountName, certificateProfile, context); + return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => BinaryData.FromString(e.GetRawText()), ClientDiagnostics, _pipeline, "SigningClient.GetExtendedKeyUsages", "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 Developer Signing account name. + /// Azure Developer Signing certificate profile name under an 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 GetExtendedKeyUsages(string accountName, string certificateProfile, RequestContext context) + { + Argument.AssertNotNullOrEmpty(accountName, nameof(accountName)); + Argument.AssertNotNullOrEmpty(certificateProfile, nameof(certificateProfile)); + + HttpMessage FirstPageRequest(int? pageSizeHint) => CreateGetExtendedKeyUsagesRequest(accountName, certificateProfile, context); + HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => CreateGetExtendedKeyUsagesNextPageRequest(nextLink, accountName, certificateProfile, context); + return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => BinaryData.FromString(e.GetRawText()), ClientDiagnostics, _pipeline, "SigningClient.GetExtendedKeyUsages", "value", "nextLink", context); + } + + /// Submit a sign 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 Developer Signing account name. + /// Azure Developer Signing certificate profile name under an account. + /// The artifact 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 sign operation under the created account and profile name provided. + /// + public virtual async Task> SignAsync(WaitUntil waitUntil, string accountName, string certificateProfile, SigningPayloadOptions signingPayloadOptions, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(accountName, nameof(accountName)); + Argument.AssertNotNullOrEmpty(certificateProfile, nameof(certificateProfile)); + Argument.AssertNotNull(signingPayloadOptions, nameof(signingPayloadOptions)); + + RequestContext context = FromCancellationToken(cancellationToken); + using RequestContent content = signingPayloadOptions.ToRequestContent(); + Operation response = await SignAsync(waitUntil, accountName, certificateProfile, content, context).ConfigureAwait(false); + return ProtocolOperationHelpers.Convert(response, ResourceOperationStatusCertificateProfileNameSignResultError.FromResponse, ClientDiagnostics, "SigningClient.Sign"); + } + + /// Submit a sign 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 Developer Signing account name. + /// Azure Developer Signing certificate profile name under an account. + /// The artifact 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 sign operation under the created account and profile name provided. + /// + public virtual Operation Sign(WaitUntil waitUntil, string accountName, string certificateProfile, SigningPayloadOptions signingPayloadOptions, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(accountName, nameof(accountName)); + Argument.AssertNotNullOrEmpty(certificateProfile, nameof(certificateProfile)); + Argument.AssertNotNull(signingPayloadOptions, nameof(signingPayloadOptions)); + + RequestContext context = FromCancellationToken(cancellationToken); + using RequestContent content = signingPayloadOptions.ToRequestContent(); + Operation response = Sign(waitUntil, accountName, certificateProfile, content, context); + return ProtocolOperationHelpers.Convert(response, ResourceOperationStatusCertificateProfileNameSignResultError.FromResponse, ClientDiagnostics, "SigningClient.Sign"); + } + + /// + /// [Protocol Method] Submit a sign 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 Developer Signing account name. + /// Azure Developer Signing certificate profile name under an 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 accountName, string certificateProfile, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(accountName, nameof(accountName)); + Argument.AssertNotNullOrEmpty(certificateProfile, nameof(certificateProfile)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("SigningClient.Sign"); + scope.Start(); + try + { + using HttpMessage message = CreateSignRequest(accountName, certificateProfile, content, context); + return await ProtocolOperationHelpers.ProcessMessageAsync(_pipeline, message, ClientDiagnostics, "SigningClient.Sign", OperationFinalStateVia.Location, context, waitUntil).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Submit a sign 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 Developer Signing account name. + /// Azure Developer Signing certificate profile name under an 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 accountName, string certificateProfile, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(accountName, nameof(accountName)); + Argument.AssertNotNullOrEmpty(certificateProfile, nameof(certificateProfile)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("SigningClient.Sign"); + scope.Start(); + try + { + using HttpMessage message = CreateSignRequest(accountName, certificateProfile, content, context); + return ProtocolOperationHelpers.ProcessMessage(_pipeline, message, ClientDiagnostics, "SigningClient.Sign", OperationFinalStateVia.Location, context, waitUntil); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateGetSignRootCertificateRequest(string accountName, string certificateProfile, 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(accountName, true); + uri.AppendPath("/certificateprofiles/", false); + uri.AppendPath(certificateProfile, 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 CreateGetExtendedKeyUsagesRequest(string accountName, string certificateProfile, 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(accountName, true); + uri.AppendPath("/certificateprofiles/", false); + uri.AppendPath(certificateProfile, 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 accountName, string certificateProfile, 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(accountName, true); + uri.AppendPath("/certificateprofiles/", false); + uri.AppendPath(certificateProfile, 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 CreateGetExtendedKeyUsagesNextPageRequest(string nextLink, string accountName, string certificateProfile, 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.Developer.Signing/src/Generated/SigningClientOptions.cs b/sdk/codesigning/Azure.Developer.Signing/src/Generated/SigningClientOptions.cs new file mode 100644 index 000000000000..28c59f1516fc --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/src/Generated/SigningClientOptions.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.Developer.Signing +{ + /// Client options for SigningClient. + public partial class SigningClientOptions : 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 SigningClientOptions. + public SigningClientOptions(ServiceVersion version = LatestVersion) + { + Version = version switch + { + ServiceVersion.V2023_06_15_Preview => "2023-06-15-preview", + _ => throw new NotSupportedException() + }; + } + } +} diff --git a/sdk/codesigning/Azure.Developer.Signing/src/Generated/SigningPayloadOptions.Serialization.cs b/sdk/codesigning/Azure.Developer.Signing/src/Generated/SigningPayloadOptions.Serialization.cs new file mode 100644 index 000000000000..ed2ca7d17019 --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/src/Generated/SigningPayloadOptions.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.Developer.Signing +{ + public partial class SigningPayloadOptions : 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.Developer.Signing/src/Generated/SigningPayloadOptions.cs b/sdk/codesigning/Azure.Developer.Signing/src/Generated/SigningPayloadOptions.cs new file mode 100644 index 000000000000..e8e1e99cba38 --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/src/Generated/SigningPayloadOptions.cs @@ -0,0 +1,98 @@ +// 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.Developer.Signing +{ + /// The artifact request information to be signed by the service. + public partial class SigningPayloadOptions + { + /// Initializes a new instance of SigningPayloadOptions. + /// The supported signature algorithm identifiers. + /// Content digest to sign. + /// is null. + public SigningPayloadOptions(SignatureAlgorithm signatureAlgorithm, BinaryData digest) + { + Argument.AssertNotNull(digest, nameof(digest)); + + SignatureAlgorithm = signatureAlgorithm; + Digest = digest; + FileHashList = new ChangeTrackingList(); + AuthenticodeHashList = new ChangeTrackingList(); + } + + /// Initializes a new instance of SigningPayloadOptions. + /// The supported signature algorithm identifiers. + /// Content digest to sign. + /// List of full file digital signatures. + /// List of authenticode digital signatures. + internal SigningPayloadOptions(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 sign. + /// + /// 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 a byte[] to the element of 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 IList FileHashList { get; } + /// + /// List of authenticode digital signatures. + /// + /// To assign a byte[] to the element of 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 IList AuthenticodeHashList { get; } + } +} diff --git a/sdk/codesigning/Azure.Developer.Signing/src/Properties/AssemblyInfo.cs b/sdk/codesigning/Azure.Developer.Signing/src/Properties/AssemblyInfo.cs new file mode 100644 index 000000000000..25359742a2de --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/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.Developer.Signing.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.Developer.Signing/tests/Azure.Developer.Signing.Tests.csproj b/sdk/codesigning/Azure.Developer.Signing/tests/Azure.Developer.Signing.Tests.csproj new file mode 100644 index 000000000000..cf2cb9db0db8 --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/tests/Azure.Developer.Signing.Tests.csproj @@ -0,0 +1,29 @@ + + + $(RequiredTargetFrameworks) + + + $(NoWarn);CS1591 + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sdk/codesigning/Azure.Developer.Signing/tests/Generated/Samples/Samples_SigningClient.cs b/sdk/codesigning/Azure.Developer.Signing/tests/Generated/Samples/Samples_SigningClient.cs new file mode 100644 index 000000000000..dcb24943f949 --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/tests/Generated/Samples/Samples_SigningClient.cs @@ -0,0 +1,381 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Text.Json; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Developer.Signing; +using Azure.Identity; +using NUnit.Framework; + +namespace Azure.Developer.Signing.Samples +{ + public partial class Samples_SigningClient + { + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_GetSignRootCertificate_ShortVersion() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + Response response = client.GetSignRootCertificate("", "", null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_GetSignRootCertificate_ShortVersion_Async() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + Response response = await client.GetSignRootCertificateAsync("", "", null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_GetSignRootCertificate_ShortVersion_Convenience() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + Response response = client.GetSignRootCertificate("", ""); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_GetSignRootCertificate_ShortVersion_Convenience_Async() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + Response response = await client.GetSignRootCertificateAsync("", ""); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_GetSignRootCertificate_AllParameters() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + Response response = client.GetSignRootCertificate("", "", null); + + 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() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + Response response = await client.GetSignRootCertificateAsync("", "", null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_GetSignRootCertificate_AllParameters_Convenience() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + Response response = client.GetSignRootCertificate("", ""); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_GetSignRootCertificate_AllParameters_Convenience_Async() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + Response response = await client.GetSignRootCertificateAsync("", ""); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_GetExtendedKeyUsages_ShortVersion() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + foreach (BinaryData item in client.GetExtendedKeyUsages("", "", null)) + { + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("eku").ToString()); + } + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_GetExtendedKeyUsages_ShortVersion_Async() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + await foreach (BinaryData item in client.GetExtendedKeyUsagesAsync("", "", null)) + { + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("eku").ToString()); + } + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_GetExtendedKeyUsages_ShortVersion_Convenience() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + foreach (ExtendedKeyUsage item in client.GetExtendedKeyUsages("", "")) + { + } + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_GetExtendedKeyUsages_ShortVersion_Convenience_Async() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + await foreach (ExtendedKeyUsage item in client.GetExtendedKeyUsagesAsync("", "")) + { + } + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_GetExtendedKeyUsages_AllParameters() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + foreach (BinaryData item in client.GetExtendedKeyUsages("", "", null)) + { + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("eku").ToString()); + } + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_GetExtendedKeyUsages_AllParameters_Async() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + await foreach (BinaryData item in client.GetExtendedKeyUsagesAsync("", "", null)) + { + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("eku").ToString()); + } + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_GetExtendedKeyUsages_AllParameters_Convenience() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + foreach (ExtendedKeyUsage item in client.GetExtendedKeyUsages("", "")) + { + } + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_GetExtendedKeyUsages_AllParameters_Convenience_Async() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + await foreach (ExtendedKeyUsage item in client.GetExtendedKeyUsagesAsync("", "")) + { + } + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_Sign_ShortVersion() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + using RequestContent content = RequestContent.Create(new + { + signatureAlgorithm = "RS256", + digest = new object(), + }); + Operation operation = client.Sign(WaitUntil.Completed, "", "", content); + 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_ShortVersion_Async() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + using RequestContent content = RequestContent.Create(new + { + signatureAlgorithm = "RS256", + digest = new object(), + }); + Operation operation = await client.SignAsync(WaitUntil.Completed, "", "", content); + 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_ShortVersion_Convenience() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + SigningPayloadOptions signingPayloadOptions = new SigningPayloadOptions(SignatureAlgorithm.RS256, BinaryData.FromObjectAsJson(new object())); + Operation operation = client.Sign(WaitUntil.Completed, "", "", signingPayloadOptions); + ResourceOperationStatusCertificateProfileNameSignResultError responseData = operation.Value; + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_Sign_ShortVersion_Convenience_Async() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + SigningPayloadOptions signingPayloadOptions = new SigningPayloadOptions(SignatureAlgorithm.RS256, BinaryData.FromObjectAsJson(new object())); + Operation operation = await client.SignAsync(WaitUntil.Completed, "", "", signingPayloadOptions); + ResourceOperationStatusCertificateProfileNameSignResultError responseData = operation.Value; + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_Sign_AllParameters() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + using RequestContent content = RequestContent.Create(new + { + signatureAlgorithm = "RS256", + digest = new object(), + fileHashList = new object[] + { +new object() + }, + authenticodeHashList = new object[] + { +new object() + }, + }); + Operation operation = client.Sign(WaitUntil.Completed, "", "", content); + 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("signature").ToString()); + Console.WriteLine(result.GetProperty("result").GetProperty("signingCertificate").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_Sign_AllParameters_Async() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + using RequestContent content = RequestContent.Create(new + { + signatureAlgorithm = "RS256", + digest = new object(), + fileHashList = new object[] + { +new object() + }, + authenticodeHashList = new object[] + { +new object() + }, + }); + Operation operation = await client.SignAsync(WaitUntil.Completed, "", "", content); + 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("signature").ToString()); + Console.WriteLine(result.GetProperty("result").GetProperty("signingCertificate").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_Sign_AllParameters_Convenience() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + SigningPayloadOptions signingPayloadOptions = new SigningPayloadOptions(SignatureAlgorithm.RS256, BinaryData.FromObjectAsJson(new object())) + { + FileHashList = { BinaryData.FromObjectAsJson(new object()) }, + AuthenticodeHashList = { BinaryData.FromObjectAsJson(new object()) }, + }; + Operation operation = client.Sign(WaitUntil.Completed, "", "", signingPayloadOptions); + ResourceOperationStatusCertificateProfileNameSignResultError responseData = operation.Value; + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_Sign_AllParameters_Convenience_Async() + { + TokenCredential credential = new DefaultAzureCredential(); + SigningClient client = new SigningClient("", credential); + + SigningPayloadOptions signingPayloadOptions = new SigningPayloadOptions(SignatureAlgorithm.RS256, BinaryData.FromObjectAsJson(new object())) + { + FileHashList = { BinaryData.FromObjectAsJson(new object()) }, + AuthenticodeHashList = { BinaryData.FromObjectAsJson(new object()) }, + }; + Operation operation = await client.SignAsync(WaitUntil.Completed, "", "", signingPayloadOptions); + ResourceOperationStatusCertificateProfileNameSignResultError responseData = operation.Value; + } + } +} diff --git a/sdk/codesigning/Azure.Developer.Signing/tsp-location.yaml b/sdk/codesigning/Azure.Developer.Signing/tsp-location.yaml new file mode 100644 index 000000000000..d6c5c4262017 --- /dev/null +++ b/sdk/codesigning/Azure.Developer.Signing/tsp-location.yaml @@ -0,0 +1,5 @@ +additionalDirectories: [] +directory: specification/codesigning/CodeSigning +repo: Azure/azure-rest-api-specs +commit: 32fe89b5cc906d9840632c3c02b2535633abe445 + diff --git a/sdk/codesigning/ci.yml b/sdk/codesigning/ci.yml new file mode 100644 index 000000000000..4e800f11a386 --- /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.Developer.Signing + +pr: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/codesigning + - sdk/codesigning/ci.yml + - sdk/codesigning/Azure.Developer.Signing + +extends: + template: /eng/pipelines/templates/stages/archetype-sdk-client.yml + parameters: + ServiceDirectory: codesigning + ArtifactName: packages + Artifacts: + - name: Azure.Developer.Signing + safeName: AzureDeveloperSigning