using System; using System.Text; using Mono.Security; namespace System.Security.Cryptography.X509Certificates { /// Defines the constraints set on a certificate. This class cannot be inherited. // Token: 0x02000287 RID: 647 public sealed class X509BasicConstraintsExtension : X509Extension { /// Initializes a new instance of the class. // Token: 0x06001793 RID: 6035 RVA: 0x0004EDD0 File Offset: 0x0004CFD0 public X509BasicConstraintsExtension() { this._oid = new Oid("2.5.29.19", "Basic Constraints"); } /// Initializes a new instance of the class using an object and a value that identifies whether the extension is critical. /// The encoded data to use to create the extension. /// true if the extension is critical; otherwise, false. // Token: 0x06001794 RID: 6036 RVA: 0x0004EDF0 File Offset: 0x0004CFF0 public X509BasicConstraintsExtension(AsnEncodedData encodedBasicConstraints, bool critical) { this._oid = new Oid("2.5.29.19", "Basic Constraints"); this._raw = encodedBasicConstraints.RawData; base.Critical = critical; this._status = this.Decode(base.RawData); } /// Initializes a new instance of the class. Parameters specify a value that indicates whether a certificate is a certificate authority (CA) certificate, a value that indicates whether the certificate has a restriction on the number of path levels it allows, the number of levels allowed in a certificate's path, and a value that indicates whether the extension is critical. /// true if the certificate is a certificate authority (CA) certificate; otherwise, false. /// true if the certificate has a restriction on the number of path levels it allows; otherwise, false. /// The number of levels allowed in a certificate's path. /// true if the extension is critical; otherwise, false. // Token: 0x06001795 RID: 6037 RVA: 0x0004EE40 File Offset: 0x0004D040 public X509BasicConstraintsExtension(bool certificateAuthority, bool hasPathLengthConstraint, int pathLengthConstraint, bool critical) { if (hasPathLengthConstraint) { if (pathLengthConstraint < 0) { throw new ArgumentOutOfRangeException("pathLengthConstraint"); } this._pathLengthConstraint = pathLengthConstraint; } this._hasPathLengthConstraint = hasPathLengthConstraint; this._certificateAuthority = certificateAuthority; this._oid = new Oid("2.5.29.19", "Basic Constraints"); base.Critical = critical; base.RawData = this.Encode(); } /// Gets a value indicating whether a certificate is a certificate authority (CA) certificate. /// true if the certificate is a certificate authority (CA) certificate, otherwise, false. // Token: 0x17000774 RID: 1908 // (get) Token: 0x06001796 RID: 6038 RVA: 0x0004EEAC File Offset: 0x0004D0AC public bool CertificateAuthority { get { AsnDecodeStatus status = this._status; if (status != AsnDecodeStatus.Ok && status != AsnDecodeStatus.InformationNotAvailable) { throw new CryptographicException("Badly encoded extension."); } return this._certificateAuthority; } } /// Gets a value indicating whether a certificate has a restriction on the number of path levels it allows. /// true if the certificate has a restriction on the number of path levels it allows, otherwise, false. /// The extension cannot be decoded. // Token: 0x17000775 RID: 1909 // (get) Token: 0x06001797 RID: 6039 RVA: 0x0004EEE4 File Offset: 0x0004D0E4 public bool HasPathLengthConstraint { get { AsnDecodeStatus status = this._status; if (status != AsnDecodeStatus.Ok && status != AsnDecodeStatus.InformationNotAvailable) { throw new CryptographicException("Badly encoded extension."); } return this._hasPathLengthConstraint; } } /// Gets the number of levels allowed in a certificate's path. /// An integer indicating the number of levels allowed in a certificate's path. /// The extension cannot be decoded. // Token: 0x17000776 RID: 1910 // (get) Token: 0x06001798 RID: 6040 RVA: 0x0004EF1C File Offset: 0x0004D11C public int PathLengthConstraint { get { AsnDecodeStatus status = this._status; if (status != AsnDecodeStatus.Ok && status != AsnDecodeStatus.InformationNotAvailable) { throw new CryptographicException("Badly encoded extension."); } return this._pathLengthConstraint; } } /// Initializes a new instance of the class using an object. /// The encoded data to use to create the extension. // Token: 0x06001799 RID: 6041 RVA: 0x0004EF54 File Offset: 0x0004D154 public override void CopyFrom(AsnEncodedData asnEncodedData) { if (asnEncodedData == null) { throw new ArgumentNullException("asnEncodedData"); } X509Extension x509Extension = asnEncodedData as X509Extension; if (x509Extension == null) { throw new ArgumentException(global::Locale.GetText("Wrong type."), "asnEncodedData"); } if (x509Extension._oid == null) { this._oid = new Oid("2.5.29.19", "Basic Constraints"); } else { this._oid = new Oid(x509Extension._oid); } base.RawData = x509Extension.RawData; base.Critical = x509Extension.Critical; this._status = this.Decode(base.RawData); } // Token: 0x0600179A RID: 6042 RVA: 0x0004EFF4 File Offset: 0x0004D1F4 internal AsnDecodeStatus Decode(byte[] extension) { if (extension == null || extension.Length == 0) { return AsnDecodeStatus.BadAsn; } if (extension[0] != 48) { return AsnDecodeStatus.BadTag; } if (extension.Length < 3 && (extension.Length != 2 || extension[1] != 0)) { return AsnDecodeStatus.BadLength; } try { ASN1 asn = new ASN1(extension); int num = 0; ASN1 asn2 = asn[num++]; if (asn2 != null && asn2.Tag == 1) { this._certificateAuthority = asn2.Value[0] == byte.MaxValue; asn2 = asn[num++]; } if (asn2 != null && asn2.Tag == 2) { this._hasPathLengthConstraint = true; this._pathLengthConstraint = ASN1Convert.ToInt32(asn2); } } catch { return AsnDecodeStatus.BadAsn; } return AsnDecodeStatus.Ok; } // Token: 0x0600179B RID: 6043 RVA: 0x0004F0D8 File Offset: 0x0004D2D8 internal byte[] Encode() { ASN1 asn = new ASN1(48); if (this._certificateAuthority) { asn.Add(new ASN1(1, new byte[] { byte.MaxValue })); } if (this._hasPathLengthConstraint) { if (this._pathLengthConstraint == 0) { asn.Add(new ASN1(2, new byte[1])); } else { asn.Add(ASN1Convert.FromInt32(this._pathLengthConstraint)); } } return asn.GetBytes(); } // Token: 0x0600179C RID: 6044 RVA: 0x0004F15C File Offset: 0x0004D35C internal override string ToString(bool multiLine) { switch (this._status) { case AsnDecodeStatus.BadAsn: return string.Empty; case AsnDecodeStatus.BadTag: case AsnDecodeStatus.BadLength: return base.FormatUnkownData(this._raw); case AsnDecodeStatus.InformationNotAvailable: return "Information Not Available"; default: { if (this._oid.Value != "2.5.29.19") { return string.Format("Unknown Key Usage ({0})", this._oid.Value); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("Subject Type="); if (this._certificateAuthority) { stringBuilder.Append("CA"); } else { stringBuilder.Append("End Entity"); } if (multiLine) { stringBuilder.Append(Environment.NewLine); } else { stringBuilder.Append(", "); } stringBuilder.Append("Path Length Constraint="); if (this._hasPathLengthConstraint) { stringBuilder.Append(this._pathLengthConstraint); } else { stringBuilder.Append("None"); } if (multiLine) { stringBuilder.Append(Environment.NewLine); } return stringBuilder.ToString(); } } } // Token: 0x040012F2 RID: 4850 internal const string oid = "2.5.29.19"; // Token: 0x040012F3 RID: 4851 internal const string friendlyName = "Basic Constraints"; // Token: 0x040012F4 RID: 4852 private bool _certificateAuthority; // Token: 0x040012F5 RID: 4853 private bool _hasPathLengthConstraint; // Token: 0x040012F6 RID: 4854 private int _pathLengthConstraint; // Token: 0x040012F7 RID: 4855 private AsnDecodeStatus _status; } }