Skip to content

Commit

Permalink
Fix digest comparison for Play Integrity API (#4307)
Browse files Browse the repository at this point in the history
Google was using a standard base64 for the certificate digest in the
Safety Net API, buit it's now the URL-safe variant for Play Integrity.
  • Loading branch information
nono committed Jan 25, 2024
2 parents b95bc1c + 3575135 commit f89d05b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion model/oauth/android_play_integrity.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,17 @@ func checkPlayIntegrityCertificateDigest(claims jwt.MapClaims) error {
if digest == certDigest[0] {
return nil
}
// XXX Google was using standard base64 for SafetyNet, but the safe-URL
// variant for Play Integrity...
urlSafeDigest := strings.TrimRight(digest, "=")
urlSafeDigest = strings.ReplaceAll(urlSafeDigest, "+", "-")
urlSafeDigest = strings.ReplaceAll(urlSafeDigest, "/", "_")
if urlSafeDigest == certDigest[0] {
return nil
}
}
logger.WithNamespace("oauth").
Debugf("Invalid certificate digest, expected %s, got %s", digests[0], certDigest)
Debugf("Invalid certificate digest, expected %s, got %s", digests[0], certDigest[0])
return errors.New("invalid certificate digest")
}

Expand Down
2 changes: 1 addition & 1 deletion model/oauth/android_safety_net.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func checkSafetyNetCertificateDigest(claims jwt.MapClaims) error {
}
}
logger.WithNamespace("oauth").
Debugf("Invalid certificate digest, expected %s, got %s", digests[0], certDigest)
Debugf("Invalid certificate digest, expected %s, got %s", digests[0], certDigest[0])
return errors.New("invalid certificate digest")
}

Expand Down

0 comments on commit f89d05b

Please sign in to comment.