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);
/**
* Encode the onion/hidden service address given its public key. As
* specified here: https://gitweb.torproject.org/torspec.git/tree/rend-spec-v3.txt?id=29245fd5#n2135
* Encode the Onion given its public key. Specified here:
* 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
public class MailboxPropertiesUpdate {
private final String onionAddress;
private final String onion;
private final MailboxAuthToken authToken;
private final MailboxFolderId inboxId;
private final MailboxFolderId outboxId;
public MailboxPropertiesUpdate(String onionAddress,
public MailboxPropertiesUpdate(String onion,
MailboxAuthToken authToken, MailboxFolderId inboxId,
MailboxFolderId outboxId) {
this.onionAddress = onionAddress;
this.onion = onion;
this.authToken = authToken;
this.inboxId = inboxId;
this.outboxId = outboxId;
}
public String getOnionAddress() {
return onionAddress;
public String getOnion() {
return onion;
}
public MailboxAuthToken getAuthToken() {

View File

@@ -35,15 +35,15 @@ public interface MailboxPropertyManager {
/**
* 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_INBOXID = "inboxId";
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,

View File

@@ -281,7 +281,7 @@ public class TestUtils {
if (a == null || b == null) {
return a == b;
}
return a.getOnionAddress().equals(b.getOnionAddress()) &&
return a.getOnion().equals(b.getOnion()) &&
a.getAuthToken().equals(b.getAuthToken()) &&
a.getInboxId().equals(b.getInboxId()) &&
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_KEY_AUTHTOKEN;
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_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_PROPERTY_LENGTH;
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
@@ -422,10 +422,10 @@ class ClientHelperImpl implements ClientHelper {
if (properties.size() < PROP_COUNT) {
throw new FormatException();
}
String onionAddress = properties.getString(PROP_KEY_ONIONADDRESS);
checkLength(onionAddress, PROP_ONIONADDRESS_LENGTH);
String onion = properties.getString(PROP_KEY_ONION);
checkLength(onion, PROP_ONION_LENGTH);
try {
Base32.decode(onionAddress, true);
Base32.decode(onion, true);
} catch (IllegalArgumentException e) {
throw new FormatException();
}
@@ -435,7 +435,7 @@ class ClientHelperImpl implements ClientHelper {
checkLength(inboxId, UniqueId.LENGTH);
byte[] outboxId = properties.getRaw(PROP_KEY_OUTBOXID);
checkLength(outboxId, UniqueId.LENGTH);
return new MailboxPropertiesUpdate(onionAddress,
return new MailboxPropertiesUpdate(onion,
new MailboxAuthToken(authToken), new MailboxFolderId(inboxId),
new MailboxFolderId(outboxId));
}

View File

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

View File

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

View File

@@ -263,7 +263,7 @@ class MailboxPropertyManagerImpl implements MailboxPropertyManager,
@Nullable MailboxPropertiesUpdate p) {
BdfDictionary dict = new BdfDictionary();
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_INBOXID, p.getInboxId().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[] remoteSeed = alice ? bobSeed : aliceSeed;
String blob = torRendezvousCrypto.getPrivateKeyBlob(localSeed);
String localOnion = torRendezvousCrypto.getOnionAddress(localSeed);
String remoteOnion = torRendezvousCrypto.getOnionAddress(remoteSeed);
String localOnion = torRendezvousCrypto.getOnion(localSeed);
String remoteOnion = torRendezvousCrypto.getOnion(remoteSeed);
TransportProperties remoteProperties = new TransportProperties();
remoteProperties.put(PROP_ONION_V3, remoteOnion);
try {

View File

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

View File

@@ -21,9 +21,9 @@ class TorRendezvousCryptoImpl implements TorRendezvousCrypto {
}
@Override
public String getOnionAddress(byte[] seed) {
public String getOnion(byte[] seed) {
EdDSAPrivateKeySpec spec = new EdDSAPrivateKeySpec(seed, CURVE_SPEC);
return crypto.encodeOnionAddress(spec.getA().toByteArray());
return crypto.encodeOnion(spec.getA().toByteArray());
}
@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.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_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.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getMessage;

View File

@@ -87,7 +87,7 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
@Test
public void testSuccessfulPairing() throws Exception {
context.checking(new Expectations() {{
oneOf(crypto).encodeOnionAddress(onionBytes);
oneOf(crypto).encodeOnion(onionBytes);
will(returnValue(onion));
oneOf(api).setup(with(matches(setupProperties)));
will(returnValue(ownerToken));
@@ -141,7 +141,7 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
private void testApiException(Exception e,
Class<? extends MailboxPairingState> s) throws Exception {
context.checking(new Expectations() {{
oneOf(crypto).encodeOnionAddress(onionBytes);
oneOf(crypto).encodeOnion(onionBytes);
will(returnValue(onion));
oneOf(api).setup(with(matches(setupProperties)));
will(throwException(e));
@@ -155,7 +155,7 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
@Test
public void testDbException() throws Exception {
context.checking(new Expectations() {{
oneOf(crypto).encodeOnionAddress(onionBytes);
oneOf(crypto).encodeOnion(onionBytes);
will(returnValue(onion));
oneOf(api).setup(with(matches(setupProperties)));
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.PROP_KEY_AUTHTOKEN;
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.sync.Group.Visibility.SHARED;
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() {
byte[] pubkeyBytes =
crypto.generateSignatureKeyPair().getPublic().getEncoded();
return crypto.encodeOnionAddress(pubkeyBytes);
return crypto.encodeOnion(pubkeyBytes);
}
private void addAvatar(Contact c) throws DbException {