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 18 commits
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: java
jdk: oraclejdk8
jdk: oraclejdk10
before_install:
grep -v '^#' src/main/resources/META-INF/services/bisq.asset.Asset | sort --check --dictionary-order --ignore-case
notifications:
Expand Down
2 changes: 1 addition & 1 deletion assets/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
group 'network.bisq'
version '-SNAPSHOT'

sourceCompatibility = 1.8
sourceCompatibility = 1.10

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
Expand Down
6 changes: 3 additions & 3 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ext {
protobufVersion = '3.5.1'
}

sourceCompatibility = 1.8
sourceCompatibility = 1.10

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
Expand Down Expand Up @@ -56,7 +56,7 @@ dependencies {
compile 'org.bouncycastle:bcpg-jdk15on:1.56'
compile 'commons-io:commons-io:2.4'
compile 'org.apache.commons:commons-lang3:3.4'
compileOnly 'org.projectlombok:lombok:1.16.16'
annotationProcessor 'org.projectlombok:lombok:1.16.16'
compileOnly 'org.projectlombok:lombok:1.18.2'
annotationProcessor 'org.projectlombok:lombok:1.18.2'
testCompile 'junit:junit:4.12'
}
31 changes: 19 additions & 12 deletions common/src/main/java/bisq/common/crypto/Encryption.java
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
31 changes: 22 additions & 9 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ plugins {
group = 'network.bisq'
version = '-SNAPSHOT'

sourceCompatibility = 1.8
sourceCompatibility = 1.10

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

def jmockitVersion = '1.42'

repositories {
jcenter()
maven { url 'https://jitpack.io' }
Expand Down Expand Up @@ -43,18 +45,29 @@ dependencies {
compile('com.fasterxml.jackson.core:jackson-databind:2.8.10') {
exclude(module: 'jackson-annotations')
}
compileOnly 'org.projectlombok:lombok:1.16.16'
annotationProcessor 'org.projectlombok:lombok:1.16.16'
compileOnly 'org.projectlombok:lombok:1.18.2'
annotationProcessor 'org.projectlombok:lombok:1.18.2'

testCompile "org.jmockit:jmockit:$jmockitVersion"
testCompile 'junit:junit:4.12'
testCompile('org.mockito:mockito-core:2.8.9') {
testCompile('org.mockito:mockito-core:2.21.0') {
exclude(module: 'objenesis')
}
testCompile 'org.powermock:powermock-module-junit4:1.7.1'
testCompile 'org.powermock:powermock-api-mockito2:1.7.1'
testCompile 'org.jmockit:jmockit:1.30'
testCompile 'org.powermock:powermock-module-junit4:2.0.0-beta.5'
testCompile 'org.powermock:powermock-api-mockito2:2.0.0-beta.5'


testCompile 'org.springframework:spring-test:4.3.6.RELEASE'
testCompile 'com.natpryce:make-it-easy:4.0.1'
testCompile group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
testCompileOnly 'org.projectlombok:lombok:1.16.16'
testAnnotationProcessor 'org.projectlombok:lombok:1.16.16'
testCompileOnly 'org.projectlombok:lombok:1.18.2'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.2'
}

test {
systemProperty 'jdk.attach.allowAttachSelf', true

def jmockit = configurations.testCompile.files.find { it.name.contains("jmockit") }.absolutePath
jvmArgs "-javaagent:$jmockit"
}

3 changes: 0 additions & 3 deletions core/src/main/java/bisq/core/app/BisqSetup.java
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import java.util.ArrayList;

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

Expand All @@ -43,12 +44,10 @@

@RunWith(PowerMockRunner.class)
@PrepareForTest({User.class, ArbitratorService.class})
@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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.util.List;

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

Expand All @@ -38,6 +39,7 @@

@RunWith(PowerMockRunner.class)
@PrepareForTest(Preferences.class)
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*"})
public class WalletSetupPreferencesTest {
@Test
public void testSelectPreferredNodesWhenPublicOption() {
Expand Down
Loading