diff options
Diffstat (limited to '')
4 files changed, 65 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/Checksum.java b/src/main/java/de/pixart/messenger/utils/Checksum.java new file mode 100644 index 000000000..25f711fcc --- /dev/null +++ b/src/main/java/de/pixart/messenger/utils/Checksum.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, Daniel Gultsch All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package de.pixart.messenger.utils; + +import android.util.Base64; + +import java.io.IOException; +import java.io.InputStream; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class Checksum { + + public static String md5(InputStream inputStream) throws IOException { + byte[] buffer = new byte[4096]; + MessageDigest messageDigest; + try { + messageDigest = MessageDigest.getInstance("MD5"); + } catch (NoSuchAlgorithmException e) { + throw new AssertionError(e); + } + + int count; + do { + count = inputStream.read(buffer); + if (count > 0) { + messageDigest.update(buffer, 0, count); + } + } while (count != -1); + inputStream.close(); + return Base64.encodeToString(messageDigest.digest(), Base64.NO_WRAP); + } +}
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/utils/CryptoHelper.java b/src/main/java/de/pixart/messenger/utils/CryptoHelper.java index 2327f6f96..cd7e72746 100644 --- a/src/main/java/de/pixart/messenger/utils/CryptoHelper.java +++ b/src/main/java/de/pixart/messenger/utils/CryptoHelper.java @@ -276,6 +276,6 @@ public final class CryptoHelper { return false; } final String u = url.toLowerCase(); - return !u.contains(" ") && (u.startsWith("https://") || u.startsWith("http://")) && u.endsWith(".pgp"); + return !u.contains(" ") && (u.startsWith("https://") || u.startsWith("http://") || u.startsWith("p1s3://")) && u.endsWith(".pgp"); } } diff --git a/src/main/java/de/pixart/messenger/utils/MessageUtils.java b/src/main/java/de/pixart/messenger/utils/MessageUtils.java index 78be415f7..4ad0e84a5 100644 --- a/src/main/java/de/pixart/messenger/utils/MessageUtils.java +++ b/src/main/java/de/pixart/messenger/utils/MessageUtils.java @@ -35,6 +35,7 @@ import java.util.regex.Pattern; import de.pixart.messenger.entities.Message; import de.pixart.messenger.http.AesGcmURLStreamHandler; +import de.pixart.messenger.http.P1S3UrlStreamHandler; public class MessageUtils { @@ -77,7 +78,8 @@ public class MessageUtils { final boolean encrypted = ref != null && AesGcmURLStreamHandler.IV_KEY.matcher(ref).matches(); final boolean followedByDataUri = lines.length == 2 && lines[1].startsWith("data:"); final boolean validAesGcm = AesGcmURLStreamHandler.PROTOCOL_NAME.equalsIgnoreCase(protocol) && encrypted && (lines.length == 1 || followedByDataUri); - final boolean validOob = ("http".equalsIgnoreCase(protocol) || "https".equalsIgnoreCase(protocol)) && (oob || encrypted) && lines.length == 1; + final boolean validProtocol = "http".equalsIgnoreCase(protocol) || "https".equalsIgnoreCase(protocol) || P1S3UrlStreamHandler.PROTOCOL_NAME.equalsIgnoreCase(protocol); + final boolean validOob = validProtocol && (oob || encrypted) && lines.length == 1; return validAesGcm || validOob; } catch (MalformedURLException e) { return false; diff --git a/src/main/java/de/pixart/messenger/utils/Namespace.java b/src/main/java/de/pixart/messenger/utils/Namespace.java index d2ba1a7ff..c3ff29697 100644 --- a/src/main/java/de/pixart/messenger/utils/Namespace.java +++ b/src/main/java/de/pixart/messenger/utils/Namespace.java @@ -21,4 +21,5 @@ public final class Namespace { public static final String NICK = "http://jabber.org/protocol/nick"; public static final String FLEXIBLE_OFFLINE_MESSAGE_RETRIEVAL = "http://jabber.org/protocol/offline"; public static final String BIND = "urn:ietf:params:xml:ns:xmpp-bind"; + public static final String P1_S3_FILE_TRANSFER = "p1:s3filetransfer"; } |