forked from bisq-network/bisq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use OAEPWithSHA256AndMGF1Padding for RSA, add tests
- Loading branch information
1 parent
37b31a5
commit 513bc79
Showing
5 changed files
with
196 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<appender name="CONSOLE_APPENDER" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%highlight(%d{MMM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{15}: %msg %xEx%n)</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="TRACE"> | ||
<appender-ref ref="CONSOLE_APPENDER"/> | ||
</root> | ||
|
||
<logger name="io.bitsquare.storage.Storage" level="WARN"/> | ||
<logger name="io.bitsquare.storage.FileManager" level="WARN"/> | ||
<logger name="io.bitsquare.locale.BSResources" level="ERROR"/> | ||
|
||
<!-- <logger name="io.bitsquare.p2p.peers.PeerGroup" level="TRACE"/> | ||
<logger name="io.bitsquare.p2p.P2PService" level="TRACE"/> | ||
<logger name="io.bitsquare.p2p.storage.ProtectedExpirableDataStorage" level="TRACE"/> | ||
<logger name="io.bitsquare.p2p.network.LocalhostNetworkNode" level="TRACE"/> | ||
<logger name="io.bitsquare.p2p.network.TorNetworkNode" level="TRACE"/> | ||
<logger name="io.bitsquare.p2p.network.NetworkNode" level="TRACE"/>--> | ||
|
||
|
||
<!-- <logger name="com.msopentech.thali.toronionproxy.OnionProxyManagerEventHandler" level="WARN"/> | ||
<logger name="io.bitsquare.btc.AddressBasedCoinSelector" level="WARN"/> | ||
<logger name="io.bitsquare.storage.Storage" level="WARN"/> | ||
<logger name="io.bitsquare.gui.util.Profiler" level="ERROR"/> | ||
<logger name="io.bitsquare.temp.storage.RemoteStorage" level="WARN"/> | ||
<logger name="io.bitsquare.storage.FileManager" level="WARN"/> | ||
<logger name="org.bitcoinj" level="WARN"/> | ||
<logger name="org.bitcoinj.core.BitcoinSerializer" level="WARN"/> | ||
<logger name="org.bitcoinj.core.Peer" level="WARN"/> | ||
<logger name="org.bitcoinj.core.HeadersMessage" level="WARN"/> | ||
<logger name="org.bitcoinj.core.AbstractBlockChain" level="ERROR"/>--> | ||
|
||
<logger name="com.msopentech.thali.toronionproxy.OnionProxyManagerEventHandler" level="INFO"/> | ||
<logger name="org.bitcoinj" level="WARN"/> | ||
|
||
</configuration> |
80 changes: 80 additions & 0 deletions
80
common/src/test/java/io/bitsquare/common/crypto/EncryptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package io.bitsquare.common.crypto; | ||
|
||
import io.bitsquare.common.util.Utilities; | ||
import org.bouncycastle.jce.provider.BouncyCastleProvider; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.Serializable; | ||
import java.security.KeyStoreException; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.security.Security; | ||
import java.security.cert.CertificateException; | ||
import java.util.Random; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class EncryptionTest { | ||
private static final Logger log = LoggerFactory.getLogger(EncryptionTest.class); | ||
private KeyRing keyRing; | ||
private File dir; | ||
|
||
@Before | ||
public void setup() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, CryptoException { | ||
Security.addProvider(new BouncyCastleProvider()); | ||
dir = File.createTempFile("temp_tests", ""); | ||
dir.delete(); | ||
dir.mkdir(); | ||
KeyStorage keyStorage = new KeyStorage(dir); | ||
keyRing = new KeyRing(keyStorage); | ||
} | ||
|
||
@After | ||
public void tearDown() throws IOException { | ||
Utilities.deleteDirectory(dir); | ||
} | ||
|
||
|
||
@Test | ||
public void testDecryptHybridWithSignature() { | ||
long ts = System.currentTimeMillis(); | ||
log.trace("start "); | ||
for (int i = 0; i < 100; i++) { | ||
MockMessage payload = new MockMessage(new Random().nextInt()); | ||
SealedAndSigned sealedAndSigned = null; | ||
try { | ||
sealedAndSigned = Encryption.encryptHybridWithSignature(payload, | ||
keyRing.getSignatureKeyPair(), keyRing.getPubKeyRing().getEncryptionPubKey()); | ||
} catch (CryptoException e) { | ||
log.error("encryptHybridWithSignature failed"); | ||
e.printStackTrace(); | ||
assertTrue(false); | ||
} | ||
try { | ||
DecryptedDataTuple tuple = Encryption.decryptHybridWithSignature(sealedAndSigned, keyRing.getEncryptionKeyPair().getPrivate()); | ||
assertEquals(((MockMessage) tuple.payload).nonce, payload.nonce); | ||
} catch (CryptoException e) { | ||
log.error("decryptHybridWithSignature failed"); | ||
e.printStackTrace(); | ||
assertTrue(false); | ||
} | ||
} | ||
log.trace("took " + (System.currentTimeMillis() - ts) + " ms."); | ||
} | ||
|
||
private static class MockMessage implements Serializable { | ||
public int nonce; | ||
|
||
public MockMessage(int nonce) { | ||
this.nonce = nonce; | ||
} | ||
} | ||
} | ||
|
||
|
68 changes: 68 additions & 0 deletions
68
common/src/test/java/io/bitsquare/common/crypto/SigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package io.bitsquare.common.crypto; | ||
|
||
import io.bitsquare.common.util.Utilities; | ||
import org.bouncycastle.jce.provider.BouncyCastleProvider; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.security.KeyStoreException; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.security.Security; | ||
import java.security.cert.CertificateException; | ||
import java.util.Random; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
public class SigTest { | ||
private static final Logger log = LoggerFactory.getLogger(SigTest.class); | ||
private KeyRing keyRing; | ||
private File dir; | ||
|
||
@Before | ||
public void setup() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, CryptoException { | ||
Security.addProvider(new BouncyCastleProvider()); | ||
dir = File.createTempFile("temp_tests", ""); | ||
dir.delete(); | ||
dir.mkdir(); | ||
KeyStorage keyStorage = new KeyStorage(dir); | ||
keyRing = new KeyRing(keyStorage); | ||
} | ||
|
||
@After | ||
public void tearDown() throws IOException { | ||
Utilities.deleteDirectory(dir); | ||
} | ||
|
||
|
||
@Test | ||
public void testSignature() { | ||
long ts = System.currentTimeMillis(); | ||
log.trace("start "); | ||
for (int i = 0; i < 100; i++) { | ||
String msg = String.valueOf(new Random().nextInt()); | ||
String sig = null; | ||
try { | ||
sig = Sig.sign(keyRing.getSignatureKeyPair().getPrivate(), msg); | ||
} catch (CryptoException e) { | ||
log.error("sign failed"); | ||
e.printStackTrace(); | ||
assertTrue(false); | ||
} | ||
try { | ||
assertTrue(Sig.verify(keyRing.getSignatureKeyPair().getPublic(), msg, sig)); | ||
} catch (CryptoException e) { | ||
log.error("verify failed"); | ||
e.printStackTrace(); | ||
assertTrue(false); | ||
} | ||
} | ||
log.trace("took " + (System.currentTimeMillis() - ts) + " ms."); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters