From 422660e9fe78c2ee71a9f60ee7eaaa23cb90e0ab Mon Sep 17 00:00:00 2001 From: vanitasvitae Date: Mon, 31 Jul 2017 14:21:49 +0200 Subject: [PATCH] JET WORKSgit add .! --- .../smackx/ciphers/AesGcmNoPadding.java | 12 +++++----- .../jft/internal/JingleIncomingFileOffer.java | 23 ++++++++----------- .../jft/internal/JingleOutgoingFileOffer.java | 1 + 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/ciphers/AesGcmNoPadding.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/ciphers/AesGcmNoPadding.java index 22681c5ed..60c4f7eff 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/ciphers/AesGcmNoPadding.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/ciphers/AesGcmNoPadding.java @@ -25,7 +25,7 @@ import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.NoSuchPaddingException; import javax.crypto.SecretKey; -import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.GCMParameterSpec; import javax.crypto.spec.SecretKeySpec; public abstract class AesGcmNoPadding { @@ -54,10 +54,10 @@ public abstract class AesGcmNoPadding { System.arraycopy(key, 0, keyAndIv, 0, bytes); System.arraycopy(iv, 0, keyAndIv, bytes, bytes); - SecretKey secretKey = new SecretKeySpec(key, keyType); - IvParameterSpec ivSpec = new IvParameterSpec(iv); cipher = Cipher.getInstance(cipherMode, "BC"); - cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivSpec); + SecretKey keySpec = new SecretKeySpec(key, keyType); + GCMParameterSpec gcmSpec = new GCMParameterSpec(128, iv); + cipher.init(Cipher.ENCRYPT_MODE, keySpec, gcmSpec); } public AesGcmNoPadding(byte[] key, byte[] iv) throws NoSuchPaddingException, NoSuchAlgorithmException, @@ -72,8 +72,8 @@ public abstract class AesGcmNoPadding { cipher = Cipher.getInstance(cipherMode, "BC"); SecretKeySpec keySpec = new SecretKeySpec(key, keyType); - IvParameterSpec ivSpec = new IvParameterSpec(iv); - cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec); + GCMParameterSpec gcmSpec = new GCMParameterSpec(128, iv); + cipher.init(Cipher.DECRYPT_MODE, keySpec, gcmSpec); } public byte[] getKeyAndIv() { diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jft/internal/JingleIncomingFileOffer.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jft/internal/JingleIncomingFileOffer.java index 7cc129818..2c6ff4e86 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jft/internal/JingleIncomingFileOffer.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jft/internal/JingleIncomingFileOffer.java @@ -72,30 +72,25 @@ public class JingleIncomingFileOffer extends AbstractJingleFileOffer inputStream = bytestreamSession.getInputStream(); outputStream = new FileOutputStream(mFile); - byte[] filebuf = new byte[(int) file.getSize()]; + int length = 0; int read = 0; byte[] bufbuf = new byte[4096]; - LOGGER.log(Level.INFO, "Begin receiving bytes."); - while (read < filebuf.length) { - int r = inputStream.read(bufbuf); - if (r >= 0) { - System.arraycopy(bufbuf, 0, filebuf, read, r); - read += r; - LOGGER.log(Level.INFO, "Read " + r + " (" + read + " of " + filebuf.length + ") bytes."); - } else { + while ((length = inputStream.read(bufbuf)) >= 0) { + outputStream.write(bufbuf, 0, length); + read += length; + LOGGER.log(Level.INFO, "Read " + read + " (" + length + ") of " + file.getSize() + " bytes."); + if (read == (int) file.getSize()) { break; } } - - outputStream.write(filebuf); - outputStream.flush(); - + LOGGER.log(Level.INFO, "Reading/Writing finished."); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Cannot get InputStream from BytestreamSession: " + e, e); } finally { if (inputStream != null) { try { inputStream.close(); + LOGGER.log(Level.INFO, "CipherInputStream closed."); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Could not close InputStream: " + e, e); } @@ -104,12 +99,12 @@ public class JingleIncomingFileOffer extends AbstractJingleFileOffer if (outputStream != null) { try { outputStream.close(); + LOGGER.log(Level.INFO, "FileOutputStream closed."); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Could not close OutputStream: " + e, e); } } } - notifyProgressListenersFinished(); } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jft/internal/JingleOutgoingFileOffer.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jft/internal/JingleOutgoingFileOffer.java index 9630d893c..6529e7719 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jft/internal/JingleOutgoingFileOffer.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jft/internal/JingleOutgoingFileOffer.java @@ -61,6 +61,7 @@ public class JingleOutgoingFileOffer extends AbstractJingleFileOffer outputStream.write(fileBuf); outputStream.flush(); + outputStream.close(); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Exception while sending file: " + e, e);