From b6bed9d772cfe5240b1199a7b35307d1df6a25ac Mon Sep 17 00:00:00 2001 From: Ravi Khadiwala Date: Tue, 1 Sep 2026 10:11:07 -0500 Subject: [PATCH] Remove confusing subscriber_id_mismatch response --- .../grpc/SubscriptionsGrpcService.java | 45 +++---------- .../proto/org/signal/chat/subscriptions.proto | 67 ++++++------------- .../grpc/SubscriptionsGrpcServiceTest.java | 7 +- 3 files changed, 36 insertions(+), 83 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/SubscriptionsGrpcService.java b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/SubscriptionsGrpcService.java index 002069552..3cd11fd10 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/SubscriptionsGrpcService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/SubscriptionsGrpcService.java @@ -140,9 +140,8 @@ public class SubscriptionsGrpcService extends SimpleSubscriptionsGrpc.Subscripti subscriptionManager.updateSubscriber(subscriberCredentials, creationPermitted); return UpdateSubscriberResponse.newBuilder().setSuccess(Empty.getDefaultInstance()).build(); - } catch (final SubscriptionForbiddenException e) { - return UpdateSubscriberResponse.newBuilder().setSubscriberIdMismatch( - FailedUnidentifiedAuthorization.newBuilder().setDescription(e.errorDetail().orElse("")).build()).build(); + } catch (final SubscriptionForbiddenException _) { + throw GrpcExceptions.invalidArguments("subscriber-ids must be randomly generated"); } catch (SubscriberIdCreationNotPermittedException _) { if (request.getDonationPermit().isEmpty()) { throw GrpcExceptions.invalidArguments("donation permit is required to create a subscriber ID"); @@ -206,11 +205,8 @@ public class SubscriptionsGrpcService extends SimpleSubscriptionsGrpc.Subscripti return CreatePaymentMethodResponse.newBuilder().setResult( CreatePaymentMethodResponse.CreatePaymentMethodResult.newBuilder().setClientSecret(token) .setPaymentProvider(customerAwareSubscriptionPaymentProcessor.getProvider().toProto()).build()).build(); - } catch (final SubscriptionNotFoundException e) { + } catch (final SubscriptionNotFoundException | SubscriptionForbiddenException _) { return CreatePaymentMethodResponse.newBuilder().setSubscriberNotFound(NotFound.newBuilder()).build(); - } catch (final SubscriptionForbiddenException e) { - return CreatePaymentMethodResponse.newBuilder().setSubscriberIdMismatch( - FailedUnidentifiedAuthorization.newBuilder().setDescription(e.errorDetail().orElse("")).build()).build(); } catch (final SubscriptionProcessorConflictException e) { return CreatePaymentMethodResponse.newBuilder().setSubscriptionProcessorConflict( FailedPrecondition.newBuilder().setDescription(e.errorDetail().orElse("")).build()).build(); @@ -231,12 +227,9 @@ public class SubscriptionsGrpcService extends SimpleSubscriptionsGrpc.Subscripti return CreatePayPalPaymentMethodResponse.newBuilder().setResult( CreatePayPalPaymentMethodResponse.CreatePayPalPaymentMethodResult.newBuilder() .setApprovalUrl(details.approvalUrl()).setToken(details.billingAgreementToken()).build()).build(); - } catch (final SubscriptionNotFoundException e) { + } catch (final SubscriptionNotFoundException | SubscriptionForbiddenException _) { return CreatePayPalPaymentMethodResponse.newBuilder().setSubscriberNotFound(NotFound.newBuilder().build()) .build(); - } catch (final SubscriptionForbiddenException e) { - return CreatePayPalPaymentMethodResponse.newBuilder().setSubscriberIdMismatch( - FailedUnidentifiedAuthorization.newBuilder().setDescription(e.errorDetail().orElse("")).build()).build(); } catch (final SubscriptionProcessorConflictException e) { return CreatePayPalPaymentMethodResponse.newBuilder().setSubscriptionProcessorConflict( FailedPrecondition.newBuilder().setDescription(e.errorDetail().orElse("")).build()).build(); @@ -275,15 +268,9 @@ public class SubscriptionsGrpcService extends SimpleSubscriptionsGrpc.Subscripti .orElseGet(() -> SetDefaultPaymentMethodResponse.newBuilder() .setPaymentMethodNotSetUp(FailedPrecondition.newBuilder().build()) .build()); - } catch (final SubscriptionNotFoundException e) { + } catch (final SubscriptionNotFoundException | SubscriptionForbiddenException _) { return SetDefaultPaymentMethodResponse.newBuilder().setSubscriberNotFound(NotFound.newBuilder().build()).build(); - } catch (final SubscriptionForbiddenException e) { - return SetDefaultPaymentMethodResponse.newBuilder() - .setSubscriberIdMismatch(FailedUnidentifiedAuthorization.newBuilder() - .setDescription(e.errorDetail().orElse("")) - .build()) - .build(); - } catch (final SubscriptionProcessorConflictException e) { + } catch (final SubscriptionProcessorConflictException _) { return SetDefaultPaymentMethodResponse.newBuilder() .setPaymentMethodNotSetUp(FailedPrecondition.newBuilder().build()) .build(); @@ -320,11 +307,8 @@ public class SubscriptionsGrpcService extends SimpleSubscriptionsGrpc.Subscripti .setPaymentMethodNotSetUp(FailedPrecondition.newBuilder().build()) .build()); - } catch (final SubscriptionNotFoundException e) { + } catch (final SubscriptionNotFoundException | SubscriptionForbiddenException _) { return SetSubscriptionLevelResponse.newBuilder().setSubscriberNotFound(NotFound.newBuilder().build()).build(); - } catch (final SubscriptionForbiddenException e) { - return SetSubscriptionLevelResponse.newBuilder().setSubscriberIdMismatch( - FailedUnidentifiedAuthorization.newBuilder().setDescription(e.errorDetail().orElse("")).build()).build(); } } @@ -399,11 +383,8 @@ public class SubscriptionsGrpcService extends SimpleSubscriptionsGrpc.Subscripti }; return SetIapSubscriptionResponse.newBuilder() .setSuccess(SetIapSubscriptionResponse.SetIapSubscriptionResult.newBuilder().setLevel(level).build()).build(); - } catch (final SubscriptionNotFoundException e) { + } catch (final SubscriptionNotFoundException | SubscriptionForbiddenException _) { return SetIapSubscriptionResponse.newBuilder().setSubscriberNotFound(NotFound.newBuilder().build()).build(); - } catch (final SubscriptionForbiddenException e) { - return SetIapSubscriptionResponse.newBuilder().setSubscriberIdMismatch( - FailedUnidentifiedAuthorization.newBuilder().setDescription(e.errorDetail().orElse("")).build()).build(); } catch (final SubscriptionProcessorConflictException e) { return SetIapSubscriptionResponse.newBuilder().setSubscriptionProcessorConflict( FailedPrecondition.newBuilder().setDescription(e.errorDetail().orElse("")).build()).build(); @@ -427,12 +408,9 @@ public class SubscriptionsGrpcService extends SimpleSubscriptionsGrpc.Subscripti .map(SubscriptionsGrpcService::buildSubscriptionInformationResponse).orElseGet( () -> GetSubscriptionInformationResponse.newBuilder().setNoSubscription(Empty.getDefaultInstance()) .build()); - } catch (final SubscriptionNotFoundException e) { + } catch (final SubscriptionNotFoundException | SubscriptionForbiddenException _) { return GetSubscriptionInformationResponse.newBuilder().setSubscriberNotFound(NotFound.newBuilder().build()) .build(); - } catch (final SubscriptionForbiddenException e) { - return GetSubscriptionInformationResponse.newBuilder().setSubscriberIdMismatch( - FailedUnidentifiedAuthorization.newBuilder().setDescription(e.errorDetail().orElse("")).build()).build(); } } @@ -492,11 +470,8 @@ public class SubscriptionsGrpcService extends SimpleSubscriptionsGrpc.Subscripti } catch (final SubscriptionReceiptAlreadyRedeemedException e) { return GetReceiptCredentialsResponse.newBuilder().setAlreadyRedeemed(FailedPrecondition.newBuilder().build()) .build(); - } catch (final SubscriptionNotFoundException e) { + } catch (final SubscriptionNotFoundException | SubscriptionForbiddenException _) { return GetReceiptCredentialsResponse.newBuilder().setSubscriberNotFound(NotFound.newBuilder().build()).build(); - } catch (final SubscriptionForbiddenException e) { - return GetReceiptCredentialsResponse.newBuilder().setSubscriberIdMismatch( - FailedUnidentifiedAuthorization.newBuilder().setDescription(e.errorDetail().orElse("")).build()).build(); } } diff --git a/service/src/main/proto/org/signal/chat/subscriptions.proto b/service/src/main/proto/org/signal/chat/subscriptions.proto index 957705e87..4f23c0027 100644 --- a/service/src/main/proto/org/signal/chat/subscriptions.proto +++ b/service/src/main/proto/org/signal/chat/subscriptions.proto @@ -21,7 +21,7 @@ import "org/signal/chat/tag.proto"; service Subscriptions { option (require.auth) = AUTH_ONLY_ANONYMOUS; // Creates a subscriber record if it does not exist, otherwise refreshes its last access time. - + // // Subscribers MUST periodically hit this endpoint to update the access time on the subscription record. Subscribers // SHOULD attempt to make an update call approximately every 3 days. Not accessing this endpoint for an extended // period of time will result in the subscription being canceled. @@ -115,6 +115,7 @@ service Subscriptions { } message UpdateSubscriberRequest { + // New subscriber-ids must be a randomly-generated 32 byte byte-string. bytes subscriber_id = 1 [(require.exactlySize) = 32]; // A libsignal DonationPermit from rpc Donations.CreateDonationPermit. // Not required if the subscriber already exists. @@ -124,11 +125,8 @@ message UpdateSubscriberRequest { message UpdateSubscriberResponse { oneof response { google.protobuf.Empty success = 1; - // The subscriber-key embedded in the subscriber-id did not match the stored - // key for the subscriber-user embedded in the subscriber-id - errors.FailedUnidentifiedAuthorization subscriber_id_mismatch = 2 [(tag.reason) = "subscriber_id_mismatch"]; // The donation permit was expired or already spent - errors.FailedZkAuthentication permit_rejected = 3 [(tag.reason) = "permit_rejected"]; + errors.FailedZkAuthentication permit_rejected = 2 [(tag.reason) = "permit_rejected"]; } } @@ -201,14 +199,11 @@ message CreatePaymentMethodResponse { CreatePaymentMethodResult result = 1; // The subscriber did not exist errors.NotFound subscriber_not_found = 2 [(tag.reason) = "subscriber_not_found"]; - // The subscriber-key embedded in the subscriber-id did not match the stored - // key for the subscriber-user embedded in the subscriber-id - errors.FailedUnidentifiedAuthorization subscriber_id_mismatch = 3 [(tag.reason) = "subscriber_id_mismatch"]; // New payment processor does not match existing processor associated with // the subscription - errors.FailedPrecondition subscription_processor_conflict = 4 [(tag.reason) = "subscription_processor_conflict"]; + errors.FailedPrecondition subscription_processor_conflict = 3 [(tag.reason) = "subscription_processor_conflict"]; // The donation permit was expired or already spent - errors.FailedZkAuthentication permit_rejected = 5 [(tag.reason) = "permit_rejected"]; + errors.FailedZkAuthentication permit_rejected = 4 [(tag.reason) = "permit_rejected"]; } } @@ -232,12 +227,9 @@ message CreatePayPalPaymentMethodResponse { CreatePayPalPaymentMethodResult result = 1; // The subscriber did not exist errors.NotFound subscriber_not_found = 2 [(tag.reason) = "subscriber_not_found"]; - // The subscriber-key embedded in the subscriber-id did not match the stored - // key for the subscriber-user embedded in the subscriber-id - errors.FailedUnidentifiedAuthorization subscriber_id_mismatch = 3 [(tag.reason) = "subscriber_id_mismatch"]; // New payment processor does not match existing processor associated with // the subscription - errors.FailedPrecondition subscription_processor_conflict = 4 [(tag.reason) = "subscription_processor_conflict"]; + errors.FailedPrecondition subscription_processor_conflict = 3 [(tag.reason) = "subscription_processor_conflict"]; } } @@ -265,12 +257,9 @@ message SetDefaultPaymentMethodResponse { google.protobuf.Empty success = 1; // The subscriber did not exist, or the referenced setup intent was not found errors.NotFound subscriber_not_found = 2 [(tag.reason) = "subscriber_not_found"]; - // The subscriber-key embedded in the subscriber-id did not match the stored - // key for the subscriber-user embedded in the subscriber-id - errors.FailedUnidentifiedAuthorization subscriber_id_mismatch = 3 [(tag.reason) = "subscriber_id_mismatch"]; // No payment method has been created for the subscriber, or the provided // payment method has not finished being set up with the processor - errors.FailedPrecondition payment_method_not_set_up = 4 [(tag.reason) = "payment_method_not_set_up"]; + errors.FailedPrecondition payment_method_not_set_up = 3 [(tag.reason) = "payment_method_not_set_up"]; } } @@ -327,28 +316,25 @@ message SetSubscriptionLevelResponse { SetSubscriptionLevelResult success = 1; // The subscriber did not exist errors.NotFound subscriber_not_found = 2 [(tag.reason) = "subscriber_not_found"]; - // The subscriber-key embedded in the subscriber-id did not match the stored - // key for the subscriber-user embedded in the subscriber-id - errors.FailedUnidentifiedAuthorization subscriber_id_mismatch = 3 [(tag.reason) = "subscriber_id_mismatch"]; // New payment processor does not match existing processor associated with // the subscription - errors.FailedPrecondition subscription_processor_conflict = 4 [(tag.reason) = "subscription_processor_conflict"]; + errors.FailedPrecondition subscription_processor_conflict = 3 [(tag.reason) = "subscription_processor_conflict"]; // No payment method has been created for the subscriber - errors.FailedPrecondition payment_method_not_set_up = 5 [(tag.reason) = "payment_method_not_set_up"]; + errors.FailedPrecondition payment_method_not_set_up = 4 [(tag.reason) = "payment_method_not_set_up"]; // The payment processor does not support this operation - errors.FailedPrecondition unsupported_operation = 6 [(tag.reason) = "unsupported_operation"]; + errors.FailedPrecondition unsupported_operation = 5 [(tag.reason) = "unsupported_operation"]; // The requested level was invalid - errors.FailedPrecondition unsupported_level = 7 [(tag.reason) = "unsupported_level"]; + errors.FailedPrecondition unsupported_level = 6 [(tag.reason) = "unsupported_level"]; // The requested currency was invalid - errors.FailedPrecondition unsupported_currency = 8 [(tag.reason) = "unsupported_currency"]; + errors.FailedPrecondition unsupported_currency = 7 [(tag.reason) = "unsupported_currency"]; // The card could not be charged - errors.FailedPrecondition payment_requires_action = 9 [(tag.reason) = "payment_requires_action"]; + errors.FailedPrecondition payment_requires_action = 8 [(tag.reason) = "payment_requires_action"]; // Cannot transition from existing level to the requested level - errors.FailedPrecondition invalid_level_transition = 10 [(tag.reason) = "invalid_level_transition"]; + errors.FailedPrecondition invalid_level_transition = 9 [(tag.reason) = "invalid_level_transition"]; // The idempotency key was invalid or re-used with a modified request - errors.FailedPrecondition invalid_idempotency_key = 11 [(tag.reason) = "invalid_idempotency_key"]; + errors.FailedPrecondition invalid_idempotency_key = 10 [(tag.reason) = "invalid_idempotency_key"]; // The payment failed; see charge failure details - ChargeFailure charge_failure = 12 [(tag.reason) = "charge_failure"]; + ChargeFailure charge_failure = 11 [(tag.reason) = "charge_failure"]; } } @@ -376,18 +362,15 @@ message SetIapSubscriptionResponse { SetIapSubscriptionResult success = 1; // The subscriber did not exist or the provided purchase identifier does not exist errors.NotFound subscriber_not_found = 2 [(tag.reason) = "subscriber_not_found"]; - // The subscriber-key embedded in the subscriber-id did not match the stored - // key for the subscriber-user embedded in the subscriber-id - errors.FailedUnidentifiedAuthorization subscriber_id_mismatch = 3 [(tag.reason) = "subscriber_id_mismatch"]; // New payment processor does not match existing processor associated with // the subscription - errors.FailedPrecondition subscription_processor_conflict = 4 [(tag.reason) = "subscription_processor_conflict"]; + errors.FailedPrecondition subscription_processor_conflict = 3 [(tag.reason) = "subscription_processor_conflict"]; // The subscription is not in a purchase state that grants the user an // entitlement - errors.FailedPrecondition payment_required = 5 [(tag.reason) = "payment_required"]; + errors.FailedPrecondition payment_required = 4 [(tag.reason) = "payment_required"]; // The provided purchase identifier is malformed or the identified // transaction is not supported for use at this endpoint - errors.FailedPrecondition invalid_transaction = 6 [(tag.reason) = "invalid_transaction"]; + errors.FailedPrecondition invalid_transaction = 5 [(tag.reason) = "invalid_transaction"]; } } @@ -405,15 +388,12 @@ message GetReceiptCredentialsResponse { GetReceiptCredentialsResult success = 1; // The subscriber did not exist or it did not have an associated subscription errors.NotFound subscriber_not_found = 2 [(tag.reason) = "subscriber_not_found"]; - // The subscriber-key embedded in the subscriber-id did not match the stored - // key for the subscriber-user embedded in the subscriber-id - errors.FailedUnidentifiedAuthorization subscriber_id_mismatch = 3 [(tag.reason) = "subscriber_id_mismatch"]; // No invoice has been issued for this subscription OR invoice is in 'draft' or 'open' state - errors.FailedPrecondition no_paid_invoice = 4 [(tag.reason) = "no_paid_invoice"]; + errors.FailedPrecondition no_paid_invoice = 3 [(tag.reason) = "no_paid_invoice"]; // Invoice is in any state other than 'draft', 'open', or 'paid'; Charge failure details may be present - PaymentRequired payment_required = 5 [(tag.reason) = "payment_required"]; + PaymentRequired payment_required = 4 [(tag.reason) = "payment_required"]; // Latest paid receipt on subscription was already redeemed for a receipt credential but with a different GetReceiptCredentialRequest - errors.FailedPrecondition already_redeemed = 6 [(tag.reason) = "already_redeemed"]; + errors.FailedPrecondition already_redeemed = 5 [(tag.reason) = "already_redeemed"]; } } @@ -455,9 +435,6 @@ message GetSubscriptionInformationResponse { google.protobuf.Empty no_subscription = 2; // The subscriber did not exist errors.NotFound subscriber_not_found = 3 [(tag.reason) = "subscriber_not_found"]; - // The subscriber-key embedded in the subscriber-id did not match the stored - // key for the subscriber-user embedded in the subscriber-id - errors.FailedUnidentifiedAuthorization subscriber_id_mismatch = 4 [(tag.reason) = "subscriber_id_mismatch"]; } } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/SubscriptionsGrpcServiceTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/SubscriptionsGrpcServiceTest.java index b6ea5f9b3..7511a4101 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/SubscriptionsGrpcServiceTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/SubscriptionsGrpcServiceTest.java @@ -8,6 +8,7 @@ package org.whispersystems.textsecuregcm.grpc; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; @@ -29,6 +30,7 @@ import java.util.Optional; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.stream.Stream; +import io.grpc.Status; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -193,11 +195,10 @@ public class SubscriptionsGrpcServiceTest extends void updateSubscriberIdMismatch() throws SubscriptionException { doThrow(new SubscriptionForbiddenException("subscriberId mismatch")) .when(subscriptionManager).updateSubscriber(any(), anyBoolean()); - final UpdateSubscriberResponse response = unauthenticatedServiceStub().updateSubscriber( + GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> unauthenticatedServiceStub().updateSubscriber( UpdateSubscriberRequest.newBuilder() .setSubscriberId(SUBSCRIBER_ID) - .build()); - assertEquals(UpdateSubscriberResponse.ResponseCase.SUBSCRIBER_ID_MISMATCH, response.getResponseCase()); + .build())); } @Test