public Collection engineReadAll() throws StreamParsingException { Certificate cert; List certs = new ArrayList(); while ((cert = (Certificate)engineRead()) != null) { certs.add(cert); } return certs; } }
/** * stores the given certificate into the keystore with the given alias name * * @param certAlias the alias name to be used for this certificate * @param certificate the X509 certificate data * @throws Exception in case of any issues related to certificate data parsing */ public static void addCertificate( String certAlias, byte[] certificate ) throws Exception { try { parser.engineInit( new ByteArrayInputStream( certificate ) ); X509Certificate cert = ( X509Certificate ) parser.engineRead(); ks.setCertificateEntry( certAlias, cert ); } catch ( Exception ex ) { LOG.warn( "failed to load the certificate associated with the alias {}", certAlias, ex ); throw ex; } }
private Set createCerts(List list, X509CertStoreSelector xselector) throws StoreException { Set certSet = new HashSet(); Iterator it = list.iterator(); X509CertParser parser = new X509CertParser(); while (it.hasNext()) { try { parser.engineInit(new ByteArrayInputStream((byte[])it .next())); X509Certificate cert = (X509Certificate)parser .engineRead(); if (xselector.match((Object)cert)) { certSet.add(cert); } } catch (Exception e) { } } return certSet; }
private X509Certificate extractCertificate(final String[] domains, InputStream inputStream) throws StreamParsingException { X509CertParser certParser = new X509CertParser(); certParser.engineInit(inputStream); X509Certificate certificate = (X509Certificate) certParser.engineRead(); certificateStorage.saveCertificate(domains, certificate); return certificate; }
certParser.engineInit(config.getEncryptionCertificate().getInputStream()); LOGGER.debug("Invoking certificate engine to parse the certificate {}", config.getEncryptionCertificate()); final X509CertificateObject cert = (X509CertificateObject) certParser.engineRead(); LOGGER.debug("Creating final credential based on the certificate {} and the private key", cert.getIssuerDN()); return new BasicX509Credential(cert, kp.getPrivate());
@Override public void saveCertificate(String[] domains, X509Certificate certificate) { for (String domain:domains){ try(OutputStream outputStream = new FileOutputStream(domain + ".crt")) { X509Utils.savePEM(outputStream, certificate); } catch (IOException e) { throw new CertificateStorageException(e); } } if (saveCAIntermediateCertificate){ try{ String caIntermediateCertificateURL = X509Utils.getCACertificateURL(certificate); if (caIntermediateCertificateURL != null){ X509CertificateObject caIntermediateCertificate; try(InputStream is = new URL(caIntermediateCertificateURL).openStream()){ X509CertParser certParser = new X509CertParser(); certParser.engineInit(is); caIntermediateCertificate = (X509CertificateObject) certParser.engineRead(); } for (String domain:domains){ try(OutputStream outputStream = new FileOutputStream(domain + ".chain.crt")) { X509Utils.savePEM(outputStream, caIntermediateCertificate); } } } }catch (IOException|StreamParsingException e) { throw new CertificateStorageException(e); } } }
certParser.engineInit(config.getEncryptionCertificate().getInputStream()); LOGGER.debug("Invoking certificate engine to parse the certificate [{}]", config.getEncryptionCertificate()); val cert = (X509CertificateObject) certParser.engineRead(); LOGGER.debug("Creating final credential based on the certificate [{}] and the private key", cert.getIssuerDN()); return new BasicX509Credential(cert, kp.getPrivate());
.getBytes() ) ); X509Certificate cert = ( X509Certificate ) parser.engineRead();