Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Certificate.cs
1using System;
2using System.Diagnostics.CodeAnalysis;
6
8{
12 public class Certificate
13 {
23 {
24 this.Asn1Vector = Asn1Vector;
25 this.ToBeSignedCertificate = ToBeSignedCertificate;
26 this.IssuerSignatureAlgorithm = IssuerSignatureAlgorithm;
27 this.Signature = Signature;
28 }
29
36 public static bool TryParse(byte[] RawCertificate, [NotNullWhen(true)] out Certificate? Parsed)
37 {
38 Parsed = null;
39
40 if (!ASN1.TryDecodeDer(RawCertificate, out object? Content))
41 return false;
42
43 if (Content is not Vector CertificateVector)
44 return false;
45
46 return TryParse(CertificateVector, out Parsed);
47 }
48
55 public static bool TryParse(Vector CertificateVector, [NotNullWhen(true)] out Certificate? Parsed)
56 {
57 Parsed = null;
58
59 if (CertificateVector.Length != 3)
60 return false;
61
62 if (CertificateVector.FirstElement is not Vector TbsCert)
63 return false;
64
65 if (CertificateVector[1] is not ISignatureAlgorithm IssuerSignatureAlgorithm)
66 {
67 if (CertificateVector[1] is not Vector AlgorithmIdentifier)
68 return false;
69
70 ISignatureAlgorithm? IssuerSignatureAlgorithm2 = SignatureAlgorithm.TryDecode(AlgorithmIdentifier);
71 if (IssuerSignatureAlgorithm2 is null)
72 return false;
73
74 IssuerSignatureAlgorithm = IssuerSignatureAlgorithm2;
75 }
76
77 if (CertificateVector[2] is not byte[] Signature)
78 return false;
79
80 if (!ToBeSignedCertificate.TryParse(TbsCert, out ToBeSignedCertificate? ToBeSigned))
81 return false;
82
83 Parsed = new Certificate(CertificateVector, ToBeSigned, IssuerSignatureAlgorithm, Signature);
84
85 return true;
86 }
87
92
97
101 public byte[] Signature { get; }
102
106 public Vector Asn1Vector { get; }
107
111 public byte[] Binary => this.Asn1Vector.SubSection;
112
116 public int? Version => this.ToBeSignedCertificate.Version;
117
121 public System.Numerics.BigInteger SerialNumber => this.ToBeSignedCertificate.SerialNumber;
122
126 public Names Issuer => this.ToBeSignedCertificate.Issuer;
127
131 public DateTimeOffset NotBefore => this.ToBeSignedCertificate.NotBefore;
132
136 public DateTimeOffset NotAfter => this.ToBeSignedCertificate.NotAfter;
137
141 public Names Subject => this.ToBeSignedCertificate.Subject;
142
146 public byte[]? AuthorityKeyIdentifier => this.ToBeSignedCertificate.AuthorityKeyIdentifier;
147
151 public byte[]? SubjectKeyIdentifier => this.ToBeSignedCertificate.SubjectKeyIdentifier;
152
156 public IPublicKey PublicKey => this.ToBeSignedCertificate.PublicKey;
157
161 public Vector? Extensions => this.ToBeSignedCertificate.Extensions;
162 }
163}
Static class for parsing and decoding security objects encoded using Abstract Syntax Notation 1 (ASN....
Definition: ASN1.cs:22
static bool TryDecodeDer(byte[] Data, out object? Value)
Decodes a DER-encoded object.
Definition: ASN1.cs:77
Certificate, as defined in RFC 5280, §4.1.
Definition: Certificate.cs:13
static bool TryParse(byte[] RawCertificate, [NotNullWhen(true)] out Certificate? Parsed)
Tries to parse an ASN.1-encoded Certificate, as defined in RFC 5280, §4.1.
Definition: Certificate.cs:36
byte?[] AuthorityKeyIdentifier
Authority Key Identifier
Definition: Certificate.cs:146
DateTimeOffset NotAfter
Signatures cannot be created after this timestamp.
Definition: Certificate.cs:136
ToBeSignedCertificate ToBeSignedCertificate
Certificate that is signed.
Definition: Certificate.cs:91
static bool TryParse(Vector CertificateVector, [NotNullWhen(true)] out Certificate? Parsed)
Tries to parse an ASN.1-encoded Certificate, as defined in RFC 5280, §4.1.
Definition: Certificate.cs:55
DateTimeOffset NotBefore
Signatures cannot be created before this timestamp.
Definition: Certificate.cs:131
ISignatureAlgorithm IssuerSignatureAlgorithm
Signature algorithm used by issuer to sign the certificate.
Definition: Certificate.cs:96
System.Numerics.BigInteger SerialNumber
Serial Number
Definition: Certificate.cs:121
byte[] Binary
ASN.1 DER encoded certificate.
Definition: Certificate.cs:111
Certificate, without signature, as defined in RFC 5280, §4.1
IPublicKey PublicKey
Certificate public key, used to verify signatures issued by the certificate.
DateTimeOffset NotAfter
Signatures cannot be created after this timestamp.
DateTimeOffset NotBefore
Signatures cannot be created before this timestamp.
static bool TryParse(Vector TbsCert, [NotNullWhen(true)] out ToBeSignedCertificate? Parsed)
Tries to parse an ASN.1-encoded Certificate, as defined in RFC 5280, §4.1
Abstract base class for signature algorithms, as defined in RFC 5280.
static ? ISignatureAlgorithm TryDecode(Vector AlgorithmIdentifier)
Tries to decode an ASN.1-decoded algorithm identifier into an instance of the corresponding signature...
Interface for signature algorithms, as defined in RFC 5280.
class Names(Vector NamesVector)
Contains a collection of distinguished names.
Definition: Names.cs:9