Search in sources :

Example 6 with CertificateValidatorException

use of org.demoiselle.signer.core.exception.CertificateValidatorException in project signer by demoiselle.

the class RepositoryService method update.

private static void update(String url) {
    try {
        Configuration config = Configuration.getInstance();
        File fileCLR = new File(config.getCrlPath(), RepositoryUtil.urlToMD5(url));
        print(coreMessagesBundle.getString("info.repository.service.download", url));
        RepositoryUtil.saveURL(url, fileCLR);
        println("...[Ok]");
    } catch (CertificateValidatorException e) {
        println(coreMessagesBundle.getString("error.repository.service.fail"));
        println(coreMessagesBundle.getString("error.repository.service.cause") + e.getMessage());
    }
}
Also used : CertificateValidatorException(org.demoiselle.signer.core.exception.CertificateValidatorException) File(java.io.File)

Example 7 with CertificateValidatorException

use of org.demoiselle.signer.core.exception.CertificateValidatorException in project signer by demoiselle.

the class RepositoryUtil method saveURL.

/**
 * @param sUrl source url
 * @param destinationFile destination file
 */
public static void saveURL(String sUrl, File destinationFile) {
    URL url;
    byte[] buf;
    int ByteRead;
    setByteWritten(0);
    BufferedOutputStream outStream = null;
    URLConnection uCon = null;
    InputStream is = null;
    try {
        url = new URL(sUrl);
        uCon = url.openConnection();
        uCon.setConnectTimeout(5000);
        is = uCon.getInputStream();
        outStream = new BufferedOutputStream(new FileOutputStream(destinationFile));
        buf = new byte[1024];
        while ((ByteRead = is.read(buf)) != -1) {
            outStream.write(buf, 0, ByteRead);
            setByteWritten(getByteWritten() + ByteRead);
        }
    } catch (MalformedURLException e) {
        throw new CertificateValidatorException(coreMessagesBundle.getString("error.malformed.url", sUrl), e);
    } catch (FileNotFoundException e) {
        throw new CertificateValidatorException(coreMessagesBundle.getString("error.file.not.found", sUrl), e);
    } catch (IOException e) {
        logger.info(coreMessagesBundle.getString("error.crl.open.connection", sUrl) + e.getMessage());
    } finally {
        try {
            if (is != null) {
                is.close();
            }
            if (outStream != null) {
                outStream.close();
            }
        } catch (Throwable e) {
            throw new CertificateValidatorException(coreMessagesBundle.getString("error.crl.close.connection", sUrl), e);
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) InputStream(java.io.InputStream) CertificateValidatorException(org.demoiselle.signer.core.exception.CertificateValidatorException) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) URL(java.net.URL) URLConnection(java.net.URLConnection)

Aggregations

CertificateValidatorException (org.demoiselle.signer.core.exception.CertificateValidatorException)7 IOException (java.io.IOException)6 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 FileOutputStream (java.io.FileOutputStream)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 URLConnection (java.net.URLConnection)2 CertificateException (java.security.cert.CertificateException)2 X509Certificate (java.security.cert.X509Certificate)2 ParseException (java.text.ParseException)2 Date (java.util.Date)2 LinkedList (java.util.LinkedList)2 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)2 ASN1UTCTime (org.bouncycastle.asn1.ASN1UTCTime)2 Attribute (org.bouncycastle.asn1.cms.Attribute)2 AttributeTable (org.bouncycastle.asn1.cms.AttributeTable)2 X509CertificateHolder (org.bouncycastle.cert.X509CertificateHolder)2