Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API Proposal]: Provide means to construct a CoseSign1Message with private key in Azure Key Vault #110431

Open
gaurav137 opened this issue Dec 5, 2024 · 9 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Security untriaged New issue has not been triaged by the area owner

Comments

@gaurav137
Copy link

gaurav137 commented Dec 5, 2024

Background and motivation

When using Azure Key Vault (AKV) HSM to store private keys as per https://microsoft.github.io/CCF/main/governance/hsm_keys.html we need a mechanism to create sign1 embedded messages similar to the steps laid down at https://microsoft.github.io/CCF/main/governance/hsm_keys.html#cose-signing. With the .NET Cose APIs its not possible to do such an orchestration where the private key to sign the message is not locally available but in AKV and the client wants to use AKV APIs to sign the data.

API Proposal

Can take inspiration from create_cose_sign1_prepare and create_cose_sign1_finish patterns.

API Usage

NA

Alternative Designs

No response

Risks

No response

@gaurav137 gaurav137 added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Dec 5, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Dec 5, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.

@vcsjones
Copy link
Member

vcsjones commented Dec 5, 2024

You can use Azure Key Vault to sign a COSE message by using CryptographyClient.CreateRSAAsync and passing that to a COSE API that accepts RSA.

Something like this:

using System.Security.Cryptography;
using System.Security.Cryptography.Cose;
using Azure.Core;
using Azure.Security.KeyVault.Keys.Cryptography;

TokenCredential credential = default; // Get a credential to AKV
CryptographyClient client = new(new Uri("key/id", UriKind.RelativeOrAbsolute), credential);
using RSA rsaKeyVault = await client.CreateRSAAsync();

CoseSigner signer = new(rsaKeyVault, RSASignaturePadding.Pkcs1, HashAlgorithmName.SHA256);
byte[] signedCoseMessage = CoseSign1Message.SignEmbedded("hello world"u8, signer);

With the following package dependencies:

<PackageReference Include="Azure.Security.KeyVault.Keys" Version="4.7.0" />
<PackageReference Include="System.Security.Cryptography.Cose" Version="9.0.0" />

@gaurav137
Copy link
Author

gaurav137 commented Dec 6, 2024

Thanks @vcsjones. I didn't realize that support for using RSA keys in AKV existed. I didn't see a way to do it using elliptic curve cryptography/ECDsa. The scenario we have (as shown in the CCF links above) is to cose sign messages with secp384r1 elliptic curve key pairs. Can that be done?

@vcsjones
Copy link
Member

vcsjones commented Dec 6, 2024

didn't see a way to do it using elliptic curve cryptography/ECDsa.

The Azure SDK did not appear to finish the ECDSA part of the implementation. Azure/azure-sdk-for-net#36069.

Perhaps @heaths could be convinced to re-open the ECDSA pull request and eventually merge it.

In the mean time, you can do this yourself. The ECDsa class is abstract and you should be able to implement a wrapper around Azure Key Vault using your own implementation.

This is generally the expected design of how other cryptographic implementations are supported in COSE as well as other formats like CMS. Whether it be from Azure Key Vault, a custom implementation of the algorithm, or similar, implementing the base type of the cryptographic algorithm is the supported way to do this.

@heaths
Copy link

heaths commented Dec 6, 2024

IIRC, no one was asking for it at the time so it'd have been an unnecessary cost. If people are interested, @jsquire may consider reopening it. I'm no longer on the Azure SDK for .NET team, focusing instead on the Rust SDK.

@gaurav137
Copy link
Author

In the mean time, you can do this yourself. The ECDsa class is abstract and you should be able to implement a wrapper around Azure Key Vault using your own implementation.

This is generally the expected design of how other cryptographic implementations are supported in COSE as well as other formats like CMS. Whether it be from Azure Key Vault, a custom implementation of the algorithm, or similar, implementing the base type of the cryptographic algorithm is the supported way to do this.

Thanks! I'll try out this approach.

@jsquire
Copy link
Member

jsquire commented Dec 6, 2024

Thanks for the heads-up, @heaths. I agree that we haven't seen strong enough demand at present to warrant the investment. But it does seem worth opening a discussion issue that we can link from this thread so that we have a place to collect feedback. @JonathanCrd: Would you please open an issue in the Azure SDK for .NET repository marked as "design-discussion" and link to it here?

//fyi: @chlowell, @sandeep-sen

@heaths
Copy link

heaths commented Dec 6, 2024

CC me as well. I seem to recall there was a technical issue I discovered that made initial costs even higher compared to RSA (which was requested by a number of customers) but I'd have to dig through email and Teams threads.

@JonathanCrd
Copy link

I have opened an issue in the Azure SDK for .NET repo to keep track of the discussion: Azure/azure-sdk-for-net#47515

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Security untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

5 participants