Exemplo n.º 1
0
 /** @return */
 private boolean checkUserPassword(String password) {
   if (dbHelper == null) {
     // not sure what can cause this condition, but a NPE has been observed
     return false;
   }
   String encryptedMasterKey = dbHelper.fetchMasterKey();
   String decryptedMasterKey = "";
   if (debug) Log.d(TAG, "checkUserPassword: encryptedMasterKey=" + encryptedMasterKey);
   try {
     ch.init(CryptoHelper.EncryptionStrong, dbSalt);
     ch.setPassword(password);
     decryptedMasterKey = ch.decrypt(encryptedMasterKey);
     if (debug) Log.d(TAG, "decryptedMasterKey=" + decryptedMasterKey);
   } catch (CryptoHelperException e) {
     Log.e(TAG, e.toString());
   }
   if (ch.getStatus() == true) {
     dbMasterKey = decryptedMasterKey;
     return true;
   }
   return false;
 }
Exemplo n.º 2
0
  /** Called when the activity is first created. */
  @SuppressLint("ShowToast")
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    mDistribution.setFirst(MENU_DISTRIBUTION_START, DIALOG_DISTRIBUTION_START);

    // Check whether EULA has been accepted
    // or information about new version can be presented.
    if (mDistribution.showEulaOrNewVersion()) {
      return;
    }

    if (debug) Log.d(TAG, "onCreate(" + icicle + ")");

    dbHelper = new DBHelper(this);
    if (dbHelper.isDatabaseOpen() == false) {
      Dialog dbError =
          new AlertDialog.Builder(this)
              .setIcon(android.R.drawable.ic_dialog_alert)
              .setTitle(R.string.database_error_title)
              .setPositiveButton(
                  android.R.string.ok,
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                      finish();
                    }
                  })
              .setMessage(R.string.database_error_msg)
              .create();
      dbError.show();
      return;
    }

    ch = new CryptoHelper();
    if (dbHelper.needsUpgrade()) {
      switch (dbHelper.fetchVersion()) {
        case 2:
          databaseVersionError();
      }
    }
    dbSalt = dbHelper.fetchSalt();
    dbMasterKey = dbHelper.fetchMasterKey();

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    boolean prefKeypad = sp.getBoolean(Preferences.PREFERENCE_KEYPAD, false);
    boolean prefKeypadMute = sp.getBoolean(Preferences.PREFERENCE_KEYPAD_MUTE, false);
    mute = prefKeypadMute;

    if (prefKeypad) {
      viewMode = VIEW_KEYPAD;
    }
    if (dbMasterKey.length() == 0) {
      firstTime = true;
    }
    if ((viewMode == VIEW_NORMAL) || (firstTime)) {
      normalInit();
    } else {
      keypadInit();
    }

    blankPasswordToast =
        Toast.makeText(AskPassword.this, R.string.notify_blank_pass, Toast.LENGTH_SHORT);
    invalidPasswordToast =
        Toast.makeText(AskPassword.this, R.string.invalid_password, Toast.LENGTH_SHORT);
    confirmPasswordFailToast =
        Toast.makeText(AskPassword.this, R.string.confirm_pass_fail, Toast.LENGTH_SHORT);
  }