mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Don't send tags for invitation connections.
This commit is contained in:
@@ -7,6 +7,7 @@ import static org.briarproject.api.transport.TransportConstants.MAC_LENGTH;
|
||||
import static org.briarproject.api.transport.TransportConstants.TAG_LENGTH;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Random;
|
||||
|
||||
import org.briarproject.BriarTestCase;
|
||||
import org.briarproject.TestLifecycleModule;
|
||||
@@ -28,18 +29,42 @@ public class OutgoingEncryptionLayerTest extends BriarTestCase {
|
||||
|
||||
private final CryptoComponent crypto;
|
||||
private final AuthenticatedCipher frameCipher;
|
||||
private final byte[] tag;
|
||||
|
||||
public OutgoingEncryptionLayerTest() {
|
||||
Injector i = Guice.createInjector(new CryptoModule(),
|
||||
new TestLifecycleModule(), new TestSystemModule());
|
||||
crypto = i.getInstance(CryptoComponent.class);
|
||||
frameCipher = crypto.getFrameCipher();
|
||||
tag = new byte[TAG_LENGTH];
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncryption() throws Exception {
|
||||
public void testEncryptionWithoutTag() throws Exception {
|
||||
int payloadLength = 123;
|
||||
byte[] iv = new byte[IV_LENGTH], aad = new byte[AAD_LENGTH];
|
||||
byte[] plaintext = new byte[FRAME_LENGTH - MAC_LENGTH];
|
||||
byte[] ciphertext = new byte[FRAME_LENGTH];
|
||||
SecretKey frameKey = crypto.generateSecretKey();
|
||||
// Calculate the expected ciphertext
|
||||
FrameEncoder.encodeIv(iv, 0);
|
||||
FrameEncoder.encodeAad(aad, 0, plaintext.length);
|
||||
frameCipher.init(true, frameKey, iv, aad);
|
||||
FrameEncoder.encodeHeader(plaintext, false, payloadLength);
|
||||
frameCipher.doFinal(plaintext, 0, plaintext.length, ciphertext, 0);
|
||||
// Check that the actual ciphertext matches what's expected
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
OutgoingEncryptionLayer o = new OutgoingEncryptionLayer(out,
|
||||
frameCipher, frameKey, FRAME_LENGTH, null);
|
||||
o.writeFrame(new byte[FRAME_LENGTH - MAC_LENGTH], payloadLength, false);
|
||||
byte[] actual = out.toByteArray();
|
||||
assertEquals(FRAME_LENGTH, actual.length);
|
||||
for(int i = 0; i < FRAME_LENGTH; i++)
|
||||
assertEquals(ciphertext[i], actual[i]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncryptionWithTag() throws Exception {
|
||||
byte[] tag = new byte[TAG_LENGTH];
|
||||
new Random().nextBytes(tag);
|
||||
int payloadLength = 123;
|
||||
byte[] iv = new byte[IV_LENGTH], aad = new byte[AAD_LENGTH];
|
||||
byte[] plaintext = new byte[FRAME_LENGTH - MAC_LENGTH];
|
||||
@@ -59,13 +84,14 @@ public class OutgoingEncryptionLayerTest extends BriarTestCase {
|
||||
byte[] actual = out.toByteArray();
|
||||
assertEquals(TAG_LENGTH + FRAME_LENGTH, actual.length);
|
||||
for(int i = 0; i < TAG_LENGTH; i++) assertEquals(tag[i], actual[i]);
|
||||
for(int i = 0; i < FRAME_LENGTH; i++) {
|
||||
assertEquals("" + i, ciphertext[i], actual[TAG_LENGTH + i]);
|
||||
}
|
||||
for(int i = 0; i < FRAME_LENGTH; i++)
|
||||
assertEquals(ciphertext[i], actual[TAG_LENGTH + i]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloseConnectionWithoutWriting() throws Exception {
|
||||
byte[] tag = new byte[TAG_LENGTH];
|
||||
new Random().nextBytes(tag);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
// Initiator's constructor
|
||||
OutgoingEncryptionLayer o = new OutgoingEncryptionLayer(out,
|
||||
|
||||
Reference in New Issue
Block a user