use of com.mindbright.asn1.ASN1IA5String in project LinLong-Java by zhenwei1108.
the class ASN1Dump method _dumpAsString.
/**
* dump a DER object as a formatted string with indentation
*
* @param obj the ASN1Primitive to be dumped out.
*/
static void _dumpAsString(String indent, boolean verbose, ASN1Primitive obj, StringBuffer buf) {
String nl = Strings.lineSeparator();
if (obj instanceof ASN1Null) {
buf.append(indent);
buf.append("NULL");
buf.append(nl);
} else if (obj instanceof ASN1Sequence) {
buf.append(indent);
if (obj instanceof BERSequence) {
buf.append("BER Sequence");
} else if (obj instanceof DERSequence) {
buf.append("DER Sequence");
} else {
buf.append("Sequence");
}
buf.append(nl);
ASN1Sequence sequence = (ASN1Sequence) obj;
String elementsIndent = indent + TAB;
for (int i = 0, count = sequence.size(); i < count; ++i) {
_dumpAsString(elementsIndent, verbose, sequence.getObjectAt(i).toASN1Primitive(), buf);
}
} else if (obj instanceof ASN1Set) {
buf.append(indent);
if (obj instanceof BERSet) {
buf.append("BER Set");
} else if (obj instanceof DERSet) {
buf.append("DER Set");
} else {
buf.append("Set");
}
buf.append(nl);
ASN1Set set = (ASN1Set) obj;
String elementsIndent = indent + TAB;
for (int i = 0, count = set.size(); i < count; ++i) {
_dumpAsString(elementsIndent, verbose, set.getObjectAt(i).toASN1Primitive(), buf);
}
} else if (obj instanceof ASN1ApplicationSpecific) {
_dumpAsString(indent, verbose, ((ASN1ApplicationSpecific) obj).getTaggedObject(), buf);
} else if (obj instanceof ASN1TaggedObject) {
buf.append(indent);
if (obj instanceof BERTaggedObject) {
buf.append("BER Tagged ");
} else if (obj instanceof DERTaggedObject) {
buf.append("DER Tagged ");
} else {
buf.append("Tagged ");
}
ASN1TaggedObject o = (ASN1TaggedObject) obj;
buf.append(ASN1Util.getTagText(o));
if (!o.isExplicit()) {
buf.append(" IMPLICIT ");
}
buf.append(nl);
String baseIndent = indent + TAB;
_dumpAsString(baseIndent, verbose, o.getBaseObject().toASN1Primitive(), buf);
} else if (obj instanceof ASN1OctetString) {
ASN1OctetString oct = (ASN1OctetString) obj;
if (obj instanceof BEROctetString) {
buf.append(indent + "BER Constructed Octet String" + "[" + oct.getOctets().length + "] ");
} else {
buf.append(indent + "DER Octet String" + "[" + oct.getOctets().length + "] ");
}
if (verbose) {
buf.append(dumpBinaryDataAsString(indent, oct.getOctets()));
} else {
buf.append(nl);
}
} else if (obj instanceof ASN1ObjectIdentifier) {
buf.append(indent + "ObjectIdentifier(" + ((ASN1ObjectIdentifier) obj).getId() + ")" + nl);
} else if (obj instanceof ASN1RelativeOID) {
buf.append(indent + "RelativeOID(" + ((ASN1RelativeOID) obj).getId() + ")" + nl);
} else if (obj instanceof ASN1Boolean) {
buf.append(indent + "Boolean(" + ((ASN1Boolean) obj).isTrue() + ")" + nl);
} else if (obj instanceof ASN1Integer) {
buf.append(indent + "Integer(" + ((ASN1Integer) obj).getValue() + ")" + nl);
} else if (obj instanceof ASN1BitString) {
ASN1BitString bitString = (ASN1BitString) obj;
byte[] bytes = bitString.getBytes();
int padBits = bitString.getPadBits();
if (bitString instanceof DERBitString) {
buf.append(indent + "DER Bit String" + "[" + bytes.length + ", " + padBits + "] ");
} else if (bitString instanceof DLBitString) {
buf.append(indent + "DL Bit String" + "[" + bytes.length + ", " + padBits + "] ");
} else {
buf.append(indent + "BER Bit String" + "[" + bytes.length + ", " + padBits + "] ");
}
if (verbose) {
buf.append(dumpBinaryDataAsString(indent, bytes));
} else {
buf.append(nl);
}
} else if (obj instanceof ASN1IA5String) {
buf.append(indent + "IA5String(" + ((ASN1IA5String) obj).getString() + ") " + nl);
} else if (obj instanceof ASN1UTF8String) {
buf.append(indent + "UTF8String(" + ((ASN1UTF8String) obj).getString() + ") " + nl);
} else if (obj instanceof ASN1NumericString) {
buf.append(indent + "NumericString(" + ((ASN1NumericString) obj).getString() + ") " + nl);
} else if (obj instanceof ASN1PrintableString) {
buf.append(indent + "PrintableString(" + ((ASN1PrintableString) obj).getString() + ") " + nl);
} else if (obj instanceof ASN1VisibleString) {
buf.append(indent + "VisibleString(" + ((ASN1VisibleString) obj).getString() + ") " + nl);
} else if (obj instanceof ASN1BMPString) {
buf.append(indent + "BMPString(" + ((ASN1BMPString) obj).getString() + ") " + nl);
} else if (obj instanceof ASN1T61String) {
buf.append(indent + "T61String(" + ((ASN1T61String) obj).getString() + ") " + nl);
} else if (obj instanceof ASN1GraphicString) {
buf.append(indent + "GraphicString(" + ((ASN1GraphicString) obj).getString() + ") " + nl);
} else if (obj instanceof ASN1VideotexString) {
buf.append(indent + "VideotexString(" + ((ASN1VideotexString) obj).getString() + ") " + nl);
} else if (obj instanceof ASN1UTCTime) {
buf.append(indent + "UTCTime(" + ((ASN1UTCTime) obj).getTime() + ") " + nl);
} else if (obj instanceof ASN1GeneralizedTime) {
buf.append(indent + "GeneralizedTime(" + ((ASN1GeneralizedTime) obj).getTime() + ") " + nl);
} else if (obj instanceof ASN1Enumerated) {
ASN1Enumerated en = (ASN1Enumerated) obj;
buf.append(indent + "DER Enumerated(" + en.getValue() + ")" + nl);
} else if (obj instanceof ASN1ObjectDescriptor) {
ASN1ObjectDescriptor od = (ASN1ObjectDescriptor) obj;
buf.append(indent + "ObjectDescriptor(" + od.getBaseGraphicString().getString() + ") " + nl);
} else if (obj instanceof ASN1External) {
ASN1External ext = (ASN1External) obj;
buf.append(indent + "External " + nl);
String tab = indent + TAB;
if (ext.getDirectReference() != null) {
buf.append(tab + "Direct Reference: " + ext.getDirectReference().getId() + nl);
}
if (ext.getIndirectReference() != null) {
buf.append(tab + "Indirect Reference: " + ext.getIndirectReference().toString() + nl);
}
if (ext.getDataValueDescriptor() != null) {
_dumpAsString(tab, verbose, ext.getDataValueDescriptor(), buf);
}
buf.append(tab + "Encoding: " + ext.getEncoding() + nl);
_dumpAsString(tab, verbose, ext.getExternalContent(), buf);
} else {
buf.append(indent + obj.toString() + nl);
}
}
use of com.mindbright.asn1.ASN1IA5String in project LinLong-Java by zhenwei1108.
the class PKIXCertPathReviewer method getCRLDistUrls.
protected Vector getCRLDistUrls(CRLDistPoint crlDistPoints) {
Vector urls = new Vector();
if (crlDistPoints != null) {
DistributionPoint[] distPoints = crlDistPoints.getDistributionPoints();
for (int i = 0; i < distPoints.length; i++) {
DistributionPointName dp_name = distPoints[i].getDistributionPoint();
if (dp_name.getType() == DistributionPointName.FULL_NAME) {
GeneralName[] generalNames = GeneralNames.getInstance(dp_name.getName()).getNames();
for (int j = 0; j < generalNames.length; j++) {
if (generalNames[j].getTagNo() == GeneralName.uniformResourceIdentifier) {
String url = ((ASN1IA5String) generalNames[j].getName()).getString();
urls.add(url);
}
}
}
}
}
return urls;
}
use of com.mindbright.asn1.ASN1IA5String in project LinLong-Java by zhenwei1108.
the class PKIXCertPathReviewer method getOCSPUrls.
protected Vector getOCSPUrls(AuthorityInformationAccess authInfoAccess) {
Vector urls = new Vector();
if (authInfoAccess != null) {
AccessDescription[] ads = authInfoAccess.getAccessDescriptions();
for (int i = 0; i < ads.length; i++) {
if (ads[i].getAccessMethod().equals(AccessDescription.id_ad_ocsp)) {
GeneralName name = ads[i].getAccessLocation();
if (name.getTagNo() == GeneralName.uniformResourceIdentifier) {
String url = ((ASN1IA5String) name.getName()).getString();
urls.add(url);
}
}
}
}
return urls;
}
use of com.mindbright.asn1.ASN1IA5String in project LinLong-Java by zhenwei1108.
the class X509CertificateObject method toString.
public String toString() {
StringBuffer buf = new StringBuffer();
String nl = Strings.lineSeparator();
buf.append(" [0] Version: ").append(this.getVersion()).append(nl);
buf.append(" SerialNumber: ").append(this.getSerialNumber()).append(nl);
buf.append(" IssuerDN: ").append(this.getIssuerDN()).append(nl);
buf.append(" Start Date: ").append(this.getNotBefore()).append(nl);
buf.append(" Final Date: ").append(this.getNotAfter()).append(nl);
buf.append(" SubjectDN: ").append(this.getSubjectDN()).append(nl);
buf.append(" Public Key: ").append(this.getPublicKey()).append(nl);
buf.append(" Signature Algorithm: ").append(this.getSigAlgName()).append(nl);
byte[] sig = this.getSignature();
buf.append(" Signature: ").append(new String(Hex.encode(sig, 0, 20))).append(nl);
for (int i = 20; i < sig.length; i += 20) {
if (i < sig.length - 20) {
buf.append(" ").append(new String(Hex.encode(sig, i, 20))).append(nl);
} else {
buf.append(" ").append(new String(Hex.encode(sig, i, sig.length - i))).append(nl);
}
}
Extensions extensions = c.getTBSCertificate().getExtensions();
if (extensions != null) {
Enumeration e = extensions.oids();
if (e.hasMoreElements()) {
buf.append(" Extensions: \n");
}
while (e.hasMoreElements()) {
ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) e.nextElement();
Extension ext = extensions.getExtension(oid);
if (ext.getExtnValue() != null) {
byte[] octs = ext.getExtnValue().getOctets();
ASN1InputStream dIn = new ASN1InputStream(octs);
buf.append(" critical(").append(ext.isCritical()).append(") ");
try {
if (oid.equals(Extension.basicConstraints)) {
buf.append(BasicConstraints.getInstance(dIn.readObject())).append(nl);
} else if (oid.equals(Extension.keyUsage)) {
buf.append(KeyUsage.getInstance(dIn.readObject())).append(nl);
} else if (oid.equals(MiscObjectIdentifiers.netscapeCertType)) {
buf.append(new NetscapeCertType((DERBitString) dIn.readObject())).append(nl);
} else if (oid.equals(MiscObjectIdentifiers.netscapeRevocationURL)) {
buf.append(new NetscapeRevocationURL((ASN1IA5String) dIn.readObject())).append(nl);
} else if (oid.equals(MiscObjectIdentifiers.verisignCzagExtension)) {
buf.append(new VerisignCzagExtension((ASN1IA5String) dIn.readObject())).append(nl);
} else {
buf.append(oid.getId());
buf.append(" value = ").append(ASN1Dump.dumpAsString(dIn.readObject())).append(nl);
// buf.append(" value = ").append("*****").append(nl);
}
} catch (Exception ex) {
buf.append(oid.getId());
// buf.append(" value = ").append(new String(Hex.encode(ext.getExtnValue().getOctets()))).append(nl);
buf.append(" value = ").append("*****").append(nl);
}
} else {
buf.append(nl);
}
}
}
return buf.toString();
}
use of com.mindbright.asn1.ASN1IA5String in project LinLong-Java by zhenwei1108.
the class CMSTimeStampedDataGenerator method generate.
public CMSTimeStampedData generate(TimeStampToken timeStamp, InputStream content) throws CMSException {
ByteArrayOutputStream contentOut = new ByteArrayOutputStream();
if (content != null) {
try {
Streams.pipeAll(content, contentOut);
} catch (IOException e) {
throw new CMSException("exception encapsulating content: " + e.getMessage(), e);
}
}
ASN1OctetString encContent = null;
if (contentOut.size() != 0) {
encContent = new BEROctetString(contentOut.toByteArray());
}
TimeStampAndCRL stamp = new TimeStampAndCRL(timeStamp.toCMSSignedData().toASN1Structure());
ASN1IA5String asn1DataUri = null;
if (dataUri != null) {
asn1DataUri = new DERIA5String(dataUri.toString());
}
return new CMSTimeStampedData(new ContentInfo(CMSObjectIdentifiers.timestampedData, new TimeStampedData(asn1DataUri, metaData, encContent, new Evidence(new TimeStampTokenEvidence(stamp)))));
}
Aggregations