mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-21 23:29:52 +01:00
Removed unused code.
This commit is contained in:
@@ -15,8 +15,9 @@ public class CryptoModule extends AbstractModule {
|
|||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(CryptoComponent.class).to(
|
bind(CryptoComponent.class).to(
|
||||||
CryptoComponentImpl.class).in(Singleton.class);
|
CryptoComponentImpl.class).in(Singleton.class);
|
||||||
|
// FIXME: Use a real key
|
||||||
bind(SecretKey.class).annotatedWith(SecretStorageKey.class).toInstance(
|
bind(SecretKey.class).annotatedWith(SecretStorageKey.class).toInstance(
|
||||||
new SecretKeySpec(new byte[32], "AES")); // FIXME
|
new SecretKeySpec(new byte[32], "AES"));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
package net.sf.briar.protocol;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.security.Signature;
|
|
||||||
import java.security.SignatureException;
|
|
||||||
|
|
||||||
import net.sf.briar.api.serial.Consumer;
|
|
||||||
|
|
||||||
// FIXME: This class is no longer used - remove it?
|
|
||||||
|
|
||||||
/** A consumer that passes its input through a signature. */
|
|
||||||
class SigningConsumer implements Consumer {
|
|
||||||
|
|
||||||
private final Signature signature;
|
|
||||||
|
|
||||||
SigningConsumer(Signature signature) {
|
|
||||||
this.signature = signature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void write(byte b) throws IOException {
|
|
||||||
try {
|
|
||||||
signature.update(b);
|
|
||||||
} catch(SignatureException e) {
|
|
||||||
throw new IOException(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void write(byte[] b) throws IOException {
|
|
||||||
try {
|
|
||||||
signature.update(b);
|
|
||||||
} catch(SignatureException e) {
|
|
||||||
throw new IOException(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void write(byte[] b, int off, int len) throws IOException {
|
|
||||||
try {
|
|
||||||
signature.update(b, off, len);
|
|
||||||
} catch(SignatureException e) {
|
|
||||||
throw new IOException(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
package net.sf.briar.protocol;
|
|
||||||
|
|
||||||
import java.io.FilterOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.Signature;
|
|
||||||
import java.security.SignatureException;
|
|
||||||
|
|
||||||
// FIXME: This class is no longer used - remove it?
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An output stream that passes its output through a signature and a message
|
|
||||||
* digest.
|
|
||||||
*/
|
|
||||||
class SigningDigestingOutputStream extends FilterOutputStream {
|
|
||||||
|
|
||||||
private final Signature signature;
|
|
||||||
private final MessageDigest messageDigest;
|
|
||||||
private boolean signing = false, digesting = false;
|
|
||||||
|
|
||||||
public SigningDigestingOutputStream(OutputStream out, Signature signature,
|
|
||||||
MessageDigest messageDigest) {
|
|
||||||
super(out);
|
|
||||||
this.signature = signature;
|
|
||||||
this.messageDigest = messageDigest;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setSigning(boolean signing) {
|
|
||||||
this.signing = signing;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDigesting(boolean digesting) {
|
|
||||||
this.digesting = digesting;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(byte[] b) throws IOException {
|
|
||||||
write(b, 0, b.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(byte[] b, int off, int len) throws IOException {
|
|
||||||
out.write(b, off, len);
|
|
||||||
if(signing) {
|
|
||||||
try {
|
|
||||||
signature.update(b, off, len);
|
|
||||||
} catch(SignatureException e) {
|
|
||||||
throw new IOException(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(digesting) messageDigest.update(b, off, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(int b) throws IOException {
|
|
||||||
out.write(b);
|
|
||||||
if(signing) {
|
|
||||||
try {
|
|
||||||
signature.update((byte) b);
|
|
||||||
} catch(SignatureException e) {
|
|
||||||
throw new IOException(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(digesting) messageDigest.update((byte) b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
package net.sf.briar.protocol;
|
package net.sf.briar.protocol;
|
||||||
|
|
||||||
import java.security.KeyPair;
|
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.Signature;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
@@ -27,25 +25,6 @@ public class ConsumersTest extends TestCase {
|
|||||||
crypto = i.getInstance(CryptoComponent.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);
|
|
||||||
signature.initSign(keyPair.getPrivate());
|
|
||||||
signature.update(data);
|
|
||||||
byte[] sig = signature.sign();
|
|
||||||
// Check that a SigningConsumer fed with the same data verifies the sig
|
|
||||||
signature.initVerify(keyPair.getPublic());
|
|
||||||
SigningConsumer sc = new SigningConsumer(signature);
|
|
||||||
sc.write(data[0]);
|
|
||||||
sc.write(data, 1, data.length - 2);
|
|
||||||
sc.write(data[data.length - 1]);
|
|
||||||
assertTrue(signature.verify(sig));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDigestingConsumer() throws Exception {
|
public void testDigestingConsumer() throws Exception {
|
||||||
MessageDigest messageDigest = crypto.getMessageDigest();
|
MessageDigest messageDigest = crypto.getMessageDigest();
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
package net.sf.briar.protocol;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.security.KeyPair;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.Signature;
|
|
||||||
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;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import com.google.inject.Guice;
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
|
|
||||||
public class SigningDigestingOutputStreamTest extends TestCase {
|
|
||||||
|
|
||||||
private CryptoComponent crypto = null;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
Injector i = Guice.createInjector(new CryptoModule());
|
|
||||||
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);
|
|
||||||
SigningDigestingOutputStream s =
|
|
||||||
new SigningDigestingOutputStream(out, signature, messageDigest);
|
|
||||||
signature.initSign(keyPair.getPrivate());
|
|
||||||
messageDigest.reset();
|
|
||||||
// Sign the first 256 bytes, digest all but the last 256 bytes
|
|
||||||
s.setDigesting(true);
|
|
||||||
s.setSigning(true);
|
|
||||||
s.write(input, 0, 256);
|
|
||||||
s.setSigning(false);
|
|
||||||
s.write(input, 256, 512);
|
|
||||||
s.setDigesting(false);
|
|
||||||
s.write(input, 768, 256);
|
|
||||||
s.close();
|
|
||||||
// Get the signature and the digest
|
|
||||||
byte[] sig = signature.sign();
|
|
||||||
byte[] digest = messageDigest.digest();
|
|
||||||
// Check that the output matches the input
|
|
||||||
assertTrue(Arrays.equals(input, out.toByteArray()));
|
|
||||||
// Verify the signature over the first 256 bytes
|
|
||||||
signature.initVerify(keyPair.getPublic());
|
|
||||||
signature.update(input, 0, 256);
|
|
||||||
assertTrue(signature.verify(sig));
|
|
||||||
// Check that the digest matches a digest over all but the last 256
|
|
||||||
// bytes
|
|
||||||
messageDigest.reset();
|
|
||||||
messageDigest.update(input, 0, 768);
|
|
||||||
byte[] directDigest = messageDigest.digest();
|
|
||||||
assertTrue(Arrays.equals(directDigest, digest));
|
|
||||||
}
|
|
||||||
|
|
||||||
@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);
|
|
||||||
s.setSigning(true); // Signature hasn't been initialised yet
|
|
||||||
try {
|
|
||||||
s.write((byte) 0);
|
|
||||||
fail();
|
|
||||||
} catch(IOException expected) {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user