-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
KeyVaultCertificate.cs
99 lines (84 loc) · 3.08 KB
/
KeyVaultCertificate.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Text.Json;
namespace Azure.Security.KeyVault.Certificates
{
/// <summary>
/// An Azure Key Vault certificate.
/// </summary>
public class KeyVaultCertificate : IJsonDeserializable
{
private const string KeyIdPropertyName = "kid";
private const string SecretIdPropertyName = "sid";
private const string CERPropertyName = "cer";
private string _keyId;
private string _secretId;
internal KeyVaultCertificate(CertificateProperties properties = null)
{
Properties = properties ?? new CertificateProperties();
}
/// <summary>
/// Gets the identifier of the certificate.
/// </summary>
public Uri Id => Properties.Id;
/// <summary>
/// Gets the name of the certificate.
/// </summary>
public string Name => Properties.Name;
/// <summary>
/// Gets the identifier of the Key Vault Key backing the certificate.
/// </summary>
public Uri KeyId
{
get => new Uri(_keyId);
internal set => _keyId = value?.AbsoluteUri;
}
/// <summary>
/// Gets the identifier of the Key Vault Secret which contains the PEM of PFX formatted content of the certificate and its private key.
/// </summary>
public Uri SecretId
{
get => new Uri(_secretId);
internal set => _secretId = value?.AbsoluteUri;
}
/// <summary>
/// Gets additional properties of the <see cref="KeyVaultCertificate"/>.
/// </summary>
public CertificateProperties Properties { get; }
/// <summary>
/// Gets the CER formatted public X509 certificate.
/// </summary>
/// <remarks>
/// This property contains only the public key.
/// If you must retrieve the key pair including the private key instead of performing cryptographic operations in Azure Key Vault, see the sample:
/// <see href="https://docs.microsoft.com/samples/azure/azure-sdk-for-net/get-certificate-private-key"/>
/// </remarks>
public byte[] Cer { get; internal set; }
internal virtual void ReadProperty(JsonProperty prop)
{
switch (prop.Name)
{
case KeyIdPropertyName:
_keyId = prop.Value.GetString();
break;
case SecretIdPropertyName:
_secretId = prop.Value.GetString();
break;
case CERPropertyName:
Cer = prop.Value.GetBytesFromBase64();
break;
default:
Properties.ReadProperty(prop);
break;
}
}
void IJsonDeserializable.ReadProperties(JsonElement json)
{
foreach (JsonProperty prop in json.EnumerateObject())
{
ReadProperty(prop);
}
}
}
}