Crypto: Test for broken Gentoo ECDSA support

Add SystemVersion.isJava9()
This commit is contained in:
zzz
2015-10-11 15:39:28 +00:00
parent 971a2652e3
commit 55a6f44651
4 changed files with 46 additions and 3 deletions

View File

@ -11,7 +11,9 @@ import java.util.Map;
import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable;
import net.i2p.data.Hash;
import net.i2p.data.SigningPrivateKey;
import net.i2p.data.SimpleDataStructure;
import net.i2p.util.SystemVersion;
/**
* Defines the properties for various signature types
@ -193,8 +195,24 @@ public enum SigType {
return true;
try {
getParams();
if (getBaseAlgorithm() != SigAlgo.EdDSA)
Signature.getInstance(getAlgorithmName());
if (getBaseAlgorithm() != SigAlgo.EdDSA) {
Signature jsig = Signature.getInstance(getAlgorithmName());
if (getBaseAlgorithm() == SigAlgo.EC && SystemVersion.isGentoo() ) {
// Do a full keygen/sign test on Gentoo, because it lies. Keygen works but sigs fail.
// https://bugs.gentoo.org/show_bug.cgi?id=528338
// http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=2497
// http://zzz.i2p/topics/1931
// Be sure nothing in the code paths below calls isAvailable()
// get an I2P keypair
SimpleDataStructure[] keys = KeyGenerator.getInstance().generateSigningKeys(this);
SigningPrivateKey privKey = (SigningPrivateKey) keys[1];
// convert privkey back to Java key and sign
jsig.initSign(SigUtil.toJavaECKey(privKey));
// use the pubkey as random data
jsig.update(keys[0].getData());
jsig.sign();
}
}
getDigestInstance();
getHashInstance();
} catch (Exception e) {

View File

@ -18,6 +18,8 @@ public abstract class SystemVersion {
private static final boolean _isArm = System.getProperty("os.arch").startsWith("arm");
private static final boolean _isX86 = System.getProperty("os.arch").contains("86") ||
System.getProperty("os.arch").equals("amd64");
private static final boolean _isGentoo = System.getProperty("os.version").contains("gentoo") ||
System.getProperty("os.version").contains("hardened"); // Funtoo
private static final boolean _isAndroid;
private static final boolean _isApache;
private static final boolean _isGNU;
@ -27,6 +29,7 @@ public abstract class SystemVersion {
private static final boolean _oneDotSix;
private static final boolean _oneDotSeven;
private static final boolean _oneDotEight;
private static final boolean _oneDotNine;
private static final int _androidSDK;
static {
@ -62,10 +65,12 @@ public abstract class SystemVersion {
_oneDotSix = _androidSDK >= 9;
_oneDotSeven = _androidSDK >= 19;
_oneDotEight = false;
_oneDotNine = false;
} else {
_oneDotSix = VersionComparator.comp(System.getProperty("java.version"), "1.6") >= 0;
_oneDotSeven = _oneDotSix && VersionComparator.comp(System.getProperty("java.version"), "1.7") >= 0;
_oneDotEight = _oneDotSeven && VersionComparator.comp(System.getProperty("java.version"), "1.8") >= 0;
_oneDotNine = _oneDotEight && VersionComparator.comp(System.getProperty("java.version"), "1.9") >= 0;
}
}
@ -95,6 +100,13 @@ public abstract class SystemVersion {
return _isGNU;
}
/**
* @since 0.9.23
*/
public static boolean isGentoo() {
return _isGentoo;
}
/**
* @since 0.9.8
*/
@ -139,6 +151,15 @@ public abstract class SystemVersion {
return _oneDotEight;
}
/**
*
* @return true if Java 1.9 or higher, false for Android.
* @since 0.9.23
*/
public static boolean isJava9() {
return _oneDotNine;
}
/**
* This isn't always correct.
* http://stackoverflow.com/questions/807263/how-do-i-detect-which-kind-of-jre-is-installed-32bit-vs-64bit