private Set < String > getOcspUrls ( Certificate bcCert ) { TBSCertificate bcTbsCert = bcCert . getTBSCertificate ( ) ; Extensions bcExts = bcTbsCert . getExtensions ( ) ; if ( bcExts == null ) { throw new RuntimeException ( "Failed to get Tbs Certificate." ) ; } Set < String > ocsp = new HashSet <> ( ) ; for ( Enumeration en = bcExts . oids ( ) ; en . hasMoreElements ( ) ; ) { ASN1ObjectIdentifier oid = ( ASN1ObjectIdentifier ) en . nextElement ( ) ; Extension bcExt = bcExts . getExtension ( oid ) ; if ( bcExt . getExtnId ( ) == Extension . authorityInfoAccess ) { // OCSP URLS are included in authorityInfoAccess DLSequence seq = ( DLSequence ) bcExt . getParsedValue ( ) ; for ( ASN1Encodable asn : seq ) { ASN1Encodable [ ] pairOfAsn = ( ( DLSequence ) asn ) . toArray ( ) ; if ( pairOfAsn . length == 2 ) { ASN1ObjectIdentifier key = ( ASN1ObjectIdentifier ) pairOfAsn [ 0 ] ; if ( key == OIDocsp ) { // ensure OCSP and not CRL GeneralName gn = GeneralName . getInstance ( pairOfAsn [ 1 ] ) ; ocsp . add ( gn . getName ( ) . toString ( ) ) ; } } } } } return ocsp ; }
Gets OCSP URLs associated with the certificate .