From 49b7c7779da38c215dfeb0b3ef19fbce2a6ea3e1 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Fri, 20 Jun 2014 19:28:47 +0200 Subject: fixes for otr file transfer --- .../siacs/conversations/xmpp/jingle/JingleTransport.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/eu/siacs/conversations/xmpp/jingle/JingleTransport.java') diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleTransport.java b/src/eu/siacs/conversations/xmpp/jingle/JingleTransport.java index b96fefede..5db4b715a 100644 --- a/src/eu/siacs/conversations/xmpp/jingle/JingleTransport.java +++ b/src/eu/siacs/conversations/xmpp/jingle/JingleTransport.java @@ -5,6 +5,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; +import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; @@ -12,6 +13,7 @@ import javax.crypto.Cipher; import javax.crypto.CipherOutputStream; import javax.crypto.CipherInputStream; import javax.crypto.NoSuchPaddingException; +import javax.crypto.spec.IvParameterSpec; import android.util.Log; @@ -19,14 +21,16 @@ public abstract class JingleTransport { public abstract void connect(final OnTransportConnected callback); public abstract void receive(final JingleFile file, final OnFileTransmitted callback); public abstract void send(final JingleFile file, final OnFileTransmitted callback); + private byte[] iv = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0xf}; protected InputStream getInputStream(JingleFile file) throws FileNotFoundException { if (file.getKey() == null) { return new FileInputStream(file); } else { try { + IvParameterSpec ips = new IvParameterSpec(iv); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); - cipher.init(Cipher.ENCRYPT_MODE, file.getKey()); + cipher.init(Cipher.ENCRYPT_MODE, file.getKey(),ips); Log.d("xmppService","opening encrypted input stream"); return new CipherInputStream(new FileInputStream(file), cipher); } catch (NoSuchAlgorithmException e) { @@ -38,6 +42,9 @@ public abstract class JingleTransport { } catch (InvalidKeyException e) { Log.d("xmppService","invalid key: "+e.getMessage()); return null; + } catch (InvalidAlgorithmParameterException e) { + Log.d("xmppService","invavid iv:"+e.getMessage()); + return null; } } } @@ -47,8 +54,9 @@ public abstract class JingleTransport { return new FileOutputStream(file); } else { try { + IvParameterSpec ips = new IvParameterSpec(iv); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); - cipher.init(Cipher.DECRYPT_MODE, file.getKey()); + cipher.init(Cipher.DECRYPT_MODE, file.getKey(),ips); Log.d("xmppService","opening encrypted output stream"); return new CipherOutputStream(new FileOutputStream(file), cipher); } catch (NoSuchAlgorithmException e) { @@ -60,6 +68,9 @@ public abstract class JingleTransport { } catch (InvalidKeyException e) { Log.d("xmppService","invalid key: "+e.getMessage()); return null; + } catch (InvalidAlgorithmParameterException e) { + Log.d("xmppService","invavid iv:"+e.getMessage()); + return null; } } } -- cgit v1.2.3