Skip to content

Commit 08d676e

Browse files
FOP-3166: Add option to sign PDF
1 parent 75e734c commit 08d676e

File tree

12 files changed

+619
-1
lines changed

12 files changed

+619
-1
lines changed

fop-core/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@
111111
<version>1.1.3</version>
112112
<scope>provided</scope>
113113
</dependency>
114+
<dependency>
115+
<groupId>org.bouncycastle</groupId>
116+
<artifactId>bcpkix-jdk15to18</artifactId>
117+
<version>1.77</version>
118+
<scope>provided</scope>
119+
</dependency>
120+
<dependency>
121+
<groupId>org.bouncycastle</groupId>
122+
<artifactId>bcprov-jdk15to18</artifactId>
123+
<version>1.77</version>
124+
<scope>provided</scope>
125+
</dependency>
114126
<dependency>
115127
<groupId>com.sun.media</groupId>
116128
<artifactId>jai-codec</artifactId>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
package org.apache.fop.pdf;
18+
19+
import java.io.IOException;
20+
import java.io.InputStream;
21+
import java.io.OutputStream;
22+
23+
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
24+
import org.bouncycastle.asn1.cms.CMSObjectIdentifiers;
25+
import org.bouncycastle.cms.CMSTypedData;
26+
27+
import org.apache.commons.io.IOUtils;
28+
29+
/**
30+
* Wraps a InputStream into a CMSProcessable object for bouncy castle. It's a memory saving
31+
* alternative to the {@link org.bouncycastle.cms.CMSProcessableByteArray CMSProcessableByteArray}
32+
* class.
33+
*/
34+
class CMSProcessableInputStream implements CMSTypedData {
35+
private InputStream in;
36+
private final ASN1ObjectIdentifier contentType;
37+
38+
CMSProcessableInputStream(InputStream is) {
39+
this(new ASN1ObjectIdentifier(CMSObjectIdentifiers.data.getId()), is);
40+
}
41+
42+
CMSProcessableInputStream(ASN1ObjectIdentifier type, InputStream is) {
43+
contentType = type;
44+
in = is;
45+
}
46+
47+
@Override
48+
public Object getContent() {
49+
return in;
50+
}
51+
52+
@Override
53+
public void write(OutputStream out) throws IOException {
54+
// read the content only one time
55+
IOUtils.copy(in, out);
56+
in.close();
57+
}
58+
59+
@Override
60+
public ASN1ObjectIdentifier getContentType() {
61+
return contentType;
62+
}
63+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
/* $Id$ */
19+
package org.apache.fop.pdf;
20+
21+
public class PDFSignParams {
22+
private String pkcs12;
23+
private String name;
24+
private String location;
25+
private String reason;
26+
private String password = "";
27+
28+
public PDFSignParams(String pkcs12, String name, String location, String reason, String password) {
29+
this.pkcs12 = pkcs12;
30+
this.name = name;
31+
this.location = location;
32+
this.reason = reason;
33+
if (password != null) {
34+
this.password = password;
35+
}
36+
}
37+
38+
public String getPkcs12() {
39+
return pkcs12;
40+
}
41+
42+
public String getName() {
43+
return name;
44+
}
45+
46+
public String getLocation() {
47+
return location;
48+
}
49+
50+
public String getReason() {
51+
return reason;
52+
}
53+
54+
public String getPassword() {
55+
return password;
56+
}
57+
}

0 commit comments

Comments
 (0)