/** * Decodes X.509 certificates in DER or PEM format. * * @param certs encoded certs * * @return decoded certs * * @throws CertificateException thrown if the certificates can not be decoded * * @since 1.2 */ public static Collection<X509Certificate> decodeCertificate(File certs) throws CertificateException{ if(!certs.exists()){ throw new CertificateException("Certificate file " + certs.getAbsolutePath() + " does not exist"); } if(!certs.canRead()){ throw new CertificateException("Certificate file " + certs.getAbsolutePath() + " is not readable"); } try{ return decodeCertificate(DatatypeHelper.fileToByteArray(certs)); }catch(IOException e){ throw new CertificateException("Error reading certificate file " + certs.getAbsolutePath(), e); } }
/** * Decodes X.509 certificates in DER or PEM format. * * @param certs encoded certs * * @return decoded certs * * @throws CertificateException thrown if the certificates can not be decoded * * @since 1.2 */ public static Collection<X509Certificate> decodeCertificate(File certs) throws CertificateException{ if(!certs.exists()){ throw new CertificateException("Certificate file " + certs.getAbsolutePath() + " does not exist"); } if(!certs.canRead()){ throw new CertificateException("Certificate file " + certs.getAbsolutePath() + " is not readable"); } try{ return decodeCertificate(DatatypeHelper.fileToByteArray(certs)); }catch(IOException e){ throw new CertificateException("Error reading certificate file " + certs.getAbsolutePath(), e); } }
/** {@inheritDoc} */ protected byte[] fetchMetadata() throws MetadataProviderException { try { return super.fetchMetadata(); } catch (MetadataProviderException e) { if (metadataBackupFile.exists()) { log.warn("Problem reading metadata from remote source, processing existing backup file: {}", metadataBackupFile.getAbsolutePath()); try { return DatatypeHelper.fileToByteArray(metadataBackupFile); } catch (IOException ioe) { String errMsg = "Unable to retrieve metadata from backup file " + metadataBackupFile.getAbsolutePath(); log.error(errMsg, ioe); throw new MetadataProviderException(errMsg, ioe); } } else { log.error("Unable to read metadata from remote server and backup does not exist"); throw new MetadataProviderException( "Unable to read metadata from remote server and backup does not exist"); } } }
/** * Decodes RSA/DSA private keys in DER, PEM, or PKCS#8 (encrypted or unencrypted) formats. * * @param key encoded key * @param password decryption password or null if the key is not encrypted * * @return deocded private key * * @throws KeyException thrown if the key can not be decoded */ public static PrivateKey decodePrivateKey(File key, char[] password) throws KeyException { if (!key.exists()) { throw new KeyException("Key file " + key.getAbsolutePath() + " does not exist"); } if (!key.canRead()) { throw new KeyException("Key file " + key.getAbsolutePath() + " is not readable"); } try { return decodePrivateKey(DatatypeHelper.fileToByteArray(key), password); } catch (IOException e) { throw new KeyException("Error reading Key file " + key.getAbsolutePath(), e); } }
/** * Decodes RSA/DSA private keys in DER, PEM, or PKCS#8 (encrypted or unencrypted) formats. * * @param key encoded key * @param password decryption password or null if the key is not encrypted * * @return deocded private key * * @throws KeyException thrown if the key can not be decoded */ public static PrivateKey decodePrivateKey(File key, char[] password) throws KeyException { if (!key.exists()) { throw new KeyException("Key file " + key.getAbsolutePath() + " does not exist"); } if (!key.canRead()) { throw new KeyException("Key file " + key.getAbsolutePath() + " is not readable"); } try { return decodePrivateKey(DatatypeHelper.fileToByteArray(key), password); } catch (IOException e) { throw new KeyException("Error reading Key file " + key.getAbsolutePath(), e); } }
/** * Decodes CRLS in DER or PKCS#7 format. If in PKCS#7 format only the CRLs are decode, the rest of the content is * ignored. * * @param crls encoded CRLs * * @return decoded CRLs * * @throws CRLException thrown if the CRLs can not be decoded * * @since 1.2 */ public static Collection<X509CRL> decodeCRLs(File crls) throws CRLException{ if(!crls.exists()){ throw new CRLException("CRL file " + crls.getAbsolutePath() + " does not exist"); } if(!crls.canRead()){ throw new CRLException("CRL file " + crls.getAbsolutePath() + " is not readable"); } try{ return decodeCRLs(DatatypeHelper.fileToByteArray(crls)); }catch(IOException e){ throw new CRLException("Error reading CRL file " + crls.getAbsolutePath(), e); } }
/** * Decodes CRLS in DER or PKCS#7 format. If in PKCS#7 format only the CRLs are decode, the rest of the content is * ignored. * * @param crls encoded CRLs * * @return decoded CRLs * * @throws CRLException thrown if the CRLs can not be decoded * * @since 1.2 */ public static Collection<X509CRL> decodeCRLs(File crls) throws CRLException{ if(!crls.exists()){ throw new CRLException("CRL file " + crls.getAbsolutePath() + " does not exist"); } if(!crls.canRead()){ throw new CRLException("CRL file " + crls.getAbsolutePath() + " is not readable"); } try{ return decodeCRLs(DatatypeHelper.fileToByteArray(crls)); }catch(IOException e){ throw new CRLException("Error reading CRL file " + crls.getAbsolutePath(), e); } }