protected override ASN1 ToBeSigned(string oid) { // TBSCertificate ASN1 tbsCert = new ASN1(0x30); if (version > 1) { // TBSCertificate / [0] Version DEFAULT v1, byte[] ver = { (byte)(version - 1) }; ASN1 v = tbsCert.Add(new ASN1(0xA0)); v.Add(new ASN1(0x02, ver)); } // TBSCertificate / CertificateSerialNumber, tbsCert.Add(new ASN1(0x02, sn)); // TBSCertificate / AlgorithmIdentifier, tbsCert.Add(PKCS7.AlgorithmIdentifier(oid)); // TBSCertificate / Name tbsCert.Add(X501.FromString(issuer)); // TBSCertificate / Validity ASN1 validity = tbsCert.Add(new ASN1(0x30)); // TBSCertificate / Validity / Time validity.Add(ASN1Convert.FromDateTime(notBefore)); // TBSCertificate / Validity / Time validity.Add(ASN1Convert.FromDateTime(notAfter)); // TBSCertificate / Name tbsCert.Add(X501.FromString(subject)); // TBSCertificate / SubjectPublicKeyInfo tbsCert.Add(SubjectPublicKeyInfo()); if (version > 1) { // TBSCertificate / [1] IMPLICIT UniqueIdentifier OPTIONAL if (issuerUniqueID != null) { tbsCert.Add(new ASN1(0xA1, UniqueIdentifier(issuerUniqueID))); } // TBSCertificate / [2] IMPLICIT UniqueIdentifier OPTIONAL if (subjectUniqueID != null) { tbsCert.Add(new ASN1(0xA1, UniqueIdentifier(subjectUniqueID))); } // TBSCertificate / [3] Extensions OPTIONAL if ((version > 2) && (extensions.Count > 0)) { tbsCert.Add(new ASN1(0xA3, extensions.GetBytes())); } } return(tbsCert); }
public void ConvertDateTimeAfter2050() { DateTime expected = DateTime.Now.AddYears(50); ASN1 dt = ASN1Convert.FromDateTime(expected); Assert.AreEqual(0x18, dt.Tag, "GENERALIZEDTIME"); DateTime actual = ASN1Convert.ToDateTime(dt); Assert.AreEqual(DateTimeKind.Utc, actual.Kind, "Kind"); AssertDate(expected, actual.ToLocalTime(), "DateTime"); }
public void ConvertDateTimeAfter2000() { DateTime expected = DateTime.Now; ASN1 dt = ASN1Convert.FromDateTime(expected); Assert.AreEqual(0x17, dt.Tag, "UTCTIME"); DateTime actual = ASN1Convert.ToDateTime(dt); Assert.AreEqual(DateTimeKind.Utc, actual.Kind, "Kind"); AssertDate(expected, actual.ToLocalTime(), "DateTime"); }
public byte[] GetBytes() { ASN1 aSN = new ASN1(48); aSN.Add(new ASN1(2, sn)); aSN.Add(ASN1Convert.FromDateTime(revocationDate)); if (extensions.Count > 0) { aSN.Add(new ASN1(extensions.GetBytes())); } return(aSN.GetBytes()); }
public byte[] GetBytes() { ASN1 sequence = new ASN1(0x30); sequence.Add(new ASN1(0x02, sn)); sequence.Add(ASN1Convert.FromDateTime(revocationDate)); if (extensions.Count > 0) { sequence.Add(new ASN1(extensions.GetBytes())); } return(sequence.GetBytes()); }
public byte[] GetBytes() { ASN1 asn = new ASN1(48); asn.Add(new ASN1(2, this.sn)); asn.Add(ASN1Convert.FromDateTime(this.revocationDate)); if (this.extensions.Count > 0) { asn.Add(new ASN1(this.extensions.GetBytes())); } return(asn.GetBytes()); }
public void ConvertDateTimeBefore2000() { DateTime expected = DateTime.Now.AddYears(-50); ASN1 dt = ASN1Convert.FromDateTime(expected); Assert.AreEqual(0x17, dt.Tag, "UTCTIME"); DateTime actual = ASN1Convert.ToDateTime(dt); #if NET_2_0 Assert.AreEqual(DateTimeKind.Utc, actual.Kind, "Kind"); #endif AssertDate(expected, actual, "DateTime"); }
protected override ASN1 ToBeSigned(string oid) { ASN1 asn = new ASN1(48); if (this.version > 1) { byte[] data = new byte[] { this.version - 1 }; ASN1 asn2 = asn.Add(new ASN1(160)); asn2.Add(new ASN1(2, data)); } asn.Add(new ASN1(2, this.sn)); asn.Add(PKCS7.AlgorithmIdentifier(oid)); asn.Add(X501.FromString(this.issuer)); ASN1 asn3 = asn.Add(new ASN1(48)); asn3.Add(ASN1Convert.FromDateTime(this.notBefore)); asn3.Add(ASN1Convert.FromDateTime(this.notAfter)); asn.Add(X501.FromString(this.subject)); asn.Add(this.SubjectPublicKeyInfo()); if (this.version > 1) { if (this.issuerUniqueID != null) { asn.Add(new ASN1(161, this.UniqueIdentifier(this.issuerUniqueID))); } if (this.subjectUniqueID != null) { asn.Add(new ASN1(161, this.UniqueIdentifier(this.subjectUniqueID))); } if (this.version > 2 && this.extensions.Count > 0) { asn.Add(new ASN1(163, this.extensions.GetBytes())); } } return(asn); }
public void Unsorted() { ASN1 dt = ASN1Convert.FromDateTime(DateTime.UtcNow); ASN1 st = PKCS7.Attribute(PKCS7.Oid.signingTime, dt); PKCS7.SignedData sd = new PKCS7.SignedData(); sd.ContentInfo.ContentType = PKCS7.Oid.data; sd.ContentInfo.Content.Add(new ASN1(0x04, Encoding.UTF8.GetBytes("Mono"))); sd.SignerInfo.AuthenticatedAttributes.Add(st); sd.SignerInfo.Key = key; // note: key and cert and unrelated - this is just for testing sd.SignerInfo.Certificate = new X509Certificate(cert); sd.HashName = "SHA1"; // this trigger the addition of two new AA byte[] result = sd.GetBytes(); Assert.AreEqual(3, sd.SignerInfo.AuthenticatedAttributes.Count, "aa-Count"); // verify that attributes are sorted (as they are stored in a SET) Assert.AreEqual(24, (sd.SignerInfo.AuthenticatedAttributes [0] as ASN1).Length, "0"); Assert.AreEqual(28, (sd.SignerInfo.AuthenticatedAttributes [1] as ASN1).Length, "1"); Assert.AreEqual(35, (sd.SignerInfo.AuthenticatedAttributes [2] as ASN1).Length, "2"); }
protected override ASN1 ToBeSigned(string oid) { ASN1 aSN = new ASN1(48); if (version > 1) { byte[] data = new byte[1] { (byte)(version - 1) }; ASN1 aSN2 = aSN.Add(new ASN1(160)); aSN2.Add(new ASN1(2, data)); } aSN.Add(new ASN1(2, sn)); aSN.Add(PKCS7.AlgorithmIdentifier(oid)); aSN.Add(X501.FromString(issuer)); ASN1 aSN3 = aSN.Add(new ASN1(48)); aSN3.Add(ASN1Convert.FromDateTime(notBefore)); aSN3.Add(ASN1Convert.FromDateTime(notAfter)); aSN.Add(X501.FromString(subject)); aSN.Add(SubjectPublicKeyInfo()); if (version > 1) { if (issuerUniqueID != null) { aSN.Add(new ASN1(161, UniqueIdentifier(issuerUniqueID))); } if (subjectUniqueID != null) { aSN.Add(new ASN1(161, UniqueIdentifier(subjectUniqueID))); } if (version > 2 && extensions.Count > 0) { aSN.Add(new ASN1(163, extensions.GetBytes())); } } return(aSN); }
protected override ASN1 ToBeSigned(string oid) { ASN1 asN1_1 = new ASN1((byte)48); if (this.version > (byte)1) { byte[] data = new byte[1] { (byte)((uint)this.version - 1U) }; asN1_1.Add(new ASN1((byte)160)).Add(new ASN1((byte)2, data)); } asN1_1.Add(new ASN1((byte)2, this.sn)); asN1_1.Add(PKCS7.AlgorithmIdentifier(oid)); asN1_1.Add(X501.FromString(this.issuer)); ASN1 asN1_2 = asN1_1.Add(new ASN1((byte)48)); asN1_2.Add(ASN1Convert.FromDateTime(this.notBefore)); asN1_2.Add(ASN1Convert.FromDateTime(this.notAfter)); asN1_1.Add(X501.FromString(this.subject)); asN1_1.Add(this.SubjectPublicKeyInfo()); if (this.version > (byte)1) { if (this.issuerUniqueID != null) { asN1_1.Add(new ASN1((byte)161, this.UniqueIdentifier(this.issuerUniqueID))); } if (this.subjectUniqueID != null) { asN1_1.Add(new ASN1((byte)161, this.UniqueIdentifier(this.subjectUniqueID))); } if (this.version > (byte)2 && this.extensions.Count > 0) { asN1_1.Add(new ASN1((byte)163, this.extensions.GetBytes())); } } return(asN1_1); }