resilar / sqleet

SQLite3 encryption that sucks less
The Unlicense
375 stars 55 forks source link

Fatal signal 11 after set rekey for unencrypted database #42

Closed denwist closed 3 years ago

denwist commented 3 years ago

Hello! When using Sqleet in Sqlite, I encountered the problem of encrypting the database through PRAGMA rekey=NewPassword. Occurs when I import an unencrypted database and try to set a new password for it (the old password is empty). Drops on next error:

A/libc: Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x7c69ef8fb0 in tid 24406 (AsyncTask #2), pid 24259

/**
 * Changing the database password 
 * */
public void changeDatabaseEncryptionPassword(String password) throws Exception {
    try {
        // Encrypts open password
        String encryptionPassword = encryptPassword(password);
        SQLiteDatabase db = getWritableDatabase(); // 17Mb of unencrypted database 
        db.execSQL("PRAGMA rekey = " + DatabaseUtils.sqlEscapeString(encryptionPassword)); // the problem is here 
    } catch (Exception e) {
        throw new Exception(e);
    }
}

@Override
public void onConfigure(SQLiteDatabase db) {
    String encryptionPassword = getEncryptionPassword(currentContext);
    db.execSQL("PRAGMA key = " + DatabaseUtils.sqlEscapeString(encryptionPassword));
    super.onConfigure(db);
}

In general, I am satisfied with the library. The database can be either encrypted or decrypted by specifying an empty password. And for databases with low weight, everything works both in the direction of encryption and decryption. Encrypt db

Questions arise: 1) What could this problem be related to and how to fix it? 2) Are there any restrictions on the size of the encrypted database? In some cases, the process of encrypting and decrypting the database goes without problems. And when I import an unencrypted database backup and try to encrypt it, it crashes on an error "Fatal signal 11..." 3) Is there enough RAM for the Android device to perform this operation, especially for weighty databases? 4) Is there a way to encrypt / decrypt large databases (several gigabytes) at the file structure level by reading them piece by piece?

denwist commented 3 years ago

The solution was found. This fixed the problem. Solution