From 0217c205a13c94b6cb28e1f6141368b9a561bebd Mon Sep 17 00:00:00 2001 From: akwizgran Date: Wed, 25 Apr 2018 12:23:46 +0100 Subject: [PATCH] Add constant-time method for verifying MACs. --- .../bramble/api/client/ClientHelper.java | 4 ++-- .../bramble/api/crypto/CryptoComponent.java | 16 ++++++++++++++-- .../bramble/client/ClientHelperImpl.java | 7 ++++--- .../contact/ContactExchangeTaskImpl.java | 3 ++- .../bramble/crypto/CryptoComponentImpl.java | 17 ++++++++++++++--- .../bramble/client/ClientHelperImplTest.java | 17 +++++++++++------ .../bramble/crypto/EdSignatureTest.java | 6 +++--- .../crypto/KeyEncodingAndParsingTest.java | 16 ++++++++-------- .../briarproject/bramble/crypto/MacTest.java | 17 +++++++++++++++++ .../bramble/crypto/SignatureTest.java | 12 ++++++------ .../briar/blog/BlogPostValidator.java | 8 ++++---- .../briar/forum/ForumPostValidator.java | 4 ++-- .../briar/introduction/IntroduceeManager.java | 2 +- .../privategroup/GroupMessageValidator.java | 13 +++++++------ .../invitation/GroupInvitationValidator.java | 4 ++-- .../briar/blog/BlogPostValidatorTest.java | 2 +- .../briar/forum/ForumPostValidatorTest.java | 16 ++++++++-------- .../introduction/IntroduceeManagerTest.java | 8 ++++---- .../privategroup/GroupMessageValidatorTest.java | 16 ++++++++-------- .../GroupInvitationValidatorTest.java | 4 ++-- 20 files changed, 120 insertions(+), 72 deletions(-) diff --git a/bramble-api/src/main/java/org/briarproject/bramble/api/client/ClientHelper.java b/bramble-api/src/main/java/org/briarproject/bramble/api/client/ClientHelper.java index dd60bb610..b0de14cda 100644 --- a/bramble-api/src/main/java/org/briarproject/bramble/api/client/ClientHelper.java +++ b/bramble-api/src/main/java/org/briarproject/bramble/api/client/ClientHelper.java @@ -105,8 +105,8 @@ public interface ClientHelper { byte[] sign(String label, BdfList toSign, byte[] privateKey) throws FormatException, GeneralSecurityException; - void verifySignature(String label, byte[] sig, byte[] publicKey, - BdfList signed) throws FormatException, GeneralSecurityException; + void verifySignature(byte[] signature, String label, BdfList signed, + byte[] publicKey) throws FormatException, GeneralSecurityException; Author parseAndValidateAuthor(BdfList author) throws FormatException; diff --git a/bramble-api/src/main/java/org/briarproject/bramble/api/crypto/CryptoComponent.java b/bramble-api/src/main/java/org/briarproject/bramble/api/crypto/CryptoComponent.java index 19a542f8a..fdc83aabb 100644 --- a/bramble-api/src/main/java/org/briarproject/bramble/api/crypto/CryptoComponent.java +++ b/bramble-api/src/main/java/org/briarproject/bramble/api/crypto/CryptoComponent.java @@ -67,8 +67,8 @@ public interface CryptoComponent { * signature created for another purpose * @return true if the signature was valid, false otherwise. */ - boolean verify(String label, byte[] signedData, byte[] publicKey, - byte[] signature) throws GeneralSecurityException; + boolean verifySignature(byte[] signature, String label, byte[] signed, + byte[] publicKey) throws GeneralSecurityException; /** * Returns the hash of the given inputs. The inputs are unambiguously @@ -91,6 +91,18 @@ public interface CryptoComponent { */ byte[] mac(String label, SecretKey macKey, byte[]... inputs); + /** + * Verifies that the given message authentication code is valid for the + * given secret key and inputs. + * + * @param label a namespaced label indicating the purpose of this MAC, to + * prevent it from being repurposed or colliding with a MAC created for + * another purpose + * @return true if the MAC was valid, false otherwise. + */ + boolean verifyMac(byte[] mac, String label, SecretKey macKey, + byte[]... inputs); + /** * Encrypts and authenticates the given plaintext so it can be written to * storage. The encryption and authentication keys are derived from the diff --git a/bramble-core/src/main/java/org/briarproject/bramble/client/ClientHelperImpl.java b/bramble-core/src/main/java/org/briarproject/bramble/client/ClientHelperImpl.java index 7c833a66d..afc40d91b 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/client/ClientHelperImpl.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/client/ClientHelperImpl.java @@ -381,9 +381,10 @@ class ClientHelperImpl implements ClientHelper { } @Override - public void verifySignature(String label, byte[] sig, byte[] publicKey, - BdfList signed) throws FormatException, GeneralSecurityException { - if (!crypto.verify(label, toByteArray(signed), publicKey, sig)) { + public void verifySignature(byte[] signature, String label, BdfList signed, + byte[] publicKey) throws FormatException, GeneralSecurityException { + if (!crypto.verifySignature(signature, label, toByteArray(signed), + publicKey)) { throw new GeneralSecurityException("Invalid signature"); } } diff --git a/bramble-core/src/main/java/org/briarproject/bramble/contact/ContactExchangeTaskImpl.java b/bramble-core/src/main/java/org/briarproject/bramble/contact/ContactExchangeTaskImpl.java index f495b5648..6fdcc7aad 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/contact/ContactExchangeTaskImpl.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/contact/ContactExchangeTaskImpl.java @@ -251,7 +251,8 @@ class ContactExchangeTaskImpl extends Thread implements ContactExchangeTask { r.readListEnd(); LOG.info("Received pseudonym"); // Verify the signature - if (!crypto.verify(SIGNING_LABEL_EXCHANGE, nonce, publicKey, sig)) { + if (!crypto.verifySignature(sig, SIGNING_LABEL_EXCHANGE, nonce, + publicKey)) { if (LOG.isLoggable(INFO)) LOG.info("Invalid signature"); throw new GeneralSecurityException(); diff --git a/bramble-core/src/main/java/org/briarproject/bramble/crypto/CryptoComponentImpl.java b/bramble-core/src/main/java/org/briarproject/bramble/crypto/CryptoComponentImpl.java index 4161db31a..83e759e3b 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/crypto/CryptoComponentImpl.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/crypto/CryptoComponentImpl.java @@ -205,12 +205,12 @@ class CryptoComponentImpl implements CryptoComponent { } @Override - public boolean verify(String label, byte[] signedData, byte[] publicKey, - byte[] signature) throws GeneralSecurityException { + public boolean verifySignature(byte[] signature, String label, + byte[] signed, byte[] publicKey) throws GeneralSecurityException { PublicKey key = signatureKeyParser.parsePublicKey(publicKey); Signature sig = new EdSignature(); sig.initVerify(key); - updateSignature(sig, label, signedData); + updateSignature(sig, label, signed); return sig.verify(signature); } @@ -262,6 +262,17 @@ class CryptoComponentImpl implements CryptoComponent { return output; } + @Override + public boolean verifyMac(byte[] mac, String label, SecretKey macKey, + byte[]... inputs) { + byte[] expected = mac(label, macKey, inputs); + if (mac.length != expected.length) return false; + // Constant-time comparison + int cmp = 0; + for (int i = 0; i < mac.length; i++) cmp |= mac[i] ^ expected[i]; + return cmp == 0; + } + @Override public byte[] encryptWithPassword(byte[] input, String password) { AuthenticatedCipher cipher = new XSalsa20Poly1305AuthenticatedCipher(); diff --git a/bramble-core/src/test/java/org/briarproject/bramble/client/ClientHelperImplTest.java b/bramble-core/src/test/java/org/briarproject/bramble/client/ClientHelperImplTest.java index 0d54281a8..dec1e1100 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/client/ClientHelperImplTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/client/ClientHelperImplTest.java @@ -37,6 +37,7 @@ import java.util.Random; import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH; import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH; +import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH; import static org.briarproject.bramble.test.TestUtils.getAuthor; import static org.briarproject.bramble.test.TestUtils.getRandomBytes; import static org.briarproject.bramble.test.TestUtils.getRandomId; @@ -300,30 +301,34 @@ public class ClientHelperImplTest extends BrambleTestCase { @Test public void testVerifySignature() throws Exception { + byte[] signature = getRandomBytes(MAX_SIGNATURE_LENGTH); byte[] publicKey = getRandomBytes(42); - byte[] bytes = expectToByteArray(list); + byte[] signed = expectToByteArray(list); context.checking(new Expectations() {{ - oneOf(cryptoComponent).verify(label, bytes, publicKey, rawMessage); + oneOf(cryptoComponent).verifySignature(signature, label, signed, + publicKey); will(returnValue(true)); }}); - clientHelper.verifySignature(label, rawMessage, publicKey, list); + clientHelper.verifySignature(signature, label, list, publicKey); context.assertIsSatisfied(); } @Test public void testVerifyWrongSignature() throws Exception { + byte[] signature = getRandomBytes(MAX_SIGNATURE_LENGTH); byte[] publicKey = getRandomBytes(42); - byte[] bytes = expectToByteArray(list); + byte[] signed = expectToByteArray(list); context.checking(new Expectations() {{ - oneOf(cryptoComponent).verify(label, bytes, publicKey, rawMessage); + oneOf(cryptoComponent).verifySignature(signature, label, signed, + publicKey); will(returnValue(false)); }}); try { - clientHelper.verifySignature(label, rawMessage, publicKey, list); + clientHelper.verifySignature(signature, label, list, publicKey); fail(); } catch (GeneralSecurityException e) { // expected diff --git a/bramble-core/src/test/java/org/briarproject/bramble/crypto/EdSignatureTest.java b/bramble-core/src/test/java/org/briarproject/bramble/crypto/EdSignatureTest.java index 3fb5c3a9c..62bf21819 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/crypto/EdSignatureTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/crypto/EdSignatureTest.java @@ -143,9 +143,9 @@ public class EdSignatureTest extends SignatureTest { } @Override - protected boolean verify(String label, byte[] signedData, byte[] publicKey, - byte[] signature) throws GeneralSecurityException { - return crypto.verify(label, signedData, publicKey, signature); + protected boolean verify(byte[] signature, String label, byte[] signed, + byte[] publicKey) throws GeneralSecurityException { + return crypto.verifySignature(signature, label, signed, publicKey); } @Test diff --git a/bramble-core/src/test/java/org/briarproject/bramble/crypto/KeyEncodingAndParsingTest.java b/bramble-core/src/test/java/org/briarproject/bramble/crypto/KeyEncodingAndParsingTest.java index 30d62ef8c..7c14ca505 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/crypto/KeyEncodingAndParsingTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/crypto/KeyEncodingAndParsingTest.java @@ -126,13 +126,13 @@ public class KeyEncodingAndParsingTest extends BrambleTestCase { byte[] signature = crypto.sign("test", message, privateKey.getEncoded()); // Verify the signature - assertTrue(crypto.verify("test", message, publicKey.getEncoded(), - signature)); + assertTrue(crypto.verifySignature(signature, "test", message, + publicKey.getEncoded())); // Encode and parse the public key - no exceptions should be thrown publicKey = parser.parsePublicKey(publicKey.getEncoded()); // Verify the signature again - assertTrue(crypto.verify("test", message, publicKey.getEncoded(), - signature)); + assertTrue(crypto.verifySignature(signature, "test", message, + publicKey.getEncoded())); } @Test @@ -146,15 +146,15 @@ public class KeyEncodingAndParsingTest extends BrambleTestCase { byte[] signature = crypto.sign("test", message, privateKey.getEncoded()); // Verify the signature - assertTrue(crypto.verify("test", message, publicKey.getEncoded(), - signature)); + assertTrue(crypto.verifySignature(signature, "test", message, + publicKey.getEncoded())); // Encode and parse the private key - no exceptions should be thrown privateKey = parser.parsePrivateKey(privateKey.getEncoded()); // Sign the data again - the signatures should be the same byte[] signature1 = crypto.sign("test", message, privateKey.getEncoded()); - assertTrue(crypto.verify("test", message, publicKey.getEncoded(), - signature1)); + assertTrue(crypto.verifySignature(signature1, "test", message, + publicKey.getEncoded())); assertArrayEquals(signature, signature1); } diff --git a/bramble-core/src/test/java/org/briarproject/bramble/crypto/MacTest.java b/bramble-core/src/test/java/org/briarproject/bramble/crypto/MacTest.java index 7fb0717b7..b55fc1017 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/crypto/MacTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/crypto/MacTest.java @@ -13,6 +13,7 @@ import static org.briarproject.bramble.test.TestUtils.getSecretKey; import static org.briarproject.bramble.util.StringUtils.getRandomString; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; public class MacTest extends BrambleTestCase { @@ -32,6 +33,7 @@ public class MacTest extends BrambleTestCase { byte[] mac = crypto.mac(label1, key1, input1, input2, input3); byte[] mac1 = crypto.mac(label1, key1, input1, input2, input3); assertArrayEquals(mac, mac1); + assertTrue(crypto.verifyMac(mac, label1, key1, input1, input2, input3)); } @Test @@ -40,6 +42,11 @@ public class MacTest extends BrambleTestCase { byte[] mac = crypto.mac(label1, key1, input1, input2, input3); byte[] mac1 = crypto.mac(label2, key1, input1, input2, input3); assertFalse(Arrays.equals(mac, mac1)); + // Each MAC should fail to verify with the other MAC's label + assertFalse(crypto.verifyMac(mac, label2, key1, input1, input2, + input3)); + assertFalse(crypto.verifyMac(mac1, label1, key2, input1, input2, + input3)); } @Test @@ -48,6 +55,11 @@ public class MacTest extends BrambleTestCase { byte[] mac = crypto.mac(label1, key1, input1, input2, input3); byte[] mac1 = crypto.mac(label1, key2, input1, input2, input3); assertFalse(Arrays.equals(mac, mac1)); + // Each MAC should fail to verify with the other MAC's key + assertFalse(crypto.verifyMac(mac, label1, key2, input1, input2, + input3)); + assertFalse(crypto.verifyMac(mac1, label2, key1, input1, input2, + input3)); } @Test @@ -57,6 +69,11 @@ public class MacTest extends BrambleTestCase { byte[] mac = crypto.mac(label1, key1, input1, input2, input3); byte[] mac1 = crypto.mac(label1, key1, input3, input2, input1); assertFalse(Arrays.equals(mac, mac1)); + // Each MAC should fail to verify with the other MAC's inputs + assertFalse(crypto.verifyMac(mac, label1, key2, input3, input2, + input1)); + assertFalse(crypto.verifyMac(mac1, label1, key1, input1, input2, + input3)); } } diff --git a/bramble-core/src/test/java/org/briarproject/bramble/crypto/SignatureTest.java b/bramble-core/src/test/java/org/briarproject/bramble/crypto/SignatureTest.java index 09561c8c6..2939541b3 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/crypto/SignatureTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/crypto/SignatureTest.java @@ -28,8 +28,8 @@ public abstract class SignatureTest extends BrambleTestCase { protected abstract byte[] sign(String label, byte[] toSign, byte[] privateKey) throws GeneralSecurityException; - protected abstract boolean verify(String label, byte[] signedData, - byte[] publicKey, byte[] signature) throws GeneralSecurityException; + protected abstract boolean verify(byte[] signature, String label, + byte[] signed, byte[] publicKey) throws GeneralSecurityException; SignatureTest() { crypto = new CryptoComponentImpl(new TestSecureRandomProvider(), null); @@ -85,7 +85,7 @@ public abstract class SignatureTest extends BrambleTestCase { @Test public void testSignatureVerification() throws Exception { byte[] sig = sign(label, inputBytes, privateKey); - assertTrue(verify(label, inputBytes, publicKey, sig)); + assertTrue(verify(sig, label, inputBytes, publicKey)); } @Test @@ -95,7 +95,7 @@ public abstract class SignatureTest extends BrambleTestCase { byte[] privateKey2 = k2.getPrivate().getEncoded(); // calculate the signature with different key, should fail to verify byte[] sig = sign(label, inputBytes, privateKey2); - assertFalse(verify(label, inputBytes, publicKey, sig)); + assertFalse(verify(sig, label, inputBytes, publicKey)); } @Test @@ -104,7 +104,7 @@ public abstract class SignatureTest extends BrambleTestCase { byte[] inputBytes2 = TestUtils.getRandomBytes(123); // calculate the signature with different input, should fail to verify byte[] sig = sign(label, inputBytes, privateKey); - assertFalse(verify(label, inputBytes2, publicKey, sig)); + assertFalse(verify(sig, label, inputBytes2, publicKey)); } @Test @@ -113,7 +113,7 @@ public abstract class SignatureTest extends BrambleTestCase { String label2 = StringUtils.getRandomString(42); // calculate the signature with different label, should fail to verify byte[] sig = sign(label, inputBytes, privateKey); - assertFalse(verify(label2, inputBytes, publicKey, sig)); + assertFalse(verify(sig, label2, inputBytes, publicKey)); } } diff --git a/briar-core/src/main/java/org/briarproject/briar/blog/BlogPostValidator.java b/briar-core/src/main/java/org/briarproject/briar/blog/BlogPostValidator.java index 122fbe7f9..6dc845623 100644 --- a/briar-core/src/main/java/org/briarproject/briar/blog/BlogPostValidator.java +++ b/briar-core/src/main/java/org/briarproject/briar/blog/BlogPostValidator.java @@ -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); } diff --git a/briar-core/src/main/java/org/briarproject/briar/forum/ForumPostValidator.java b/briar-core/src/main/java/org/briarproject/briar/forum/ForumPostValidator.java index 89260bf7c..8357361c7 100644 --- a/briar-core/src/main/java/org/briarproject/briar/forum/ForumPostValidator.java +++ b/briar-core/src/main/java/org/briarproject/briar/forum/ForumPostValidator.java @@ -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); } diff --git a/briar-core/src/main/java/org/briarproject/briar/introduction/IntroduceeManager.java b/briar-core/src/main/java/org/briarproject/briar/introduction/IntroduceeManager.java index 82b6cc949..4666ac92e 100644 --- a/briar-core/src/main/java/org/briarproject/briar/introduction/IntroduceeManager.java +++ b/briar-core/src/main/java/org/briarproject/briar/introduction/IntroduceeManager.java @@ -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(); } diff --git a/briar-core/src/main/java/org/briarproject/briar/privategroup/GroupMessageValidator.java b/briar-core/src/main/java/org/briarproject/briar/privategroup/GroupMessageValidator.java index cb5741fdb..525a7216a 100644 --- a/briar-core/src/main/java/org/briarproject/briar/privategroup/GroupMessageValidator.java +++ b/briar-core/src/main/java/org/briarproject/briar/privategroup/GroupMessageValidator.java @@ -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(); } diff --git a/briar-core/src/main/java/org/briarproject/briar/privategroup/invitation/GroupInvitationValidator.java b/briar-core/src/main/java/org/briarproject/briar/privategroup/invitation/GroupInvitationValidator.java index 8d7f0feb3..251b416a8 100644 --- a/briar-core/src/main/java/org/briarproject/briar/privategroup/invitation/GroupInvitationValidator.java +++ b/briar-core/src/main/java/org/briarproject/briar/privategroup/invitation/GroupInvitationValidator.java @@ -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(); } diff --git a/briar-core/src/test/java/org/briarproject/briar/blog/BlogPostValidatorTest.java b/briar-core/src/test/java/org/briarproject/briar/blog/BlogPostValidatorTest.java index 6ca21569d..f2ca321d7 100644 --- a/briar-core/src/test/java/org/briarproject/briar/blog/BlogPostValidatorTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/blog/BlogPostValidatorTest.java @@ -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()); }}); } diff --git a/briar-core/src/test/java/org/briarproject/briar/forum/ForumPostValidatorTest.java b/briar-core/src/test/java/org/briarproject/briar/forum/ForumPostValidatorTest.java index ee04074e2..6fc64fccb 100644 --- a/briar-core/src/test/java/org/briarproject/briar/forum/ForumPostValidatorTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/forum/ForumPostValidatorTest.java @@ -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())); }}); diff --git a/briar-core/src/test/java/org/briarproject/briar/introduction/IntroduceeManagerTest.java b/briar-core/src/test/java/org/briarproject/briar/introduction/IntroduceeManagerTest.java index 647502b13..5f8391d9b 100644 --- a/briar-core/src/test/java/org/briarproject/briar/introduction/IntroduceeManagerTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/introduction/IntroduceeManagerTest.java @@ -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); diff --git a/briar-core/src/test/java/org/briarproject/briar/privategroup/GroupMessageValidatorTest.java b/briar-core/src/test/java/org/briarproject/briar/privategroup/GroupMessageValidatorTest.java index 8d8039794..196ce09ca 100644 --- a/briar-core/src/test/java/org/briarproject/briar/privategroup/GroupMessageValidatorTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/privategroup/GroupMessageValidatorTest.java @@ -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())); }}); diff --git a/briar-core/src/test/java/org/briarproject/briar/privategroup/invitation/GroupInvitationValidatorTest.java b/briar-core/src/test/java/org/briarproject/briar/privategroup/invitation/GroupInvitationValidatorTest.java index d469b959e..d68a5edab 100644 --- a/briar-core/src/test/java/org/briarproject/briar/privategroup/invitation/GroupInvitationValidatorTest.java +++ b/briar-core/src/test/java/org/briarproject/briar/privategroup/invitation/GroupInvitationValidatorTest.java @@ -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 {