aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2013-12-24 23:13:21 +0000
committerAndreas Beeker <kiwiwings@apache.org>2013-12-24 23:13:21 +0000
commitbf2b13b9faf6140776a52bc8698266b59418c122 (patch)
tree774037c34920f4fe4f1825f90c5544bb2bc390cf /src/testcases/org
parent97e6fae71e9841bb94b3478d2f2ea2c26c03efb4 (diff)
downloadpoi-bf2b13b9faf6140776a52bc8698266b59418c122.tar.gz
poi-bf2b13b9faf6140776a52bc8698266b59418c122.zip
Patch for Bug/Enhancement 55818 - add encryption support
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1553336 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org')
-rw-r--r--src/testcases/org/apache/poi/poifs/crypt/AllPOIFSCryptoTests.java37
-rw-r--r--src/testcases/org/apache/poi/poifs/crypt/TestDecryptor.java117
-rw-r--r--src/testcases/org/apache/poi/poifs/crypt/TestEncryptionInfo.java60
3 files changed, 0 insertions, 214 deletions
diff --git a/src/testcases/org/apache/poi/poifs/crypt/AllPOIFSCryptoTests.java b/src/testcases/org/apache/poi/poifs/crypt/AllPOIFSCryptoTests.java
deleted file mode 100644
index d7aef1039f..0000000000
--- a/src/testcases/org/apache/poi/poifs/crypt/AllPOIFSCryptoTests.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.poifs.crypt;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-
-/**
- * Tests for org.apache.poi.poifs.crypt
- *
- * @author Gary King
- */
-public final class AllPOIFSCryptoTests {
-
- public static Test suite() {
- TestSuite result = new TestSuite(AllPOIFSCryptoTests.class.getName());
- result.addTestSuite(TestDecryptor.class);
- result.addTestSuite(TestEncryptionInfo.class);
- return result;
- }
-} \ No newline at end of file
diff --git a/src/testcases/org/apache/poi/poifs/crypt/TestDecryptor.java b/src/testcases/org/apache/poi/poifs/crypt/TestDecryptor.java
deleted file mode 100644
index dcef8d31cd..0000000000
--- a/src/testcases/org/apache/poi/poifs/crypt/TestDecryptor.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-package org.apache.poi.poifs.crypt;
-
-import junit.framework.TestCase;
-import org.apache.poi.POIDataSamples;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.GeneralSecurityException;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
-/**
- * @author Maxim Valyanskiy
- * @author Gary King
- */
-public class TestDecryptor extends TestCase {
- public void testPasswordVerification() throws IOException, GeneralSecurityException {
- POIFSFileSystem fs = new POIFSFileSystem(POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx"));
-
- EncryptionInfo info = new EncryptionInfo(fs);
-
- Decryptor d = Decryptor.getInstance(info);
-
- assertTrue(d.verifyPassword(Decryptor.DEFAULT_PASSWORD));
- }
-
- public void testDecrypt() throws IOException, GeneralSecurityException {
- POIFSFileSystem fs = new POIFSFileSystem(POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx"));
-
- EncryptionInfo info = new EncryptionInfo(fs);
-
- Decryptor d = Decryptor.getInstance(info);
-
- d.verifyPassword(Decryptor.DEFAULT_PASSWORD);
-
- zipOk(fs, d);
- }
-
- public void testAgile() throws IOException, GeneralSecurityException {
- POIFSFileSystem fs = new POIFSFileSystem(POIDataSamples.getPOIFSInstance().openResourceAsStream("protected_agile.docx"));
-
- EncryptionInfo info = new EncryptionInfo(fs);
-
- assertTrue(info.getVersionMajor() == 4 && info.getVersionMinor() == 4);
-
- Decryptor d = Decryptor.getInstance(info);
-
- assertTrue(d.verifyPassword(Decryptor.DEFAULT_PASSWORD));
-
- zipOk(fs, d);
- }
-
- private void zipOk(POIFSFileSystem fs, Decryptor d) throws IOException, GeneralSecurityException {
- ZipInputStream zin = new ZipInputStream(d.getDataStream(fs));
-
- while (true) {
- ZipEntry entry = zin.getNextEntry();
- if (entry==null) {
- break;
- }
-
- while (zin.available()>0) {
- zin.skip(zin.available());
- }
- }
- }
- public void testDataLength() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(POIDataSamples.getPOIFSInstance().openResourceAsStream("protected_agile.docx"));
-
- EncryptionInfo info = new EncryptionInfo(fs);
-
- Decryptor d = Decryptor.getInstance(info);
-
- d.verifyPassword(Decryptor.DEFAULT_PASSWORD);
-
- InputStream is = d.getDataStream(fs);
-
- long len = d.getLength();
- assertEquals(12810, len);
-
- byte[] buf = new byte[(int)len];
-
- is.read(buf);
-
- ZipInputStream zin = new ZipInputStream(new ByteArrayInputStream(buf));
-
- while (true) {
- ZipEntry entry = zin.getNextEntry();
- if (entry==null) {
- break;
- }
-
- while (zin.available()>0) {
- zin.skip(zin.available());
- }
- }
- }
-
-}
diff --git a/src/testcases/org/apache/poi/poifs/crypt/TestEncryptionInfo.java b/src/testcases/org/apache/poi/poifs/crypt/TestEncryptionInfo.java
deleted file mode 100644
index 7869183c9f..0000000000
--- a/src/testcases/org/apache/poi/poifs/crypt/TestEncryptionInfo.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/* ====================================================================
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-package org.apache.poi.poifs.crypt;
-
-import junit.framework.TestCase;
-import org.apache.poi.POIDataSamples;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-
-import java.io.IOException;
-
-/**
- * @author Maxim Valyanskiy
- */
-public class TestEncryptionInfo extends TestCase {
- public void testEncryptionInfo() throws IOException {
- POIFSFileSystem fs = new POIFSFileSystem(POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx"));
-
- EncryptionInfo info = new EncryptionInfo(fs);
-
- assertEquals(3, info.getVersionMajor());
- assertEquals(2, info.getVersionMinor());
-
- assertEquals(EncryptionHeader.ALGORITHM_AES_128, info.getHeader().getAlgorithm());
- assertEquals(EncryptionHeader.HASH_SHA1, info.getHeader().getHashAlgorithm());
- assertEquals(128, info.getHeader().getKeySize());
- assertEquals(32, info.getVerifier().getVerifierHash().length);
- assertEquals(EncryptionHeader.PROVIDER_AES, info.getHeader().getProviderType());
- assertEquals("Microsoft Enhanced RSA and AES Cryptographic Provider", info.getHeader().getCspName());
- }
-
- public void testEncryptionInfoSHA512() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(POIDataSamples.getPOIFSInstance().openResourceAsStream("protected_sha512.xlsx"));
-
- EncryptionInfo info = new EncryptionInfo(fs);
-
- assertEquals(4, info.getVersionMajor());
- assertEquals(4, info.getVersionMinor());
-
- assertEquals(EncryptionHeader.ALGORITHM_AES_256, info.getHeader().getAlgorithm());
- assertEquals(EncryptionHeader.HASH_SHA512, info.getHeader().getHashAlgorithm());
- assertEquals(256, info.getHeader().getKeySize());
- assertEquals(64, info.getVerifier().getVerifierHash().length);
- assertEquals(EncryptionHeader.PROVIDER_AES, info.getHeader().getProviderType());
-// assertEquals("Microsoft Enhanced RSA and AES Cryptographic Provider", info.getHeader().getCspName());
- }
-}