mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
Separated key agreement algorithm from signature algorithm.
This commit is contained in:
@@ -100,12 +100,12 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
||||
// Create two groups: one restricted, one unrestricted
|
||||
GroupFactory groupFactory = i.getInstance(GroupFactory.class);
|
||||
group = groupFactory.createGroup("Unrestricted group", null);
|
||||
KeyPair groupKeyPair = crypto.generateKeyPair();
|
||||
KeyPair groupKeyPair = crypto.generateSignatureKeyPair();
|
||||
group1 = groupFactory.createGroup("Restricted group",
|
||||
groupKeyPair.getPublic().getEncoded());
|
||||
// Create an author
|
||||
AuthorFactory authorFactory = i.getInstance(AuthorFactory.class);
|
||||
KeyPair authorKeyPair = crypto.generateKeyPair();
|
||||
KeyPair authorKeyPair = crypto.generateSignatureKeyPair();
|
||||
author = authorFactory.createAuthor(authorName,
|
||||
authorKeyPair.getPublic().getEncoded());
|
||||
// Create two messages to each group: one anonymous, one pseudonymous
|
||||
|
||||
44
test/net/sf/briar/plugins/InvitationStarterImplTest.java
Normal file
44
test/net/sf/briar/plugins/InvitationStarterImplTest.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package net.sf.briar.plugins;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
import java.security.KeyPair;
|
||||
import java.security.PrivateKey;
|
||||
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.api.crypto.CryptoComponent;
|
||||
import net.sf.briar.crypto.CryptoModule;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
public class InvitationStarterImplTest extends BriarTestCase {
|
||||
|
||||
private final CryptoComponent crypto;
|
||||
|
||||
public InvitationStarterImplTest() {
|
||||
super();
|
||||
Injector i = Guice.createInjector(new CryptoModule());
|
||||
crypto = i.getInstance(CryptoComponent.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKeyAgreement() {
|
||||
KeyPair a = crypto.generateAgreementKeyPair();
|
||||
byte[] aPub = a.getPublic().getEncoded();
|
||||
PrivateKey aPriv = a.getPrivate();
|
||||
KeyPair b = crypto.generateAgreementKeyPair();
|
||||
byte[] bPub = b.getPublic().getEncoded();
|
||||
PrivateKey bPriv = b.getPrivate();
|
||||
byte[][] aSecrets = crypto.deriveInitialSecrets(aPub, bPub, aPriv, 123,
|
||||
true);
|
||||
byte[][] bSecrets = crypto.deriveInitialSecrets(bPub, aPub, bPriv, 123,
|
||||
false);
|
||||
assertEquals(2, aSecrets.length);
|
||||
assertEquals(2, bSecrets.length);
|
||||
assertArrayEquals(aSecrets[0], bSecrets[0]);
|
||||
assertArrayEquals(aSecrets[1], bSecrets[1]);
|
||||
}
|
||||
}
|
||||
@@ -108,8 +108,8 @@ public class ConstantsTest extends BriarTestCase {
|
||||
byte[] authorPublic = new byte[MAX_PUBLIC_KEY_LENGTH];
|
||||
Author author = authorFactory.createAuthor(authorName, authorPublic);
|
||||
// Create a maximum-length message
|
||||
PrivateKey groupPrivate = crypto.generateKeyPair().getPrivate();
|
||||
PrivateKey authorPrivate = crypto.generateKeyPair().getPrivate();
|
||||
PrivateKey groupPrivate = crypto.generateSignatureKeyPair().getPrivate();
|
||||
PrivateKey authorPrivate = crypto.generateSignatureKeyPair().getPrivate();
|
||||
String subject = createRandomString(MAX_SUBJECT_LENGTH);
|
||||
byte[] body = new byte[MAX_BODY_LENGTH];
|
||||
Message message = messageFactory.createMessage(null, group,
|
||||
|
||||
@@ -122,8 +122,8 @@ public class UnverifiedBatchImplTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testSignatures() throws Exception {
|
||||
final int signedByAuthor = 100, signedByGroup = 110;
|
||||
final KeyPair authorKeyPair = crypto.generateKeyPair();
|
||||
final KeyPair groupKeyPair = crypto.generateKeyPair();
|
||||
final KeyPair authorKeyPair = crypto.generateSignatureKeyPair();
|
||||
final KeyPair groupKeyPair = crypto.generateSignatureKeyPair();
|
||||
Signature signature = crypto.getSignature();
|
||||
// Calculate the expected author and group signatures
|
||||
signature.initSign(authorKeyPair.getPrivate());
|
||||
@@ -202,7 +202,7 @@ public class UnverifiedBatchImplTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testExceptionThrownIfMessageIsModified() throws Exception {
|
||||
final int signedByAuthor = 100;
|
||||
final KeyPair authorKeyPair = crypto.generateKeyPair();
|
||||
final KeyPair authorKeyPair = crypto.generateSignatureKeyPair();
|
||||
Signature signature = crypto.getSignature();
|
||||
// Calculate the expected author signature
|
||||
signature.initSign(authorKeyPair.getPrivate());
|
||||
|
||||
Reference in New Issue
Block a user