facebook隐藏图书馆的问题

时间:2014-04-07 08:14:52

标签: java android facebook encryption io

我从隐藏中读取解密数据时遇到问题。看起来我无法正确完成流式传输。 我假装隐藏有一些问题,因为当我切换我的proxyStream(只是加密部分)而不是通过隐藏运行它时,一切都按预期工作。我也假设写作没问题,没有任何例外,我可以在磁盘上找到加密文件。

我通过contentprovider代理我的数据,以允许其他应用在用户需要时读取解密数据。 (分享,......)

在我的内容提供商中,我使用openFile方法允许contentResolvers读取数据

@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {

    try {
        ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
        String name = uri.getLastPathSegment();
        File file = new File(name);
        InputStream fileContents = mStorageProxy.getDecryptInputStream(file);
        ParcelFileDescriptor.AutoCloseOutputStream stream = new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1]);
        PipeThread pipeThread = new PipeThread(fileContents, stream);
        pipeThread.start();
        return pipe[0];
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

我想在Facebook应用程序中,Facebook安卓团队可能会使用标准的query()方法,而MediaStore.MediaColumns()中发送的字节数组不适合我,因为我不仅仅是因为我加密媒体文件,我也更喜欢流的方法。

这就是我从Inpustream中读取的内容。它基本上是两个parcelFileDescriptors之间的管道。输入流来自隐藏,它是一个原始包装在BufferedInputStream中的FileInputstream。

static class PipeThread extends Thread {
    InputStream input;
    OutputStream out;

    PipeThread(InputStream inputStream, OutputStream out) {
        this.input=inputStream;
        this.out=out;
    }

    @Override
    public void run() {
            byte[] buf=new byte[1024];
            int len;

            try {
                while ((len=input.read(buf)) > 0) {
                    out.write(buf, 0, len);
                }

                input.close();
                out.flush();
                out.close();
            }
        catch (IOException e) {
            Log.e(getClass().getSimpleName(),
                "Exception transferring file", e);
        }
    }
}

我已尝试过其他方法如何阅读流,因此它确实不应该成为问题。

最后,这是我不断结束的例外情况。你知道这可能是什么问题吗?它指向本机电话,我迷失了......

Exception transferring file
com.facebook.crypto.cipher.NativeGCMCipherException: decryptFinal
        at com.facebook.crypto.cipher.NativeGCMCipher.decryptFinal(NativeGCMCipher.java:108)
        at com.facebook.crypto.streams.NativeGCMCipherInputStream.ensureTagValid(NativeGCMCipherInputStream.java:126)
        at com.facebook.crypto.streams.NativeGCMCipherInputStream.read(NativeGCMCipherInputStream.java:91)
        at com.facebook.crypto.streams.NativeGCMCipherInputStream.read(NativeGCMCipherInputStream.java:76)

编辑: 看起来流工作正常,但失败的是从中读取的最后一次迭代。由于我使用缓冲区,似乎缓冲区大于重新生成数据量导致问题的事实。我一直在寻找隐瞒的来源,从这方面来看似乎没问题。无法在原生层中的某个地方失败吗? 注意:我已经设法获得解密文件,除了它的最后一块字节..所以我有一个不完整的图像文件(最后几千个像素没有显示)

2 个答案:

答案 0 :(得分:4)

根据我隐藏的小经验,我注意到,只有加密文件的相同应用程序才能成功解密,无论它是否具有相同的包。一定要记住这一点

答案 1 :(得分:0)

这已在https://github.com/facebook/conceal/issues/24中得到解决。为了后人的缘故,这里的问题是作者忘了在输出流上调用close()。

相关问题