use of com.sun.org.apache.xml.internal.security.keys.storage.StorageResolverException in project jdk8u_jdk by JetBrains.
the class CertsInFilesystemDirectoryResolver method readCertsFromHarddrive.
/**
* Method readCertsFromHarddrive
*
* @throws StorageResolverException
*/
private void readCertsFromHarddrive() throws StorageResolverException {
File certDir = new File(this.merlinsCertificatesDir);
List<String> al = new ArrayList<String>();
String[] names = certDir.list();
for (int i = 0; i < names.length; i++) {
String currentFileName = names[i];
if (currentFileName.endsWith(".crt")) {
al.add(names[i]);
}
}
CertificateFactory cf = null;
try {
cf = CertificateFactory.getInstance("X.509");
} catch (CertificateException ex) {
throw new StorageResolverException("empty", ex);
}
if (cf == null) {
throw new StorageResolverException("empty");
}
for (int i = 0; i < al.size(); i++) {
String filename = certDir.getAbsolutePath() + File.separator + al.get(i);
File file = new File(filename);
boolean added = false;
String dn = null;
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
X509Certificate cert = (X509Certificate) cf.generateCertificate(fis);
//add to ArrayList
cert.checkValidity();
this.certs.add(cert);
dn = cert.getSubjectX500Principal().getName();
added = true;
} catch (FileNotFoundException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Could not add certificate from file " + filename, ex);
}
} catch (CertificateNotYetValidException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Could not add certificate from file " + filename, ex);
}
} catch (CertificateExpiredException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Could not add certificate from file " + filename, ex);
}
} catch (CertificateException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Could not add certificate from file " + filename, ex);
}
} finally {
try {
if (fis != null) {
fis.close();
}
} catch (IOException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Could not add certificate from file " + filename, ex);
}
}
}
if (added && log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Added certificate: " + dn);
}
}
}
Aggregations