List of usage examples for org.bouncycastle.asn1 ASN1InputStream ASN1InputStream
public ASN1InputStream(byte[] input)
From source file:de.fraunhofer.fokus.openeid.ca.SignedData.java
License:Open Source License
public SignedData(DEROctetString object) throws IOException { ASN1InputStream signedDataReader = new ASN1InputStream(object.getOctets()); signedData = signedDataReader.readObject(); signedDataReader.close();/*from www . j ava2 s .co m*/ }
From source file:de.fraunhofer.fokus.openeid.eac.EfFile.java
License:Open Source License
protected void processContent() throws IOException { ASN1InputStream asn1InputStream = new ASN1InputStream(content); file = asn1InputStream.readObject(); asn1InputStream.close();//w ww. jav a 2 s .co m }
From source file:de.rub.dez6a3.jpdfsigner.TimeStampToken.java
License:Open Source License
public TimeStampToken(CMSSignedData signedData) throws TSPException, IOException { this.tsToken = signedData; if (!this.tsToken.getSignedContentTypeOID().equals(PKCSObjectIdentifiers.id_ct_TSTInfo.getId())) { throw new TSPValidationException("ContentInfo object not for a time stamp."); }//from w ww.j ava 2 s .com Collection signers = tsToken.getSignerInfos().getSigners(); if (signers.size() != 1) { throw new IllegalArgumentException("Time-stamp token signed by " + signers.size() + " signers, but it must contain just the TSA signature."); } tsaSignerInfo = (SignerInformation) signers.iterator().next(); try { CMSProcessable content = tsToken.getSignedContent(); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); content.write(bOut); ASN1InputStream aIn = new ASN1InputStream(new ByteArrayInputStream(bOut.toByteArray())); this.tstInfo = new TimeStampTokenInfo(TSTInfo.getInstance(aIn.readObject())); Attribute attr = tsaSignerInfo.getSignedAttributes() .get(PKCSObjectIdentifiers.id_aa_signingCertificate); if (attr == null) { throw new TSPValidationException("no signing certificate attribute found, time stamp invalid."); } SigningCertificate signCert = SigningCertificate.getInstance(attr.getAttrValues().getObjectAt(0)); this.certID = ESSCertID.getInstance(signCert.getCerts()[0]); } catch (CMSException e) { throw new TSPException(e.getMessage(), e.getUnderlyingException()); } }
From source file:de.tsenger.animamea.iso7816.DO87.java
License:Open Source License
public void fromByteArray(byte[] encodedData) { ASN1InputStream asn1in = new ASN1InputStream(encodedData); try {/*from w w w. ja va2s . co m*/ to = (DERTaggedObject) asn1in.readObject(); asn1in.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } DEROctetString ocs = (DEROctetString) to.getObject(); value_ = ocs.getOctets(); data = removePaddingIndicator(value_); }
From source file:de.tsenger.animamea.iso7816.DO8E.java
License:Open Source License
public void fromByteArray(byte[] encodedData) { ASN1InputStream asn1in = new ASN1InputStream(encodedData); try {/* w ww . j a v a2 s . com*/ to = (DERTaggedObject) asn1in.readObject(); asn1in.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } DEROctetString ocs = (DEROctetString) to.getObject(); data = ocs.getOctets(); }
From source file:de.tsenger.animamea.iso7816.DO97.java
License:Open Source License
public void fromByteArray(byte[] encodedData) { ASN1InputStream asn1in = new ASN1InputStream(encodedData); try {//from w w w . j a v a 2 s . c o m to = (DERTaggedObject) asn1in.readObject(); asn1in.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } DEROctetString ocs = (DEROctetString) to.getObject(); data = ocs.getOctets(); }
From source file:de.tsenger.animamea.iso7816.DO99.java
License:Open Source License
public void fromByteArray(byte[] encodedData) { ASN1InputStream asn1in = new ASN1InputStream(encodedData); try {// ww w.jav a2 s.c o m to = (DERTaggedObject) asn1in.readObject(); asn1in.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } DEROctetString ocs = (DEROctetString) to.getObject(); data = ocs.getOctets(); }
From source file:de.tsenger.animamea.iso7816.SecureMessaging.java
License:Open Source License
/** * Erzeugt aus einer SM geschtzten Response-APDU eine plain Response-APDU * ohne Secure Messaging./* www .j a va 2 s . c o m*/ * @param rapdu SM protected RAPDU * @return plain RAPDU * @throws SecureMessagingException */ public ResponseAPDU unwrap(ResponseAPDU rapdu) throws SecureMessagingException { DO87 do87 = null; DO99 do99 = null; DO8E do8E = null; incrementAtIndex(ssc, ssc.length - 1); int pointer = 0; byte[] rapduBytes = rapdu.getData(); byte[] subArray = new byte[rapduBytes.length]; while (pointer < rapduBytes.length) { System.arraycopy(rapduBytes, pointer, subArray, 0, rapduBytes.length - pointer); ASN1InputStream asn1sp = new ASN1InputStream(subArray); byte[] encodedBytes = null; try { encodedBytes = asn1sp.readObject().getEncoded(); asn1sp.close(); } catch (IOException e) { throw new SecureMessagingException(e); } ASN1InputStream asn1in = new ASN1InputStream(encodedBytes); try { switch (encodedBytes[0]) { case (byte) 0x87: do87 = new DO87(); do87.fromByteArray(asn1in.readObject().getEncoded()); break; case (byte) 0x99: do99 = new DO99(); do99.fromByteArray(asn1in.readObject().getEncoded()); break; case (byte) 0x8E: do8E = new DO8E(); do8E.fromByteArray(asn1in.readObject().getEncoded()); } asn1in.close(); } catch (IOException e) { throw new SecureMessagingException(e); } pointer += encodedBytes.length; } if (do99 == null) throw new SecureMessagingException("Secure Messaging error: mandatory DO99 not found"); // DO99 is mandatory // and only absent // if SM error // occurs // Construct K (SSC||DO87||DO99) ByteArrayOutputStream bout = new ByteArrayOutputStream(); try { if (do87 != null) bout.write(do87.getEncoded()); bout.write(do99.getEncoded()); } catch (IOException e) { throw new SecureMessagingException(e); } crypto.init(ks_mac, ssc); byte[] cc = crypto.getMAC(bout.toByteArray()); byte[] do8eData = do8E.getData(); if (!java.util.Arrays.equals(cc, do8eData)) throw new SecureMessagingException("Checksum is incorrect!\n Calculated CC: " + HexString.bufferToHex(cc) + "\nCC in DO8E: " + HexString.bufferToHex(do8eData)); // Decrypt DO87 byte[] data = null; byte[] unwrappedAPDUBytes = null; if (do87 != null) { crypto.init(ks_enc, ssc); byte[] do87Data = do87.getData(); try { data = crypto.decrypt(do87Data); } catch (AmCryptoException e) { throw new SecureMessagingException(e); } // Build unwrapped RAPDU unwrappedAPDUBytes = new byte[data.length + 2]; System.arraycopy(data, 0, unwrappedAPDUBytes, 0, data.length); byte[] do99Data = do99.getData(); System.arraycopy(do99Data, 0, unwrappedAPDUBytes, data.length, do99Data.length); } else unwrappedAPDUBytes = do99.getData().clone(); return new ResponseAPDU(unwrappedAPDUBytes); }
From source file:demo.sts.provider.cert.CRLVerifier.java
License:Apache License
/** * Extracts all CRL distribution point URLs from the * "CRL Distribution Point" extension in a X.509 certificate. If CRL * distribution point extension is unavailable, returns an empty list. */// w w w . j av a 2 s. c o m public static List<String> getCrlDistributionPoints(X509Certificate cert) throws CertificateParsingException, IOException { byte[] crldpExt = cert.getExtensionValue(X509Extensions.CRLDistributionPoints.getId()); if (crldpExt == null) { return new ArrayList<String>(); } ASN1InputStream oAsnInStream = new ASN1InputStream(new ByteArrayInputStream(crldpExt)); DERObject derObjCrlDP = oAsnInStream.readObject(); DEROctetString dosCrlDP = (DEROctetString) derObjCrlDP; byte[] crldpExtOctets = dosCrlDP.getOctets(); ASN1InputStream oAsnInStream2 = new ASN1InputStream(new ByteArrayInputStream(crldpExtOctets)); DERObject derObj2 = oAsnInStream2.readObject(); CRLDistPoint distPoint = CRLDistPoint.getInstance(derObj2); List<String> crlUrls = new ArrayList<String>(); for (DistributionPoint dp : distPoint.getDistributionPoints()) { DistributionPointName dpn = dp.getDistributionPoint(); // Look for URIs in fullName if (dpn != null && dpn.getType() == DistributionPointName.FULL_NAME) { GeneralName[] genNames = GeneralNames.getInstance(dpn.getName()).getNames(); // Look for an URI for (int j = 0; j < genNames.length; j++) { if (genNames[j].getTagNo() == GeneralName.uniformResourceIdentifier) { String url = DERIA5String.getInstance(genNames[j].getName()).getString(); crlUrls.add(url); } } } } return crlUrls; }
From source file:dk.itst.oiosaml.security.SecurityHelper.java
License:Mozilla Public License
public static X509Certificate generateCertificate(Credential credential, String entityId) throws Exception { X500Name issuer = new X500Name("o=keymanager, ou=oiosaml-sp"); BigInteger serialNumber = BigInteger.valueOf(System.currentTimeMillis()); Date notBefore = new Date(); Date notAfter = new Date(System.currentTimeMillis() + 1000L * 60L * 60L * 24L * 365L * 10L); X500Name subject = new X500Name("cn=" + entityId + ", ou=oiosaml-sp"); ByteArrayInputStream bIn = new ByteArrayInputStream(credential.getPublicKey().getEncoded()); SubjectPublicKeyInfo publicKeyInfo = new SubjectPublicKeyInfo( (ASN1Sequence) new ASN1InputStream(bIn).readObject()); X509v3CertificateBuilder gen = new X509v3CertificateBuilder(issuer, serialNumber, notBefore, notAfter, subject, publicKeyInfo);// w ww. ja v a2s. c o m gen.addExtension(X509Extension.subjectKeyIdentifier, false, new JcaX509ExtensionUtils().createSubjectKeyIdentifier(credential.getPublicKey())); gen.addExtension(X509Extension.authorityKeyIdentifier, false, new JcaX509ExtensionUtils().createAuthorityKeyIdentifier(credential.getPublicKey())); ContentSigner sigGen = new JcaContentSignerBuilder("SHA1withRSA").setProvider("BC") .build(credential.getPrivateKey()); X509CertificateHolder certificateHolder = gen.build(sigGen); X509Certificate x509Certificate = new JcaX509CertificateConverter().setProvider("BC") .getCertificate(certificateHolder); return x509Certificate; }