Search in sources :

Example 16 with PasswordException

use of i2p.bote.fileencryption.PasswordException in project i2p.i2p-bote by i2p.

the class EditContactFragment method initializeContact.

private void initializeContact() {
    String newDest = getArguments().getString(NEW_DESTINATION);
    if (mDestination != null) {
        try {
            Contact contact = BoteHelper.getContact(mDestination);
            String pic = contact.getPictureBase64();
            if (pic != null && !pic.isEmpty()) {
                setPictureB64(pic);
            }
            mNameField.setText(contact.getName());
            mTextField.setText(contact.getText());
        } catch (PasswordException e) {
            // TODO Handle
            e.printStackTrace();
        }
    } else if (newDest != null) {
        mNameField.setText(getArguments().getString(NEW_NAME));
        mDestinationField.setText(newDest);
    }
}
Also used : PasswordException(i2p.bote.fileencryption.PasswordException) Contact(i2p.bote.packet.dht.Contact)

Example 17 with PasswordException

use of i2p.bote.fileencryption.PasswordException in project i2p.i2p-bote by i2p.

the class AttachmentProvider method getType.

@Override
public String getType(Uri uri) {
    if (sUriMatcher.match(uri) != UriMatcher.NO_MATCH) {
        try {
            Part attachment = getAttachment(uri);
            if (attachment != null) {
                String contentType = attachment.getContentType();
                // Remove any "; name=fileName" suffix
                int delim = contentType.indexOf(';');
                if (delim >= 0) {
                    String params = contentType.substring(delim + 1);
                    contentType = contentType.substring(0, delim);
                    // I2P-Bote version that didn't detect MIME types correctly.
                    if ("application/octet-stream".equals(contentType)) {
                        // Find the filename
                        String filename = "";
                        delim = params.indexOf("name=");
                        if (delim >= 0) {
                            filename = params.substring(delim + 5);
                            delim = filename.indexOf(' ');
                            if (delim >= 0)
                                filename = params.substring(0, delim);
                        }
                        if (!filename.isEmpty()) {
                            MimetypesFileTypeMap mimeTypeMap = new MimetypesFileTypeMap();
                            contentType = mimeTypeMap.getContentType(filename);
                        }
                    }
                }
                return contentType;
            }
        } catch (PasswordException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : PasswordException(i2p.bote.fileencryption.PasswordException) MimetypesFileTypeMap(javax.activation.MimetypesFileTypeMap) MessagingException(javax.mail.MessagingException) Part(javax.mail.Part) IOException(java.io.IOException)

Example 18 with PasswordException

use of i2p.bote.fileencryption.PasswordException in project i2p.i2p-bote by i2p.

the class AttachmentProvider method query.

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    if (sUriMatcher.match(uri) == UriMatcher.NO_MATCH)
        throw new IllegalArgumentException("Invalid URI: " + uri);
    if (projection == null) {
        projection = OPENABLE_PROJECTION;
    }
    final MatrixCursor cursor = new MatrixCursor(projection, 1);
    MatrixCursor.RowBuilder b = cursor.newRow();
    try {
        Part attachment = getAttachment(uri);
        if (attachment == null)
            return null;
        for (String col : projection) {
            switch(col) {
                case OpenableColumns.DISPLAY_NAME:
                    b.add(attachment.getFileName());
                    break;
                case OpenableColumns.SIZE:
                    b.add(Util.getPartSize(attachment));
                    break;
            }
        }
    } catch (PasswordException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (MessagingException e) {
        e.printStackTrace();
    }
    return cursor;
}
Also used : PasswordException(i2p.bote.fileencryption.PasswordException) MessagingException(javax.mail.MessagingException) Part(javax.mail.Part) IOException(java.io.IOException) MatrixCursor(android.database.MatrixCursor)

Example 19 with PasswordException

use of i2p.bote.fileencryption.PasswordException in project i2p.i2p-bote by i2p.

the class I2PBote method tryPassword.

/**
 * Tests if a password is correct and stores it in the cache if it is.
 * If the password is not correct, a <code>PasswordException</code> is thrown.
 * @param password
 * @throws IOException
 * @throws GeneralSecurityException
 * @throws PasswordException
 */
@Override
public void tryPassword(byte[] password) throws IOException, GeneralSecurityException, PasswordException {
    File passwordFile = configuration.getPasswordFile();
    boolean correct = FileEncryptionUtil.isPasswordCorrect(password, passwordFile);
    if (correct) {
        // inputs a random string.
        if (passwordFile.exists())
            passwordCache.setPassword(password);
    } else
        throw new PasswordException();
}
Also used : PasswordException(i2p.bote.fileencryption.PasswordException) SecureFile(net.i2p.util.SecureFile) File(java.io.File)

Example 20 with PasswordException

use of i2p.bote.fileencryption.PasswordException in project i2p.i2p-bote by i2p.

the class AddressBook method readContacts.

/**
 * Reads an <code>AddressBook</code> from the encrypted address book file.
 * Each contact is defined by one line that contains an Email Destination
 * and a name, separated by a tab character.
 * @throws PasswordException
 */
private void readContacts() throws PasswordException {
    if (!addressFile.exists()) {
        log.debug("Address file does not exist: <" + addressFile.getAbsolutePath() + ">");
        contacts = new TreeSet<Contact>(new ContactComparator());
        return;
    }
    log.debug("Reading address book from <" + addressFile.getAbsolutePath() + ">");
    BufferedReader input = null;
    try {
        InputStream encryptedStream = new EncryptedInputStream(new FileInputStream(addressFile), passwordHolder);
        input = new BufferedReader(new InputStreamReader(encryptedStream));
        // No PasswordException occurred, so parse the input stream
        Properties properties = new Properties();
        properties.load(new InputStreamReader(encryptedStream));
        loadFromProperties(properties, false, false);
    } catch (PasswordException e) {
        throw e;
    } catch (Exception e) {
        log.error("Can't read address book.", e);
    } finally {
        if (input != null)
            try {
                input.close();
            } catch (IOException e) {
                log.error("Error closing input stream.", e);
            }
    }
}
Also used : EncryptedInputStream(i2p.bote.fileencryption.EncryptedInputStream) PasswordException(i2p.bote.fileencryption.PasswordException) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) EncryptedInputStream(i2p.bote.fileencryption.EncryptedInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) Properties(java.util.Properties) SortedProperties(i2p.bote.util.SortedProperties) FileInputStream(java.io.FileInputStream) PasswordException(i2p.bote.fileencryption.PasswordException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Contact(i2p.bote.packet.dht.Contact)

Aggregations

PasswordException (i2p.bote.fileencryption.PasswordException)26 IOException (java.io.IOException)16 GeneralSecurityException (java.security.GeneralSecurityException)15 MessagingException (javax.mail.MessagingException)11 Email (i2p.bote.email.Email)9 Bitmap (android.graphics.Bitmap)4 View (android.view.View)4 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 Person (i2p.bote.android.util.Person)4 Contact (i2p.bote.packet.dht.Contact)4 Part (javax.mail.Part)4 Intent (android.content.Intent)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Address (javax.mail.Address)3 InternetAddress (javax.mail.internet.InternetAddress)3 SuppressLint (android.annotation.SuppressLint)2 IconicsDrawable (com.mikepenz.iconics.IconicsDrawable)2 ContentAttachment (i2p.bote.android.util.ContentAttachment)2