[ https://issues.apache.org/jira/browse/ODFTOOLKIT-403?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Damjan Jovanovic updated ODFTOOLKIT-403: ---------------------------------------- Attachment: decryption.patch Preliminary patch: * odf-toolkit currently only supports ODF 1.0 and 1.1 encryption algorithms, and uses them blindly without checking what is specified in the document elements. LibreOffice uses ODF 1.2 algorithms missing from odf-toolkit. This patch implements all the ODF 1.2 algorithms. * Fixes a bug in OdfPacket.derivePBKDF2Key() where variable k was looping up to T.length instead of hmacLen, leading to an ArrayIndexOutOfBoundsException for encryption algorithms with > 128 bits such as AES-256. * Extends OdfDecryptedException to store a cause. Successfully tested with both a Blowfish encrypted file from older OpenOffice versions and a AES-256 encrypted file from LibreOffice. Would you like regression tests? But I also have further issues: * My spacing is messed up. What is the coding style for odf-toolkit? 1 tab + rest of line spaces? * Shouldn't OdfDecryptedException be renamed to OdfDecryptionException? * Why is OdfDecryptedException **unchecked**? * OdfDecryptedException never reaches the caller, as it's caught and logged, with null being returned instead, which turns into an NPE in eg. Document.getContentRoot(). For my own purposes I have patched Document.getContentRoot() to return null instead, but to fix it properly, quite a lot of code would have to be changed. > ODF decryption errors > --------------------- > > Key: ODFTOOLKIT-403 > URL: https://issues.apache.org/jira/browse/ODFTOOLKIT-403 > Project: ODF Toolkit > Issue Type: Bug > Components: odfdom > Reporter: Damjan Jovanovic > Attachments: decryption.patch > > > Patching my way through ODFTOOLKIT-401 and ODFTOOLKIT-402, I now get one of > these errors when it come to decrypting the file: > {quote} > Aug 02, 2015 10:51:12 AM org.odftoolkit.odfdom.pkg.OdfPackage decryptData > SEVERE: null > java.security.InvalidAlgorithmParameterException: Wrong IV length: must be 8 > bytes long > at com.sun.crypto.provider.CipherCore.init(CipherCore.java:430) > at > com.sun.crypto.provider.BlowfishCipher.engineInit(BlowfishCipher.java:222) > at javax.crypto.Cipher.implInit(Cipher.java:796) > at javax.crypto.Cipher.chooseProvider(Cipher.java:854) > at javax.crypto.Cipher.init(Cipher.java:1374) > at javax.crypto.Cipher.init(Cipher.java:1308) > at > org.odftoolkit.odfdom.pkg.OdfPackage.decryptData(OdfPackage.java:1897) > at org.odftoolkit.odfdom.pkg.OdfPackage.getBytes(OdfPackage.java:1729) > at > org.odftoolkit.odfdom.pkg.OdfPackage.getInputStream(OdfPackage.java:2018) > at org.odftoolkit.odfdom.pkg.OdfFileDom.initialize(OdfFileDom.java:210) > at > org.odftoolkit.odfdom.dom.OdfContentDom.initialize(OdfContentDom.java:60) > at org.odftoolkit.odfdom.pkg.OdfFileDom.<init>(OdfFileDom.java:105) > at org.odftoolkit.odfdom.dom.OdfContentDom.<init>(OdfContentDom.java:50) > at org.odftoolkit.odfdom.pkg.OdfFileDom.newFileDom(OdfFileDom.java:157) > at > org.odftoolkit.odfdom.pkg.OdfPackageDocument.getFileDom(OdfPackageDocument.java:323) > at > org.odftoolkit.odfdom.dom.OdfSchemaDocument.getFileDom(OdfSchemaDocument.java:405) > at > org.odftoolkit.odfdom.dom.OdfSchemaDocument.getContentDom(OdfSchemaDocument.java:206) > at org.odftoolkit.simple.Document.getContentRoot(Document.java:870) > at > org.odftoolkit.simple.TextDocument.getContentRoot(TextDocument.java:327) > at > org.odftoolkit.simple.TextDocument.getContentRoot(TextDocument.java:114) > at local.Main.main(Main.java:22) > Exception in thread "main" java.lang.NullPointerException > at org.odftoolkit.simple.Document.getContentRoot(Document.java:872) > at > org.odftoolkit.simple.TextDocument.getContentRoot(TextDocument.java:327) > at > org.odftoolkit.simple.TextDocument.getContentRoot(TextDocument.java:114) > at local.Main.main(Main.java:22) > {quote} > or this one (when the password is wrong): > {quote} > Aug 02, 2015 10:56:21 AM org.odftoolkit.odfdom.pkg.OdfPackage decryptData > SEVERE: null > org.odftoolkit.odfdom.pkg.OdfDecryptedException: The given password is wrong, > please check it. > at > org.odftoolkit.odfdom.pkg.OdfPackage.decryptData(OdfPackage.java:1914) > at org.odftoolkit.odfdom.pkg.OdfPackage.getBytes(OdfPackage.java:1729) > at > org.odftoolkit.odfdom.pkg.OdfPackage.getInputStream(OdfPackage.java:2018) > at org.odftoolkit.odfdom.pkg.OdfFileDom.initialize(OdfFileDom.java:210) > at > org.odftoolkit.odfdom.dom.OdfContentDom.initialize(OdfContentDom.java:60) > at org.odftoolkit.odfdom.pkg.OdfFileDom.<init>(OdfFileDom.java:105) > at org.odftoolkit.odfdom.dom.OdfContentDom.<init>(OdfContentDom.java:50) > at org.odftoolkit.odfdom.pkg.OdfFileDom.newFileDom(OdfFileDom.java:157) > at > org.odftoolkit.odfdom.pkg.OdfPackageDocument.getFileDom(OdfPackageDocument.java:323) > at > org.odftoolkit.odfdom.dom.OdfSchemaDocument.getFileDom(OdfSchemaDocument.java:405) > at > org.odftoolkit.odfdom.dom.OdfSchemaDocument.getContentDom(OdfSchemaDocument.java:206) > at org.odftoolkit.simple.Document.getContentRoot(Document.java:870) > at > org.odftoolkit.simple.TextDocument.getContentRoot(TextDocument.java:327) > at > org.odftoolkit.simple.TextDocument.getContentRoot(TextDocument.java:114) > at local.Main.main(Main.java:22) > Exception in thread "main" java.lang.NullPointerException > at org.odftoolkit.simple.Document.getContentRoot(Document.java:872) > at > org.odftoolkit.simple.TextDocument.getContentRoot(TextDocument.java:327) > at > org.odftoolkit.simple.TextDocument.getContentRoot(TextDocument.java:114) > at local.Main.main(Main.java:22) > {quote} > Note how both actually come through as NullPointerException, while the > original exception is logged earlier. -- This message was sent by Atlassian JIRA (v6.3.4#6332)