poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1615273 - in /poi/trunk/src: java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java ooxml/java/org/apache/poi/poifs/crypt/agile/AgileEncryptionInfoBuilder.java ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java
Date Sat, 02 Aug 2014 00:51:56 GMT
Author: kiwiwings
Date: Sat Aug  2 00:51:56 2014
New Revision: 1615273

URL: http://svn.apache.org/r1615273
Log:
Another test for NPOIFS in-place writing support - probably the deletion of an entry causes
the problem

Modified:
    poi/trunk/src/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java
    poi/trunk/src/ooxml/java/org/apache/poi/poifs/crypt/agile/AgileEncryptionInfoBuilder.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java

Modified: poi/trunk/src/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java?rev=1615273&r1=1615272&r2=1615273&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java Sat Aug  2 00:51:56
2014
@@ -69,7 +69,13 @@ public class DataSpaceMapUtils {
         LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(buf,
0);
         out.write(bos);
         
-        return dir.createDocument(parts[parts.length-1], bos.getWriteIndex(), new POIFSWriterListener(){
+        String fileName = parts[parts.length-1];
+        
+        if (dir.hasEntry(fileName)) {
+            dir.getEntry(fileName).delete();
+        }
+        
+        return dir.createDocument(fileName, bos.getWriteIndex(), new POIFSWriterListener(){
             public void processPOIFSWriterEvent(POIFSWriterEvent event) {
                 try {
                     event.getStream().write(buf, 0, event.getLimit());

Modified: poi/trunk/src/ooxml/java/org/apache/poi/poifs/crypt/agile/AgileEncryptionInfoBuilder.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/poifs/crypt/agile/AgileEncryptionInfoBuilder.java?rev=1615273&r1=1615272&r2=1615273&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/poifs/crypt/agile/AgileEncryptionInfoBuilder.java
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/poifs/crypt/agile/AgileEncryptionInfoBuilder.java
Sat Aug  2 00:51:56 2014
@@ -48,6 +48,7 @@ public class AgileEncryptionInfoBuilder 
         if (info.getVersionMajor() == EncryptionMode.agile.versionMajor
             && info.getVersionMinor() == EncryptionMode.agile.versionMinor) {
             decryptor = new AgileDecryptor(this);
+            encryptor = new AgileEncryptor(this);
         }
     }
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java?rev=1615273&r1=1615272&r2=1615273&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java Sat Aug  2
00:51:56 2014
@@ -41,7 +41,10 @@ import org.apache.poi.poifs.filesystem.N
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.util.BoundedInputStream;
 import org.apache.poi.util.IOUtils;
+import org.apache.poi.util.TempFile;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
 import org.junit.Assume;
+import org.junit.Ignore;
 import org.junit.Test;
 
 public class TestEncryptor {
@@ -227,6 +230,38 @@ public class TestEncryptor {
         assertThat(payloadExpected, equalTo(payloadActual));
     }
     
+    @Test
+    @Ignore
+    public void testInPlaceRewrite() throws Exception {
+        File f = TempFile.createTempFile("protected_agile", ".docx");
+        // File f = new File("protected_agile.docx");
+        FileOutputStream fos = new FileOutputStream(f);
+        InputStream fis = POIDataSamples.getPOIFSInstance().openResourceAsStream("protected_agile.docx");
+        IOUtils.copy(fis, fos);
+        fis.close();
+        fos.close();
+        
+        NPOIFSFileSystem fs = new NPOIFSFileSystem(f, false);
+
+        // decrypt the protected file - in this case it was encrypted with the default password
+        EncryptionInfo encInfo = new EncryptionInfo(fs);
+        Decryptor d = encInfo.getDecryptor();
+        boolean b = d.verifyPassword(Decryptor.DEFAULT_PASSWORD);
+        assertTrue(b);
+
+        // do some strange things with it ;)
+        XWPFDocument docx = new XWPFDocument(d.getDataStream(fs));
+        docx.getParagraphArray(0).insertNewRun(0).setText("POI was here! All your base are
belong to us!");
+        docx.getParagraphArray(0).insertNewRun(1).addBreak();
+
+        // and encrypt it again
+        Encryptor e = encInfo.getEncryptor();
+        e.confirmPassword("AYBABTU");
+        docx.write(e.getDataStream(fs));
+        
+        fs.close();
+    }
+    
     
     private void listEntry(DocumentNode de, String ext, String path) throws IOException {
         path += "\\" + de.getName().replace('\u0006', '_');



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message