/// <summary> /// Used to create the extension from typed model /// </summary> /// <param name="isCompliant"><b>QcCompliant</b>. True is the cert is European Qualified Certificate otherwize false</param> /// <param name="limit"><b>QcLimitValue</b>. Monetary value </param> /// <param name="retentionPeriod"><b>QcRetentionPeriod</b></param> /// <param name="isQSCD"><b>QcSSCD</b></param> /// <param name="pdsLocations"><b>QcPds</b></param> /// <param name="type"><b>QcType</b></param> /// <param name="psd2"><b>PSD2 QcStatement</b></param> /// <param name="critical"></param> public QualifiedCertificateStatementsExtension(bool isCompliant, QcMonetaryValue limit, int retentionPeriod, bool isQSCD, IEnumerable <PdsLocation> pdsLocations, QcTypeIdentifiers type, Psd2Attributes psd2, bool critical) { Oid = new Oid(Oid_QC_Statements, "Qualified Certificate Statements"); Critical = critical; var statements = new List <DerAsnSequence>(); if (isCompliant) { statements.Add(new QcComplianceStatement()); } if (retentionPeriod > 0) { statements.Add(new QcRetentionPeriodStatement(retentionPeriod)); } if (limit != null) { statements.Add(new QcLimitValueStatement(limit)); } if (isQSCD) { statements.Add(new QcSSCDStatement()); } statements.Add(new QcTypeStatement(type)); if (pdsLocations?.Any() == true) { statements.Add(new QcPdsStatement(pdsLocations)); } if (psd2 != null) { statements.Add(new Psd2QcStatement(psd2)); } RawData = DerConvert.Encode(new DerAsnSequence(statements.ToArray())).ToArray(); _Statements = new QualifiedCertificateStatements(isCompliant, limit, retentionPeriod, isQSCD, pdsLocations, type, psd2); _decoded = true; }
/// <summary> /// Used to create the extension from typed model /// </summary> /// <param name="psd2Type"></param> /// <param name="critical"></param> public QualifiedCertificateStatementsExtension(Psd2CertificateAttributes psd2Type, bool critical) { Oid = new Oid(Oid_QC_Statements, "Qualified Certificate Statements"); Critical = critical; RawData = DerConvert.Encode(new Psd2QcStatement(psd2Type)).ToArray(); _Psd2Type = psd2Type; _decoded = true; }
/// <summary> /// Used to create the extension from typed model /// </summary> /// <param name="policies"></param> /// <param name="critical"></param> public CertificatePoliciesExtension(PolicyInformation[] policies, bool critical) { Oid = new Oid(Oid_CertificatePolicies, "Certificate Policies"); Critical = critical; RawData = DerConvert.Encode(new CertificatePolicies(policies)).ToArray(); _Policies = policies; _decoded = true; }
/// <summary> /// Used to create the extension from typed model /// </summary> /// <param name="distributionPoints"></param> /// <param name="critical"></param> public CRLDistributionPointsExtension(CRLDistributionPoint[] distributionPoints, bool critical) { Oid = new Oid(Oid_CRLDistributionPoints, "CRL Distribution Points"); Critical = critical; RawData = DerConvert.Encode(new CRLDistributionPoints(distributionPoints)).ToArray(); _DistributionPoints = distributionPoints; _decoded = true; }
/// <summary> /// Used to create the extension from typed model /// </summary> /// <param name="accessDescritpions"></param> /// <param name="critical"></param> public AuthorityInformationAccessExtension(AccessDescription[] accessDescritpions, bool critical) { Oid = new Oid(Oid_AuthorityInformationAccess, "Authority Information Access"); Critical = critical; RawData = DerConvert.Encode(new AccessDescriptionList(accessDescritpions)).ToArray(); _AccessDescriptions = accessDescritpions; _decoded = true; }
public void Encode_NoDefaultEncoder_ShouldThrowArgumentNullException() { var typeMock = new Mock <DerAsnType>(DerAsnIdentifiers.Primitive.Boolean); DerConvert.DefaultEncoder = null; var ex = Assert.Throws <ArgumentNullException>(() => DerConvert.Encode(typeMock.Object)); Assert.That(ex.ParamName, Is.EqualTo("DefaultEncoder")); }
/// <summary> /// Used to create the extension from typed model /// </summary> /// <param name="issuerKeyIdentifier">The subject key identifier of the issuer certificate</param> /// <param name="critical"></param> public AuthorityKeyIdentifierExtension(byte[] issuerKeyIdentifier, bool critical) { Oid = new Oid(Oid_AuthorityKeyIdentifier, "Authority Key Identifier"); Critical = critical; RawData = DerConvert.Encode( new DerAsnSequence(new[] { new DerAsnOctetString(new DerAsnIdentifier(DerAsnTagClass.ContextSpecific, DerAsnEncodingType.Primitive, 0x0), issuerKeyIdentifier) })); _decoded = false; }
public void Encode_ShouldForwardCallToEncoder_ShouldDisposeEncoder() { var typeMock = new Mock <DerAsnType>(DerAsnIdentifiers.Primitive.Boolean); var encoderMock = new Mock <IDerAsnEncoder>(); DerConvert.DefaultEncoder = () => encoderMock.Object; DerConvert.Encode(typeMock.Object); encoderMock.Verify(x => x.Encode(typeMock.Object), Times.Once); encoderMock.Verify(x => x.Dispose(), Times.Once); }
/// <summary> /// Used to create the extension from typed model /// </summary> /// <param name="organizationIdentifier"></param> /// <param name="critical"></param> public CABForumOrganizationIdentifierExtension(CABForumOrganizationIdentifier organizationIdentifier, bool critical) { Oid = new Oid(Oid_CabForumOrganizationIdentifier, "CRL Distribution Points"); Critical = critical; var container = new DerAsnSequence(new DerAsnType[] { new DerAsnPrintableString(organizationIdentifier.SchemeIdentifier), new DerAsnPrintableString(organizationIdentifier.Country), new DerAsnUtf8String(organizationIdentifier.Reference), }); RawData = DerConvert.Encode(container).ToArray(); _OrganizationIdentifier = organizationIdentifier; _decoded = true; }
private void Write(DerAsnType der, PemFormat format) { var derBytes = DerConvert.Encode(der); var derBase64 = Convert.ToBase64String(derBytes); var pem = new StringBuilder(); pem.Append(format.Header + "\n"); for (var i = 0; i < derBase64.Length; i += _maximumLineLength) { pem.Append(derBase64.Substring(i, Math.Min(_maximumLineLength, derBase64.Length - i))); pem.Append("\n"); } pem.Append(format.Footer + "\n"); using (var writer = new StreamWriter(_stream, _encoding, 4096, true)) writer.Write(pem.ToString()); }
public void WritePublicKey(RSAParameters parameters) { var innerSequence = new DerAsnSequence(new DerAsnType[] { new DerAsnInteger(parameters.Modulus, true), new DerAsnInteger(parameters.Exponent, true) }); var outerSequence = new DerAsnSequence(new DerAsnType[] { new DerAsnSequence(new DerAsnType[] { new DerAsnObjectIdentifier("1.2.840.113549.1.1.1"), // rsaEncryption http://www.oid-info.com/get/1.2.840.113549.1.1.1 new DerAsnNull() }), new DerAsnBitString(DerConvert.Encode(innerSequence)) }); Write(outerSequence, PemFormat.Public); }
public void WritePublicKey(RSAParameters parameters) { var innerSequence = new DerAsnSequence(new DerAsnType[] { new DerAsnInteger(ToBigInteger(parameters.Modulus)), new DerAsnInteger(ToBigInteger(parameters.Exponent)) }); var innerSequenceData = DerConvert.Encode(innerSequence); var outerSequence = new DerAsnSequence(new DerAsnType[] { new DerAsnSequence(new DerAsnType[] { new DerAsnObjectIdentifier(1, 2, 840, 113549, 1, 1, 1), // rsaEncryption http://www.oid-info.com/get/1.2.840.113549.1.1.1 new DerAsnNull() }), new DerAsnBitString(ToBitArray(innerSequenceData)) }); Write(outerSequence, PemFormat.Public); }
public void Encode_NullAsAsnType_ShouldThrowArgumentNullException() { var ex = Assert.Throws <ArgumentNullException>(() => DerConvert.Encode(null)); Assert.That(ex.ParamName, Is.EqualTo("asnType")); }