init commit
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class CAKeyUpdAnnContent : Asn1Encodable
|
||||
{
|
||||
private readonly CmpCertificate oldWithNew;
|
||||
|
||||
private readonly CmpCertificate newWithOld;
|
||||
|
||||
private readonly CmpCertificate newWithNew;
|
||||
|
||||
public virtual CmpCertificate OldWithNew => oldWithNew;
|
||||
|
||||
public virtual CmpCertificate NewWithOld => newWithOld;
|
||||
|
||||
public virtual CmpCertificate NewWithNew => newWithNew;
|
||||
|
||||
private CAKeyUpdAnnContent(Asn1Sequence seq)
|
||||
{
|
||||
oldWithNew = CmpCertificate.GetInstance(seq[0]);
|
||||
newWithOld = CmpCertificate.GetInstance(seq[1]);
|
||||
newWithNew = CmpCertificate.GetInstance(seq[2]);
|
||||
}
|
||||
|
||||
public static CAKeyUpdAnnContent GetInstance(object obj)
|
||||
{
|
||||
if (obj is CAKeyUpdAnnContent)
|
||||
{
|
||||
return (CAKeyUpdAnnContent)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new CAKeyUpdAnnContent((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerSequence(oldWithNew, newWithOld, newWithNew);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class CertConfirmContent : Asn1Encodable
|
||||
{
|
||||
private readonly Asn1Sequence content;
|
||||
|
||||
private CertConfirmContent(Asn1Sequence seq)
|
||||
{
|
||||
content = seq;
|
||||
}
|
||||
|
||||
public static CertConfirmContent GetInstance(object obj)
|
||||
{
|
||||
if (obj is CertConfirmContent)
|
||||
{
|
||||
return (CertConfirmContent)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new CertConfirmContent((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public virtual CertStatus[] ToCertStatusArray()
|
||||
{
|
||||
CertStatus[] array = new CertStatus[content.Count];
|
||||
for (int i = 0; i != array.Length; i++)
|
||||
{
|
||||
array[i] = CertStatus.GetInstance(content[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Asn1.Crmf;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class CertOrEncCert : Asn1Encodable, IAsn1Choice
|
||||
{
|
||||
private readonly CmpCertificate certificate;
|
||||
|
||||
private readonly EncryptedValue encryptedCert;
|
||||
|
||||
public virtual CmpCertificate Certificate => certificate;
|
||||
|
||||
public virtual EncryptedValue EncryptedCert => encryptedCert;
|
||||
|
||||
private CertOrEncCert(Asn1TaggedObject tagged)
|
||||
{
|
||||
if (tagged.TagNo == 0)
|
||||
{
|
||||
certificate = CmpCertificate.GetInstance(tagged.GetObject());
|
||||
return;
|
||||
}
|
||||
if (tagged.TagNo == 1)
|
||||
{
|
||||
encryptedCert = EncryptedValue.GetInstance(tagged.GetObject());
|
||||
return;
|
||||
}
|
||||
throw new ArgumentException("unknown tag: " + tagged.TagNo, "tagged");
|
||||
}
|
||||
|
||||
public static CertOrEncCert GetInstance(object obj)
|
||||
{
|
||||
if (obj is CertOrEncCert)
|
||||
{
|
||||
return (CertOrEncCert)obj;
|
||||
}
|
||||
if (obj is Asn1TaggedObject)
|
||||
{
|
||||
return new CertOrEncCert((Asn1TaggedObject)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public CertOrEncCert(CmpCertificate certificate)
|
||||
{
|
||||
if (certificate == null)
|
||||
{
|
||||
throw new ArgumentNullException("certificate");
|
||||
}
|
||||
this.certificate = certificate;
|
||||
}
|
||||
|
||||
public CertOrEncCert(EncryptedValue encryptedCert)
|
||||
{
|
||||
if (encryptedCert == null)
|
||||
{
|
||||
throw new ArgumentNullException("encryptedCert");
|
||||
}
|
||||
this.encryptedCert = encryptedCert;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
if (certificate != null)
|
||||
{
|
||||
return new DerTaggedObject(explicitly: true, 0, certificate);
|
||||
}
|
||||
return new DerTaggedObject(explicitly: true, 1, encryptedCert);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class CertRepMessage : Asn1Encodable
|
||||
{
|
||||
private readonly Asn1Sequence caPubs;
|
||||
|
||||
private readonly Asn1Sequence response;
|
||||
|
||||
private CertRepMessage(Asn1Sequence seq)
|
||||
{
|
||||
int index = 0;
|
||||
if (seq.Count > 1)
|
||||
{
|
||||
caPubs = Asn1Sequence.GetInstance((Asn1TaggedObject)seq[index++], explicitly: true);
|
||||
}
|
||||
response = Asn1Sequence.GetInstance(seq[index]);
|
||||
}
|
||||
|
||||
public static CertRepMessage GetInstance(object obj)
|
||||
{
|
||||
if (obj is CertRepMessage)
|
||||
{
|
||||
return (CertRepMessage)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new CertRepMessage((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public CertRepMessage(CmpCertificate[] caPubs, CertResponse[] response)
|
||||
{
|
||||
if (response == null)
|
||||
{
|
||||
throw new ArgumentNullException("response");
|
||||
}
|
||||
if (caPubs != null)
|
||||
{
|
||||
this.caPubs = new DerSequence(caPubs);
|
||||
}
|
||||
this.response = new DerSequence(response);
|
||||
}
|
||||
|
||||
public virtual CmpCertificate[] GetCAPubs()
|
||||
{
|
||||
if (caPubs == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
CmpCertificate[] array = new CmpCertificate[caPubs.Count];
|
||||
for (int i = 0; i != array.Length; i++)
|
||||
{
|
||||
array[i] = CmpCertificate.GetInstance(caPubs[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public virtual CertResponse[] GetResponse()
|
||||
{
|
||||
CertResponse[] array = new CertResponse[response.Count];
|
||||
for (int i = 0; i != array.Length; i++)
|
||||
{
|
||||
array[i] = CertResponse.GetInstance(response[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
if (caPubs != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: true, 1, caPubs));
|
||||
}
|
||||
asn1EncodableVector.Add(response);
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class CertResponse : Asn1Encodable
|
||||
{
|
||||
private readonly DerInteger certReqId;
|
||||
|
||||
private readonly PkiStatusInfo status;
|
||||
|
||||
private readonly CertifiedKeyPair certifiedKeyPair;
|
||||
|
||||
private readonly Asn1OctetString rspInfo;
|
||||
|
||||
public virtual DerInteger CertReqID => certReqId;
|
||||
|
||||
public virtual PkiStatusInfo Status => status;
|
||||
|
||||
public virtual CertifiedKeyPair CertifiedKeyPair => certifiedKeyPair;
|
||||
|
||||
private CertResponse(Asn1Sequence seq)
|
||||
{
|
||||
certReqId = DerInteger.GetInstance(seq[0]);
|
||||
status = PkiStatusInfo.GetInstance(seq[1]);
|
||||
if (seq.Count < 3)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (seq.Count == 3)
|
||||
{
|
||||
Asn1Encodable asn1Encodable = seq[2];
|
||||
if (asn1Encodable is Asn1OctetString)
|
||||
{
|
||||
rspInfo = Asn1OctetString.GetInstance(asn1Encodable);
|
||||
}
|
||||
else
|
||||
{
|
||||
certifiedKeyPair = CertifiedKeyPair.GetInstance(asn1Encodable);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
certifiedKeyPair = CertifiedKeyPair.GetInstance(seq[2]);
|
||||
rspInfo = Asn1OctetString.GetInstance(seq[3]);
|
||||
}
|
||||
}
|
||||
|
||||
public static CertResponse GetInstance(object obj)
|
||||
{
|
||||
if (obj is CertResponse)
|
||||
{
|
||||
return (CertResponse)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new CertResponse((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public CertResponse(DerInteger certReqId, PkiStatusInfo status)
|
||||
: this(certReqId, status, null, null)
|
||||
{
|
||||
}
|
||||
|
||||
public CertResponse(DerInteger certReqId, PkiStatusInfo status, CertifiedKeyPair certifiedKeyPair, Asn1OctetString rspInfo)
|
||||
{
|
||||
if (certReqId == null)
|
||||
{
|
||||
throw new ArgumentNullException("certReqId");
|
||||
}
|
||||
if (status == null)
|
||||
{
|
||||
throw new ArgumentNullException("status");
|
||||
}
|
||||
this.certReqId = certReqId;
|
||||
this.status = status;
|
||||
this.certifiedKeyPair = certifiedKeyPair;
|
||||
this.rspInfo = rspInfo;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(certReqId, status);
|
||||
asn1EncodableVector.AddOptional(certifiedKeyPair, rspInfo);
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Math;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class CertStatus : Asn1Encodable
|
||||
{
|
||||
private readonly Asn1OctetString certHash;
|
||||
|
||||
private readonly DerInteger certReqId;
|
||||
|
||||
private readonly PkiStatusInfo statusInfo;
|
||||
|
||||
public virtual Asn1OctetString CertHash => certHash;
|
||||
|
||||
public virtual DerInteger CertReqID => certReqId;
|
||||
|
||||
public virtual PkiStatusInfo StatusInfo => statusInfo;
|
||||
|
||||
private CertStatus(Asn1Sequence seq)
|
||||
{
|
||||
certHash = Asn1OctetString.GetInstance(seq[0]);
|
||||
certReqId = DerInteger.GetInstance(seq[1]);
|
||||
if (seq.Count > 2)
|
||||
{
|
||||
statusInfo = PkiStatusInfo.GetInstance(seq[2]);
|
||||
}
|
||||
}
|
||||
|
||||
public CertStatus(byte[] certHash, BigInteger certReqId)
|
||||
{
|
||||
this.certHash = new DerOctetString(certHash);
|
||||
this.certReqId = new DerInteger(certReqId);
|
||||
}
|
||||
|
||||
public CertStatus(byte[] certHash, BigInteger certReqId, PkiStatusInfo statusInfo)
|
||||
{
|
||||
this.certHash = new DerOctetString(certHash);
|
||||
this.certReqId = new DerInteger(certReqId);
|
||||
this.statusInfo = statusInfo;
|
||||
}
|
||||
|
||||
public static CertStatus GetInstance(object obj)
|
||||
{
|
||||
if (obj is CertStatus)
|
||||
{
|
||||
return (CertStatus)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new CertStatus((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(certHash, certReqId);
|
||||
asn1EncodableVector.AddOptional(statusInfo);
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Asn1.Crmf;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class CertifiedKeyPair : Asn1Encodable
|
||||
{
|
||||
private readonly CertOrEncCert certOrEncCert;
|
||||
|
||||
private readonly EncryptedValue privateKey;
|
||||
|
||||
private readonly PkiPublicationInfo publicationInfo;
|
||||
|
||||
public virtual CertOrEncCert CertOrEncCert => certOrEncCert;
|
||||
|
||||
public virtual EncryptedValue PrivateKey => privateKey;
|
||||
|
||||
public virtual PkiPublicationInfo PublicationInfo => publicationInfo;
|
||||
|
||||
private CertifiedKeyPair(Asn1Sequence seq)
|
||||
{
|
||||
certOrEncCert = CertOrEncCert.GetInstance(seq[0]);
|
||||
if (seq.Count < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (seq.Count == 2)
|
||||
{
|
||||
Asn1TaggedObject instance = Asn1TaggedObject.GetInstance(seq[1]);
|
||||
if (instance.TagNo == 0)
|
||||
{
|
||||
privateKey = EncryptedValue.GetInstance(instance.GetObject());
|
||||
}
|
||||
else
|
||||
{
|
||||
publicationInfo = PkiPublicationInfo.GetInstance(instance.GetObject());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
privateKey = EncryptedValue.GetInstance(Asn1TaggedObject.GetInstance(seq[1]));
|
||||
publicationInfo = PkiPublicationInfo.GetInstance(Asn1TaggedObject.GetInstance(seq[2]));
|
||||
}
|
||||
}
|
||||
|
||||
public static CertifiedKeyPair GetInstance(object obj)
|
||||
{
|
||||
if (obj is CertifiedKeyPair)
|
||||
{
|
||||
return (CertifiedKeyPair)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new CertifiedKeyPair((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public CertifiedKeyPair(CertOrEncCert certOrEncCert)
|
||||
: this(certOrEncCert, null, null)
|
||||
{
|
||||
}
|
||||
|
||||
public CertifiedKeyPair(CertOrEncCert certOrEncCert, EncryptedValue privateKey, PkiPublicationInfo publicationInfo)
|
||||
{
|
||||
if (certOrEncCert == null)
|
||||
{
|
||||
throw new ArgumentNullException("certOrEncCert");
|
||||
}
|
||||
this.certOrEncCert = certOrEncCert;
|
||||
this.privateKey = privateKey;
|
||||
this.publicationInfo = publicationInfo;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(certOrEncCert);
|
||||
if (privateKey != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: true, 0, privateKey));
|
||||
}
|
||||
if (publicationInfo != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: true, 1, publicationInfo));
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class Challenge : Asn1Encodable
|
||||
{
|
||||
private readonly AlgorithmIdentifier owf;
|
||||
|
||||
private readonly Asn1OctetString witness;
|
||||
|
||||
private readonly Asn1OctetString challenge;
|
||||
|
||||
public virtual AlgorithmIdentifier Owf => owf;
|
||||
|
||||
private Challenge(Asn1Sequence seq)
|
||||
{
|
||||
int index = 0;
|
||||
if (seq.Count == 3)
|
||||
{
|
||||
owf = AlgorithmIdentifier.GetInstance(seq[index++]);
|
||||
}
|
||||
witness = Asn1OctetString.GetInstance(seq[index++]);
|
||||
challenge = Asn1OctetString.GetInstance(seq[index]);
|
||||
}
|
||||
|
||||
public static Challenge GetInstance(object obj)
|
||||
{
|
||||
if (obj is Challenge)
|
||||
{
|
||||
return (Challenge)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new Challenge((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
asn1EncodableVector.AddOptional(owf);
|
||||
asn1EncodableVector.Add(witness);
|
||||
asn1EncodableVector.Add(challenge);
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class CmpCertificate : Asn1Encodable, IAsn1Choice
|
||||
{
|
||||
private readonly X509CertificateStructure x509v3PKCert;
|
||||
|
||||
private readonly AttributeCertificate x509v2AttrCert;
|
||||
|
||||
public virtual bool IsX509v3PKCert => x509v3PKCert != null;
|
||||
|
||||
public virtual X509CertificateStructure X509v3PKCert => x509v3PKCert;
|
||||
|
||||
public virtual AttributeCertificate X509v2AttrCert => x509v2AttrCert;
|
||||
|
||||
public CmpCertificate(AttributeCertificate x509v2AttrCert)
|
||||
{
|
||||
this.x509v2AttrCert = x509v2AttrCert;
|
||||
}
|
||||
|
||||
public CmpCertificate(X509CertificateStructure x509v3PKCert)
|
||||
{
|
||||
if (x509v3PKCert.Version != 3)
|
||||
{
|
||||
throw new ArgumentException("only version 3 certificates allowed", "x509v3PKCert");
|
||||
}
|
||||
this.x509v3PKCert = x509v3PKCert;
|
||||
}
|
||||
|
||||
public static CmpCertificate GetInstance(object obj)
|
||||
{
|
||||
if (obj is CmpCertificate)
|
||||
{
|
||||
return (CmpCertificate)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new CmpCertificate(X509CertificateStructure.GetInstance(obj));
|
||||
}
|
||||
if (obj is Asn1TaggedObject)
|
||||
{
|
||||
return new CmpCertificate(AttributeCertificate.GetInstance(((Asn1TaggedObject)obj).GetObject()));
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
if (x509v2AttrCert != null)
|
||||
{
|
||||
return new DerTaggedObject(explicitly: true, 1, x509v2AttrCert);
|
||||
}
|
||||
return x509v3PKCert.ToAsn1Object();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public abstract class CmpObjectIdentifiers
|
||||
{
|
||||
public static readonly DerObjectIdentifier passwordBasedMac = new DerObjectIdentifier("1.2.840.113533.7.66.13");
|
||||
|
||||
public static readonly DerObjectIdentifier dhBasedMac = new DerObjectIdentifier("1.2.840.113533.7.66.30");
|
||||
|
||||
public static readonly DerObjectIdentifier it_caProtEncCert = new DerObjectIdentifier("1.3.6.1.5.5.7.4.1");
|
||||
|
||||
public static readonly DerObjectIdentifier it_signKeyPairTypes = new DerObjectIdentifier("1.3.6.1.5.5.7.4.2");
|
||||
|
||||
public static readonly DerObjectIdentifier it_encKeyPairTypes = new DerObjectIdentifier("1.3.6.1.5.5.7.4.3");
|
||||
|
||||
public static readonly DerObjectIdentifier it_preferredSymAlg = new DerObjectIdentifier("1.3.6.1.5.5.7.4.4");
|
||||
|
||||
public static readonly DerObjectIdentifier it_caKeyUpdateInfo = new DerObjectIdentifier("1.3.6.1.5.5.7.4.5");
|
||||
|
||||
public static readonly DerObjectIdentifier it_currentCRL = new DerObjectIdentifier("1.3.6.1.5.5.7.4.6");
|
||||
|
||||
public static readonly DerObjectIdentifier it_unsupportedOIDs = new DerObjectIdentifier("1.3.6.1.5.5.7.4.7");
|
||||
|
||||
public static readonly DerObjectIdentifier it_keyPairParamReq = new DerObjectIdentifier("1.3.6.1.5.5.7.4.10");
|
||||
|
||||
public static readonly DerObjectIdentifier it_keyPairParamRep = new DerObjectIdentifier("1.3.6.1.5.5.7.4.11");
|
||||
|
||||
public static readonly DerObjectIdentifier it_revPassphrase = new DerObjectIdentifier("1.3.6.1.5.5.7.4.12");
|
||||
|
||||
public static readonly DerObjectIdentifier it_implicitConfirm = new DerObjectIdentifier("1.3.6.1.5.5.7.4.13");
|
||||
|
||||
public static readonly DerObjectIdentifier it_confirmWaitTime = new DerObjectIdentifier("1.3.6.1.5.5.7.4.14");
|
||||
|
||||
public static readonly DerObjectIdentifier it_origPKIMessage = new DerObjectIdentifier("1.3.6.1.5.5.7.4.15");
|
||||
|
||||
public static readonly DerObjectIdentifier it_suppLangTags = new DerObjectIdentifier("1.3.6.1.5.5.7.4.16");
|
||||
|
||||
public static readonly DerObjectIdentifier regCtrl_regToken = new DerObjectIdentifier("1.3.6.1.5.5.7.5.1.1");
|
||||
|
||||
public static readonly DerObjectIdentifier regCtrl_authenticator = new DerObjectIdentifier("1.3.6.1.5.5.7.5.1.2");
|
||||
|
||||
public static readonly DerObjectIdentifier regCtrl_pkiPublicationInfo = new DerObjectIdentifier("1.3.6.1.5.5.7.5.1.3");
|
||||
|
||||
public static readonly DerObjectIdentifier regCtrl_pkiArchiveOptions = new DerObjectIdentifier("1.3.6.1.5.5.7.5.1.4");
|
||||
|
||||
public static readonly DerObjectIdentifier regCtrl_oldCertID = new DerObjectIdentifier("1.3.6.1.5.5.7.5.1.5");
|
||||
|
||||
public static readonly DerObjectIdentifier regCtrl_protocolEncrKey = new DerObjectIdentifier("1.3.6.1.5.5.7.5.1.6");
|
||||
|
||||
public static readonly DerObjectIdentifier regCtrl_altCertTemplate = new DerObjectIdentifier("1.3.6.1.5.5.7.5.1.7");
|
||||
|
||||
public static readonly DerObjectIdentifier regInfo_utf8Pairs = new DerObjectIdentifier("1.3.6.1.5.5.7.5.2.1");
|
||||
|
||||
public static readonly DerObjectIdentifier regInfo_certReq = new DerObjectIdentifier("1.3.6.1.5.5.7.5.2.2");
|
||||
|
||||
public static readonly DerObjectIdentifier ct_encKeyWithID = new DerObjectIdentifier("1.2.840.113549.1.9.16.1.21");
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class CrlAnnContent : Asn1Encodable
|
||||
{
|
||||
private readonly Asn1Sequence content;
|
||||
|
||||
private CrlAnnContent(Asn1Sequence seq)
|
||||
{
|
||||
content = seq;
|
||||
}
|
||||
|
||||
public static CrlAnnContent GetInstance(object obj)
|
||||
{
|
||||
if (obj is CrlAnnContent)
|
||||
{
|
||||
return (CrlAnnContent)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new CrlAnnContent((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public virtual CertificateList[] ToCertificateListArray()
|
||||
{
|
||||
CertificateList[] array = new CertificateList[content.Count];
|
||||
for (int i = 0; i != array.Length; i++)
|
||||
{
|
||||
array[i] = CertificateList.GetInstance(content[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class ErrorMsgContent : Asn1Encodable
|
||||
{
|
||||
private readonly PkiStatusInfo pkiStatusInfo;
|
||||
|
||||
private readonly DerInteger errorCode;
|
||||
|
||||
private readonly PkiFreeText errorDetails;
|
||||
|
||||
public virtual PkiStatusInfo PkiStatusInfo => pkiStatusInfo;
|
||||
|
||||
public virtual DerInteger ErrorCode => errorCode;
|
||||
|
||||
public virtual PkiFreeText ErrorDetails => errorDetails;
|
||||
|
||||
private ErrorMsgContent(Asn1Sequence seq)
|
||||
{
|
||||
pkiStatusInfo = PkiStatusInfo.GetInstance(seq[0]);
|
||||
for (int i = 1; i < seq.Count; i++)
|
||||
{
|
||||
Asn1Encodable asn1Encodable = seq[i];
|
||||
if (asn1Encodable is DerInteger)
|
||||
{
|
||||
errorCode = DerInteger.GetInstance(asn1Encodable);
|
||||
}
|
||||
else
|
||||
{
|
||||
errorDetails = PkiFreeText.GetInstance(asn1Encodable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ErrorMsgContent GetInstance(object obj)
|
||||
{
|
||||
if (obj is ErrorMsgContent)
|
||||
{
|
||||
return (ErrorMsgContent)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new ErrorMsgContent((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public ErrorMsgContent(PkiStatusInfo pkiStatusInfo)
|
||||
: this(pkiStatusInfo, null, null)
|
||||
{
|
||||
}
|
||||
|
||||
public ErrorMsgContent(PkiStatusInfo pkiStatusInfo, DerInteger errorCode, PkiFreeText errorDetails)
|
||||
{
|
||||
if (pkiStatusInfo == null)
|
||||
{
|
||||
throw new ArgumentNullException("pkiStatusInfo");
|
||||
}
|
||||
this.pkiStatusInfo = pkiStatusInfo;
|
||||
this.errorCode = errorCode;
|
||||
this.errorDetails = errorDetails;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(pkiStatusInfo);
|
||||
asn1EncodableVector.AddOptional(errorCode, errorDetails);
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class GenMsgContent : Asn1Encodable
|
||||
{
|
||||
private readonly Asn1Sequence content;
|
||||
|
||||
private GenMsgContent(Asn1Sequence seq)
|
||||
{
|
||||
content = seq;
|
||||
}
|
||||
|
||||
public static GenMsgContent GetInstance(object obj)
|
||||
{
|
||||
if (obj is GenMsgContent)
|
||||
{
|
||||
return (GenMsgContent)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new GenMsgContent((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public GenMsgContent(params InfoTypeAndValue[] itv)
|
||||
{
|
||||
content = new DerSequence(itv);
|
||||
}
|
||||
|
||||
public virtual InfoTypeAndValue[] ToInfoTypeAndValueArray()
|
||||
{
|
||||
InfoTypeAndValue[] array = new InfoTypeAndValue[content.Count];
|
||||
for (int i = 0; i != array.Length; i++)
|
||||
{
|
||||
array[i] = InfoTypeAndValue.GetInstance(content[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class GenRepContent : Asn1Encodable
|
||||
{
|
||||
private readonly Asn1Sequence content;
|
||||
|
||||
private GenRepContent(Asn1Sequence seq)
|
||||
{
|
||||
content = seq;
|
||||
}
|
||||
|
||||
public static GenRepContent GetInstance(object obj)
|
||||
{
|
||||
if (obj is GenRepContent)
|
||||
{
|
||||
return (GenRepContent)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new GenRepContent((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public GenRepContent(params InfoTypeAndValue[] itv)
|
||||
{
|
||||
content = new DerSequence(itv);
|
||||
}
|
||||
|
||||
public virtual InfoTypeAndValue[] ToInfoTypeAndValueArray()
|
||||
{
|
||||
InfoTypeAndValue[] array = new InfoTypeAndValue[content.Count];
|
||||
for (int i = 0; i != array.Length; i++)
|
||||
{
|
||||
array[i] = InfoTypeAndValue.GetInstance(content[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class InfoTypeAndValue : Asn1Encodable
|
||||
{
|
||||
private readonly DerObjectIdentifier infoType;
|
||||
|
||||
private readonly Asn1Encodable infoValue;
|
||||
|
||||
public virtual DerObjectIdentifier InfoType => infoType;
|
||||
|
||||
public virtual Asn1Encodable InfoValue => infoValue;
|
||||
|
||||
private InfoTypeAndValue(Asn1Sequence seq)
|
||||
{
|
||||
infoType = DerObjectIdentifier.GetInstance(seq[0]);
|
||||
if (seq.Count > 1)
|
||||
{
|
||||
infoValue = seq[1];
|
||||
}
|
||||
}
|
||||
|
||||
public static InfoTypeAndValue GetInstance(object obj)
|
||||
{
|
||||
if (obj is InfoTypeAndValue)
|
||||
{
|
||||
return (InfoTypeAndValue)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new InfoTypeAndValue((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public InfoTypeAndValue(DerObjectIdentifier infoType)
|
||||
{
|
||||
this.infoType = infoType;
|
||||
infoValue = null;
|
||||
}
|
||||
|
||||
public InfoTypeAndValue(DerObjectIdentifier infoType, Asn1Encodable optionalValue)
|
||||
{
|
||||
this.infoType = infoType;
|
||||
infoValue = optionalValue;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(infoType);
|
||||
if (infoValue != null)
|
||||
{
|
||||
asn1EncodableVector.Add(infoValue);
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class KeyRecRepContent : Asn1Encodable
|
||||
{
|
||||
private readonly PkiStatusInfo status;
|
||||
|
||||
private readonly CmpCertificate newSigCert;
|
||||
|
||||
private readonly Asn1Sequence caCerts;
|
||||
|
||||
private readonly Asn1Sequence keyPairHist;
|
||||
|
||||
public virtual PkiStatusInfo Status => status;
|
||||
|
||||
public virtual CmpCertificate NewSigCert => newSigCert;
|
||||
|
||||
private KeyRecRepContent(Asn1Sequence seq)
|
||||
{
|
||||
status = PkiStatusInfo.GetInstance(seq[0]);
|
||||
for (int i = 1; i < seq.Count; i++)
|
||||
{
|
||||
Asn1TaggedObject instance = Asn1TaggedObject.GetInstance(seq[i]);
|
||||
switch (instance.TagNo)
|
||||
{
|
||||
case 0:
|
||||
newSigCert = CmpCertificate.GetInstance(instance.GetObject());
|
||||
break;
|
||||
case 1:
|
||||
caCerts = Asn1Sequence.GetInstance(instance.GetObject());
|
||||
break;
|
||||
case 2:
|
||||
keyPairHist = Asn1Sequence.GetInstance(instance.GetObject());
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("unknown tag number: " + instance.TagNo, "seq");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static KeyRecRepContent GetInstance(object obj)
|
||||
{
|
||||
if (obj is KeyRecRepContent)
|
||||
{
|
||||
return (KeyRecRepContent)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new KeyRecRepContent((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public virtual CmpCertificate[] GetCACerts()
|
||||
{
|
||||
if (caCerts == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
CmpCertificate[] array = new CmpCertificate[caCerts.Count];
|
||||
for (int i = 0; i != array.Length; i++)
|
||||
{
|
||||
array[i] = CmpCertificate.GetInstance(caCerts[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public virtual CertifiedKeyPair[] GetKeyPairHist()
|
||||
{
|
||||
if (keyPairHist == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
CertifiedKeyPair[] array = new CertifiedKeyPair[keyPairHist.Count];
|
||||
for (int i = 0; i != array.Length; i++)
|
||||
{
|
||||
array[i] = CertifiedKeyPair.GetInstance(keyPairHist[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector v = new Asn1EncodableVector(status);
|
||||
AddOptional(v, 0, newSigCert);
|
||||
AddOptional(v, 1, caCerts);
|
||||
AddOptional(v, 2, keyPairHist);
|
||||
return new DerSequence(v);
|
||||
}
|
||||
|
||||
private void AddOptional(Asn1EncodableVector v, int tagNo, Asn1Encodable obj)
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
v.Add(new DerTaggedObject(explicitly: true, tagNo, obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Asn1.Crmf;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class OobCertHash : Asn1Encodable
|
||||
{
|
||||
private readonly AlgorithmIdentifier hashAlg;
|
||||
|
||||
private readonly CertId certId;
|
||||
|
||||
private readonly DerBitString hashVal;
|
||||
|
||||
public virtual AlgorithmIdentifier HashAlg => hashAlg;
|
||||
|
||||
public virtual CertId CertID => certId;
|
||||
|
||||
private OobCertHash(Asn1Sequence seq)
|
||||
{
|
||||
int num = seq.Count - 1;
|
||||
hashVal = DerBitString.GetInstance(seq[num--]);
|
||||
for (int num2 = num; num2 >= 0; num2--)
|
||||
{
|
||||
Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)seq[num2];
|
||||
if (asn1TaggedObject.TagNo == 0)
|
||||
{
|
||||
hashAlg = AlgorithmIdentifier.GetInstance(asn1TaggedObject, explicitly: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
certId = CertId.GetInstance(asn1TaggedObject, isExplicit: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static OobCertHash GetInstance(object obj)
|
||||
{
|
||||
if (obj is OobCertHash)
|
||||
{
|
||||
return (OobCertHash)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new OobCertHash((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
AddOptional(asn1EncodableVector, 0, hashAlg);
|
||||
AddOptional(asn1EncodableVector, 1, certId);
|
||||
asn1EncodableVector.Add(hashVal);
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
|
||||
private void AddOptional(Asn1EncodableVector v, int tagNo, Asn1Encodable obj)
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
v.Add(new DerTaggedObject(explicitly: true, tagNo, obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class PbmParameter : Asn1Encodable
|
||||
{
|
||||
private Asn1OctetString salt;
|
||||
|
||||
private AlgorithmIdentifier owf;
|
||||
|
||||
private DerInteger iterationCount;
|
||||
|
||||
private AlgorithmIdentifier mac;
|
||||
|
||||
public virtual Asn1OctetString Salt => salt;
|
||||
|
||||
public virtual AlgorithmIdentifier Owf => owf;
|
||||
|
||||
public virtual DerInteger IterationCount => iterationCount;
|
||||
|
||||
public virtual AlgorithmIdentifier Mac => mac;
|
||||
|
||||
private PbmParameter(Asn1Sequence seq)
|
||||
{
|
||||
salt = Asn1OctetString.GetInstance(seq[0]);
|
||||
owf = AlgorithmIdentifier.GetInstance(seq[1]);
|
||||
iterationCount = DerInteger.GetInstance(seq[2]);
|
||||
mac = AlgorithmIdentifier.GetInstance(seq[3]);
|
||||
}
|
||||
|
||||
public static PbmParameter GetInstance(object obj)
|
||||
{
|
||||
if (obj is PbmParameter)
|
||||
{
|
||||
return (PbmParameter)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new PbmParameter((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public PbmParameter(byte[] salt, AlgorithmIdentifier owf, int iterationCount, AlgorithmIdentifier mac)
|
||||
: this(new DerOctetString(salt), owf, new DerInteger(iterationCount), mac)
|
||||
{
|
||||
}
|
||||
|
||||
public PbmParameter(Asn1OctetString salt, AlgorithmIdentifier owf, DerInteger iterationCount, AlgorithmIdentifier mac)
|
||||
{
|
||||
this.salt = salt;
|
||||
this.owf = owf;
|
||||
this.iterationCount = iterationCount;
|
||||
this.mac = mac;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerSequence(salt, owf, iterationCount, mac);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Asn1.Crmf;
|
||||
using Org.BouncyCastle.Asn1.Pkcs;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class PkiBody : Asn1Encodable, IAsn1Choice
|
||||
{
|
||||
public const int TYPE_INIT_REQ = 0;
|
||||
|
||||
public const int TYPE_INIT_REP = 1;
|
||||
|
||||
public const int TYPE_CERT_REQ = 2;
|
||||
|
||||
public const int TYPE_CERT_REP = 3;
|
||||
|
||||
public const int TYPE_P10_CERT_REQ = 4;
|
||||
|
||||
public const int TYPE_POPO_CHALL = 5;
|
||||
|
||||
public const int TYPE_POPO_REP = 6;
|
||||
|
||||
public const int TYPE_KEY_UPDATE_REQ = 7;
|
||||
|
||||
public const int TYPE_KEY_UPDATE_REP = 8;
|
||||
|
||||
public const int TYPE_KEY_RECOVERY_REQ = 9;
|
||||
|
||||
public const int TYPE_KEY_RECOVERY_REP = 10;
|
||||
|
||||
public const int TYPE_REVOCATION_REQ = 11;
|
||||
|
||||
public const int TYPE_REVOCATION_REP = 12;
|
||||
|
||||
public const int TYPE_CROSS_CERT_REQ = 13;
|
||||
|
||||
public const int TYPE_CROSS_CERT_REP = 14;
|
||||
|
||||
public const int TYPE_CA_KEY_UPDATE_ANN = 15;
|
||||
|
||||
public const int TYPE_CERT_ANN = 16;
|
||||
|
||||
public const int TYPE_REVOCATION_ANN = 17;
|
||||
|
||||
public const int TYPE_CRL_ANN = 18;
|
||||
|
||||
public const int TYPE_CONFIRM = 19;
|
||||
|
||||
public const int TYPE_NESTED = 20;
|
||||
|
||||
public const int TYPE_GEN_MSG = 21;
|
||||
|
||||
public const int TYPE_GEN_REP = 22;
|
||||
|
||||
public const int TYPE_ERROR = 23;
|
||||
|
||||
public const int TYPE_CERT_CONFIRM = 24;
|
||||
|
||||
public const int TYPE_POLL_REQ = 25;
|
||||
|
||||
public const int TYPE_POLL_REP = 26;
|
||||
|
||||
private int tagNo;
|
||||
|
||||
private Asn1Encodable body;
|
||||
|
||||
public virtual int Type => tagNo;
|
||||
|
||||
public virtual Asn1Encodable Content => body;
|
||||
|
||||
public static PkiBody GetInstance(object obj)
|
||||
{
|
||||
if (obj is PkiBody)
|
||||
{
|
||||
return (PkiBody)obj;
|
||||
}
|
||||
if (obj is Asn1TaggedObject)
|
||||
{
|
||||
return new PkiBody((Asn1TaggedObject)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
private PkiBody(Asn1TaggedObject tagged)
|
||||
{
|
||||
tagNo = tagged.TagNo;
|
||||
body = GetBodyForType(tagNo, tagged.GetObject());
|
||||
}
|
||||
|
||||
public PkiBody(int type, Asn1Encodable content)
|
||||
{
|
||||
tagNo = type;
|
||||
body = GetBodyForType(type, content);
|
||||
}
|
||||
|
||||
private static Asn1Encodable GetBodyForType(int type, Asn1Encodable o)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
0 => CertReqMessages.GetInstance(o),
|
||||
1 => CertRepMessage.GetInstance(o),
|
||||
2 => CertReqMessages.GetInstance(o),
|
||||
3 => CertRepMessage.GetInstance(o),
|
||||
4 => CertificationRequest.GetInstance(o),
|
||||
5 => PopoDecKeyChallContent.GetInstance(o),
|
||||
6 => PopoDecKeyRespContent.GetInstance(o),
|
||||
7 => CertReqMessages.GetInstance(o),
|
||||
8 => CertRepMessage.GetInstance(o),
|
||||
9 => CertReqMessages.GetInstance(o),
|
||||
10 => KeyRecRepContent.GetInstance(o),
|
||||
11 => RevReqContent.GetInstance(o),
|
||||
12 => RevRepContent.GetInstance(o),
|
||||
13 => CertReqMessages.GetInstance(o),
|
||||
14 => CertRepMessage.GetInstance(o),
|
||||
15 => CAKeyUpdAnnContent.GetInstance(o),
|
||||
16 => CmpCertificate.GetInstance(o),
|
||||
17 => RevAnnContent.GetInstance(o),
|
||||
18 => CrlAnnContent.GetInstance(o),
|
||||
19 => PkiConfirmContent.GetInstance(o),
|
||||
20 => PkiMessages.GetInstance(o),
|
||||
21 => GenMsgContent.GetInstance(o),
|
||||
22 => GenRepContent.GetInstance(o),
|
||||
23 => ErrorMsgContent.GetInstance(o),
|
||||
24 => CertConfirmContent.GetInstance(o),
|
||||
25 => PollReqContent.GetInstance(o),
|
||||
26 => PollRepContent.GetInstance(o),
|
||||
_ => throw new ArgumentException("unknown tag number: " + type, "type"),
|
||||
};
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerTaggedObject(explicitly: true, tagNo, body);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class PkiConfirmContent : Asn1Encodable
|
||||
{
|
||||
public static PkiConfirmContent GetInstance(object obj)
|
||||
{
|
||||
if (obj is PkiConfirmContent)
|
||||
{
|
||||
return (PkiConfirmContent)obj;
|
||||
}
|
||||
if (obj is Asn1Null)
|
||||
{
|
||||
return new PkiConfirmContent();
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return DerNull.Instance;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class PkiFailureInfo : DerBitString
|
||||
{
|
||||
public const int BadAlg = 128;
|
||||
|
||||
public const int BadMessageCheck = 64;
|
||||
|
||||
public const int BadRequest = 32;
|
||||
|
||||
public const int BadTime = 16;
|
||||
|
||||
public const int BadCertId = 8;
|
||||
|
||||
public const int BadDataFormat = 4;
|
||||
|
||||
public const int WrongAuthority = 2;
|
||||
|
||||
public const int IncorrectData = 1;
|
||||
|
||||
public const int MissingTimeStamp = 32768;
|
||||
|
||||
public const int BadPop = 16384;
|
||||
|
||||
public const int CertRevoked = 8192;
|
||||
|
||||
public const int CertConfirmed = 4096;
|
||||
|
||||
public const int WrongIntegrity = 2048;
|
||||
|
||||
public const int BadRecipientNonce = 1024;
|
||||
|
||||
public const int TimeNotAvailable = 512;
|
||||
|
||||
public const int UnacceptedPolicy = 256;
|
||||
|
||||
public const int UnacceptedExtension = 8388608;
|
||||
|
||||
public const int AddInfoNotAvailable = 4194304;
|
||||
|
||||
public const int BadSenderNonce = 2097152;
|
||||
|
||||
public const int BadCertTemplate = 1048576;
|
||||
|
||||
public const int SignerNotTrusted = 524288;
|
||||
|
||||
public const int TransactionIdInUse = 262144;
|
||||
|
||||
public const int UnsupportedVersion = 131072;
|
||||
|
||||
public const int NotAuthorized = 65536;
|
||||
|
||||
public const int SystemUnavail = int.MinValue;
|
||||
|
||||
public const int SystemFailure = 1073741824;
|
||||
|
||||
public const int DuplicateCertReq = 536870912;
|
||||
|
||||
public PkiFailureInfo(int info)
|
||||
: base(info)
|
||||
{
|
||||
}
|
||||
|
||||
public PkiFailureInfo(DerBitString info)
|
||||
: base(info.GetBytes(), info.PadBits)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "PkiFailureInfo: 0x" + IntValue.ToString("X");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class PkiFreeText : Asn1Encodable
|
||||
{
|
||||
internal Asn1Sequence strings;
|
||||
|
||||
[Obsolete("Use 'Count' property instead")]
|
||||
public int Size => strings.Count;
|
||||
|
||||
public int Count => strings.Count;
|
||||
|
||||
public DerUtf8String this[int index] => (DerUtf8String)strings[index];
|
||||
|
||||
public static PkiFreeText GetInstance(Asn1TaggedObject obj, bool isExplicit)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
|
||||
}
|
||||
|
||||
public static PkiFreeText GetInstance(object obj)
|
||||
{
|
||||
if (obj is PkiFreeText)
|
||||
{
|
||||
return (PkiFreeText)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new PkiFreeText((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public PkiFreeText(Asn1Sequence seq)
|
||||
{
|
||||
foreach (object item in seq)
|
||||
{
|
||||
if (!(item is DerUtf8String))
|
||||
{
|
||||
throw new ArgumentException("attempt to insert non UTF8 STRING into PkiFreeText");
|
||||
}
|
||||
}
|
||||
strings = seq;
|
||||
}
|
||||
|
||||
public PkiFreeText(DerUtf8String p)
|
||||
{
|
||||
strings = new DerSequence(p);
|
||||
}
|
||||
|
||||
[Obsolete("Use 'object[index]' syntax instead")]
|
||||
public DerUtf8String GetStringAt(int index)
|
||||
{
|
||||
return this[index];
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return strings;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class PkiHeader : Asn1Encodable
|
||||
{
|
||||
public static readonly GeneralName NULL_NAME = new GeneralName(X509Name.GetInstance(new DerSequence()));
|
||||
|
||||
public static readonly int CMP_1999 = 1;
|
||||
|
||||
public static readonly int CMP_2000 = 2;
|
||||
|
||||
private readonly DerInteger pvno;
|
||||
|
||||
private readonly GeneralName sender;
|
||||
|
||||
private readonly GeneralName recipient;
|
||||
|
||||
private readonly DerGeneralizedTime messageTime;
|
||||
|
||||
private readonly AlgorithmIdentifier protectionAlg;
|
||||
|
||||
private readonly Asn1OctetString senderKID;
|
||||
|
||||
private readonly Asn1OctetString recipKID;
|
||||
|
||||
private readonly Asn1OctetString transactionID;
|
||||
|
||||
private readonly Asn1OctetString senderNonce;
|
||||
|
||||
private readonly Asn1OctetString recipNonce;
|
||||
|
||||
private readonly PkiFreeText freeText;
|
||||
|
||||
private readonly Asn1Sequence generalInfo;
|
||||
|
||||
public virtual DerInteger Pvno => pvno;
|
||||
|
||||
public virtual GeneralName Sender => sender;
|
||||
|
||||
public virtual GeneralName Recipient => recipient;
|
||||
|
||||
public virtual DerGeneralizedTime MessageTime => messageTime;
|
||||
|
||||
public virtual AlgorithmIdentifier ProtectionAlg => protectionAlg;
|
||||
|
||||
public virtual Asn1OctetString SenderKID => senderKID;
|
||||
|
||||
public virtual Asn1OctetString RecipKID => recipKID;
|
||||
|
||||
public virtual Asn1OctetString TransactionID => transactionID;
|
||||
|
||||
public virtual Asn1OctetString SenderNonce => senderNonce;
|
||||
|
||||
public virtual Asn1OctetString RecipNonce => recipNonce;
|
||||
|
||||
public virtual PkiFreeText FreeText => freeText;
|
||||
|
||||
private PkiHeader(Asn1Sequence seq)
|
||||
{
|
||||
pvno = DerInteger.GetInstance(seq[0]);
|
||||
sender = GeneralName.GetInstance(seq[1]);
|
||||
recipient = GeneralName.GetInstance(seq[2]);
|
||||
for (int i = 3; i < seq.Count; i++)
|
||||
{
|
||||
Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)seq[i];
|
||||
switch (asn1TaggedObject.TagNo)
|
||||
{
|
||||
case 0:
|
||||
messageTime = DerGeneralizedTime.GetInstance(asn1TaggedObject, isExplicit: true);
|
||||
break;
|
||||
case 1:
|
||||
protectionAlg = AlgorithmIdentifier.GetInstance(asn1TaggedObject, explicitly: true);
|
||||
break;
|
||||
case 2:
|
||||
senderKID = Asn1OctetString.GetInstance(asn1TaggedObject, isExplicit: true);
|
||||
break;
|
||||
case 3:
|
||||
recipKID = Asn1OctetString.GetInstance(asn1TaggedObject, isExplicit: true);
|
||||
break;
|
||||
case 4:
|
||||
transactionID = Asn1OctetString.GetInstance(asn1TaggedObject, isExplicit: true);
|
||||
break;
|
||||
case 5:
|
||||
senderNonce = Asn1OctetString.GetInstance(asn1TaggedObject, isExplicit: true);
|
||||
break;
|
||||
case 6:
|
||||
recipNonce = Asn1OctetString.GetInstance(asn1TaggedObject, isExplicit: true);
|
||||
break;
|
||||
case 7:
|
||||
freeText = PkiFreeText.GetInstance(asn1TaggedObject, isExplicit: true);
|
||||
break;
|
||||
case 8:
|
||||
generalInfo = Asn1Sequence.GetInstance(asn1TaggedObject, explicitly: true);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("unknown tag number: " + asn1TaggedObject.TagNo, "seq");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static PkiHeader GetInstance(object obj)
|
||||
{
|
||||
if (obj is PkiHeader)
|
||||
{
|
||||
return (PkiHeader)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new PkiHeader((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public PkiHeader(int pvno, GeneralName sender, GeneralName recipient)
|
||||
: this(new DerInteger(pvno), sender, recipient)
|
||||
{
|
||||
}
|
||||
|
||||
private PkiHeader(DerInteger pvno, GeneralName sender, GeneralName recipient)
|
||||
{
|
||||
this.pvno = pvno;
|
||||
this.sender = sender;
|
||||
this.recipient = recipient;
|
||||
}
|
||||
|
||||
public virtual InfoTypeAndValue[] GetGeneralInfo()
|
||||
{
|
||||
if (generalInfo == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
InfoTypeAndValue[] array = new InfoTypeAndValue[generalInfo.Count];
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
array[i] = InfoTypeAndValue.GetInstance(generalInfo[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector v = new Asn1EncodableVector(pvno, sender, recipient);
|
||||
AddOptional(v, 0, messageTime);
|
||||
AddOptional(v, 1, protectionAlg);
|
||||
AddOptional(v, 2, senderKID);
|
||||
AddOptional(v, 3, recipKID);
|
||||
AddOptional(v, 4, transactionID);
|
||||
AddOptional(v, 5, senderNonce);
|
||||
AddOptional(v, 6, recipNonce);
|
||||
AddOptional(v, 7, freeText);
|
||||
AddOptional(v, 8, generalInfo);
|
||||
return new DerSequence(v);
|
||||
}
|
||||
|
||||
private static void AddOptional(Asn1EncodableVector v, int tagNo, Asn1Encodable obj)
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
v.Add(new DerTaggedObject(explicitly: true, tagNo, obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class PkiHeaderBuilder
|
||||
{
|
||||
private DerInteger pvno;
|
||||
|
||||
private GeneralName sender;
|
||||
|
||||
private GeneralName recipient;
|
||||
|
||||
private DerGeneralizedTime messageTime;
|
||||
|
||||
private AlgorithmIdentifier protectionAlg;
|
||||
|
||||
private Asn1OctetString senderKID;
|
||||
|
||||
private Asn1OctetString recipKID;
|
||||
|
||||
private Asn1OctetString transactionID;
|
||||
|
||||
private Asn1OctetString senderNonce;
|
||||
|
||||
private Asn1OctetString recipNonce;
|
||||
|
||||
private PkiFreeText freeText;
|
||||
|
||||
private Asn1Sequence generalInfo;
|
||||
|
||||
public PkiHeaderBuilder(int pvno, GeneralName sender, GeneralName recipient)
|
||||
: this(new DerInteger(pvno), sender, recipient)
|
||||
{
|
||||
}
|
||||
|
||||
private PkiHeaderBuilder(DerInteger pvno, GeneralName sender, GeneralName recipient)
|
||||
{
|
||||
this.pvno = pvno;
|
||||
this.sender = sender;
|
||||
this.recipient = recipient;
|
||||
}
|
||||
|
||||
public virtual PkiHeaderBuilder SetMessageTime(DerGeneralizedTime time)
|
||||
{
|
||||
messageTime = time;
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual PkiHeaderBuilder SetProtectionAlg(AlgorithmIdentifier aid)
|
||||
{
|
||||
protectionAlg = aid;
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual PkiHeaderBuilder SetSenderKID(byte[] kid)
|
||||
{
|
||||
return SetSenderKID((kid == null) ? null : new DerOctetString(kid));
|
||||
}
|
||||
|
||||
public virtual PkiHeaderBuilder SetSenderKID(Asn1OctetString kid)
|
||||
{
|
||||
senderKID = kid;
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual PkiHeaderBuilder SetRecipKID(byte[] kid)
|
||||
{
|
||||
return SetRecipKID((kid == null) ? null : new DerOctetString(kid));
|
||||
}
|
||||
|
||||
public virtual PkiHeaderBuilder SetRecipKID(DerOctetString kid)
|
||||
{
|
||||
recipKID = kid;
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual PkiHeaderBuilder SetTransactionID(byte[] tid)
|
||||
{
|
||||
return SetTransactionID((tid == null) ? null : new DerOctetString(tid));
|
||||
}
|
||||
|
||||
public virtual PkiHeaderBuilder SetTransactionID(Asn1OctetString tid)
|
||||
{
|
||||
transactionID = tid;
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual PkiHeaderBuilder SetSenderNonce(byte[] nonce)
|
||||
{
|
||||
return SetSenderNonce((nonce == null) ? null : new DerOctetString(nonce));
|
||||
}
|
||||
|
||||
public virtual PkiHeaderBuilder SetSenderNonce(Asn1OctetString nonce)
|
||||
{
|
||||
senderNonce = nonce;
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual PkiHeaderBuilder SetRecipNonce(byte[] nonce)
|
||||
{
|
||||
return SetRecipNonce((nonce == null) ? null : new DerOctetString(nonce));
|
||||
}
|
||||
|
||||
public virtual PkiHeaderBuilder SetRecipNonce(Asn1OctetString nonce)
|
||||
{
|
||||
recipNonce = nonce;
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual PkiHeaderBuilder SetFreeText(PkiFreeText text)
|
||||
{
|
||||
freeText = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual PkiHeaderBuilder SetGeneralInfo(InfoTypeAndValue genInfo)
|
||||
{
|
||||
return SetGeneralInfo(MakeGeneralInfoSeq(genInfo));
|
||||
}
|
||||
|
||||
public virtual PkiHeaderBuilder SetGeneralInfo(InfoTypeAndValue[] genInfos)
|
||||
{
|
||||
return SetGeneralInfo(MakeGeneralInfoSeq(genInfos));
|
||||
}
|
||||
|
||||
public virtual PkiHeaderBuilder SetGeneralInfo(Asn1Sequence seqOfInfoTypeAndValue)
|
||||
{
|
||||
generalInfo = seqOfInfoTypeAndValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
private static Asn1Sequence MakeGeneralInfoSeq(InfoTypeAndValue generalInfo)
|
||||
{
|
||||
return new DerSequence(generalInfo);
|
||||
}
|
||||
|
||||
private static Asn1Sequence MakeGeneralInfoSeq(InfoTypeAndValue[] generalInfos)
|
||||
{
|
||||
Asn1Sequence result = null;
|
||||
if (generalInfos != null)
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
for (int i = 0; i < generalInfos.Length; i++)
|
||||
{
|
||||
asn1EncodableVector.Add(generalInfos[i]);
|
||||
}
|
||||
result = new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public virtual PkiHeader Build()
|
||||
{
|
||||
Asn1EncodableVector v = new Asn1EncodableVector(pvno, sender, recipient);
|
||||
AddOptional(v, 0, messageTime);
|
||||
AddOptional(v, 1, protectionAlg);
|
||||
AddOptional(v, 2, senderKID);
|
||||
AddOptional(v, 3, recipKID);
|
||||
AddOptional(v, 4, transactionID);
|
||||
AddOptional(v, 5, senderNonce);
|
||||
AddOptional(v, 6, recipNonce);
|
||||
AddOptional(v, 7, freeText);
|
||||
AddOptional(v, 8, generalInfo);
|
||||
messageTime = null;
|
||||
protectionAlg = null;
|
||||
senderKID = null;
|
||||
recipKID = null;
|
||||
transactionID = null;
|
||||
senderNonce = null;
|
||||
recipNonce = null;
|
||||
freeText = null;
|
||||
generalInfo = null;
|
||||
return PkiHeader.GetInstance(new DerSequence(v));
|
||||
}
|
||||
|
||||
private void AddOptional(Asn1EncodableVector v, int tagNo, Asn1Encodable obj)
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
v.Add(new DerTaggedObject(explicitly: true, tagNo, obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class PkiMessage : Asn1Encodable
|
||||
{
|
||||
private readonly PkiHeader header;
|
||||
|
||||
private readonly PkiBody body;
|
||||
|
||||
private readonly DerBitString protection;
|
||||
|
||||
private readonly Asn1Sequence extraCerts;
|
||||
|
||||
public virtual PkiHeader Header => header;
|
||||
|
||||
public virtual PkiBody Body => body;
|
||||
|
||||
public virtual DerBitString Protection => protection;
|
||||
|
||||
private PkiMessage(Asn1Sequence seq)
|
||||
{
|
||||
header = PkiHeader.GetInstance(seq[0]);
|
||||
body = PkiBody.GetInstance(seq[1]);
|
||||
for (int i = 2; i < seq.Count; i++)
|
||||
{
|
||||
Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)seq[i].ToAsn1Object();
|
||||
if (asn1TaggedObject.TagNo == 0)
|
||||
{
|
||||
protection = DerBitString.GetInstance(asn1TaggedObject, isExplicit: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
extraCerts = Asn1Sequence.GetInstance(asn1TaggedObject, explicitly: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static PkiMessage GetInstance(object obj)
|
||||
{
|
||||
if (obj is PkiMessage)
|
||||
{
|
||||
return (PkiMessage)obj;
|
||||
}
|
||||
if (obj != null)
|
||||
{
|
||||
return new PkiMessage(Asn1Sequence.GetInstance(obj));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PkiMessage(PkiHeader header, PkiBody body, DerBitString protection, CmpCertificate[] extraCerts)
|
||||
{
|
||||
this.header = header;
|
||||
this.body = body;
|
||||
this.protection = protection;
|
||||
if (extraCerts != null)
|
||||
{
|
||||
this.extraCerts = new DerSequence(extraCerts);
|
||||
}
|
||||
}
|
||||
|
||||
public PkiMessage(PkiHeader header, PkiBody body, DerBitString protection)
|
||||
: this(header, body, protection, null)
|
||||
{
|
||||
}
|
||||
|
||||
public PkiMessage(PkiHeader header, PkiBody body)
|
||||
: this(header, body, null, null)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual CmpCertificate[] GetExtraCerts()
|
||||
{
|
||||
if (extraCerts == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
CmpCertificate[] array = new CmpCertificate[extraCerts.Count];
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
array[i] = CmpCertificate.GetInstance(extraCerts[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector v = new Asn1EncodableVector(header, body);
|
||||
AddOptional(v, 0, protection);
|
||||
AddOptional(v, 1, extraCerts);
|
||||
return new DerSequence(v);
|
||||
}
|
||||
|
||||
private static void AddOptional(Asn1EncodableVector v, int tagNo, Asn1Encodable obj)
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
v.Add(new DerTaggedObject(explicitly: true, tagNo, obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class PkiMessages : Asn1Encodable
|
||||
{
|
||||
private Asn1Sequence content;
|
||||
|
||||
private PkiMessages(Asn1Sequence seq)
|
||||
{
|
||||
content = seq;
|
||||
}
|
||||
|
||||
public static PkiMessages GetInstance(object obj)
|
||||
{
|
||||
if (obj is PkiMessages)
|
||||
{
|
||||
return (PkiMessages)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new PkiMessages((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public PkiMessages(params PkiMessage[] msgs)
|
||||
{
|
||||
content = new DerSequence(msgs);
|
||||
}
|
||||
|
||||
public virtual PkiMessage[] ToPkiMessageArray()
|
||||
{
|
||||
PkiMessage[] array = new PkiMessage[content.Count];
|
||||
for (int i = 0; i != array.Length; i++)
|
||||
{
|
||||
array[i] = PkiMessage.GetInstance(content[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public enum PkiStatus
|
||||
{
|
||||
Granted,
|
||||
GrantedWithMods,
|
||||
Rejection,
|
||||
Waiting,
|
||||
RevocationWarning,
|
||||
RevocationNotification,
|
||||
KeyUpdateWarning
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Math;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class PkiStatusEncodable : Asn1Encodable
|
||||
{
|
||||
public static readonly PkiStatusEncodable granted = new PkiStatusEncodable(PkiStatus.Granted);
|
||||
|
||||
public static readonly PkiStatusEncodable grantedWithMods = new PkiStatusEncodable(PkiStatus.GrantedWithMods);
|
||||
|
||||
public static readonly PkiStatusEncodable rejection = new PkiStatusEncodable(PkiStatus.Rejection);
|
||||
|
||||
public static readonly PkiStatusEncodable waiting = new PkiStatusEncodable(PkiStatus.Waiting);
|
||||
|
||||
public static readonly PkiStatusEncodable revocationWarning = new PkiStatusEncodable(PkiStatus.RevocationWarning);
|
||||
|
||||
public static readonly PkiStatusEncodable revocationNotification = new PkiStatusEncodable(PkiStatus.RevocationNotification);
|
||||
|
||||
public static readonly PkiStatusEncodable keyUpdateWaiting = new PkiStatusEncodable(PkiStatus.KeyUpdateWarning);
|
||||
|
||||
private readonly DerInteger status;
|
||||
|
||||
public virtual BigInteger Value => status.Value;
|
||||
|
||||
private PkiStatusEncodable(PkiStatus status)
|
||||
: this(new DerInteger((int)status))
|
||||
{
|
||||
}
|
||||
|
||||
private PkiStatusEncodable(DerInteger status)
|
||||
{
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public static PkiStatusEncodable GetInstance(object obj)
|
||||
{
|
||||
if (obj is PkiStatusEncodable)
|
||||
{
|
||||
return (PkiStatusEncodable)obj;
|
||||
}
|
||||
if (obj is DerInteger)
|
||||
{
|
||||
return new PkiStatusEncodable((DerInteger)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return status;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Math;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class PkiStatusInfo : Asn1Encodable
|
||||
{
|
||||
private DerInteger status;
|
||||
|
||||
private PkiFreeText statusString;
|
||||
|
||||
private DerBitString failInfo;
|
||||
|
||||
public BigInteger Status => status.Value;
|
||||
|
||||
public PkiFreeText StatusString => statusString;
|
||||
|
||||
public DerBitString FailInfo => failInfo;
|
||||
|
||||
public static PkiStatusInfo GetInstance(Asn1TaggedObject obj, bool isExplicit)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
|
||||
}
|
||||
|
||||
public static PkiStatusInfo GetInstance(object obj)
|
||||
{
|
||||
if (obj is PkiStatusInfo)
|
||||
{
|
||||
return (PkiStatusInfo)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new PkiStatusInfo((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public PkiStatusInfo(Asn1Sequence seq)
|
||||
{
|
||||
status = DerInteger.GetInstance(seq[0]);
|
||||
statusString = null;
|
||||
failInfo = null;
|
||||
if (seq.Count > 2)
|
||||
{
|
||||
statusString = PkiFreeText.GetInstance(seq[1]);
|
||||
failInfo = DerBitString.GetInstance(seq[2]);
|
||||
}
|
||||
else if (seq.Count > 1)
|
||||
{
|
||||
object obj = seq[1];
|
||||
if (obj is DerBitString)
|
||||
{
|
||||
failInfo = DerBitString.GetInstance(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
statusString = PkiFreeText.GetInstance(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PkiStatusInfo(int status)
|
||||
{
|
||||
this.status = new DerInteger(status);
|
||||
}
|
||||
|
||||
public PkiStatusInfo(int status, PkiFreeText statusString)
|
||||
{
|
||||
this.status = new DerInteger(status);
|
||||
this.statusString = statusString;
|
||||
}
|
||||
|
||||
public PkiStatusInfo(int status, PkiFreeText statusString, PkiFailureInfo failInfo)
|
||||
{
|
||||
this.status = new DerInteger(status);
|
||||
this.statusString = statusString;
|
||||
this.failInfo = failInfo;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(status);
|
||||
if (statusString != null)
|
||||
{
|
||||
asn1EncodableVector.Add(statusString);
|
||||
}
|
||||
if (failInfo != null)
|
||||
{
|
||||
asn1EncodableVector.Add(failInfo);
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class PollRepContent : Asn1Encodable
|
||||
{
|
||||
private readonly DerInteger certReqId;
|
||||
|
||||
private readonly DerInteger checkAfter;
|
||||
|
||||
private readonly PkiFreeText reason;
|
||||
|
||||
public virtual DerInteger CertReqID => certReqId;
|
||||
|
||||
public virtual DerInteger CheckAfter => checkAfter;
|
||||
|
||||
public virtual PkiFreeText Reason => reason;
|
||||
|
||||
private PollRepContent(Asn1Sequence seq)
|
||||
{
|
||||
certReqId = DerInteger.GetInstance(seq[0]);
|
||||
checkAfter = DerInteger.GetInstance(seq[1]);
|
||||
if (seq.Count > 2)
|
||||
{
|
||||
reason = PkiFreeText.GetInstance(seq[2]);
|
||||
}
|
||||
}
|
||||
|
||||
public static PollRepContent GetInstance(object obj)
|
||||
{
|
||||
if (obj is PollRepContent)
|
||||
{
|
||||
return (PollRepContent)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new PollRepContent((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public PollRepContent(DerInteger certReqId, DerInteger checkAfter)
|
||||
{
|
||||
this.certReqId = certReqId;
|
||||
this.checkAfter = checkAfter;
|
||||
reason = null;
|
||||
}
|
||||
|
||||
public PollRepContent(DerInteger certReqId, DerInteger checkAfter, PkiFreeText reason)
|
||||
{
|
||||
this.certReqId = certReqId;
|
||||
this.checkAfter = checkAfter;
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(certReqId, checkAfter);
|
||||
asn1EncodableVector.AddOptional(reason);
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class PollReqContent : Asn1Encodable
|
||||
{
|
||||
private readonly Asn1Sequence content;
|
||||
|
||||
private PollReqContent(Asn1Sequence seq)
|
||||
{
|
||||
content = seq;
|
||||
}
|
||||
|
||||
public static PollReqContent GetInstance(object obj)
|
||||
{
|
||||
if (obj is PollReqContent)
|
||||
{
|
||||
return (PollReqContent)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new PollReqContent((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public virtual DerInteger[][] GetCertReqIDs()
|
||||
{
|
||||
DerInteger[][] array = new DerInteger[content.Count][];
|
||||
for (int i = 0; i != array.Length; i++)
|
||||
{
|
||||
array[i] = SequenceToDerIntegerArray((Asn1Sequence)content[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
private static DerInteger[] SequenceToDerIntegerArray(Asn1Sequence seq)
|
||||
{
|
||||
DerInteger[] array = new DerInteger[seq.Count];
|
||||
for (int i = 0; i != array.Length; i++)
|
||||
{
|
||||
array[i] = DerInteger.GetInstance(seq[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class PopoDecKeyChallContent : Asn1Encodable
|
||||
{
|
||||
private readonly Asn1Sequence content;
|
||||
|
||||
private PopoDecKeyChallContent(Asn1Sequence seq)
|
||||
{
|
||||
content = seq;
|
||||
}
|
||||
|
||||
public static PopoDecKeyChallContent GetInstance(object obj)
|
||||
{
|
||||
if (obj is PopoDecKeyChallContent)
|
||||
{
|
||||
return (PopoDecKeyChallContent)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new PopoDecKeyChallContent((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public virtual Challenge[] ToChallengeArray()
|
||||
{
|
||||
Challenge[] array = new Challenge[content.Count];
|
||||
for (int i = 0; i != array.Length; i++)
|
||||
{
|
||||
array[i] = Challenge.GetInstance(content[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class PopoDecKeyRespContent : Asn1Encodable
|
||||
{
|
||||
private readonly Asn1Sequence content;
|
||||
|
||||
private PopoDecKeyRespContent(Asn1Sequence seq)
|
||||
{
|
||||
content = seq;
|
||||
}
|
||||
|
||||
public static PopoDecKeyRespContent GetInstance(object obj)
|
||||
{
|
||||
if (obj is PopoDecKeyRespContent)
|
||||
{
|
||||
return (PopoDecKeyRespContent)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new PopoDecKeyRespContent((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public virtual DerInteger[] ToDerIntegerArray()
|
||||
{
|
||||
DerInteger[] array = new DerInteger[content.Count];
|
||||
for (int i = 0; i != array.Length; i++)
|
||||
{
|
||||
array[i] = DerInteger.GetInstance(content[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class ProtectedPart : Asn1Encodable
|
||||
{
|
||||
private readonly PkiHeader header;
|
||||
|
||||
private readonly PkiBody body;
|
||||
|
||||
public virtual PkiHeader Header => header;
|
||||
|
||||
public virtual PkiBody Body => body;
|
||||
|
||||
private ProtectedPart(Asn1Sequence seq)
|
||||
{
|
||||
header = PkiHeader.GetInstance(seq[0]);
|
||||
body = PkiBody.GetInstance(seq[1]);
|
||||
}
|
||||
|
||||
public static ProtectedPart GetInstance(object obj)
|
||||
{
|
||||
if (obj is ProtectedPart)
|
||||
{
|
||||
return (ProtectedPart)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new ProtectedPart((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public ProtectedPart(PkiHeader header, PkiBody body)
|
||||
{
|
||||
this.header = header;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerSequence(header, body);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Asn1.Crmf;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class RevAnnContent : Asn1Encodable
|
||||
{
|
||||
private readonly PkiStatusEncodable status;
|
||||
|
||||
private readonly CertId certId;
|
||||
|
||||
private readonly DerGeneralizedTime willBeRevokedAt;
|
||||
|
||||
private readonly DerGeneralizedTime badSinceDate;
|
||||
|
||||
private readonly X509Extensions crlDetails;
|
||||
|
||||
public virtual PkiStatusEncodable Status => status;
|
||||
|
||||
public virtual CertId CertID => certId;
|
||||
|
||||
public virtual DerGeneralizedTime WillBeRevokedAt => willBeRevokedAt;
|
||||
|
||||
public virtual DerGeneralizedTime BadSinceDate => badSinceDate;
|
||||
|
||||
public virtual X509Extensions CrlDetails => crlDetails;
|
||||
|
||||
private RevAnnContent(Asn1Sequence seq)
|
||||
{
|
||||
status = PkiStatusEncodable.GetInstance(seq[0]);
|
||||
certId = CertId.GetInstance(seq[1]);
|
||||
willBeRevokedAt = DerGeneralizedTime.GetInstance(seq[2]);
|
||||
badSinceDate = DerGeneralizedTime.GetInstance(seq[3]);
|
||||
if (seq.Count > 4)
|
||||
{
|
||||
crlDetails = X509Extensions.GetInstance(seq[4]);
|
||||
}
|
||||
}
|
||||
|
||||
public static RevAnnContent GetInstance(object obj)
|
||||
{
|
||||
if (obj is RevAnnContent)
|
||||
{
|
||||
return (RevAnnContent)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new RevAnnContent((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(status, certId, willBeRevokedAt, badSinceDate);
|
||||
asn1EncodableVector.AddOptional(crlDetails);
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Asn1.Crmf;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class RevDetails : Asn1Encodable
|
||||
{
|
||||
private readonly CertTemplate certDetails;
|
||||
|
||||
private readonly X509Extensions crlEntryDetails;
|
||||
|
||||
public virtual CertTemplate CertDetails => certDetails;
|
||||
|
||||
public virtual X509Extensions CrlEntryDetails => crlEntryDetails;
|
||||
|
||||
private RevDetails(Asn1Sequence seq)
|
||||
{
|
||||
certDetails = CertTemplate.GetInstance(seq[0]);
|
||||
crlEntryDetails = ((seq.Count <= 1) ? null : X509Extensions.GetInstance(seq[1]));
|
||||
}
|
||||
|
||||
public static RevDetails GetInstance(object obj)
|
||||
{
|
||||
if (obj is RevDetails)
|
||||
{
|
||||
return (RevDetails)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new RevDetails((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public RevDetails(CertTemplate certDetails)
|
||||
: this(certDetails, null)
|
||||
{
|
||||
}
|
||||
|
||||
public RevDetails(CertTemplate certDetails, X509Extensions crlEntryDetails)
|
||||
{
|
||||
this.certDetails = certDetails;
|
||||
this.crlEntryDetails = crlEntryDetails;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(certDetails);
|
||||
asn1EncodableVector.AddOptional(crlEntryDetails);
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Asn1.Crmf;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class RevRepContent : Asn1Encodable
|
||||
{
|
||||
private readonly Asn1Sequence status;
|
||||
|
||||
private readonly Asn1Sequence revCerts;
|
||||
|
||||
private readonly Asn1Sequence crls;
|
||||
|
||||
private RevRepContent(Asn1Sequence seq)
|
||||
{
|
||||
status = Asn1Sequence.GetInstance(seq[0]);
|
||||
for (int i = 1; i < seq.Count; i++)
|
||||
{
|
||||
Asn1TaggedObject instance = Asn1TaggedObject.GetInstance(seq[i]);
|
||||
if (instance.TagNo == 0)
|
||||
{
|
||||
revCerts = Asn1Sequence.GetInstance(instance, explicitly: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
crls = Asn1Sequence.GetInstance(instance, explicitly: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static RevRepContent GetInstance(object obj)
|
||||
{
|
||||
if (obj is RevRepContent)
|
||||
{
|
||||
return (RevRepContent)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new RevRepContent((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public virtual PkiStatusInfo[] GetStatus()
|
||||
{
|
||||
PkiStatusInfo[] array = new PkiStatusInfo[status.Count];
|
||||
for (int i = 0; i != array.Length; i++)
|
||||
{
|
||||
array[i] = PkiStatusInfo.GetInstance(status[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public virtual CertId[] GetRevCerts()
|
||||
{
|
||||
if (revCerts == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
CertId[] array = new CertId[revCerts.Count];
|
||||
for (int i = 0; i != array.Length; i++)
|
||||
{
|
||||
array[i] = CertId.GetInstance(revCerts[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public virtual CertificateList[] GetCrls()
|
||||
{
|
||||
if (crls == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
CertificateList[] array = new CertificateList[crls.Count];
|
||||
for (int i = 0; i != array.Length; i++)
|
||||
{
|
||||
array[i] = CertificateList.GetInstance(crls[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector v = new Asn1EncodableVector(status);
|
||||
AddOptional(v, 0, revCerts);
|
||||
AddOptional(v, 1, crls);
|
||||
return new DerSequence(v);
|
||||
}
|
||||
|
||||
private void AddOptional(Asn1EncodableVector v, int tagNo, Asn1Encodable obj)
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
v.Add(new DerTaggedObject(explicitly: true, tagNo, obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Asn1.Crmf;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class RevRepContentBuilder
|
||||
{
|
||||
private readonly Asn1EncodableVector status = new Asn1EncodableVector();
|
||||
|
||||
private readonly Asn1EncodableVector revCerts = new Asn1EncodableVector();
|
||||
|
||||
private readonly Asn1EncodableVector crls = new Asn1EncodableVector();
|
||||
|
||||
public virtual RevRepContentBuilder Add(PkiStatusInfo status)
|
||||
{
|
||||
this.status.Add(status);
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual RevRepContentBuilder Add(PkiStatusInfo status, CertId certId)
|
||||
{
|
||||
if (this.status.Count != revCerts.Count)
|
||||
{
|
||||
throw new InvalidOperationException("status and revCerts sequence must be in common order");
|
||||
}
|
||||
this.status.Add(status);
|
||||
revCerts.Add(certId);
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual RevRepContentBuilder AddCrl(CertificateList crl)
|
||||
{
|
||||
crls.Add(crl);
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual RevRepContent Build()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
asn1EncodableVector.Add(new DerSequence(status));
|
||||
if (revCerts.Count != 0)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: true, 0, new DerSequence(revCerts)));
|
||||
}
|
||||
if (crls.Count != 0)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: true, 1, new DerSequence(crls)));
|
||||
}
|
||||
return RevRepContent.GetInstance(new DerSequence(asn1EncodableVector));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class RevReqContent : Asn1Encodable
|
||||
{
|
||||
private readonly Asn1Sequence content;
|
||||
|
||||
private RevReqContent(Asn1Sequence seq)
|
||||
{
|
||||
content = seq;
|
||||
}
|
||||
|
||||
public static RevReqContent GetInstance(object obj)
|
||||
{
|
||||
if (obj is RevReqContent)
|
||||
{
|
||||
return (RevReqContent)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new RevReqContent((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public RevReqContent(params RevDetails[] revDetails)
|
||||
{
|
||||
content = new DerSequence(revDetails);
|
||||
}
|
||||
|
||||
public virtual RevDetails[] ToRevDetailsArray()
|
||||
{
|
||||
RevDetails[] array = new RevDetails[content.Count];
|
||||
for (int i = 0; i != array.Length; i++)
|
||||
{
|
||||
array[i] = RevDetails.GetInstance(content[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return content;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user