Rename, clarifying this is not an address; it has no scheme, no .onion

This commit is contained in:
Daniel Lublin
2022-03-18 14:04:08 +01:00
parent 5bc5791ddb
commit 13eebe393a
15 changed files with 35 additions and 33 deletions

View File

@@ -175,9 +175,11 @@ public interface CryptoComponent {
String asciiArmour(byte[] b, int lineLength); String asciiArmour(byte[] b, int lineLength);
/** /**
* Encode the onion/hidden service address given its public key. As * Encode the Onion given its public key. Specified here:
* specified here: https://gitweb.torproject.org/torspec.git/tree/rend-spec-v3.txt?id=29245fd5#n2135 * https://gitweb.torproject.org/torspec.git/tree/rend-spec-v3.txt?id=29245fd5#n2135
*
* @return the encoded onion, base32 chars
*/ */
String encodeOnionAddress(byte[] publicKey); String encodeOnion(byte[] publicKey);
} }

View File

@@ -8,22 +8,22 @@ import javax.annotation.concurrent.Immutable;
@NotNullByDefault @NotNullByDefault
public class MailboxPropertiesUpdate { public class MailboxPropertiesUpdate {
private final String onionAddress; private final String onion;
private final MailboxAuthToken authToken; private final MailboxAuthToken authToken;
private final MailboxFolderId inboxId; private final MailboxFolderId inboxId;
private final MailboxFolderId outboxId; private final MailboxFolderId outboxId;
public MailboxPropertiesUpdate(String onionAddress, public MailboxPropertiesUpdate(String onion,
MailboxAuthToken authToken, MailboxFolderId inboxId, MailboxAuthToken authToken, MailboxFolderId inboxId,
MailboxFolderId outboxId) { MailboxFolderId outboxId) {
this.onionAddress = onionAddress; this.onion = onion;
this.authToken = authToken; this.authToken = authToken;
this.inboxId = inboxId; this.inboxId = inboxId;
this.outboxId = outboxId; this.outboxId = outboxId;
} }
public String getOnionAddress() { public String getOnion() {
return onionAddress; return onion;
} }
public MailboxAuthToken getAuthToken() { public MailboxAuthToken getAuthToken() {

View File

@@ -35,15 +35,15 @@ public interface MailboxPropertyManager {
/** /**
* The required properties of a non-empty update message. * The required properties of a non-empty update message.
*/ */
String PROP_KEY_ONIONADDRESS = "onionAddress"; String PROP_KEY_ONION = "onion";
String PROP_KEY_AUTHTOKEN = "authToken"; String PROP_KEY_AUTHTOKEN = "authToken";
String PROP_KEY_INBOXID = "inboxId"; String PROP_KEY_INBOXID = "inboxId";
String PROP_KEY_OUTBOXID = "outboxId"; String PROP_KEY_OUTBOXID = "outboxId";
/** /**
* Length of the Onion Address property. * Length of the Onion property.
*/ */
int PROP_ONIONADDRESS_LENGTH = 56; int PROP_ONION_LENGTH = 56;
/** /**
* Message metadata key for the version number of a local or remote update, * Message metadata key for the version number of a local or remote update,

View File

@@ -281,7 +281,7 @@ public class TestUtils {
if (a == null || b == null) { if (a == null || b == null) {
return a == b; return a == b;
} }
return a.getOnionAddress().equals(b.getOnionAddress()) && return a.getOnion().equals(b.getOnion()) &&
a.getAuthToken().equals(b.getAuthToken()) && a.getAuthToken().equals(b.getAuthToken()) &&
a.getInboxId().equals(b.getInboxId()) && a.getInboxId().equals(b.getInboxId()) &&
a.getOutboxId().equals(b.getOutboxId()); a.getOutboxId().equals(b.getOutboxId());

View File

@@ -55,9 +55,9 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_K
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_COUNT; import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_COUNT;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_AUTHTOKEN; import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_AUTHTOKEN;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_INBOXID; import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_INBOXID;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_ONIONADDRESS; import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_ONION;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_OUTBOXID; import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_OUTBOXID;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_ONIONADDRESS_LENGTH; import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_ONION_LENGTH;
import static org.briarproject.bramble.api.properties.TransportPropertyConstants.MAX_PROPERTIES_PER_TRANSPORT; import static org.briarproject.bramble.api.properties.TransportPropertyConstants.MAX_PROPERTIES_PER_TRANSPORT;
import static org.briarproject.bramble.api.properties.TransportPropertyConstants.MAX_PROPERTY_LENGTH; import static org.briarproject.bramble.api.properties.TransportPropertyConstants.MAX_PROPERTY_LENGTH;
import static org.briarproject.bramble.util.ValidationUtils.checkLength; import static org.briarproject.bramble.util.ValidationUtils.checkLength;
@@ -422,10 +422,10 @@ class ClientHelperImpl implements ClientHelper {
if (properties.size() < PROP_COUNT) { if (properties.size() < PROP_COUNT) {
throw new FormatException(); throw new FormatException();
} }
String onionAddress = properties.getString(PROP_KEY_ONIONADDRESS); String onion = properties.getString(PROP_KEY_ONION);
checkLength(onionAddress, PROP_ONIONADDRESS_LENGTH); checkLength(onion, PROP_ONION_LENGTH);
try { try {
Base32.decode(onionAddress, true); Base32.decode(onion, true);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
throw new FormatException(); throw new FormatException();
} }
@@ -435,7 +435,7 @@ class ClientHelperImpl implements ClientHelper {
checkLength(inboxId, UniqueId.LENGTH); checkLength(inboxId, UniqueId.LENGTH);
byte[] outboxId = properties.getRaw(PROP_KEY_OUTBOXID); byte[] outboxId = properties.getRaw(PROP_KEY_OUTBOXID);
checkLength(outboxId, UniqueId.LENGTH); checkLength(outboxId, UniqueId.LENGTH);
return new MailboxPropertiesUpdate(onionAddress, return new MailboxPropertiesUpdate(onion,
new MailboxAuthToken(authToken), new MailboxFolderId(inboxId), new MailboxAuthToken(authToken), new MailboxFolderId(inboxId),
new MailboxFolderId(outboxId)); new MailboxFolderId(outboxId));
} }

View File

@@ -458,7 +458,7 @@ class CryptoComponentImpl implements CryptoComponent {
} }
@Override @Override
public String encodeOnionAddress(byte[] publicKey) { public String encodeOnion(byte[] publicKey) {
Digest digest = new SHA3Digest(256); Digest digest = new SHA3Digest(256);
byte[] label = ".onion checksum".getBytes(Charset.forName("US-ASCII")); byte[] label = ".onion checksum".getBytes(Charset.forName("US-ASCII"));
digest.update(label, 0, label.length); digest.update(label, 0, label.length);

View File

@@ -162,8 +162,8 @@ class MailboxPairingTaskImpl implements MailboxPairingTask {
} }
LOG.info("QR code is valid"); LOG.info("QR code is valid");
byte[] onionPubKey = Arrays.copyOfRange(bytes, 1, 33); byte[] onionPubKey = Arrays.copyOfRange(bytes, 1, 33);
String onionAddress = crypto.encodeOnionAddress(onionPubKey); String onion = crypto.encodeOnion(onionPubKey);
String baseUrl = "http://" + onionAddress + ".onion"; String baseUrl = "http://" + onion + ".onion";
byte[] tokenBytes = Arrays.copyOfRange(bytes, 33, 65); byte[] tokenBytes = Arrays.copyOfRange(bytes, 33, 65);
MailboxAuthToken setupToken = new MailboxAuthToken(tokenBytes); MailboxAuthToken setupToken = new MailboxAuthToken(tokenBytes);
return new MailboxProperties(baseUrl, setupToken, true); return new MailboxProperties(baseUrl, setupToken, true);

View File

@@ -263,7 +263,7 @@ class MailboxPropertyManagerImpl implements MailboxPropertyManager,
@Nullable MailboxPropertiesUpdate p) { @Nullable MailboxPropertiesUpdate p) {
BdfDictionary dict = new BdfDictionary(); BdfDictionary dict = new BdfDictionary();
if (p != null) { if (p != null) {
dict.put(PROP_KEY_ONIONADDRESS, p.getOnionAddress()); dict.put(PROP_KEY_ONION, p.getOnion());
dict.put(PROP_KEY_AUTHTOKEN, p.getAuthToken().getBytes()); dict.put(PROP_KEY_AUTHTOKEN, p.getAuthToken().getBytes());
dict.put(PROP_KEY_INBOXID, p.getInboxId().getBytes()); dict.put(PROP_KEY_INBOXID, p.getInboxId().getBytes());
dict.put(PROP_KEY_OUTBOXID, p.getOutboxId().getBytes()); dict.put(PROP_KEY_OUTBOXID, p.getOutboxId().getBytes());

View File

@@ -682,8 +682,8 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
byte[] localSeed = alice ? aliceSeed : bobSeed; byte[] localSeed = alice ? aliceSeed : bobSeed;
byte[] remoteSeed = alice ? bobSeed : aliceSeed; byte[] remoteSeed = alice ? bobSeed : aliceSeed;
String blob = torRendezvousCrypto.getPrivateKeyBlob(localSeed); String blob = torRendezvousCrypto.getPrivateKeyBlob(localSeed);
String localOnion = torRendezvousCrypto.getOnionAddress(localSeed); String localOnion = torRendezvousCrypto.getOnion(localSeed);
String remoteOnion = torRendezvousCrypto.getOnionAddress(remoteSeed); String remoteOnion = torRendezvousCrypto.getOnion(remoteSeed);
TransportProperties remoteProperties = new TransportProperties(); TransportProperties remoteProperties = new TransportProperties();
remoteProperties.put(PROP_ONION_V3, remoteOnion); remoteProperties.put(PROP_ONION_V3, remoteOnion);
try { try {

View File

@@ -4,7 +4,7 @@ interface TorRendezvousCrypto {
static final int SEED_BYTES = 32; static final int SEED_BYTES = 32;
String getOnionAddress(byte[] seed); String getOnion(byte[] seed);
String getPrivateKeyBlob(byte[] seed); String getPrivateKeyBlob(byte[] seed);
} }

View File

@@ -21,9 +21,9 @@ class TorRendezvousCryptoImpl implements TorRendezvousCrypto {
} }
@Override @Override
public String getOnionAddress(byte[] seed) { public String getOnion(byte[] seed) {
EdDSAPrivateKeySpec spec = new EdDSAPrivateKeySpec(seed, CURVE_SPEC); EdDSAPrivateKeySpec spec = new EdDSAPrivateKeySpec(seed, CURVE_SPEC);
return crypto.encodeOnionAddress(spec.getA().toByteArray()); return crypto.encodeOnion(spec.getA().toByteArray());
} }
@Override @Override

View File

@@ -46,7 +46,7 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_K
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH; import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATURE_LENGTH;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_AUTHTOKEN; import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_AUTHTOKEN;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_INBOXID; import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_INBOXID;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_ONIONADDRESS; import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_ONION;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_OUTBOXID; import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_OUTBOXID;
import static org.briarproject.bramble.test.TestUtils.getAuthor; import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getMessage; import static org.briarproject.bramble.test.TestUtils.getMessage;

View File

@@ -87,7 +87,7 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
@Test @Test
public void testSuccessfulPairing() throws Exception { public void testSuccessfulPairing() throws Exception {
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(crypto).encodeOnionAddress(onionBytes); oneOf(crypto).encodeOnion(onionBytes);
will(returnValue(onion)); will(returnValue(onion));
oneOf(api).setup(with(matches(setupProperties))); oneOf(api).setup(with(matches(setupProperties)));
will(returnValue(ownerToken)); will(returnValue(ownerToken));
@@ -141,7 +141,7 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
private void testApiException(Exception e, private void testApiException(Exception e,
Class<? extends MailboxPairingState> s) throws Exception { Class<? extends MailboxPairingState> s) throws Exception {
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(crypto).encodeOnionAddress(onionBytes); oneOf(crypto).encodeOnion(onionBytes);
will(returnValue(onion)); will(returnValue(onion));
oneOf(api).setup(with(matches(setupProperties))); oneOf(api).setup(with(matches(setupProperties)));
will(throwException(e)); will(throwException(e));
@@ -155,7 +155,7 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
@Test @Test
public void testDbException() throws Exception { public void testDbException() throws Exception {
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(crypto).encodeOnionAddress(onionBytes); oneOf(crypto).encodeOnion(onionBytes);
will(returnValue(onion)); will(returnValue(onion));
oneOf(api).setup(with(matches(setupProperties))); oneOf(api).setup(with(matches(setupProperties)));
will(returnValue(ownerToken)); will(returnValue(ownerToken));

View File

@@ -38,7 +38,7 @@ import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.MSG_KE
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.MSG_KEY_VERSION; import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.MSG_KEY_VERSION;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_AUTHTOKEN; import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_AUTHTOKEN;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_INBOXID; import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_INBOXID;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_ONIONADDRESS; import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_ONION;
import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_OUTBOXID; import static org.briarproject.bramble.api.mailbox.MailboxPropertyManager.PROP_KEY_OUTBOXID;
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED; import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_DO_NOT_SHARE; import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_DO_NOT_SHARE;

View File

@@ -299,7 +299,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
private String getRandomTorAddress() { private String getRandomTorAddress() {
byte[] pubkeyBytes = byte[] pubkeyBytes =
crypto.generateSignatureKeyPair().getPublic().getEncoded(); crypto.generateSignatureKeyPair().getPublic().getEncoded();
return crypto.encodeOnionAddress(pubkeyBytes); return crypto.encodeOnion(pubkeyBytes);
} }
private void addAvatar(Contact c) throws DbException { private void addAvatar(Contact c) throws DbException {