Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions src/Sign.Cli/AzureKeyVaultCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.CommandLine.Parsing;
using Azure.Core;
using Azure.Security.KeyVault.Certificates;
using Azure.Security.KeyVault.Keys.Cryptography;
using Azure.Security.KeyVault.Keys;
using Microsoft.Extensions.Azure;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
Expand All @@ -18,6 +18,7 @@ namespace Sign.Cli
internal sealed class AzureKeyVaultCommand : Command
{
internal Option<Uri> UrlOption { get; }
internal Option<string> CertificateVersionOption { get; }
internal Option<string> CertificateOption { get; }
internal AzureCredentialOptions AzureCredentialOptions { get; } = new();

Expand All @@ -40,6 +41,11 @@ internal AzureKeyVaultCommand(CodeCommand codeCommand, IServiceProviderFactory s
Description = AzureKeyVaultResources.CertificateOptionDescription,
Required = true
};
CertificateVersionOption = new Option<string>("--azure-key-vault-certificate-version", "-kvcv")
{
Description = AzureKeyVaultResources.CertificateVersionOptionDescription,
CustomParser = ParseCertificateVersion
};
FilesArgument = new Argument<List<string>?>("file(s)")
{
Description = Resources.FilesArgumentDescription,
Expand All @@ -48,6 +54,7 @@ internal AzureKeyVaultCommand(CodeCommand codeCommand, IServiceProviderFactory s

Options.Add(UrlOption);
Options.Add(CertificateOption);
Options.Add(CertificateVersionOption);
AzureCredentialOptions.AddOptionsToCommand(this);

Arguments.Add(FilesArgument);
Expand Down Expand Up @@ -82,8 +89,9 @@ internal AzureKeyVaultCommand(CodeCommand codeCommand, IServiceProviderFactory s
// the null-forgiving operator (!) to simplify the code.
Uri url = parseResult.GetValue(UrlOption)!;
string certificateId = parseResult.GetValue(CertificateOption)!;
string? certificateVersion = parseResult.GetValue(CertificateVersionOption);

// Construct the URI for the certificate and the key from user parameters. We'll validate those with the SDK
// Construct the URI for the certificate from user parameters. We'll validate it with the SDK.
var certUri = new Uri($"{url.Scheme}://{url.Authority}/certificates/{certificateId}");

if (!KeyVaultCertificateIdentifier.TryCreate(certUri, out var certId))
Expand All @@ -93,15 +101,12 @@ internal AzureKeyVaultCommand(CodeCommand codeCommand, IServiceProviderFactory s
return Task.FromResult(ExitCode.InvalidOptions);
}

// The key uri is similar and the key name matches the certificate name
var keyUri = new Uri($"{url.Scheme}://{url.Authority}/keys/{certificateId}");

serviceProviderFactory.AddServices(services =>
{
services.AddAzureClients(builder =>
{
builder.AddCertificateClient(certId.VaultUri);
builder.AddCryptographyClient(keyUri);
builder.AddKeyClient(certId.VaultUri);
builder.UseCredential(credential);
builder.ConfigureDefaults(options => options.Retry.Mode = RetryMode.Exponential);
});
Expand All @@ -110,8 +115,9 @@ internal AzureKeyVaultCommand(CodeCommand codeCommand, IServiceProviderFactory s
{
return new KeyVaultService(
serviceProvider.GetRequiredService<CertificateClient>(),
serviceProvider.GetRequiredService<CryptographyClient>(),
serviceProvider.GetRequiredService<KeyClient>(),
certId.Name,
certificateVersion,
serviceProvider.GetRequiredService<ILogger<KeyVaultService>>());
});
});
Expand All @@ -135,5 +141,17 @@ internal AzureKeyVaultCommand(CodeCommand codeCommand, IServiceProviderFactory s

return uri;
}

private static string? ParseCertificateVersion(ArgumentResult result)
{
if (result.Tokens.Count != 1 || result.Tokens[0].Value.Length != 32)
Comment thread
dtivel marked this conversation as resolved.
Resolved
{
result.AddError(AzureKeyVaultResources.InvalidCertificateVersionValue);

return null;
}

return result.Tokens[0].Value;
}
}
}
15 changes: 15 additions & 0 deletions src/Sign.Cli/AzureKeyVaultResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/Sign.Cli/AzureKeyVaultResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
<data name="CertificateOptionDescription" xml:space="preserve">
<value>Name of the certificate in Azure Key Vault.</value>
</data>
<data name="CertificateVersionOptionDescription" xml:space="preserve">
<value>Optional version of the Azure Key Vault certificate.</value>
</data>
<data name="ClickOnceExtensionNotSupported" xml:space="preserve">
<value>ClickOnce signing via the legacy .clickonce ZIP workaround is no longer supported. See documentation.</value>
</data>
Expand All @@ -129,6 +132,9 @@
<data name="InvalidKeyVaultUrl" xml:space="preserve">
<value>URL must only contain the protocol and host. (e.g.: https://&lt;vault-name&gt;.vault.azure.net/)</value>
</data>
<data name="InvalidCertificateVersionValue" xml:space="preserve">
<value>Certificate version must be a 32-character string.</value>
</data>
<data name="InvalidUrlValue" xml:space="preserve">
<value>URL must be an absolute HTTPS URL to an Azure Key Vault.</value>
</data>
Expand Down
10 changes: 10 additions & 0 deletions src/Sign.Cli/xlf/AzureKeyVaultResources.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<target state="translated">Název certifikátu v Azure Key Vault.</target>
<note />
</trans-unit>
<trans-unit id="CertificateVersionOptionDescription">
<source>Optional version of the Azure Key Vault certificate.</source>
<target state="new">Optional version of the Azure Key Vault certificate.</target>
<note />
</trans-unit>
<trans-unit id="ClickOnceExtensionNotSupported">
<source>ClickOnce signing via the legacy .clickonce ZIP workaround is no longer supported. See documentation.</source>
<target state="translated">Podepisování ClickOnce prostřednictvím starší verze alternativního řešení .clickonce ZIP se už nepodporuje. Projděte si dokumentaci.</target>
Expand All @@ -17,6 +22,11 @@
<target state="translated">Použijte Azure Key Vault.</target>
<note />
</trans-unit>
<trans-unit id="InvalidCertificateVersionValue">
<source>Certificate version must be a 32-character string.</source>
<target state="new">Certificate version must be a 32-character string.</target>
<note />
</trans-unit>
<trans-unit id="InvalidKeyVaultUrl">
<source>URL must only contain the protocol and host. (e.g.: https://&lt;vault-name&gt;.vault.azure.net/)</source>
<target state="translated">Adresa URL musí obsahovat pouze protokol a hostitele. (např. https://&lt;vault-name&gt;.vault.azure.net/)</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Sign.Cli/xlf/AzureKeyVaultResources.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<target state="translated">Name des Zertifikats in Azure Key Vault.</target>
<note />
</trans-unit>
<trans-unit id="CertificateVersionOptionDescription">
<source>Optional version of the Azure Key Vault certificate.</source>
<target state="new">Optional version of the Azure Key Vault certificate.</target>
<note />
</trans-unit>
<trans-unit id="ClickOnceExtensionNotSupported">
<source>ClickOnce signing via the legacy .clickonce ZIP workaround is no longer supported. See documentation.</source>
<target state="translated">Die ClickOnce-Signierung über die Legacy-.clickonce-ZIP-Problemumgehung wird nicht mehr unterstützt. Siehe Dokumentation.</target>
Expand All @@ -17,6 +22,11 @@
<target state="translated">Verwenden Sie Azure Key Vault.</target>
<note />
</trans-unit>
<trans-unit id="InvalidCertificateVersionValue">
<source>Certificate version must be a 32-character string.</source>
<target state="new">Certificate version must be a 32-character string.</target>
<note />
</trans-unit>
<trans-unit id="InvalidKeyVaultUrl">
<source>URL must only contain the protocol and host. (e.g.: https://&lt;vault-name&gt;.vault.azure.net/)</source>
<target state="translated">Die URL darf nur das Protokoll und den Host enthalten. (Beispiel: https://&lt;vault-name&gt;.vault.azure.net/)</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Sign.Cli/xlf/AzureKeyVaultResources.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<target state="translated">Nombre del certificado en Azure Key Vault.</target>
<note />
</trans-unit>
<trans-unit id="CertificateVersionOptionDescription">
<source>Optional version of the Azure Key Vault certificate.</source>
<target state="new">Optional version of the Azure Key Vault certificate.</target>
<note />
</trans-unit>
<trans-unit id="ClickOnceExtensionNotSupported">
<source>ClickOnce signing via the legacy .clickonce ZIP workaround is no longer supported. See documentation.</source>
<target state="translated">Ya no se admite la firma ClickOnce a través de la solución zip heredada .clickonce. Consulte la documentación.</target>
Expand All @@ -17,6 +22,11 @@
<target state="translated">Use Azure Key Vault.</target>
<note />
</trans-unit>
<trans-unit id="InvalidCertificateVersionValue">
<source>Certificate version must be a 32-character string.</source>
<target state="new">Certificate version must be a 32-character string.</target>
<note />
</trans-unit>
<trans-unit id="InvalidKeyVaultUrl">
<source>URL must only contain the protocol and host. (e.g.: https://&lt;vault-name&gt;.vault.azure.net/)</source>
<target state="translated">La dirección URL solo debe contener el protocolo y el host. (por ejemplo: https://&lt;vault-name&gt;.vault.azure.net/)</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Sign.Cli/xlf/AzureKeyVaultResources.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<target state="translated">Nom du certificat dans Azure Key Vault.</target>
<note />
</trans-unit>
<trans-unit id="CertificateVersionOptionDescription">
<source>Optional version of the Azure Key Vault certificate.</source>
<target state="new">Optional version of the Azure Key Vault certificate.</target>
<note />
</trans-unit>
<trans-unit id="ClickOnceExtensionNotSupported">
<source>ClickOnce signing via the legacy .clickonce ZIP workaround is no longer supported. See documentation.</source>
<target state="translated">La signature ClickOnce via la solution de contournement zip .clickonce héritée n’est plus prise en charge. Consulter la documentation.</target>
Expand All @@ -17,6 +22,11 @@
<target state="translated">Utilisez Azure Key Vault.</target>
<note />
</trans-unit>
<trans-unit id="InvalidCertificateVersionValue">
<source>Certificate version must be a 32-character string.</source>
<target state="new">Certificate version must be a 32-character string.</target>
<note />
</trans-unit>
<trans-unit id="InvalidKeyVaultUrl">
<source>URL must only contain the protocol and host. (e.g.: https://&lt;vault-name&gt;.vault.azure.net/)</source>
<target state="translated">L’URL doit contenir uniquement le protocole et l’hôte. (par exemple : https://&lt;vault-name&gt;.vault.azure.net/)</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Sign.Cli/xlf/AzureKeyVaultResources.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<target state="translated">Nome del certificato in Azure Key Vault.</target>
<note />
</trans-unit>
<trans-unit id="CertificateVersionOptionDescription">
<source>Optional version of the Azure Key Vault certificate.</source>
<target state="new">Optional version of the Azure Key Vault certificate.</target>
<note />
</trans-unit>
<trans-unit id="ClickOnceExtensionNotSupported">
<source>ClickOnce signing via the legacy .clickonce ZIP workaround is no longer supported. See documentation.</source>
<target state="translated">La firma ClickOnce tramite la soluzione alternativa legacy .clickonce ZIP non è più supportata. Vedere la documentazione.</target>
Expand All @@ -17,6 +22,11 @@
<target state="translated">Usare Azure Key Vault.</target>
<note />
</trans-unit>
<trans-unit id="InvalidCertificateVersionValue">
<source>Certificate version must be a 32-character string.</source>
<target state="new">Certificate version must be a 32-character string.</target>
<note />
</trans-unit>
<trans-unit id="InvalidKeyVaultUrl">
<source>URL must only contain the protocol and host. (e.g.: https://&lt;vault-name&gt;.vault.azure.net/)</source>
<target state="translated">L'URL deve contenere solo il protocollo e l'host. (ad esempio: https://&lt;vault-name&gt;.vault.azure.net/)</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Sign.Cli/xlf/AzureKeyVaultResources.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<target state="translated">Azure Key Vault 内の証明書の名前。</target>
<note />
</trans-unit>
<trans-unit id="CertificateVersionOptionDescription">
<source>Optional version of the Azure Key Vault certificate.</source>
<target state="new">Optional version of the Azure Key Vault certificate.</target>
<note />
</trans-unit>
<trans-unit id="ClickOnceExtensionNotSupported">
<source>ClickOnce signing via the legacy .clickonce ZIP workaround is no longer supported. See documentation.</source>
<target state="translated">従来の .clickonce ZIP 回避策による ClickOnce 署名はサポートされなくなりました。ドキュメントを参照してください。</target>
Expand All @@ -17,6 +22,11 @@
<target state="translated">Azure Key Vault を使用してください。</target>
<note />
</trans-unit>
<trans-unit id="InvalidCertificateVersionValue">
<source>Certificate version must be a 32-character string.</source>
<target state="new">Certificate version must be a 32-character string.</target>
<note />
</trans-unit>
<trans-unit id="InvalidKeyVaultUrl">
<source>URL must only contain the protocol and host. (e.g.: https://&lt;vault-name&gt;.vault.azure.net/)</source>
<target state="translated">URL にはプロトコルとホストのみを含めなければなりません。(例: https://&lt;vault-name&gt;.vault.azure.net/)</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Sign.Cli/xlf/AzureKeyVaultResources.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<target state="translated">Azure Key Vault의 인증서 이름입니다.</target>
<note />
</trans-unit>
<trans-unit id="CertificateVersionOptionDescription">
<source>Optional version of the Azure Key Vault certificate.</source>
<target state="new">Optional version of the Azure Key Vault certificate.</target>
<note />
</trans-unit>
<trans-unit id="ClickOnceExtensionNotSupported">
<source>ClickOnce signing via the legacy .clickonce ZIP workaround is no longer supported. See documentation.</source>
<target state="translated">레거시 .clickonce ZIP 해결 방법을 통한 ClickOnce 서명은 더 이상 지원되지 않습니다. 설명서를 참조하세요.</target>
Expand All @@ -17,6 +22,11 @@
<target state="translated">Azure Key Vault를 사용합니다.</target>
<note />
</trans-unit>
<trans-unit id="InvalidCertificateVersionValue">
<source>Certificate version must be a 32-character string.</source>
<target state="new">Certificate version must be a 32-character string.</target>
<note />
</trans-unit>
<trans-unit id="InvalidKeyVaultUrl">
<source>URL must only contain the protocol and host. (e.g.: https://&lt;vault-name&gt;.vault.azure.net/)</source>
<target state="translated">URL은 프로토콜과 호스트만 포함해야 합니다. (예: https://&lt;vault-name&gt;.vault.azure.net/)</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Sign.Cli/xlf/AzureKeyVaultResources.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<target state="translated">Nazwa certyfikatu w usłudze Azure Key Vault.</target>
<note />
</trans-unit>
<trans-unit id="CertificateVersionOptionDescription">
<source>Optional version of the Azure Key Vault certificate.</source>
<target state="new">Optional version of the Azure Key Vault certificate.</target>
<note />
</trans-unit>
<trans-unit id="ClickOnceExtensionNotSupported">
<source>ClickOnce signing via the legacy .clickonce ZIP workaround is no longer supported. See documentation.</source>
<target state="translated">Podpisywanie clickOnce za pośrednictwem starszego obejścia .clickonce ZIP nie jest już obsługiwane. Zobacz dokumentację.</target>
Expand All @@ -17,6 +22,11 @@
<target state="translated">Użyj usługi Azure Key Vault.</target>
<note />
</trans-unit>
<trans-unit id="InvalidCertificateVersionValue">
<source>Certificate version must be a 32-character string.</source>
<target state="new">Certificate version must be a 32-character string.</target>
<note />
</trans-unit>
<trans-unit id="InvalidKeyVaultUrl">
<source>URL must only contain the protocol and host. (e.g.: https://&lt;vault-name&gt;.vault.azure.net/)</source>
<target state="translated">Adres URL może zawierać tylko protokół i hosta. (np. https://&lt;vault-name&gt;.vault.azure.net/)</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Sign.Cli/xlf/AzureKeyVaultResources.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<target state="translated">Nome do certificado no Azure Key Vault.</target>
<note />
</trans-unit>
<trans-unit id="CertificateVersionOptionDescription">
<source>Optional version of the Azure Key Vault certificate.</source>
<target state="new">Optional version of the Azure Key Vault certificate.</target>
<note />
</trans-unit>
<trans-unit id="ClickOnceExtensionNotSupported">
<source>ClickOnce signing via the legacy .clickonce ZIP workaround is no longer supported. See documentation.</source>
<target state="translated">Não há mais suporte para a assinatura do ClickOnce por meio da solução alternativa .clickonce ZIP herdada. Consulte a documentação.</target>
Expand All @@ -17,6 +22,11 @@
<target state="translated">Use o Azure Key Vault.</target>
<note />
</trans-unit>
<trans-unit id="InvalidCertificateVersionValue">
<source>Certificate version must be a 32-character string.</source>
<target state="new">Certificate version must be a 32-character string.</target>
<note />
</trans-unit>
<trans-unit id="InvalidKeyVaultUrl">
<source>URL must only contain the protocol and host. (e.g.: https://&lt;vault-name&gt;.vault.azure.net/)</source>
<target state="translated">A URL deve conter somente o protocolo e o host. (por exemplo: https://&lt;vault-name&gt;.vault.azure.net/)</target>
Expand Down
Loading