Merge branch 'master' into Development

This commit is contained in:
Manfred Karrer 2016-10-20 13:03:22 +02:00
commit e3bd595048
8 changed files with 75 additions and 53 deletions

View file

@ -0,0 +1,24 @@
/*
* This file is part of Bitsquare.
*
* Bitsquare is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bitsquare.common.util;
public class LimitedKeyStrengthException extends Exception {
public LimitedKeyStrengthException() {
super("Default crypto policy has not been changed. Only weak keys with length 128 are allowed by the default policy.");
}
}

View file

@ -30,15 +30,13 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.crypto.Cipher;
import java.awt.*;
import java.io.*;
import java.lang.reflect.Field;
import java.net.URI;
import java.net.URLConnection;
import java.security.Permission;
import java.security.PermissionCollection;
import java.security.NoSuchAlgorithmException;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.*;
@ -408,42 +406,11 @@ public class Utilities {
}
}
// See: https://stackoverflow.com/questions/1179672/how-to-avoid-installing-unlimited-strength-jce-policy-files-when-deploying-an
public static void removeCryptographyRestrictions() {
if (!isRestrictedCryptography()) {
log.debug("Cryptography restrictions removal not needed");
return;
}
try {
final Class<?> jceSecurity = Class.forName("javax.crypto.JceSecurity");
final Class<?> cryptoPermissions = Class.forName("javax.crypto.CryptoPermissions");
final Class<?> cryptoAllPermission = Class.forName("javax.crypto.CryptoAllPermission");
final Field isRestrictedField = jceSecurity.getDeclaredField("isRestricted");
isRestrictedField.setAccessible(true);
isRestrictedField.set(null, false);
final Field defaultPolicyField = jceSecurity.getDeclaredField("defaultPolicy");
defaultPolicyField.setAccessible(true);
final PermissionCollection defaultPolicy = (PermissionCollection) defaultPolicyField.get(null);
final Field perms = cryptoPermissions.getDeclaredField("perms");
perms.setAccessible(true);
((Map<?, ?>) perms.get(defaultPolicy)).clear();
final Field instance = cryptoAllPermission.getDeclaredField("INSTANCE");
instance.setAccessible(true);
defaultPolicy.add((Permission) instance.get(null));
log.debug("Successfully removed cryptography restrictions");
} catch (Exception e) {
log.warn("Failed to remove cryptography restrictions", e);
}
}
public static boolean isRestrictedCryptography() {
// This simply matches the Oracle JRE, but not OpenJDK.
return "Java(TM) SE Runtime Environment".equals(System.getProperty("java.runtime.name"));
public static void checkCryptoPolicySetup() throws NoSuchAlgorithmException, LimitedKeyStrengthException {
if (Cipher.getMaxAllowedKeyLength("AES") > 128)
log.debug("Congratulations, you have unlimited key length support!");
else
throw new LimitedKeyStrengthException();
}
public static String toTruncatedString(Object message, int maxLenght) {

View file

@ -27,6 +27,7 @@ import io.bitsquare.btc.WalletService;
import io.bitsquare.common.CommonOptionKeys;
import io.bitsquare.common.UserThread;
import io.bitsquare.common.handlers.ResultHandler;
import io.bitsquare.common.util.LimitedKeyStrengthException;
import io.bitsquare.common.util.Profiler;
import io.bitsquare.common.util.Utilities;
import io.bitsquare.filter.FilterManager;
@ -74,6 +75,7 @@ import org.springframework.core.env.Environment;
import java.io.IOException;
import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
import java.security.Security;
import java.util.ArrayList;
import java.util.List;
@ -118,6 +120,8 @@ public class BitsquareApp extends Application {
UserThread.setExecutor(Platform::runLater);
UserThread.setTimerClass(UITimer.class);
shutDownHandler = this::stop;
// setup UncaughtExceptionHandler
Thread.UncaughtExceptionHandler handler = (thread, throwable) -> {
// Might come from another thread
@ -136,11 +140,14 @@ public class BitsquareApp extends Application {
Thread.setDefaultUncaughtExceptionHandler(handler);
Thread.currentThread().setUncaughtExceptionHandler(handler);
if (Utilities.isRestrictedCryptography())
Utilities.removeCryptographyRestrictions();
Security.addProvider(new BouncyCastleProvider());
try {
Utilities.checkCryptoPolicySetup();
} catch (NoSuchAlgorithmException | LimitedKeyStrengthException e) {
e.printStackTrace();
UserThread.execute(() -> showErrorPopup(e, true));
}
shutDownHandler = this::stop;
Security.addProvider(new BouncyCastleProvider());
try {
// Guice

View file

@ -12,6 +12,7 @@ import io.bitsquare.btc.WalletService;
import io.bitsquare.common.CommonOptionKeys;
import io.bitsquare.common.UserThread;
import io.bitsquare.common.handlers.ResultHandler;
import io.bitsquare.common.util.LimitedKeyStrengthException;
import io.bitsquare.common.util.Utilities;
import io.bitsquare.p2p.P2PService;
import io.bitsquare.p2p.P2PServiceListener;
@ -25,6 +26,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
import java.security.Security;
public class Headless {
@ -66,8 +68,12 @@ public class Headless {
Thread.setDefaultUncaughtExceptionHandler(handler);
Thread.currentThread().setUncaughtExceptionHandler(handler);
if (Utilities.isRestrictedCryptography())
Utilities.removeCryptographyRestrictions();
try {
Utilities.checkCryptoPolicySetup();
} catch (NoSuchAlgorithmException | LimitedKeyStrengthException e) {
e.printStackTrace();
UserThread.execute(this::shutDown);
}
Security.addProvider(new BouncyCastleProvider());

View file

@ -12,6 +12,7 @@ import io.bitsquare.btc.WalletService;
import io.bitsquare.common.CommonOptionKeys;
import io.bitsquare.common.UserThread;
import io.bitsquare.common.handlers.ResultHandler;
import io.bitsquare.common.util.LimitedKeyStrengthException;
import io.bitsquare.common.util.Utilities;
import io.bitsquare.p2p.P2PService;
import io.bitsquare.p2p.P2PServiceListener;
@ -25,6 +26,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
import java.security.Security;
public class Monitor {
@ -67,8 +69,12 @@ public class Monitor {
Thread.setDefaultUncaughtExceptionHandler(handler);
Thread.currentThread().setUncaughtExceptionHandler(handler);
if (Utilities.isRestrictedCryptography())
Utilities.removeCryptographyRestrictions();
try {
Utilities.checkCryptoPolicySetup();
} catch (NoSuchAlgorithmException | LimitedKeyStrengthException e) {
e.printStackTrace();
UserThread.execute(this::shutDown);
}
Security.addProvider(new BouncyCastleProvider());

View file

@ -12,6 +12,7 @@ import io.bitsquare.btc.WalletService;
import io.bitsquare.common.CommonOptionKeys;
import io.bitsquare.common.UserThread;
import io.bitsquare.common.handlers.ResultHandler;
import io.bitsquare.common.util.LimitedKeyStrengthException;
import io.bitsquare.common.util.Utilities;
import io.bitsquare.p2p.BootstrapListener;
import io.bitsquare.p2p.P2PService;
@ -25,6 +26,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
import java.security.Security;
public class SeedNode {
@ -65,8 +67,12 @@ public class SeedNode {
Thread.setDefaultUncaughtExceptionHandler(handler);
Thread.currentThread().setUncaughtExceptionHandler(handler);
if (Utilities.isRestrictedCryptography())
Utilities.removeCryptographyRestrictions();
try {
Utilities.checkCryptoPolicySetup();
} catch (NoSuchAlgorithmException | LimitedKeyStrengthException e) {
e.printStackTrace();
UserThread.execute(this::shutDown);
}
Security.addProvider(new BouncyCastleProvider());

View file

@ -13,6 +13,7 @@ import io.bitsquare.btc.pricefeed.PriceFeedService;
import io.bitsquare.common.CommonOptionKeys;
import io.bitsquare.common.UserThread;
import io.bitsquare.common.handlers.ResultHandler;
import io.bitsquare.common.util.LimitedKeyStrengthException;
import io.bitsquare.common.util.Utilities;
import io.bitsquare.locale.CurrencyUtil;
import io.bitsquare.p2p.BootstrapListener;
@ -28,6 +29,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
import java.security.Security;
public class Statistics {
@ -70,8 +72,12 @@ public class Statistics {
Thread.setDefaultUncaughtExceptionHandler(handler);
Thread.currentThread().setUncaughtExceptionHandler(handler);
if (Utilities.isRestrictedCryptography())
Utilities.removeCryptographyRestrictions();
try {
Utilities.checkCryptoPolicySetup();
} catch (NoSuchAlgorithmException | LimitedKeyStrengthException e) {
e.printStackTrace();
UserThread.execute(this::shutDown);
}
Security.addProvider(new BouncyCastleProvider());