From 75fc35ee4b48b93b150fb970ded3ddba63cf54b7 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Tue, 21 Jan 2020 11:29:08 -0800 Subject: [PATCH] Parameterize access to zk operations --- .../textsecuregcm/WhisperServerService.java | 5 +++-- .../textsecuregcm/configuration/ZkConfig.java | 8 ++++++++ .../controllers/CertificateController.java | 5 ++++- .../textsecuregcm/controllers/ProfileController.java | 11 ++++++++++- .../tests/controllers/CertificateControllerTest.java | 7 +------ .../tests/controllers/ProfileControllerTest.java | 3 ++- 6 files changed, 28 insertions(+), 11 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java index 0fd59a500..e7d6397b4 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java @@ -255,12 +255,13 @@ public class WhisperServerService extends Application accountAuthFilter = new BasicCredentialAuthFilter.Builder().setAuthenticator(accountAuthenticator).buildAuthFilter (); @@ -274,7 +275,7 @@ public class WhisperServerService extends Application endRedemptionTime) throw new WebApplicationException(Response.Status.BAD_REQUEST); if (endRedemptionTime > Util.currentDaysSinceEpoch() + 7) throw new WebApplicationException(Response.Status.BAD_REQUEST); if (startRedemptionTime < Util.currentDaysSinceEpoch()) throw new WebApplicationException(Response.Status.BAD_REQUEST); 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 9f5cd8ada..3796d0158 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java @@ -68,6 +68,7 @@ public class ProfileController { private final PolicySigner policySigner; private final PostPolicyGenerator policyGenerator; private final ServerZkProfileOperations zkProfileOperations; + private final boolean isZkEnabled; private final AmazonS3 s3client; private final String bucket; @@ -80,7 +81,8 @@ public class ProfileController { PostPolicyGenerator policyGenerator, PolicySigner policySigner, String bucket, - ServerZkProfileOperations zkProfileOperations) + ServerZkProfileOperations zkProfileOperations, + boolean isZkEnabled) { this.rateLimiters = rateLimiters; this.accountsManager = accountsManager; @@ -91,6 +93,7 @@ public class ProfileController { this.s3client = s3client; this.policyGenerator = policyGenerator; this.policySigner = policySigner; + this.isZkEnabled = isZkEnabled; } @Timed @@ -98,6 +101,8 @@ public class ProfileController { @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response setProfile(@Auth Account account, @Valid CreateProfileRequest request) { + if (!isZkEnabled) throw new WebApplicationException(Response.Status.NOT_FOUND); + Optional currentProfile = profilesManager.get(account.getUuid(), request.getVersion()); String avatar = request.isAvatar() ? generateAvatarObjectName() : null; Optional response = Optional.empty(); @@ -138,6 +143,7 @@ public class ProfileController { @PathParam("version") String version) throws RateLimitExceededException { + if (!isZkEnabled) throw new WebApplicationException(Response.Status.NOT_FOUND); return getVersionedProfile(requestAccount, accessKey, uuid, version, Optional.empty()); } @@ -152,6 +158,7 @@ public class ProfileController { @PathParam("credentialRequest") String credentialRequest) throws RateLimitExceededException { + if (!isZkEnabled) throw new WebApplicationException(Response.Status.NOT_FOUND); return getVersionedProfile(requestAccount, accessKey, uuid, version, Optional.of(credentialRequest)); } @@ -163,6 +170,8 @@ public class ProfileController { Optional credentialRequest) throws RateLimitExceededException { + if (!isZkEnabled) throw new WebApplicationException(Response.Status.NOT_FOUND); + try { if (!requestAccount.isPresent() && !accessKey.isPresent()) { throw new WebApplicationException(Response.Status.UNAUTHORIZED); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/CertificateControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/CertificateControllerTest.java index cdf96326a..4fcb79cd5 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/CertificateControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/CertificateControllerTest.java @@ -65,10 +65,9 @@ public class CertificateControllerTest { .addProvider(new PolymorphicAuthValueFactoryProvider.Binder<>(ImmutableSet.of(Account.class, DisabledPermittedAccount.class))) .setMapper(SystemMapper.getMapper()) .setTestContainerFactory(new GrizzlyWebTestContainerFactory()) - .addResource(new CertificateController(certificateGenerator, serverZkAuthOperations)) + .addResource(new CertificateController(certificateGenerator, serverZkAuthOperations, true)) .build(); - @Test public void testValidCertificate() throws Exception { DeliveryCertificate certificateObject = resources.getJerseyTest() @@ -228,8 +227,4 @@ public class CertificateControllerTest { assertThat(response.getStatus()).isEqualTo(401); } - - - - } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ProfileControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ProfileControllerTest.java index eaf5179b0..cad13abf4 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ProfileControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ProfileControllerTest.java @@ -73,7 +73,8 @@ public class ProfileControllerTest { postPolicyGenerator, policySigner, "profilesBucket", - zkProfileOperations)) + zkProfileOperations, + true)) .build(); @Before