Ringlord Technologies ODF Java Library
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/com/ringlord
.antbuildrc
.gitignore
LICENSE.TXT
README.org
README.text
TODO.org
TestAES.odt
TestBlowfish.odt
TestOOo.sxw
build.xml
package.html
testAES
testBlowfish
testOOo

README.org

Ringlord Technologies ODF Java Library

 Copyright © 2012 Ringlord Technologiesa
 Copyright © 2012 K. Udo Schuermann
 All rights reserved

Introduction

The Ringlord Technologies ODF Java Library provides access to the contents of OASIS Open Document File containers such as supported by LibreOffice, OpenOffice.org, KOffice, AbiWord, Google Docs, Scribus, Microsoft® Office, etc.

Specifically, cryptographically secured files can be extracted using the correct password.

License

The Ringlord Technologies ODF Java Library is licensed under the GNU General Public License v3 (or later at your option).

For the license text see the LICENSE.TXT file in the rltodfjlib.jar archive (treat the archive as a zip file for that purpose), run the software with a -L option (“java -jar rltodfjlib.jar -L”), or visit http://www.gnu.org/licenses/

Use Cases

You could use this library to test archives, extract & convert the text into another format, provide a simple viewer for ODF content, search for things, transform the encryption used from one algorithm to another, or simply read the source code and learn a little about cryptography and related concepts.

GitHub Repository

The sources are at GitHub (Project: rltodfjlib): https://github.com/kuschuermann/rltodfjlib

Building from Source

The command “ant jar” should do it. If that fails, here is what you need to know:

The source code is essentially compatible with Java 1.5 but a minor dependency on Console in the Test class (which could be fixed by commenting out some parts) pushes the minimum version to Java 1.6.

Also required (for easy rebuilding) is Apache Ant 1.7 but an earlier version of Ant may also work; you could also rebuild the software using “javac -d .build src/*.java” and then use jar to build an appropriate jar file from a manifest file and the contents of the .build/ directory. Essentially, these three commands are all you really need to build it:

mkdir .build
jar cfe odf.jar Test -C .build/ . \
                     -C . src/*.java \
                     README.text LICENSE.TXT build.xml

The included “build.xml” script builds for Java 1.7 by default but you can force compilation with Java 1.6 by using a command like “ant jar6”

The password for test documents in the repository is ‘test’.

How does it work?

The Ringlord Technologies ODF Java Library first parses the META-INF/manifest.xml file, collecting the names of all known OASIS Open Document File elements. The container (.zip file) may contain additional files not mentioned in the manifest, and these are added to the Container class afterwards so that a program wanting to look at everything in the container gets all the files, whether the manifest listed them, or not.

Aside from simply listing what’s in the ODF container, the manifest provides detailed instructions on each element’s cryptographical information (if any): What algorithm was used to encrypt it, the size of the key, the initialisation vector, the salt for the key, and a bunch of other “complicated” stuff.

When querying the Container class, each Entry returned is either one coming directly from the manifest, or one that the manifest did not list but was found in the .zip container in addition to what the manifest listed. Each such Entry may contain a Crypto object that describes what the manifest had to say about cryptographical data.

The Crypto object is responsible for decrypting the data.

The Entry is responsible for inflating (uncompressing) the data, whether it was encrypted or not.

More detailed information about this process can be found at http://ringlord.com/odfdecrypt.html

Example Code

import com.ringlord.odf.Container;
import com.ringlord.odf.Entry;

:

...

Container odf = new Container( new File("test.odt") );
try
  {
    for( Entry item : odf )
      {
        System.err.println( "\t" + item );
      }
    final Entry body = odf.get( "content.xml" );
    if( body != null )
      {
        System.err.println( "Found the 'content.xml' entry" );
        final byte[] data = (body.isEncrypted()
                             ? body.data("test") // "test" is the password
                             : body.data());
        if( data != null ) // it's a file, not a directory?
          {
            System.err.println( "Here is the XML:\n" + new String(data) );
          }
      }
  }
finally
  {
    odf.close();
  }