From 8cbc8b0ce6ce9d7fe395e44e037c9ddff0dd4919 Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Mon, 3 Aug 2026 14:46:18 -0400 Subject: [PATCH] Add `accountRecoveryPassword` to accounts --- .../textsecuregcm/storage/Account.java | 26 +++++++++++++++++++ .../tests/util/AccountsHelper.java | 1 + 2 files changed, 27 insertions(+) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java index 38372fa48..2b82c5e6b 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java @@ -145,6 +145,14 @@ public class Account { @JsonProperty("holds") private List usernameHolds = Collections.emptyList(); + @JsonProperty("arps") + @Nullable + private String accountRecoveryPasswordSalt; + + @JsonProperty("arph") + @Nullable + private String accountRecoveryPasswordHash; + @JsonIgnore private boolean stale; @@ -678,6 +686,24 @@ public class Account { this.zkCredentialKeyRotationId = zkCredentialKeyRotationId; } + public Optional getAccountRecoveryPassword() { + requireNotStale(); + + return accountRecoveryPasswordSalt != null && accountRecoveryPasswordHash != null + ? Optional.of(new SaltedTokenHash(accountRecoveryPasswordSalt, accountRecoveryPasswordHash)) + : Optional.empty(); + } + + public void setAccountRecoveryPassword(final byte[] accountRecoveryPassword) { + requireNotStale(); + + final SaltedTokenHash saltedTokenHash = + SaltedTokenHash.generateFor(HexFormat.of().formatHex(accountRecoveryPassword)); + + this.accountRecoveryPasswordSalt = saltedTokenHash.salt(); + this.accountRecoveryPasswordHash = saltedTokenHash.hash(); + } + public void markStale() { stale = true; } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/AccountsHelper.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/AccountsHelper.java index f66b86c7c..317279b32 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/AccountsHelper.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/AccountsHelper.java @@ -243,6 +243,7 @@ public class AccountsHelper { case "hasLockedCredentials" -> when(updatedAccount.hasLockedCredentials()).thenAnswer(stubbing); case "getCurrentProfileVersion" -> when(updatedAccount.getCurrentProfileVersion()).thenAnswer(stubbing); case "getUnidentifiedAccessKey" -> when(updatedAccount.getUnidentifiedAccessKey()).thenAnswer(stubbing); + case "getRecoveryPassword" -> when(updatedAccount.getAccountRecoveryPassword()).thenAnswer(stubbing); default -> throw new IllegalArgumentException("unsupported method: Account#" + stubbing.getInvocation().getMethod().getName()); } }