1414import java .util .List ;
1515import java .util .Optional ;
1616import org .whispersystems .textsecuregcm .captcha .Action ;
17+ import org .whispersystems .textsecuregcm .captcha .AssessmentResult ;
1718import org .whispersystems .textsecuregcm .captcha .CaptchaChecker ;
1819import org .whispersystems .textsecuregcm .controllers .RateLimitExceededException ;
20+ import org .whispersystems .textsecuregcm .metrics .CaptchaMetrics ;
1921import org .whispersystems .textsecuregcm .metrics .UserAgentTagUtil ;
2022import org .whispersystems .textsecuregcm .push .NotPushRegisteredException ;
2123import org .whispersystems .textsecuregcm .spam .ChallengeType ;
@@ -61,13 +63,18 @@ public void answerPushChallenge(final Account account, final String challenge) t
6163 }
6264 }
6365
64- public boolean answerCaptchaChallenge (final Account account , final String captcha , final String mostRecentProxyIp ,
65- final String userAgent , final Optional <Float > scoreThreshold )
66- throws RateLimitExceededException , IOException {
66+ public boolean answerCaptchaChallenge (final Account account ,
67+ final String captcha ,
68+ final String mostRecentProxyIp ,
69+ final String userAgent ,
70+ final Optional <Float > scoreThreshold ) throws RateLimitExceededException , IOException {
6771
6872 rateLimiters .getCaptchaChallengeAttemptLimiter ().validate (account .getUuid ());
6973
70- final boolean challengeSuccess = captchaChecker .verify (Optional .of (account .getUuid ()), Action .CHALLENGE , captcha , mostRecentProxyIp , userAgent ).isValid (scoreThreshold );
74+ final AssessmentResult assessmentResult =
75+ captchaChecker .verify (Optional .of (account .getUuid ()), Action .CHALLENGE , captcha , mostRecentProxyIp , userAgent );
76+
77+ final boolean challengeSuccess = assessmentResult .isValid (scoreThreshold );
7178
7279 final Tags tags = Tags .of (
7380 Tag .of (SOURCE_COUNTRY_TAG_NAME , Util .getCountryCode (account .getNumber ())),
@@ -77,6 +84,13 @@ public boolean answerCaptchaChallenge(final Account account, final String captch
7784
7885 Metrics .counter (CAPTCHA_ATTEMPT_COUNTER_NAME , tags ).increment ();
7986
87+ CaptchaMetrics .measureCaptchaOutcome (assessmentResult .getNormalizedIntScore (),
88+ challengeSuccess ,
89+ Util .getRegion (account .getNumber ()),
90+ // Note: currently all challenges are for message-sending, but if we add more use cases, we'll need to make the
91+ // accept a context from callers rather than hard-coding it here
92+ "sendMessage" );
93+
8094 if (challengeSuccess ) {
8195 rateLimiters .getCaptchaChallengeSuccessLimiter ().validate (account .getUuid ());
8296 resetRateLimits (account , ChallengeType .CAPTCHA );
0 commit comments