List of usage examples for org.bouncycastle.asn1 DERSequence size
public int size()
From source file:bluecrystal.bcdeps.helper.DerEncoder.java
License:Open Source License
public static ASN1Encodable getAt(DERSequence seq, int index) { return seq.size() > index ? seq.getObjectAt(index) : null; }
From source file:br.gov.frameworkdemoiselle.certificate.extension.BasicCertificate.java
License:Open Source License
/** * returns the ICP-BRASIL Level Certificate(A1, A2, A3, A4, S1, S2, S3, * S4).<br>// ww w . j a v a2 s . c o m * DOC-ICP-04 Returns the <b>null</b> value if the CertificatePolicies is * NOT present. * * @return String */ public String getNivelCertificado() { try { DERSequence seq = (DERSequence) getExtensionValue(X509Extensions.CertificatePolicies.getId()); if (seq == null) { return null; } for (int pos = 0; pos < seq.size(); pos++) { PolicyInformation policyInformation = new PolicyInformation((ASN1Sequence) seq.getObjectAt(pos)); 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) { e.printStackTrace(); } return null; }
From source file:br.gov.frameworkdemoiselle.certificate.extension.BasicCertificate.java
License:Open Source License
/** * Returns the AuthorityKeyIdentifier extension value on String format.<br> * Otherwise, returns <b>null</b>.<br> * * @return String//from w ww . ja va 2 s . com * @throws IOException */ public String getAuthorityKeyIdentifier() throws IOException { // TODO - Precisa validar este metodo com a RFC DERSequence seq = (DERSequence) getExtensionValue(X509Extensions.AuthorityKeyIdentifier.getId()); if (seq == null || seq.size() == 0) { return null; } DERTaggedObject tag = (DERTaggedObject) seq.getObjectAt(0); DEROctetString oct = (DEROctetString) DEROctetString.getInstance(tag); return toString(oct.getOctets()); }
From source file:crossbear.CVRProcessor.java
License:Open Source License
/** * Search the "Subject Alternative Name"-field (OID is 2.5.29.17) for Common Names and add all of them as byte[] to a Vector of byte[]s * /* w w w. ja v a 2 s. c o m*/ * @param altNames The DEROctetString found within the "Subject Alternative Name"-Field * @param cnBytes The Vector to add all found CNs to * @throws IOException */ private static void searchAltNamesForCN(DEROctetString altNames, Vector<byte[]> cnBytes) throws IOException { DERSequence altNameSequence = (DERSequence) DERSequence.fromByteArray(altNames.getOctets()); // Look on the type of each element of the sequence for (int i = 0; i < altNameSequence.size(); i++) { DEREncodable altNameT = altNameSequence.getObjectAt(i); // Assert type of the element being a DERTaggedObject if (!(altNameT instanceof DERTaggedObject)) continue; // Extract the content of the DERTaggedObject DERObject altNameO = ((DERTaggedObject) altNameT).getObject(); // Assert type of the content being a DEROctetString if (!(altNameO instanceof DEROctetString)) continue; // Extract name field and store it cnBytes.add(((DEROctetString) altNameO).getEncoded()); } }
From source file:crossbear.CVRProcessor.java
License:Open Source License
/** * Search a DERSequence for all occurrences of Common Names. They might be stored in the "Subject Alternative Name"-field (OID is 2.5.29.17) or in a commonName-field (OID is 2.5.4.3) * //from ww w .j av a2s . c om * @param seq The sequence to be searched (might be created by calling DERSequence.fromByteArray(X509Certificate.getEncoded())) * @param cnBytes The Vector to add all found CNs to * @throws IOException */ private static void searchSequenceForCNs(DERSequence seq, Vector<byte[]> cnBytes) throws IOException { // Look on the type of each element of the sequence for (int i = 0; i < seq.size(); i++) { DEREncodable derEncodable = seq.getObjectAt(i); // if the type is a DERSequence (i.e. a subsequence) then check if starts with an OID or not if (derEncodable instanceof DERSequence) { DEREncodable firstSubSequenceElement = ((DERSequence) derEncodable).getObjectAt(0); // If it starts with an OID and If the OID is 2.5.29.17 then we found the "Subject Alternative Name"-field if ((firstSubSequenceElement instanceof ASN1ObjectIdentifier) && ((ASN1ObjectIdentifier) firstSubSequenceElement).getId().equals("2.5.29.17")) { DEREncodable secondSubSequenceElement = ((DERSequence) derEncodable).getObjectAt(1); // Assert type of SAN-field being an octetString if (secondSubSequenceElement instanceof DEROctetString) { searchAltNamesForCN((DEROctetString) secondSubSequenceElement, cnBytes); } // If not just continue recursively } else { searchSequenceForCNs((DERSequence) derEncodable, cnBytes); } // If the type is a DERSet then we might be close to the CN-Field -> try to extract it } else if (derEncodable instanceof DERSet) { searchSetForCN((DERSet) derEncodable, cnBytes); // If the type is a DERTaggedObject then we might have found the Extension of the certificate } else if (derEncodable instanceof DERTaggedObject) { int tagno = ((DERTaggedObject) derEncodable).getTagNo(); // The tag for the extension we are looking for is 3 if (tagno == 3) { DERObject exensionList = ((DERTaggedObject) derEncodable).getObject(); // Assert type of the extension being a DERSequence if (exensionList instanceof DERSequence) { searchSequenceForCNs((DERSequence) exensionList, cnBytes); } } } } }
From source file:de.fraunhofer.fokus.openeid.ca.AlgorithmIdentifier.java
License:Open Source License
public AlgorithmIdentifier(DERSequence algorithmInfo) { DERObjectIdentifier derOid = (DERObjectIdentifier) algorithmInfo.getObjectAt(0); algorithmOid = derOid.getId();/*from w w w. j av a 2s . c o m*/ for (int i = 1; i < algorithmInfo.size(); i++) { parameter.add(algorithmInfo.getObjectAt(i)); } }
From source file:de.fraunhofer.fokus.openeid.ca.ChipAuthenticationInfo.java
License:Open Source License
public ChipAuthenticationInfo(DERSequence chipInfoSequence) { DERObjectIdentifier derOid = (DERObjectIdentifier) chipInfoSequence.getObjectAt(0); protocolOid = derOid.getId();//from w w w. j ava2s .c o m DERInteger derVersion = (DERInteger) chipInfoSequence.getObjectAt(1); version = derVersion.getValue().intValue(); if (chipInfoSequence.size() > 2) { DERInteger derKeyId = (DERInteger) chipInfoSequence.getObjectAt(2); keyId = derKeyId.getValue().intValue(); } }
From source file:de.fraunhofer.fokus.openeid.ca.ChipAuthenticationPublicKeyInfo.java
License:Open Source License
public ChipAuthenticationPublicKeyInfo(DERSequence chipInfoSequence) { DERObjectIdentifier derOid = (DERObjectIdentifier) chipInfoSequence.getObjectAt(0); oid = derOid.getId();/*from www . j a v a 2 s.c o m*/ DERSequence publicKey = (DERSequence) chipInfoSequence.getObjectAt(1); logger.info(ASN1Dump.dumpAsString(publicKey, true)); algorithmIdentifier = (DERSequence) publicKey.getObjectAt(0); DERBitString encodedKey = (DERBitString) publicKey.getObjectAt(1); encodedPublicKey = encodedKey.getBytes(); if (chipInfoSequence.size() > 2) { DERInteger derKeyId = (DERInteger) chipInfoSequence.getObjectAt(2); keyId = derKeyId.getValue().intValue(); } }
From source file:de.fraunhofer.fokus.openeid.pace.PACEInfo.java
License:Open Source License
public PACEInfo(DERSequence paceInfoSequence) throws UnsupportedProtocolException, InvalidDomainParameter { DERObjectIdentifier derOid = (DERObjectIdentifier) paceInfoSequence.getObjectAt(0); protocol = PACEInfoProtocol.getProtocolByOid(derOid.getId()); DERInteger derVersion = (DERInteger) paceInfoSequence.getObjectAt(1); version = derVersion.getValue().intValue(); if (paceInfoSequence.size() == 3) { //parameterId is OPTIONAL DERInteger derParameter = (DERInteger) paceInfoSequence.getObjectAt(2); int parameterId = derParameter.getValue().intValue(); domainParameter = StandardizedDomainParameters.getById(parameterId); //TODO there could be non-standardized DomainParameters defined -> @see TR-03110 A.2.1 / A.2.1.1. }/*from w w w . j av a 2s .c om*/ }
From source file:de.fraunhofer.fokus.openeid.ri.RestrictedIdentificationInfo.java
License:Open Source License
public RestrictedIdentificationInfo(DERSequence sequence) { DERObjectIdentifier derOid = (DERObjectIdentifier) sequence.getObjectAt(0); protocolOid = derOid.getId();/*from w ww. j a v a 2 s . c om*/ this.protocolParams = new ProtocolParams((DERSequence) sequence.getObjectAt(1)); if (sequence.size() > 2) { this.maxKeyLen = ((DERInteger) sequence.getObjectAt(2)).getValue().intValue(); } }