From dc6971734a5e5eead2f3ae2f000c883197b361e4 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Tue, 14 May 2019 14:58:11 -0300 Subject: [PATCH] [briar-core] Add a getRealHandshakeLink() method to BriarTestUtils Also allow testOutput from briar-core to be used in briar-headless --- briar-core/build.gradle | 12 ++++++++++++ .../briarproject/briar/test/BriarTestUtils.java | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/briar-core/build.gradle b/briar-core/build.gradle index c37cedb75..cd3fee934 100644 --- a/briar-core/build.gradle +++ b/briar-core/build.gradle @@ -30,3 +30,15 @@ dependencies { signature 'org.codehaus.mojo.signature:java16:1.1@signature' } + +// needed to make test output available to briar-headless +configurations { + testOutput.extendsFrom(testCompile) +} +task jarTest(type: Jar, dependsOn: testClasses) { + from sourceSets.test.output + classifier = 'test' +} +artifacts { + testOutput jarTest +} diff --git a/briar-core/src/test/java/org/briarproject/briar/test/BriarTestUtils.java b/briar-core/src/test/java/org/briarproject/briar/test/BriarTestUtils.java index 314040cfe..b99ab2c36 100644 --- a/briar-core/src/test/java/org/briarproject/briar/test/BriarTestUtils.java +++ b/briar-core/src/test/java/org/briarproject/briar/test/BriarTestUtils.java @@ -1,13 +1,19 @@ package org.briarproject.briar.test; +import org.briarproject.bramble.api.crypto.CryptoComponent; +import org.briarproject.bramble.api.crypto.KeyPair; import org.briarproject.bramble.api.db.DbException; import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.AuthorFactory; import org.briarproject.bramble.api.identity.LocalAuthor; import org.briarproject.bramble.api.sync.GroupId; +import org.briarproject.bramble.util.Base32; import org.briarproject.briar.api.client.MessageTracker; import org.briarproject.briar.api.client.MessageTracker.GroupCount; +import static java.lang.System.arraycopy; +import static org.briarproject.bramble.api.contact.HandshakeLinkConstants.FORMAT_VERSION; +import static org.briarproject.bramble.api.contact.HandshakeLinkConstants.RAW_LINK_BYTES; import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH; import static org.briarproject.bramble.util.StringUtils.getRandomString; import static org.junit.Assert.assertEquals; @@ -40,4 +46,14 @@ public class BriarTestUtils { return authorFactory.createLocalAuthor(name); } + public static String getRealHandshakeLink(CryptoComponent cryptoComponent) { + KeyPair keyPair = cryptoComponent.generateAgreementKeyPair(); + byte[] linkBytes = new byte[RAW_LINK_BYTES]; + byte[] version = new byte[] {FORMAT_VERSION}; + byte[] publicKey = keyPair.getPublic().getEncoded(); + arraycopy(version,0, linkBytes, 0, 1); + arraycopy(publicKey,0, linkBytes, 1, RAW_LINK_BYTES - 1); + return ("briar://" + Base32.encode(linkBytes)).toLowerCase(); + } + }