mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-05-01 14:13:22 +01:00
Combine username confirmation and link creation into a single operation.
This commit is contained in:
@@ -783,8 +783,15 @@ public class SignalServiceAccountManager {
|
||||
return this.pushServiceSocket.reserveUsername(usernameHashes);
|
||||
}
|
||||
|
||||
public void confirmUsername(Username username) throws IOException {
|
||||
this.pushServiceSocket.confirmUsername(username);
|
||||
public UsernameLinkComponents confirmUsernameAndCreateNewLink(Username username) throws IOException {
|
||||
try {
|
||||
UsernameLink link = link = username.generateLink();
|
||||
UUID serverId = this.pushServiceSocket.confirmUsernameAndCreateNewLink(username, link);
|
||||
|
||||
return new UsernameLinkComponents(link.getEntropy(), serverId);
|
||||
} catch (BaseUsernameException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public UsernameLinkComponents updateUsernameLink(UsernameLink newUsernameLink) throws IOException {
|
||||
|
||||
@@ -9,8 +9,12 @@ class ConfirmUsernameRequest {
|
||||
@JsonProperty
|
||||
private String zkProof;
|
||||
|
||||
ConfirmUsernameRequest(String usernameHash, String zkProof) {
|
||||
this.usernameHash = usernameHash;
|
||||
this.zkProof = zkProof;
|
||||
@JsonProperty
|
||||
private String encryptedUsername;
|
||||
|
||||
ConfirmUsernameRequest(String usernameHash, String zkProof, String encryptedUsername) {
|
||||
this.usernameHash = usernameHash;
|
||||
this.zkProof = zkProof;
|
||||
this.encryptedUsername = encryptedUsername;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.whispersystems.signalservice.internal.push
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
|
||||
import org.whispersystems.signalservice.internal.util.JsonUtil
|
||||
import java.util.UUID
|
||||
|
||||
/** Response body for confirming a username reservation. */
|
||||
class ConfirmUsernameResponse(
|
||||
@JsonProperty
|
||||
val usernameHash: String,
|
||||
|
||||
@JsonProperty
|
||||
@JsonDeserialize(using = JsonUtil.UuidDeserializer::class)
|
||||
val usernameLinkHandle: UUID
|
||||
)
|
||||
@@ -1112,15 +1112,19 @@ public class PushServiceSocket {
|
||||
* @param username The username the user wishes to confirm.
|
||||
* @throws IOException Thrown when the username is invalid or taken, or when another network error occurs.
|
||||
*/
|
||||
public void confirmUsername(Username username) throws IOException {
|
||||
public UUID confirmUsernameAndCreateNewLink(Username username, Username.UsernameLink link) throws IOException {
|
||||
try {
|
||||
byte[] randomness = new byte[32];
|
||||
random.nextBytes(randomness);
|
||||
|
||||
byte[] proof = username.generateProofWithRandomness(randomness);
|
||||
ConfirmUsernameRequest confirmUsernameRequest = new ConfirmUsernameRequest(Base64.encodeUrlSafeWithoutPadding(username.getHash()), Base64.encodeUrlSafeWithoutPadding(proof));
|
||||
ConfirmUsernameRequest confirmUsernameRequest = new ConfirmUsernameRequest(
|
||||
Base64.encodeUrlSafeWithoutPadding(username.getHash()),
|
||||
Base64.encodeUrlSafeWithoutPadding(proof),
|
||||
Base64.encodeUrlSafeWithoutPadding(link.getEncryptedUsername())
|
||||
);
|
||||
|
||||
makeServiceRequest(CONFIRM_USERNAME_PATH, "PUT", JsonUtil.toJson(confirmUsernameRequest), NO_HEADERS, (responseCode, body) -> {
|
||||
String response = makeServiceRequest(CONFIRM_USERNAME_PATH, "PUT", JsonUtil.toJson(confirmUsernameRequest), NO_HEADERS, (responseCode, body) -> {
|
||||
switch (responseCode) {
|
||||
case 409:
|
||||
throw new UsernameIsNotReservedException();
|
||||
@@ -1128,6 +1132,8 @@ public class PushServiceSocket {
|
||||
throw new UsernameTakenException();
|
||||
}
|
||||
}, Optional.empty());
|
||||
|
||||
return JsonUtil.fromJson(response, ConfirmUsernameResponse.class).getUsernameLinkHandle();
|
||||
} catch (BaseUsernameException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user