private string GetAccessLocation(X509Certificate certificate, DerObjectIdentifier accessMethod) { Asn1OctetString authInfoAccessExtensionValue = certificate.GetExtensionValue(X509Extensions .AuthorityInfoAccess); if (null == authInfoAccessExtensionValue) { return(null); } AuthorityInformationAccess authorityInformationAccess = AuthorityInformationAccess.GetInstance(authInfoAccessExtensionValue.GetOctets()); AccessDescription[] accessDescriptions = authorityInformationAccess.GetAccessDescriptions(); foreach (AccessDescription accessDescription in accessDescriptions) { logger.Info("access method: " + accessDescription.AccessMethod); bool correctAccessMethod = accessDescription.AccessMethod.Equals(accessMethod); if (!correctAccessMethod) { continue; } GeneralName gn = accessDescription.AccessLocation; if (gn.TagNo != GeneralName.UniformResourceIdentifier) { logger.Info("not a uniform resource identifier"); continue; } DerIA5String str = (DerIA5String)((DerTaggedObject)gn.ToAsn1Object()).GetObject(); string accessLocation = str.GetString(); logger.Info("access location: " + accessLocation); return(accessLocation); } return(null); }
private string GetAccessLocation(X509Certificate certificate, DerObjectIdentifier accessMethod) { try { //byte[] authInfoAccessExtensionValue = certificate.GetExtensionValue(X509Extensions // .AuthorityInfoAccess); Asn1OctetString authInfoAccessExtensionValue = certificate.GetExtensionValue(X509Extensions .AuthorityInfoAccess); if (null == authInfoAccessExtensionValue) { return(null); } AuthorityInformationAccess authorityInformationAccess; //DerOctetString oct = (DerOctetString)(new Asn1InputStream(new MemoryStream // (authInfoAccessExtensionValue)).ReadObject()); DerOctetString oct = (DerOctetString)authInfoAccessExtensionValue; //authorityInformationAccess = new AuthorityInformationAccess((Asn1Sequence)new Asn1InputStream // (oct.GetOctets()).ReadObject()); authorityInformationAccess = AuthorityInformationAccess.GetInstance(oct); AccessDescription[] accessDescriptions = authorityInformationAccess.GetAccessDescriptions (); foreach (AccessDescription accessDescription in accessDescriptions) { LOG.Info("access method: " + accessDescription.AccessMethod); bool correctAccessMethod = accessDescription.AccessMethod.Equals(accessMethod ); if (!correctAccessMethod) { continue; } GeneralName gn = accessDescription.AccessLocation; if (gn.TagNo != GeneralName.UniformResourceIdentifier) { LOG.Info("not a uniform resource identifier"); continue; } DerIA5String str = (DerIA5String)((DerTaggedObject)gn.ToAsn1Object()).GetObject(); string accessLocation = str.GetString(); LOG.Info("access location: " + accessLocation); return(accessLocation); } return(null); } catch (IOException e) { throw new RuntimeException("IO error: " + e.Message, e); } }