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

@@ -111,8 +111,8 @@ class BlogPostValidator extends BdfMessageValidator {
Blog b = blogFactory.parseBlog(g);
Author a = b.getAuthor();
try {
clientHelper.verifySignature(SIGNING_LABEL_POST, sig,
a.getPublicKey(), signed);
clientHelper.verifySignature(sig, SIGNING_LABEL_POST, signed,
a.getPublicKey());
} catch (GeneralSecurityException e) {
throw new InvalidMessageException(e);
}
@@ -157,8 +157,8 @@ class BlogPostValidator extends BdfMessageValidator {
Blog b = blogFactory.parseBlog(g);
Author a = b.getAuthor();
try {
clientHelper.verifySignature(SIGNING_LABEL_COMMENT, sig,
a.getPublicKey(), signed);
clientHelper.verifySignature(sig, SIGNING_LABEL_COMMENT,
signed, a.getPublicKey());
} catch (GeneralSecurityException e) {
throw new InvalidMessageException(e);
}

View File

@@ -66,8 +66,8 @@ class ForumPostValidator extends BdfMessageValidator {
BdfList signed = BdfList.of(g.getId(), m.getTimestamp(), parent,
authorList, content);
try {
clientHelper.verifySignature(SIGNING_LABEL_POST, sig,
author.getPublicKey(), signed);
clientHelper.verifySignature(sig, SIGNING_LABEL_POST,
signed, author.getPublicKey());
} catch (GeneralSecurityException e) {
throw new InvalidMessageException(e);
}

View File

@@ -500,7 +500,7 @@ class IntroduceeManager {
byte[] key = localState.getRaw(PUBLIC_KEY);
// Verify the signature
if (!cryptoComponent.verify(SIGNING_LABEL, nonce, key, sig)) {
if (!cryptoComponent.verifySignature(sig, SIGNING_LABEL, nonce, key)) {
LOG.warning("Invalid nonce signature in ACK");
throw new GeneralSecurityException();
}

View File

@@ -112,8 +112,9 @@ class GroupMessageValidator extends BdfMessageValidator {
creator.getId(), member.getId(), g.getId(),
inviteTimestamp);
try {
clientHelper.verifySignature(SIGNING_LABEL_INVITE,
creatorSignature, creator.getPublicKey(), token);
clientHelper.verifySignature(creatorSignature,
SIGNING_LABEL_INVITE,
token, creator.getPublicKey());
} catch (GeneralSecurityException e) {
throw new FormatException();
}
@@ -128,8 +129,8 @@ class GroupMessageValidator extends BdfMessageValidator {
inviteList
);
try {
clientHelper.verifySignature(SIGNING_LABEL_JOIN, memberSignature,
member.getPublicKey(), signed);
clientHelper.verifySignature(memberSignature, SIGNING_LABEL_JOIN,
signed, member.getPublicKey());
} catch (GeneralSecurityException e) {
throw new FormatException();
}
@@ -165,8 +166,8 @@ class GroupMessageValidator extends BdfMessageValidator {
content
);
try {
clientHelper.verifySignature(SIGNING_LABEL_POST, signature,
member.getPublicKey(), signed);
clientHelper.verifySignature(signature, SIGNING_LABEL_POST,
signed, member.getPublicKey());
} catch (GeneralSecurityException e) {
throw new FormatException();
}

View File

@@ -94,8 +94,8 @@ class GroupInvitationValidator extends BdfMessageValidator {
privateGroup.getId()
);
try {
clientHelper.verifySignature(SIGNING_LABEL_INVITE, signature,
creator.getPublicKey(), signed);
clientHelper.verifySignature(signature, SIGNING_LABEL_INVITE,
signed, creator.getPublicKey());
} catch (GeneralSecurityException e) {
throw new FormatException();
}

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 {