From 44838d62389cc56ad4a8171bc30bda74eb8a00bc Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Wed, 28 Jul 2021 15:24:10 -0400 Subject: [PATCH] Verify that nobody's addressing API calls by e164 any more. --- .../textsecuregcm/auth/AmbiguousIdentifier.java | 16 ++++++++++++++++ .../controllers/KeysController.java | 3 +++ .../controllers/MessageController.java | 3 +++ .../controllers/ProfileController.java | 4 ++++ 4 files changed, 26 insertions(+) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/auth/AmbiguousIdentifier.java b/service/src/main/java/org/whispersystems/textsecuregcm/auth/AmbiguousIdentifier.java index 203522a15..aab3d837b 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/auth/AmbiguousIdentifier.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/auth/AmbiguousIdentifier.java @@ -5,13 +5,22 @@ package org.whispersystems.textsecuregcm.auth; +import io.micrometer.core.instrument.Metrics; +import io.micrometer.core.instrument.Tag; +import io.micrometer.core.instrument.Tags; +import org.whispersystems.textsecuregcm.metrics.UserAgentTagUtil; +import javax.annotation.Nullable; import java.util.UUID; +import static com.codahale.metrics.MetricRegistry.name; + public class AmbiguousIdentifier { private final UUID uuid; private final String number; + private static final String REQUEST_COUNTER_NAME = name(AmbiguousIdentifier.class, "request"); + public AmbiguousIdentifier(String target) { if (target.startsWith("+")) { this.uuid = null; @@ -42,4 +51,11 @@ public class AmbiguousIdentifier { public String toString() { return hasUuid() ? uuid.toString() : number; } + + public void incrementRequestCounter(final String context, @Nullable final String userAgent) { + Metrics.counter(REQUEST_COUNTER_NAME, Tags.of( + Tag.of("type", hasUuid() ? "uuid" : "e164"), + Tag.of("context", context), + UserAgentTagUtil.getPlatformTag(userAgent))).increment(); + } } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/KeysController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/KeysController.java index 972fe0ea8..529f4ee86 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/KeysController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/KeysController.java @@ -128,6 +128,9 @@ public class KeysController { @PathParam("device_id") String deviceId, @HeaderParam("User-Agent") String userAgent) throws RateLimitExceededException, RateLimitChallengeException { + + targetName.incrementRequestCounter("getDeviceKeys", userAgent); + if (!account.isPresent() && !accessKey.isPresent()) { throw new WebApplicationException(Response.Status.UNAUTHORIZED); } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java index d4fd06040..d4fe7df91 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java @@ -197,6 +197,9 @@ public class MessageController { @PathParam("destination") AmbiguousIdentifier destinationName, @Valid IncomingMessageList messages) throws RateLimitExceededException, RateLimitChallengeException { + + destinationName.incrementRequestCounter("sendMessage", userAgent); + if (source.isEmpty() && accessKey.isEmpty()) { throw new WebApplicationException(Response.Status.UNAUTHORIZED); } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java index beb15c78b..caa3d0245 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java @@ -328,10 +328,14 @@ public class ProfileController { @Path("/{identifier}") public Profile getProfile(@Auth Optional requestAccount, @HeaderParam(OptionalAccess.UNIDENTIFIED) Optional accessKey, + @HeaderParam("User-Agent") String userAgent, @PathParam("identifier") AmbiguousIdentifier identifier, @QueryParam("ca") boolean useCaCertificate) throws RateLimitExceededException { + + identifier.incrementRequestCounter("getProfile", userAgent); + if (requestAccount.isEmpty() && accessKey.isEmpty()) { throw new WebApplicationException(Response.Status.UNAUTHORIZED); }