use of com.helger.commons.io.stream.NonBlockingBufferedInputStream in project as2-server by phax.
the class ImportCertCommand method importCert.
@Nonnull
protected CommandResult importCert(final IAliasedCertificateFactory certFx, final String sAlias, final String sFilename) throws IOException, CertificateException, OpenAS2Exception {
try (final FileInputStream fis = new FileInputStream(sFilename);
final NonBlockingBufferedInputStream bis = new NonBlockingBufferedInputStream(fis)) {
final CertificateFactory cf = CertificateFactory.getInstance("X.509");
while (bis.available() > 0) {
final Certificate aCert = cf.generateCertificate(bis);
if (aCert instanceof X509Certificate) {
certFx.addCertificate(sAlias, (X509Certificate) aCert, true);
final CommandResult cmdRes = new CommandResult(ECommandResultType.TYPE_OK, "Certificate(s) imported successfully");
cmdRes.addResult("Imported certificate: " + aCert.toString());
return cmdRes;
}
}
return new CommandResult(ECommandResultType.TYPE_ERROR, "No valid X509 certificates found");
}
}
Aggregations