Skip to content

Commit aa91f24

Browse files
committed
Bug 56836 - XML signature support
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1628348 13f79535-47bb-0310-9956-ffa450edef68
2 parents 21f01ab + e1be463 commit aa91f24

File tree

56 files changed

+6908
-92
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+6908
-92
lines changed

.classpath

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<classpath>
3-
<classpathentry kind="src" path="src/java"/>
4-
<classpathentry kind="src" path="src/testcases"/>
5-
<classpathentry kind="src" path="src/resources/main"/>
6-
<classpathentry kind="src" path="src/ooxml/java"/>
7-
<classpathentry kind="src" path="src/ooxml/testcases"/>
8-
<classpathentry kind="src" path="src/resources/ooxml"/>
9-
<classpathentry kind="src" path="src/scratchpad/src"/>
10-
<classpathentry kind="src" path="src/scratchpad/testcases"/>
11-
<classpathentry kind="src" path="src/resources/scratchpad"/>
12-
<classpathentry kind="src" path="src/contrib/poi-ruby/java"/>
13-
<classpathentry kind="src" path="src/examples/src"/>
14-
<classpathentry kind="src" path="src/excelant/java"/>
15-
<classpathentry kind="src" path="src/excelant/testcases"/>
16-
<classpathentry kind="src" path="src/excelant/resources"/>
17-
<classpathentry kind="lib" path="lib/ant-1.9.4.jar"/>
18-
<classpathentry kind="lib" path="lib/ant-launcher-1.9.4.jar"/>
19-
<classpathentry kind="lib" path="lib/commons-codec-1.9.jar"/>
20-
<classpathentry kind="lib" path="lib/commons-logging-1.1.3.jar"/>
21-
<classpathentry kind="lib" path="lib/log4j-1.2.17.jar"/>
22-
<classpathentry kind="lib" path="ooxml-lib/xmlbeans-2.6.0.jar"/>
23-
<classpathentry kind="lib" path="lib/hamcrest-core-1.3.jar"/>
24-
<classpathentry kind="lib" path="lib/junit-4.11.jar"/>
25-
<classpathentry kind="lib" path="ooxml-lib/ooxml-schemas-1.1.jar" sourcepath="ooxml-lib/ooxml-schemas-src-1.1.jar"/>
26-
<classpathentry kind="lib" path="ooxml-lib/ooxml-encryption-1.1.jar" sourcepath="ooxml-lib/ooxml-encryption-src-1.1.jar"/>
27-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
28-
<classpathentry kind="output" path="build/eclipse"/>
29-
</classpath>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src/java"/>
4+
<classpathentry kind="src" path="src/testcases"/>
5+
<classpathentry kind="src" path="src/resources/main"/>
6+
<classpathentry kind="src" path="src/ooxml/java"/>
7+
<classpathentry kind="src" path="src/ooxml/testcases"/>
8+
<classpathentry kind="src" path="src/resources/ooxml"/>
9+
<classpathentry kind="src" path="src/scratchpad/src"/>
10+
<classpathentry kind="src" path="src/scratchpad/testcases"/>
11+
<classpathentry kind="src" path="src/resources/scratchpad"/>
12+
<classpathentry kind="src" path="src/contrib/poi-ruby/java"/>
13+
<classpathentry kind="src" path="src/examples/src"/>
14+
<classpathentry kind="src" path="src/excelant/java"/>
15+
<classpathentry kind="src" path="src/excelant/testcases"/>
16+
<classpathentry kind="src" path="src/excelant/resources"/>
17+
<classpathentry kind="lib" path="lib/ant-1.9.4.jar"/>
18+
<classpathentry kind="lib" path="lib/ant-launcher-1.9.4.jar"/>
19+
<classpathentry kind="lib" path="lib/commons-codec-1.9.jar"/>
20+
<classpathentry kind="lib" path="lib/commons-logging-1.1.3.jar"/>
21+
<classpathentry kind="lib" path="lib/log4j-1.2.17.jar"/>
22+
<classpathentry kind="lib" path="ooxml-lib/xmlbeans-2.6.0.jar"/>
23+
<classpathentry kind="lib" path="lib/hamcrest-core-1.3.jar"/>
24+
<classpathentry kind="lib" path="lib/junit-4.11.jar"/>
25+
<classpathentry kind="lib" path="ooxml-lib/ooxml-schemas-1.1.jar" sourcepath="ooxml-lib/ooxml-schemas-src-1.1.jar"/>
26+
<classpathentry kind="lib" path="ooxml-lib/ooxml-encryption-1.2.jar" sourcepath="ooxml-lib/ooxml-encryption-src-1.2.jar"/>
27+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
28+
<classpathentry kind="lib" path="compile-lib/slf4j-api-1.7.7.jar"/>
29+
<classpathentry kind="lib" path="compile-lib/bcpkix-jdk15on-1.51.jar"/>
30+
<classpathentry kind="lib" path="compile-lib/bcprov-ext-jdk15on-1.51.jar"/>
31+
<classpathentry kind="lib" path="compile-lib/xmlsec-2.0.1.jar"/>
32+
<classpathentry kind="output" path="build/eclipse"/>
33+
</classpath>

build.xml

Lines changed: 111 additions & 53 deletions
Large diffs are not rendered by default.

src/java/org/apache/poi/poifs/crypt/CipherAlgorithm.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public enum CipherAlgorithm {
3434
// need bouncycastle provider for this one ...
3535
// see http://stackoverflow.com/questions/4436397/3des-des-encryption-using-the-jce-generating-an-acceptable-key
3636
des3_112(null, "DESede", -1, 128, new int[]{128}, 8, 32, "3DES_112", true),
37+
// only for digital signatures
38+
rsa(null, "RSA", -1, 1024, new int[]{1024, 2048, 3072, 4096}, -1, -1, "", false);
3739
;
3840

3941
public final CipherProvider provider;

src/java/org/apache/poi/poifs/crypt/CryptoFunctions.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
1919
import java.nio.charset.Charset;
2020
import java.security.DigestException;
2121
import java.security.GeneralSecurityException;
22+
import java.security.Key;
2223
import java.security.MessageDigest;
2324
import java.security.Provider;
2425
import java.security.Security;
@@ -195,7 +196,7 @@ public static Cipher getCipher(SecretKey key, CipherAlgorithm cipherAlgorithm, C
195196
* @throws EncryptedDocumentException if the initialization failed or if an algorithm was specified,
196197
* which depends on a missing bouncy castle provider
197198
*/
198-
public static Cipher getCipher(SecretKey key, CipherAlgorithm cipherAlgorithm, ChainingMode chain, byte[] vec, int cipherMode, String padding) {
199+
public static Cipher getCipher(Key key, CipherAlgorithm cipherAlgorithm, ChainingMode chain, byte[] vec, int cipherMode, String padding) {
199200
int keySizeInBytes = key.getEncoded().length;
200201
if (padding == null) padding = "NoPadding";
201202

@@ -296,10 +297,12 @@ public static Mac getMac(HashAlgorithm hashAlgorithm) {
296297
}
297298

298299
@SuppressWarnings("unchecked")
299-
private static void registerBouncyCastle() {
300+
public static void registerBouncyCastle() {
300301
if (Security.getProvider("BC") != null) return;
301302
try {
302-
Class<Provider> clazz = (Class<Provider>)Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
303+
ClassLoader cl = Thread.currentThread().getContextClassLoader();
304+
String bcProviderName = "org.bouncycastle.jce.provider.BouncyCastleProvider";
305+
Class<Provider> clazz = (Class<Provider>)cl.loadClass(bcProviderName);
303306
Security.addProvider(clazz.newInstance());
304307
} catch (Exception e) {
305308
throw new EncryptedDocumentException("Only the BouncyCastle provider supports your encryption settings - please add it to the classpath.");

src/java/org/apache/poi/poifs/crypt/HashAlgorithm.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public enum HashAlgorithm {
3333
ripemd128("RipeMD128", -1, "RIPEMD-128", 16, "HMac-RipeMD128", true),
3434
ripemd160("RipeMD160", -1, "RIPEMD-160", 20, "HMac-RipeMD160", true),
3535
whirlpool("Whirlpool", -1, "WHIRLPOOL", 64, "HMac-Whirlpool", true),
36+
// only for xml signing
37+
sha224 ( "SHA-224", -1, "SHA224", 28, "HmacSHA224", true);
3638
;
3739

3840
public final String jceId;

src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,6 @@ public URI getSourceURI() {
182182
}
183183

184184
/**
185-
* public URI getSourceUri(){ }
186-
*
187185
* @return the targetMode
188186
*/
189187
public TargetMode getTargetMode() {

src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public int size() {
307307
* @throws InvalidFormatException
308308
* Throws if the relationship part is invalid.
309309
*/
310-
private void parseRelationshipsPart(PackagePart relPart)
310+
public void parseRelationshipsPart(PackagePart relPart)
311311
throws InvalidFormatException {
312312
try {
313313
logger.log(POILogger.DEBUG, "Parsing relationship: " + relPart.getPartName());

src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ContentTypeManager.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,10 @@ public ContentTypeManager(InputStream in, OPCPackage pkg)
145145
* </p>
146146
*/
147147
public void addContentType(PackagePartName partName, String contentType) {
148-
boolean defaultCTExists = false;
148+
boolean defaultCTExists = this.defaultContentType.containsValue(contentType);
149149
String extension = partName.getExtension().toLowerCase();
150150
if ((extension.length() == 0)
151-
|| (this.defaultContentType.containsKey(extension) && !(defaultCTExists = this.defaultContentType
152-
.containsValue(contentType))))
151+
|| (this.defaultContentType.containsKey(extension) && !defaultCTExists))
153152
this.addOverrideContentType(partName, contentType);
154153
else if (!defaultCTExists)
155154
this.addDefaultContentType(extension, contentType);
@@ -452,7 +451,7 @@ private void appendSpecificTypes(Element root,
452451
}
453452

454453
/**
455-
* Use to append default types XML elements, use by the save() metid.
454+
* Use to append default types XML elements, use by the save() method.
456455
*
457456
* @param root
458457
* XML parent element use to append this default type element.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* ====================================================================
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
==================================================================== */
17+
18+
/* ====================================================================
19+
This product contains an ASLv2 licensed version of the OOXML signer
20+
package from the eID Applet project
21+
http://code.google.com/p/eid-applet/source/browse/trunk/README.txt
22+
Copyright (C) 2008-2014 FedICT.
23+
================================================================= */
24+
25+
package org.apache.poi.poifs.crypt.dsig;
26+
27+
/**
28+
* Exception thrown in case there is something wrong with the incoming eID
29+
* certificate.
30+
*
31+
* @author Frank Cornelis
32+
*
33+
*/
34+
public class CertificateSecurityException extends SecurityException {
35+
36+
private static final long serialVersionUID = 1L;
37+
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* ====================================================================
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
==================================================================== */
17+
18+
/* ====================================================================
19+
This product contains an ASLv2 licensed version of the OOXML signer
20+
package from the eID Applet project
21+
http://code.google.com/p/eid-applet/source/browse/trunk/README.txt
22+
Copyright (C) 2008-2014 FedICT.
23+
================================================================= */
24+
25+
package org.apache.poi.poifs.crypt.dsig;
26+
27+
/**
28+
* Exception thrown in case the incoming eID certificate is expired.
29+
*
30+
* @author Frank Cornelis
31+
*
32+
*/
33+
public class ExpiredCertificateSecurityException extends
34+
CertificateSecurityException {
35+
36+
private static final long serialVersionUID = 1L;
37+
38+
}

0 commit comments

Comments
 (0)