Correctly serialize provisioning addresses.

// FREEBIE
This commit is contained in:
Moxie Marlinspike 2015-03-24 12:10:59 -07:00
parent a58f3f0fe3
commit 843b16c1f0
3 changed files with 18 additions and 11 deletions

View File

@ -46,7 +46,7 @@ public class ProvisioningController {
{
rateLimiters.getMessagesLimiter().validate(source.getNumber());
if (!websocketSender.sendProvisioningMessage(new ProvisioningAddress(destinationName),
if (!websocketSender.sendProvisioningMessage(new ProvisioningAddress(destinationName, 0),
Base64.decode(message.getBody())))
{
throw new WebApplicationException(Response.Status.NOT_FOUND);

View File

@ -7,15 +7,16 @@ import java.security.SecureRandom;
public class ProvisioningAddress extends WebsocketAddress {
private final String address;
public ProvisioningAddress(String address, int id) throws InvalidWebsocketAddressException {
super(address, id);
}
public ProvisioningAddress(String address) throws InvalidWebsocketAddressException {
super(address, 0);
this.address = address;
public ProvisioningAddress(String serialized) throws InvalidWebsocketAddressException {
super(serialized);
}
public String getAddress() {
return address;
return getNumber();
}
public static ProvisioningAddress generate() {
@ -24,7 +25,7 @@ public class ProvisioningAddress extends WebsocketAddress {
SecureRandom.getInstance("SHA1PRNG").nextBytes(random);
return new ProvisioningAddress(Base64.encodeBytesWithoutPadding(random)
.replace('+', '-').replace('/', '_'));
.replace('+', '-').replace('/', '_'), 0);
} catch (NoSuchAlgorithmException | InvalidWebsocketAddressException e) {
throw new AssertionError(e);
}

View File

@ -52,10 +52,16 @@ public class ProvisioningConnection implements DispatchChannel {
@Override
public void onDispatchSubscribed(String channel) {
this.client.sendRequest("PUT", "/v1/address", Optional.of(ProvisioningUuid.newBuilder()
.setUuid(channel)
.build()
.toByteArray()));
try {
ProvisioningAddress address = new ProvisioningAddress(channel);
this.client.sendRequest("PUT", "/v1/address", Optional.of(ProvisioningUuid.newBuilder()
.setUuid(address.getAddress())
.build()
.toByteArray()));
} catch (InvalidWebsocketAddressException e) {
logger.warn("Badly formatted address", e);
this.client.close(1001, "Server Error");
}
}
@Override