Java Code Examples for org.bouncycastle.asn1.DLSequence#size()
The following examples show how to use
org.bouncycastle.asn1.DLSequence#size() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DSSASN1Utils.java From dss with GNU Lesser General Public License v2.1 | 7 votes |
public static Map<String, String> get(final X500Principal x500Principal) { Map<String, String> treeMap = new HashMap<>(); final byte[] encoded = x500Principal.getEncoded(); final ASN1Sequence asn1Sequence = ASN1Sequence.getInstance(encoded); final ASN1Encodable[] asn1Encodables = asn1Sequence.toArray(); for (final ASN1Encodable asn1Encodable : asn1Encodables) { final DLSet dlSet = (DLSet) asn1Encodable; for (int ii = 0; ii < dlSet.size(); ii++) { final DLSequence dlSequence = (DLSequence) dlSet.getObjectAt(ii); if (dlSequence.size() != 2) { throw new DSSException("The DLSequence must contains exactly 2 elements."); } final ASN1Encodable asn1EncodableAttributeType = dlSequence.getObjectAt(0); final String stringAttributeType = getString(asn1EncodableAttributeType); final ASN1Encodable asn1EncodableAttributeValue = dlSequence.getObjectAt(1); final String stringAttributeValue = getString(asn1EncodableAttributeValue); treeMap.put(stringAttributeType, stringAttributeValue); } } return treeMap; }
Example 2
Source File: OcspUtils.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
private static <T> T findObject(DLSequence sequence, ASN1ObjectIdentifier oid, Class<T> type) { for (ASN1Encodable element : sequence) { if (!(element instanceof DLSequence)) { continue; } DLSequence subSequence = (DLSequence) element; if (subSequence.size() != 2) { continue; } ASN1Encodable key = subSequence.getObjectAt(0); ASN1Encodable value = subSequence.getObjectAt(1); if (key.equals(oid) && type.isInstance(value)) { return type.cast(value); } } return null; }
Example 3
Source File: LPA.java From signer with GNU Lesser General Public License v3.0 | 6 votes |
public void parse(ASN1Primitive derObject) { ASN1Sequence sequence = ASN1Object.getDERSequence(derObject); ASN1Primitive firstObject = sequence.getObjectAt(0).toASN1Primitive(); this.version = new Version(); int indice = 0; if (firstObject instanceof ASN1Integer) { this.version.parse(firstObject); indice++; } ASN1Primitive policyInfos = sequence.getObjectAt(indice).toASN1Primitive(); DLSequence policyInfosSequence = (DLSequence) policyInfos; if (policyInfosSequence != null && policyInfosSequence.size() > 0) { this.policyInfos = new ArrayList<>(); for (int i = 0; i < policyInfosSequence.size(); i++) { PolicyInfo policyInfo = new PolicyInfo(); policyInfo.parse(policyInfosSequence.getObjectAt(i).toASN1Primitive()); this.policyInfos.add(policyInfo); } } this.nextUpdate = new GeneralizedTime(); this.nextUpdate.parse(sequence.getObjectAt(indice + 1).toASN1Primitive()); }
Example 4
Source File: LPA.java From signer with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void parse(ASN1Primitive derObject) { ASN1Sequence sequence = ASN1Object.getDERSequence(derObject); ASN1Primitive policyInfos = sequence.getObjectAt(0).toASN1Primitive(); DLSequence policyInfosSequence = (DLSequence) policyInfos; if (policyInfosSequence != null && policyInfosSequence.size() > 0) { this.policyInfos = new ArrayList<>(); for (int i = 0; i < policyInfosSequence.size(); i++) { PolicyInfo policyInfo = new PolicyInfo(); policyInfo.parse(policyInfosSequence.getObjectAt(i).toASN1Primitive()); this.policyInfos.add(policyInfo); } } this.nextUpdate = new Time(); this.nextUpdate.parse(sequence.getObjectAt(1).toASN1Primitive()); }
Example 5
Source File: BasicCertificate.java From signer with GNU Lesser General Public License v3.0 | 6 votes |
/** * * * @return the authority key identifier of a certificate * */ public String getAuthorityKeyIdentifier() { // TODO - Precisa validar este metodo com a RFC try { DLSequence sequence = (DLSequence) getExtensionValue(Extension.authorityKeyIdentifier.getId()); if (sequence == null || sequence.size() == 0) { return null; } DERTaggedObject taggedObject = (DERTaggedObject) sequence.getObjectAt(0); DEROctetString oct = (DEROctetString) taggedObject.getObject(); return toString(oct.getOctets()); } catch (Exception error) { logger.info(error.getMessage()); return null; } }
Example 6
Source File: XmppDomainVerifier.java From ComplianceTester with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static OtherName parseOtherName(byte[] otherName) { try { ASN1Primitive asn1Primitive = ASN1Primitive.fromByteArray(otherName); if (asn1Primitive instanceof DERTaggedObject) { ASN1Primitive inner = ((DERTaggedObject) asn1Primitive).getObject(); if (inner instanceof DLSequence) { DLSequence sequence = (DLSequence) inner; if (sequence.size() >= 2 && sequence.getObjectAt(1) instanceof DERTaggedObject) { String oid = sequence.getObjectAt(0).toString(); ASN1Primitive value = ((DERTaggedObject) sequence.getObjectAt(1)).getObject(); if (value instanceof DERUTF8String) { return new OtherName(oid, ((DERUTF8String) value).getString()); } else if (value instanceof DERIA5String) { return new OtherName(oid, ((DERIA5String) value).getString()); } } } } return null; } catch (IOException e) { return null; } }
Example 7
Source File: XmppDomainVerifier.java From Pix-Art-Messenger with GNU General Public License v3.0 | 6 votes |
private static Pair<String, String> parseOtherName(byte[] otherName) { try { ASN1Primitive asn1Primitive = ASN1Primitive.fromByteArray(otherName); if (asn1Primitive instanceof DERTaggedObject) { ASN1Primitive inner = ((DERTaggedObject) asn1Primitive).getObject(); if (inner instanceof DLSequence) { DLSequence sequence = (DLSequence) inner; if (sequence.size() >= 2 && sequence.getObjectAt(1) instanceof DERTaggedObject) { String oid = sequence.getObjectAt(0).toString(); ASN1Primitive value = ((DERTaggedObject) sequence.getObjectAt(1)).getObject(); if (value instanceof DERUTF8String) { return new Pair<>(oid, ((DERUTF8String) value).getString()); } else if (value instanceof DERIA5String) { return new Pair<>(oid, ((DERIA5String) value).getString()); } } } } return null; } catch (IOException e) { return null; } }
Example 8
Source File: XmppDomainVerifier.java From Conversations with GNU General Public License v3.0 | 6 votes |
private static Pair<String, String> parseOtherName(byte[] otherName) { try { ASN1Primitive asn1Primitive = ASN1Primitive.fromByteArray(otherName); if (asn1Primitive instanceof DERTaggedObject) { ASN1Primitive inner = ((DERTaggedObject) asn1Primitive).getObject(); if (inner instanceof DLSequence) { DLSequence sequence = (DLSequence) inner; if (sequence.size() >= 2 && sequence.getObjectAt(1) instanceof DERTaggedObject) { String oid = sequence.getObjectAt(0).toString(); ASN1Primitive value = ((DERTaggedObject) sequence.getObjectAt(1)).getObject(); if (value instanceof DERUTF8String) { return new Pair<>(oid, ((DERUTF8String) value).getString()); } else if (value instanceof DERIA5String) { return new Pair<>(oid, ((DERIA5String) value).getString()); } } } } return null; } catch (IOException e) { return null; } }
Example 9
Source File: BasicCertificate.java From signer with GNU Lesser General Public License v3.0 | 4 votes |
/** * returns the ICP-BRASIL Certificate Level(A1, A2, A3, A4, S1, S2, S3, * S4).<br> * DOC-ICP-04 Returns the <b>null</b> value if the CertificatePolicies is * NOT present. * * @return String Certificate level */ public String getCertificateLevel() { try { DLSequence sequence = (DLSequence) getExtensionValue(Extension.certificatePolicies.getId()); if (sequence != null) { for (int pos = 0; pos < sequence.size(); pos++) { DLSequence sequence2 = (DLSequence) sequence.getObjectAt(pos); ASN1ObjectIdentifier policyIdentifier = (ASN1ObjectIdentifier) sequence2.getObjectAt(0); PolicyInformation policyInformation = new PolicyInformation(policyIdentifier); String id = policyInformation.getPolicyIdentifier().getId(); if (id == null) { continue; } if (id.startsWith(OID_A1_CERTIFICATE)) { return "A1"; } if (id.startsWith(OID_A2_CERTIFICATE)) { return "A2"; } if (id.startsWith(OID_A3_CERTIFICATE)) { return "A3"; } if (id.startsWith(OID_A4_CERTIFICATE)) { return "A4"; } if (id.startsWith(OID_S1_CERTIFICATE)) { return "S1"; } if (id.startsWith(OID_S2_CERTIFICATE)) { return "S2"; } if (id.startsWith(OID_S3_CERTIFICATE)) { return "S3"; } if (id.startsWith(OID_S4_CERTIFICATE)) { return "S4"; } } } return null; } catch (Exception e) { logger.info(e.getMessage()); e.printStackTrace(); return null; } }
Example 10
Source File: DSSASN1Utils.java From dss with GNU Lesser General Public License v2.1 | 4 votes |
public static String getUtf8String(final X500Principal x500Principal) { final byte[] encoded = x500Principal.getEncoded(); final ASN1Sequence asn1Sequence = ASN1Sequence.getInstance(encoded); final ASN1Encodable[] asn1Encodables = asn1Sequence.toArray(); final StringBuilder stringBuilder = new StringBuilder(); /** * RFC 4514 LDAP: Distinguished Names * 2.1. Converting the RDNSequence * * If the RDNSequence is an empty sequence, the result is the empty or * zero-length string. * * Otherwise, the output consists of the string encodings of each * RelativeDistinguishedName in the RDNSequence (according to Section * 2.2), starting with the last element of the sequence and moving * backwards toward the first. * ... */ for (int ii = asn1Encodables.length - 1; ii >= 0; ii--) { final ASN1Encodable asn1Encodable = asn1Encodables[ii]; final DLSet dlSet = (DLSet) asn1Encodable; for (int jj = 0; jj < dlSet.size(); jj++) { final DLSequence dlSequence = (DLSequence) dlSet.getObjectAt(jj); if (dlSequence.size() != 2) { throw new DSSException("The DLSequence must contains exactly 2 elements."); } final ASN1Encodable attributeType = dlSequence.getObjectAt(0); final ASN1Encodable attributeValue = dlSequence.getObjectAt(1); String string = getString(attributeValue); /** * RFC 4514 LDAP: Distinguished Names * ... * Other characters may be escaped. * * Each octet of the character to be escaped is replaced by a backslash * and two hex digits, which form a single octet in the code of the * character. Alternatively, if and only if the character to be escaped * is one of * * ' ', '"', '#', '+', ',', ';', '<', '=', '>', or '\' * (U+0020, U+0022, U+0023, U+002B, U+002C, U+003B, * U+003C, U+003D, U+003E, U+005C, respectively) * * it can be prefixed by a backslash ('\' U+005C). */ string = Rdn.escapeValue(string); if (stringBuilder.length() != 0) { stringBuilder.append(','); } stringBuilder.append(attributeType).append('=').append(string); } } return stringBuilder.toString(); }