Verifying in-app-purchases

霸气de小男生 提交于 2020-01-14 07:45:24

问题


The sample app that the Google Developers guide refers to has a method called verifyValidSignature() that looks like this in the BillingManager class:

/**
 * Verifies that the purchase was signed correctly for this developer's public key.
 *
 * Note: It's strongly recommended to perform such check on your backend since hackers can
 * replace this method with "constant true" if they decompile/rebuild your app.
 */
private boolean verifyValidSignature(String signedData, String signature) {
    try {
        return Security.verifyPurchase(BASE_64_ENCODED_PUBLIC_KEY, signedData, signature);
    } catch (IOException e) {
        Log.e(TAG, "Got an exception trying to validate a purchase: " + e);
        return false;
    }
}

What exactly do they mean by "perform such check on your backend" ? What backend?

This method is called from this method (also in BillingManager):

private void handlePurchase(Purchase purchase) {
    if (!verifyValidSignature(purchase.getOriginalJson(), purchase.getSignature())) {
        Log.i(TAG, "Got a purchase: " + purchase + "; but signature is bad. Skipping...");
        return;
    }

    Log.d(TAG, "Got a verified purchase: " + purchase);

    mPurchases.add(purchase);
}

I don't really understand what I'm supposed to do on said backend, that is to stop an attacker from simply removing

if (!verifyValidSignature(purchase.getOriginalJson(), purchase.getSignature())) {
    Log.i(TAG, "Got a purchase: " + purchase + "; but signature is bad. Skipping...");
    return;
}

just as easily as replacing verifyValidSignature() with "constant true" as the JavaDoc for verifyValidSignature() warns.

How would I stop an attacker from decompiling my app and replacing something to bypass my in-app-purchase check?

来源:https://stackoverflow.com/questions/50089175/verifying-in-app-purchases

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!