use of i2p.bote.crypto.CryptoImplementation in project i2p.i2p-bote by i2p.
the class EditIdentityFragment method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.action_save_identity:
String picture = getPictureB64();
String publicName = mNameField.getText().toString();
String description = mDescField.getText().toString();
boolean setDefault = mDefaultField.isChecked();
int cryptoImplId = -1;
if (mKey == null)
cryptoImplId = ((CryptoImplementation) mCryptoField.getSelectedItem()).getId();
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mNameField.getWindowToken(), 0);
setInterfaceEnabled(false);
mError.setText("");
IdentityWaiterFrag f = IdentityWaiterFrag.newInstance((mKey == null), cryptoImplId, null, mKey, publicName, description, picture, null, setDefault);
f.setTask(new IdentityWaiter());
f.setTargetFragment(EditIdentityFragment.this, IDENTITY_WAITER);
getFragmentManager().beginTransaction().replace(R.id.identity_waiter_frag, f, IDENTITY_WAITER_TAG).commit();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
use of i2p.bote.crypto.CryptoImplementation in project i2p.i2p-bote by i2p.
the class IdentitiesTest method testUpdateKey.
/**
* Checks that the private signing key is updated on disk if the <code>CryptoImplementation</code> requires it
*/
@Test
public void testUpdateKey() throws GeneralSecurityException, PasswordException, IOException {
byte[] message = "Hopfen und Malz, Gott erhalt's!".getBytes();
Iterator<EmailIdentity> iterator = identities.iterator();
while (iterator.hasNext()) {
EmailIdentity identity = iterator.next();
PublicKey publicKey = identity.getPublicSigningKey();
PrivateKey privateKey = identity.getPrivateSigningKey();
// make a copy of the old signing keys
byte[] encodedPublicKey = publicKey.getEncoded().clone();
byte[] encodedPrivateKey = privateKey.getEncoded().clone();
CryptoImplementation cryptoImpl = identity.getCryptoImpl();
cryptoImpl.sign(message, privateKey, identities);
// read identities from file and compare keys before / after
boolean publicKeyChanged;
boolean privateKeyChanged;
if (!identitiesFile.exists())
publicKeyChanged = privateKeyChanged = false;
else {
Identities newIdentities = new Identities(identitiesFile, passwordHolder);
PublicKey newPublicKey = newIdentities.get(identity).getPublicSigningKey();
PrivateKey newPrivateKey = newIdentities.get(identity).getPrivateSigningKey();
publicKeyChanged = !Arrays.equals(encodedPublicKey, newPublicKey.getEncoded());
privateKeyChanged = !Arrays.equals(encodedPrivateKey, newPrivateKey.getEncoded());
}
assertFalse(publicKeyChanged);
assertTrue(privateKeyChanged == (cryptoImpl instanceof NTRUEncrypt1087_GMSS512));
}
}
use of i2p.bote.crypto.CryptoImplementation in project i2p.i2p-bote by i2p.
the class Contact method verify.
/**
* Verifies the signature and the fingerprint.
* @return
* @throws GeneralSecurityException
*/
public boolean verify() throws GeneralSecurityException {
if (signature == null || fingerprint == null)
return false;
CryptoImplementation cryptoImpl = destination.getCryptoImpl();
PublicKey key = destination.getPublicSigningKey();
boolean valid = cryptoImpl.verify(getDataToSign(), signature, key);
valid &= fingerprint.isValid();
return valid;
}
Aggregations