Android SMS verification APi

89 Views Asked by At

I have developed app with multiple build flavours like dev, test, prod so when i am using sms verification api, i am able to read sms only in prod mode but not in other mode, i have verified that the hash that is being sent to server is different for different build flavour and server is also sending the same hash in sms which is being send by the app, but the problem is the the sms verification api receiver is able to read the sms for prod build flavour and not for other build flavour.

Build flavour code

flavorDimensions "version"

productFlavors {

    gamma {
        dimension "version"
        applicationId "packagename.test"
        versionNameSuffix "-test"
    }

    api2 {
        dimension "version"
        applicationId "packagename.dev"
        versionNameSuffix "-dev"
    }
    prod {
        dimension "version"
        applicationId "packagename"
    }
}

code to generate hash

   public ArrayList<String> getAppSignatures() {
    ArrayList<String> appSignaturesHashs = new ArrayList<>();
try {
        // Get all package details
        String packageName = getPackageName();
        PackageManager packageManager = getPackageManager();
        Signature[] signatures = packageManager.getPackageInfo(packageName,
                PackageManager.GET_SIGNATURES).signatures;

        for (Signature signature : signatures) {
            String hash = hash(packageName, signature.toCharsString());
            if (hash != null) {
                appSignaturesHashs.add(String.format("%s", hash));
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Package not found", e);
    }
    return appSignaturesHashs;
}

@TargetApi(19)
private static String hash(String packageName, String signature) {
    String appInfo = packageName + " " + signature;
    try {
        MessageDigest messageDigest = MessageDigest.getInstance(HASH_TYPE);
        messageDigest.update(appInfo.getBytes(StandardCharsets.UTF_8));
        byte[] hashSignature = messageDigest.digest();

        // truncated into NUM_HASHED_BYTES
        hashSignature = Arrays.copyOfRange(hashSignature, 0, NUM_HASHED_BYTES);
        // encode into Base64
        String base64Hash = Base64.encodeToString(hashSignature, Base64.NO_PADDING | Base64.NO_WRAP);
        base64Hash = base64Hash.substring(0, NUM_BASE64_CHAR);

        return base64Hash;
    } catch (NoSuchAlgorithmException e) {
        Log.e(TAG, "No Such Algorithm Exception", e);
    }
    return null;
}

Any suggestion or help would be great.

0

There are 0 best solutions below