diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/VerificationController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/VerificationController.java index 58a79d49c..72ff01d61 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/VerificationController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/VerificationController.java @@ -193,6 +193,8 @@ public class VerificationController { registrationServiceSession = registrationServiceClient.createRegistrationSession(phoneNumber, sourceHost, accountsManager.getByE164(request.number()).isPresent(), + request.updateVerificationSessionRequest().mcc(), + request.updateVerificationSessionRequest().mnc(), REGISTRATION_RPC_TIMEOUT).join(); } catch (final CancellationException e) { diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/registration/RegistrationServiceClient.java b/service/src/main/java/org/whispersystems/textsecuregcm/registration/RegistrationServiceClient.java index 73a166d95..b3db545b5 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/registration/RegistrationServiceClient.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/registration/RegistrationServiceClient.java @@ -94,7 +94,12 @@ public class RegistrationServiceClient implements Managed { } public CompletableFuture createRegistrationSession( - final Phonenumber.PhoneNumber phoneNumber, final String sourceHost, final boolean accountExistsWithPhoneNumber, final Duration timeout) { + final Phonenumber.PhoneNumber phoneNumber, + final String sourceHost, + final boolean accountExistsWithPhoneNumber, + @javax.annotation.Nullable final String clientMcc, + @javax.annotation.Nullable final String clientMnc, + final Duration timeout) { final long e164 = Long.parseLong( PhoneNumberUtil.getInstance().format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.E164).substring(1)); @@ -105,6 +110,8 @@ public class RegistrationServiceClient implements Managed { .setE164(e164) .setAccountExistsWithE164(accountExistsWithPhoneNumber) .setRateLimitCollationKey(rateLimitCollationKey) + .setMcc(clientMcc != null ? clientMcc : "") + .setMnc(clientMnc != null ? clientMnc : "") .build()), callbackExecutor) .thenApply(response -> switch (response.getResponseCase()) { case SESSION_METADATA -> buildSessionResponseFromMetadata(response.getSessionMetadata()); diff --git a/service/src/main/proto/RegistrationService.proto b/service/src/main/proto/RegistrationService.proto index d54c744ec..a3ad8935a 100644 --- a/service/src/main/proto/RegistrationService.proto +++ b/service/src/main/proto/RegistrationService.proto @@ -45,6 +45,16 @@ message CreateRegistrationSessionRequest { * collated by this key. */ string rate_limit_collation_key = 3; + + /** + * The MCC for the given `e164` as reported by the client. + */ + string mcc = 4; + + /** + * The MNC for the given `e164` as reported by the client. + */ + string mnc = 5; } message CreateRegistrationSessionResponse { diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/configuration/StubRegistrationServiceClientFactory.java b/service/src/test/java/org/whispersystems/textsecuregcm/configuration/StubRegistrationServiceClientFactory.java index 80692a2e6..d566a599e 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/configuration/StubRegistrationServiceClientFactory.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/configuration/StubRegistrationServiceClientFactory.java @@ -61,7 +61,12 @@ public class StubRegistrationServiceClientFactory implements RegistrationService @Override public CompletableFuture createRegistrationSession( - final Phonenumber.PhoneNumber phoneNumber, final String sourceHost, final boolean accountExistsWithPhoneNumber, final Duration timeout) { + final Phonenumber.PhoneNumber phoneNumber, + final String sourceHost, + final boolean accountExistsWithPhoneNumber, + @javax.annotation.Nullable final String clientMcc, + @javax.annotation.Nullable final String clientMnc, + final Duration timeout) { final String e164 = PhoneNumberUtil.getInstance() .format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.E164); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/VerificationControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/VerificationControllerTest.java index b8856d245..47f6b1393 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/VerificationControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/VerificationControllerTest.java @@ -192,7 +192,7 @@ class VerificationControllerTest { @Test void createSessionRateLimited() { - when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any())) + when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any(), any(), any())) .thenReturn(CompletableFuture.failedFuture(new RateLimitExceededException(null))); final Invocation.Builder request = resources.getJerseyTest() @@ -206,7 +206,7 @@ class VerificationControllerTest { @Test void createSessionRegistrationServiceError() { - when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any())) + when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any(), any(), any())) .thenReturn(CompletableFuture.failedFuture(new RuntimeException("expected service error"))); final Invocation.Builder request = resources.getJerseyTest() @@ -221,7 +221,7 @@ class VerificationControllerTest { @ParameterizedTest @MethodSource void createBeninSessionSuccess(final String requestedNumber, final String expectedNumber) { - when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any())) + when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any(), any(), any())) .thenReturn( CompletableFuture.completedFuture( new RegistrationServiceSession(SESSION_ID, requestedNumber, false, null, null, null, @@ -238,7 +238,7 @@ class VerificationControllerTest { final ArgumentCaptor phoneNumberArgumentCaptor = ArgumentCaptor.forClass( Phonenumber.PhoneNumber.class); - verify(registrationServiceClient).createRegistrationSession(phoneNumberArgumentCaptor.capture(), anyString(), anyBoolean(), any()); + verify(registrationServiceClient).createRegistrationSession(phoneNumberArgumentCaptor.capture(), anyString(), anyBoolean(), any(), any(), any()); final Phonenumber.PhoneNumber phoneNumber = phoneNumberArgumentCaptor.getValue(); assertEquals(expectedNumber, PhoneNumberUtil.getInstance().format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.E164)); @@ -262,7 +262,7 @@ class VerificationControllerTest { .format(PhoneNumberUtil.getInstance().getExampleNumber("BJ"), PhoneNumberUtil.PhoneNumberFormat.E164); final String oldFormatBeninE164 = newFormatBeninE164.replaceFirst("01", ""); - when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any())) + when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any(), any(), any())) .thenReturn( CompletableFuture.completedFuture( new RegistrationServiceSession(SESSION_ID, NUMBER, false, null, null, null, @@ -283,7 +283,7 @@ class VerificationControllerTest { @MethodSource void createSessionSuccess(final String pushToken, final String pushTokenType, final List expectedRequestedInformation) { - when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any())) + when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any(), any(), any())) .thenReturn( CompletableFuture.completedFuture( new RegistrationServiceSession(SESSION_ID, NUMBER, false, null, null, null, @@ -317,7 +317,7 @@ class VerificationControllerTest { @ParameterizedTest @ValueSource(booleans = {true, false}) void createSessionReregistration(final boolean isReregistration) throws NumberParseException { - when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any())) + when(registrationServiceClient.createRegistrationSession(any(), anyString(), anyBoolean(), any(), any(), any())) .thenReturn( CompletableFuture.completedFuture( new RegistrationServiceSession(SESSION_ID, NUMBER, false, null, null, null, @@ -341,6 +341,8 @@ class VerificationControllerTest { eq(PhoneNumberUtil.getInstance().parse(NUMBER, null)), anyString(), eq(isReregistration), + any(), + any(), any() ); }