import java.io.StringWriter;
import java.security.Security;
import java.security.cert.Certificate;
+import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.util.ArrayList;
import java.util.List;
}
boolean isFileWithoutPemCertificate() throws TruststoreDataOperationException {
- List<Certificate> certificateList = extractCertificatesFromFile();
- return certificateList.isEmpty();
+ try {
+ List<Certificate> certificateList = extractCertificatesFromFile();
+ return certificateList.isEmpty();
+ } catch (TruststoreDataOperationException e) {
+ LOGGER.error("Cannot extract certificates from file: {}", storeFile.getPath());
+ }
+ return true;
}
String transformToStringInPemFormat(List<Certificate> certificates) throws TruststoreDataOperationException {
Security.addProvider(new BouncyCastleProvider());
CertificateFactory certFactory = CertificateFactory.getInstance(X_509_CERTIFICATE, BOUNCY_CASTLE_PROVIDER);
return new ArrayList<>(certFactory.generateCertificates(inputStream));
- } catch (Exception e) {
+ }
+ catch (CertificateException e) {
+ LOGGER.error("Cannot read certificates from file: {}", storeFile.getPath());
+ throw new TruststoreDataOperationException(e);
+ }
+ catch (Exception e) {
LOGGER.error("Cannot read certificates from file: {}", storeFile.getPath());
throw new TruststoreDataOperationException(e);
}