Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 10 support #1660

Merged
merged 21 commits into from Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9b4b062
Clean up errors for testing
ripcurlx Aug 21, 2018
4725191
Remove files that use classes that can't be accessed anymore
ripcurlx Sep 5, 2018
73e4ee5
Update lombok library
ripcurlx Sep 5, 2018
bd9a208
Update source compatibility to Java 10
ripcurlx Sep 7, 2018
5d23971
Update travis Java version
ripcurlx Sep 7, 2018
e319449
Make power mock tests Java 10 compatibile
ripcurlx Sep 7, 2018
8ed7f42
Add not working JMockit setup (help wanted)
ripcurlx Sep 7, 2018
13266b2
Use FXCollections instead of not existing ObservableListWrapper
ripcurlx Sep 7, 2018
dd6a372
Change progress indicator skin to work with Java 9+
ripcurlx Sep 10, 2018
2efe20a
Add temporary workaround for running desktop build
ripcurlx Sep 11, 2018
672e362
Add -srcdir for Java 10 javapackager
ripcurlx Sep 11, 2018
64370f7
Fix JMockit setup
ripcurlx Sep 13, 2018
1c783e4
Update fontawesome library
ripcurlx Sep 14, 2018
4c068af
Use default security provider instead of Bouncy Castle
ripcurlx Sep 14, 2018
40eadcc
Merge branch 'master' into java10-support
ripcurlx Sep 14, 2018
28c96d6
Merge branch 'master' of github.com:bisq-network/bisq-desktop into ja…
ripcurlx Sep 15, 2018
68fb116
Add Java 10 configuration for merged repositories
ripcurlx Sep 17, 2018
a8dd11c
Add workaround to prevent javapackager to fail because of module conf…
ripcurlx Sep 18, 2018
f7e4e5a
Add missing result handler execution
ripcurlx Sep 18, 2018
0643357
Clear list before setting all currencies
ripcurlx Sep 18, 2018
db17991
Remove not thrown exceptions
ripcurlx Sep 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 19 additions & 12 deletions common/src/main/java/bisq/common/crypto/Encryption.java
Expand Up @@ -25,6 +25,8 @@
import javax.crypto.KeyGenerator;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.OAEPParameterSpec;
import javax.crypto.spec.PSource;
import javax.crypto.spec.SecretKeySpec;

import java.security.InvalidKeyException;
Expand All @@ -36,6 +38,7 @@
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.MGF1ParameterSpec;
import java.security.spec.X509EncodedKeySpec;

import java.io.ByteArrayOutputStream;
Expand All @@ -51,7 +54,7 @@ public class Encryption {
private static final Logger log = LoggerFactory.getLogger(Encryption.class);

public static final String ASYM_KEY_ALGO = "RSA";
private static final String ASYM_CIPHER = "RSA/None/OAEPWithSHA256AndMGF1Padding";
private static final String ASYM_CIPHER = "RSA/ECB/OAEPWithSHA-256AndMGF1PADDING";

private static final String SYM_KEY_ALGO = "AES";
private static final String SYM_CIPHER = "AES";
Expand All @@ -61,7 +64,7 @@ public class Encryption {
public static KeyPair generateKeyPair() {
long ts = System.currentTimeMillis();
try {
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(ASYM_KEY_ALGO, "BC");
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(ASYM_KEY_ALGO);
keyPairGenerator.initialize(2048);
KeyPair keyPair = keyPairGenerator.genKeyPair();
log.trace("Generate msgEncryptionKeyPair needed {} ms", System.currentTimeMillis() - ts);
Expand All @@ -80,7 +83,7 @@ public static KeyPair generateKeyPair() {

public static byte[] encrypt(byte[] payload, SecretKey secretKey) throws CryptoException {
try {
Cipher cipher = Cipher.getInstance(SYM_CIPHER, "BC");
Cipher cipher = Cipher.getInstance(SYM_CIPHER);
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
return cipher.doFinal(payload);
} catch (Throwable e) {
Expand All @@ -91,7 +94,7 @@ public static byte[] encrypt(byte[] payload, SecretKey secretKey) throws CryptoE

public static byte[] decrypt(byte[] encryptedPayload, SecretKey secretKey) throws CryptoException {
try {
Cipher cipher = Cipher.getInstance(SYM_CIPHER, "BC");
Cipher cipher = Cipher.getInstance(SYM_CIPHER);
cipher.init(Cipher.DECRYPT_MODE, secretKey);
return cipher.doFinal(encryptedPayload);
} catch (Throwable e) {
Expand Down Expand Up @@ -157,7 +160,7 @@ private static boolean verifyHmac(byte[] message, byte[] hmac, SecretKey secretK
}

private static byte[] getHmac(byte[] payload, SecretKey secretKey) throws NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException {
Mac mac = Mac.getInstance(HMAC, "BC");
Mac mac = Mac.getInstance(HMAC);
mac.init(secretKey);
return mac.doFinal(payload);
}
Expand Down Expand Up @@ -195,8 +198,10 @@ public static byte[] decryptPayloadWithHmac(byte[] encryptedPayloadWithHmac, Sec

public static byte[] encryptSecretKey(SecretKey secretKey, PublicKey publicKey) throws CryptoException {
try {
Cipher cipher = Cipher.getInstance(ASYM_CIPHER, "BC");
cipher.init(Cipher.WRAP_MODE, publicKey);
Cipher cipher = Cipher.getInstance(ASYM_CIPHER);
OAEPParameterSpec oaepParameterSpec = new OAEPParameterSpec("SHA-256", "MGF1",
MGF1ParameterSpec.SHA256, PSource.PSpecified.DEFAULT);
cipher.init(Cipher.WRAP_MODE, publicKey, oaepParameterSpec);
return cipher.wrap(secretKey);
} catch (Throwable e) {
e.printStackTrace();
Expand All @@ -206,8 +211,10 @@ public static byte[] encryptSecretKey(SecretKey secretKey, PublicKey publicKey)

public static SecretKey decryptSecretKey(byte[] encryptedSecretKey, PrivateKey privateKey) throws CryptoException {
try {
Cipher cipher = Cipher.getInstance(ASYM_CIPHER, "BC");
cipher.init(Cipher.UNWRAP_MODE, privateKey);
Cipher cipher = Cipher.getInstance(ASYM_CIPHER);
OAEPParameterSpec oaepParameterSpec = new OAEPParameterSpec("SHA-256", "MGF1",
MGF1ParameterSpec.SHA256, PSource.PSpecified.DEFAULT);
cipher.init(Cipher.UNWRAP_MODE, privateKey, oaepParameterSpec);
return (SecretKey) cipher.unwrap(encryptedSecretKey, "AES", Cipher.SECRET_KEY);
} catch (Throwable e) {
// errors when trying to decrypt foreign network_messages are normal
Expand All @@ -222,7 +229,7 @@ public static SecretKey decryptSecretKey(byte[] encryptedSecretKey, PrivateKey p

public static SecretKey generateSecretKey(int bits) {
try {
KeyGenerator keyPairGenerator = KeyGenerator.getInstance(SYM_KEY_ALGO, "BC");
KeyGenerator keyPairGenerator = KeyGenerator.getInstance(SYM_KEY_ALGO);
keyPairGenerator.init(bits);
return keyPairGenerator.generateKey();
} catch (Throwable e) {
Expand All @@ -242,8 +249,8 @@ public static byte[] getPublicKeyBytes(PublicKey encryptionPubKey) {
*/
public static PublicKey getPublicKeyFromBytes(byte[] encryptionPubKeyBytes) {
try {
return KeyFactory.getInstance(Encryption.ASYM_KEY_ALGO, "BC").generatePublic(new X509EncodedKeySpec(encryptionPubKeyBytes));
} catch (InvalidKeySpecException | NoSuchAlgorithmException | NoSuchProviderException e) {
return KeyFactory.getInstance(Encryption.ASYM_KEY_ALGO).generatePublic(new X509EncodedKeySpec(encryptionPubKeyBytes));
} catch (InvalidKeySpecException | NoSuchAlgorithmException e) {
log.error("Error creating sigPublicKey from bytes. sigPublicKeyBytes as hex={}, error={}", Utilities.bytesAsHexString(encryptionPubKeyBytes), e);
e.printStackTrace();
throw new KeyConversionException(e);
Expand Down
5 changes: 2 additions & 3 deletions common/src/main/java/bisq/common/crypto/Hash.java
Expand Up @@ -25,7 +25,6 @@

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;

import java.nio.ByteBuffer;

Expand All @@ -40,10 +39,10 @@ public class Hash {
*/
public static byte[] getSha256Hash(byte[] data) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256", "BC");
MessageDigest digest = MessageDigest.getInstance("SHA-256");
digest.update(data, 0, data.length);
return digest.digest();
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
} catch (NoSuchAlgorithmException e) {
log.error("Could not create MessageDigest for hash. " + e.toString());
e.printStackTrace();
throw new RuntimeException(e);
Expand Down
5 changes: 2 additions & 3 deletions common/src/main/java/bisq/common/crypto/KeyStorage.java
Expand Up @@ -28,7 +28,6 @@
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.interfaces.DSAParams;
Expand Down Expand Up @@ -121,7 +120,7 @@ public KeyPair loadKeyPair(KeyEntry keyEntry) {
FileUtil.rollingBackup(storageDir, keyEntry.getFileName() + ".key", 20);
// long now = System.currentTimeMillis();
try {
KeyFactory keyFactory = KeyFactory.getInstance(keyEntry.getAlgorithm(), "BC");
KeyFactory keyFactory = KeyFactory.getInstance(keyEntry.getAlgorithm());
PublicKey publicKey;
PrivateKey privateKey;

Expand Down Expand Up @@ -158,7 +157,7 @@ public KeyPair loadKeyPair(KeyEntry keyEntry) {

log.debug("load completed in {} msec", System.currentTimeMillis() - new Date().getTime());
return new KeyPair(publicKey, privateKey);
} catch (NoSuchAlgorithmException | InvalidKeySpecException | NoSuchProviderException e) {
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
e.printStackTrace();
log.error(e.getMessage());
throw new RuntimeException("Could not load key " + keyEntry.toString(), e);
Expand Down
17 changes: 8 additions & 9 deletions common/src/main/java/bisq/common/crypto/Sig.java
Expand Up @@ -28,7 +28,6 @@
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Signature;
Expand Down Expand Up @@ -60,12 +59,12 @@ public class Sig {
public static KeyPair generateKeyPair() {
long ts = System.currentTimeMillis();
try {
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KEY_ALGO, "BC");
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KEY_ALGO);
keyPairGenerator.initialize(1024);
KeyPair keyPair = keyPairGenerator.genKeyPair();
log.trace("Generate msgSignatureKeyPair needed {} ms", System.currentTimeMillis() - ts);
return keyPair;
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
log.error(e.toString());
throw new RuntimeException("Could not create key.");
Expand All @@ -80,11 +79,11 @@ public static KeyPair generateKeyPair() {
*/
public static byte[] sign(PrivateKey privateKey, byte[] data) throws CryptoException {
try {
Signature sig = Signature.getInstance(ALGO, "BC");
Signature sig = Signature.getInstance(ALGO);
sig.initSign(privateKey);
sig.update(data);
return sig.sign();
} catch (SignatureException | NoSuchProviderException | InvalidKeyException | NoSuchAlgorithmException e) {
} catch (SignatureException | InvalidKeyException | NoSuchAlgorithmException e) {
throw new CryptoException("Signing failed. " + e.getMessage());
}
}
Expand All @@ -107,11 +106,11 @@ public static String sign(PrivateKey privateKey, String message) throws CryptoEx
*/
public static boolean verify(PublicKey publicKey, byte[] data, byte[] signature) throws CryptoException {
try {
Signature sig = Signature.getInstance(ALGO, "BC");
Signature sig = Signature.getInstance(ALGO);
sig.initVerify(publicKey);
sig.update(data);
return sig.verify(signature);
} catch (SignatureException | NoSuchProviderException | InvalidKeyException | NoSuchAlgorithmException e) {
} catch (SignatureException | InvalidKeyException | NoSuchAlgorithmException e) {
throw new CryptoException("Signature verification failed. " + e.getMessage());
}
}
Expand All @@ -132,8 +131,8 @@ public static boolean verify(PublicKey publicKey, String message, String signatu
*/
public static PublicKey getPublicKeyFromBytes(byte[] sigPublicKeyBytes) {
try {
return KeyFactory.getInstance(Sig.KEY_ALGO, "BC").generatePublic(new X509EncodedKeySpec(sigPublicKeyBytes));
} catch (InvalidKeySpecException | NoSuchAlgorithmException | NoSuchProviderException e) {
return KeyFactory.getInstance(Sig.KEY_ALGO).generatePublic(new X509EncodedKeySpec(sigPublicKeyBytes));
} catch (InvalidKeySpecException | NoSuchAlgorithmException e) {
log.error("Error creating sigPublicKey from bytes. sigPublicKeyBytes as hex={}, error={}", Utilities.bytesAsHexString(sigPublicKeyBytes), e);
e.printStackTrace();
throw new KeyConversionException(e);
Expand Down
5 changes: 0 additions & 5 deletions common/src/main/java/bisq/common/setup/CommonSetup.java
Expand Up @@ -25,10 +25,7 @@

import org.apache.commons.lang3.exception.ExceptionUtils;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

import java.security.NoSuchAlgorithmException;
import java.security.Security;

import lombok.extern.slf4j.Slf4j;

Expand All @@ -38,8 +35,6 @@ public class CommonSetup {
public static void setup(UncaughtExceptionHandler uncaughtExceptionHandler) {
setupErrorHandler(uncaughtExceptionHandler);

Security.addProvider(new BouncyCastleProvider());

if (Utilities.isLinux())
System.setProperty("prism.lcdtext", "false");
}
Expand Down
3 changes: 0 additions & 3 deletions core/src/main/java/bisq/core/app/BisqSetup.java
Expand Up @@ -444,9 +444,6 @@ private void checkCryptoSetup() {
((Ping) tuple.getNetworkEnvelope()).getNonce() == payload.getNonce() &&
((Ping) tuple.getNetworkEnvelope()).getLastRoundTripTime() == payload.getLastRoundTripTime()) {
log.debug("Crypto test succeeded");

if (Security.getProvider("BC") == null)
throw new CryptoException("Security provider BountyCastle is not available.");
} else {
throw new CryptoException("Payload not correct after decryption");
}
Expand Down
8 changes: 0 additions & 8 deletions core/src/main/java/bisq/core/app/SetupUtils.java
Expand Up @@ -34,8 +34,6 @@
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;

import java.security.Security;

import java.util.Date;
import java.util.function.Consumer;

Expand Down Expand Up @@ -67,12 +65,6 @@ public void run() {
((Ping) tuple.getNetworkEnvelope()).getNonce() == payload.getNonce() &&
((Ping) tuple.getNetworkEnvelope()).getLastRoundTripTime() == payload.getLastRoundTripTime()) {
log.debug("Crypto test succeeded");

if (Security.getProvider("BC") != null) {
UserThread.execute(resultHandler::handleResult);
} else {
errorHandler.accept(new CryptoException("Security provider BountyCastle is not available."));
}
} else {
errorHandler.accept(new CryptoException("Payload not correct after decryption"));
}
Expand Down
Expand Up @@ -47,10 +47,7 @@
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*"})
public class ArbitratorManagerTest {

@Before
public void setUp() {
Security.addProvider(new BouncyCastleProvider());
}


@Test
public void testIsArbitratorAvailableForLanguage() {
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/bisq/core/crypto/EncryptionTest.java
Expand Up @@ -45,7 +45,7 @@ public class EncryptionTest {

@Before
public void setup() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, CryptoException {
Security.addProvider(new BouncyCastleProvider());

dir = File.createTempFile("temp_tests", "");
//noinspection ResultOfMethodCallIgnored
dir.delete();
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/bisq/core/crypto/SigTest.java
Expand Up @@ -51,7 +51,7 @@ public class SigTest {

@Before
public void setup() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, CryptoException {
Security.addProvider(new BouncyCastleProvider());

dir = File.createTempFile("temp_tests", "");
//noinspection ResultOfMethodCallIgnored
dir.delete();
Expand Down
Expand Up @@ -36,10 +36,7 @@
import static org.mockito.Mockito.mock;

public class SeedNodeAddressLookupTest {
@Before
public void setUp() {
Security.addProvider(new BouncyCastleProvider());
}


@Test
public void testResolveNodeAddressesWhenLocalAddressSpecified() {
Expand Down
Expand Up @@ -37,10 +37,7 @@
import static org.junit.Assert.assertTrue;

public class SeedNodeAddressesTest {
@Before
public void setUp() {
Security.addProvider(new BouncyCastleProvider());
}


@Test
public void testCollector() {
Expand Down
Expand Up @@ -38,10 +38,6 @@
import javafx.collections.FXCollections;
import javafx.collections.ObservableSet;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

import java.security.Security;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -128,7 +124,7 @@ public class TradesChartsViewModelTest {

@Before
public void setup() throws IOException {
Security.addProvider(new BouncyCastleProvider());

dir = File.createTempFile("temp_tests1", "");
//noinspection ResultOfMethodCallIgnored
dir.delete();
Expand Down
Expand Up @@ -27,17 +27,12 @@
import javafx.collections.FXCollections;
import javafx.collections.ObservableMap;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

import java.security.Security;

import java.util.ArrayList;

import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

Expand All @@ -50,10 +45,7 @@
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*"})
public class PreferencesViewModelTest {

@Before
public void setUp() {
Security.addProvider(new BouncyCastleProvider());
}


@Test
public void testGetArbitrationLanguages() {
Expand Down
Expand Up @@ -7,7 +7,6 @@
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class AccountNrValidatorTest {
Expand Down