Java Code Examples for android.os.StrictMode#noteSlowCall()

The following examples show how to use android.os.StrictMode#noteSlowCall() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArmadilloBcryptKeyStretcher.java    From armadillo with Apache License 2.0 5 votes vote down vote up
/**
 * Computes the Bcrypt hash of a password.
 *
 * @param password  the password to hash.
 * @param salt      the salt
 * @param logRounds log2(Iterations). e.g. 12 ==> 2^12 = 4,096 iterations
 * @return the Bcrypt hash of the password
 */
private static byte[] bcrypt(byte[] salt, char[] password, int logRounds) {
    StrictMode.noteSlowCall("bcrypt is a very expensive call and should not be done on the main thread");
    Bytes passwordBytes = Bytes.empty();
    try {
        passwordBytes = Bytes.from(password);
        return BCrypt.with(BCrypt.Version.VERSION_2A).hashRaw(logRounds,
                HKDF.fromHmacSha256().expand(salt, "bcrypt-salt".getBytes(), 16),
            HKDF.fromHmacSha256().expand(passwordBytes.array(), "bcrypt-pw".getBytes(), 71)).rawHash;
    } finally {
        passwordBytes.mutable().secureWipe();
    }
}
 
Example 2
Source File: SecureSharedPreferences.java    From armadillo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isValidPassword() {
    StrictMode.noteSlowCall("checking password should only be done in a background thread");
    if (!supportVerifyPassword) {
        throw new UnsupportedOperationException("support verify password is not enabled");
    }
    try {
        String storedValue = getString(PASSWORD_VALIDATION_KEY, null);
        return storedValue != null && Bytes.parseBase64(storedValue).equalsConstantTime(preferencesSalt);
    } catch (SecureSharedPreferenceCryptoException e) {
        return false;
    }
}
 
Example 3
Source File: SecureSharedPreferences.java    From armadillo with Apache License 2.0 5 votes vote down vote up
@SuppressLint("ApplySharedPref")
@Override
public void changePassword(@Nullable char[] newPassword, @Nullable KeyStretchingFunction newKsFunction) {
    StrictMode.noteSlowCall("changing password should only be done in a background thread");

    newPassword = newPassword == null || newPassword.length == 0 ? null : newPassword;

    SharedPreferences.Editor editor = this.edit();
    KeyStretchingFunction currentFunction = encryptionProtocol.getKeyStretchingFunction();

    for (String keyHash : getAll().keySet()) {
        encryptionProtocol.setKeyStretchingFunction(currentFunction);
        if (!reencryptStringType(newPassword, (Editor) editor, keyHash, newKsFunction)) {
            reencryptStringSetType(newPassword, (Editor) editor, keyHash, newKsFunction);
        }
    }
    editor.commit();

    if (newKsFunction != null) {
        encryptionProtocol.setKeyStretchingFunction(newKsFunction);
    }

    if (password != null) {
        password.wipe();
    }
    password = encryptionProtocol.obfuscatePassword(newPassword);
}
 
Example 4
Source File: WebView.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Finds all instances of find on the page and highlights them.
 * Notifies any registered {@link FindListener}.
 *
 * @param find the string to find
 * @return the number of occurrences of the String "find" that were found
 * @deprecated {@link #findAllAsync} is preferred.
 * @see #setFindListener
 */
@Deprecated
public int findAll(String find) {
    checkThread();
    StrictMode.noteSlowCall("findAll blocks UI: prefer findAllAsync");
    return mProvider.findAll(find);
}
 
Example 5
Source File: PBKDF2KeyStretcher.java    From armadillo with Apache License 2.0 3 votes vote down vote up
/**
 * Computes the PBKDF2 hash of a password.
 *
 * @param password   the password to hash.
 * @param salt       the salt
 * @param iterations the iteration count (slowness factor)
 * @param outBytes   the length of the hash to compute in bytes
 * @return the PBDKF2 hash of the password
 */
private static byte[] pbkdf2(Provider provider, char[] password, byte[] salt, int iterations, int outBytes) throws NoSuchAlgorithmException, InvalidKeySpecException {
    StrictMode.noteSlowCall("pbkdf2 is a very expensive call and should not be done on the main thread");
    PBEKeySpec spec = new PBEKeySpec(password, salt, iterations, outBytes * 8);
    SecretKeyFactory skf = provider != null ? SecretKeyFactory.getInstance(PBKDF2_ALGORITHM, provider) : SecretKeyFactory.getInstance(PBKDF2_ALGORITHM);
    return skf.generateSecret(spec).getEncoded();
}
 
Example 6
Source File: BrokenBcryptKeyStretcher.java    From armadillo with Apache License 2.0 3 votes vote down vote up
/**
 * Computes the Bcrypt hash of a password.
 *
 * @param password  the password to hash.
 * @param salt      the salt
 * @param logRounds log2(Iterations). e.g. 12 ==> 2^12 = 4,096 iterations
 * @return the Bcrypt hash of the password
 */
private static byte[] bcrypt(char[] password, byte[] salt, int logRounds) {
    StrictMode.noteSlowCall("bcrypt is a very expensive call and should not be done on the main thread");
    return BCrypt.with(CUSTOM_LEGACY_VERSION, new SecureRandom(), rawPassword -> Bytes.wrapNullSafe(rawPassword).copy().array()).hash(logRounds,
        createLegacySalt(salt),
        createLegacyPassword(password, salt));
}
 
Example 7
Source File: BrokenBcryptKeyStretcherTest.java    From armadillo with Apache License 2.0 2 votes vote down vote up
/**
 * Computes the Bcrypt hash of a password.
 *
 * @param password  the password to hash.
 * @param salt      the salt
 * @param logRounds log2(Iterations). e.g. 12 ==> 2^12 = 4,096 iterations
 * @return the Bcrypt hash of the password
 */
private static byte[] bcrypt(char[] password, byte[] salt, int logRounds) {
    StrictMode.noteSlowCall("bcrypt is a very expensive call and should not be done on the main thread");
    return Bytes.from(BCrypt.hashpw(String.valueOf(password) + Bytes.wrap(salt).encodeHex(), generateSalt(salt, logRounds))).array();
}