Support for ephemeral provisioning communication channels.

// FREEBIE
This commit is contained in:
Moxie Marlinspike
2015-01-18 18:09:25 -08:00
parent 715181f830
commit 79f83babb3
14 changed files with 724 additions and 17 deletions

View File

@@ -0,0 +1,38 @@
package org.whispersystems.textsecuregcm.websocket;
import org.whispersystems.textsecuregcm.util.Base64;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
public class ProvisioningAddress extends WebsocketAddress {
private static final String PREFIX = ">>ephemeral-";
private final String address;
public ProvisioningAddress(String address) throws InvalidWebsocketAddressException {
super(address, 0);
this.address = address;
if (address == null || !address.startsWith(PREFIX)) {
throw new InvalidWebsocketAddressException(address);
}
}
public String getAddress() {
return address;
}
public static ProvisioningAddress generate() {
try {
byte[] random = new byte[16];
SecureRandom.getInstance("SHA1PRNG").nextBytes(random);
return new ProvisioningAddress(PREFIX + Base64.encodeBytesWithoutPadding(random)
.replace('+', '-').replace('/', '_'));
} catch (NoSuchAlgorithmException | InvalidWebsocketAddressException e) {
throw new AssertionError(e);
}
}
}