private X509Certificate generateJcaObject(TBSCertificate tbsCert, byte[] signature) throws CertificateEncodingException { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(tbsCert); v.add(sigAlgId); v.add(new DERBitString(signature)); try { return new X509CertificateObject(Certificate.getInstance(new DERSequence(v))); } catch (CertificateParsingException e) { throw new ExtCertificateEncodingException("exception producing certificate object", e); } }
/** * Add a given extension field for the standard extensions tag (tag 3) * copying the extension value from another certificate. * * @param oid the OID defining the extension type. * @param isCritical true if the copied extension is to be marked as critical, false otherwise. * @param certHolder the holder for the certificate that the extension is to be copied from. * @return this builder object. */ public X509v3CertificateBuilder copyAndAddExtension( ASN1ObjectIdentifier oid, boolean isCritical, X509CertificateHolder certHolder) { Certificate cert = certHolder.toASN1Structure(); Extension extension = cert.getTBSCertificate().getExtensions().getExtension(oid); if (extension == null) { throw new NullPointerException("extension " + oid + " not present"); } extGenerator.addExtension(oid, isCritical, extension.getExtnValue().getOctets()); return this; }
private CscaMasterList( ASN1Sequence seq) { if (seq == null || seq.size() == 0) { throw new IllegalArgumentException( "null or empty sequence passed."); } if (seq.size() != 2) { throw new IllegalArgumentException( "Incorrect sequence size: " + seq.size()); } version = ASN1Integer.getInstance(seq.getObjectAt(0)); ASN1Set certSet = ASN1Set.getInstance(seq.getObjectAt(1)); certList = new Certificate[certSet.size()]; for (int i = 0; i < certList.length; i++) { certList[i] = Certificate.getInstance(certSet.getObjectAt(i)); } }
public static RequestedCertificate getInstance(Object obj) { if (obj == null || obj instanceof RequestedCertificate) { return (RequestedCertificate)obj; } if (obj instanceof ASN1Sequence) { return new RequestedCertificate(Certificate.getInstance(obj)); } if (obj instanceof ASN1TaggedObject) { return new RequestedCertificate((ASN1TaggedObject)obj); } throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName()); }
public static CMPCertificate getInstance(Object o) { if (o == null || o instanceof CMPCertificate) { return (CMPCertificate)o; } if (o instanceof ASN1Sequence || o instanceof byte[]) { return new CMPCertificate(Certificate.getInstance(o)); } if (o instanceof ASN1TaggedObject) { return new CMPCertificate(AttributeCertificate.getInstance(((ASN1TaggedObject)o).getObject())); } throw new IllegalArgumentException("Invalid object: " + o.getClass().getName()); }
private java.security.cert.Certificate readDERCertificate( ASN1InputStream dIn) throws IOException, CertificateParsingException { ASN1Sequence seq = (ASN1Sequence)dIn.readObject(); if (seq.size() > 1 && seq.getObjectAt(0) instanceof ASN1ObjectIdentifier) { if (seq.getObjectAt(0).equals(PKCSObjectIdentifiers.signedData)) { sData = SignedData.getInstance(ASN1Sequence.getInstance( (ASN1TaggedObject)seq.getObjectAt(1), true)).getCertificates(); return getCertificate(); } } return new X509CertificateObject( Certificate.getInstance(seq)); }
private java.security.cert.Certificate getCertificate() throws CertificateParsingException { if (sData != null) { while (sDataObjectCount < sData.size()) { Object obj = sData.getObjectAt(sDataObjectCount++); if (obj instanceof ASN1Sequence) { return new X509CertificateObject( Certificate.getInstance(obj)); } } } return null; }
Store getCertificates(ASN1Set certSet) { if (certSet != null) { List certList = new ArrayList(certSet.size()); for (Enumeration en = certSet.getObjects(); en.hasMoreElements();) { ASN1Primitive obj = ((ASN1Encodable)en.nextElement()).toASN1Primitive(); if (obj instanceof ASN1Sequence) { certList.add(new X509CertificateHolder(Certificate.getInstance(obj))); } } return new CollectionStore(certList); } return new CollectionStore(new ArrayList()); }
/** * Return the certificates stored in the underlying OriginatorInfo object. * * @return a Store of X509CertificateHolder objects. */ public Store getCertificates() { ASN1Set certSet = originatorInfo.getCertificates(); if (certSet != null) { List certList = new ArrayList(certSet.size()); for (Enumeration en = certSet.getObjects(); en.hasMoreElements();) { ASN1Primitive obj = ((ASN1Encodable)en.nextElement()).toASN1Primitive(); if (obj instanceof ASN1Sequence) { certList.add(new X509CertificateHolder(Certificate.getInstance(obj))); } } return new CollectionStore(certList); } return new CollectionStore(new ArrayList()); }
@Override protected Object execute0() throws Exception { Certificate cert = Certificate.getInstance(IoUtil.read(inFile)); if (serial != null && serial) { return getNumber(cert.getSerialNumber().getPositiveValue()); } else if (subject != null && subject) { return cert.getSubject().toString(); } else if (issuer != null && issuer) { return cert.getIssuer().toString(); } else if (notBefore != null && notBefore) { return toUtcTimeyyyyMMddhhmmssZ(cert.getStartDate().getDate()); } else if (notAfter != null && notAfter) { return toUtcTimeyyyyMMddhhmmssZ(cert.getEndDate().getDate()); } else if (fingerprint != null && fingerprint) { byte[] encoded = cert.getEncoded(); return HashAlgoType.getHashAlgoType(hashAlgo).hexHash(encoded); } return null; }
private void checkConstruction( RequestedCertificate requested, int type, byte[] certOctets, Certificate cert) throws IOException { checkValues(requested, type, certOctets, cert); requested = RequestedCertificate.getInstance(requested); checkValues(requested, type, certOctets, cert); ASN1InputStream aIn = new ASN1InputStream(requested.toASN1Primitive().getEncoded()); Object obj = aIn.readObject(); requested = RequestedCertificate.getInstance(obj); checkValues(requested, type, certOctets, cert); }
private void checkValues( RequestedCertificate requested, int type, byte[] certOctets, Certificate cert) throws IOException { checkMandatoryField("certType", type, requested.getType()); if (requested.getType() == RequestedCertificate.certificate) { checkMandatoryField("certificate", cert.getEncoded(), requested.getCertificateBytes()); } else { checkMandatoryField("certificateOctets", certOctets, requested.getCertificateBytes()); } }
private static byte[] buildCRT(TBSCertificate tbs, AlgorithmIdentifier aid, byte[] sig) { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(tbs); v.add(aid); v.add(new DERBitString(sig)); byte [] crt = null; try { Certificate c = Certificate.getInstance(new DERSequence(v)); crt = c.getEncoded(); Base64.encode(crt, System.out); System.out.println(""); } catch (Exception ex) { ex.printStackTrace(System.out); Assert.fail(); } return crt; }
private java.security.cert.Certificate readDERCertificate( ASN1InputStream dIn) throws IOException, CertificateParsingException { ASN1Sequence seq = (ASN1Sequence)dIn.readObject(); if (seq.size() > 1 && seq.getObjectAt(0) instanceof ASN1ObjectIdentifier) { if (seq.getObjectAt(0).equals(PKCSObjectIdentifiers.signedData)) { sData = SignedData.getInstance(ASN1Sequence.getInstance( (ASN1TaggedObject)seq.getObjectAt(1), true)).getCertificates(); return getCertificate(); } } return new X509CertificateObject(bcHelper, Certificate.getInstance(seq)); }
private java.security.cert.Certificate getCertificate() throws CertificateParsingException { if (sData != null) { while (sDataObjectCount < sData.size()) { Object obj = sData.getObjectAt(sDataObjectCount++); if (obj instanceof ASN1Sequence) { return new X509CertificateObject(bcHelper, Certificate.getInstance(obj)); } } } return null; }
private void extractCertificateFromUnsignedAttribute(List<CertificateToken> encapsulatedCerts, Attribute attribute) { if (attribute != null) { final ASN1Sequence seq = (ASN1Sequence) attribute.getAttrValues().getObjectAt(0); for (int ii = 0; ii < seq.size(); ii++) { try { final Certificate cs = Certificate.getInstance(seq.getObjectAt(ii)); final CertificateToken certToken = addCertificate(DSSUtils.loadCertificate(cs.getEncoded())); if (!encapsulatedCerts.contains(certToken)) { encapsulatedCerts.add(certToken); } } catch (Exception e) { LOG.warn("Unable to parse encapsulated certificate : " + e.getMessage()); } } } }
private X509Certificate generateJcaObject(TBSCertificate tbsCert, byte[] signature) throws CertificateEncodingException { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(tbsCert); v.add(sigAlgId); v.add(new DERBitString(signature)); try { return new X509CertificateObject(Certificate.getInstance((new DERSequence(v)))); } catch (CertificateParsingException e) { throw new ExtCertificateEncodingException("exception producing certificate object", e); } }
public Store getCertificates() throws CMSException { populateCertCrlSets(); ASN1Set certSet = _certSet; if (certSet != null) { List certList = new ArrayList(certSet.size()); for (Enumeration en = certSet.getObjects(); en.hasMoreElements();) { ASN1Primitive obj = ((ASN1Encodable)en.nextElement()).toASN1Primitive(); if (obj instanceof ASN1Sequence) { certList.add(new X509CertificateHolder(Certificate.getInstance(obj))); } } return new CollectionStore(certList); } return new CollectionStore(new ArrayList()); }
public Store getCertificates() { ASN1Set certSet = signedData.getCertificates(); if (certSet != null) { List certList = new ArrayList(certSet.size()); for (Enumeration en = certSet.getObjects(); en.hasMoreElements();) { ASN1Primitive obj = ((ASN1Encodable)en.nextElement()).toASN1Primitive(); if (obj instanceof ASN1Sequence) { certList.add(new X509CertificateHolder(Certificate.getInstance(obj))); } } return new CollectionStore(certList); } return new CollectionStore(new ArrayList()); }