net.sqlcipher.database.SQLiteException Java Examples

The following examples show how to use net.sqlcipher.database.SQLiteException. 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: Helper.java    From cwac-saferoom with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * NOTE: by default, this implementation zeros out the passphrase after opening the
 * database
 */
@Override
synchronized public SupportSQLiteDatabase getWritableDatabase() {
  SupportSQLiteDatabase result;

  try {
    result = delegate.getWritableSupportDatabase(passphrase);
  }
  catch (SQLiteException e) {
    if (passphrase != null) {
      boolean isCleared = true;

      for (byte b : passphrase) {
        isCleared = isCleared && (b == (byte) 0);
      }

      if (isCleared) {
        throw new IllegalStateException("The passphrase appears to be cleared. This happens by" +
            "default the first time you use the factory to open a database, so we can remove the" +
            "cleartext passphrase from memory. If you close the database yourself, please use a" +
            "fresh SafeHelperFactory to reopen it. If something else (e.g., Room) closed the" +
            "database, and you cannot control that, use SafeHelperFactory.Options to opt out of" +
            "the automatic password clearing step. See the project README for more information.");
      }
    }

    throw e;
  }

  if (clearPassphrase && passphrase != null) {
    for (int i = 0; i < passphrase.length; i++) {
      passphrase[i] = (byte) 0;
    }
  }

  return(result);
}
 
Example #2
Source File: AndroidSQLCipherSQLite.java    From sync-android with Apache License 2.0 5 votes vote down vote up
@Override
public Cursor rawQuery(String sql, String[] values) throws java.sql.SQLException {
    try {
        return new AndroidSQLiteCursor(this.database.rawQuery(sql, values));
    } catch (SQLiteException e) {
        throw new java.sql.SQLException(e);
    }
}
 
Example #3
Source File: DatabaseGlobalOpenHelper.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@Override
public SQLiteDatabase getWritableDatabase(String key) {
    try {
        return super.getWritableDatabase(key);
    } catch (SQLiteException sqle) {
        DbUtil.trySqlCipherDbUpdate(key, mContext, GLOBAL_DB_LOCATOR);
        return super.getWritableDatabase(key);
    }
}
 
Example #4
Source File: DatabaseAppOpenHelper.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@Override
public SQLiteDatabase getWritableDatabase(String key) {
    try {
        return super.getWritableDatabase(key);
    } catch (SQLiteException sqle) {
        DbUtil.trySqlCipherDbUpdate(key, context, getDbName(mAppId));
        return super.getWritableDatabase(key);
    }
}
 
Example #5
Source File: DatabaseUserOpenHelper.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@Override
public SQLiteDatabase getWritableDatabase(String key) {
    fileMigrationKeySeed = key.getBytes();

    try {
        return super.getWritableDatabase(key);
    } catch (SQLiteException sqle) {
        DbUtil.trySqlCipherDbUpdate(key, context, getDbName(mUserId));
        return super.getWritableDatabase(key);
    }
}
 
Example #6
Source File: KriptonSQLCipherHelper.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * NOTE: by default, this implementation zeros out the passphrase after
 * opening the database
 */
@Override
synchronized public SupportSQLiteDatabase getWritableDatabase() {
	SupportSQLiteDatabase result;

	// if we don't have a passphrase, an exception will be thrown
	if (requiredPassphrase && passphrase == null) {
		Logger.fatal("Try to open ciphered database %s without any passphrase", getDatabaseName());

		throw new SQLCipherPassphraseRequiredException();
	}
	try {
		result = delegate.getWritableSupportDatabase(passphrase);
	} catch (SQLiteException e) {
		if (passphrase != null) {
			boolean isCleared = true;

			for (byte b : passphrase) {
				isCleared = isCleared && (b == (byte) 0);
			}

			if (isCleared) {
				throw new IllegalStateException("The passphrase appears to be cleared. This happens by"
						+ "default the first time you use the factory to open a database, so we can remove the"
						+ "cleartext passphrase from memory. If you close the database yourself, please use a"
						+ "fresh SafeHelperFactory to reopen it. If something else (e.g., Room) closed the"
						+ "database, and you cannot control that, use SafeHelperFactory.Options to opt out of"
						+ "the automatic password clearing step. See the project README for more information.");
			}
		}

		throw e;
	}

	if (clearPassphrase && passphrase != null) {
		for (int i = 0; i < passphrase.length; i++) {
			passphrase[i] = (byte) 0;
		}
	}

	return (result);
}
 
Example #7
Source File: SQLiteDatabaseNative.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
@Implementation
public void changePassword(char[] password) throws SQLiteException {
}
 
Example #8
Source File: SQLiteDatabaseNative.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
@Implementation
public void changePassword(String password) throws SQLiteException {
}
 
Example #9
Source File: SQLCipherOpenHelper.java    From Zom-Android-XMPP with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Create and/or open a database that will be used for reading and writing.
 * Once opened successfully, the database is cached, so you can call this
 * method every time you need to write to the database. Make sure to call
 * {@link #close} when you no longer need it.
 * <p>
 * Errors such as bad permissions or a full disk may cause this operation to
 * fail, but future attempts may succeed if the problem is fixed.
 * </p>
 *
 * @throws SQLiteException if the database cannot be opened for writing
 * @return a read/write database object valid until {@link #close} is called
 */
public synchronized SQLiteDatabase getWritableDatabase() {
    if (mHandler.isLocked())
        throw new SQLiteException("Database locked. Decryption key unavailable.");

    return super.getWritableDatabase(encodeRawKey(mHandler.getEncryptionKey()));
}
 
Example #10
Source File: SQLCipherOpenHelper.java    From Zom-Android-XMPP with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Create and/or open a database. This will be the same object returned by
 * {@link #getWritableDatabase} unless some problem, such as a full disk,
 * requires the database to be opened read-only. In that case, a read-only
 * database object will be returned. If the problem is fixed, a future call
 * to {@link #getWritableDatabase} may succeed, in which case the read-only
 * database object will be closed and the read/write object will be returned
 * in the future.
 *
 * @throws SQLiteException if the database cannot be opened
 * @return a database object valid until {@link #getWritableDatabase} or
 *         {@link #close} is called.
 */
public synchronized SQLiteDatabase getReadableDatabase() {
    if (mHandler.isLocked())
        throw new SQLiteException("Database locked. Decryption key unavailable.");

    return super.getReadableDatabase(encodeRawKey(mHandler.getEncryptionKey()));
}
 
Example #11
Source File: SQLCipherOpenHelper.java    From bitseal with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Create and/or open a database that will be used for reading and writing.
 * Once opened successfully, the database is cached, so you can call this
 * method every time you need to write to the database. Make sure to call
 * {@link #close} when you no longer need it.
 * <p>
 * Errors such as bad permissions or a full disk may cause this operation to
 * fail, but future attempts may succeed if the problem is fixed.
 * </p>
 *
 * @throws SQLiteException if the database cannot be opened for writing
 * @return a read/write database object valid until {@link #close} is called
 */
public synchronized SQLiteDatabase getWritableDatabase()
{
	if (mCacheWordHandler.isLocked())
    {
		throw new SQLiteException("Database locked. Decryption key unavailable.");
    }
    
    return super.getWritableDatabase(encodeRawKey(mCacheWordHandler.getEncryptionKey()));
}
 
Example #12
Source File: SQLCipherOpenHelper.java    From bitseal with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Create and/or open a database. This will be the same object returned by
 * {@link #getWritableDatabase} unless some problem, such as a full disk,
 * requires the database to be opened read-only. In that case, a read-only
 * database object will be returned. If the problem is fixed, a future call
 * to {@link #getWritableDatabase} may succeed, in which case the read-only
 * database object will be closed and the read/write object will be returned
 * in the future.
 *
 * @throws SQLiteException if the database cannot be opened
 * @return a database object valid until {@link #getWritableDatabase} or
 *         {@link #close} is called.
 */
public synchronized SQLiteDatabase getReadableDatabase()
{
	if (mCacheWordHandler.isLocked())
    {
    	throw new SQLiteException("Database locked. Decryption key unavailable.");
    }
    
    return super.getReadableDatabase(encodeRawKey(mCacheWordHandler.getEncryptionKey()));
}