|
50 | 50 | import java.util.ArrayList; |
51 | 51 | import java.util.Arrays; |
52 | 52 | import java.util.List; |
53 | | -import java.util.logging.Level; |
54 | 53 | import java.util.logging.Logger; |
55 | 54 | import java.util.stream.Collectors; |
56 | 55 | import org.apache.commons.codec.binary.Hex; |
@@ -245,13 +244,24 @@ private static final PEMEncodable convertedPemToPemDecodable(Object object, char |
245 | 244 | + object.getClass().getName()); |
246 | 245 | } |
247 | 246 | } catch (PKCSException | InvalidKeySpecException e) { |
248 | | - LOGGER.log(Level.WARNING, "Could not read PEM encrypted information", e); |
249 | | - throw new UnrecoverableKeyException(); |
| 247 | + UnrecoverableKeyException unrecoverableKeyEx = new UnrecoverableKeyException(e.getMessage()); |
| 248 | + unrecoverableKeyEx.initCause(e); |
| 249 | + throw unrecoverableKeyEx; |
250 | 250 | } catch (CertificateException e) { |
251 | 251 | throw new IOException("Could not read certificate", e); |
252 | 252 | } catch (NoSuchAlgorithmException e) { |
253 | | - throw new AssertionError( |
254 | | - "RSA algorithm support is mandated by Java Language Specification. See https://docs.oracle.com/javase/7/docs/api/java/security/KeyFactory.html"); |
| 253 | + throw new IOException("Algorithm required for parsing is not implemented", e); |
| 254 | + } catch (AssertionError e) { |
| 255 | + // when using the FIPS BC variety org.bouncycastle.crypto.fips.FipsUnapprovedOperationError can be throw |
| 256 | + // if the encoded object is not FIPS compliant. |
| 257 | + // there are no known subclasses so just match on the classname. |
| 258 | + if (e.getClass().getName().equals("org.bouncycastle.crypto.fips.FipsUnapprovedOperationError")) { |
| 259 | + UnrecoverableKeyException unrecoverableKeyEx = |
| 260 | + new UnrecoverableKeyException("Provided Object is not FIPS 140 compliant"); |
| 261 | + unrecoverableKeyEx.initCause(e); |
| 262 | + throw unrecoverableKeyEx; |
| 263 | + } |
| 264 | + throw e; |
255 | 265 | } |
256 | 266 | } |
257 | 267 |
|
|
0 commit comments