Add constant-time method for verifying MACs.

This commit is contained in:
akwizgran
2018-04-25 12:23:46 +01:00
parent 615f527270
commit 0217c205a1
20 changed files with 120 additions and 72 deletions

View File

@@ -280,7 +280,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
oneOf(clientHelper).toList(b.getAuthor());
will(returnValue(authorList));
oneOf(clientHelper)
.verifySignature(label, sig, author.getPublicKey(), signed);
.verifySignature(sig, label, signed, author.getPublicKey());
}});
}

View File

@@ -64,8 +64,8 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
public void testAcceptsNullParentId() throws Exception {
expectCreateAuthor();
context.checking(new Expectations() {{
oneOf(clientHelper).verifySignature(SIGNING_LABEL_POST, signature,
authorPublicKey, signedWithoutParent);
oneOf(clientHelper).verifySignature(signature, SIGNING_LABEL_POST,
signedWithoutParent, authorPublicKey);
}});
BdfMessageContext messageContext = v.validateMessage(message, group,
@@ -139,8 +139,8 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
expectCreateAuthor();
context.checking(new Expectations() {{
oneOf(clientHelper).verifySignature(SIGNING_LABEL_POST, signature,
authorPublicKey, signedWithShortContent);
oneOf(clientHelper).verifySignature(signature, SIGNING_LABEL_POST,
signedWithShortContent, authorPublicKey);
}});
BdfMessageContext messageContext = v.validateMessage(message, group,
@@ -189,8 +189,8 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
throws Exception {
expectCreateAuthor();
context.checking(new Expectations() {{
oneOf(clientHelper).verifySignature(SIGNING_LABEL_POST, signature,
authorPublicKey, signedWithParent);
oneOf(clientHelper).verifySignature(signature, SIGNING_LABEL_POST,
signedWithParent, authorPublicKey);
will(throwException(new FormatException()));
}});
@@ -203,8 +203,8 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
throws Exception {
expectCreateAuthor();
context.checking(new Expectations() {{
oneOf(clientHelper).verifySignature(SIGNING_LABEL_POST, signature,
authorPublicKey, signedWithParent);
oneOf(clientHelper).verifySignature(signature, SIGNING_LABEL_POST,
signedWithParent, authorPublicKey);
will(throwException(new GeneralSecurityException()));
}});

View File

@@ -262,8 +262,8 @@ public class IntroduceeManagerTest extends BriarTestCase {
);
context.checking(new Expectations() {{
oneOf(cryptoComponent).verify(SIGNING_LABEL, nonce,
introducee2.getAuthor().getPublicKey(), sig);
oneOf(cryptoComponent).verifySignature(sig, SIGNING_LABEL, nonce,
introducee2.getAuthor().getPublicKey());
will(returnValue(false));
}});
@@ -292,8 +292,8 @@ public class IntroduceeManagerTest extends BriarTestCase {
state.put(SIGNATURE, sig);
context.checking(new Expectations() {{
oneOf(cryptoComponent).verify(SIGNING_LABEL, nonce,
publicKeyBytes, sig);
oneOf(cryptoComponent).verifySignature(sig, SIGNING_LABEL, nonce,
publicKeyBytes);
will(returnValue(true));
}});
introduceeManager.verifySignature(state);

View File

@@ -401,8 +401,8 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
expectParseAuthor(creatorList, creator);
expectParsePrivateGroup();
context.checking(new Expectations() {{
oneOf(clientHelper).verifySignature(SIGNING_LABEL_JOIN,
memberSignature, creator.getPublicKey(), signed);
oneOf(clientHelper).verifySignature(memberSignature,
SIGNING_LABEL_JOIN, signed, creator.getPublicKey());
if (!memberSigValid)
will(throwException(new GeneralSecurityException()));
}});
@@ -422,13 +422,13 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
oneOf(groupInvitationFactory).createInviteToken(creator.getId(),
member.getId(), privateGroup.getId(), inviteTimestamp);
will(returnValue(token));
oneOf(clientHelper).verifySignature(SIGNING_LABEL_INVITE,
creatorSignature, creator.getPublicKey(), token);
oneOf(clientHelper).verifySignature(creatorSignature,
SIGNING_LABEL_INVITE, token, creator.getPublicKey());
if (!creatorSigValid) {
will(throwException(new GeneralSecurityException()));
} else {
oneOf(clientHelper).verifySignature(SIGNING_LABEL_JOIN,
memberSignature, member.getPublicKey(), signed);
oneOf(clientHelper).verifySignature(memberSignature,
SIGNING_LABEL_JOIN, signed, member.getPublicKey());
if (!memberSigValid)
will(throwException(new GeneralSecurityException()));
}
@@ -648,8 +648,8 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
);
expectParseAuthor(memberList, member);
context.checking(new Expectations() {{
oneOf(clientHelper).verifySignature(SIGNING_LABEL_POST,
memberSignature, member.getPublicKey(), signed);
oneOf(clientHelper).verifySignature(memberSignature,
SIGNING_LABEL_POST, signed, member.getPublicKey());
if (!sigValid)
will(throwException(new GeneralSecurityException()));
}});

View File

@@ -256,8 +256,8 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
oneOf(privateGroupFactory).createPrivateGroup(groupName, creator,
salt);
will(returnValue(privateGroup));
oneOf(clientHelper).verifySignature(SIGNING_LABEL_INVITE, signature,
creator.getPublicKey(), signed);
oneOf(clientHelper).verifySignature(signature, SIGNING_LABEL_INVITE,
signed, creator.getPublicKey());
if (exception) {
will(throwException(new GeneralSecurityException()));
} else {