forked from bitwarden/mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
X509CertificateChainSpec.cs
42 lines (34 loc) · 1.31 KB
/
X509CertificateChainSpec.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
using System;
using System.Text;
using Bit.Core.Models;
using Java.Security;
using Java.Security.Cert;
namespace Bit.Droid.Security
{
public class X509CertificateChainSpec : ICertificateChainSpec<Java.Security.Cert.X509Certificate, IKey>
{
public string Alias { get; set; }
public IKey PrivateKeyRef { get; internal set; }
public X509Certificate RootCertificate
{
get => CertificateChain?[0];
}
public X509Certificate[] CertificateChain { get; set; }
public X509Certificate LeafCertificate {
get => CertificateChain?[CertificateChain.Length-1];
}
public string ToString(string format, IFormatProvider formatProvider)
{
if (LeafCertificate == null) {
return string.Empty;
}
StringBuilder sb = new StringBuilder();
sb.AppendLine($"Subject: {LeafCertificate.SubjectDN}");
sb.AppendLine($"Issuer: {LeafCertificate.IssuerDN}");
sb.AppendLine($"Valid From: {LeafCertificate.NotBefore}");
sb.AppendLine($"Valid Until: {LeafCertificate.NotAfter}");
return sb.ToString();
}
public override string ToString() => this.ToString(null, System.Globalization.CultureInfo.CurrentCulture);
}
}