Java Code Examples for org.bouncycastle.asn1.DLSequence#getObjectAt()
The following examples show how to use
org.bouncycastle.asn1.DLSequence#getObjectAt() .
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: 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 4
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 5
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 6
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 7
Source File: DSSASN1Utils.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
/** * Computes SHA-1 hash of the given {@code publicKey}'s * @param publicKey {@link PublicKey} to compute digest for * @return byte array of public key's SHA-1 hash */ public static byte[] computeSkiFromCertPublicKey(final PublicKey publicKey) { try { DLSequence seq = (DLSequence) ASN1Primitive.fromByteArray(publicKey.getEncoded()); DERBitString item = (DERBitString) seq.getObjectAt(1); return DSSUtils.digest(DigestAlgorithm.SHA1, item.getOctets()); } catch (IOException e) { throw new DSSException(e); } }
Example 8
Source File: Asn1.java From UAF with Apache License 2.0 | 5 votes |
/** * DER - From byte[] to Big Integer rs * UAF_ALG_SIGN_SECP256K1_ECDSA_SHA256_DER 0x06 DER [ITU-X690-2008] encoded * ECDSA signature [RFC5480] on the secp256k1 curve. I.e. a DER encoded * SEQUENCE { r INTEGER, s INTEGER } * * @param signature * @return * @throws IOException */ public static BigInteger[] decodeToBigIntegerArray(byte[] signature) throws IOException { ASN1InputStream decoder = new ASN1InputStream(signature); DLSequence seq = (DLSequence) decoder.readObject(); ASN1Integer r = (ASN1Integer) seq.getObjectAt(0); ASN1Integer s = (ASN1Integer) seq.getObjectAt(1); decoder.close(); BigInteger[] ret = new BigInteger[2]; ret[0] = r.getPositiveValue(); ret[1] = s.getPositiveValue(); return ret; }
Example 9
Source File: PolicyIssuerName.java From signer with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void parse(ASN1Primitive primitive) { if (primitive instanceof DLSequence) { DLSequence sequence = (DLSequence) primitive; ASN1Encodable asn1Encodable = sequence.getObjectAt(0); if (asn1Encodable instanceof DERTaggedObject) { DERTaggedObject derTaggedObject = (DERTaggedObject) asn1Encodable; ASN1Primitive object = derTaggedObject.getObject(); if (object instanceof DEROctetString) { OctetString octetString = new OctetString(); octetString.parse(object); this.issuerName = octetString.getValueUTF8(); } else if (object instanceof DERSequence) { DERSequence sequence2 = (DERSequence) object; for (int i = 0; i < sequence2.size(); i++) { ASN1Encodable obj = sequence2.getObjectAt(i); if (obj instanceof DERSet) { DERSet set = (DERSet) obj; ASN1Encodable object2 = set.getObjectAt(0); if (object2 instanceof DERSequence) { DERSequence sequence3 = (DERSequence) object2; ObjectIdentifier objectIdendifier = new ObjectIdentifier(); objectIdendifier.parse(sequence3.getObjectAt(0).toASN1Primitive()); String name = null; ASN1Encodable object3 = sequence3.getObjectAt(1); if (object3 instanceof DERPrintableString) { name = ((DERPrintableString) object3).getString(); } else if (object3 instanceof DERUTF8String) { name = ((DERUTF8String) object3).getString(); } else { System.out.println(policyMessagesBundle.getString("error.not.recognized.object",object3.getClass(),object3.toString())); } if (this.issuerNames == null) { this.issuerNames = new HashMap<ObjectIdentifier, String>(); } this.issuerNames.put(objectIdendifier, name); } } } } } } }
Example 10
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 11
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(); }