* I2CP Client: Generate revocation key of same type as signing key

* i2ptunnel: Only offer Sig options that are available in the JVM
 * LeaseSet: Add check for SigTYpe mismatch
 * SigType: Add isAvailable()
This commit is contained in:
zzz
2014-02-21 17:47:30 +00:00
parent 3102970540
commit 18b4a2427b
8 changed files with 70 additions and 3 deletions

View File

@ -9,6 +9,7 @@ package net.i2p.client;
*
*/
import java.security.GeneralSecurityException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -25,6 +26,7 @@ import net.i2p.data.PublicKey;
import net.i2p.data.SessionKey;
import net.i2p.data.SigningPrivateKey;
import net.i2p.data.SigningPublicKey;
import net.i2p.data.SimpleDataStructure;
import net.i2p.data.i2cp.I2CPMessage;
import net.i2p.data.i2cp.RequestLeaseSetMessage;
import net.i2p.util.Log;
@ -129,9 +131,16 @@ class RequestLeaseSetMessageHandler extends HandlerImpl {
private final PrivateKey _privKey;
private final SigningPublicKey _signingPubKey;
private final SigningPrivateKey _signingPrivKey;
public LeaseInfo(Destination dest) {
Object encKeys[] = KeyGenerator.getInstance().generatePKIKeypair();
Object signKeys[] = KeyGenerator.getInstance().generateSigningKeypair();
// must be same type as the Destination's signing key
SimpleDataStructure signKeys[];
try {
signKeys = KeyGenerator.getInstance().generateSigningKeys(dest.getSigningPublicKey().getType());
} catch (GeneralSecurityException gse) {
throw new IllegalStateException(gse);
}
_pubKey = (PublicKey) encKeys[0];
_privKey = (PrivateKey) encKeys[1];
_signingPubKey = (SigningPublicKey) signKeys[0];

View File

@ -2,6 +2,7 @@ package net.i2p.crypto;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.Signature;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.InvalidParameterSpecException;
import java.util.HashMap;
@ -159,6 +160,24 @@ public enum SigType {
}
}
/**
* @since 0.9.12
* @return true if supported in this JVM
*/
public boolean isAvailable() {
if (DSA_SHA1 == this)
return true;
try {
getParams();
Signature.getInstance(getAlgorithmName());
getDigestInstance();
getHashInstance();
} catch (Exception e) {
return false;
}
return true;
}
private static final Map<Integer, SigType> BY_CODE = new HashMap<Integer, SigType>();
static {

View File

@ -137,12 +137,23 @@ public class LeaseSet extends DatabaseEntry {
_encryptionKey = encryptionKey;
}
/** @deprecated unused */
/**
* The revocation key.
* @deprecated unused
*/
public SigningPublicKey getSigningKey() {
return _signingKey;
}
/**
* The revocation key. Unused.
* Must be the same type as the Destination's SigningPublicKey.
* @throws IllegalArgumentException if different type
*/
public void setSigningKey(SigningPublicKey key) {
if (key != null && _destination != null &&
key.getType() != _destination.getSigningPublicKey().getType())
throw new IllegalArgumentException("Signing key type mismatch");
_signingKey = key;
}