List of usage examples for org.bouncycastle.asn1 DEROctetString toString
public String toString()
From source file:org.ejbca.core.protocol.MSPKCS10RequestMessage.java
License:Open Source License
/** * Returns a String vector with known subject altnames: * [0] Requested GUID//from w ww. ja v a2 s .c o m * [1] Requested DNS */ public String[] getMSRequestInfoSubjectAltnames() { String[] ret = new String[2]; // GUID, DNS so far.. if (pkcs10 == null) { log.error("PKCS10 not inited!"); return ret; } // Get attributes Attribute[] attributes = pkcs10.getAttributes(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest); if (attributes.length != 0) { ASN1Set set = attributes[0].getAttrValues(); DERSequence seq = (DERSequence) DERSequence.getInstance(set.getObjectAt(0)); Enumeration<?> enumeration = seq.getObjects(); while (enumeration.hasMoreElements()) { DERSequence seq2 = (DERSequence) DERSequence.getInstance(enumeration.nextElement()); ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) seq2.getObjectAt(0); if ("2.5.29.17".equals(oid.getId())) { //SubjectAN try { DEROctetString dos = (DEROctetString) seq2.getObjectAt(2); ASN1InputStream ais = new ASN1InputStream(new ByteArrayInputStream(dos.getOctets())); while (ais.available() > 0) { DERSequence seq3 = (DERSequence) ais.readObject(); Enumeration<?> enum1 = seq3.getObjects(); while (enum1.hasMoreElements()) { DERTaggedObject dto = (DERTaggedObject) enum1.nextElement(); if (dto.getTagNo() == 0) { // Sequence of OIDs and tagged objects DERSequence ds = (DERSequence) dto.getObject(); ASN1ObjectIdentifier doid = (ASN1ObjectIdentifier) ds.getObjectAt(0); if (OID_GUID.equals((doid).getId())) { DEROctetString dos3 = (DEROctetString) ((DERTaggedObject) ds.getObjectAt(1)) .getObject(); ret[0] = dos3.toString().substring(1); // Removes the initial #-sign } } else if (dto.getTagNo() == 2) { // DNS DEROctetString dos3 = (DEROctetString) dto.getObject(); ret[1] = new String(dos3.getOctets()); } } } ais.close(); } catch (IOException e) { log.error(e); } } } } return ret; }