mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Use the BouncyCastle provider so we can be sure we won't get
NoSuchAlgorithmExceptions. Key generation is *slow* - I guess that's a good sign. ;-)
This commit is contained in:
@@ -7,6 +7,7 @@ import java.security.MessageDigest;
|
||||
import java.util.Collections;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.briar.api.crypto.CryptoComponent;
|
||||
import net.sf.briar.api.protocol.Batch;
|
||||
import net.sf.briar.api.protocol.BatchId;
|
||||
import net.sf.briar.api.protocol.Message;
|
||||
@@ -42,7 +43,7 @@ public class BatchReaderTest extends TestCase {
|
||||
new CryptoModule());
|
||||
readerFactory = i.getInstance(ReaderFactory.class);
|
||||
writerFactory = i.getInstance(WriterFactory.class);
|
||||
messageDigest = i.getInstance(MessageDigest.class);
|
||||
messageDigest = i.getInstance(CryptoComponent.class).getMessageDigest();
|
||||
context = new Mockery();
|
||||
message = context.mock(Message.class);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.briar.api.crypto.CryptoComponent;
|
||||
import net.sf.briar.api.serial.FormatException;
|
||||
import net.sf.briar.crypto.CryptoModule;
|
||||
|
||||
@@ -18,20 +19,18 @@ import com.google.inject.Injector;
|
||||
|
||||
public class ConsumersTest extends TestCase {
|
||||
|
||||
private Signature signature = null;
|
||||
private KeyPair keyPair = null;
|
||||
private MessageDigest messageDigest = null;
|
||||
private CryptoComponent crypto = null;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Injector i = Guice.createInjector(new CryptoModule());
|
||||
signature = i.getInstance(Signature.class);
|
||||
keyPair = i.getInstance(KeyPair.class);
|
||||
messageDigest = i.getInstance(MessageDigest.class);
|
||||
crypto = i.getInstance(CryptoComponent.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSigningConsumer() throws Exception {
|
||||
Signature signature = crypto.getSignature();
|
||||
KeyPair keyPair = crypto.generateKeyPair();
|
||||
byte[] data = new byte[1234];
|
||||
// Generate some random data and sign it
|
||||
new Random().nextBytes(data);
|
||||
@@ -50,6 +49,7 @@ public class ConsumersTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testDigestingConsumer() throws Exception {
|
||||
MessageDigest messageDigest = crypto.getMessageDigest();
|
||||
byte[] data = new byte[1234];
|
||||
// Generate some random data and digest it
|
||||
new Random().nextBytes(data);
|
||||
|
||||
@@ -13,6 +13,7 @@ import java.util.Iterator;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.crypto.CryptoComponent;
|
||||
import net.sf.briar.api.crypto.KeyParser;
|
||||
import net.sf.briar.api.protocol.Ack;
|
||||
import net.sf.briar.api.protocol.Batch;
|
||||
@@ -63,6 +64,7 @@ public class FileReadWriteTest extends TestCase {
|
||||
private final ReaderFactory readerFactory;
|
||||
private final WriterFactory writerFactory;
|
||||
private final PacketWriterFactory packetWriterFactory;
|
||||
private final CryptoComponent crypto;
|
||||
private final Signature signature;
|
||||
private final MessageDigest messageDigest, batchDigest;
|
||||
private final KeyParser keyParser;
|
||||
@@ -77,15 +79,16 @@ public class FileReadWriteTest extends TestCase {
|
||||
readerFactory = i.getInstance(ReaderFactory.class);
|
||||
writerFactory = i.getInstance(WriterFactory.class);
|
||||
packetWriterFactory = i.getInstance(PacketWriterFactory.class);
|
||||
keyParser = i.getInstance(KeyParser.class);
|
||||
signature = i.getInstance(Signature.class);
|
||||
messageDigest = i.getInstance(MessageDigest.class);
|
||||
batchDigest = i.getInstance(MessageDigest.class);
|
||||
crypto = i.getInstance(CryptoComponent.class);
|
||||
keyParser = crypto.getKeyParser();
|
||||
signature = crypto.getSignature();
|
||||
messageDigest = crypto.getMessageDigest();
|
||||
batchDigest = crypto.getMessageDigest();
|
||||
assertEquals(messageDigest.getDigestLength(), UniqueId.LENGTH);
|
||||
assertEquals(batchDigest.getDigestLength(), UniqueId.LENGTH);
|
||||
// Create and encode a test message
|
||||
MessageEncoder messageEncoder = i.getInstance(MessageEncoder.class);
|
||||
KeyPair keyPair = i.getInstance(KeyPair.class);
|
||||
KeyPair keyPair = crypto.generateKeyPair();
|
||||
message = messageEncoder.encodeMessage(MessageId.NONE, sub, nick,
|
||||
keyPair, messageBody.getBytes("UTF-8"));
|
||||
// Create a test group, then write and read it to calculate its ID
|
||||
@@ -144,7 +147,7 @@ public class FileReadWriteTest extends TestCase {
|
||||
ObjectReader<Batch> batchReader = new BatchReader(batchDigest,
|
||||
messageReader, new BatchFactoryImpl());
|
||||
ObjectReader<Group> groupReader = new GroupReader(batchDigest,
|
||||
new GroupFactoryImpl(keyParser));
|
||||
new GroupFactoryImpl(crypto));
|
||||
ObjectReader<Subscriptions> subscriptionReader =
|
||||
new SubscriptionReader(groupReader, new SubscriptionFactoryImpl());
|
||||
ObjectReader<Transports> transportReader =
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.briar.api.crypto.CryptoComponent;
|
||||
import net.sf.briar.crypto.CryptoModule;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -19,20 +20,19 @@ import com.google.inject.Injector;
|
||||
|
||||
public class SigningDigestingOutputStreamTest extends TestCase {
|
||||
|
||||
private Signature signature = null;
|
||||
private KeyPair keyPair = null;
|
||||
private MessageDigest messageDigest = null;
|
||||
private CryptoComponent crypto = null;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Injector i = Guice.createInjector(new CryptoModule());
|
||||
signature = i.getInstance(Signature.class);
|
||||
keyPair = i.getInstance(KeyPair.class);
|
||||
messageDigest = i.getInstance(MessageDigest.class);
|
||||
crypto = i.getInstance(CryptoComponent.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStopAndStart() throws Exception {
|
||||
Signature signature = crypto.getSignature();
|
||||
KeyPair keyPair = crypto.generateKeyPair();
|
||||
MessageDigest messageDigest = crypto.getMessageDigest();
|
||||
byte[] input = new byte[1024];
|
||||
new Random().nextBytes(input);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(input.length);
|
||||
@@ -69,6 +69,8 @@ public class SigningDigestingOutputStreamTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testSignatureExceptionThrowsIOException() throws Exception {
|
||||
Signature signature = crypto.getSignature();
|
||||
MessageDigest messageDigest = crypto.getMessageDigest();
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
SigningDigestingOutputStream s =
|
||||
new SigningDigestingOutputStream(out, signature, messageDigest);
|
||||
|
||||
Reference in New Issue
Block a user