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