Skip to content

Commit

Permalink
Merge pull request #397 from arthurscchan/illegalstateexception
Browse files Browse the repository at this point in the history
Exception handling: Wrap illegal state exception
  • Loading branch information
loosebazooka authored Mar 24, 2023
2 parents c0f8ce0 + c13b6d8 commit a01c405
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion sigstore-java/src/main/java/dev/sigstore/encryption/Keys.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,17 @@ public static PublicKey parsePublicKey(byte[] keyBytes)
// otherwise, we are dealing with PKIX X509 encoded keys
byte[] content = section.getContent();
EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(content);
AsymmetricKeyParameter keyParameters = PublicKeyFactory.createKey(content);
AsymmetricKeyParameter keyParameters = null;

// Ensure PEM content can be parsed correctly
try {
keyParameters = PublicKeyFactory.createKey(content);
} catch (IllegalStateException e) {
throw new InvalidKeySpecException("Invalid key, could not parse PEM content");
}
if (keyParameters == null) {
throw new InvalidKeySpecException("Invalid key, could not parse PEM content");
}

// get algorithm inspecting the created class
String keyAlgorithm = extractKeyAlgorithm(keyParameters);
Expand Down

0 comments on commit a01c405

Please sign in to comment.