List of usage examples for org.bouncycastle.asn1 ASN1Sequence getObjects
public Enumeration getObjects()
From source file:be.fedict.trust.constraints.CertificatePoliciesCertificateConstraint.java
License:Open Source License
@Override public void check(X509Certificate certificate) throws TrustLinkerResultException, Exception { byte[] extensionValue = certificate.getExtensionValue(Extension.certificatePolicies.getId()); if (null == extensionValue) { throw new TrustLinkerResultException(TrustLinkerResultReason.CONSTRAINT_VIOLATION, "missing certificate policies X509 extension"); }/* w w w . j a v a 2s .c o m*/ DEROctetString oct = (DEROctetString) (new ASN1InputStream(new ByteArrayInputStream(extensionValue)) .readObject()); ASN1Sequence certPolicies = (ASN1Sequence) new ASN1InputStream(oct.getOctets()).readObject(); Enumeration<?> certPoliciesEnum = certPolicies.getObjects(); while (certPoliciesEnum.hasMoreElements()) { PolicyInformation policyInfo = PolicyInformation.getInstance(certPoliciesEnum.nextElement()); ASN1ObjectIdentifier policyOid = policyInfo.getPolicyIdentifier(); String policyId = policyOid.getId(); LOG.debug("present policy OID: " + policyId); if (this.certificatePolicies.contains(policyId)) { LOG.debug("matching certificate policy OID: " + policyId); return; } } throw new TrustLinkerResultException(TrustLinkerResultReason.CONSTRAINT_VIOLATION, "required policy OID not present"); }
From source file:be.fedict.trust.constraints.QCStatementsCertificateConstraint.java
License:Open Source License
@Override public void check(X509Certificate certificate) throws TrustLinkerResultException, Exception { byte[] extensionValue = certificate.getExtensionValue(Extension.qCStatements.getId()); if (null == extensionValue) { throw new TrustLinkerResultException(TrustLinkerResultReason.CONSTRAINT_VIOLATION, "missing QCStatements extension"); }//from w w w . j av a 2 s . co m DEROctetString oct = (DEROctetString) (new ASN1InputStream(new ByteArrayInputStream(extensionValue)) .readObject()); ASN1Sequence qcStatements = (ASN1Sequence) new ASN1InputStream(oct.getOctets()).readObject(); Enumeration<?> qcStatementEnum = qcStatements.getObjects(); boolean qcCompliance = false; boolean qcSSCD = false; while (qcStatementEnum.hasMoreElements()) { QCStatement qcStatement = QCStatement.getInstance(qcStatementEnum.nextElement()); ASN1ObjectIdentifier statementId = qcStatement.getStatementId(); LOG.debug("statement Id: " + statementId.getId()); if (QCStatement.id_etsi_qcs_QcCompliance.equals(statementId)) { qcCompliance = true; } if (QCStatement.id_etsi_qcs_QcSSCD.equals(statementId)) { qcSSCD = true; } } if (null != this.qcComplianceFilter) { if (qcCompliance != this.qcComplianceFilter) { LOG.error("qcCompliance QCStatements error"); throw new TrustLinkerResultException(TrustLinkerResultReason.CONSTRAINT_VIOLATION, "QCStatements not matching"); } } if (null != this.qcSSCDFilter) { if (qcSSCD != this.qcSSCDFilter) { LOG.error("qcSSCD QCStatements error"); throw new TrustLinkerResultException(TrustLinkerResultReason.CONSTRAINT_VIOLATION, "QCStatements not matching"); } } }
From source file:com.aaasec.sigserv.cscommon.xmldsig.EcdsaSigValue.java
License:Open Source License
public EcdsaSigValue(ASN1Sequence obj) { Enumeration e = obj.getObjects(); r = DERInteger.getInstance(e.nextElement()).getValue(); s = DERInteger.getInstance(e.nextElement()).getValue(); }
From source file:com.codename1.payments.GooglePlayValidator.java
/** * Generates a private key from a PKCS#8 encoded string. * @param key//from www .j a v a 2s .com * @return */ private RSAPrivateKey getRSAPrivateKey(String key) { String privKeyPEM = key.replace("-----BEGIN PRIVATE KEY-----\n", "").replace("-----END PRIVATE KEY-----", ""); try { byte[] encodedPrivateKey = Base64.decode(privKeyPEM.getBytes("UTF-8")); ASN1Sequence primitive = (ASN1Sequence) ASN1Sequence.fromByteArray(encodedPrivateKey); Enumeration<?> e = primitive.getObjects(); BigInteger v = ((ASN1Integer) e.nextElement()).getValue(); int version = v.intValue(); if (version != 0 && version != 1) { throw new IllegalArgumentException("wrong version for RSA private key"); } e.nextElement(); DEROctetString octetString = (DEROctetString) e.nextElement(); encodedPrivateKey = octetString.getOctets(); primitive = (ASN1Sequence) ASN1Sequence.fromByteArray(encodedPrivateKey); return RSAPrivateKey.getInstance(primitive); } catch (Exception e2) { throw new RuntimeException(e2); } }
From source file:com.guardtime.asn1.CertToken.java
License:Apache License
public Asn1CertToken(ASN1Sequence seq) { Enumeration en = seq.getObjects(); // Required elements version = ASN1Integer.getInstance(en.nextElement()); history = ASN1OctetString.getInstance(en.nextElement()); publishedData = Asn1PublishedData.getInstance(en.nextElement()); pubReference = ASN1Set.getInstance(en.nextElement()); // Optional elements while (en.hasMoreElements()) { ASN1TaggedObject obj = ASN1TaggedObject.getInstance(en.nextElement()); if (obj.getTagNo() == 0 && extensions == null) { extensions = Extensions.getInstance(obj, true); } else {//from ww w . j a va 2 s . com throw new IllegalArgumentException("invalid object in factory: " + obj); } } }
From source file:com.guardtime.asn1.CertTokenRequest.java
License:Apache License
public Asn1CertTokenRequest(ASN1Sequence seq) { Enumeration en = seq.getObjects(); // Required elements version = ASN1Integer.getInstance(en.nextElement()); historyIdentifier = ASN1Integer.getInstance(en.nextElement()); // Optional elements while (en.hasMoreElements()) { ASN1TaggedObject obj = ASN1TaggedObject.getInstance(en.nextElement()); if (obj.getTagNo() == 0 && extensions == null) { extensions = Extensions.getInstance(obj, true); } else {/*w w w . j a v a 2s. co m*/ throw new IllegalArgumentException("invalid object in factory: " + obj); } } }
From source file:com.guardtime.asn1.CertTokenResponse.java
License:Apache License
public Asn1CertTokenResponse(ASN1Sequence seq) { Enumeration en = seq.getObjects(); // Required elements status = PKIStatusInfo.getInstance(en.nextElement()); // Optional elements while (en.hasMoreElements()) { ASN1TaggedObject obj = ASN1TaggedObject.getInstance(en.nextElement()); if (obj.getTagNo() == 0 && certToken == null) { certToken = Asn1CertToken.getInstance(obj, false); } else {//from ww w.j a v a 2 s. co m throw new IllegalArgumentException("invalid object in factory: " + obj); } } }
From source file:com.guardtime.asn1.PublishedData.java
License:Apache License
public Asn1PublishedData(ASN1Sequence seq) { Enumeration en = seq.getObjects(); // Required elements publicationIdentifier = ASN1Integer.getInstance(en.nextElement()); publicationImprint = ASN1OctetString.getInstance(en.nextElement()); // Extra elements (not allowed) if (en.hasMoreElements()) { throw new IllegalArgumentException("invalid object in factory: " + en.nextElement()); }//from w ww . j ava2 s .c om }
From source file:com.guardtime.asn1.SignatureInfo.java
License:Apache License
public Asn1SignatureInfo(ASN1Sequence seq) { Enumeration en = seq.getObjects(); // Required elements signatureAlgorithm = AlgorithmIdentifier.getInstance(en.nextElement()); signatureValue = ASN1OctetString.getInstance(en.nextElement()); // Optional elements while (en.hasMoreElements()) { ASN1TaggedObject obj = ASN1TaggedObject.getInstance(en.nextElement()); if (obj.getTagNo() == 0 && pkiReferences == null) { pkiReferences = ASN1Set.getInstance(obj, false); } else {//from w w w . jav a2s.c om throw new IllegalArgumentException("invalid object in factory: " + obj); } } }
From source file:com.guardtime.asn1.TimeSignature.java
License:Apache License
public Asn1TimeSignature(ASN1Sequence seq) { Enumeration en = seq.getObjects(); // Required elements location = ASN1OctetString.getInstance(en.nextElement()); history = ASN1OctetString.getInstance(en.nextElement()); publishedData = Asn1PublishedData.getInstance(en.nextElement()); // Optional elements while (en.hasMoreElements()) { ASN1TaggedObject obj = ASN1TaggedObject.getInstance(en.nextElement()); int tag = obj.getTagNo(); if (tag == 0 && pkSignature == null) { pkSignature = Asn1SignatureInfo.getInstance(obj, false); } else if (tag == 1 && pubReferences == null) { pubReferences = ASN1Set.getInstance(obj, false); } else {/*from w w w . j a v a 2 s . c o m*/ throw new IllegalArgumentException("invalid object in factory: " + obj); } } }