Search in sources :

Example 6 with CryptoImplementation

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);
    }
}
Also used : CryptoImplementation(i2p.bote.crypto.CryptoImplementation) InputMethodManager(android.view.inputmethod.InputMethodManager)

Example 7 with CryptoImplementation

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));
    }
}
Also used : PrivateKey(java.security.PrivateKey) CryptoImplementation(i2p.bote.crypto.CryptoImplementation) PublicKey(java.security.PublicKey) NTRUEncrypt1087_GMSS512(i2p.bote.crypto.NTRUEncrypt1087_GMSS512) Test(org.junit.Test)

Example 8 with CryptoImplementation

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;
}
Also used : CryptoImplementation(i2p.bote.crypto.CryptoImplementation) PublicKey(java.security.PublicKey)

Aggregations

CryptoImplementation (i2p.bote.crypto.CryptoImplementation)8 PrivateKey (java.security.PrivateKey)3 GeneralSecurityException (java.security.GeneralSecurityException)2 PublicKey (java.security.PublicKey)2 InputMethodManager (android.view.inputmethod.InputMethodManager)1 NTRUEncrypt1087_GMSS512 (i2p.bote.crypto.NTRUEncrypt1087_GMSS512)1 EmailIdentity (i2p.bote.email.EmailIdentity)1 Identities (i2p.bote.email.Identities)1 PasswordException (i2p.bote.fileencryption.PasswordException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MessagingException (javax.mail.MessagingException)1 AddressException (javax.mail.internet.AddressException)1 Log (net.i2p.util.Log)1 Test (org.junit.Test)1