Not sure this is relevant to Firebase but here are some details in case anyone is using Node / JS. You can use Node's inbuilt crypto
library. First fetch
the available Google AdMob verifier keys from https://gstatic.com/admob/reward/verifier-keys.json
.
You'll then need to loop through the returned JSON keys
array and grab the pem
public key file string corresponding to the req.query.key_id
parameter of your incoming req.url
string.
Then the "message" we wish to verify signatures with is the incoming req.url
substring inbetween the parameter ?
symbol and &signature...
strings.
Now we can verify easily:
const verifier = crypto.createVerify("sha256");
verifier.update(message);
if(verifier.verify(pem, req.query.signature, "base64"))
console.log("Ad was successfully verified.");
else
console.log("Ad could not be verified - quick call the cops !");
One caveat to beware of is you may need to unescape(...)
your req.url
string before you use it since some characters may have been escaped. I was stuck on that for a good hour or two. You can do this using e.g. Node's built in querystring
library.