init commit
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class AccessDescription : Asn1Encodable
|
||||
{
|
||||
public static readonly DerObjectIdentifier IdADCAIssuers = new DerObjectIdentifier("1.3.6.1.5.5.7.48.2");
|
||||
|
||||
public static readonly DerObjectIdentifier IdADOcsp = new DerObjectIdentifier("1.3.6.1.5.5.7.48.1");
|
||||
|
||||
private readonly DerObjectIdentifier accessMethod;
|
||||
|
||||
private readonly GeneralName accessLocation;
|
||||
|
||||
public DerObjectIdentifier AccessMethod => accessMethod;
|
||||
|
||||
public GeneralName AccessLocation => accessLocation;
|
||||
|
||||
public static AccessDescription GetInstance(object obj)
|
||||
{
|
||||
if (obj is AccessDescription)
|
||||
{
|
||||
return (AccessDescription)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new AccessDescription((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
private AccessDescription(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count != 2)
|
||||
{
|
||||
throw new ArgumentException("wrong number of elements in sequence");
|
||||
}
|
||||
accessMethod = DerObjectIdentifier.GetInstance(seq[0]);
|
||||
accessLocation = GeneralName.GetInstance(seq[1]);
|
||||
}
|
||||
|
||||
public AccessDescription(DerObjectIdentifier oid, GeneralName location)
|
||||
{
|
||||
accessMethod = oid;
|
||||
accessLocation = location;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerSequence(accessMethod, accessLocation);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "AccessDescription: Oid(" + accessMethod.Id + ")";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class AlgorithmIdentifier : Asn1Encodable
|
||||
{
|
||||
private readonly DerObjectIdentifier algorithm;
|
||||
|
||||
private readonly Asn1Encodable parameters;
|
||||
|
||||
public virtual DerObjectIdentifier Algorithm => algorithm;
|
||||
|
||||
[Obsolete("Use 'Algorithm' property instead")]
|
||||
public virtual DerObjectIdentifier ObjectID => algorithm;
|
||||
|
||||
public virtual Asn1Encodable Parameters => parameters;
|
||||
|
||||
public static AlgorithmIdentifier GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
|
||||
}
|
||||
|
||||
public static AlgorithmIdentifier GetInstance(object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (obj is AlgorithmIdentifier)
|
||||
{
|
||||
return (AlgorithmIdentifier)obj;
|
||||
}
|
||||
return new AlgorithmIdentifier(Asn1Sequence.GetInstance(obj));
|
||||
}
|
||||
|
||||
public AlgorithmIdentifier(DerObjectIdentifier algorithm)
|
||||
{
|
||||
this.algorithm = algorithm;
|
||||
}
|
||||
|
||||
[Obsolete("Use version taking a DerObjectIdentifier")]
|
||||
public AlgorithmIdentifier(string algorithm)
|
||||
{
|
||||
this.algorithm = new DerObjectIdentifier(algorithm);
|
||||
}
|
||||
|
||||
public AlgorithmIdentifier(DerObjectIdentifier algorithm, Asn1Encodable parameters)
|
||||
{
|
||||
this.algorithm = algorithm;
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
internal AlgorithmIdentifier(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count < 1 || seq.Count > 2)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count);
|
||||
}
|
||||
algorithm = DerObjectIdentifier.GetInstance(seq[0]);
|
||||
parameters = ((seq.Count < 2) ? null : seq[1]);
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(algorithm);
|
||||
asn1EncodableVector.AddOptional(parameters);
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class AttCertIssuer : Asn1Encodable, IAsn1Choice
|
||||
{
|
||||
internal readonly Asn1Encodable obj;
|
||||
|
||||
internal readonly Asn1Object choiceObj;
|
||||
|
||||
public Asn1Encodable Issuer => obj;
|
||||
|
||||
public static AttCertIssuer GetInstance(object obj)
|
||||
{
|
||||
if (obj is AttCertIssuer)
|
||||
{
|
||||
return (AttCertIssuer)obj;
|
||||
}
|
||||
if (obj is V2Form)
|
||||
{
|
||||
return new AttCertIssuer(V2Form.GetInstance(obj));
|
||||
}
|
||||
if (obj is GeneralNames)
|
||||
{
|
||||
return new AttCertIssuer((GeneralNames)obj);
|
||||
}
|
||||
if (obj is Asn1TaggedObject)
|
||||
{
|
||||
return new AttCertIssuer(V2Form.GetInstance((Asn1TaggedObject)obj, explicitly: false));
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new AttCertIssuer(GeneralNames.GetInstance(obj));
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public static AttCertIssuer GetInstance(Asn1TaggedObject obj, bool isExplicit)
|
||||
{
|
||||
return GetInstance(obj.GetObject());
|
||||
}
|
||||
|
||||
public AttCertIssuer(GeneralNames names)
|
||||
{
|
||||
obj = names;
|
||||
choiceObj = obj.ToAsn1Object();
|
||||
}
|
||||
|
||||
public AttCertIssuer(V2Form v2Form)
|
||||
{
|
||||
obj = v2Form;
|
||||
choiceObj = new DerTaggedObject(explicitly: false, 0, obj);
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return choiceObj;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class AttCertValidityPeriod : Asn1Encodable
|
||||
{
|
||||
private readonly DerGeneralizedTime notBeforeTime;
|
||||
|
||||
private readonly DerGeneralizedTime notAfterTime;
|
||||
|
||||
public DerGeneralizedTime NotBeforeTime => notBeforeTime;
|
||||
|
||||
public DerGeneralizedTime NotAfterTime => notAfterTime;
|
||||
|
||||
public static AttCertValidityPeriod GetInstance(object obj)
|
||||
{
|
||||
if (obj is AttCertValidityPeriod || obj == null)
|
||||
{
|
||||
return (AttCertValidityPeriod)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new AttCertValidityPeriod((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public static AttCertValidityPeriod GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
|
||||
}
|
||||
|
||||
private AttCertValidityPeriod(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count != 2)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count);
|
||||
}
|
||||
notBeforeTime = DerGeneralizedTime.GetInstance(seq[0]);
|
||||
notAfterTime = DerGeneralizedTime.GetInstance(seq[1]);
|
||||
}
|
||||
|
||||
public AttCertValidityPeriod(DerGeneralizedTime notBeforeTime, DerGeneralizedTime notAfterTime)
|
||||
{
|
||||
this.notBeforeTime = notBeforeTime;
|
||||
this.notAfterTime = notAfterTime;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerSequence(notBeforeTime, notAfterTime);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class AttributeCertificate : Asn1Encodable
|
||||
{
|
||||
private readonly AttributeCertificateInfo acinfo;
|
||||
|
||||
private readonly AlgorithmIdentifier signatureAlgorithm;
|
||||
|
||||
private readonly DerBitString signatureValue;
|
||||
|
||||
public AttributeCertificateInfo ACInfo => acinfo;
|
||||
|
||||
public AlgorithmIdentifier SignatureAlgorithm => signatureAlgorithm;
|
||||
|
||||
public DerBitString SignatureValue => signatureValue;
|
||||
|
||||
public static AttributeCertificate GetInstance(object obj)
|
||||
{
|
||||
if (obj is AttributeCertificate)
|
||||
{
|
||||
return (AttributeCertificate)obj;
|
||||
}
|
||||
if (obj != null)
|
||||
{
|
||||
return new AttributeCertificate(Asn1Sequence.GetInstance(obj));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public AttributeCertificate(AttributeCertificateInfo acinfo, AlgorithmIdentifier signatureAlgorithm, DerBitString signatureValue)
|
||||
{
|
||||
this.acinfo = acinfo;
|
||||
this.signatureAlgorithm = signatureAlgorithm;
|
||||
this.signatureValue = signatureValue;
|
||||
}
|
||||
|
||||
private AttributeCertificate(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count != 3)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count);
|
||||
}
|
||||
acinfo = AttributeCertificateInfo.GetInstance(seq[0]);
|
||||
signatureAlgorithm = AlgorithmIdentifier.GetInstance(seq[1]);
|
||||
signatureValue = DerBitString.GetInstance(seq[2]);
|
||||
}
|
||||
|
||||
public byte[] GetSignatureOctets()
|
||||
{
|
||||
return signatureValue.GetOctets();
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerSequence(acinfo, signatureAlgorithm, signatureValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class AttributeCertificateInfo : Asn1Encodable
|
||||
{
|
||||
internal readonly DerInteger version;
|
||||
|
||||
internal readonly Holder holder;
|
||||
|
||||
internal readonly AttCertIssuer issuer;
|
||||
|
||||
internal readonly AlgorithmIdentifier signature;
|
||||
|
||||
internal readonly DerInteger serialNumber;
|
||||
|
||||
internal readonly AttCertValidityPeriod attrCertValidityPeriod;
|
||||
|
||||
internal readonly Asn1Sequence attributes;
|
||||
|
||||
internal readonly DerBitString issuerUniqueID;
|
||||
|
||||
internal readonly X509Extensions extensions;
|
||||
|
||||
public DerInteger Version => version;
|
||||
|
||||
public Holder Holder => holder;
|
||||
|
||||
public AttCertIssuer Issuer => issuer;
|
||||
|
||||
public AlgorithmIdentifier Signature => signature;
|
||||
|
||||
public DerInteger SerialNumber => serialNumber;
|
||||
|
||||
public AttCertValidityPeriod AttrCertValidityPeriod => attrCertValidityPeriod;
|
||||
|
||||
public Asn1Sequence Attributes => attributes;
|
||||
|
||||
public DerBitString IssuerUniqueID => issuerUniqueID;
|
||||
|
||||
public X509Extensions Extensions => extensions;
|
||||
|
||||
public static AttributeCertificateInfo GetInstance(Asn1TaggedObject obj, bool isExplicit)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
|
||||
}
|
||||
|
||||
public static AttributeCertificateInfo GetInstance(object obj)
|
||||
{
|
||||
if (obj is AttributeCertificateInfo)
|
||||
{
|
||||
return (AttributeCertificateInfo)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new AttributeCertificateInfo((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
private AttributeCertificateInfo(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count < 7 || seq.Count > 9)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count);
|
||||
}
|
||||
version = DerInteger.GetInstance(seq[0]);
|
||||
holder = Holder.GetInstance(seq[1]);
|
||||
issuer = AttCertIssuer.GetInstance(seq[2]);
|
||||
signature = AlgorithmIdentifier.GetInstance(seq[3]);
|
||||
serialNumber = DerInteger.GetInstance(seq[4]);
|
||||
attrCertValidityPeriod = AttCertValidityPeriod.GetInstance(seq[5]);
|
||||
attributes = Asn1Sequence.GetInstance(seq[6]);
|
||||
for (int i = 7; i < seq.Count; i++)
|
||||
{
|
||||
Asn1Encodable asn1Encodable = seq[i];
|
||||
if (asn1Encodable is DerBitString)
|
||||
{
|
||||
issuerUniqueID = DerBitString.GetInstance(seq[i]);
|
||||
}
|
||||
else if (asn1Encodable is Asn1Sequence || asn1Encodable is X509Extensions)
|
||||
{
|
||||
extensions = X509Extensions.GetInstance(seq[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(version, holder, issuer, signature, serialNumber, attrCertValidityPeriod, attributes);
|
||||
if (issuerUniqueID != null)
|
||||
{
|
||||
asn1EncodableVector.Add(issuerUniqueID);
|
||||
}
|
||||
if (extensions != null)
|
||||
{
|
||||
asn1EncodableVector.Add(extensions);
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class AttributeTable
|
||||
{
|
||||
private readonly IDictionary attributes;
|
||||
|
||||
public AttributeTable(IDictionary attrs)
|
||||
{
|
||||
attributes = Platform.CreateHashtable(attrs);
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public AttributeTable(Hashtable attrs)
|
||||
{
|
||||
attributes = Platform.CreateHashtable(attrs);
|
||||
}
|
||||
|
||||
public AttributeTable(Asn1EncodableVector v)
|
||||
{
|
||||
attributes = Platform.CreateHashtable(v.Count);
|
||||
for (int i = 0; i != v.Count; i++)
|
||||
{
|
||||
AttributeX509 instance = AttributeX509.GetInstance(v[i]);
|
||||
attributes.Add(instance.AttrType, instance);
|
||||
}
|
||||
}
|
||||
|
||||
public AttributeTable(Asn1Set s)
|
||||
{
|
||||
attributes = Platform.CreateHashtable(s.Count);
|
||||
for (int i = 0; i != s.Count; i++)
|
||||
{
|
||||
AttributeX509 instance = AttributeX509.GetInstance(s[i]);
|
||||
attributes.Add(instance.AttrType, instance);
|
||||
}
|
||||
}
|
||||
|
||||
public AttributeX509 Get(DerObjectIdentifier oid)
|
||||
{
|
||||
return (AttributeX509)attributes[oid];
|
||||
}
|
||||
|
||||
[Obsolete("Use 'ToDictionary' instead")]
|
||||
public Hashtable ToHashtable()
|
||||
{
|
||||
return new Hashtable(attributes);
|
||||
}
|
||||
|
||||
public IDictionary ToDictionary()
|
||||
{
|
||||
return Platform.CreateHashtable(attributes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class AttributeX509 : Asn1Encodable
|
||||
{
|
||||
private readonly DerObjectIdentifier attrType;
|
||||
|
||||
private readonly Asn1Set attrValues;
|
||||
|
||||
public DerObjectIdentifier AttrType => attrType;
|
||||
|
||||
public Asn1Set AttrValues => attrValues;
|
||||
|
||||
public static AttributeX509 GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is AttributeX509)
|
||||
{
|
||||
return (AttributeX509)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new AttributeX509((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
private AttributeX509(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count != 2)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count);
|
||||
}
|
||||
attrType = DerObjectIdentifier.GetInstance(seq[0]);
|
||||
attrValues = Asn1Set.GetInstance(seq[1]);
|
||||
}
|
||||
|
||||
public AttributeX509(DerObjectIdentifier attrType, Asn1Set attrValues)
|
||||
{
|
||||
this.attrType = attrType;
|
||||
this.attrValues = attrValues;
|
||||
}
|
||||
|
||||
public Asn1Encodable[] GetAttributeValues()
|
||||
{
|
||||
return attrValues.ToArray();
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerSequence(attrType, attrValues);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class AuthorityInformationAccess : Asn1Encodable
|
||||
{
|
||||
private readonly AccessDescription[] descriptions;
|
||||
|
||||
public static AuthorityInformationAccess GetInstance(object obj)
|
||||
{
|
||||
if (obj is AuthorityInformationAccess)
|
||||
{
|
||||
return (AuthorityInformationAccess)obj;
|
||||
}
|
||||
if (obj == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new AuthorityInformationAccess(Asn1Sequence.GetInstance(obj));
|
||||
}
|
||||
|
||||
private AuthorityInformationAccess(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count < 1)
|
||||
{
|
||||
throw new ArgumentException("sequence may not be empty");
|
||||
}
|
||||
descriptions = new AccessDescription[seq.Count];
|
||||
for (int i = 0; i < seq.Count; i++)
|
||||
{
|
||||
descriptions[i] = AccessDescription.GetInstance(seq[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public AuthorityInformationAccess(AccessDescription description)
|
||||
{
|
||||
descriptions = new AccessDescription[1] { description };
|
||||
}
|
||||
|
||||
public AuthorityInformationAccess(DerObjectIdentifier oid, GeneralName location)
|
||||
: this(new AccessDescription(oid, location))
|
||||
{
|
||||
}
|
||||
|
||||
public AccessDescription[] GetAccessDescriptions()
|
||||
{
|
||||
return (AccessDescription[])descriptions.Clone();
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerSequence(descriptions);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
string newLine = Platform.NewLine;
|
||||
stringBuilder.Append("AuthorityInformationAccess:");
|
||||
stringBuilder.Append(newLine);
|
||||
AccessDescription[] array = descriptions;
|
||||
foreach (AccessDescription value in array)
|
||||
{
|
||||
stringBuilder.Append(" ");
|
||||
stringBuilder.Append(value);
|
||||
stringBuilder.Append(newLine);
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Crypto;
|
||||
using Org.BouncyCastle.Crypto.Digests;
|
||||
using Org.BouncyCastle.Math;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class AuthorityKeyIdentifier : Asn1Encodable
|
||||
{
|
||||
internal readonly Asn1OctetString keyidentifier;
|
||||
|
||||
internal readonly GeneralNames certissuer;
|
||||
|
||||
internal readonly DerInteger certserno;
|
||||
|
||||
public GeneralNames AuthorityCertIssuer => certissuer;
|
||||
|
||||
public BigInteger AuthorityCertSerialNumber
|
||||
{
|
||||
get
|
||||
{
|
||||
if (certserno != null)
|
||||
{
|
||||
return certserno.Value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static AuthorityKeyIdentifier GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
|
||||
}
|
||||
|
||||
public static AuthorityKeyIdentifier GetInstance(object obj)
|
||||
{
|
||||
if (obj is AuthorityKeyIdentifier)
|
||||
{
|
||||
return (AuthorityKeyIdentifier)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new AuthorityKeyIdentifier((Asn1Sequence)obj);
|
||||
}
|
||||
if (obj is X509Extension)
|
||||
{
|
||||
return GetInstance(X509Extension.ConvertValueToObject((X509Extension)obj));
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
protected internal AuthorityKeyIdentifier(Asn1Sequence seq)
|
||||
{
|
||||
foreach (Asn1TaggedObject item in seq)
|
||||
{
|
||||
switch (item.TagNo)
|
||||
{
|
||||
case 0:
|
||||
keyidentifier = Asn1OctetString.GetInstance(item, isExplicit: false);
|
||||
break;
|
||||
case 1:
|
||||
certissuer = GeneralNames.GetInstance(item, explicitly: false);
|
||||
break;
|
||||
case 2:
|
||||
certserno = DerInteger.GetInstance(item, isExplicit: false);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("illegal tag");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public AuthorityKeyIdentifier(SubjectPublicKeyInfo spki)
|
||||
{
|
||||
IDigest digest = new Sha1Digest();
|
||||
byte[] array = new byte[digest.GetDigestSize()];
|
||||
byte[] bytes = spki.PublicKeyData.GetBytes();
|
||||
digest.BlockUpdate(bytes, 0, bytes.Length);
|
||||
digest.DoFinal(array, 0);
|
||||
keyidentifier = new DerOctetString(array);
|
||||
}
|
||||
|
||||
public AuthorityKeyIdentifier(SubjectPublicKeyInfo spki, GeneralNames name, BigInteger serialNumber)
|
||||
{
|
||||
IDigest digest = new Sha1Digest();
|
||||
byte[] array = new byte[digest.GetDigestSize()];
|
||||
byte[] bytes = spki.PublicKeyData.GetBytes();
|
||||
digest.BlockUpdate(bytes, 0, bytes.Length);
|
||||
digest.DoFinal(array, 0);
|
||||
keyidentifier = new DerOctetString(array);
|
||||
certissuer = name;
|
||||
certserno = new DerInteger(serialNumber);
|
||||
}
|
||||
|
||||
public AuthorityKeyIdentifier(GeneralNames name, BigInteger serialNumber)
|
||||
{
|
||||
keyidentifier = null;
|
||||
certissuer = GeneralNames.GetInstance(name.ToAsn1Object());
|
||||
certserno = new DerInteger(serialNumber);
|
||||
}
|
||||
|
||||
public AuthorityKeyIdentifier(byte[] keyIdentifier)
|
||||
{
|
||||
keyidentifier = new DerOctetString(keyIdentifier);
|
||||
certissuer = null;
|
||||
certserno = null;
|
||||
}
|
||||
|
||||
public AuthorityKeyIdentifier(byte[] keyIdentifier, GeneralNames name, BigInteger serialNumber)
|
||||
{
|
||||
keyidentifier = new DerOctetString(keyIdentifier);
|
||||
certissuer = GeneralNames.GetInstance(name.ToAsn1Object());
|
||||
certserno = new DerInteger(serialNumber);
|
||||
}
|
||||
|
||||
public byte[] GetKeyIdentifier()
|
||||
{
|
||||
if (keyidentifier != null)
|
||||
{
|
||||
return keyidentifier.GetOctets();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
if (keyidentifier != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 0, keyidentifier));
|
||||
}
|
||||
if (certissuer != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 1, certissuer));
|
||||
}
|
||||
if (certserno != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 2, certserno));
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Concat("AuthorityKeyIdentifier: KeyID(", keyidentifier.GetOctets(), ")");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Math;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class BasicConstraints : Asn1Encodable
|
||||
{
|
||||
private readonly DerBoolean cA;
|
||||
|
||||
private readonly DerInteger pathLenConstraint;
|
||||
|
||||
public BigInteger PathLenConstraint
|
||||
{
|
||||
get
|
||||
{
|
||||
if (pathLenConstraint != null)
|
||||
{
|
||||
return pathLenConstraint.Value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static BasicConstraints GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
|
||||
}
|
||||
|
||||
public static BasicConstraints GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is BasicConstraints)
|
||||
{
|
||||
return (BasicConstraints)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new BasicConstraints((Asn1Sequence)obj);
|
||||
}
|
||||
if (obj is X509Extension)
|
||||
{
|
||||
return GetInstance(X509Extension.ConvertValueToObject((X509Extension)obj));
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
private BasicConstraints(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (seq[0] is DerBoolean)
|
||||
{
|
||||
cA = DerBoolean.GetInstance(seq[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
pathLenConstraint = DerInteger.GetInstance(seq[0]);
|
||||
}
|
||||
if (seq.Count > 1)
|
||||
{
|
||||
if (cA == null)
|
||||
{
|
||||
throw new ArgumentException("wrong sequence in constructor", "seq");
|
||||
}
|
||||
pathLenConstraint = DerInteger.GetInstance(seq[1]);
|
||||
}
|
||||
}
|
||||
|
||||
public BasicConstraints(bool cA)
|
||||
{
|
||||
if (cA)
|
||||
{
|
||||
this.cA = DerBoolean.True;
|
||||
}
|
||||
}
|
||||
|
||||
public BasicConstraints(int pathLenConstraint)
|
||||
{
|
||||
cA = DerBoolean.True;
|
||||
this.pathLenConstraint = new DerInteger(pathLenConstraint);
|
||||
}
|
||||
|
||||
public bool IsCA()
|
||||
{
|
||||
if (cA != null)
|
||||
{
|
||||
return cA.IsTrue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
if (cA != null)
|
||||
{
|
||||
asn1EncodableVector.Add(cA);
|
||||
}
|
||||
if (pathLenConstraint != null)
|
||||
{
|
||||
asn1EncodableVector.Add(pathLenConstraint);
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if (pathLenConstraint == null)
|
||||
{
|
||||
return "BasicConstraints: isCa(" + IsCA() + ")";
|
||||
}
|
||||
return "BasicConstraints: isCa(" + IsCA() + "), pathLenConstraint = " + pathLenConstraint.Value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class CertPolicyID : DerObjectIdentifier
|
||||
{
|
||||
public CertPolicyID(string id)
|
||||
: base(id)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class CertificateList : Asn1Encodable
|
||||
{
|
||||
private readonly TbsCertificateList tbsCertList;
|
||||
|
||||
private readonly AlgorithmIdentifier sigAlgID;
|
||||
|
||||
private readonly DerBitString sig;
|
||||
|
||||
public TbsCertificateList TbsCertList => tbsCertList;
|
||||
|
||||
public AlgorithmIdentifier SignatureAlgorithm => sigAlgID;
|
||||
|
||||
public DerBitString Signature => sig;
|
||||
|
||||
public int Version => tbsCertList.Version;
|
||||
|
||||
public X509Name Issuer => tbsCertList.Issuer;
|
||||
|
||||
public Time ThisUpdate => tbsCertList.ThisUpdate;
|
||||
|
||||
public Time NextUpdate => tbsCertList.NextUpdate;
|
||||
|
||||
public static CertificateList GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
|
||||
}
|
||||
|
||||
public static CertificateList GetInstance(object obj)
|
||||
{
|
||||
if (obj is CertificateList)
|
||||
{
|
||||
return (CertificateList)obj;
|
||||
}
|
||||
if (obj != null)
|
||||
{
|
||||
return new CertificateList(Asn1Sequence.GetInstance(obj));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private CertificateList(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count != 3)
|
||||
{
|
||||
throw new ArgumentException("sequence wrong size for CertificateList", "seq");
|
||||
}
|
||||
tbsCertList = TbsCertificateList.GetInstance(seq[0]);
|
||||
sigAlgID = AlgorithmIdentifier.GetInstance(seq[1]);
|
||||
sig = DerBitString.GetInstance(seq[2]);
|
||||
}
|
||||
|
||||
public CrlEntry[] GetRevokedCertificates()
|
||||
{
|
||||
return tbsCertList.GetRevokedCertificates();
|
||||
}
|
||||
|
||||
public IEnumerable GetRevokedCertificateEnumeration()
|
||||
{
|
||||
return tbsCertList.GetRevokedCertificateEnumeration();
|
||||
}
|
||||
|
||||
public byte[] GetSignatureOctets()
|
||||
{
|
||||
return sig.GetOctets();
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerSequence(tbsCertList, sigAlgID, sig);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class CertificatePair : Asn1Encodable
|
||||
{
|
||||
private X509CertificateStructure forward;
|
||||
|
||||
private X509CertificateStructure reverse;
|
||||
|
||||
public X509CertificateStructure Forward => forward;
|
||||
|
||||
public X509CertificateStructure Reverse => reverse;
|
||||
|
||||
public static CertificatePair GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is CertificatePair)
|
||||
{
|
||||
return (CertificatePair)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new CertificatePair((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
private CertificatePair(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count != 1 && seq.Count != 2)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
|
||||
}
|
||||
foreach (object item in seq)
|
||||
{
|
||||
Asn1TaggedObject instance = Asn1TaggedObject.GetInstance(item);
|
||||
if (instance.TagNo == 0)
|
||||
{
|
||||
forward = X509CertificateStructure.GetInstance(instance, explicitly: true);
|
||||
continue;
|
||||
}
|
||||
if (instance.TagNo == 1)
|
||||
{
|
||||
reverse = X509CertificateStructure.GetInstance(instance, explicitly: true);
|
||||
continue;
|
||||
}
|
||||
throw new ArgumentException("Bad tag number: " + instance.TagNo);
|
||||
}
|
||||
}
|
||||
|
||||
public CertificatePair(X509CertificateStructure forward, X509CertificateStructure reverse)
|
||||
{
|
||||
this.forward = forward;
|
||||
this.reverse = reverse;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
if (forward != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(0, forward));
|
||||
}
|
||||
if (reverse != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(1, reverse));
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using System.Text;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class CertificatePolicies : Asn1Encodable
|
||||
{
|
||||
private readonly PolicyInformation[] policyInformation;
|
||||
|
||||
public static CertificatePolicies GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is CertificatePolicies)
|
||||
{
|
||||
return (CertificatePolicies)obj;
|
||||
}
|
||||
return new CertificatePolicies(Asn1Sequence.GetInstance(obj));
|
||||
}
|
||||
|
||||
public static CertificatePolicies GetInstance(Asn1TaggedObject obj, bool isExplicit)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
|
||||
}
|
||||
|
||||
public CertificatePolicies(PolicyInformation name)
|
||||
{
|
||||
policyInformation = new PolicyInformation[1] { name };
|
||||
}
|
||||
|
||||
public CertificatePolicies(PolicyInformation[] policyInformation)
|
||||
{
|
||||
this.policyInformation = policyInformation;
|
||||
}
|
||||
|
||||
private CertificatePolicies(Asn1Sequence seq)
|
||||
{
|
||||
policyInformation = new PolicyInformation[seq.Count];
|
||||
for (int i = 0; i < seq.Count; i++)
|
||||
{
|
||||
policyInformation[i] = PolicyInformation.GetInstance(seq[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual PolicyInformation[] GetPolicyInformation()
|
||||
{
|
||||
return (PolicyInformation[])policyInformation.Clone();
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerSequence(policyInformation);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder("CertificatePolicies:");
|
||||
if (policyInformation != null && policyInformation.Length > 0)
|
||||
{
|
||||
stringBuilder.Append(' ');
|
||||
stringBuilder.Append(policyInformation[0]);
|
||||
for (int i = 1; i < policyInformation.Length; i++)
|
||||
{
|
||||
stringBuilder.Append(", ");
|
||||
stringBuilder.Append(policyInformation[i]);
|
||||
}
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class CrlDistPoint : Asn1Encodable
|
||||
{
|
||||
internal readonly Asn1Sequence seq;
|
||||
|
||||
public static CrlDistPoint GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
|
||||
}
|
||||
|
||||
public static CrlDistPoint GetInstance(object obj)
|
||||
{
|
||||
if (obj is CrlDistPoint || obj == null)
|
||||
{
|
||||
return (CrlDistPoint)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new CrlDistPoint((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
private CrlDistPoint(Asn1Sequence seq)
|
||||
{
|
||||
this.seq = seq;
|
||||
}
|
||||
|
||||
public CrlDistPoint(DistributionPoint[] points)
|
||||
{
|
||||
seq = new DerSequence(points);
|
||||
}
|
||||
|
||||
public DistributionPoint[] GetDistributionPoints()
|
||||
{
|
||||
DistributionPoint[] array = new DistributionPoint[seq.Count];
|
||||
for (int i = 0; i != seq.Count; i++)
|
||||
{
|
||||
array[i] = DistributionPoint.GetInstance(seq[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return seq;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
string newLine = Platform.NewLine;
|
||||
stringBuilder.Append("CRLDistPoint:");
|
||||
stringBuilder.Append(newLine);
|
||||
DistributionPoint[] distributionPoints = GetDistributionPoints();
|
||||
for (int i = 0; i != distributionPoints.Length; i++)
|
||||
{
|
||||
stringBuilder.Append(" ");
|
||||
stringBuilder.Append(distributionPoints[i]);
|
||||
stringBuilder.Append(newLine);
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class CrlEntry : Asn1Encodable
|
||||
{
|
||||
internal Asn1Sequence seq;
|
||||
|
||||
internal DerInteger userCertificate;
|
||||
|
||||
internal Time revocationDate;
|
||||
|
||||
internal X509Extensions crlEntryExtensions;
|
||||
|
||||
public DerInteger UserCertificate => userCertificate;
|
||||
|
||||
public Time RevocationDate => revocationDate;
|
||||
|
||||
public X509Extensions Extensions
|
||||
{
|
||||
get
|
||||
{
|
||||
if (crlEntryExtensions == null && seq.Count == 3)
|
||||
{
|
||||
crlEntryExtensions = X509Extensions.GetInstance(seq[2]);
|
||||
}
|
||||
return crlEntryExtensions;
|
||||
}
|
||||
}
|
||||
|
||||
public CrlEntry(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count < 2 || seq.Count > 3)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count);
|
||||
}
|
||||
this.seq = seq;
|
||||
userCertificate = DerInteger.GetInstance(seq[0]);
|
||||
revocationDate = Time.GetInstance(seq[1]);
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return seq;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using Org.BouncyCastle.Math;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class CrlNumber : DerInteger
|
||||
{
|
||||
public BigInteger Number => base.PositiveValue;
|
||||
|
||||
public CrlNumber(BigInteger number)
|
||||
: base(number)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "CRLNumber: " + Number;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class CrlReason : DerEnumerated
|
||||
{
|
||||
public const int Unspecified = 0;
|
||||
|
||||
public const int KeyCompromise = 1;
|
||||
|
||||
public const int CACompromise = 2;
|
||||
|
||||
public const int AffiliationChanged = 3;
|
||||
|
||||
public const int Superseded = 4;
|
||||
|
||||
public const int CessationOfOperation = 5;
|
||||
|
||||
public const int CertificateHold = 6;
|
||||
|
||||
public const int RemoveFromCrl = 8;
|
||||
|
||||
public const int PrivilegeWithdrawn = 9;
|
||||
|
||||
public const int AACompromise = 10;
|
||||
|
||||
private static readonly string[] ReasonString = new string[11]
|
||||
{
|
||||
"Unspecified", "KeyCompromise", "CACompromise", "AffiliationChanged", "Superseded", "CessationOfOperation", "CertificateHold", "Unknown", "RemoveFromCrl", "PrivilegeWithdrawn",
|
||||
"AACompromise"
|
||||
};
|
||||
|
||||
public CrlReason(int reason)
|
||||
: base(reason)
|
||||
{
|
||||
}
|
||||
|
||||
public CrlReason(DerEnumerated reason)
|
||||
: base(reason.Value.IntValue)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
int intValue = base.Value.IntValue;
|
||||
string text = ((intValue < 0 || intValue > 10) ? "Invalid" : ReasonString[intValue]);
|
||||
return "CrlReason: " + text;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class DigestInfo : Asn1Encodable
|
||||
{
|
||||
private readonly byte[] digest;
|
||||
|
||||
private readonly AlgorithmIdentifier algID;
|
||||
|
||||
public AlgorithmIdentifier AlgorithmID => algID;
|
||||
|
||||
public static DigestInfo GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
|
||||
}
|
||||
|
||||
public static DigestInfo GetInstance(object obj)
|
||||
{
|
||||
if (obj is DigestInfo)
|
||||
{
|
||||
return (DigestInfo)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new DigestInfo((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public DigestInfo(AlgorithmIdentifier algID, byte[] digest)
|
||||
{
|
||||
this.digest = digest;
|
||||
this.algID = algID;
|
||||
}
|
||||
|
||||
private DigestInfo(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count != 2)
|
||||
{
|
||||
throw new ArgumentException("Wrong number of elements in sequence", "seq");
|
||||
}
|
||||
algID = AlgorithmIdentifier.GetInstance(seq[0]);
|
||||
digest = Asn1OctetString.GetInstance(seq[1]).GetOctets();
|
||||
}
|
||||
|
||||
public byte[] GetDigest()
|
||||
{
|
||||
return digest;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerSequence(algID, new DerOctetString(digest));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class DisplayText : Asn1Encodable, IAsn1Choice
|
||||
{
|
||||
public const int ContentTypeIA5String = 0;
|
||||
|
||||
public const int ContentTypeBmpString = 1;
|
||||
|
||||
public const int ContentTypeUtf8String = 2;
|
||||
|
||||
public const int ContentTypeVisibleString = 3;
|
||||
|
||||
public const int DisplayTextMaximumSize = 200;
|
||||
|
||||
internal readonly int contentType;
|
||||
|
||||
internal readonly IAsn1String contents;
|
||||
|
||||
public DisplayText(int type, string text)
|
||||
{
|
||||
if (text.Length > 200)
|
||||
{
|
||||
text = text.Substring(0, 200);
|
||||
}
|
||||
contentType = type;
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
contents = new DerIA5String(text);
|
||||
break;
|
||||
case 2:
|
||||
contents = new DerUtf8String(text);
|
||||
break;
|
||||
case 3:
|
||||
contents = new DerVisibleString(text);
|
||||
break;
|
||||
case 1:
|
||||
contents = new DerBmpString(text);
|
||||
break;
|
||||
default:
|
||||
contents = new DerUtf8String(text);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public DisplayText(string text)
|
||||
{
|
||||
if (text.Length > 200)
|
||||
{
|
||||
text = text.Substring(0, 200);
|
||||
}
|
||||
contentType = 2;
|
||||
contents = new DerUtf8String(text);
|
||||
}
|
||||
|
||||
public DisplayText(IAsn1String contents)
|
||||
{
|
||||
this.contents = contents;
|
||||
}
|
||||
|
||||
public static DisplayText GetInstance(object obj)
|
||||
{
|
||||
if (obj is IAsn1String)
|
||||
{
|
||||
return new DisplayText((IAsn1String)obj);
|
||||
}
|
||||
if (obj is DisplayText)
|
||||
{
|
||||
return (DisplayText)obj;
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return (Asn1Object)contents;
|
||||
}
|
||||
|
||||
public string GetString()
|
||||
{
|
||||
return contents.GetString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class DistributionPoint : Asn1Encodable
|
||||
{
|
||||
internal readonly DistributionPointName distributionPoint;
|
||||
|
||||
internal readonly ReasonFlags reasons;
|
||||
|
||||
internal readonly GeneralNames cRLIssuer;
|
||||
|
||||
public DistributionPointName DistributionPointName => distributionPoint;
|
||||
|
||||
public ReasonFlags Reasons => reasons;
|
||||
|
||||
public GeneralNames CrlIssuer => cRLIssuer;
|
||||
|
||||
public static DistributionPoint GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
|
||||
}
|
||||
|
||||
public static DistributionPoint GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is DistributionPoint)
|
||||
{
|
||||
return (DistributionPoint)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new DistributionPoint((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid DistributionPoint: " + Platform.GetTypeName(obj));
|
||||
}
|
||||
|
||||
private DistributionPoint(Asn1Sequence seq)
|
||||
{
|
||||
for (int i = 0; i != seq.Count; i++)
|
||||
{
|
||||
Asn1TaggedObject instance = Asn1TaggedObject.GetInstance(seq[i]);
|
||||
switch (instance.TagNo)
|
||||
{
|
||||
case 0:
|
||||
distributionPoint = DistributionPointName.GetInstance(instance, explicitly: true);
|
||||
break;
|
||||
case 1:
|
||||
reasons = new ReasonFlags(DerBitString.GetInstance(instance, isExplicit: false));
|
||||
break;
|
||||
case 2:
|
||||
cRLIssuer = GeneralNames.GetInstance(instance, explicitly: false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public DistributionPoint(DistributionPointName distributionPointName, ReasonFlags reasons, GeneralNames crlIssuer)
|
||||
{
|
||||
distributionPoint = distributionPointName;
|
||||
this.reasons = reasons;
|
||||
cRLIssuer = crlIssuer;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
if (distributionPoint != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(0, distributionPoint));
|
||||
}
|
||||
if (reasons != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 1, reasons));
|
||||
}
|
||||
if (cRLIssuer != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 2, cRLIssuer));
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string newLine = Platform.NewLine;
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.Append("DistributionPoint: [");
|
||||
stringBuilder.Append(newLine);
|
||||
if (distributionPoint != null)
|
||||
{
|
||||
appendObject(stringBuilder, newLine, "distributionPoint", distributionPoint.ToString());
|
||||
}
|
||||
if (reasons != null)
|
||||
{
|
||||
appendObject(stringBuilder, newLine, "reasons", reasons.ToString());
|
||||
}
|
||||
if (cRLIssuer != null)
|
||||
{
|
||||
appendObject(stringBuilder, newLine, "cRLIssuer", cRLIssuer.ToString());
|
||||
}
|
||||
stringBuilder.Append("]");
|
||||
stringBuilder.Append(newLine);
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
private void appendObject(StringBuilder buf, string sep, string name, string val)
|
||||
{
|
||||
string value = " ";
|
||||
buf.Append(value);
|
||||
buf.Append(name);
|
||||
buf.Append(":");
|
||||
buf.Append(sep);
|
||||
buf.Append(value);
|
||||
buf.Append(value);
|
||||
buf.Append(val);
|
||||
buf.Append(sep);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class DistributionPointName : Asn1Encodable, IAsn1Choice
|
||||
{
|
||||
public const int FullName = 0;
|
||||
|
||||
public const int NameRelativeToCrlIssuer = 1;
|
||||
|
||||
internal readonly Asn1Encodable name;
|
||||
|
||||
internal readonly int type;
|
||||
|
||||
public int PointType => type;
|
||||
|
||||
public Asn1Encodable Name => name;
|
||||
|
||||
public static DistributionPointName GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1TaggedObject.GetInstance(obj, explicitly: true));
|
||||
}
|
||||
|
||||
public static DistributionPointName GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is DistributionPointName)
|
||||
{
|
||||
return (DistributionPointName)obj;
|
||||
}
|
||||
if (obj is Asn1TaggedObject)
|
||||
{
|
||||
return new DistributionPointName((Asn1TaggedObject)obj);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public DistributionPointName(int type, Asn1Encodable name)
|
||||
{
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public DistributionPointName(GeneralNames name)
|
||||
: this(0, name)
|
||||
{
|
||||
}
|
||||
|
||||
public DistributionPointName(Asn1TaggedObject obj)
|
||||
{
|
||||
type = obj.TagNo;
|
||||
if (type == 0)
|
||||
{
|
||||
name = GeneralNames.GetInstance(obj, explicitly: false);
|
||||
}
|
||||
else
|
||||
{
|
||||
name = Asn1Set.GetInstance(obj, explicitly: false);
|
||||
}
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerTaggedObject(explicitly: false, type, name);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string newLine = Platform.NewLine;
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.Append("DistributionPointName: [");
|
||||
stringBuilder.Append(newLine);
|
||||
if (type == 0)
|
||||
{
|
||||
appendObject(stringBuilder, newLine, "fullName", name.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
appendObject(stringBuilder, newLine, "nameRelativeToCRLIssuer", name.ToString());
|
||||
}
|
||||
stringBuilder.Append("]");
|
||||
stringBuilder.Append(newLine);
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
private void appendObject(StringBuilder buf, string sep, string name, string val)
|
||||
{
|
||||
string value = " ";
|
||||
buf.Append(value);
|
||||
buf.Append(name);
|
||||
buf.Append(":");
|
||||
buf.Append(sep);
|
||||
buf.Append(value);
|
||||
buf.Append(value);
|
||||
buf.Append(val);
|
||||
buf.Append(sep);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Math;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class DsaParameter : Asn1Encodable
|
||||
{
|
||||
internal readonly DerInteger p;
|
||||
|
||||
internal readonly DerInteger q;
|
||||
|
||||
internal readonly DerInteger g;
|
||||
|
||||
public BigInteger P => p.PositiveValue;
|
||||
|
||||
public BigInteger Q => q.PositiveValue;
|
||||
|
||||
public BigInteger G => g.PositiveValue;
|
||||
|
||||
public static DsaParameter GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
|
||||
}
|
||||
|
||||
public static DsaParameter GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is DsaParameter)
|
||||
{
|
||||
return (DsaParameter)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new DsaParameter((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid DsaParameter: " + Platform.GetTypeName(obj));
|
||||
}
|
||||
|
||||
public DsaParameter(BigInteger p, BigInteger q, BigInteger g)
|
||||
{
|
||||
this.p = new DerInteger(p);
|
||||
this.q = new DerInteger(q);
|
||||
this.g = new DerInteger(g);
|
||||
}
|
||||
|
||||
private DsaParameter(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count != 3)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
|
||||
}
|
||||
p = DerInteger.GetInstance(seq[0]);
|
||||
q = DerInteger.GetInstance(seq[1]);
|
||||
g = DerInteger.GetInstance(seq[2]);
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerSequence(p, q, g);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class ExtendedKeyUsage : Asn1Encodable
|
||||
{
|
||||
internal readonly IDictionary usageTable = Platform.CreateHashtable();
|
||||
|
||||
internal readonly Asn1Sequence seq;
|
||||
|
||||
public int Count => usageTable.Count;
|
||||
|
||||
public static ExtendedKeyUsage GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
|
||||
}
|
||||
|
||||
public static ExtendedKeyUsage GetInstance(object obj)
|
||||
{
|
||||
if (obj is ExtendedKeyUsage)
|
||||
{
|
||||
return (ExtendedKeyUsage)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new ExtendedKeyUsage((Asn1Sequence)obj);
|
||||
}
|
||||
if (obj is X509Extension)
|
||||
{
|
||||
return GetInstance(X509Extension.ConvertValueToObject((X509Extension)obj));
|
||||
}
|
||||
throw new ArgumentException("Invalid ExtendedKeyUsage: " + Platform.GetTypeName(obj));
|
||||
}
|
||||
|
||||
private ExtendedKeyUsage(Asn1Sequence seq)
|
||||
{
|
||||
this.seq = seq;
|
||||
foreach (object item in seq)
|
||||
{
|
||||
if (!(item is DerObjectIdentifier))
|
||||
{
|
||||
throw new ArgumentException("Only DerObjectIdentifier instances allowed in ExtendedKeyUsage.");
|
||||
}
|
||||
usageTable[item] = item;
|
||||
}
|
||||
}
|
||||
|
||||
public ExtendedKeyUsage(params KeyPurposeID[] usages)
|
||||
{
|
||||
seq = new DerSequence(usages);
|
||||
foreach (KeyPurposeID keyPurposeID in usages)
|
||||
{
|
||||
usageTable[keyPurposeID] = keyPurposeID;
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public ExtendedKeyUsage(ArrayList usages)
|
||||
: this((IEnumerable)usages)
|
||||
{
|
||||
}
|
||||
|
||||
public ExtendedKeyUsage(IEnumerable usages)
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
foreach (object usage in usages)
|
||||
{
|
||||
Asn1Encodable instance = DerObjectIdentifier.GetInstance(usage);
|
||||
asn1EncodableVector.Add(instance);
|
||||
usageTable[instance] = instance;
|
||||
}
|
||||
seq = new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
|
||||
public bool HasKeyPurposeId(KeyPurposeID keyPurposeId)
|
||||
{
|
||||
return usageTable.Contains(keyPurposeId);
|
||||
}
|
||||
|
||||
[Obsolete("Use 'GetAllUsages'")]
|
||||
public ArrayList GetUsages()
|
||||
{
|
||||
return new ArrayList(usageTable.Values);
|
||||
}
|
||||
|
||||
public IList GetAllUsages()
|
||||
{
|
||||
return Platform.CreateArrayList(usageTable.Values);
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return seq;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
using Org.BouncyCastle.Utilities.Net;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class GeneralName : Asn1Encodable, IAsn1Choice
|
||||
{
|
||||
public const int OtherName = 0;
|
||||
|
||||
public const int Rfc822Name = 1;
|
||||
|
||||
public const int DnsName = 2;
|
||||
|
||||
public const int X400Address = 3;
|
||||
|
||||
public const int DirectoryName = 4;
|
||||
|
||||
public const int EdiPartyName = 5;
|
||||
|
||||
public const int UniformResourceIdentifier = 6;
|
||||
|
||||
public const int IPAddress = 7;
|
||||
|
||||
public const int RegisteredID = 8;
|
||||
|
||||
internal readonly Asn1Encodable obj;
|
||||
|
||||
internal readonly int tag;
|
||||
|
||||
public int TagNo => tag;
|
||||
|
||||
public Asn1Encodable Name => obj;
|
||||
|
||||
public GeneralName(X509Name directoryName)
|
||||
{
|
||||
obj = directoryName;
|
||||
tag = 4;
|
||||
}
|
||||
|
||||
public GeneralName(Asn1Object name, int tag)
|
||||
{
|
||||
obj = name;
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public GeneralName(int tag, Asn1Encodable name)
|
||||
{
|
||||
obj = name;
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public GeneralName(int tag, string name)
|
||||
{
|
||||
this.tag = tag;
|
||||
switch (tag)
|
||||
{
|
||||
case 1:
|
||||
case 2:
|
||||
case 6:
|
||||
obj = new DerIA5String(name);
|
||||
break;
|
||||
case 8:
|
||||
obj = new DerObjectIdentifier(name);
|
||||
break;
|
||||
case 4:
|
||||
obj = new X509Name(name);
|
||||
break;
|
||||
case 7:
|
||||
{
|
||||
byte[] array = toGeneralNameEncoding(name);
|
||||
if (array == null)
|
||||
{
|
||||
throw new ArgumentException("IP Address is invalid", "name");
|
||||
}
|
||||
obj = new DerOctetString(array);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new ArgumentException("can't process string for tag: " + tag, "tag");
|
||||
}
|
||||
}
|
||||
|
||||
public static GeneralName GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is GeneralName)
|
||||
{
|
||||
return (GeneralName)obj;
|
||||
}
|
||||
if (obj is Asn1TaggedObject)
|
||||
{
|
||||
Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)obj;
|
||||
int tagNo = asn1TaggedObject.TagNo;
|
||||
switch (tagNo)
|
||||
{
|
||||
case 0:
|
||||
return new GeneralName(tagNo, Asn1Sequence.GetInstance(asn1TaggedObject, explicitly: false));
|
||||
case 1:
|
||||
return new GeneralName(tagNo, DerIA5String.GetInstance(asn1TaggedObject, isExplicit: false));
|
||||
case 2:
|
||||
return new GeneralName(tagNo, DerIA5String.GetInstance(asn1TaggedObject, isExplicit: false));
|
||||
case 3:
|
||||
throw new ArgumentException("unknown tag: " + tagNo);
|
||||
case 4:
|
||||
return new GeneralName(tagNo, X509Name.GetInstance(asn1TaggedObject, explicitly: true));
|
||||
case 5:
|
||||
return new GeneralName(tagNo, Asn1Sequence.GetInstance(asn1TaggedObject, explicitly: false));
|
||||
case 6:
|
||||
return new GeneralName(tagNo, DerIA5String.GetInstance(asn1TaggedObject, isExplicit: false));
|
||||
case 7:
|
||||
return new GeneralName(tagNo, Asn1OctetString.GetInstance(asn1TaggedObject, isExplicit: false));
|
||||
case 8:
|
||||
return new GeneralName(tagNo, DerObjectIdentifier.GetInstance(asn1TaggedObject, explicitly: false));
|
||||
}
|
||||
}
|
||||
if (obj is byte[])
|
||||
{
|
||||
try
|
||||
{
|
||||
return GetInstance(Asn1Object.FromByteArray((byte[])obj));
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
throw new ArgumentException("unable to parse encoded general name");
|
||||
}
|
||||
}
|
||||
throw new ArgumentException("unknown object in GetInstance: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public static GeneralName GetInstance(Asn1TaggedObject tagObj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1TaggedObject.GetInstance(tagObj, explicitly: true));
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.Append(tag);
|
||||
stringBuilder.Append(": ");
|
||||
switch (tag)
|
||||
{
|
||||
case 1:
|
||||
case 2:
|
||||
case 6:
|
||||
stringBuilder.Append(DerIA5String.GetInstance(obj).GetString());
|
||||
break;
|
||||
case 4:
|
||||
stringBuilder.Append(X509Name.GetInstance(obj).ToString());
|
||||
break;
|
||||
default:
|
||||
stringBuilder.Append(obj.ToString());
|
||||
break;
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
private byte[] toGeneralNameEncoding(string ip)
|
||||
{
|
||||
if (Org.BouncyCastle.Utilities.Net.IPAddress.IsValidIPv6WithNetmask(ip) || Org.BouncyCastle.Utilities.Net.IPAddress.IsValidIPv6(ip))
|
||||
{
|
||||
int num = ip.IndexOf('/');
|
||||
if (num < 0)
|
||||
{
|
||||
byte[] array = new byte[16];
|
||||
int[] parsedIp = parseIPv6(ip);
|
||||
copyInts(parsedIp, array, 0);
|
||||
return array;
|
||||
}
|
||||
byte[] array2 = new byte[32];
|
||||
int[] parsedIp2 = parseIPv6(ip.Substring(0, num));
|
||||
copyInts(parsedIp2, array2, 0);
|
||||
string text = ip.Substring(num + 1);
|
||||
parsedIp2 = ((text.IndexOf(':') <= 0) ? parseMask(text) : parseIPv6(text));
|
||||
copyInts(parsedIp2, array2, 16);
|
||||
return array2;
|
||||
}
|
||||
if (Org.BouncyCastle.Utilities.Net.IPAddress.IsValidIPv4WithNetmask(ip) || Org.BouncyCastle.Utilities.Net.IPAddress.IsValidIPv4(ip))
|
||||
{
|
||||
int num2 = ip.IndexOf('/');
|
||||
if (num2 < 0)
|
||||
{
|
||||
byte[] array3 = new byte[4];
|
||||
parseIPv4(ip, array3, 0);
|
||||
return array3;
|
||||
}
|
||||
byte[] array4 = new byte[8];
|
||||
parseIPv4(ip.Substring(0, num2), array4, 0);
|
||||
string text2 = ip.Substring(num2 + 1);
|
||||
if (text2.IndexOf('.') > 0)
|
||||
{
|
||||
parseIPv4(text2, array4, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
parseIPv4Mask(text2, array4, 4);
|
||||
}
|
||||
return array4;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void parseIPv4Mask(string mask, byte[] addr, int offset)
|
||||
{
|
||||
int num = int.Parse(mask);
|
||||
for (int i = 0; i != num; i++)
|
||||
{
|
||||
byte[] array2;
|
||||
byte[] array = (array2 = addr);
|
||||
int num2 = i / 8 + offset;
|
||||
nint num3 = num2;
|
||||
array[num2] = (byte)(array2[num3] | (byte)(1 << i % 8));
|
||||
}
|
||||
}
|
||||
|
||||
private void parseIPv4(string ip, byte[] addr, int offset)
|
||||
{
|
||||
string[] array = ip.Split('.', '/');
|
||||
foreach (string s in array)
|
||||
{
|
||||
addr[offset++] = (byte)int.Parse(s);
|
||||
}
|
||||
}
|
||||
|
||||
private int[] parseMask(string mask)
|
||||
{
|
||||
int[] array = new int[8];
|
||||
int num = int.Parse(mask);
|
||||
for (int i = 0; i != num; i++)
|
||||
{
|
||||
int[] array3;
|
||||
int[] array2 = (array3 = array);
|
||||
int num2 = i / 16;
|
||||
nint num3 = num2;
|
||||
array2[num2] = array3[num3] | (1 << i % 16);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
private void copyInts(int[] parsedIp, byte[] addr, int offSet)
|
||||
{
|
||||
for (int i = 0; i != parsedIp.Length; i++)
|
||||
{
|
||||
addr[i * 2 + offSet] = (byte)(parsedIp[i] >> 8);
|
||||
addr[i * 2 + 1 + offSet] = (byte)parsedIp[i];
|
||||
}
|
||||
}
|
||||
|
||||
private int[] parseIPv6(string ip)
|
||||
{
|
||||
if (Platform.StartsWith(ip, "::"))
|
||||
{
|
||||
ip = ip.Substring(1);
|
||||
}
|
||||
else if (Platform.EndsWith(ip, "::"))
|
||||
{
|
||||
ip = ip.Substring(0, ip.Length - 1);
|
||||
}
|
||||
IEnumerator enumerator = ip.Split(new char[1] { ':' }).GetEnumerator();
|
||||
int num = 0;
|
||||
int[] array = new int[8];
|
||||
int num2 = -1;
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
string text = (string)enumerator.Current;
|
||||
if (text.Length == 0)
|
||||
{
|
||||
num2 = num;
|
||||
array[num++] = 0;
|
||||
continue;
|
||||
}
|
||||
if (text.IndexOf('.') < 0)
|
||||
{
|
||||
array[num++] = int.Parse(text, NumberStyles.AllowHexSpecifier);
|
||||
continue;
|
||||
}
|
||||
string[] array2 = text.Split(new char[1] { '.' });
|
||||
array[num++] = (int.Parse(array2[0]) << 8) | int.Parse(array2[1]);
|
||||
array[num++] = (int.Parse(array2[2]) << 8) | int.Parse(array2[3]);
|
||||
}
|
||||
if (num != array.Length)
|
||||
{
|
||||
Array.Copy(array, num2, array, array.Length - (num - num2), num - num2);
|
||||
for (int i = num2; i != array.Length - (num - num2); i++)
|
||||
{
|
||||
array[i] = 0;
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerTaggedObject(tag == 4, tag, obj);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class GeneralNames : Asn1Encodable
|
||||
{
|
||||
private readonly GeneralName[] names;
|
||||
|
||||
public static GeneralNames GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is GeneralNames)
|
||||
{
|
||||
return (GeneralNames)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new GeneralNames((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public static GeneralNames GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
|
||||
}
|
||||
|
||||
public GeneralNames(GeneralName name)
|
||||
{
|
||||
names = new GeneralName[1] { name };
|
||||
}
|
||||
|
||||
public GeneralNames(GeneralName[] names)
|
||||
{
|
||||
this.names = (GeneralName[])names.Clone();
|
||||
}
|
||||
|
||||
private GeneralNames(Asn1Sequence seq)
|
||||
{
|
||||
names = new GeneralName[seq.Count];
|
||||
for (int i = 0; i != seq.Count; i++)
|
||||
{
|
||||
names[i] = GeneralName.GetInstance(seq[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public GeneralName[] GetNames()
|
||||
{
|
||||
return (GeneralName[])names.Clone();
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerSequence(names);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
string newLine = Platform.NewLine;
|
||||
stringBuilder.Append("GeneralNames:");
|
||||
stringBuilder.Append(newLine);
|
||||
GeneralName[] array = names;
|
||||
foreach (GeneralName value in array)
|
||||
{
|
||||
stringBuilder.Append(" ");
|
||||
stringBuilder.Append(value);
|
||||
stringBuilder.Append(newLine);
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Math;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class GeneralSubtree : Asn1Encodable
|
||||
{
|
||||
private readonly GeneralName baseName;
|
||||
|
||||
private readonly DerInteger minimum;
|
||||
|
||||
private readonly DerInteger maximum;
|
||||
|
||||
public GeneralName Base => baseName;
|
||||
|
||||
public BigInteger Minimum
|
||||
{
|
||||
get
|
||||
{
|
||||
if (minimum != null)
|
||||
{
|
||||
return minimum.Value;
|
||||
}
|
||||
return BigInteger.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
public BigInteger Maximum
|
||||
{
|
||||
get
|
||||
{
|
||||
if (maximum != null)
|
||||
{
|
||||
return maximum.Value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private GeneralSubtree(Asn1Sequence seq)
|
||||
{
|
||||
baseName = GeneralName.GetInstance(seq[0]);
|
||||
switch (seq.Count)
|
||||
{
|
||||
case 2:
|
||||
{
|
||||
Asn1TaggedObject instance3 = Asn1TaggedObject.GetInstance(seq[1]);
|
||||
switch (instance3.TagNo)
|
||||
{
|
||||
case 0:
|
||||
minimum = DerInteger.GetInstance(instance3, isExplicit: false);
|
||||
break;
|
||||
case 1:
|
||||
maximum = DerInteger.GetInstance(instance3, isExplicit: false);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Bad tag number: " + instance3.TagNo);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
Asn1TaggedObject instance = Asn1TaggedObject.GetInstance(seq[1]);
|
||||
if (instance.TagNo != 0)
|
||||
{
|
||||
throw new ArgumentException("Bad tag number for 'minimum': " + instance.TagNo);
|
||||
}
|
||||
minimum = DerInteger.GetInstance(instance, isExplicit: false);
|
||||
Asn1TaggedObject instance2 = Asn1TaggedObject.GetInstance(seq[2]);
|
||||
if (instance2.TagNo != 1)
|
||||
{
|
||||
throw new ArgumentException("Bad tag number for 'maximum': " + instance2.TagNo);
|
||||
}
|
||||
maximum = DerInteger.GetInstance(instance2, isExplicit: false);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count);
|
||||
case 1:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public GeneralSubtree(GeneralName baseName, BigInteger minimum, BigInteger maximum)
|
||||
{
|
||||
this.baseName = baseName;
|
||||
if (minimum != null)
|
||||
{
|
||||
this.minimum = new DerInteger(minimum);
|
||||
}
|
||||
if (maximum != null)
|
||||
{
|
||||
this.maximum = new DerInteger(maximum);
|
||||
}
|
||||
}
|
||||
|
||||
public GeneralSubtree(GeneralName baseName)
|
||||
: this(baseName, null, null)
|
||||
{
|
||||
}
|
||||
|
||||
public static GeneralSubtree GetInstance(Asn1TaggedObject o, bool isExplicit)
|
||||
{
|
||||
return new GeneralSubtree(Asn1Sequence.GetInstance(o, isExplicit));
|
||||
}
|
||||
|
||||
public static GeneralSubtree GetInstance(object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (obj is GeneralSubtree)
|
||||
{
|
||||
return (GeneralSubtree)obj;
|
||||
}
|
||||
return new GeneralSubtree(Asn1Sequence.GetInstance(obj));
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(baseName);
|
||||
if (minimum != null && minimum.Value.SignValue != 0)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 0, minimum));
|
||||
}
|
||||
if (maximum != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 1, maximum));
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class Holder : Asn1Encodable
|
||||
{
|
||||
internal readonly IssuerSerial baseCertificateID;
|
||||
|
||||
internal readonly GeneralNames entityName;
|
||||
|
||||
internal readonly ObjectDigestInfo objectDigestInfo;
|
||||
|
||||
private readonly int version;
|
||||
|
||||
public int Version => version;
|
||||
|
||||
public IssuerSerial BaseCertificateID => baseCertificateID;
|
||||
|
||||
public GeneralNames EntityName => entityName;
|
||||
|
||||
public ObjectDigestInfo ObjectDigestInfo => objectDigestInfo;
|
||||
|
||||
public static Holder GetInstance(object obj)
|
||||
{
|
||||
if (obj is Holder)
|
||||
{
|
||||
return (Holder)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new Holder((Asn1Sequence)obj);
|
||||
}
|
||||
if (obj is Asn1TaggedObject)
|
||||
{
|
||||
return new Holder((Asn1TaggedObject)obj);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public Holder(Asn1TaggedObject tagObj)
|
||||
{
|
||||
switch (tagObj.TagNo)
|
||||
{
|
||||
case 0:
|
||||
baseCertificateID = IssuerSerial.GetInstance(tagObj, explicitly: false);
|
||||
break;
|
||||
case 1:
|
||||
entityName = GeneralNames.GetInstance(tagObj, explicitly: false);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("unknown tag in Holder");
|
||||
}
|
||||
version = 0;
|
||||
}
|
||||
|
||||
private Holder(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count > 3)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count);
|
||||
}
|
||||
for (int i = 0; i != seq.Count; i++)
|
||||
{
|
||||
Asn1TaggedObject instance = Asn1TaggedObject.GetInstance(seq[i]);
|
||||
switch (instance.TagNo)
|
||||
{
|
||||
case 0:
|
||||
baseCertificateID = IssuerSerial.GetInstance(instance, explicitly: false);
|
||||
break;
|
||||
case 1:
|
||||
entityName = GeneralNames.GetInstance(instance, explicitly: false);
|
||||
break;
|
||||
case 2:
|
||||
objectDigestInfo = ObjectDigestInfo.GetInstance(instance, isExplicit: false);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("unknown tag in Holder");
|
||||
}
|
||||
}
|
||||
version = 1;
|
||||
}
|
||||
|
||||
public Holder(IssuerSerial baseCertificateID)
|
||||
: this(baseCertificateID, 1)
|
||||
{
|
||||
}
|
||||
|
||||
public Holder(IssuerSerial baseCertificateID, int version)
|
||||
{
|
||||
this.baseCertificateID = baseCertificateID;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public Holder(GeneralNames entityName)
|
||||
: this(entityName, 1)
|
||||
{
|
||||
}
|
||||
|
||||
public Holder(GeneralNames entityName, int version)
|
||||
{
|
||||
this.entityName = entityName;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public Holder(ObjectDigestInfo objectDigestInfo)
|
||||
{
|
||||
this.objectDigestInfo = objectDigestInfo;
|
||||
version = 1;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
if (version == 1)
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
if (baseCertificateID != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 0, baseCertificateID));
|
||||
}
|
||||
if (entityName != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 1, entityName));
|
||||
}
|
||||
if (objectDigestInfo != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 2, objectDigestInfo));
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
if (entityName != null)
|
||||
{
|
||||
return new DerTaggedObject(explicitly: false, 1, entityName);
|
||||
}
|
||||
return new DerTaggedObject(explicitly: false, 0, baseCertificateID);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class IetfAttrSyntax : Asn1Encodable
|
||||
{
|
||||
public const int ValueOctets = 1;
|
||||
|
||||
public const int ValueOid = 2;
|
||||
|
||||
public const int ValueUtf8 = 3;
|
||||
|
||||
internal readonly GeneralNames policyAuthority;
|
||||
|
||||
internal readonly Asn1EncodableVector values = new Asn1EncodableVector();
|
||||
|
||||
internal int valueChoice = -1;
|
||||
|
||||
public GeneralNames PolicyAuthority => policyAuthority;
|
||||
|
||||
public int ValueType => valueChoice;
|
||||
|
||||
public IetfAttrSyntax(Asn1Sequence seq)
|
||||
{
|
||||
int num = 0;
|
||||
if (seq[0] is Asn1TaggedObject)
|
||||
{
|
||||
policyAuthority = GeneralNames.GetInstance((Asn1TaggedObject)seq[0], explicitly: false);
|
||||
num++;
|
||||
}
|
||||
else if (seq.Count == 2)
|
||||
{
|
||||
policyAuthority = GeneralNames.GetInstance(seq[0]);
|
||||
num++;
|
||||
}
|
||||
if (!(seq[num] is Asn1Sequence))
|
||||
{
|
||||
throw new ArgumentException("Non-IetfAttrSyntax encoding");
|
||||
}
|
||||
seq = (Asn1Sequence)seq[num];
|
||||
foreach (Asn1Object item in seq)
|
||||
{
|
||||
int num2;
|
||||
if (item is DerObjectIdentifier)
|
||||
{
|
||||
num2 = 2;
|
||||
}
|
||||
else if (item is DerUtf8String)
|
||||
{
|
||||
num2 = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(item is DerOctetString))
|
||||
{
|
||||
throw new ArgumentException("Bad value type encoding IetfAttrSyntax");
|
||||
}
|
||||
num2 = 1;
|
||||
}
|
||||
if (valueChoice < 0)
|
||||
{
|
||||
valueChoice = num2;
|
||||
}
|
||||
if (num2 != valueChoice)
|
||||
{
|
||||
throw new ArgumentException("Mix of value types in IetfAttrSyntax");
|
||||
}
|
||||
values.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
public object[] GetValues()
|
||||
{
|
||||
if (ValueType == 1)
|
||||
{
|
||||
Asn1OctetString[] array = new Asn1OctetString[values.Count];
|
||||
for (int i = 0; i != array.Length; i++)
|
||||
{
|
||||
array[i] = (Asn1OctetString)values[i];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
if (ValueType == 2)
|
||||
{
|
||||
DerObjectIdentifier[] array2 = new DerObjectIdentifier[values.Count];
|
||||
for (int j = 0; j != array2.Length; j++)
|
||||
{
|
||||
array2[j] = (DerObjectIdentifier)values[j];
|
||||
}
|
||||
return array2;
|
||||
}
|
||||
DerUtf8String[] array3 = new DerUtf8String[values.Count];
|
||||
for (int k = 0; k != array3.Length; k++)
|
||||
{
|
||||
array3[k] = (DerUtf8String)values[k];
|
||||
}
|
||||
return array3;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
if (policyAuthority != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(0, policyAuthority));
|
||||
}
|
||||
asn1EncodableVector.Add(new DerSequence(values));
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class IssuerSerial : Asn1Encodable
|
||||
{
|
||||
internal readonly GeneralNames issuer;
|
||||
|
||||
internal readonly DerInteger serial;
|
||||
|
||||
internal readonly DerBitString issuerUid;
|
||||
|
||||
public GeneralNames Issuer => issuer;
|
||||
|
||||
public DerInteger Serial => serial;
|
||||
|
||||
public DerBitString IssuerUid => issuerUid;
|
||||
|
||||
public static IssuerSerial GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is IssuerSerial)
|
||||
{
|
||||
return (IssuerSerial)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new IssuerSerial((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public static IssuerSerial GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
|
||||
}
|
||||
|
||||
private IssuerSerial(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count != 2 && seq.Count != 3)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count);
|
||||
}
|
||||
issuer = GeneralNames.GetInstance(seq[0]);
|
||||
serial = DerInteger.GetInstance(seq[1]);
|
||||
if (seq.Count == 3)
|
||||
{
|
||||
issuerUid = DerBitString.GetInstance(seq[2]);
|
||||
}
|
||||
}
|
||||
|
||||
public IssuerSerial(GeneralNames issuer, DerInteger serial)
|
||||
{
|
||||
this.issuer = issuer;
|
||||
this.serial = serial;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(issuer, serial);
|
||||
if (issuerUid != null)
|
||||
{
|
||||
asn1EncodableVector.Add(issuerUid);
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class IssuingDistributionPoint : Asn1Encodable
|
||||
{
|
||||
private readonly DistributionPointName _distributionPoint;
|
||||
|
||||
private readonly bool _onlyContainsUserCerts;
|
||||
|
||||
private readonly bool _onlyContainsCACerts;
|
||||
|
||||
private readonly ReasonFlags _onlySomeReasons;
|
||||
|
||||
private readonly bool _indirectCRL;
|
||||
|
||||
private readonly bool _onlyContainsAttributeCerts;
|
||||
|
||||
private readonly Asn1Sequence seq;
|
||||
|
||||
public bool OnlyContainsUserCerts => _onlyContainsUserCerts;
|
||||
|
||||
public bool OnlyContainsCACerts => _onlyContainsCACerts;
|
||||
|
||||
public bool IsIndirectCrl => _indirectCRL;
|
||||
|
||||
public bool OnlyContainsAttributeCerts => _onlyContainsAttributeCerts;
|
||||
|
||||
public DistributionPointName DistributionPoint => _distributionPoint;
|
||||
|
||||
public ReasonFlags OnlySomeReasons => _onlySomeReasons;
|
||||
|
||||
public static IssuingDistributionPoint GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
|
||||
}
|
||||
|
||||
public static IssuingDistributionPoint GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is IssuingDistributionPoint)
|
||||
{
|
||||
return (IssuingDistributionPoint)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new IssuingDistributionPoint((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public IssuingDistributionPoint(DistributionPointName distributionPoint, bool onlyContainsUserCerts, bool onlyContainsCACerts, ReasonFlags onlySomeReasons, bool indirectCRL, bool onlyContainsAttributeCerts)
|
||||
{
|
||||
_distributionPoint = distributionPoint;
|
||||
_indirectCRL = indirectCRL;
|
||||
_onlyContainsAttributeCerts = onlyContainsAttributeCerts;
|
||||
_onlyContainsCACerts = onlyContainsCACerts;
|
||||
_onlyContainsUserCerts = onlyContainsUserCerts;
|
||||
_onlySomeReasons = onlySomeReasons;
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
if (distributionPoint != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: true, 0, distributionPoint));
|
||||
}
|
||||
if (onlyContainsUserCerts)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 1, DerBoolean.True));
|
||||
}
|
||||
if (onlyContainsCACerts)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 2, DerBoolean.True));
|
||||
}
|
||||
if (onlySomeReasons != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 3, onlySomeReasons));
|
||||
}
|
||||
if (indirectCRL)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 4, DerBoolean.True));
|
||||
}
|
||||
if (onlyContainsAttributeCerts)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 5, DerBoolean.True));
|
||||
}
|
||||
seq = new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
|
||||
private IssuingDistributionPoint(Asn1Sequence seq)
|
||||
{
|
||||
this.seq = seq;
|
||||
for (int i = 0; i != seq.Count; i++)
|
||||
{
|
||||
Asn1TaggedObject instance = Asn1TaggedObject.GetInstance(seq[i]);
|
||||
switch (instance.TagNo)
|
||||
{
|
||||
case 0:
|
||||
_distributionPoint = DistributionPointName.GetInstance(instance, explicitly: true);
|
||||
break;
|
||||
case 1:
|
||||
_onlyContainsUserCerts = DerBoolean.GetInstance(instance, isExplicit: false).IsTrue;
|
||||
break;
|
||||
case 2:
|
||||
_onlyContainsCACerts = DerBoolean.GetInstance(instance, isExplicit: false).IsTrue;
|
||||
break;
|
||||
case 3:
|
||||
_onlySomeReasons = new ReasonFlags(DerBitString.GetInstance(instance, isExplicit: false));
|
||||
break;
|
||||
case 4:
|
||||
_indirectCRL = DerBoolean.GetInstance(instance, isExplicit: false).IsTrue;
|
||||
break;
|
||||
case 5:
|
||||
_onlyContainsAttributeCerts = DerBoolean.GetInstance(instance, isExplicit: false).IsTrue;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("unknown tag in IssuingDistributionPoint");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return seq;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string newLine = Platform.NewLine;
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.Append("IssuingDistributionPoint: [");
|
||||
stringBuilder.Append(newLine);
|
||||
if (_distributionPoint != null)
|
||||
{
|
||||
appendObject(stringBuilder, newLine, "distributionPoint", _distributionPoint.ToString());
|
||||
}
|
||||
if (_onlyContainsUserCerts)
|
||||
{
|
||||
bool onlyContainsUserCerts = _onlyContainsUserCerts;
|
||||
appendObject(stringBuilder, newLine, "onlyContainsUserCerts", onlyContainsUserCerts.ToString());
|
||||
}
|
||||
if (_onlyContainsCACerts)
|
||||
{
|
||||
bool onlyContainsUserCerts = _onlyContainsCACerts;
|
||||
appendObject(stringBuilder, newLine, "onlyContainsCACerts", onlyContainsUserCerts.ToString());
|
||||
}
|
||||
if (_onlySomeReasons != null)
|
||||
{
|
||||
appendObject(stringBuilder, newLine, "onlySomeReasons", _onlySomeReasons.ToString());
|
||||
}
|
||||
if (_onlyContainsAttributeCerts)
|
||||
{
|
||||
bool onlyContainsUserCerts = _onlyContainsAttributeCerts;
|
||||
appendObject(stringBuilder, newLine, "onlyContainsAttributeCerts", onlyContainsUserCerts.ToString());
|
||||
}
|
||||
if (_indirectCRL)
|
||||
{
|
||||
bool onlyContainsUserCerts = _indirectCRL;
|
||||
appendObject(stringBuilder, newLine, "indirectCRL", onlyContainsUserCerts.ToString());
|
||||
}
|
||||
stringBuilder.Append("]");
|
||||
stringBuilder.Append(newLine);
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
private void appendObject(StringBuilder buf, string sep, string name, string val)
|
||||
{
|
||||
string value = " ";
|
||||
buf.Append(value);
|
||||
buf.Append(name);
|
||||
buf.Append(":");
|
||||
buf.Append(sep);
|
||||
buf.Append(value);
|
||||
buf.Append(value);
|
||||
buf.Append(val);
|
||||
buf.Append(sep);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public sealed class KeyPurposeID : DerObjectIdentifier
|
||||
{
|
||||
private const string IdKP = "1.3.6.1.5.5.7.3";
|
||||
|
||||
public static readonly KeyPurposeID AnyExtendedKeyUsage = new KeyPurposeID(X509Extensions.ExtendedKeyUsage.Id + ".0");
|
||||
|
||||
public static readonly KeyPurposeID IdKPServerAuth = new KeyPurposeID("1.3.6.1.5.5.7.3.1");
|
||||
|
||||
public static readonly KeyPurposeID IdKPClientAuth = new KeyPurposeID("1.3.6.1.5.5.7.3.2");
|
||||
|
||||
public static readonly KeyPurposeID IdKPCodeSigning = new KeyPurposeID("1.3.6.1.5.5.7.3.3");
|
||||
|
||||
public static readonly KeyPurposeID IdKPEmailProtection = new KeyPurposeID("1.3.6.1.5.5.7.3.4");
|
||||
|
||||
public static readonly KeyPurposeID IdKPIpsecEndSystem = new KeyPurposeID("1.3.6.1.5.5.7.3.5");
|
||||
|
||||
public static readonly KeyPurposeID IdKPIpsecTunnel = new KeyPurposeID("1.3.6.1.5.5.7.3.6");
|
||||
|
||||
public static readonly KeyPurposeID IdKPIpsecUser = new KeyPurposeID("1.3.6.1.5.5.7.3.7");
|
||||
|
||||
public static readonly KeyPurposeID IdKPTimeStamping = new KeyPurposeID("1.3.6.1.5.5.7.3.8");
|
||||
|
||||
public static readonly KeyPurposeID IdKPOcspSigning = new KeyPurposeID("1.3.6.1.5.5.7.3.9");
|
||||
|
||||
public static readonly KeyPurposeID IdKPSmartCardLogon = new KeyPurposeID("1.3.6.1.4.1.311.20.2.2");
|
||||
|
||||
public static readonly KeyPurposeID IdKPMacAddress = new KeyPurposeID("1.3.6.1.1.1.1.22");
|
||||
|
||||
private KeyPurposeID(string id)
|
||||
: base(id)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class KeyUsage : DerBitString
|
||||
{
|
||||
public const int DigitalSignature = 128;
|
||||
|
||||
public const int NonRepudiation = 64;
|
||||
|
||||
public const int KeyEncipherment = 32;
|
||||
|
||||
public const int DataEncipherment = 16;
|
||||
|
||||
public const int KeyAgreement = 8;
|
||||
|
||||
public const int KeyCertSign = 4;
|
||||
|
||||
public const int CrlSign = 2;
|
||||
|
||||
public const int EncipherOnly = 1;
|
||||
|
||||
public const int DecipherOnly = 32768;
|
||||
|
||||
public new static KeyUsage GetInstance(object obj)
|
||||
{
|
||||
if (obj is KeyUsage)
|
||||
{
|
||||
return (KeyUsage)obj;
|
||||
}
|
||||
if (obj is X509Extension)
|
||||
{
|
||||
return GetInstance(X509Extension.ConvertValueToObject((X509Extension)obj));
|
||||
}
|
||||
return new KeyUsage(DerBitString.GetInstance(obj));
|
||||
}
|
||||
|
||||
public KeyUsage(int usage)
|
||||
: base(usage)
|
||||
{
|
||||
}
|
||||
|
||||
private KeyUsage(DerBitString usage)
|
||||
: base(usage.GetBytes(), usage.PadBits)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
byte[] bytes = GetBytes();
|
||||
if (bytes.Length == 1)
|
||||
{
|
||||
return "KeyUsage: 0x" + (bytes[0] & 0xFF).ToString("X");
|
||||
}
|
||||
return "KeyUsage: 0x" + (((bytes[1] & 0xFF) << 8) | (bytes[0] & 0xFF)).ToString("X");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class NameConstraints : Asn1Encodable
|
||||
{
|
||||
private Asn1Sequence permitted;
|
||||
|
||||
private Asn1Sequence excluded;
|
||||
|
||||
public Asn1Sequence PermittedSubtrees => permitted;
|
||||
|
||||
public Asn1Sequence ExcludedSubtrees => excluded;
|
||||
|
||||
public static NameConstraints GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is NameConstraints)
|
||||
{
|
||||
return (NameConstraints)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new NameConstraints((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public NameConstraints(Asn1Sequence seq)
|
||||
{
|
||||
foreach (Asn1TaggedObject item in seq)
|
||||
{
|
||||
switch (item.TagNo)
|
||||
{
|
||||
case 0:
|
||||
permitted = Asn1Sequence.GetInstance(item, explicitly: false);
|
||||
break;
|
||||
case 1:
|
||||
excluded = Asn1Sequence.GetInstance(item, explicitly: false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public NameConstraints(ArrayList permitted, ArrayList excluded)
|
||||
: this((IList)permitted, (IList)excluded)
|
||||
{
|
||||
}
|
||||
|
||||
public NameConstraints(IList permitted, IList excluded)
|
||||
{
|
||||
if (permitted != null)
|
||||
{
|
||||
this.permitted = CreateSequence(permitted);
|
||||
}
|
||||
if (excluded != null)
|
||||
{
|
||||
this.excluded = CreateSequence(excluded);
|
||||
}
|
||||
}
|
||||
|
||||
private DerSequence CreateSequence(IList subtrees)
|
||||
{
|
||||
GeneralSubtree[] array = new GeneralSubtree[subtrees.Count];
|
||||
for (int i = 0; i < subtrees.Count; i++)
|
||||
{
|
||||
array[i] = (GeneralSubtree)subtrees[i];
|
||||
}
|
||||
return new DerSequence(array);
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
if (permitted != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 0, permitted));
|
||||
}
|
||||
if (excluded != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 1, excluded));
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Org.BouncyCastle.Math;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class NoticeReference : Asn1Encodable
|
||||
{
|
||||
private readonly DisplayText organization;
|
||||
|
||||
private readonly Asn1Sequence noticeNumbers;
|
||||
|
||||
public virtual DisplayText Organization => organization;
|
||||
|
||||
private static Asn1EncodableVector ConvertVector(IList numbers)
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
foreach (object number in numbers)
|
||||
{
|
||||
DerInteger derInteger;
|
||||
if (number is BigInteger)
|
||||
{
|
||||
derInteger = new DerInteger((BigInteger)number);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(number is int))
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
derInteger = new DerInteger((int)number);
|
||||
}
|
||||
asn1EncodableVector.Add(derInteger);
|
||||
}
|
||||
return asn1EncodableVector;
|
||||
}
|
||||
|
||||
public NoticeReference(string organization, IList numbers)
|
||||
: this(organization, ConvertVector(numbers))
|
||||
{
|
||||
}
|
||||
|
||||
public NoticeReference(string organization, Asn1EncodableVector noticeNumbers)
|
||||
: this(new DisplayText(organization), noticeNumbers)
|
||||
{
|
||||
}
|
||||
|
||||
public NoticeReference(DisplayText organization, Asn1EncodableVector noticeNumbers)
|
||||
{
|
||||
this.organization = organization;
|
||||
this.noticeNumbers = new DerSequence(noticeNumbers);
|
||||
}
|
||||
|
||||
private NoticeReference(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count != 2)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
|
||||
}
|
||||
organization = DisplayText.GetInstance(seq[0]);
|
||||
noticeNumbers = Asn1Sequence.GetInstance(seq[1]);
|
||||
}
|
||||
|
||||
public static NoticeReference GetInstance(object obj)
|
||||
{
|
||||
if (obj is NoticeReference)
|
||||
{
|
||||
return (NoticeReference)obj;
|
||||
}
|
||||
if (obj == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new NoticeReference(Asn1Sequence.GetInstance(obj));
|
||||
}
|
||||
|
||||
public virtual DerInteger[] GetNoticeNumbers()
|
||||
{
|
||||
DerInteger[] array = new DerInteger[noticeNumbers.Count];
|
||||
for (int i = 0; i != noticeNumbers.Count; i++)
|
||||
{
|
||||
array[i] = DerInteger.GetInstance(noticeNumbers[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerSequence(organization, noticeNumbers);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class ObjectDigestInfo : Asn1Encodable
|
||||
{
|
||||
public const int PublicKey = 0;
|
||||
|
||||
public const int PublicKeyCert = 1;
|
||||
|
||||
public const int OtherObjectDigest = 2;
|
||||
|
||||
internal readonly DerEnumerated digestedObjectType;
|
||||
|
||||
internal readonly DerObjectIdentifier otherObjectTypeID;
|
||||
|
||||
internal readonly AlgorithmIdentifier digestAlgorithm;
|
||||
|
||||
internal readonly DerBitString objectDigest;
|
||||
|
||||
public DerEnumerated DigestedObjectType => digestedObjectType;
|
||||
|
||||
public DerObjectIdentifier OtherObjectTypeID => otherObjectTypeID;
|
||||
|
||||
public AlgorithmIdentifier DigestAlgorithm => digestAlgorithm;
|
||||
|
||||
public DerBitString ObjectDigest => objectDigest;
|
||||
|
||||
public static ObjectDigestInfo GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is ObjectDigestInfo)
|
||||
{
|
||||
return (ObjectDigestInfo)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new ObjectDigestInfo((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public static ObjectDigestInfo GetInstance(Asn1TaggedObject obj, bool isExplicit)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
|
||||
}
|
||||
|
||||
public ObjectDigestInfo(int digestedObjectType, string otherObjectTypeID, AlgorithmIdentifier digestAlgorithm, byte[] objectDigest)
|
||||
{
|
||||
this.digestedObjectType = new DerEnumerated(digestedObjectType);
|
||||
if (digestedObjectType == 2)
|
||||
{
|
||||
this.otherObjectTypeID = new DerObjectIdentifier(otherObjectTypeID);
|
||||
}
|
||||
this.digestAlgorithm = digestAlgorithm;
|
||||
this.objectDigest = new DerBitString(objectDigest);
|
||||
}
|
||||
|
||||
private ObjectDigestInfo(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count > 4 || seq.Count < 3)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count);
|
||||
}
|
||||
digestedObjectType = DerEnumerated.GetInstance(seq[0]);
|
||||
int num = 0;
|
||||
if (seq.Count == 4)
|
||||
{
|
||||
otherObjectTypeID = DerObjectIdentifier.GetInstance(seq[1]);
|
||||
num++;
|
||||
}
|
||||
digestAlgorithm = AlgorithmIdentifier.GetInstance(seq[1 + num]);
|
||||
objectDigest = DerBitString.GetInstance(seq[2 + num]);
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(digestedObjectType);
|
||||
if (otherObjectTypeID != null)
|
||||
{
|
||||
asn1EncodableVector.Add(otherObjectTypeID);
|
||||
}
|
||||
asn1EncodableVector.Add(digestAlgorithm, objectDigest);
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class PolicyInformation : Asn1Encodable
|
||||
{
|
||||
private readonly DerObjectIdentifier policyIdentifier;
|
||||
|
||||
private readonly Asn1Sequence policyQualifiers;
|
||||
|
||||
public DerObjectIdentifier PolicyIdentifier => policyIdentifier;
|
||||
|
||||
public Asn1Sequence PolicyQualifiers => policyQualifiers;
|
||||
|
||||
private PolicyInformation(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count < 1 || seq.Count > 2)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count);
|
||||
}
|
||||
policyIdentifier = DerObjectIdentifier.GetInstance(seq[0]);
|
||||
if (seq.Count > 1)
|
||||
{
|
||||
policyQualifiers = Asn1Sequence.GetInstance(seq[1]);
|
||||
}
|
||||
}
|
||||
|
||||
public PolicyInformation(DerObjectIdentifier policyIdentifier)
|
||||
{
|
||||
this.policyIdentifier = policyIdentifier;
|
||||
}
|
||||
|
||||
public PolicyInformation(DerObjectIdentifier policyIdentifier, Asn1Sequence policyQualifiers)
|
||||
{
|
||||
this.policyIdentifier = policyIdentifier;
|
||||
this.policyQualifiers = policyQualifiers;
|
||||
}
|
||||
|
||||
public static PolicyInformation GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is PolicyInformation)
|
||||
{
|
||||
return (PolicyInformation)obj;
|
||||
}
|
||||
return new PolicyInformation(Asn1Sequence.GetInstance(obj));
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(policyIdentifier);
|
||||
if (policyQualifiers != null)
|
||||
{
|
||||
asn1EncodableVector.Add(policyQualifiers);
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class PolicyMappings : Asn1Encodable
|
||||
{
|
||||
private readonly Asn1Sequence seq;
|
||||
|
||||
public PolicyMappings(Asn1Sequence seq)
|
||||
{
|
||||
this.seq = seq;
|
||||
}
|
||||
|
||||
public PolicyMappings(Hashtable mappings)
|
||||
: this((IDictionary)mappings)
|
||||
{
|
||||
}
|
||||
|
||||
public PolicyMappings(IDictionary mappings)
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
foreach (string key in mappings.Keys)
|
||||
{
|
||||
string identifier = (string)mappings[key];
|
||||
asn1EncodableVector.Add(new DerSequence(new DerObjectIdentifier(key), new DerObjectIdentifier(identifier)));
|
||||
}
|
||||
seq = new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return seq;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public sealed class PolicyQualifierID : DerObjectIdentifier
|
||||
{
|
||||
private const string IdQt = "1.3.6.1.5.5.7.2";
|
||||
|
||||
public static readonly PolicyQualifierID IdQtCps = new PolicyQualifierID("1.3.6.1.5.5.7.2.1");
|
||||
|
||||
public static readonly PolicyQualifierID IdQtUnotice = new PolicyQualifierID("1.3.6.1.5.5.7.2.2");
|
||||
|
||||
private PolicyQualifierID(string id)
|
||||
: base(id)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class PolicyQualifierInfo : Asn1Encodable
|
||||
{
|
||||
private readonly DerObjectIdentifier policyQualifierId;
|
||||
|
||||
private readonly Asn1Encodable qualifier;
|
||||
|
||||
public virtual DerObjectIdentifier PolicyQualifierId => policyQualifierId;
|
||||
|
||||
public virtual Asn1Encodable Qualifier => qualifier;
|
||||
|
||||
public PolicyQualifierInfo(DerObjectIdentifier policyQualifierId, Asn1Encodable qualifier)
|
||||
{
|
||||
this.policyQualifierId = policyQualifierId;
|
||||
this.qualifier = qualifier;
|
||||
}
|
||||
|
||||
public PolicyQualifierInfo(string cps)
|
||||
{
|
||||
policyQualifierId = PolicyQualifierID.IdQtCps;
|
||||
qualifier = new DerIA5String(cps);
|
||||
}
|
||||
|
||||
private PolicyQualifierInfo(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count != 2)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
|
||||
}
|
||||
policyQualifierId = DerObjectIdentifier.GetInstance(seq[0]);
|
||||
qualifier = seq[1];
|
||||
}
|
||||
|
||||
public static PolicyQualifierInfo GetInstance(object obj)
|
||||
{
|
||||
if (obj is PolicyQualifierInfo)
|
||||
{
|
||||
return (PolicyQualifierInfo)obj;
|
||||
}
|
||||
if (obj == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new PolicyQualifierInfo(Asn1Sequence.GetInstance(obj));
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerSequence(policyQualifierId, qualifier);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class PrivateKeyUsagePeriod : Asn1Encodable
|
||||
{
|
||||
private DerGeneralizedTime _notBefore;
|
||||
|
||||
private DerGeneralizedTime _notAfter;
|
||||
|
||||
public DerGeneralizedTime NotBefore => _notBefore;
|
||||
|
||||
public DerGeneralizedTime NotAfter => _notAfter;
|
||||
|
||||
public static PrivateKeyUsagePeriod GetInstance(object obj)
|
||||
{
|
||||
if (obj is PrivateKeyUsagePeriod)
|
||||
{
|
||||
return (PrivateKeyUsagePeriod)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new PrivateKeyUsagePeriod((Asn1Sequence)obj);
|
||||
}
|
||||
if (obj is X509Extension)
|
||||
{
|
||||
return GetInstance(X509Extension.ConvertValueToObject((X509Extension)obj));
|
||||
}
|
||||
throw new ArgumentException("unknown object in GetInstance: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
private PrivateKeyUsagePeriod(Asn1Sequence seq)
|
||||
{
|
||||
foreach (Asn1TaggedObject item in seq)
|
||||
{
|
||||
if (item.TagNo == 0)
|
||||
{
|
||||
_notBefore = DerGeneralizedTime.GetInstance(item, isExplicit: false);
|
||||
}
|
||||
else if (item.TagNo == 1)
|
||||
{
|
||||
_notAfter = DerGeneralizedTime.GetInstance(item, isExplicit: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
if (_notBefore != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 0, _notBefore));
|
||||
}
|
||||
if (_notAfter != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 1, _notAfter));
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509.Qualified;
|
||||
|
||||
public class BiometricData : Asn1Encodable
|
||||
{
|
||||
private readonly TypeOfBiometricData typeOfBiometricData;
|
||||
|
||||
private readonly AlgorithmIdentifier hashAlgorithm;
|
||||
|
||||
private readonly Asn1OctetString biometricDataHash;
|
||||
|
||||
private readonly DerIA5String sourceDataUri;
|
||||
|
||||
public TypeOfBiometricData TypeOfBiometricData => typeOfBiometricData;
|
||||
|
||||
public AlgorithmIdentifier HashAlgorithm => hashAlgorithm;
|
||||
|
||||
public Asn1OctetString BiometricDataHash => biometricDataHash;
|
||||
|
||||
public DerIA5String SourceDataUri => sourceDataUri;
|
||||
|
||||
public static BiometricData GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is BiometricData)
|
||||
{
|
||||
return (BiometricData)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new BiometricData(Asn1Sequence.GetInstance(obj));
|
||||
}
|
||||
throw new ArgumentException("unknown object in GetInstance: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
private BiometricData(Asn1Sequence seq)
|
||||
{
|
||||
typeOfBiometricData = TypeOfBiometricData.GetInstance(seq[0]);
|
||||
hashAlgorithm = AlgorithmIdentifier.GetInstance(seq[1]);
|
||||
biometricDataHash = Asn1OctetString.GetInstance(seq[2]);
|
||||
if (seq.Count > 3)
|
||||
{
|
||||
sourceDataUri = DerIA5String.GetInstance(seq[3]);
|
||||
}
|
||||
}
|
||||
|
||||
public BiometricData(TypeOfBiometricData typeOfBiometricData, AlgorithmIdentifier hashAlgorithm, Asn1OctetString biometricDataHash, DerIA5String sourceDataUri)
|
||||
{
|
||||
this.typeOfBiometricData = typeOfBiometricData;
|
||||
this.hashAlgorithm = hashAlgorithm;
|
||||
this.biometricDataHash = biometricDataHash;
|
||||
this.sourceDataUri = sourceDataUri;
|
||||
}
|
||||
|
||||
public BiometricData(TypeOfBiometricData typeOfBiometricData, AlgorithmIdentifier hashAlgorithm, Asn1OctetString biometricDataHash)
|
||||
{
|
||||
this.typeOfBiometricData = typeOfBiometricData;
|
||||
this.hashAlgorithm = hashAlgorithm;
|
||||
this.biometricDataHash = biometricDataHash;
|
||||
sourceDataUri = null;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(typeOfBiometricData, hashAlgorithm, biometricDataHash);
|
||||
if (sourceDataUri != null)
|
||||
{
|
||||
asn1EncodableVector.Add(sourceDataUri);
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Org.BouncyCastle.Asn1.X509.Qualified;
|
||||
|
||||
public abstract class EtsiQCObjectIdentifiers
|
||||
{
|
||||
public static readonly DerObjectIdentifier IdEtsiQcs = new DerObjectIdentifier("0.4.0.1862.1");
|
||||
|
||||
public static readonly DerObjectIdentifier IdEtsiQcsQcCompliance = new DerObjectIdentifier(string.Concat(IdEtsiQcs, ".1"));
|
||||
|
||||
public static readonly DerObjectIdentifier IdEtsiQcsLimitValue = new DerObjectIdentifier(string.Concat(IdEtsiQcs, ".2"));
|
||||
|
||||
public static readonly DerObjectIdentifier IdEtsiQcsRetentionPeriod = new DerObjectIdentifier(string.Concat(IdEtsiQcs, ".3"));
|
||||
|
||||
public static readonly DerObjectIdentifier IdEtsiQcsQcSscd = new DerObjectIdentifier(string.Concat(IdEtsiQcs, ".4"));
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509.Qualified;
|
||||
|
||||
public class Iso4217CurrencyCode : Asn1Encodable, IAsn1Choice
|
||||
{
|
||||
internal const int AlphabeticMaxSize = 3;
|
||||
|
||||
internal const int NumericMinSize = 1;
|
||||
|
||||
internal const int NumericMaxSize = 999;
|
||||
|
||||
internal Asn1Encodable obj;
|
||||
|
||||
public bool IsAlphabetic => obj is DerPrintableString;
|
||||
|
||||
public string Alphabetic => ((DerPrintableString)obj).GetString();
|
||||
|
||||
public int Numeric => ((DerInteger)obj).Value.IntValue;
|
||||
|
||||
public static Iso4217CurrencyCode GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is Iso4217CurrencyCode)
|
||||
{
|
||||
return (Iso4217CurrencyCode)obj;
|
||||
}
|
||||
if (obj is DerInteger)
|
||||
{
|
||||
DerInteger instance = DerInteger.GetInstance(obj);
|
||||
int intValue = instance.Value.IntValue;
|
||||
return new Iso4217CurrencyCode(intValue);
|
||||
}
|
||||
if (obj is DerPrintableString)
|
||||
{
|
||||
DerPrintableString instance2 = DerPrintableString.GetInstance(obj);
|
||||
return new Iso4217CurrencyCode(instance2.GetString());
|
||||
}
|
||||
throw new ArgumentException("unknown object in GetInstance: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public Iso4217CurrencyCode(int numeric)
|
||||
{
|
||||
if (numeric > 999 || numeric < 1)
|
||||
{
|
||||
throw new ArgumentException("wrong size in numeric code : not in (" + 1 + ".." + 999 + ")");
|
||||
}
|
||||
obj = new DerInteger(numeric);
|
||||
}
|
||||
|
||||
public Iso4217CurrencyCode(string alphabetic)
|
||||
{
|
||||
if (alphabetic.Length > 3)
|
||||
{
|
||||
throw new ArgumentException("wrong size in alphabetic code : max size is " + 3);
|
||||
}
|
||||
obj = new DerPrintableString(alphabetic);
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return obj.ToAsn1Object();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Math;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509.Qualified;
|
||||
|
||||
public class MonetaryValue : Asn1Encodable
|
||||
{
|
||||
internal Iso4217CurrencyCode currency;
|
||||
|
||||
internal DerInteger amount;
|
||||
|
||||
internal DerInteger exponent;
|
||||
|
||||
public Iso4217CurrencyCode Currency => currency;
|
||||
|
||||
public BigInteger Amount => amount.Value;
|
||||
|
||||
public BigInteger Exponent => exponent.Value;
|
||||
|
||||
public static MonetaryValue GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is MonetaryValue)
|
||||
{
|
||||
return (MonetaryValue)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new MonetaryValue(Asn1Sequence.GetInstance(obj));
|
||||
}
|
||||
throw new ArgumentException("unknown object in GetInstance: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
private MonetaryValue(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count != 3)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
|
||||
}
|
||||
currency = Iso4217CurrencyCode.GetInstance(seq[0]);
|
||||
amount = DerInteger.GetInstance(seq[1]);
|
||||
exponent = DerInteger.GetInstance(seq[2]);
|
||||
}
|
||||
|
||||
public MonetaryValue(Iso4217CurrencyCode currency, int amount, int exponent)
|
||||
{
|
||||
this.currency = currency;
|
||||
this.amount = new DerInteger(amount);
|
||||
this.exponent = new DerInteger(exponent);
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerSequence(currency, amount, exponent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509.Qualified;
|
||||
|
||||
public class QCStatement : Asn1Encodable
|
||||
{
|
||||
private readonly DerObjectIdentifier qcStatementId;
|
||||
|
||||
private readonly Asn1Encodable qcStatementInfo;
|
||||
|
||||
public DerObjectIdentifier StatementId => qcStatementId;
|
||||
|
||||
public Asn1Encodable StatementInfo => qcStatementInfo;
|
||||
|
||||
public static QCStatement GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is QCStatement)
|
||||
{
|
||||
return (QCStatement)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new QCStatement(Asn1Sequence.GetInstance(obj));
|
||||
}
|
||||
throw new ArgumentException("unknown object in GetInstance: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
private QCStatement(Asn1Sequence seq)
|
||||
{
|
||||
qcStatementId = DerObjectIdentifier.GetInstance(seq[0]);
|
||||
if (seq.Count > 1)
|
||||
{
|
||||
qcStatementInfo = seq[1];
|
||||
}
|
||||
}
|
||||
|
||||
public QCStatement(DerObjectIdentifier qcStatementId)
|
||||
{
|
||||
this.qcStatementId = qcStatementId;
|
||||
}
|
||||
|
||||
public QCStatement(DerObjectIdentifier qcStatementId, Asn1Encodable qcStatementInfo)
|
||||
{
|
||||
this.qcStatementId = qcStatementId;
|
||||
this.qcStatementInfo = qcStatementInfo;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(qcStatementId);
|
||||
if (qcStatementInfo != null)
|
||||
{
|
||||
asn1EncodableVector.Add(qcStatementInfo);
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Org.BouncyCastle.Asn1.X509.Qualified;
|
||||
|
||||
public sealed class Rfc3739QCObjectIdentifiers
|
||||
{
|
||||
public static readonly DerObjectIdentifier IdQcs = new DerObjectIdentifier("1.3.6.1.5.5.7.11");
|
||||
|
||||
public static readonly DerObjectIdentifier IdQcsPkixQCSyntaxV1 = new DerObjectIdentifier(string.Concat(IdQcs, ".1"));
|
||||
|
||||
public static readonly DerObjectIdentifier IdQcsPkixQCSyntaxV2 = new DerObjectIdentifier(string.Concat(IdQcs, ".2"));
|
||||
|
||||
private Rfc3739QCObjectIdentifiers()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509.Qualified;
|
||||
|
||||
public class SemanticsInformation : Asn1Encodable
|
||||
{
|
||||
private readonly DerObjectIdentifier semanticsIdentifier;
|
||||
|
||||
private readonly GeneralName[] nameRegistrationAuthorities;
|
||||
|
||||
public DerObjectIdentifier SemanticsIdentifier => semanticsIdentifier;
|
||||
|
||||
public static SemanticsInformation GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is SemanticsInformation)
|
||||
{
|
||||
return (SemanticsInformation)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new SemanticsInformation(Asn1Sequence.GetInstance(obj));
|
||||
}
|
||||
throw new ArgumentException("unknown object in GetInstance: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public SemanticsInformation(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count < 1)
|
||||
{
|
||||
throw new ArgumentException("no objects in SemanticsInformation");
|
||||
}
|
||||
IEnumerator enumerator = seq.GetEnumerator();
|
||||
enumerator.MoveNext();
|
||||
object obj = enumerator.Current;
|
||||
if (obj is DerObjectIdentifier)
|
||||
{
|
||||
semanticsIdentifier = DerObjectIdentifier.GetInstance(obj);
|
||||
obj = ((!enumerator.MoveNext()) ? null : enumerator.Current);
|
||||
}
|
||||
if (obj != null)
|
||||
{
|
||||
Asn1Sequence instance = Asn1Sequence.GetInstance(obj);
|
||||
nameRegistrationAuthorities = new GeneralName[instance.Count];
|
||||
for (int i = 0; i < instance.Count; i++)
|
||||
{
|
||||
nameRegistrationAuthorities[i] = GeneralName.GetInstance(instance[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SemanticsInformation(DerObjectIdentifier semanticsIdentifier, GeneralName[] generalNames)
|
||||
{
|
||||
this.semanticsIdentifier = semanticsIdentifier;
|
||||
nameRegistrationAuthorities = generalNames;
|
||||
}
|
||||
|
||||
public SemanticsInformation(DerObjectIdentifier semanticsIdentifier)
|
||||
{
|
||||
this.semanticsIdentifier = semanticsIdentifier;
|
||||
}
|
||||
|
||||
public SemanticsInformation(GeneralName[] generalNames)
|
||||
{
|
||||
nameRegistrationAuthorities = generalNames;
|
||||
}
|
||||
|
||||
public GeneralName[] GetNameRegistrationAuthorities()
|
||||
{
|
||||
return nameRegistrationAuthorities;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
if (semanticsIdentifier != null)
|
||||
{
|
||||
asn1EncodableVector.Add(semanticsIdentifier);
|
||||
}
|
||||
if (nameRegistrationAuthorities != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerSequence(nameRegistrationAuthorities));
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509.Qualified;
|
||||
|
||||
public class TypeOfBiometricData : Asn1Encodable, IAsn1Choice
|
||||
{
|
||||
public const int Picture = 0;
|
||||
|
||||
public const int HandwrittenSignature = 1;
|
||||
|
||||
internal Asn1Encodable obj;
|
||||
|
||||
public bool IsPredefined => obj is DerInteger;
|
||||
|
||||
public int PredefinedBiometricType => ((DerInteger)obj).Value.IntValue;
|
||||
|
||||
public DerObjectIdentifier BiometricDataOid => (DerObjectIdentifier)obj;
|
||||
|
||||
public static TypeOfBiometricData GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is TypeOfBiometricData)
|
||||
{
|
||||
return (TypeOfBiometricData)obj;
|
||||
}
|
||||
if (obj is DerInteger)
|
||||
{
|
||||
DerInteger instance = DerInteger.GetInstance(obj);
|
||||
int intValue = instance.Value.IntValue;
|
||||
return new TypeOfBiometricData(intValue);
|
||||
}
|
||||
if (obj is DerObjectIdentifier)
|
||||
{
|
||||
DerObjectIdentifier instance2 = DerObjectIdentifier.GetInstance(obj);
|
||||
return new TypeOfBiometricData(instance2);
|
||||
}
|
||||
throw new ArgumentException("unknown object in GetInstance: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public TypeOfBiometricData(int predefinedBiometricType)
|
||||
{
|
||||
if (predefinedBiometricType == 0 || predefinedBiometricType == 1)
|
||||
{
|
||||
obj = new DerInteger(predefinedBiometricType);
|
||||
return;
|
||||
}
|
||||
throw new ArgumentException("unknow PredefinedBiometricType : " + predefinedBiometricType);
|
||||
}
|
||||
|
||||
public TypeOfBiometricData(DerObjectIdentifier biometricDataOid)
|
||||
{
|
||||
obj = biometricDataOid;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return obj.ToAsn1Object();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class ReasonFlags : DerBitString
|
||||
{
|
||||
public const int Unused = 128;
|
||||
|
||||
public const int KeyCompromise = 64;
|
||||
|
||||
public const int CACompromise = 32;
|
||||
|
||||
public const int AffiliationChanged = 16;
|
||||
|
||||
public const int Superseded = 8;
|
||||
|
||||
public const int CessationOfOperation = 4;
|
||||
|
||||
public const int CertificateHold = 2;
|
||||
|
||||
public const int PrivilegeWithdrawn = 1;
|
||||
|
||||
public const int AACompromise = 32768;
|
||||
|
||||
public ReasonFlags(int reasons)
|
||||
: base(reasons)
|
||||
{
|
||||
}
|
||||
|
||||
public ReasonFlags(DerBitString reasons)
|
||||
: base(reasons.GetBytes(), reasons.PadBits)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class RoleSyntax : Asn1Encodable
|
||||
{
|
||||
private readonly GeneralNames roleAuthority;
|
||||
|
||||
private readonly GeneralName roleName;
|
||||
|
||||
public GeneralNames RoleAuthority => roleAuthority;
|
||||
|
||||
public GeneralName RoleName => roleName;
|
||||
|
||||
public static RoleSyntax GetInstance(object obj)
|
||||
{
|
||||
if (obj is RoleSyntax)
|
||||
{
|
||||
return (RoleSyntax)obj;
|
||||
}
|
||||
if (obj != null)
|
||||
{
|
||||
return new RoleSyntax(Asn1Sequence.GetInstance(obj));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public RoleSyntax(GeneralNames roleAuthority, GeneralName roleName)
|
||||
{
|
||||
if (roleName == null || roleName.TagNo != 6 || ((IAsn1String)roleName.Name).GetString().Equals(""))
|
||||
{
|
||||
throw new ArgumentException("the role name MUST be non empty and MUST use the URI option of GeneralName");
|
||||
}
|
||||
this.roleAuthority = roleAuthority;
|
||||
this.roleName = roleName;
|
||||
}
|
||||
|
||||
public RoleSyntax(GeneralName roleName)
|
||||
: this(null, roleName)
|
||||
{
|
||||
}
|
||||
|
||||
public RoleSyntax(string roleName)
|
||||
: this(new GeneralName(6, (roleName == null) ? "" : roleName))
|
||||
{
|
||||
}
|
||||
|
||||
private RoleSyntax(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count < 1 || seq.Count > 2)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count);
|
||||
}
|
||||
for (int i = 0; i != seq.Count; i++)
|
||||
{
|
||||
Asn1TaggedObject instance = Asn1TaggedObject.GetInstance(seq[i]);
|
||||
switch (instance.TagNo)
|
||||
{
|
||||
case 0:
|
||||
roleAuthority = GeneralNames.GetInstance(instance, explicitly: false);
|
||||
break;
|
||||
case 1:
|
||||
roleName = GeneralName.GetInstance(instance, explicitly: true);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Unknown tag in RoleSyntax");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GetRoleNameAsString()
|
||||
{
|
||||
return ((IAsn1String)roleName.Name).GetString();
|
||||
}
|
||||
|
||||
public string[] GetRoleAuthorityAsString()
|
||||
{
|
||||
if (roleAuthority == null)
|
||||
{
|
||||
return new string[0];
|
||||
}
|
||||
GeneralName[] names = roleAuthority.GetNames();
|
||||
string[] array = new string[names.Length];
|
||||
for (int i = 0; i < names.Length; i++)
|
||||
{
|
||||
Asn1Encodable name = names[i].Name;
|
||||
if (name is IAsn1String)
|
||||
{
|
||||
array[i] = ((IAsn1String)name).GetString();
|
||||
}
|
||||
else
|
||||
{
|
||||
array[i] = name.ToString();
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
if (roleAuthority != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 0, roleAuthority));
|
||||
}
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: true, 1, roleName));
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder("Name: " + GetRoleNameAsString() + " - Auth: ");
|
||||
if (roleAuthority == null || roleAuthority.GetNames().Length == 0)
|
||||
{
|
||||
stringBuilder.Append("N/A");
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] roleAuthorityAsString = GetRoleAuthorityAsString();
|
||||
stringBuilder.Append('[').Append(roleAuthorityAsString[0]);
|
||||
for (int i = 1; i < roleAuthorityAsString.Length; i++)
|
||||
{
|
||||
stringBuilder.Append(", ").Append(roleAuthorityAsString[i]);
|
||||
}
|
||||
stringBuilder.Append(']');
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Math;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class RsaPublicKeyStructure : Asn1Encodable
|
||||
{
|
||||
private BigInteger modulus;
|
||||
|
||||
private BigInteger publicExponent;
|
||||
|
||||
public BigInteger Modulus => modulus;
|
||||
|
||||
public BigInteger PublicExponent => publicExponent;
|
||||
|
||||
public static RsaPublicKeyStructure GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
|
||||
}
|
||||
|
||||
public static RsaPublicKeyStructure GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is RsaPublicKeyStructure)
|
||||
{
|
||||
return (RsaPublicKeyStructure)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new RsaPublicKeyStructure((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid RsaPublicKeyStructure: " + Platform.GetTypeName(obj));
|
||||
}
|
||||
|
||||
public RsaPublicKeyStructure(BigInteger modulus, BigInteger publicExponent)
|
||||
{
|
||||
if (modulus == null)
|
||||
{
|
||||
throw new ArgumentNullException("modulus");
|
||||
}
|
||||
if (publicExponent == null)
|
||||
{
|
||||
throw new ArgumentNullException("publicExponent");
|
||||
}
|
||||
if (modulus.SignValue <= 0)
|
||||
{
|
||||
throw new ArgumentException("Not a valid RSA modulus", "modulus");
|
||||
}
|
||||
if (publicExponent.SignValue <= 0)
|
||||
{
|
||||
throw new ArgumentException("Not a valid RSA public exponent", "publicExponent");
|
||||
}
|
||||
this.modulus = modulus;
|
||||
this.publicExponent = publicExponent;
|
||||
}
|
||||
|
||||
private RsaPublicKeyStructure(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count != 2)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count);
|
||||
}
|
||||
modulus = DerInteger.GetInstance(seq[0]).PositiveValue;
|
||||
publicExponent = DerInteger.GetInstance(seq[1]).PositiveValue;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerSequence(new DerInteger(Modulus), new DerInteger(PublicExponent));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Asn1.X500;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509.SigI;
|
||||
|
||||
public class NameOrPseudonym : Asn1Encodable, IAsn1Choice
|
||||
{
|
||||
private readonly DirectoryString pseudonym;
|
||||
|
||||
private readonly DirectoryString surname;
|
||||
|
||||
private readonly Asn1Sequence givenName;
|
||||
|
||||
public DirectoryString Pseudonym => pseudonym;
|
||||
|
||||
public DirectoryString Surname => surname;
|
||||
|
||||
public static NameOrPseudonym GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is NameOrPseudonym)
|
||||
{
|
||||
return (NameOrPseudonym)obj;
|
||||
}
|
||||
if (obj is IAsn1String)
|
||||
{
|
||||
return new NameOrPseudonym(DirectoryString.GetInstance(obj));
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new NameOrPseudonym((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public NameOrPseudonym(DirectoryString pseudonym)
|
||||
{
|
||||
this.pseudonym = pseudonym;
|
||||
}
|
||||
|
||||
private NameOrPseudonym(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count != 2)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count);
|
||||
}
|
||||
if (!(seq[0] is IAsn1String))
|
||||
{
|
||||
throw new ArgumentException("Bad object encountered: " + Platform.GetTypeName(seq[0]));
|
||||
}
|
||||
surname = DirectoryString.GetInstance(seq[0]);
|
||||
givenName = Asn1Sequence.GetInstance(seq[1]);
|
||||
}
|
||||
|
||||
public NameOrPseudonym(string pseudonym)
|
||||
: this(new DirectoryString(pseudonym))
|
||||
{
|
||||
}
|
||||
|
||||
public NameOrPseudonym(DirectoryString surname, Asn1Sequence givenName)
|
||||
{
|
||||
this.surname = surname;
|
||||
this.givenName = givenName;
|
||||
}
|
||||
|
||||
public DirectoryString[] GetGivenName()
|
||||
{
|
||||
DirectoryString[] array = new DirectoryString[givenName.Count];
|
||||
int num = 0;
|
||||
foreach (object item in givenName)
|
||||
{
|
||||
array[num++] = DirectoryString.GetInstance(item);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
if (pseudonym != null)
|
||||
{
|
||||
return pseudonym.ToAsn1Object();
|
||||
}
|
||||
return new DerSequence(surname, givenName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Org.BouncyCastle.Asn1.X500;
|
||||
using Org.BouncyCastle.Math;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509.SigI;
|
||||
|
||||
public class PersonalData : Asn1Encodable
|
||||
{
|
||||
private readonly NameOrPseudonym nameOrPseudonym;
|
||||
|
||||
private readonly BigInteger nameDistinguisher;
|
||||
|
||||
private readonly DerGeneralizedTime dateOfBirth;
|
||||
|
||||
private readonly DirectoryString placeOfBirth;
|
||||
|
||||
private readonly string gender;
|
||||
|
||||
private readonly DirectoryString postalAddress;
|
||||
|
||||
public NameOrPseudonym NameOrPseudonym => nameOrPseudonym;
|
||||
|
||||
public BigInteger NameDistinguisher => nameDistinguisher;
|
||||
|
||||
public DerGeneralizedTime DateOfBirth => dateOfBirth;
|
||||
|
||||
public DirectoryString PlaceOfBirth => placeOfBirth;
|
||||
|
||||
public string Gender => gender;
|
||||
|
||||
public DirectoryString PostalAddress => postalAddress;
|
||||
|
||||
public static PersonalData GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is PersonalData)
|
||||
{
|
||||
return (PersonalData)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new PersonalData((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
private PersonalData(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count < 1)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count);
|
||||
}
|
||||
IEnumerator enumerator = seq.GetEnumerator();
|
||||
enumerator.MoveNext();
|
||||
nameOrPseudonym = NameOrPseudonym.GetInstance(enumerator.Current);
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
Asn1TaggedObject instance = Asn1TaggedObject.GetInstance(enumerator.Current);
|
||||
switch (instance.TagNo)
|
||||
{
|
||||
case 0:
|
||||
nameDistinguisher = DerInteger.GetInstance(instance, isExplicit: false).Value;
|
||||
break;
|
||||
case 1:
|
||||
dateOfBirth = DerGeneralizedTime.GetInstance(instance, isExplicit: false);
|
||||
break;
|
||||
case 2:
|
||||
placeOfBirth = DirectoryString.GetInstance(instance, isExplicit: true);
|
||||
break;
|
||||
case 3:
|
||||
gender = DerPrintableString.GetInstance(instance, isExplicit: false).GetString();
|
||||
break;
|
||||
case 4:
|
||||
postalAddress = DirectoryString.GetInstance(instance, isExplicit: true);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Bad tag number: " + instance.TagNo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PersonalData(NameOrPseudonym nameOrPseudonym, BigInteger nameDistinguisher, DerGeneralizedTime dateOfBirth, DirectoryString placeOfBirth, string gender, DirectoryString postalAddress)
|
||||
{
|
||||
this.nameOrPseudonym = nameOrPseudonym;
|
||||
this.dateOfBirth = dateOfBirth;
|
||||
this.gender = gender;
|
||||
this.nameDistinguisher = nameDistinguisher;
|
||||
this.postalAddress = postalAddress;
|
||||
this.placeOfBirth = placeOfBirth;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
asn1EncodableVector.Add(nameOrPseudonym);
|
||||
if (nameDistinguisher != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 0, new DerInteger(nameDistinguisher)));
|
||||
}
|
||||
if (dateOfBirth != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 1, dateOfBirth));
|
||||
}
|
||||
if (placeOfBirth != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: true, 2, placeOfBirth));
|
||||
}
|
||||
if (gender != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 3, new DerPrintableString(gender, validate: true)));
|
||||
}
|
||||
if (postalAddress != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: true, 4, postalAddress));
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace Org.BouncyCastle.Asn1.X509.SigI;
|
||||
|
||||
public sealed class SigIObjectIdentifiers
|
||||
{
|
||||
public static readonly DerObjectIdentifier IdSigI = new DerObjectIdentifier("1.3.36.8");
|
||||
|
||||
public static readonly DerObjectIdentifier IdSigIKP = new DerObjectIdentifier(string.Concat(IdSigI, ".2"));
|
||||
|
||||
public static readonly DerObjectIdentifier IdSigICP = new DerObjectIdentifier(string.Concat(IdSigI, ".1"));
|
||||
|
||||
public static readonly DerObjectIdentifier IdSigION = new DerObjectIdentifier(string.Concat(IdSigI, ".4"));
|
||||
|
||||
public static readonly DerObjectIdentifier IdSigIKPDirectoryService = new DerObjectIdentifier(string.Concat(IdSigIKP, ".1"));
|
||||
|
||||
public static readonly DerObjectIdentifier IdSigIONPersonalData = new DerObjectIdentifier(string.Concat(IdSigION, ".1"));
|
||||
|
||||
public static readonly DerObjectIdentifier IdSigICPSigConform = new DerObjectIdentifier(string.Concat(IdSigICP, ".1"));
|
||||
|
||||
private SigIObjectIdentifiers()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
using Org.BouncyCastle.Utilities.Collections;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class SubjectDirectoryAttributes : Asn1Encodable
|
||||
{
|
||||
private readonly IList attributes;
|
||||
|
||||
public IEnumerable Attributes => new EnumerableProxy(attributes);
|
||||
|
||||
public static SubjectDirectoryAttributes GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is SubjectDirectoryAttributes)
|
||||
{
|
||||
return (SubjectDirectoryAttributes)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new SubjectDirectoryAttributes((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
private SubjectDirectoryAttributes(Asn1Sequence seq)
|
||||
{
|
||||
attributes = Platform.CreateArrayList();
|
||||
foreach (object item in seq)
|
||||
{
|
||||
Asn1Sequence instance = Asn1Sequence.GetInstance(item);
|
||||
attributes.Add(AttributeX509.GetInstance(instance));
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public SubjectDirectoryAttributes(ArrayList attributes)
|
||||
: this((IList)attributes)
|
||||
{
|
||||
}
|
||||
|
||||
public SubjectDirectoryAttributes(IList attributes)
|
||||
{
|
||||
this.attributes = Platform.CreateArrayList(attributes);
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
AttributeX509[] array = new AttributeX509[attributes.Count];
|
||||
for (int i = 0; i < attributes.Count; i++)
|
||||
{
|
||||
array[i] = (AttributeX509)attributes[i];
|
||||
}
|
||||
return new DerSequence(array);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Crypto;
|
||||
using Org.BouncyCastle.Crypto.Digests;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class SubjectKeyIdentifier : Asn1Encodable
|
||||
{
|
||||
private readonly byte[] keyIdentifier;
|
||||
|
||||
public static SubjectKeyIdentifier GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1OctetString.GetInstance(obj, explicitly));
|
||||
}
|
||||
|
||||
public static SubjectKeyIdentifier GetInstance(object obj)
|
||||
{
|
||||
if (obj is SubjectKeyIdentifier)
|
||||
{
|
||||
return (SubjectKeyIdentifier)obj;
|
||||
}
|
||||
if (obj is SubjectPublicKeyInfo)
|
||||
{
|
||||
return new SubjectKeyIdentifier((SubjectPublicKeyInfo)obj);
|
||||
}
|
||||
if (obj is Asn1OctetString)
|
||||
{
|
||||
return new SubjectKeyIdentifier((Asn1OctetString)obj);
|
||||
}
|
||||
if (obj is X509Extension)
|
||||
{
|
||||
return GetInstance(X509Extension.ConvertValueToObject((X509Extension)obj));
|
||||
}
|
||||
throw new ArgumentException("Invalid SubjectKeyIdentifier: " + Platform.GetTypeName(obj));
|
||||
}
|
||||
|
||||
public SubjectKeyIdentifier(byte[] keyID)
|
||||
{
|
||||
if (keyID == null)
|
||||
{
|
||||
throw new ArgumentNullException("keyID");
|
||||
}
|
||||
keyIdentifier = keyID;
|
||||
}
|
||||
|
||||
public SubjectKeyIdentifier(Asn1OctetString keyID)
|
||||
{
|
||||
keyIdentifier = keyID.GetOctets();
|
||||
}
|
||||
|
||||
public SubjectKeyIdentifier(SubjectPublicKeyInfo spki)
|
||||
{
|
||||
keyIdentifier = GetDigest(spki);
|
||||
}
|
||||
|
||||
public byte[] GetKeyIdentifier()
|
||||
{
|
||||
return keyIdentifier;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerOctetString(keyIdentifier);
|
||||
}
|
||||
|
||||
public static SubjectKeyIdentifier CreateSha1KeyIdentifier(SubjectPublicKeyInfo keyInfo)
|
||||
{
|
||||
return new SubjectKeyIdentifier(keyInfo);
|
||||
}
|
||||
|
||||
public static SubjectKeyIdentifier CreateTruncatedSha1KeyIdentifier(SubjectPublicKeyInfo keyInfo)
|
||||
{
|
||||
byte[] digest = GetDigest(keyInfo);
|
||||
byte[] array = new byte[8];
|
||||
Array.Copy(digest, digest.Length - 8, array, 0, array.Length);
|
||||
byte[] array2;
|
||||
(array2 = array)[0] = (byte)(array2[0] & 0xF);
|
||||
(array2 = array)[0] = (byte)(array2[0] | 0x40);
|
||||
return new SubjectKeyIdentifier(array);
|
||||
}
|
||||
|
||||
private static byte[] GetDigest(SubjectPublicKeyInfo spki)
|
||||
{
|
||||
IDigest digest = new Sha1Digest();
|
||||
byte[] array = new byte[digest.GetDigestSize()];
|
||||
byte[] bytes = spki.PublicKeyData.GetBytes();
|
||||
digest.BlockUpdate(bytes, 0, bytes.Length);
|
||||
digest.DoFinal(array, 0);
|
||||
return array;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class SubjectPublicKeyInfo : Asn1Encodable
|
||||
{
|
||||
private readonly AlgorithmIdentifier algID;
|
||||
|
||||
private readonly DerBitString keyData;
|
||||
|
||||
public AlgorithmIdentifier AlgorithmID => algID;
|
||||
|
||||
public DerBitString PublicKeyData => keyData;
|
||||
|
||||
public static SubjectPublicKeyInfo GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
|
||||
}
|
||||
|
||||
public static SubjectPublicKeyInfo GetInstance(object obj)
|
||||
{
|
||||
if (obj is SubjectPublicKeyInfo)
|
||||
{
|
||||
return (SubjectPublicKeyInfo)obj;
|
||||
}
|
||||
if (obj != null)
|
||||
{
|
||||
return new SubjectPublicKeyInfo(Asn1Sequence.GetInstance(obj));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public SubjectPublicKeyInfo(AlgorithmIdentifier algID, Asn1Encodable publicKey)
|
||||
{
|
||||
keyData = new DerBitString(publicKey);
|
||||
this.algID = algID;
|
||||
}
|
||||
|
||||
public SubjectPublicKeyInfo(AlgorithmIdentifier algID, byte[] publicKey)
|
||||
{
|
||||
keyData = new DerBitString(publicKey);
|
||||
this.algID = algID;
|
||||
}
|
||||
|
||||
private SubjectPublicKeyInfo(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count != 2)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
|
||||
}
|
||||
algID = AlgorithmIdentifier.GetInstance(seq[0]);
|
||||
keyData = DerBitString.GetInstance(seq[1]);
|
||||
}
|
||||
|
||||
public Asn1Object GetPublicKey()
|
||||
{
|
||||
return Asn1Object.FromByteArray(keyData.GetOctets());
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerSequence(algID, keyData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class Target : Asn1Encodable, IAsn1Choice
|
||||
{
|
||||
public enum Choice
|
||||
{
|
||||
Name,
|
||||
Group
|
||||
}
|
||||
|
||||
private readonly GeneralName targetName;
|
||||
|
||||
private readonly GeneralName targetGroup;
|
||||
|
||||
public virtual GeneralName TargetGroup => targetGroup;
|
||||
|
||||
public virtual GeneralName TargetName => targetName;
|
||||
|
||||
public static Target GetInstance(object obj)
|
||||
{
|
||||
if (obj is Target)
|
||||
{
|
||||
return (Target)obj;
|
||||
}
|
||||
if (obj is Asn1TaggedObject)
|
||||
{
|
||||
return new Target((Asn1TaggedObject)obj);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
private Target(Asn1TaggedObject tagObj)
|
||||
{
|
||||
switch ((Choice)tagObj.TagNo)
|
||||
{
|
||||
case Choice.Name:
|
||||
targetName = GeneralName.GetInstance(tagObj, explicitly: true);
|
||||
break;
|
||||
case Choice.Group:
|
||||
targetGroup = GeneralName.GetInstance(tagObj, explicitly: true);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("unknown tag: " + tagObj.TagNo);
|
||||
}
|
||||
}
|
||||
|
||||
public Target(Choice type, GeneralName name)
|
||||
: this(new DerTaggedObject((int)type, name))
|
||||
{
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
if (targetName != null)
|
||||
{
|
||||
return new DerTaggedObject(explicitly: true, 0, targetName);
|
||||
}
|
||||
return new DerTaggedObject(explicitly: true, 1, targetGroup);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class TargetInformation : Asn1Encodable
|
||||
{
|
||||
private readonly Asn1Sequence targets;
|
||||
|
||||
public static TargetInformation GetInstance(object obj)
|
||||
{
|
||||
if (obj is TargetInformation)
|
||||
{
|
||||
return (TargetInformation)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new TargetInformation((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
private TargetInformation(Asn1Sequence targets)
|
||||
{
|
||||
this.targets = targets;
|
||||
}
|
||||
|
||||
public virtual Targets[] GetTargetsObjects()
|
||||
{
|
||||
Targets[] array = new Targets[targets.Count];
|
||||
for (int i = 0; i < targets.Count; i++)
|
||||
{
|
||||
array[i] = Targets.GetInstance(targets[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public TargetInformation(Targets targets)
|
||||
{
|
||||
this.targets = new DerSequence(targets);
|
||||
}
|
||||
|
||||
public TargetInformation(Target[] targets)
|
||||
: this(new Targets(targets))
|
||||
{
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return targets;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class Targets : Asn1Encodable
|
||||
{
|
||||
private readonly Asn1Sequence targets;
|
||||
|
||||
public static Targets GetInstance(object obj)
|
||||
{
|
||||
if (obj is Targets)
|
||||
{
|
||||
return (Targets)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new Targets((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
private Targets(Asn1Sequence targets)
|
||||
{
|
||||
this.targets = targets;
|
||||
}
|
||||
|
||||
public Targets(Target[] targets)
|
||||
{
|
||||
this.targets = new DerSequence(targets);
|
||||
}
|
||||
|
||||
public virtual Target[] GetTargets()
|
||||
{
|
||||
Target[] array = new Target[targets.Count];
|
||||
for (int i = 0; i < targets.Count; i++)
|
||||
{
|
||||
array[i] = Target.GetInstance(targets[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return targets;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
using Org.BouncyCastle.Utilities.Collections;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class TbsCertificateList : Asn1Encodable
|
||||
{
|
||||
private class RevokedCertificatesEnumeration : IEnumerable
|
||||
{
|
||||
private class RevokedCertificatesEnumerator : IEnumerator
|
||||
{
|
||||
private readonly IEnumerator e;
|
||||
|
||||
public object Current => new CrlEntry(Asn1Sequence.GetInstance(e.Current));
|
||||
|
||||
internal RevokedCertificatesEnumerator(IEnumerator e)
|
||||
{
|
||||
this.e = e;
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
return e.MoveNext();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
e.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly IEnumerable en;
|
||||
|
||||
internal RevokedCertificatesEnumeration(IEnumerable en)
|
||||
{
|
||||
this.en = en;
|
||||
}
|
||||
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
return new RevokedCertificatesEnumerator(en.GetEnumerator());
|
||||
}
|
||||
}
|
||||
|
||||
internal Asn1Sequence seq;
|
||||
|
||||
internal DerInteger version;
|
||||
|
||||
internal AlgorithmIdentifier signature;
|
||||
|
||||
internal X509Name issuer;
|
||||
|
||||
internal Time thisUpdate;
|
||||
|
||||
internal Time nextUpdate;
|
||||
|
||||
internal Asn1Sequence revokedCertificates;
|
||||
|
||||
internal X509Extensions crlExtensions;
|
||||
|
||||
public int Version => version.Value.IntValue + 1;
|
||||
|
||||
public DerInteger VersionNumber => version;
|
||||
|
||||
public AlgorithmIdentifier Signature => signature;
|
||||
|
||||
public X509Name Issuer => issuer;
|
||||
|
||||
public Time ThisUpdate => thisUpdate;
|
||||
|
||||
public Time NextUpdate => nextUpdate;
|
||||
|
||||
public X509Extensions Extensions => crlExtensions;
|
||||
|
||||
public static TbsCertificateList GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
|
||||
}
|
||||
|
||||
public static TbsCertificateList GetInstance(object obj)
|
||||
{
|
||||
TbsCertificateList tbsCertificateList = obj as TbsCertificateList;
|
||||
if (obj == null || tbsCertificateList != null)
|
||||
{
|
||||
return tbsCertificateList;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new TbsCertificateList((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
internal TbsCertificateList(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count < 3 || seq.Count > 7)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count);
|
||||
}
|
||||
int num = 0;
|
||||
this.seq = seq;
|
||||
if (seq[num] is DerInteger)
|
||||
{
|
||||
version = DerInteger.GetInstance(seq[num++]);
|
||||
}
|
||||
else
|
||||
{
|
||||
version = new DerInteger(0);
|
||||
}
|
||||
signature = AlgorithmIdentifier.GetInstance(seq[num++]);
|
||||
issuer = X509Name.GetInstance(seq[num++]);
|
||||
thisUpdate = Time.GetInstance(seq[num++]);
|
||||
if (num < seq.Count && (seq[num] is DerUtcTime || seq[num] is DerGeneralizedTime || seq[num] is Time))
|
||||
{
|
||||
nextUpdate = Time.GetInstance(seq[num++]);
|
||||
}
|
||||
if (num < seq.Count && !(seq[num] is DerTaggedObject))
|
||||
{
|
||||
revokedCertificates = Asn1Sequence.GetInstance(seq[num++]);
|
||||
}
|
||||
if (num < seq.Count && seq[num] is DerTaggedObject)
|
||||
{
|
||||
crlExtensions = X509Extensions.GetInstance(seq[num]);
|
||||
}
|
||||
}
|
||||
|
||||
public CrlEntry[] GetRevokedCertificates()
|
||||
{
|
||||
if (revokedCertificates == null)
|
||||
{
|
||||
return new CrlEntry[0];
|
||||
}
|
||||
CrlEntry[] array = new CrlEntry[revokedCertificates.Count];
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
array[i] = new CrlEntry(Asn1Sequence.GetInstance(revokedCertificates[i]));
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public IEnumerable GetRevokedCertificateEnumeration()
|
||||
{
|
||||
if (revokedCertificates == null)
|
||||
{
|
||||
return EmptyEnumerable.Instance;
|
||||
}
|
||||
return new RevokedCertificatesEnumeration(revokedCertificates);
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return seq;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Math;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class TbsCertificateStructure : Asn1Encodable
|
||||
{
|
||||
internal Asn1Sequence seq;
|
||||
|
||||
internal DerInteger version;
|
||||
|
||||
internal DerInteger serialNumber;
|
||||
|
||||
internal AlgorithmIdentifier signature;
|
||||
|
||||
internal X509Name issuer;
|
||||
|
||||
internal Time startDate;
|
||||
|
||||
internal Time endDate;
|
||||
|
||||
internal X509Name subject;
|
||||
|
||||
internal SubjectPublicKeyInfo subjectPublicKeyInfo;
|
||||
|
||||
internal DerBitString issuerUniqueID;
|
||||
|
||||
internal DerBitString subjectUniqueID;
|
||||
|
||||
internal X509Extensions extensions;
|
||||
|
||||
public int Version => version.Value.IntValue + 1;
|
||||
|
||||
public DerInteger VersionNumber => version;
|
||||
|
||||
public DerInteger SerialNumber => serialNumber;
|
||||
|
||||
public AlgorithmIdentifier Signature => signature;
|
||||
|
||||
public X509Name Issuer => issuer;
|
||||
|
||||
public Time StartDate => startDate;
|
||||
|
||||
public Time EndDate => endDate;
|
||||
|
||||
public X509Name Subject => subject;
|
||||
|
||||
public SubjectPublicKeyInfo SubjectPublicKeyInfo => subjectPublicKeyInfo;
|
||||
|
||||
public DerBitString IssuerUniqueID => issuerUniqueID;
|
||||
|
||||
public DerBitString SubjectUniqueID => subjectUniqueID;
|
||||
|
||||
public X509Extensions Extensions => extensions;
|
||||
|
||||
public static TbsCertificateStructure GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
|
||||
}
|
||||
|
||||
public static TbsCertificateStructure GetInstance(object obj)
|
||||
{
|
||||
if (obj is TbsCertificateStructure)
|
||||
{
|
||||
return (TbsCertificateStructure)obj;
|
||||
}
|
||||
if (obj != null)
|
||||
{
|
||||
return new TbsCertificateStructure(Asn1Sequence.GetInstance(obj));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
internal TbsCertificateStructure(Asn1Sequence seq)
|
||||
{
|
||||
int num = 0;
|
||||
this.seq = seq;
|
||||
if (seq[0] is DerTaggedObject)
|
||||
{
|
||||
version = DerInteger.GetInstance((Asn1TaggedObject)seq[0], isExplicit: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
num = -1;
|
||||
version = new DerInteger(0);
|
||||
}
|
||||
bool flag = false;
|
||||
bool flag2 = false;
|
||||
if (version.Value.Equals(BigInteger.Zero))
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
else if (version.Value.Equals(BigInteger.One))
|
||||
{
|
||||
flag2 = true;
|
||||
}
|
||||
else if (!version.Value.Equals(BigInteger.Two))
|
||||
{
|
||||
throw new ArgumentException("version number not recognised");
|
||||
}
|
||||
serialNumber = DerInteger.GetInstance(seq[num + 1]);
|
||||
signature = AlgorithmIdentifier.GetInstance(seq[num + 2]);
|
||||
issuer = X509Name.GetInstance(seq[num + 3]);
|
||||
Asn1Sequence asn1Sequence = (Asn1Sequence)seq[num + 4];
|
||||
startDate = Time.GetInstance(asn1Sequence[0]);
|
||||
endDate = Time.GetInstance(asn1Sequence[1]);
|
||||
subject = X509Name.GetInstance(seq[num + 5]);
|
||||
subjectPublicKeyInfo = SubjectPublicKeyInfo.GetInstance(seq[num + 6]);
|
||||
int num2 = seq.Count - (num + 6) - 1;
|
||||
if (num2 != 0 && flag)
|
||||
{
|
||||
throw new ArgumentException("version 1 certificate contains extra data");
|
||||
}
|
||||
while (num2 > 0)
|
||||
{
|
||||
DerTaggedObject derTaggedObject = (DerTaggedObject)seq[num + 6 + num2];
|
||||
switch (derTaggedObject.TagNo)
|
||||
{
|
||||
case 1:
|
||||
issuerUniqueID = DerBitString.GetInstance(derTaggedObject, isExplicit: false);
|
||||
break;
|
||||
case 2:
|
||||
subjectUniqueID = DerBitString.GetInstance(derTaggedObject, isExplicit: false);
|
||||
break;
|
||||
case 3:
|
||||
if (flag2)
|
||||
{
|
||||
throw new ArgumentException("version 2 certificate cannot contain extensions");
|
||||
}
|
||||
extensions = X509Extensions.GetInstance(Asn1Sequence.GetInstance(derTaggedObject, explicitly: true));
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Unknown tag encountered in structure: " + derTaggedObject.TagNo);
|
||||
}
|
||||
num2--;
|
||||
}
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return seq;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class Time : Asn1Encodable, IAsn1Choice
|
||||
{
|
||||
private readonly Asn1Object time;
|
||||
|
||||
public static Time GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(obj.GetObject());
|
||||
}
|
||||
|
||||
public Time(Asn1Object time)
|
||||
{
|
||||
if (time == null)
|
||||
{
|
||||
throw new ArgumentNullException("time");
|
||||
}
|
||||
if (!(time is DerUtcTime) && !(time is DerGeneralizedTime))
|
||||
{
|
||||
throw new ArgumentException("unknown object passed to Time");
|
||||
}
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public Time(DateTime date)
|
||||
{
|
||||
string text = date.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture) + "Z";
|
||||
int num = int.Parse(text.Substring(0, 4));
|
||||
if (num < 1950 || num > 2049)
|
||||
{
|
||||
time = new DerGeneralizedTime(text);
|
||||
}
|
||||
else
|
||||
{
|
||||
time = new DerUtcTime(text.Substring(2));
|
||||
}
|
||||
}
|
||||
|
||||
public static Time GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is Time)
|
||||
{
|
||||
return (Time)obj;
|
||||
}
|
||||
if (obj is DerUtcTime)
|
||||
{
|
||||
return new Time((DerUtcTime)obj);
|
||||
}
|
||||
if (obj is DerGeneralizedTime)
|
||||
{
|
||||
return new Time((DerGeneralizedTime)obj);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public string GetTime()
|
||||
{
|
||||
if (time is DerUtcTime)
|
||||
{
|
||||
return ((DerUtcTime)time).AdjustedTimeString;
|
||||
}
|
||||
return ((DerGeneralizedTime)time).GetTime();
|
||||
}
|
||||
|
||||
public DateTime ToDateTime()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (time is DerUtcTime)
|
||||
{
|
||||
return ((DerUtcTime)time).ToAdjustedDateTime();
|
||||
}
|
||||
return ((DerGeneralizedTime)time).ToDateTime();
|
||||
}
|
||||
catch (FormatException ex)
|
||||
{
|
||||
throw new InvalidOperationException("invalid date string: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return time;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return GetTime();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class UserNotice : Asn1Encodable
|
||||
{
|
||||
private readonly NoticeReference noticeRef;
|
||||
|
||||
private readonly DisplayText explicitText;
|
||||
|
||||
public virtual NoticeReference NoticeRef => noticeRef;
|
||||
|
||||
public virtual DisplayText ExplicitText => explicitText;
|
||||
|
||||
public UserNotice(NoticeReference noticeRef, DisplayText explicitText)
|
||||
{
|
||||
this.noticeRef = noticeRef;
|
||||
this.explicitText = explicitText;
|
||||
}
|
||||
|
||||
public UserNotice(NoticeReference noticeRef, string str)
|
||||
: this(noticeRef, new DisplayText(str))
|
||||
{
|
||||
}
|
||||
|
||||
[Obsolete("Use GetInstance() instead")]
|
||||
public UserNotice(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count == 2)
|
||||
{
|
||||
noticeRef = NoticeReference.GetInstance(seq[0]);
|
||||
explicitText = DisplayText.GetInstance(seq[1]);
|
||||
}
|
||||
else if (seq.Count == 1)
|
||||
{
|
||||
if (seq[0].ToAsn1Object() is Asn1Sequence)
|
||||
{
|
||||
noticeRef = NoticeReference.GetInstance(seq[0]);
|
||||
explicitText = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
noticeRef = null;
|
||||
explicitText = DisplayText.GetInstance(seq[0]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (seq.Count != 0)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count);
|
||||
}
|
||||
noticeRef = null;
|
||||
explicitText = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static UserNotice GetInstance(object obj)
|
||||
{
|
||||
if (obj is UserNotice)
|
||||
{
|
||||
return (UserNotice)obj;
|
||||
}
|
||||
if (obj == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new UserNotice(Asn1Sequence.GetInstance(obj));
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
if (noticeRef != null)
|
||||
{
|
||||
asn1EncodableVector.Add(noticeRef);
|
||||
}
|
||||
if (explicitText != null)
|
||||
{
|
||||
asn1EncodableVector.Add(explicitText);
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class V1TbsCertificateGenerator
|
||||
{
|
||||
internal DerTaggedObject version = new DerTaggedObject(0, new DerInteger(0));
|
||||
|
||||
internal DerInteger serialNumber;
|
||||
|
||||
internal AlgorithmIdentifier signature;
|
||||
|
||||
internal X509Name issuer;
|
||||
|
||||
internal Time startDate;
|
||||
|
||||
internal Time endDate;
|
||||
|
||||
internal X509Name subject;
|
||||
|
||||
internal SubjectPublicKeyInfo subjectPublicKeyInfo;
|
||||
|
||||
public void SetSerialNumber(DerInteger serialNumber)
|
||||
{
|
||||
this.serialNumber = serialNumber;
|
||||
}
|
||||
|
||||
public void SetSignature(AlgorithmIdentifier signature)
|
||||
{
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public void SetIssuer(X509Name issuer)
|
||||
{
|
||||
this.issuer = issuer;
|
||||
}
|
||||
|
||||
public void SetStartDate(Time startDate)
|
||||
{
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public void SetStartDate(DerUtcTime startDate)
|
||||
{
|
||||
this.startDate = new Time(startDate);
|
||||
}
|
||||
|
||||
public void SetEndDate(Time endDate)
|
||||
{
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
public void SetEndDate(DerUtcTime endDate)
|
||||
{
|
||||
this.endDate = new Time(endDate);
|
||||
}
|
||||
|
||||
public void SetSubject(X509Name subject)
|
||||
{
|
||||
this.subject = subject;
|
||||
}
|
||||
|
||||
public void SetSubjectPublicKeyInfo(SubjectPublicKeyInfo pubKeyInfo)
|
||||
{
|
||||
subjectPublicKeyInfo = pubKeyInfo;
|
||||
}
|
||||
|
||||
public TbsCertificateStructure GenerateTbsCertificate()
|
||||
{
|
||||
if (serialNumber == null || signature == null || issuer == null || startDate == null || endDate == null || subject == null || subjectPublicKeyInfo == null)
|
||||
{
|
||||
throw new InvalidOperationException("not all mandatory fields set in V1 TBScertificate generator");
|
||||
}
|
||||
return new TbsCertificateStructure(new DerSequence(serialNumber, signature, issuer, new DerSequence(startDate, endDate), subject, subjectPublicKeyInfo));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class V2AttributeCertificateInfoGenerator
|
||||
{
|
||||
internal DerInteger version;
|
||||
|
||||
internal Holder holder;
|
||||
|
||||
internal AttCertIssuer issuer;
|
||||
|
||||
internal AlgorithmIdentifier signature;
|
||||
|
||||
internal DerInteger serialNumber;
|
||||
|
||||
internal Asn1EncodableVector attributes;
|
||||
|
||||
internal DerBitString issuerUniqueID;
|
||||
|
||||
internal X509Extensions extensions;
|
||||
|
||||
internal DerGeneralizedTime startDate;
|
||||
|
||||
internal DerGeneralizedTime endDate;
|
||||
|
||||
public V2AttributeCertificateInfoGenerator()
|
||||
{
|
||||
version = new DerInteger(1);
|
||||
attributes = new Asn1EncodableVector();
|
||||
}
|
||||
|
||||
public void SetHolder(Holder holder)
|
||||
{
|
||||
this.holder = holder;
|
||||
}
|
||||
|
||||
public void AddAttribute(string oid, Asn1Encodable value)
|
||||
{
|
||||
attributes.Add(new AttributeX509(new DerObjectIdentifier(oid), new DerSet(value)));
|
||||
}
|
||||
|
||||
public void AddAttribute(AttributeX509 attribute)
|
||||
{
|
||||
attributes.Add(attribute);
|
||||
}
|
||||
|
||||
public void SetSerialNumber(DerInteger serialNumber)
|
||||
{
|
||||
this.serialNumber = serialNumber;
|
||||
}
|
||||
|
||||
public void SetSignature(AlgorithmIdentifier signature)
|
||||
{
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public void SetIssuer(AttCertIssuer issuer)
|
||||
{
|
||||
this.issuer = issuer;
|
||||
}
|
||||
|
||||
public void SetStartDate(DerGeneralizedTime startDate)
|
||||
{
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public void SetEndDate(DerGeneralizedTime endDate)
|
||||
{
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
public void SetIssuerUniqueID(DerBitString issuerUniqueID)
|
||||
{
|
||||
this.issuerUniqueID = issuerUniqueID;
|
||||
}
|
||||
|
||||
public void SetExtensions(X509Extensions extensions)
|
||||
{
|
||||
this.extensions = extensions;
|
||||
}
|
||||
|
||||
public AttributeCertificateInfo GenerateAttributeCertificateInfo()
|
||||
{
|
||||
if (serialNumber == null || signature == null || issuer == null || startDate == null || endDate == null || holder == null || attributes == null)
|
||||
{
|
||||
throw new InvalidOperationException("not all mandatory fields set in V2 AttributeCertificateInfo generator");
|
||||
}
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(version, holder, issuer, signature, serialNumber);
|
||||
asn1EncodableVector.Add(new AttCertValidityPeriod(startDate, endDate));
|
||||
asn1EncodableVector.Add(new DerSequence(attributes));
|
||||
if (issuerUniqueID != null)
|
||||
{
|
||||
asn1EncodableVector.Add(issuerUniqueID);
|
||||
}
|
||||
if (extensions != null)
|
||||
{
|
||||
asn1EncodableVector.Add(extensions);
|
||||
}
|
||||
return AttributeCertificateInfo.GetInstance(new DerSequence(asn1EncodableVector));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class V2Form : Asn1Encodable
|
||||
{
|
||||
internal GeneralNames issuerName;
|
||||
|
||||
internal IssuerSerial baseCertificateID;
|
||||
|
||||
internal ObjectDigestInfo objectDigestInfo;
|
||||
|
||||
public GeneralNames IssuerName => issuerName;
|
||||
|
||||
public IssuerSerial BaseCertificateID => baseCertificateID;
|
||||
|
||||
public ObjectDigestInfo ObjectDigestInfo => objectDigestInfo;
|
||||
|
||||
public static V2Form GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
|
||||
}
|
||||
|
||||
public static V2Form GetInstance(object obj)
|
||||
{
|
||||
if (obj is V2Form)
|
||||
{
|
||||
return (V2Form)obj;
|
||||
}
|
||||
if (obj != null)
|
||||
{
|
||||
return new V2Form(Asn1Sequence.GetInstance(obj));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public V2Form(GeneralNames issuerName)
|
||||
: this(issuerName, null, null)
|
||||
{
|
||||
}
|
||||
|
||||
public V2Form(GeneralNames issuerName, IssuerSerial baseCertificateID)
|
||||
: this(issuerName, baseCertificateID, null)
|
||||
{
|
||||
}
|
||||
|
||||
public V2Form(GeneralNames issuerName, ObjectDigestInfo objectDigestInfo)
|
||||
: this(issuerName, null, objectDigestInfo)
|
||||
{
|
||||
}
|
||||
|
||||
public V2Form(GeneralNames issuerName, IssuerSerial baseCertificateID, ObjectDigestInfo objectDigestInfo)
|
||||
{
|
||||
this.issuerName = issuerName;
|
||||
this.baseCertificateID = baseCertificateID;
|
||||
this.objectDigestInfo = objectDigestInfo;
|
||||
}
|
||||
|
||||
private V2Form(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count > 3)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count);
|
||||
}
|
||||
int num = 0;
|
||||
if (!(seq[0] is Asn1TaggedObject))
|
||||
{
|
||||
num++;
|
||||
issuerName = GeneralNames.GetInstance(seq[0]);
|
||||
}
|
||||
for (int i = num; i != seq.Count; i++)
|
||||
{
|
||||
Asn1TaggedObject instance = Asn1TaggedObject.GetInstance(seq[i]);
|
||||
if (instance.TagNo == 0)
|
||||
{
|
||||
baseCertificateID = IssuerSerial.GetInstance(instance, explicitly: false);
|
||||
continue;
|
||||
}
|
||||
if (instance.TagNo == 1)
|
||||
{
|
||||
objectDigestInfo = ObjectDigestInfo.GetInstance(instance, isExplicit: false);
|
||||
continue;
|
||||
}
|
||||
throw new ArgumentException("Bad tag number: " + instance.TagNo);
|
||||
}
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
if (issuerName != null)
|
||||
{
|
||||
asn1EncodableVector.Add(issuerName);
|
||||
}
|
||||
if (baseCertificateID != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 0, baseCertificateID));
|
||||
}
|
||||
if (objectDigestInfo != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 1, objectDigestInfo));
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class V2TbsCertListGenerator
|
||||
{
|
||||
private DerInteger version = new DerInteger(1);
|
||||
|
||||
private AlgorithmIdentifier signature;
|
||||
|
||||
private X509Name issuer;
|
||||
|
||||
private Time thisUpdate;
|
||||
|
||||
private Time nextUpdate;
|
||||
|
||||
private X509Extensions extensions;
|
||||
|
||||
private IList crlEntries;
|
||||
|
||||
public void SetSignature(AlgorithmIdentifier signature)
|
||||
{
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public void SetIssuer(X509Name issuer)
|
||||
{
|
||||
this.issuer = issuer;
|
||||
}
|
||||
|
||||
public void SetThisUpdate(DerUtcTime thisUpdate)
|
||||
{
|
||||
this.thisUpdate = new Time(thisUpdate);
|
||||
}
|
||||
|
||||
public void SetNextUpdate(DerUtcTime nextUpdate)
|
||||
{
|
||||
this.nextUpdate = ((nextUpdate != null) ? new Time(nextUpdate) : null);
|
||||
}
|
||||
|
||||
public void SetThisUpdate(Time thisUpdate)
|
||||
{
|
||||
this.thisUpdate = thisUpdate;
|
||||
}
|
||||
|
||||
public void SetNextUpdate(Time nextUpdate)
|
||||
{
|
||||
this.nextUpdate = nextUpdate;
|
||||
}
|
||||
|
||||
public void AddCrlEntry(Asn1Sequence crlEntry)
|
||||
{
|
||||
if (crlEntries == null)
|
||||
{
|
||||
crlEntries = Platform.CreateArrayList();
|
||||
}
|
||||
crlEntries.Add(crlEntry);
|
||||
}
|
||||
|
||||
public void AddCrlEntry(DerInteger userCertificate, DerUtcTime revocationDate, int reason)
|
||||
{
|
||||
AddCrlEntry(userCertificate, new Time(revocationDate), reason);
|
||||
}
|
||||
|
||||
public void AddCrlEntry(DerInteger userCertificate, Time revocationDate, int reason)
|
||||
{
|
||||
AddCrlEntry(userCertificate, revocationDate, reason, null);
|
||||
}
|
||||
|
||||
public void AddCrlEntry(DerInteger userCertificate, Time revocationDate, int reason, DerGeneralizedTime invalidityDate)
|
||||
{
|
||||
IList list = Platform.CreateArrayList();
|
||||
IList list2 = Platform.CreateArrayList();
|
||||
if (reason != 0)
|
||||
{
|
||||
CrlReason crlReason = new CrlReason(reason);
|
||||
try
|
||||
{
|
||||
list.Add(X509Extensions.ReasonCode);
|
||||
list2.Add(new X509Extension(critical: false, new DerOctetString(crlReason.GetEncoded())));
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
throw new ArgumentException("error encoding reason: " + ex);
|
||||
}
|
||||
}
|
||||
if (invalidityDate != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
list.Add(X509Extensions.InvalidityDate);
|
||||
list2.Add(new X509Extension(critical: false, new DerOctetString(invalidityDate.GetEncoded())));
|
||||
}
|
||||
catch (IOException ex2)
|
||||
{
|
||||
throw new ArgumentException("error encoding invalidityDate: " + ex2);
|
||||
}
|
||||
}
|
||||
if (list.Count != 0)
|
||||
{
|
||||
AddCrlEntry(userCertificate, revocationDate, new X509Extensions(list, list2));
|
||||
}
|
||||
else
|
||||
{
|
||||
AddCrlEntry(userCertificate, revocationDate, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddCrlEntry(DerInteger userCertificate, Time revocationDate, X509Extensions extensions)
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(userCertificate, revocationDate);
|
||||
if (extensions != null)
|
||||
{
|
||||
asn1EncodableVector.Add(extensions);
|
||||
}
|
||||
AddCrlEntry(new DerSequence(asn1EncodableVector));
|
||||
}
|
||||
|
||||
public void SetExtensions(X509Extensions extensions)
|
||||
{
|
||||
this.extensions = extensions;
|
||||
}
|
||||
|
||||
public TbsCertificateList GenerateTbsCertList()
|
||||
{
|
||||
if (signature == null || issuer == null || thisUpdate == null)
|
||||
{
|
||||
throw new InvalidOperationException("Not all mandatory fields set in V2 TbsCertList generator.");
|
||||
}
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(version, signature, issuer, thisUpdate);
|
||||
if (nextUpdate != null)
|
||||
{
|
||||
asn1EncodableVector.Add(nextUpdate);
|
||||
}
|
||||
if (crlEntries != null)
|
||||
{
|
||||
Asn1Sequence[] array = new Asn1Sequence[crlEntries.Count];
|
||||
for (int i = 0; i < crlEntries.Count; i++)
|
||||
{
|
||||
array[i] = (Asn1Sequence)crlEntries[i];
|
||||
}
|
||||
asn1EncodableVector.Add(new DerSequence(array));
|
||||
}
|
||||
if (extensions != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(0, extensions));
|
||||
}
|
||||
return new TbsCertificateList(new DerSequence(asn1EncodableVector));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class V3TbsCertificateGenerator
|
||||
{
|
||||
internal DerTaggedObject version = new DerTaggedObject(0, new DerInteger(2));
|
||||
|
||||
internal DerInteger serialNumber;
|
||||
|
||||
internal AlgorithmIdentifier signature;
|
||||
|
||||
internal X509Name issuer;
|
||||
|
||||
internal Time startDate;
|
||||
|
||||
internal Time endDate;
|
||||
|
||||
internal X509Name subject;
|
||||
|
||||
internal SubjectPublicKeyInfo subjectPublicKeyInfo;
|
||||
|
||||
internal X509Extensions extensions;
|
||||
|
||||
private bool altNamePresentAndCritical;
|
||||
|
||||
private DerBitString issuerUniqueID;
|
||||
|
||||
private DerBitString subjectUniqueID;
|
||||
|
||||
public void SetSerialNumber(DerInteger serialNumber)
|
||||
{
|
||||
this.serialNumber = serialNumber;
|
||||
}
|
||||
|
||||
public void SetSignature(AlgorithmIdentifier signature)
|
||||
{
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public void SetIssuer(X509Name issuer)
|
||||
{
|
||||
this.issuer = issuer;
|
||||
}
|
||||
|
||||
public void SetStartDate(DerUtcTime startDate)
|
||||
{
|
||||
this.startDate = new Time(startDate);
|
||||
}
|
||||
|
||||
public void SetStartDate(Time startDate)
|
||||
{
|
||||
this.startDate = startDate;
|
||||
}
|
||||
|
||||
public void SetEndDate(DerUtcTime endDate)
|
||||
{
|
||||
this.endDate = new Time(endDate);
|
||||
}
|
||||
|
||||
public void SetEndDate(Time endDate)
|
||||
{
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
public void SetSubject(X509Name subject)
|
||||
{
|
||||
this.subject = subject;
|
||||
}
|
||||
|
||||
public void SetIssuerUniqueID(DerBitString uniqueID)
|
||||
{
|
||||
issuerUniqueID = uniqueID;
|
||||
}
|
||||
|
||||
public void SetSubjectUniqueID(DerBitString uniqueID)
|
||||
{
|
||||
subjectUniqueID = uniqueID;
|
||||
}
|
||||
|
||||
public void SetSubjectPublicKeyInfo(SubjectPublicKeyInfo pubKeyInfo)
|
||||
{
|
||||
subjectPublicKeyInfo = pubKeyInfo;
|
||||
}
|
||||
|
||||
public void SetExtensions(X509Extensions extensions)
|
||||
{
|
||||
this.extensions = extensions;
|
||||
if (extensions != null)
|
||||
{
|
||||
X509Extension extension = extensions.GetExtension(X509Extensions.SubjectAlternativeName);
|
||||
if (extension != null && extension.IsCritical)
|
||||
{
|
||||
altNamePresentAndCritical = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TbsCertificateStructure GenerateTbsCertificate()
|
||||
{
|
||||
if (serialNumber == null || signature == null || issuer == null || startDate == null || endDate == null || (subject == null && !altNamePresentAndCritical) || subjectPublicKeyInfo == null)
|
||||
{
|
||||
throw new InvalidOperationException("not all mandatory fields set in V3 TBScertificate generator");
|
||||
}
|
||||
DerSequence derSequence = new DerSequence(startDate, endDate);
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(version, serialNumber, signature, issuer, derSequence);
|
||||
if (subject != null)
|
||||
{
|
||||
asn1EncodableVector.Add(subject);
|
||||
}
|
||||
else
|
||||
{
|
||||
asn1EncodableVector.Add(DerSequence.Empty);
|
||||
}
|
||||
asn1EncodableVector.Add(subjectPublicKeyInfo);
|
||||
if (issuerUniqueID != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 1, issuerUniqueID));
|
||||
}
|
||||
if (subjectUniqueID != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 2, subjectUniqueID));
|
||||
}
|
||||
if (extensions != null)
|
||||
{
|
||||
asn1EncodableVector.Add(new DerTaggedObject(3, extensions));
|
||||
}
|
||||
return new TbsCertificateStructure(new DerSequence(asn1EncodableVector));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class X509Attributes
|
||||
{
|
||||
public static readonly DerObjectIdentifier RoleSyntax = new DerObjectIdentifier("2.5.4.72");
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class X509CertificateStructure : Asn1Encodable
|
||||
{
|
||||
private readonly TbsCertificateStructure tbsCert;
|
||||
|
||||
private readonly AlgorithmIdentifier sigAlgID;
|
||||
|
||||
private readonly DerBitString sig;
|
||||
|
||||
public TbsCertificateStructure TbsCertificate => tbsCert;
|
||||
|
||||
public int Version => tbsCert.Version;
|
||||
|
||||
public DerInteger SerialNumber => tbsCert.SerialNumber;
|
||||
|
||||
public X509Name Issuer => tbsCert.Issuer;
|
||||
|
||||
public Time StartDate => tbsCert.StartDate;
|
||||
|
||||
public Time EndDate => tbsCert.EndDate;
|
||||
|
||||
public X509Name Subject => tbsCert.Subject;
|
||||
|
||||
public SubjectPublicKeyInfo SubjectPublicKeyInfo => tbsCert.SubjectPublicKeyInfo;
|
||||
|
||||
public AlgorithmIdentifier SignatureAlgorithm => sigAlgID;
|
||||
|
||||
public DerBitString Signature => sig;
|
||||
|
||||
public static X509CertificateStructure GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
|
||||
}
|
||||
|
||||
public static X509CertificateStructure GetInstance(object obj)
|
||||
{
|
||||
if (obj is X509CertificateStructure)
|
||||
{
|
||||
return (X509CertificateStructure)obj;
|
||||
}
|
||||
if (obj == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new X509CertificateStructure(Asn1Sequence.GetInstance(obj));
|
||||
}
|
||||
|
||||
public X509CertificateStructure(TbsCertificateStructure tbsCert, AlgorithmIdentifier sigAlgID, DerBitString sig)
|
||||
{
|
||||
if (tbsCert == null)
|
||||
{
|
||||
throw new ArgumentNullException("tbsCert");
|
||||
}
|
||||
if (sigAlgID == null)
|
||||
{
|
||||
throw new ArgumentNullException("sigAlgID");
|
||||
}
|
||||
if (sig == null)
|
||||
{
|
||||
throw new ArgumentNullException("sig");
|
||||
}
|
||||
this.tbsCert = tbsCert;
|
||||
this.sigAlgID = sigAlgID;
|
||||
this.sig = sig;
|
||||
}
|
||||
|
||||
private X509CertificateStructure(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count != 3)
|
||||
{
|
||||
throw new ArgumentException("sequence wrong size for a certificate", "seq");
|
||||
}
|
||||
tbsCert = TbsCertificateStructure.GetInstance(seq[0]);
|
||||
sigAlgID = AlgorithmIdentifier.GetInstance(seq[1]);
|
||||
sig = DerBitString.GetInstance(seq[2]);
|
||||
}
|
||||
|
||||
public byte[] GetSignatureOctets()
|
||||
{
|
||||
return sig.GetOctets();
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return new DerSequence(tbsCert, sigAlgID, sig);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class X509DefaultEntryConverter : X509NameEntryConverter
|
||||
{
|
||||
public override Asn1Object GetConvertedValue(DerObjectIdentifier oid, string value)
|
||||
{
|
||||
if (value.Length != 0 && value[0] == '#')
|
||||
{
|
||||
try
|
||||
{
|
||||
return ConvertHexEncoded(value, 1);
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
throw new Exception("can't recode value for oid " + oid.Id);
|
||||
}
|
||||
}
|
||||
if (value.Length != 0 && value[0] == '\\')
|
||||
{
|
||||
value = value.Substring(1);
|
||||
}
|
||||
if (oid.Equals(X509Name.EmailAddress) || oid.Equals(X509Name.DC))
|
||||
{
|
||||
return new DerIA5String(value);
|
||||
}
|
||||
if (oid.Equals(X509Name.DateOfBirth))
|
||||
{
|
||||
return new DerGeneralizedTime(value);
|
||||
}
|
||||
if (oid.Equals(X509Name.C) || oid.Equals(X509Name.SerialNumber) || oid.Equals(X509Name.DnQualifier) || oid.Equals(X509Name.TelephoneNumber))
|
||||
{
|
||||
return new DerPrintableString(value);
|
||||
}
|
||||
return new DerUtf8String(value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class X509Extension
|
||||
{
|
||||
internal bool critical;
|
||||
|
||||
internal Asn1OctetString value;
|
||||
|
||||
public bool IsCritical => critical;
|
||||
|
||||
public Asn1OctetString Value => value;
|
||||
|
||||
public X509Extension(DerBoolean critical, Asn1OctetString value)
|
||||
{
|
||||
if (critical == null)
|
||||
{
|
||||
throw new ArgumentNullException("critical");
|
||||
}
|
||||
this.critical = critical.IsTrue;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public X509Extension(bool critical, Asn1OctetString value)
|
||||
{
|
||||
this.critical = critical;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Asn1Encodable GetParsedValue()
|
||||
{
|
||||
return ConvertValueToObject(this);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int hashCode = Value.GetHashCode();
|
||||
if (!IsCritical)
|
||||
{
|
||||
return ~hashCode;
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is X509Extension x509Extension))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (Value.Equals(x509Extension.Value))
|
||||
{
|
||||
return IsCritical == x509Extension.IsCritical;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Asn1Object ConvertValueToObject(X509Extension ext)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Asn1Object.FromByteArray(ext.Value.GetOctets());
|
||||
}
|
||||
catch (Exception innerException)
|
||||
{
|
||||
throw new ArgumentException("can't convert extension", innerException);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
using Org.BouncyCastle.Utilities.Collections;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class X509Extensions : Asn1Encodable
|
||||
{
|
||||
public static readonly DerObjectIdentifier SubjectDirectoryAttributes = new DerObjectIdentifier("2.5.29.9");
|
||||
|
||||
public static readonly DerObjectIdentifier SubjectKeyIdentifier = new DerObjectIdentifier("2.5.29.14");
|
||||
|
||||
public static readonly DerObjectIdentifier KeyUsage = new DerObjectIdentifier("2.5.29.15");
|
||||
|
||||
public static readonly DerObjectIdentifier PrivateKeyUsagePeriod = new DerObjectIdentifier("2.5.29.16");
|
||||
|
||||
public static readonly DerObjectIdentifier SubjectAlternativeName = new DerObjectIdentifier("2.5.29.17");
|
||||
|
||||
public static readonly DerObjectIdentifier IssuerAlternativeName = new DerObjectIdentifier("2.5.29.18");
|
||||
|
||||
public static readonly DerObjectIdentifier BasicConstraints = new DerObjectIdentifier("2.5.29.19");
|
||||
|
||||
public static readonly DerObjectIdentifier CrlNumber = new DerObjectIdentifier("2.5.29.20");
|
||||
|
||||
public static readonly DerObjectIdentifier ReasonCode = new DerObjectIdentifier("2.5.29.21");
|
||||
|
||||
public static readonly DerObjectIdentifier InstructionCode = new DerObjectIdentifier("2.5.29.23");
|
||||
|
||||
public static readonly DerObjectIdentifier InvalidityDate = new DerObjectIdentifier("2.5.29.24");
|
||||
|
||||
public static readonly DerObjectIdentifier DeltaCrlIndicator = new DerObjectIdentifier("2.5.29.27");
|
||||
|
||||
public static readonly DerObjectIdentifier IssuingDistributionPoint = new DerObjectIdentifier("2.5.29.28");
|
||||
|
||||
public static readonly DerObjectIdentifier CertificateIssuer = new DerObjectIdentifier("2.5.29.29");
|
||||
|
||||
public static readonly DerObjectIdentifier NameConstraints = new DerObjectIdentifier("2.5.29.30");
|
||||
|
||||
public static readonly DerObjectIdentifier CrlDistributionPoints = new DerObjectIdentifier("2.5.29.31");
|
||||
|
||||
public static readonly DerObjectIdentifier CertificatePolicies = new DerObjectIdentifier("2.5.29.32");
|
||||
|
||||
public static readonly DerObjectIdentifier PolicyMappings = new DerObjectIdentifier("2.5.29.33");
|
||||
|
||||
public static readonly DerObjectIdentifier AuthorityKeyIdentifier = new DerObjectIdentifier("2.5.29.35");
|
||||
|
||||
public static readonly DerObjectIdentifier PolicyConstraints = new DerObjectIdentifier("2.5.29.36");
|
||||
|
||||
public static readonly DerObjectIdentifier ExtendedKeyUsage = new DerObjectIdentifier("2.5.29.37");
|
||||
|
||||
public static readonly DerObjectIdentifier FreshestCrl = new DerObjectIdentifier("2.5.29.46");
|
||||
|
||||
public static readonly DerObjectIdentifier InhibitAnyPolicy = new DerObjectIdentifier("2.5.29.54");
|
||||
|
||||
public static readonly DerObjectIdentifier AuthorityInfoAccess = new DerObjectIdentifier("1.3.6.1.5.5.7.1.1");
|
||||
|
||||
public static readonly DerObjectIdentifier SubjectInfoAccess = new DerObjectIdentifier("1.3.6.1.5.5.7.1.11");
|
||||
|
||||
public static readonly DerObjectIdentifier LogoType = new DerObjectIdentifier("1.3.6.1.5.5.7.1.12");
|
||||
|
||||
public static readonly DerObjectIdentifier BiometricInfo = new DerObjectIdentifier("1.3.6.1.5.5.7.1.2");
|
||||
|
||||
public static readonly DerObjectIdentifier QCStatements = new DerObjectIdentifier("1.3.6.1.5.5.7.1.3");
|
||||
|
||||
public static readonly DerObjectIdentifier AuditIdentity = new DerObjectIdentifier("1.3.6.1.5.5.7.1.4");
|
||||
|
||||
public static readonly DerObjectIdentifier NoRevAvail = new DerObjectIdentifier("2.5.29.56");
|
||||
|
||||
public static readonly DerObjectIdentifier TargetInformation = new DerObjectIdentifier("2.5.29.55");
|
||||
|
||||
public static readonly DerObjectIdentifier ExpiredCertsOnCrl = new DerObjectIdentifier("2.5.29.60");
|
||||
|
||||
private readonly IDictionary extensions = Platform.CreateHashtable();
|
||||
|
||||
private readonly IList ordering;
|
||||
|
||||
public IEnumerable ExtensionOids => new EnumerableProxy(ordering);
|
||||
|
||||
public static X509Extensions GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
|
||||
}
|
||||
|
||||
public static X509Extensions GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is X509Extensions)
|
||||
{
|
||||
return (X509Extensions)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new X509Extensions((Asn1Sequence)obj);
|
||||
}
|
||||
if (obj is Asn1TaggedObject)
|
||||
{
|
||||
return GetInstance(((Asn1TaggedObject)obj).GetObject());
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
private X509Extensions(Asn1Sequence seq)
|
||||
{
|
||||
ordering = Platform.CreateArrayList();
|
||||
foreach (Asn1Encodable item in seq)
|
||||
{
|
||||
Asn1Sequence instance = Asn1Sequence.GetInstance(item.ToAsn1Object());
|
||||
if (instance.Count < 2 || instance.Count > 3)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + instance.Count);
|
||||
}
|
||||
DerObjectIdentifier instance2 = DerObjectIdentifier.GetInstance(instance[0].ToAsn1Object());
|
||||
bool critical = instance.Count == 3 && DerBoolean.GetInstance(instance[1].ToAsn1Object()).IsTrue;
|
||||
Asn1OctetString instance3 = Asn1OctetString.GetInstance(instance[instance.Count - 1].ToAsn1Object());
|
||||
if (extensions.Contains(instance2))
|
||||
{
|
||||
throw new ArgumentException("repeated extension found: " + instance2);
|
||||
}
|
||||
extensions.Add(instance2, new X509Extension(critical, instance3));
|
||||
ordering.Add(instance2);
|
||||
}
|
||||
}
|
||||
|
||||
public X509Extensions(IDictionary extensions)
|
||||
: this(null, extensions)
|
||||
{
|
||||
}
|
||||
|
||||
public X509Extensions(IList ordering, IDictionary extensions)
|
||||
{
|
||||
if (ordering == null)
|
||||
{
|
||||
this.ordering = Platform.CreateArrayList(extensions.Keys);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ordering = Platform.CreateArrayList(ordering);
|
||||
}
|
||||
foreach (DerObjectIdentifier item in this.ordering)
|
||||
{
|
||||
this.extensions.Add(item, (X509Extension)extensions[item]);
|
||||
}
|
||||
}
|
||||
|
||||
public X509Extensions(IList oids, IList values)
|
||||
{
|
||||
ordering = Platform.CreateArrayList(oids);
|
||||
int num = 0;
|
||||
foreach (DerObjectIdentifier item in ordering)
|
||||
{
|
||||
extensions.Add(item, (X509Extension)values[num++]);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public X509Extensions(Hashtable extensions)
|
||||
: this(null, extensions)
|
||||
{
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public X509Extensions(ArrayList ordering, Hashtable extensions)
|
||||
{
|
||||
if (ordering == null)
|
||||
{
|
||||
this.ordering = Platform.CreateArrayList(extensions.Keys);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ordering = Platform.CreateArrayList(ordering);
|
||||
}
|
||||
foreach (DerObjectIdentifier item in this.ordering)
|
||||
{
|
||||
this.extensions.Add(item, (X509Extension)extensions[item]);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public X509Extensions(ArrayList oids, ArrayList values)
|
||||
{
|
||||
ordering = Platform.CreateArrayList(oids);
|
||||
int num = 0;
|
||||
foreach (DerObjectIdentifier item in ordering)
|
||||
{
|
||||
extensions.Add(item, (X509Extension)values[num++]);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use ExtensionOids IEnumerable property")]
|
||||
public IEnumerator Oids()
|
||||
{
|
||||
return ExtensionOids.GetEnumerator();
|
||||
}
|
||||
|
||||
public X509Extension GetExtension(DerObjectIdentifier oid)
|
||||
{
|
||||
return (X509Extension)extensions[oid];
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
foreach (DerObjectIdentifier item in ordering)
|
||||
{
|
||||
X509Extension x509Extension = (X509Extension)extensions[item];
|
||||
Asn1EncodableVector asn1EncodableVector2 = new Asn1EncodableVector(item);
|
||||
if (x509Extension.IsCritical)
|
||||
{
|
||||
asn1EncodableVector2.Add(DerBoolean.True);
|
||||
}
|
||||
asn1EncodableVector2.Add(x509Extension.Value);
|
||||
asn1EncodableVector.Add(new DerSequence(asn1EncodableVector2));
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
|
||||
public bool Equivalent(X509Extensions other)
|
||||
{
|
||||
if (extensions.Count != other.extensions.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
foreach (DerObjectIdentifier key in extensions.Keys)
|
||||
{
|
||||
if (!extensions[key].Equals(other.extensions[key]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public DerObjectIdentifier[] GetExtensionOids()
|
||||
{
|
||||
return ToOidArray(ordering);
|
||||
}
|
||||
|
||||
public DerObjectIdentifier[] GetNonCriticalExtensionOids()
|
||||
{
|
||||
return GetExtensionOids(isCritical: false);
|
||||
}
|
||||
|
||||
public DerObjectIdentifier[] GetCriticalExtensionOids()
|
||||
{
|
||||
return GetExtensionOids(isCritical: true);
|
||||
}
|
||||
|
||||
private DerObjectIdentifier[] GetExtensionOids(bool isCritical)
|
||||
{
|
||||
IList list = Platform.CreateArrayList();
|
||||
foreach (DerObjectIdentifier item in ordering)
|
||||
{
|
||||
X509Extension x509Extension = (X509Extension)extensions[item];
|
||||
if (x509Extension.IsCritical == isCritical)
|
||||
{
|
||||
list.Add(item);
|
||||
}
|
||||
}
|
||||
return ToOidArray(list);
|
||||
}
|
||||
|
||||
private static DerObjectIdentifier[] ToOidArray(IList oids)
|
||||
{
|
||||
DerObjectIdentifier[] array = new DerObjectIdentifier[oids.Count];
|
||||
oids.CopyTo(array, 0);
|
||||
return array;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class X509ExtensionsGenerator
|
||||
{
|
||||
private IDictionary extensions = Platform.CreateHashtable();
|
||||
|
||||
private IList extOrdering = Platform.CreateArrayList();
|
||||
|
||||
public bool IsEmpty => extOrdering.Count < 1;
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
extensions = Platform.CreateHashtable();
|
||||
extOrdering = Platform.CreateArrayList();
|
||||
}
|
||||
|
||||
public void AddExtension(DerObjectIdentifier oid, bool critical, Asn1Encodable extValue)
|
||||
{
|
||||
byte[] derEncoded;
|
||||
try
|
||||
{
|
||||
derEncoded = extValue.GetDerEncoded();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new ArgumentException("error encoding value: " + ex);
|
||||
}
|
||||
AddExtension(oid, critical, derEncoded);
|
||||
}
|
||||
|
||||
public void AddExtension(DerObjectIdentifier oid, bool critical, byte[] extValue)
|
||||
{
|
||||
if (extensions.Contains(oid))
|
||||
{
|
||||
throw new ArgumentException(string.Concat("extension ", oid, " already added"));
|
||||
}
|
||||
extOrdering.Add(oid);
|
||||
extensions.Add(oid, new X509Extension(critical, new DerOctetString(extValue)));
|
||||
}
|
||||
|
||||
public X509Extensions Generate()
|
||||
{
|
||||
return new X509Extensions(extOrdering, extensions);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,724 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Org.BouncyCastle.Asn1.Pkcs;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
using Org.BouncyCastle.Utilities.Encoders;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class X509Name : Asn1Encodable
|
||||
{
|
||||
public static readonly DerObjectIdentifier C;
|
||||
|
||||
public static readonly DerObjectIdentifier O;
|
||||
|
||||
public static readonly DerObjectIdentifier OU;
|
||||
|
||||
public static readonly DerObjectIdentifier T;
|
||||
|
||||
public static readonly DerObjectIdentifier CN;
|
||||
|
||||
public static readonly DerObjectIdentifier Street;
|
||||
|
||||
public static readonly DerObjectIdentifier SerialNumber;
|
||||
|
||||
public static readonly DerObjectIdentifier L;
|
||||
|
||||
public static readonly DerObjectIdentifier ST;
|
||||
|
||||
public static readonly DerObjectIdentifier Surname;
|
||||
|
||||
public static readonly DerObjectIdentifier GivenName;
|
||||
|
||||
public static readonly DerObjectIdentifier Initials;
|
||||
|
||||
public static readonly DerObjectIdentifier Generation;
|
||||
|
||||
public static readonly DerObjectIdentifier UniqueIdentifier;
|
||||
|
||||
public static readonly DerObjectIdentifier BusinessCategory;
|
||||
|
||||
public static readonly DerObjectIdentifier PostalCode;
|
||||
|
||||
public static readonly DerObjectIdentifier DnQualifier;
|
||||
|
||||
public static readonly DerObjectIdentifier Pseudonym;
|
||||
|
||||
public static readonly DerObjectIdentifier DateOfBirth;
|
||||
|
||||
public static readonly DerObjectIdentifier PlaceOfBirth;
|
||||
|
||||
public static readonly DerObjectIdentifier Gender;
|
||||
|
||||
public static readonly DerObjectIdentifier CountryOfCitizenship;
|
||||
|
||||
public static readonly DerObjectIdentifier CountryOfResidence;
|
||||
|
||||
public static readonly DerObjectIdentifier NameAtBirth;
|
||||
|
||||
public static readonly DerObjectIdentifier PostalAddress;
|
||||
|
||||
public static readonly DerObjectIdentifier DmdName;
|
||||
|
||||
public static readonly DerObjectIdentifier TelephoneNumber;
|
||||
|
||||
public static readonly DerObjectIdentifier OrganizationIdentifier;
|
||||
|
||||
public static readonly DerObjectIdentifier Name;
|
||||
|
||||
public static readonly DerObjectIdentifier EmailAddress;
|
||||
|
||||
public static readonly DerObjectIdentifier UnstructuredName;
|
||||
|
||||
public static readonly DerObjectIdentifier UnstructuredAddress;
|
||||
|
||||
public static readonly DerObjectIdentifier E;
|
||||
|
||||
public static readonly DerObjectIdentifier DC;
|
||||
|
||||
public static readonly DerObjectIdentifier UID;
|
||||
|
||||
private static readonly bool[] defaultReverse;
|
||||
|
||||
public static readonly Hashtable DefaultSymbols;
|
||||
|
||||
public static readonly Hashtable RFC2253Symbols;
|
||||
|
||||
public static readonly Hashtable RFC1779Symbols;
|
||||
|
||||
public static readonly Hashtable DefaultLookup;
|
||||
|
||||
private readonly IList ordering = Platform.CreateArrayList();
|
||||
|
||||
private readonly X509NameEntryConverter converter;
|
||||
|
||||
private IList values = Platform.CreateArrayList();
|
||||
|
||||
private IList added = Platform.CreateArrayList();
|
||||
|
||||
private Asn1Sequence seq;
|
||||
|
||||
public static bool DefaultReverse
|
||||
{
|
||||
get
|
||||
{
|
||||
return defaultReverse[0];
|
||||
}
|
||||
set
|
||||
{
|
||||
defaultReverse[0] = value;
|
||||
}
|
||||
}
|
||||
|
||||
static X509Name()
|
||||
{
|
||||
C = new DerObjectIdentifier("2.5.4.6");
|
||||
O = new DerObjectIdentifier("2.5.4.10");
|
||||
OU = new DerObjectIdentifier("2.5.4.11");
|
||||
T = new DerObjectIdentifier("2.5.4.12");
|
||||
CN = new DerObjectIdentifier("2.5.4.3");
|
||||
Street = new DerObjectIdentifier("2.5.4.9");
|
||||
SerialNumber = new DerObjectIdentifier("2.5.4.5");
|
||||
L = new DerObjectIdentifier("2.5.4.7");
|
||||
ST = new DerObjectIdentifier("2.5.4.8");
|
||||
Surname = new DerObjectIdentifier("2.5.4.4");
|
||||
GivenName = new DerObjectIdentifier("2.5.4.42");
|
||||
Initials = new DerObjectIdentifier("2.5.4.43");
|
||||
Generation = new DerObjectIdentifier("2.5.4.44");
|
||||
UniqueIdentifier = new DerObjectIdentifier("2.5.4.45");
|
||||
BusinessCategory = new DerObjectIdentifier("2.5.4.15");
|
||||
PostalCode = new DerObjectIdentifier("2.5.4.17");
|
||||
DnQualifier = new DerObjectIdentifier("2.5.4.46");
|
||||
Pseudonym = new DerObjectIdentifier("2.5.4.65");
|
||||
DateOfBirth = new DerObjectIdentifier("1.3.6.1.5.5.7.9.1");
|
||||
PlaceOfBirth = new DerObjectIdentifier("1.3.6.1.5.5.7.9.2");
|
||||
Gender = new DerObjectIdentifier("1.3.6.1.5.5.7.9.3");
|
||||
CountryOfCitizenship = new DerObjectIdentifier("1.3.6.1.5.5.7.9.4");
|
||||
CountryOfResidence = new DerObjectIdentifier("1.3.6.1.5.5.7.9.5");
|
||||
NameAtBirth = new DerObjectIdentifier("1.3.36.8.3.14");
|
||||
PostalAddress = new DerObjectIdentifier("2.5.4.16");
|
||||
DmdName = new DerObjectIdentifier("2.5.4.54");
|
||||
TelephoneNumber = X509ObjectIdentifiers.id_at_telephoneNumber;
|
||||
OrganizationIdentifier = X509ObjectIdentifiers.id_at_organizationIdentifier;
|
||||
Name = X509ObjectIdentifiers.id_at_name;
|
||||
EmailAddress = PkcsObjectIdentifiers.Pkcs9AtEmailAddress;
|
||||
UnstructuredName = PkcsObjectIdentifiers.Pkcs9AtUnstructuredName;
|
||||
UnstructuredAddress = PkcsObjectIdentifiers.Pkcs9AtUnstructuredAddress;
|
||||
E = EmailAddress;
|
||||
DC = new DerObjectIdentifier("0.9.2342.19200300.100.1.25");
|
||||
UID = new DerObjectIdentifier("0.9.2342.19200300.100.1.1");
|
||||
bool[] array = new bool[1];
|
||||
defaultReverse = array;
|
||||
DefaultSymbols = new Hashtable();
|
||||
RFC2253Symbols = new Hashtable();
|
||||
RFC1779Symbols = new Hashtable();
|
||||
DefaultLookup = new Hashtable();
|
||||
DefaultSymbols.Add(C, "C");
|
||||
DefaultSymbols.Add(O, "O");
|
||||
DefaultSymbols.Add(T, "T");
|
||||
DefaultSymbols.Add(OU, "OU");
|
||||
DefaultSymbols.Add(CN, "CN");
|
||||
DefaultSymbols.Add(L, "L");
|
||||
DefaultSymbols.Add(ST, "ST");
|
||||
DefaultSymbols.Add(SerialNumber, "SERIALNUMBER");
|
||||
DefaultSymbols.Add(EmailAddress, "E");
|
||||
DefaultSymbols.Add(DC, "DC");
|
||||
DefaultSymbols.Add(UID, "UID");
|
||||
DefaultSymbols.Add(Street, "STREET");
|
||||
DefaultSymbols.Add(Surname, "SURNAME");
|
||||
DefaultSymbols.Add(GivenName, "GIVENNAME");
|
||||
DefaultSymbols.Add(Initials, "INITIALS");
|
||||
DefaultSymbols.Add(Generation, "GENERATION");
|
||||
DefaultSymbols.Add(UnstructuredAddress, "unstructuredAddress");
|
||||
DefaultSymbols.Add(UnstructuredName, "unstructuredName");
|
||||
DefaultSymbols.Add(UniqueIdentifier, "UniqueIdentifier");
|
||||
DefaultSymbols.Add(DnQualifier, "DN");
|
||||
DefaultSymbols.Add(Pseudonym, "Pseudonym");
|
||||
DefaultSymbols.Add(PostalAddress, "PostalAddress");
|
||||
DefaultSymbols.Add(NameAtBirth, "NameAtBirth");
|
||||
DefaultSymbols.Add(CountryOfCitizenship, "CountryOfCitizenship");
|
||||
DefaultSymbols.Add(CountryOfResidence, "CountryOfResidence");
|
||||
DefaultSymbols.Add(Gender, "Gender");
|
||||
DefaultSymbols.Add(PlaceOfBirth, "PlaceOfBirth");
|
||||
DefaultSymbols.Add(DateOfBirth, "DateOfBirth");
|
||||
DefaultSymbols.Add(PostalCode, "PostalCode");
|
||||
DefaultSymbols.Add(BusinessCategory, "BusinessCategory");
|
||||
DefaultSymbols.Add(TelephoneNumber, "TelephoneNumber");
|
||||
RFC2253Symbols.Add(C, "C");
|
||||
RFC2253Symbols.Add(O, "O");
|
||||
RFC2253Symbols.Add(OU, "OU");
|
||||
RFC2253Symbols.Add(CN, "CN");
|
||||
RFC2253Symbols.Add(L, "L");
|
||||
RFC2253Symbols.Add(ST, "ST");
|
||||
RFC2253Symbols.Add(Street, "STREET");
|
||||
RFC2253Symbols.Add(DC, "DC");
|
||||
RFC2253Symbols.Add(UID, "UID");
|
||||
RFC1779Symbols.Add(C, "C");
|
||||
RFC1779Symbols.Add(O, "O");
|
||||
RFC1779Symbols.Add(OU, "OU");
|
||||
RFC1779Symbols.Add(CN, "CN");
|
||||
RFC1779Symbols.Add(L, "L");
|
||||
RFC1779Symbols.Add(ST, "ST");
|
||||
RFC1779Symbols.Add(Street, "STREET");
|
||||
DefaultLookup.Add("c", C);
|
||||
DefaultLookup.Add("o", O);
|
||||
DefaultLookup.Add("t", T);
|
||||
DefaultLookup.Add("ou", OU);
|
||||
DefaultLookup.Add("cn", CN);
|
||||
DefaultLookup.Add("l", L);
|
||||
DefaultLookup.Add("st", ST);
|
||||
DefaultLookup.Add("serialnumber", SerialNumber);
|
||||
DefaultLookup.Add("street", Street);
|
||||
DefaultLookup.Add("emailaddress", E);
|
||||
DefaultLookup.Add("dc", DC);
|
||||
DefaultLookup.Add("e", E);
|
||||
DefaultLookup.Add("uid", UID);
|
||||
DefaultLookup.Add("surname", Surname);
|
||||
DefaultLookup.Add("givenname", GivenName);
|
||||
DefaultLookup.Add("initials", Initials);
|
||||
DefaultLookup.Add("generation", Generation);
|
||||
DefaultLookup.Add("unstructuredaddress", UnstructuredAddress);
|
||||
DefaultLookup.Add("unstructuredname", UnstructuredName);
|
||||
DefaultLookup.Add("uniqueidentifier", UniqueIdentifier);
|
||||
DefaultLookup.Add("dn", DnQualifier);
|
||||
DefaultLookup.Add("pseudonym", Pseudonym);
|
||||
DefaultLookup.Add("postaladdress", PostalAddress);
|
||||
DefaultLookup.Add("nameofbirth", NameAtBirth);
|
||||
DefaultLookup.Add("countryofcitizenship", CountryOfCitizenship);
|
||||
DefaultLookup.Add("countryofresidence", CountryOfResidence);
|
||||
DefaultLookup.Add("gender", Gender);
|
||||
DefaultLookup.Add("placeofbirth", PlaceOfBirth);
|
||||
DefaultLookup.Add("dateofbirth", DateOfBirth);
|
||||
DefaultLookup.Add("postalcode", PostalCode);
|
||||
DefaultLookup.Add("businesscategory", BusinessCategory);
|
||||
DefaultLookup.Add("telephonenumber", TelephoneNumber);
|
||||
}
|
||||
|
||||
public static X509Name GetInstance(Asn1TaggedObject obj, bool explicitly)
|
||||
{
|
||||
return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
|
||||
}
|
||||
|
||||
public static X509Name GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is X509Name)
|
||||
{
|
||||
return (X509Name)obj;
|
||||
}
|
||||
if (obj != null)
|
||||
{
|
||||
return new X509Name(Asn1Sequence.GetInstance(obj));
|
||||
}
|
||||
throw new ArgumentException("null object in factory", "obj");
|
||||
}
|
||||
|
||||
protected X509Name()
|
||||
{
|
||||
}
|
||||
|
||||
protected X509Name(Asn1Sequence seq)
|
||||
{
|
||||
this.seq = seq;
|
||||
foreach (Asn1Encodable item in seq)
|
||||
{
|
||||
Asn1Set instance = Asn1Set.GetInstance(item.ToAsn1Object());
|
||||
for (int i = 0; i < instance.Count; i++)
|
||||
{
|
||||
Asn1Sequence instance2 = Asn1Sequence.GetInstance(instance[i].ToAsn1Object());
|
||||
if (instance2.Count != 2)
|
||||
{
|
||||
throw new ArgumentException("badly sized pair");
|
||||
}
|
||||
ordering.Add(DerObjectIdentifier.GetInstance(instance2[0].ToAsn1Object()));
|
||||
Asn1Object asn1Object = instance2[1].ToAsn1Object();
|
||||
if (asn1Object is IAsn1String && !(asn1Object is DerUniversalString))
|
||||
{
|
||||
string text = ((IAsn1String)asn1Object).GetString();
|
||||
if (Platform.StartsWith(text, "#"))
|
||||
{
|
||||
text = "\\" + text;
|
||||
}
|
||||
values.Add(text);
|
||||
}
|
||||
else
|
||||
{
|
||||
values.Add("#" + Hex.ToHexString(asn1Object.GetEncoded()));
|
||||
}
|
||||
added.Add(i != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public X509Name(IList ordering, IDictionary attributes)
|
||||
: this(ordering, attributes, new X509DefaultEntryConverter())
|
||||
{
|
||||
}
|
||||
|
||||
public X509Name(IList ordering, IDictionary attributes, X509NameEntryConverter converter)
|
||||
{
|
||||
this.converter = converter;
|
||||
foreach (DerObjectIdentifier item in ordering)
|
||||
{
|
||||
object obj = attributes[item];
|
||||
if (obj == null)
|
||||
{
|
||||
throw new ArgumentException(string.Concat("No attribute for object id - ", item, " - passed to distinguished name"));
|
||||
}
|
||||
this.ordering.Add(item);
|
||||
added.Add(false);
|
||||
values.Add(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public X509Name(IList oids, IList values)
|
||||
: this(oids, values, new X509DefaultEntryConverter())
|
||||
{
|
||||
}
|
||||
|
||||
public X509Name(IList oids, IList values, X509NameEntryConverter converter)
|
||||
{
|
||||
this.converter = converter;
|
||||
if (oids.Count != values.Count)
|
||||
{
|
||||
throw new ArgumentException("'oids' must be same length as 'values'.");
|
||||
}
|
||||
for (int i = 0; i < oids.Count; i++)
|
||||
{
|
||||
ordering.Add(oids[i]);
|
||||
this.values.Add(values[i]);
|
||||
added.Add(false);
|
||||
}
|
||||
}
|
||||
|
||||
public X509Name(string dirName)
|
||||
: this(DefaultReverse, DefaultLookup, dirName)
|
||||
{
|
||||
}
|
||||
|
||||
public X509Name(string dirName, X509NameEntryConverter converter)
|
||||
: this(DefaultReverse, DefaultLookup, dirName, converter)
|
||||
{
|
||||
}
|
||||
|
||||
public X509Name(bool reverse, string dirName)
|
||||
: this(reverse, DefaultLookup, dirName)
|
||||
{
|
||||
}
|
||||
|
||||
public X509Name(bool reverse, string dirName, X509NameEntryConverter converter)
|
||||
: this(reverse, DefaultLookup, dirName, converter)
|
||||
{
|
||||
}
|
||||
|
||||
public X509Name(bool reverse, IDictionary lookUp, string dirName)
|
||||
: this(reverse, lookUp, dirName, new X509DefaultEntryConverter())
|
||||
{
|
||||
}
|
||||
|
||||
private DerObjectIdentifier DecodeOid(string name, IDictionary lookUp)
|
||||
{
|
||||
if (Platform.StartsWith(Platform.ToUpperInvariant(name), "OID."))
|
||||
{
|
||||
return new DerObjectIdentifier(name.Substring(4));
|
||||
}
|
||||
if (name[0] >= '0' && name[0] <= '9')
|
||||
{
|
||||
return new DerObjectIdentifier(name);
|
||||
}
|
||||
DerObjectIdentifier derObjectIdentifier = (DerObjectIdentifier)lookUp[Platform.ToLowerInvariant(name)];
|
||||
if (derObjectIdentifier == null)
|
||||
{
|
||||
throw new ArgumentException("Unknown object id - " + name + " - passed to distinguished name");
|
||||
}
|
||||
return derObjectIdentifier;
|
||||
}
|
||||
|
||||
public X509Name(bool reverse, IDictionary lookUp, string dirName, X509NameEntryConverter converter)
|
||||
{
|
||||
this.converter = converter;
|
||||
X509NameTokenizer x509NameTokenizer = new X509NameTokenizer(dirName);
|
||||
while (x509NameTokenizer.HasMoreTokens())
|
||||
{
|
||||
string text = x509NameTokenizer.NextToken();
|
||||
int num = text.IndexOf('=');
|
||||
if (num == -1)
|
||||
{
|
||||
throw new ArgumentException("badly formated directory string");
|
||||
}
|
||||
string name = text.Substring(0, num);
|
||||
string text2 = text.Substring(num + 1);
|
||||
DerObjectIdentifier value = DecodeOid(name, lookUp);
|
||||
if (text2.IndexOf('+') > 0)
|
||||
{
|
||||
X509NameTokenizer x509NameTokenizer2 = new X509NameTokenizer(text2, '+');
|
||||
string value2 = x509NameTokenizer2.NextToken();
|
||||
ordering.Add(value);
|
||||
values.Add(value2);
|
||||
added.Add(false);
|
||||
while (x509NameTokenizer2.HasMoreTokens())
|
||||
{
|
||||
string text3 = x509NameTokenizer2.NextToken();
|
||||
int num2 = text3.IndexOf('=');
|
||||
string name2 = text3.Substring(0, num2);
|
||||
string value3 = text3.Substring(num2 + 1);
|
||||
ordering.Add(DecodeOid(name2, lookUp));
|
||||
values.Add(value3);
|
||||
added.Add(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ordering.Add(value);
|
||||
values.Add(text2);
|
||||
added.Add(false);
|
||||
}
|
||||
}
|
||||
if (!reverse)
|
||||
{
|
||||
return;
|
||||
}
|
||||
IList list = Platform.CreateArrayList();
|
||||
IList list2 = Platform.CreateArrayList();
|
||||
IList list3 = Platform.CreateArrayList();
|
||||
int num3 = 1;
|
||||
for (int i = 0; i < ordering.Count; i++)
|
||||
{
|
||||
if (!(bool)added[i])
|
||||
{
|
||||
num3 = 0;
|
||||
}
|
||||
int index = num3++;
|
||||
list.Insert(index, ordering[i]);
|
||||
list2.Insert(index, values[i]);
|
||||
list3.Insert(index, added[i]);
|
||||
}
|
||||
ordering = list;
|
||||
values = list2;
|
||||
added = list3;
|
||||
}
|
||||
|
||||
public IList GetOidList()
|
||||
{
|
||||
return Platform.CreateArrayList(ordering);
|
||||
}
|
||||
|
||||
public IList GetValueList()
|
||||
{
|
||||
return GetValueList(null);
|
||||
}
|
||||
|
||||
public IList GetValueList(DerObjectIdentifier oid)
|
||||
{
|
||||
IList list = Platform.CreateArrayList();
|
||||
for (int i = 0; i != values.Count; i++)
|
||||
{
|
||||
if (oid == null || oid.Equals(ordering[i]))
|
||||
{
|
||||
string text = (string)values[i];
|
||||
if (Platform.StartsWith(text, "\\#"))
|
||||
{
|
||||
text = text.Substring(1);
|
||||
}
|
||||
list.Add(text);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
if (seq == null)
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
Asn1EncodableVector asn1EncodableVector2 = new Asn1EncodableVector();
|
||||
DerObjectIdentifier derObjectIdentifier = null;
|
||||
for (int i = 0; i != ordering.Count; i++)
|
||||
{
|
||||
DerObjectIdentifier derObjectIdentifier2 = (DerObjectIdentifier)ordering[i];
|
||||
string value = (string)values[i];
|
||||
if (derObjectIdentifier != null && !(bool)added[i])
|
||||
{
|
||||
asn1EncodableVector.Add(new DerSet(asn1EncodableVector2));
|
||||
asn1EncodableVector2 = new Asn1EncodableVector();
|
||||
}
|
||||
asn1EncodableVector2.Add(new DerSequence(derObjectIdentifier2, converter.GetConvertedValue(derObjectIdentifier2, value)));
|
||||
derObjectIdentifier = derObjectIdentifier2;
|
||||
}
|
||||
asn1EncodableVector.Add(new DerSet(asn1EncodableVector2));
|
||||
seq = new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
return seq;
|
||||
}
|
||||
|
||||
public bool Equivalent(X509Name other, bool inOrder)
|
||||
{
|
||||
if (!inOrder)
|
||||
{
|
||||
return Equivalent(other);
|
||||
}
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (other == this)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
int count = ordering.Count;
|
||||
if (count != other.ordering.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
DerObjectIdentifier derObjectIdentifier = (DerObjectIdentifier)ordering[i];
|
||||
DerObjectIdentifier obj = (DerObjectIdentifier)other.ordering[i];
|
||||
if (!derObjectIdentifier.Equals(obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string s = (string)values[i];
|
||||
string s2 = (string)other.values[i];
|
||||
if (!equivalentStrings(s, s2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Equivalent(X509Name other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (other == this)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
int count = ordering.Count;
|
||||
if (count != other.ordering.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool[] array = new bool[count];
|
||||
int num;
|
||||
int num2;
|
||||
int num3;
|
||||
if (ordering[0].Equals(other.ordering[0]))
|
||||
{
|
||||
num = 0;
|
||||
num2 = count;
|
||||
num3 = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
num = count - 1;
|
||||
num2 = -1;
|
||||
num3 = -1;
|
||||
}
|
||||
for (int i = num; i != num2; i += num3)
|
||||
{
|
||||
bool flag = false;
|
||||
DerObjectIdentifier derObjectIdentifier = (DerObjectIdentifier)ordering[i];
|
||||
string s = (string)values[i];
|
||||
for (int j = 0; j < count; j++)
|
||||
{
|
||||
if (array[j])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
DerObjectIdentifier obj = (DerObjectIdentifier)other.ordering[j];
|
||||
if (derObjectIdentifier.Equals(obj))
|
||||
{
|
||||
string s2 = (string)other.values[j];
|
||||
if (equivalentStrings(s, s2))
|
||||
{
|
||||
array[j] = true;
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool equivalentStrings(string s1, string s2)
|
||||
{
|
||||
string text = canonicalize(s1);
|
||||
string text2 = canonicalize(s2);
|
||||
if (!text.Equals(text2))
|
||||
{
|
||||
text = stripInternalSpaces(text);
|
||||
text2 = stripInternalSpaces(text2);
|
||||
if (!text.Equals(text2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static string canonicalize(string s)
|
||||
{
|
||||
string text = Platform.ToLowerInvariant(s).Trim();
|
||||
if (Platform.StartsWith(text, "#"))
|
||||
{
|
||||
Asn1Object asn1Object = decodeObject(text);
|
||||
if (asn1Object is IAsn1String)
|
||||
{
|
||||
text = Platform.ToLowerInvariant(((IAsn1String)asn1Object).GetString()).Trim();
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
private static Asn1Object decodeObject(string v)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Asn1Object.FromByteArray(Hex.Decode(v.Substring(1)));
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
throw new InvalidOperationException("unknown encoding in name: " + ex.Message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static string stripInternalSpaces(string str)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if (str.Length != 0)
|
||||
{
|
||||
char c = str[0];
|
||||
stringBuilder.Append(c);
|
||||
for (int i = 1; i < str.Length; i++)
|
||||
{
|
||||
char c2 = str[i];
|
||||
if (c != ' ' || c2 != ' ')
|
||||
{
|
||||
stringBuilder.Append(c2);
|
||||
}
|
||||
c = c2;
|
||||
}
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
private void AppendValue(StringBuilder buf, IDictionary oidSymbols, DerObjectIdentifier oid, string val)
|
||||
{
|
||||
string text = (string)oidSymbols[oid];
|
||||
if (text != null)
|
||||
{
|
||||
buf.Append(text);
|
||||
}
|
||||
else
|
||||
{
|
||||
buf.Append(oid.Id);
|
||||
}
|
||||
buf.Append('=');
|
||||
int i = buf.Length;
|
||||
buf.Append(val);
|
||||
int num = buf.Length;
|
||||
if (Platform.StartsWith(val, "\\#"))
|
||||
{
|
||||
i += 2;
|
||||
}
|
||||
for (; i != num; i++)
|
||||
{
|
||||
if (buf[i] == ',' || buf[i] == '"' || buf[i] == '\\' || buf[i] == '+' || buf[i] == '=' || buf[i] == '<' || buf[i] == '>' || buf[i] == ';')
|
||||
{
|
||||
buf.Insert(i++, "\\");
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string ToString(bool reverse, IDictionary oidSymbols)
|
||||
{
|
||||
ArrayList arrayList = new ArrayList();
|
||||
StringBuilder stringBuilder = null;
|
||||
for (int i = 0; i < ordering.Count; i++)
|
||||
{
|
||||
if ((bool)added[i])
|
||||
{
|
||||
stringBuilder.Append('+');
|
||||
AppendValue(stringBuilder, oidSymbols, (DerObjectIdentifier)ordering[i], (string)values[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
stringBuilder = new StringBuilder();
|
||||
AppendValue(stringBuilder, oidSymbols, (DerObjectIdentifier)ordering[i], (string)values[i]);
|
||||
arrayList.Add(stringBuilder);
|
||||
}
|
||||
}
|
||||
if (reverse)
|
||||
{
|
||||
arrayList.Reverse();
|
||||
}
|
||||
StringBuilder stringBuilder2 = new StringBuilder();
|
||||
if (arrayList.Count > 0)
|
||||
{
|
||||
stringBuilder2.Append(arrayList[0].ToString());
|
||||
for (int j = 1; j < arrayList.Count; j++)
|
||||
{
|
||||
stringBuilder2.Append(',');
|
||||
stringBuilder2.Append(arrayList[j].ToString());
|
||||
}
|
||||
}
|
||||
return stringBuilder2.ToString();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ToString(DefaultReverse, DefaultSymbols);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Org.BouncyCastle.Utilities.Encoders;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public abstract class X509NameEntryConverter
|
||||
{
|
||||
protected Asn1Object ConvertHexEncoded(string hexString, int offset)
|
||||
{
|
||||
string data = hexString.Substring(offset);
|
||||
return Asn1Object.FromByteArray(Hex.Decode(data));
|
||||
}
|
||||
|
||||
protected bool CanBePrintable(string str)
|
||||
{
|
||||
return DerPrintableString.IsPrintableString(str);
|
||||
}
|
||||
|
||||
public abstract Asn1Object GetConvertedValue(DerObjectIdentifier oid, string value);
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
using System.Text;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public class X509NameTokenizer
|
||||
{
|
||||
private string value;
|
||||
|
||||
private int index;
|
||||
|
||||
private char separator;
|
||||
|
||||
private StringBuilder buffer = new StringBuilder();
|
||||
|
||||
public X509NameTokenizer(string oid)
|
||||
: this(oid, ',')
|
||||
{
|
||||
}
|
||||
|
||||
public X509NameTokenizer(string oid, char separator)
|
||||
{
|
||||
value = oid;
|
||||
index = -1;
|
||||
this.separator = separator;
|
||||
}
|
||||
|
||||
public bool HasMoreTokens()
|
||||
{
|
||||
return index != value.Length;
|
||||
}
|
||||
|
||||
public string NextToken()
|
||||
{
|
||||
if (index == value.Length)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
int i = index + 1;
|
||||
bool flag = false;
|
||||
bool flag2 = false;
|
||||
buffer.Remove(0, buffer.Length);
|
||||
for (; i != value.Length; i++)
|
||||
{
|
||||
char c = value[i];
|
||||
if (c == '"')
|
||||
{
|
||||
if (!flag2)
|
||||
{
|
||||
flag = !flag;
|
||||
continue;
|
||||
}
|
||||
buffer.Append(c);
|
||||
flag2 = false;
|
||||
}
|
||||
else if (flag2 || flag)
|
||||
{
|
||||
if (c == '#' && buffer[buffer.Length - 1] == '=')
|
||||
{
|
||||
buffer.Append('\\');
|
||||
}
|
||||
else if (c == '+' && separator != '+')
|
||||
{
|
||||
buffer.Append('\\');
|
||||
}
|
||||
buffer.Append(c);
|
||||
flag2 = false;
|
||||
}
|
||||
else if (c == '\\')
|
||||
{
|
||||
flag2 = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (c == separator)
|
||||
{
|
||||
break;
|
||||
}
|
||||
buffer.Append(c);
|
||||
}
|
||||
}
|
||||
index = i;
|
||||
return buffer.ToString().Trim();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
namespace Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
public abstract class X509ObjectIdentifiers
|
||||
{
|
||||
internal const string ID = "2.5.4";
|
||||
|
||||
public static readonly DerObjectIdentifier CommonName = new DerObjectIdentifier("2.5.4.3");
|
||||
|
||||
public static readonly DerObjectIdentifier CountryName = new DerObjectIdentifier("2.5.4.6");
|
||||
|
||||
public static readonly DerObjectIdentifier LocalityName = new DerObjectIdentifier("2.5.4.7");
|
||||
|
||||
public static readonly DerObjectIdentifier StateOrProvinceName = new DerObjectIdentifier("2.5.4.8");
|
||||
|
||||
public static readonly DerObjectIdentifier Organization = new DerObjectIdentifier("2.5.4.10");
|
||||
|
||||
public static readonly DerObjectIdentifier OrganizationalUnitName = new DerObjectIdentifier("2.5.4.11");
|
||||
|
||||
public static readonly DerObjectIdentifier id_at_telephoneNumber = new DerObjectIdentifier("2.5.4.20");
|
||||
|
||||
public static readonly DerObjectIdentifier id_at_name = new DerObjectIdentifier("2.5.4.41");
|
||||
|
||||
public static readonly DerObjectIdentifier id_at_organizationIdentifier = new DerObjectIdentifier("2.5.4.97");
|
||||
|
||||
public static readonly DerObjectIdentifier IdSha1 = new DerObjectIdentifier("1.3.14.3.2.26");
|
||||
|
||||
public static readonly DerObjectIdentifier RipeMD160 = new DerObjectIdentifier("1.3.36.3.2.1");
|
||||
|
||||
public static readonly DerObjectIdentifier RipeMD160WithRsaEncryption = new DerObjectIdentifier("1.3.36.3.3.1.2");
|
||||
|
||||
public static readonly DerObjectIdentifier IdEARsa = new DerObjectIdentifier("2.5.8.1.1");
|
||||
|
||||
public static readonly DerObjectIdentifier IdPkix = new DerObjectIdentifier("1.3.6.1.5.5.7");
|
||||
|
||||
public static readonly DerObjectIdentifier IdPE = new DerObjectIdentifier(string.Concat(IdPkix, ".1"));
|
||||
|
||||
public static readonly DerObjectIdentifier IdAD = new DerObjectIdentifier(string.Concat(IdPkix, ".48"));
|
||||
|
||||
public static readonly DerObjectIdentifier IdADCAIssuers = new DerObjectIdentifier(string.Concat(IdAD, ".2"));
|
||||
|
||||
public static readonly DerObjectIdentifier IdADOcsp = new DerObjectIdentifier(string.Concat(IdAD, ".1"));
|
||||
|
||||
public static readonly DerObjectIdentifier OcspAccessMethod = IdADOcsp;
|
||||
|
||||
public static readonly DerObjectIdentifier CrlAccessMethod = IdADCAIssuers;
|
||||
}
|
||||
Reference in New Issue
Block a user