/// <summary> /// Gets the subject email address of the certificate. /// </summary> /// <remarks> /// The email address component of the certificate's Subject identifier is /// sometimes used as a way of looking up certificates for a particular /// user if a fingerprint is not available. /// </remarks> /// <returns>The subject email address.</returns> /// <param name="certificate">The certificate.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="certificate"/> is <c>null</c>. /// </exception> public static string GetSubjectEmailAddress(this X509Certificate certificate) { var address = certificate.GetSubjectNameInfo(X509Name.EmailAddress); if (address != null) { return(address); } var alt = certificate.GetExtensionValue(X509Extensions.SubjectAlternativeName); if (alt == null) { return(null); } var seq = DerSequence.GetInstance(Asn1Object.FromByteArray(alt.GetOctets())); foreach (Asn1Encodable encodable in seq) { var name = GeneralName.GetInstance(encodable); if (name.TagNo == GeneralName.Rfc822Name) { return(((IAsn1String)name.Name).GetString()); } } return(null); }
private static ICollection GetAlternativeName( Asn1OctetString extVal) { IList temp = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(); if (extVal != null) { try { Asn1Sequence seq = DerSequence.GetInstance(FromExtensionValue(extVal)); foreach (Asn1Encodable primName in seq) { IList list = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateArrayList(); GeneralName genName = GeneralName.GetInstance(primName); list.Add(genName.TagNo); switch (genName.TagNo) { case GeneralName.EdiPartyName: case GeneralName.X400Address: case GeneralName.OtherName: list.Add(genName.Name.ToAsn1Object()); break; case GeneralName.DirectoryName: list.Add(X509Name.GetInstance(genName.Name).ToString()); break; case GeneralName.DnsName: case GeneralName.Rfc822Name: case GeneralName.UniformResourceIdentifier: list.Add(((IAsn1String)genName.Name).GetString()); break; case GeneralName.RegisteredID: list.Add(DerObjectIdentifier.GetInstance(genName.Name).Id); break; case GeneralName.IPAddress: list.Add(DerOctetString.GetInstance(genName.Name).GetOctets()); break; default: throw new IOException("Bad tag number: " + genName.TagNo); } temp.Add(list); } } catch (Exception e) { throw new CertificateParsingException(e.Message); } } return(temp); }
public static byte[] decodeDERSM2Cipher(byte[] derCipher) { Asn1Sequence ds = DerSequence.GetInstance(derCipher); byte[] c1x = ((DerInteger)ds[0]).Value.ToByteArray(); byte[] c1y = ((DerInteger)ds[1]).Value.ToByteArray(); byte[] c3 = ((DerOctetString)ds[2]).GetOctets(); byte[] c2 = ((DerOctetString)ds[3]).GetOctets(); int pos = 0; int cureLength = 32; byte[] cipherText = new byte[1 + c2.Length + cureLength * 2 + c3.Length]; byte uncompressedFlag = 0x04; cipherText[0] = uncompressedFlag; pos += 1; if (c1x.Length >= cureLength) { Buffer.BlockCopy(c1x, c1x.Length - cureLength, cipherText, pos, cureLength); } else { Buffer.BlockCopy(c1x, 0, cipherText, pos + cureLength - c1x.Length, c1x.Length); } pos += cureLength; if (c1y.Length >= cureLength) { Buffer.BlockCopy(c1y, c1y.Length - cureLength, cipherText, pos, cureLength); } else { Buffer.BlockCopy(c1y, 0, cipherText, pos + cureLength - c1y.Length, c1y.Length); } pos += cureLength; Buffer.BlockCopy(c2, 0, cipherText, pos, c2.Length); pos += c2.Length; Buffer.BlockCopy(c3, 0, cipherText, pos, c3.Length); return(cipherText); }
/** * Constructor from Asn1Sequence. * <p/> * The sequence is of type ProcurationSyntax: * <p/> * <pre> * AdmissionSyntax ::= SEQUENCE * { * admissionAuthority GeneralName OPTIONAL, * contentsOfAdmissions SEQUENCE OF Admissions * } * <p/> * Admissions ::= SEQUENCE * { * admissionAuthority [0] EXPLICIT GeneralName OPTIONAL * namingAuthority [1] EXPLICIT NamingAuthority OPTIONAL * professionInfos SEQUENCE OF ProfessionInfo * } * <p/> * NamingAuthority ::= SEQUENCE * { * namingAuthorityId OBJECT IDENTIFIER OPTIONAL, * namingAuthorityUrl IA5String OPTIONAL, * namingAuthorityText DirectoryString(SIZE(1..128)) OPTIONAL * } * <p/> * ProfessionInfo ::= SEQUENCE * { * namingAuthority [0] EXPLICIT NamingAuthority OPTIONAL, * professionItems SEQUENCE OF DirectoryString (SIZE(1..128)), * professionOIDs SEQUENCE OF OBJECT IDENTIFIER OPTIONAL, * registrationNumber PrintableString(SIZE(1..128)) OPTIONAL, * addProfessionInfo OCTET STRING OPTIONAL * } * </pre> * * @param seq The ASN.1 sequence. */ private AdmissionSyntax( Asn1Sequence seq) { switch (seq.Count) { case 1: this.contentsOfAdmissions = DerSequence.GetInstance(seq[0]); break; case 2: admissionAuthority = GeneralName.GetInstance(seq[0]); contentsOfAdmissions = DerSequence.GetInstance(seq[1]); break; default: throw new ArgumentException("Bad sequence size: " + seq.Count); } }
internal static void PrepareNextCertB1( int i, IList[] policyNodes, string id_p, IDictionary m_idp, X509Certificate cert) { bool idp_found = false; IEnumerator nodes_i = policyNodes[i].GetEnumerator(); while (nodes_i.MoveNext()) { PkixPolicyNode node = (PkixPolicyNode)nodes_i.Current; if (node.ValidPolicy.Equals(id_p)) { idp_found = true; node.ExpectedPolicies = (ISet)m_idp[id_p]; break; } } if (!idp_found) { nodes_i = policyNodes[i].GetEnumerator(); while (nodes_i.MoveNext()) { PkixPolicyNode node = (PkixPolicyNode)nodes_i.Current; if (ANY_POLICY.Equals(node.ValidPolicy)) { ISet pq = null; Asn1Sequence policies = null; try { policies = DerSequence.GetInstance(GetExtensionValue(cert, X509Extensions.CertificatePolicies)); } catch (Exception e) { throw new Exception("Certificate policies cannot be decoded.", e); } IEnumerator enm = policies.GetEnumerator(); while (enm.MoveNext()) { PolicyInformation pinfo = null; try { pinfo = PolicyInformation.GetInstance(enm.Current); } catch (Exception ex) { throw new Exception("Policy information cannot be decoded.", ex); } if (ANY_POLICY.Equals(pinfo.PolicyIdentifier.Id)) { try { pq = GetQualifierSet(pinfo.PolicyQualifiers); } catch (PkixCertPathValidatorException ex) { throw new PkixCertPathValidatorException( "Policy qualifier info set could not be built.", ex); } break; } } bool ci = false; ISet critExtOids = cert.GetCriticalExtensionOids(); if (critExtOids != null) { ci = critExtOids.Contains(X509Extensions.CertificatePolicies.Id); } PkixPolicyNode p_node = (PkixPolicyNode)node.Parent; if (ANY_POLICY.Equals(p_node.ValidPolicy)) { PkixPolicyNode c_node = new PkixPolicyNode( Platform.CreateArrayList(), i, (ISet)m_idp[id_p], p_node, pq, id_p, ci); p_node.AddChild(c_node); policyNodes[i].Add(c_node); } break; } } } }