check for uuid change when decrypting pgp messages

This commit is contained in:
Daniel Gultsch 2016-02-21 11:43:03 +01:00
parent ed740b4868
commit b00c561f81
1 changed files with 6 additions and 7 deletions

View File

@ -37,25 +37,24 @@ public class PgpEngine {
this.mXmppConnectionService = service; this.mXmppConnectionService = service;
} }
public void decrypt(final Message message, public void decrypt(final Message message, final UiCallback<Message> callback) {
final UiCallback<Message> callback) {
Intent params = new Intent(); Intent params = new Intent();
params.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY); params.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
final String uuid = message.getUuid();
if (message.getType() == Message.TYPE_TEXT) { if (message.getType() == Message.TYPE_TEXT) {
InputStream is = new ByteArrayInputStream(message.getBody() InputStream is = new ByteArrayInputStream(message.getBody().getBytes());
.getBytes());
final OutputStream os = new ByteArrayOutputStream(); final OutputStream os = new ByteArrayOutputStream();
api.executeApiAsync(params, is, os, new IOpenPgpCallback() { api.executeApiAsync(params, is, os, new IOpenPgpCallback() {
@Override @Override
public void onReturn(Intent result) { public void onReturn(Intent result) {
notifyPgpDecryptionService(message.getConversation().getAccount(), OpenPgpApi.ACTION_DECRYPT_VERIFY, result); notifyPgpDecryptionService(message.getConversation().getAccount(), OpenPgpApi.ACTION_DECRYPT_VERIFY, result);
switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
OpenPgpApi.RESULT_CODE_ERROR)) {
case OpenPgpApi.RESULT_CODE_SUCCESS: case OpenPgpApi.RESULT_CODE_SUCCESS:
try { try {
os.flush(); os.flush();
if (message.getEncryption() == Message.ENCRYPTION_PGP) { if (message.getEncryption() == Message.ENCRYPTION_PGP
&& message.getUuid().equals(uuid)) {
message.setBody(os.toString()); message.setBody(os.toString());
message.setEncryption(Message.ENCRYPTION_DECRYPTED); message.setEncryption(Message.ENCRYPTION_DECRYPTED);
final HttpConnectionManager manager = mXmppConnectionService.getHttpConnectionManager(); final HttpConnectionManager manager = mXmppConnectionService.getHttpConnectionManager();