How to unzip encrypted ODT OpenDocument in Java

I have an encrypted ODT (Open Document Text) file and I need to unzip it. ODT is a ZIP file. Encrypted ODT is a regular ZIP file, only some files inside ZIP are encrypted.

Using ZipFile works well in the test, but I can not use ZipFile, because I have a stream in memory, I do not want to work with the file.

Therefore, I use ZipInputStream . But using ZipInputStream.getNextEntry () causes terrible only DEFLATED elements can have an EXT descriptor exception.

From what I can understand, it throws the first encrypted file inside the ZIP package, for example, in content.xml. Since OpenOffice encrypted the XML file, it was probably not compressed, and it was saved in a ZIP package without compression.

But ZipInputStream has a problem with this, and I don't see the way.

And yes, the encrypted ODT file was created by OpenOffice Writer 3.2.1. And yes, the stock ZipInputStream cannot even list through entries in it.

What can you offer?

+4
source share
3 answers

You can see if this is possible with the ODF Toolkit library

+1
source

The problem has nothing to do with encryption, but with the fact that ZipInputStream does not expect (and does not know how to process) an EXT descriptor when the associated data was not DEFLATED (i.e. it was saved uncompressed as it is), It may be a flaw ("bug") in ZipInputStream, but I'm not familiar enough with zip specifications to know anyway.

An inelegant, even error-free, workaround is to save the stream in a temporary file and then treat it as a ZipFile.

(I am the author of ODFind and the document "Decrypting ODF Files" mentioned above.)

+1
source

Have you stumbled upon what Ringlord is in ODFind to read encrypted ODF files? This ODF document (which can be viewed as HTML here courtesy Google ) states that there is simply no way to rely solely on Java libraries to decrypt OpenOffice.org documents. However, the author explains how to decrypt the content.xml payload of an ODF file with knowledge of the ODF Manifesto , RFC 2989 , PBKDF2Engine in JBoss3, and some of the original discoveries of the author.

Best wishes.

DISCLAIMER . I have nothing to do with Ringlord, although each link above points to Ringlord content.

0
source

Source: https://habr.com/ru/post/1332886/


All Articles