Search in sources :

Example 1 with PassphraseSecrets

use of info.guardianproject.cacheword.PassphraseSecrets in project storymaker by StoryMaker.

the class CacheWordActivity method createPassphrase.

private void createPassphrase() {
    mViewCreatePin.setVisibility(View.VISIBLE);
    mViewEnterPin.setVisibility(View.GONE);
    mTextCreatePin.setOnEditorActionListener(new OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_NULL || actionId == EditorInfo.IME_ACTION_DONE) {
                if (!isPasswordValid())
                    showValidationError();
                else
                    mSlider.showConfirmationField();
            }
            return false;
        }
    });
    mTextConfirmPin.setOnEditorActionListener(new OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_NULL || actionId == EditorInfo.IME_ACTION_DONE) {
                if (!newEqualsConfirmation()) {
                    showInequalityError();
                    mSlider.showNewPasswordField();
                }
            }
            return false;
        }
    });
    Button btnCreate = (Button) findViewById(R.id.btnCreate);
    btnCreate.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // validate pin
            if (!isPasswordValid()) {
                showValidationError();
                mSlider.showNewPasswordField();
            } else if (isConfirmationFieldEmpty()) {
                mSlider.showConfirmationField();
            } else if (!newEqualsConfirmation()) {
                showInequalityError();
                mSlider.showNewPasswordField();
            } else {
                try {
                    CharSequence defaultPinSequence = getText(R.string.cacheword_default_pin);
                    char[] defaultPin = defaultPinSequence.toString().toCharArray();
                    PassphraseSecrets secrets = PassphraseSecrets.fetchSecrets(CacheWordActivity.this, defaultPin);
                    mCacheWordHandler.changePassphrase(secrets, mTextCreatePin.getText().toString().toCharArray());
                    Timber.d("replaced default pin");
                    // moving this code here to prevent accidental locks
                    // set status to prevent use of default pin
                    SharedPreferences sp = getSharedPreferences("appPrefs", Context.MODE_PRIVATE);
                    SharedPreferences.Editor e = sp.edit();
                    e.putString("cacheword_status", BaseActivity.CACHEWORD_SET);
                    e.commit();
                    // changePassphrase does not seem to trigger this so it is called manually
                    onCacheWordOpened();
                } catch (GeneralSecurityException gse1) {
                    Log.e("CacheWordActivity", "failed to replace default pin: " + gse1.getMessage());
                    try {
                        mCacheWordHandler.setPassphrase(mTextCreatePin.getText().toString().toCharArray());
                        Timber.d("created new pin (create)");
                    } catch (GeneralSecurityException gse2) {
                        Log.e("CacheWordActivity", "failed to create new pin (create): " + gse2.getMessage());
                    }
                } catch (IOException ioe) {
                    Log.e("CacheWordActivity", "unexpected exception: " + ioe.getMessage());
                }
            }
        }
    });
}
Also used : SharedPreferences(android.content.SharedPreferences) GeneralSecurityException(java.security.GeneralSecurityException) PassphraseSecrets(info.guardianproject.cacheword.PassphraseSecrets) IOException(java.io.IOException) View(android.view.View) TextView(android.widget.TextView) KeyEvent(android.view.KeyEvent) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) OnEditorActionListener(android.widget.TextView.OnEditorActionListener) TextView(android.widget.TextView)

Aggregations

SharedPreferences (android.content.SharedPreferences)1 KeyEvent (android.view.KeyEvent)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 Button (android.widget.Button)1 TextView (android.widget.TextView)1 OnEditorActionListener (android.widget.TextView.OnEditorActionListener)1 PassphraseSecrets (info.guardianproject.cacheword.PassphraseSecrets)1 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1