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());
}
}
}
});
}
Aggregations