diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcService.java b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcService.java index c46920636..2e3914afe 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcService.java @@ -562,6 +562,11 @@ public class AccountsGrpcService extends SimpleAccountsGrpc.AccountsImplBase { @Override public GenerateTotpKeyResponse generateTotpKey(final GenerateTotpKeyRequest request) { try { + final Account account = getAuthenticatedAccount(); + if (account.getNumber().isPresent()) { + throw GrpcExceptions.invalidArguments("TOTP keys may not be generated for an account with a number"); + } + final TotpKey pendingTotpKey = accountsManager.generatePendingTotpKey(AuthenticationUtil.requireAuthenticatedDevice().accountIdentifier()); @@ -585,6 +590,11 @@ public class AccountsGrpcService extends SimpleAccountsGrpc.AccountsImplBase { @Override public ConfirmTotpKeyResponse confirmTotpKey(final ConfirmTotpKeyRequest request) { try { + final Account account = getAuthenticatedAccount(); + if (account.getNumber().isPresent()) { + throw GrpcExceptions.invalidArguments("TOTP keys may not be added to an account with a number"); + } + final Optional maybeConfirmedTotpKeyId = accountsManager.confirmPendingTotpKey( AuthenticationUtil.requireAuthenticatedDevice().accountIdentifier(), diff --git a/service/src/main/proto/org/signal/chat/account.proto b/service/src/main/proto/org/signal/chat/account.proto index 06f95b202..af749fbbc 100644 --- a/service/src/main/proto/org/signal/chat/account.proto +++ b/service/src/main/proto/org/signal/chat/account.proto @@ -80,11 +80,15 @@ service Accounts { // Generates and stores a pending TOTP key for the authenticated account. // To "activate" the key, callers must call the `ConfirmTotpKey` endpoint. + // + // TOTP keys may only be generated for accounts without phone numbers. rpc GenerateTotpKey(GenerateTotpKeyRequest) returns (GenerateTotpKeyResponse) {} // Confirms that the caller has stored and can derive one-time passwords from // a pending TOTP key generated via `GenerateTotpKey` and stores/activates the // key for the caller's account + // + // TOTP keys may only be generated for accounts without phone numbers. rpc ConfirmTotpKey(ConfirmTotpKeyRequest) returns (ConfirmTotpKeyResponse) {} // Returns a list of confirmed MFA keys for the authenticated account diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcServiceTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcServiceTest.java index 98a9da7d5..be246f0d3 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcServiceTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/AccountsGrpcServiceTest.java @@ -1130,6 +1130,11 @@ class AccountsGrpcServiceTest extends SimpleBaseGrpcTest + authenticatedServiceStub().generateTotpKey(GenerateTotpKeyRequest.getDefaultInstance())); + + GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, "CONSTRAINT_VIOLATED", () -> + authenticatedServiceStub().confirmTotpKey(ConfirmTotpKeyRequest.newBuilder() + .setOneTimePassword(123456) + .setMetadataCiphertext(ByteString.copyFrom(TestRandomUtil.nextBytes(MFA_KEY_METADATA_SIZE))) + .build())); + } + @Test void listTotpKeys() {