List of usage examples for org.bouncycastle.asn1.x509 GeneralName toString
public String toString()
From source file:com.guardtime.asn1.TstInfo.java
License:Apache License
/** * Class constructor.//from w w w. j a v a 2s. c o m * * @param obj ASN.1 representation of TST info. * * @throws Asn1FormatException if provided ASN.1 object has invalid format. */ TstInfo(ASN1Encodable obj) throws Asn1FormatException { try { tstInfo = TSTInfo.getInstance(obj); // Extract and check version BigInteger ver = tstInfo.getVersion().getValue(); if (!ver.equals(BigInteger.valueOf(VERSION))) { throw new Asn1FormatException("invalid TST info version: " + ver); } version = ver.intValue(); // Extract policy policy = tstInfo.getPolicy().getId(); // Extract message imprint messageImprint = new MessageImprint(tstInfo.getMessageImprint().toASN1Primitive()); // Extract serial number // // As `DERInteger` can be constructed out of `ASN1OctetString` // without any error, here we have no option to determine // if the serial number is actually an INTEGER or OCTET STRING. // // Possible solutions is to rewrite BouncyCastle `TSTInfo` class // adding more strict checks. serialNumber = tstInfo.getSerialNumber().getValue(); // Extract request time // // Current BouncyCastle implementation can parse the time string // that does not omit trailing zeros in second fraction part. // RFC 3161 requires that such time string is labeled invalid. genTime = tstInfo.getGenTime().getDate(); // Extract optional fields ASN1Encodable acc = tstInfo.getAccuracy(); accuracy = ((acc == null) ? null : new Accuracy(acc.toASN1Primitive())); ASN1Boolean ord = tstInfo.getOrdering(); ordering = (ord != null && ord.isTrue()); ASN1Integer nnc = tstInfo.getNonce(); nonce = ((nnc == null) ? null : nnc.getValue()); GeneralName tsaName = tstInfo.getTsa(); tsa = ((tsaName == null) ? null : tsaName.toString()); Extensions exts = tstInfo.getExtensions(); if (exts != null) { // check for critical extensions Asn1Util.checkExtensions(exts); extensions = exts.getEncoded(ASN1Encoding.DER); } } catch (Asn1FormatException e) { throw e; } catch (Exception e) { throw new Asn1FormatException("TST info has invalid format", e); } }
From source file:de.thiemann.ssl.report.model.CertificateV3.java
License:Open Source License
private List<String> transferDistributionPoints(byte[] extension) { if (extension == null) return null; ASN1Sequence crlDistributionPoints = null; try {/*from ww w . j ava 2s . c o m*/ ASN1Object o = null; o = (DEROctetString) ASN1Object.fromByteArray(extension); if (o instanceof DEROctetString) { DEROctetString octStr = (DEROctetString) o; o = ASN1Object.fromByteArray(octStr.getOctets()); if (o instanceof ASN1Sequence) { crlDistributionPoints = (ASN1Sequence) o; } } } catch (IOException e) { e.printStackTrace(); } if (crlDistributionPoints == null) return null; List<String> l = new ArrayList<String>(); Enumeration<?> e = crlDistributionPoints.getObjects(); while (e.hasMoreElements()) { Object o = e.nextElement(); if (o instanceof ASN1Sequence) { ASN1Sequence seqDP = (ASN1Sequence) o; DistributionPoint dp = new DistributionPoint(seqDP); DistributionPointName dpn = dp.getDistributionPoint(); ASN1Encodable enc = dpn.getName(); if (enc instanceof GeneralNames) { GeneralNames gns = (GeneralNames) enc; for (GeneralName gn : gns.getNames()) { l.add(gn.toString()); } } } } if (!l.isEmpty()) return l; else return null; }