List of usage examples for org.bouncycastle.asn1 DERIA5String getString
public String getString()
From source file:eu.europa.esig.dss.client.ocsp.OnlineOCSPSource.java
License:Open Source License
/** * Gives back the OCSP URI meta-data found within the given X509 cert. * * @param certificate/*from w w w . j av a 2s . c o m*/ * the cert token. * @return the OCSP URI, or <code>null</code> if the extension is not present. * @throws DSSException */ public String getAccessLocation(final CertificateToken certificate) throws DSSException { final byte[] authInfoAccessExtensionValue = certificate.getCertificate() .getExtensionValue(Extension.authorityInfoAccess.getId()); if (ArrayUtils.isEmpty(authInfoAccessExtensionValue)) { return null; } ASN1InputStream ais1 = null; ASN1InputStream ais2 = null; try { ais1 = new ASN1InputStream(authInfoAccessExtensionValue); final DEROctetString oct = (DEROctetString) (ais1.readObject()); ais2 = new ASN1InputStream(oct.getOctets()); final AuthorityInformationAccess authorityInformationAccess = AuthorityInformationAccess .getInstance(ais2.readObject()); final AccessDescription[] accessDescriptions = authorityInformationAccess.getAccessDescriptions(); for (AccessDescription accessDescription : accessDescriptions) { if (logger.isDebugEnabled()) { logger.debug("Access method OID : " + accessDescription.getAccessMethod()); } final boolean correctAccessMethod = X509ObjectIdentifiers.ocspAccessMethod .equals(accessDescription.getAccessMethod()); if (!correctAccessMethod) { continue; } final GeneralName gn = accessDescription.getAccessLocation(); if (gn.getTagNo() != GeneralName.uniformResourceIdentifier) { if (logger.isDebugEnabled()) { logger.debug("Not a uniform resource identifier"); } continue; } final DERIA5String str = (DERIA5String) ((DERTaggedObject) gn.toASN1Primitive()).getObject(); final String accessLocation = str.getString(); if (logger.isDebugEnabled()) { logger.debug("Access location: " + accessLocation); } return accessLocation; } return null; } catch (IOException e) { throw new DSSException(e); } finally { IOUtils.closeQuietly(ais1); IOUtils.closeQuietly(ais2); } }
From source file:eu.europa.esig.dss.DSSASN1Utils.java
License:Open Source License
public static List<String> getAccessLocations(final CertificateToken certificate) { final byte[] authInfoAccessExtensionValue = certificate.getCertificate() .getExtensionValue(Extension.authorityInfoAccess.getId()); if (null == authInfoAccessExtensionValue) { return null; }//w w w . java 2 s. c o m // Parse the extension ASN1Sequence asn1Sequence = null; try { asn1Sequence = DSSASN1Utils.getAsn1SequenceFromDerOctetString(authInfoAccessExtensionValue); } catch (DSSException e) { return null; } AuthorityInformationAccess authorityInformationAccess = AuthorityInformationAccess .getInstance(asn1Sequence); AccessDescription[] accessDescriptions = authorityInformationAccess.getAccessDescriptions(); List<String> locationsUrls = new ArrayList<String>(); for (AccessDescription accessDescription : accessDescriptions) { if (X509ObjectIdentifiers.id_ad_caIssuers.equals(accessDescription.getAccessMethod())) { GeneralName gn = accessDescription.getAccessLocation(); if (GeneralName.uniformResourceIdentifier == gn.getTagNo()) { DERIA5String str = (DERIA5String) ((DERTaggedObject) gn.toASN1Primitive()).getObject(); locationsUrls.add(str.getString()); } } } return locationsUrls; }
From source file:net.ripe.rpki.commons.crypto.cms.manifest.ManifestCmsParser.java
License:BSD License
void decodeFileAndHash(Map<String, byte[]> result, ASN1Encodable encoded) { ASN1Sequence seq = expect(encoded, ASN1Sequence.class); Validate.isTrue(seq.size() == 2, "der sequence does not contain file and hash"); DERIA5String derFile = expect(seq.getObjectAt(0), DERIA5String.class); DERBitString derHash = expect(seq.getObjectAt(1), DERBitString.class); result.put(derFile.getString(), derHash.getBytes()); }
From source file:net.ripe.rpki.commons.crypto.x509cert.X509CertificateUtil.java
License:BSD License
private static URI[] convertCrlDistributionPointToUris(CRLDistPoint crldp) { List<URI> result = new ArrayList<URI>(); for (DistributionPoint dp : crldp.getDistributionPoints()) { GeneralNames names = (GeneralNames) dp.getDistributionPoint().getName(); for (GeneralName name : names.getNames()) { DERIA5String uri = (DERIA5String) name.getName(); result.add(URI.create(uri.getString())); }//from w w w. ja v a2 s .co m } return result.toArray(new URI[result.size()]); }
From source file:net.ripe.rpki.commons.crypto.x509cert.X509ResourceCertificateParser.java
License:BSD License
private void testCrlDistributionPointsToUrisConversion(CRLDistPoint crldp) { for (DistributionPoint dp : crldp.getDistributionPoints()) { result.rejectIfNotNull(dp.getCRLIssuer(), CRLDP_ISSUER_OMITTED); result.rejectIfNotNull(dp.getReasons(), CRLDP_REASONS_OMITTED); if (!result.rejectIfNull(dp.getDistributionPoint(), CRLDP_PRESENT)) { return; }//from w w w. ja va 2s . c o m if (!result.rejectIfFalse(dp.getDistributionPoint().getType() == DistributionPointName.FULL_NAME, CRLDP_TYPE_FULL_NAME)) { return; } GeneralNames names = (GeneralNames) dp.getDistributionPoint().getName(); for (GeneralName name : names.getNames()) { if (!result.rejectIfFalse(name.getTagNo() == GeneralName.uniformResourceIdentifier, CRLDP_NAME_IS_A_URI)) { return; } DERIA5String uri = (DERIA5String) name.getName(); try { URI.create(uri.getString()); } catch (IllegalArgumentException e) { result.error(CRLDP_URI_SYNTAX); return; } } } }
From source file:net.sabamiso.android.revocationtest.crl.RevocationTestUsingCRL.java
License:MIT License
private static String getCRLUrl(X509Certificate cert) { byte[] asn1_bytes = cert.getExtensionValue("2.5.29.31"); // CRL Distribution Points OID:"2.5.29.31" if (asn1_bytes == null) { Log.e(TAG, "cannot find 2.5.29.31..."); return null; }/*from ww w. j a v a 2s .co m*/ CRLDistPoint crldp = getCRLDistPoint(asn1_bytes); if (crldp == null) { Log.e(TAG, "cannot find CRLDistPoint..."); return null; } String url = null; for (DistributionPoint dp : crldp.getDistributionPoints()) { DistributionPointName dpn = dp.getDistributionPoint(); if (DistributionPointName.FULL_NAME != dpn.getType()) continue; GeneralNames gns = (GeneralNames) dpn.getName(); for (GeneralName gn : gns.getNames()) { if (gn.getTagNo() != GeneralName.uniformResourceIdentifier) { continue; } DERIA5String der_str = DERIA5String.getInstance((ASN1TaggedObject) gn.toASN1Primitive(), false); url = der_str.getString(); Log.d(TAG, "url=" + url); } } return url; }
From source file:net.sf.keystore_explorer.crypto.csr.spkac.Spkac.java
License:Open Source License
private void decodeSpkac(byte[] der) throws SpkacException { try {/* ww w . j a v a2s. c om*/ ASN1Sequence signedPublicKeyAndChallenge = ASN1Sequence.getInstance(der); ASN1Sequence publicKeyAndChallenge = (ASN1Sequence) signedPublicKeyAndChallenge.getObjectAt(0); ASN1Sequence signatureAlgorithm = (ASN1Sequence) signedPublicKeyAndChallenge.getObjectAt(1); DERBitString signature = (DERBitString) signedPublicKeyAndChallenge.getObjectAt(2); ASN1ObjectIdentifier signatureAlgorithmOid = (ASN1ObjectIdentifier) signatureAlgorithm.getObjectAt(0); ASN1Sequence spki = (ASN1Sequence) publicKeyAndChallenge.getObjectAt(0); DERIA5String challenge = (DERIA5String) publicKeyAndChallenge.getObjectAt(1); ASN1Sequence publicKeyAlgorithm = (ASN1Sequence) spki.getObjectAt(0); DERBitString publicKey = (DERBitString) spki.getObjectAt(1); ASN1ObjectIdentifier publicKeyAlgorithmOid = (ASN1ObjectIdentifier) publicKeyAlgorithm.getObjectAt(0); ASN1Primitive algorithmParameters = publicKeyAlgorithm.getObjectAt(1).toASN1Primitive(); this.challenge = challenge.getString(); this.publicKey = decodePublicKeyFromBitString(publicKeyAlgorithmOid, algorithmParameters, publicKey); this.signatureAlgorithm = getSignatureAlgorithm(signatureAlgorithmOid); this.signature = signature.getBytes(); } catch (Exception ex) { throw new SpkacException(res.getString("NoDecodeSpkac.exception.message"), ex); } }
From source file:net.sf.keystore_explorer.crypto.x509.GeneralNameUtil.java
License:Open Source License
/** * Get string representation for General names that cannot cause a * IOException to be thrown. Unsupported are ediPartyName, otherName and * x400Address. Returns a blank string for these. * * @param generalName//from w ww . j ava 2s. c om * General name * @param addLinkForURI * If true, convert URI to a clickable link * @return String representation of general name */ public static String safeToString(GeneralName generalName, boolean addLinkForURI) { if (generalName == null) { return ""; } switch (generalName.getTagNo()) { case GeneralName.directoryName: { X500Name directoryName = (X500Name) generalName.getName(); return MessageFormat.format(res.getString("GeneralNameUtil.DirectoryGeneralName"), directoryName.toString()); } case GeneralName.dNSName: { DERIA5String dnsName = (DERIA5String) generalName.getName(); return MessageFormat.format(res.getString("GeneralNameUtil.DnsGeneralName"), dnsName.getString()); } case GeneralName.iPAddress: { byte[] ipAddressBytes = ((ASN1OctetString) generalName.getName()).getOctets(); String ipAddressString = ""; try { ipAddressString = InetAddress.getByAddress(ipAddressBytes).getHostAddress(); } catch (UnknownHostException e) { // ignore -> results in empty IP address string } return MessageFormat.format(res.getString("GeneralNameUtil.IpAddressGeneralName"), ipAddressString); } case GeneralName.registeredID: { ASN1ObjectIdentifier registeredId = (ASN1ObjectIdentifier) generalName.getName(); return MessageFormat.format(res.getString("GeneralNameUtil.RegisteredIdGeneralName"), ObjectIdUtil.toString(registeredId)); } case GeneralName.rfc822Name: { DERIA5String rfc822Name = (DERIA5String) generalName.getName(); return MessageFormat.format(res.getString("GeneralNameUtil.Rfc822GeneralName"), rfc822Name.getString()); } case GeneralName.uniformResourceIdentifier: { DERIA5String uri = (DERIA5String) generalName.getName(); String link = addLinkForURI ? "<html><a href=\"" + uri.getString() + "\">" + uri.getString() + "</a></html>" : uri.getString(); return MessageFormat.format(res.getString("GeneralNameUtil.UriGeneralName"), link); } case GeneralName.otherName: { // we currently only support UPN in otherName String upn = parseUPN(generalName); return MessageFormat.format(res.getString("GeneralNameUtil.OtherGeneralName"), "UPN", upn); } default: { return ""; } } }
From source file:net.sf.keystore_explorer.crypto.x509.X509Ext.java
License:Open Source License
private String getNetscapeBaseUrlStringValue(byte[] value) throws IOException { // @formatter:off /* NetscapeBaseUrl ::= DERIA5String */ // @formatter:on StringBuilder sb = new StringBuilder(); DERIA5String netscapeBaseUrl = DERIA5String.getInstance(value); sb.append(netscapeBaseUrl.getString()); sb.append(NEWLINE);//from w w w . ja v a 2s. co m return sb.toString(); }
From source file:net.sf.keystore_explorer.crypto.x509.X509Ext.java
License:Open Source License
private String getNetscapeRevocationUrlStringValue(byte[] value) throws IOException { // @formatter:off /* NetscapeRevocationUrl ::= DERIA5String */ // @formatter:on StringBuilder sb = new StringBuilder(); DERIA5String netscapeRevocationUrl = DERIA5String.getInstance(value); sb.append(netscapeRevocationUrl.getString()); sb.append(NEWLINE);//from ww w .ja v a 2 s .c o m return sb.toString(); }