diff --git a/service/config/sample.yml b/service/config/sample.yml index 9f6ec4d7d..0c280ca6b 100644 --- a/service/config/sample.yml +++ b/service/config/sample.yml @@ -285,10 +285,6 @@ unidentifiedDelivery: privateKey: secret://unidentifiedDelivery.privateKey expiresDays: 7 -recaptcha: - projectPath: projects/example - credentialConfigurationJson: "{ }" # service account configuration for backend authentication - hCaptcha: apiKey: secret://hCaptcha.apiKey diff --git a/service/pom.xml b/service/pom.xml index 620f79900..acc3eae2e 100644 --- a/service/pom.xml +++ b/service/pom.xml @@ -466,18 +466,6 @@ google-auth-library-oauth2-http - - com.google.cloud - google-cloud-recaptchaenterprise - - - - com.google.guava - failureaccess - - - - com.stripe stripe-java diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerConfiguration.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerConfiguration.java index 450ac7581..2d4175f81 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerConfiguration.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerConfiguration.java @@ -41,7 +41,6 @@ import org.whispersystems.textsecuregcm.configuration.MessageCacheConfiguration; import org.whispersystems.textsecuregcm.configuration.MonitoredS3ObjectConfiguration; import org.whispersystems.textsecuregcm.configuration.OneTimeDonationConfiguration; import org.whispersystems.textsecuregcm.configuration.PaymentsServiceConfiguration; -import org.whispersystems.textsecuregcm.configuration.RecaptchaConfiguration; import org.whispersystems.textsecuregcm.configuration.RedisClusterConfiguration; import org.whispersystems.textsecuregcm.configuration.RedisConfiguration; import org.whispersystems.textsecuregcm.configuration.RegistrationServiceConfiguration; @@ -204,11 +203,6 @@ public class WhisperServerConfiguration extends Configuration { @JsonProperty private UnidentifiedDeliveryConfiguration unidentifiedDelivery; - @Valid - @NotNull - @JsonProperty - private RecaptchaConfiguration recaptcha; - @Valid @NotNull @JsonProperty @@ -359,10 +353,6 @@ public class WhisperServerConfiguration extends Configuration { return dynamoDbTables; } - public RecaptchaConfiguration getRecaptchaConfiguration() { - return recaptcha; - } - public HCaptchaConfiguration getHCaptchaConfiguration() { return hCaptcha; } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java index 5f18d11c8..4c6853625 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java @@ -85,7 +85,6 @@ import org.whispersystems.textsecuregcm.calls.routing.DynamicConfigTurnRouter; import org.whispersystems.textsecuregcm.calls.routing.TurnCallRouter; import org.whispersystems.textsecuregcm.captcha.CaptchaChecker; import org.whispersystems.textsecuregcm.captcha.HCaptchaClient; -import org.whispersystems.textsecuregcm.captcha.RecaptchaClient; import org.whispersystems.textsecuregcm.captcha.RegistrationCaptchaManager; import org.whispersystems.textsecuregcm.captcha.ShortCodeExpander; import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicConfiguration; @@ -625,10 +624,6 @@ public class WhisperServerService extends Application dynamicConfigurationManager; - - public RecaptchaClient( - @Nonnull final String projectPath, - @Nonnull final String recaptchaCredentialConfigurationJson, - final DynamicConfigurationManager dynamicConfigurationManager) { - try { - this.projectPath = Objects.requireNonNull(projectPath); - this.client = RecaptchaEnterpriseServiceClient.create(RecaptchaEnterpriseServiceSettings.newBuilder() - .setCredentialsProvider(FixedCredentialsProvider.create(GoogleCredentials.fromStream( - new ByteArrayInputStream(recaptchaCredentialConfigurationJson.getBytes(StandardCharsets.UTF_8))))) - .build()); - - this.dynamicConfigurationManager = dynamicConfigurationManager; - } catch (IOException e) { - throw new AssertionError(e); - } - } - - @Override - public String scheme() { - return V2_PREFIX; - } - - @Override - public Set validSiteKeys(final Action action) { - final DynamicCaptchaConfiguration config = dynamicConfigurationManager.getConfiguration().getCaptchaConfiguration(); - if (!config.isAllowRecaptcha()) { - log.warn("Received request to verify a recaptcha, but recaptcha is not enabled"); - return Collections.emptySet(); - } - return Optional - .ofNullable(config.getRecaptchaSiteKeys().get(action)) - .orElse(Collections.emptySet()); - } - - @Override - public org.whispersystems.textsecuregcm.captcha.AssessmentResult verify( - final String sitekey, - final Action action, - final String token, - final String ip) throws IOException { - final DynamicCaptchaConfiguration config = dynamicConfigurationManager.getConfiguration().getCaptchaConfiguration(); - final Set allowedSiteKeys = config.getRecaptchaSiteKeys().get(action); - if (allowedSiteKeys != null && !allowedSiteKeys.contains(sitekey)) { - log.info("invalid recaptcha sitekey {}, action={}, token={}", action, token); - Metrics.counter(INVALID_SITEKEY_COUNTER_NAME, "action", action.getActionName()).increment(); - return AssessmentResult.invalid(); - } - - Event.Builder eventBuilder = Event.newBuilder() - .setSiteKey(sitekey) - .setToken(token) - .setUserIpAddress(ip); - - if (action != null) { - eventBuilder.setExpectedAction(action.getActionName()); - } - - final Event event = eventBuilder.build(); - final Assessment assessment; - try { - assessment = client.createAssessment(projectPath, Assessment.newBuilder().setEvent(event).build()); - } catch (ApiException e) { - throw new IOException(e); - } - - if (assessment.getTokenProperties().getValid()) { - final float score = assessment.getRiskAnalysis().getScore(); - log.debug("assessment for {} was valid, score: {}", action.getActionName(), score); - final BigDecimal threshold = config.getScoreFloorByAction().getOrDefault(action, config.getScoreFloor()); - final AssessmentResult assessmentResult = AssessmentResult.fromScore(score, threshold.floatValue()); - for (RiskAnalysis.ClassificationReason reason : assessment.getRiskAnalysis().getReasonsList()) { - Metrics.counter(ASSESSMENT_REASON_COUNTER_NAME, - "action", action.getActionName(), - "score", assessmentResult.getScoreString(), - "reason", reason.name()) - .increment(); - } - return assessmentResult; - } else { - Metrics.counter(INVALID_REASON_COUNTER_NAME, - "action", action.getActionName(), - "reason", assessment.getTokenProperties().getInvalidReason().name()) - .increment(); - return AssessmentResult.invalid(); - } - } -} diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/RecaptchaConfiguration.java b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/RecaptchaConfiguration.java deleted file mode 100644 index 948fee148..000000000 --- a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/RecaptchaConfiguration.java +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright 2021-2022 Signal Messenger, LLC - * SPDX-License-Identifier: AGPL-3.0-only - */ - -package org.whispersystems.textsecuregcm.configuration; - -import javax.validation.constraints.NotEmpty; - -public record RecaptchaConfiguration(@NotEmpty String projectPath, @NotEmpty String credentialConfigurationJson) { - -} diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicCaptchaConfiguration.java b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicCaptchaConfiguration.java index 636031f86..bc99a8b25 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicCaptchaConfiguration.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicCaptchaConfiguration.java @@ -10,7 +10,6 @@ import com.google.common.annotations.VisibleForTesting; import org.whispersystems.textsecuregcm.captcha.Action; import java.math.BigDecimal; import java.util.Collections; -import java.util.List; import java.util.Map; import java.util.Set; import javax.validation.constraints.DecimalMax; @@ -28,9 +27,6 @@ public class DynamicCaptchaConfiguration { @JsonProperty private boolean allowHCaptcha = false; - @JsonProperty - private boolean allowRecaptcha = true; - @JsonProperty @NotNull private Map> hCaptchaSiteKeys = Collections.emptyMap(); @@ -51,10 +47,6 @@ public class DynamicCaptchaConfiguration { return allowHCaptcha; } - public boolean isAllowRecaptcha() { - return allowRecaptcha; - } - public Map getScoreFloorByAction() { return scoreFloorByAction; }