diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/RegistrationController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/RegistrationController.java index 251e0b1f6..683c62008 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/RegistrationController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/RegistrationController.java @@ -98,6 +98,7 @@ public class RegistrationController { private static final String COUNTRY_CODE_TAG_NAME = "countryCode"; private static final String REGION_CODE_TAG_NAME = "regionCode"; private static final String VERIFICATION_TYPE_TAG_NAME = "verification"; + private static final String FICTITIOUS_NUMBER_TAG_NAME = "fictitiousNumber"; private final AccountsManager accounts; private final PhoneVerificationTokenManager phoneVerificationTokenManager; @@ -320,7 +321,8 @@ public class RegistrationController { Metrics.counter(ACCOUNT_CREATED_COUNTER_NAME, Tags.of(UserAgentTagUtil.getPlatformTag(userAgent), Tag.of(COUNTRY_CODE_TAG_NAME, Util.getCountryCode(number)), Tag.of(REGION_CODE_TAG_NAME, Util.getRegion(number)), - Tag.of(VERIFICATION_TYPE_TAG_NAME, verificationType.name()))) + Tag.of(VERIFICATION_TYPE_TAG_NAME, verificationType.name()), + Tag.of(FICTITIOUS_NUMBER_TAG_NAME, String.valueOf(Util.isFictitiousNumber(number))))) .increment(); final AccountIdentityResponse identityResponse = new AccountIdentityResponseBuilder(account) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java index c099e540f..5d551e318 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java @@ -740,7 +740,8 @@ public class AccountsManager extends RedisPubSubAdapter implemen Tags tags = Tags.of(UserAgentTagUtil.getPlatformTag(userAgent), Tag.of("type", accountCreationType.getTagValue()), Tag.of("pushTokenType", pushTokenType.getTagValue()), - Tag.of("hasRecoveryPassword", String.valueOf(hasRecoveryPassword))); + Tag.of("hasRecoveryPassword", String.valueOf(hasRecoveryPassword)), + Tag.of("fictitiousNumber", String.valueOf(account.getNumber().map(Util::isFictitiousNumber).orElse(false)))); if (previousPushTokenType != null) { tags = tags.and(Tag.of("previousPushTokenType", previousPushTokenType.getTagValue())); diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/util/Util.java b/service/src/main/java/org/whispersystems/textsecuregcm/util/Util.java index 05b6b958e..f7eb660df 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/util/Util.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/util/Util.java @@ -24,6 +24,7 @@ import java.util.Optional; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.function.Function; +import java.util.regex.Pattern; import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.whispersystems.textsecuregcm.storage.Account; @@ -37,6 +38,19 @@ public class Util { public static final String COUNTRY_CODE_NOT_APPLICABLE = "n/a"; public static final String REGION_NOT_APPLICABLE = "n/a"; + // Keep in sync with registration-service's FictitiousNumberVerificationCodeSender, which sends verification codes + // for these numbers to a datastore instead of an SMS/voice provider + private static final List FICTITIOUS_NUMBER_PATTERNS = List.of( + // NANPA fictitious numbers + Pattern.compile("\\+1[0-9]{3}55501[0-9]{2}"), + + // UK "numbers for drama" + Pattern.compile("\\+447700900[0-9]{3}"), + + // French numbers "for use in audiovisual productions" + Pattern.compile("\\+3363998[0-9]{4}") + ); + // We use a `HashMap` because `HashMap` allows for null keys at query time, and `PhoneNumberUtil` may return a null // region code for some phone numbers private static final Map ALTERNATE_FORM_GENERATORS_BY_REGION = @@ -226,6 +240,13 @@ public class Util { PHONE_NUMBER_UTIL.getNationalSignificantNumber(phoneNumber).length() == 8; } + /** + * @return whether the E164-formatted {@code number} is in a range that registration-service treats as fictitious + */ + public static boolean isFictitiousNumber(final String number) { + return FICTITIOUS_NUMBER_PATTERNS.stream().anyMatch(pattern -> pattern.matcher(number).matches()); + } + /** * If applicable, return the canonical form of the provided phone number. * This is relevant in cases where a numbering authority has changed the numbering format for a region.