From 91408cbdcef9831858162cf09e281574ffa9585d Mon Sep 17 00:00:00 2001 From: zzz Date: Mon, 5 May 2014 19:49:24 +0000 Subject: [PATCH] SigUtil: Catch EdDSA IAE SU3File: Hide EdDSA and unavailable sig types from help text --- core/java/src/net/i2p/crypto/SU3File.java | 4 ++++ core/java/src/net/i2p/crypto/SigUtil.java | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/core/java/src/net/i2p/crypto/SU3File.java b/core/java/src/net/i2p/crypto/SU3File.java index b401c8f28..6647c8d45 100644 --- a/core/java/src/net/i2p/crypto/SU3File.java +++ b/core/java/src/net/i2p/crypto/SU3File.java @@ -515,6 +515,10 @@ public class SU3File { StringBuilder buf = new StringBuilder(256); buf.append("Available signature types:\n"); for (SigType t : EnumSet.allOf(SigType.class)) { + if (!t.isAvailable()) + continue; + if (t == SigType.EdDSA_SHA512_25519) + continue; // not supported by keytool, and does double hashing right now buf.append(" ").append(t).append("\t(code: ").append(t.getCode()).append(')'); if (t.getCode() == DEFAULT_SIG_CODE) buf.append(" DEFAULT"); diff --git a/core/java/src/net/i2p/crypto/SigUtil.java b/core/java/src/net/i2p/crypto/SigUtil.java index 3d423c662..cbf330ccb 100644 --- a/core/java/src/net/i2p/crypto/SigUtil.java +++ b/core/java/src/net/i2p/crypto/SigUtil.java @@ -248,14 +248,22 @@ public class SigUtil { private static EdDSAPublicKey cvtToJavaEdDSAKey(SigningPublicKey pk) throws GeneralSecurityException { - return new EdDSAPublicKey(new EdDSAPublicKeySpec( + try { + return new EdDSAPublicKey(new EdDSAPublicKeySpec( pk.getData(), (EdDSAParameterSpec) pk.getType().getParams())); + } catch (IllegalArgumentException iae) { + throw new InvalidKeyException(iae); + } } private static EdDSAPrivateKey cvtToJavaEdDSAKey(SigningPrivateKey pk) throws GeneralSecurityException { - return new EdDSAPrivateKey(new EdDSAPrivateKeySpec( + try { + return new EdDSAPrivateKey(new EdDSAPrivateKeySpec( pk.getData(), (EdDSAParameterSpec) pk.getType().getParams())); + } catch (IllegalArgumentException iae) { + throw new InvalidKeyException(iae); + } } public static SigningPublicKey fromJavaKey(EdDSAPublicKey pk, SigType type)