From dfbe3c4eb184214689abc7a4dd9e46ba79a31b0b Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Wed, 9 Jul 2014 13:29:52 +0000
Subject: [PATCH] signing key type check

---
 core/java/src/net/i2p/crypto/KeyGenerator.java | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/core/java/src/net/i2p/crypto/KeyGenerator.java b/core/java/src/net/i2p/crypto/KeyGenerator.java
index 025da6f592..34cd1f3465 100644
--- a/core/java/src/net/i2p/crypto/KeyGenerator.java
+++ b/core/java/src/net/i2p/crypto/KeyGenerator.java
@@ -159,6 +159,7 @@ public class KeyGenerator {
     /** Convert a PrivateKey to its corresponding PublicKey
      * @param priv PrivateKey object
      * @return the corresponding PublicKey object
+     * @throws IllegalArgumentException on bad key
      */
     public static PublicKey getPublicKey(PrivateKey priv) {
         BigInteger a = new NativeBigInteger(1, priv.toByteArray());
@@ -265,8 +266,11 @@ public class KeyGenerator {
      *
      * @param priv a SigningPrivateKey object
      * @return a SigningPublicKey object
+     * @throws IllegalArgumentException on bad key
      */
     public static SigningPublicKey getSigningPublicKey(SigningPrivateKey priv) {
+        if (priv.getType() != SigType.DSA_SHA1)
+            throw new IllegalArgumentException();
         BigInteger x = new NativeBigInteger(1, priv.toByteArray());
         BigInteger y = CryptoConstants.dsag.modPow(x, CryptoConstants.dsap);
         SigningPublicKey pub = new SigningPublicKey();
-- 
GitLab