Skip to content

Commit c87e21a

Browse files
committed
Add ASN.1 correctors for some Adobe X.509 extensions
Found these two extensions used in this example file: https://sautinsoft.com/products/pdf/help/net/Code%20samples/CSharp/07.%20Securing%20and%20signing/05.%20Read%20Signature%20Properties/digital%20signature.pdf Extension format descriptions are available here: https://www.adobe.com/devnet-docs/acrobatetk/tools/DigSigDC/oids.html
1 parent b29ad77 commit c87e21a

File tree

7 files changed

+899
-0
lines changed

7 files changed

+899
-0
lines changed

src/main/java/com/itextpdf/rups/view/itext/treenodes/asn1/correctors/OidCorrectorMapper.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ This file is part of the iText (R) project.
6464
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.x509.attributes.ocsp.OcspNonceCorrector;
6565
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.x509.attributes.ocsp.OcspPreferredSignatureAlgorithmsCorrector;
6666
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.x509.attributes.ocsp.OcspServiceLocatorCorrector;
67+
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.x509.extensions.ArchiveRevInfoCorrector;
6768
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.x509.extensions.AuthorityInfoAccessCorrector;
6869
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.x509.extensions.AuthorityKeyIdentifierCorrector;
6970
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.x509.extensions.BasicConstraintsCorrector;
@@ -72,6 +73,8 @@ This file is part of the iText (R) project.
7273
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.x509.extensions.ExtKeyUsageCorrector;
7374
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.x509.extensions.KeyUsageCorrector;
7475
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.x509.extensions.SubjectKeyIdentifierCorrector;
76+
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.x509.extensions.TimeStampCorrector;
77+
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.x509.extensions.UbiquityRightsCorrector;
7578
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.x509.policies.CpsPointerCorrector;
7679
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.x509.policies.UserNoticeCorrector;
7780

@@ -187,6 +190,10 @@ public final class OidCorrectorMapper {
187190
TimeStampTokenCorrector.INSTANCE
188191
),
189192
// X.509 Extensions
193+
Map.entry(
194+
ArchiveRevInfoCorrector.OID,
195+
ArchiveRevInfoCorrector.INSTANCE
196+
),
190197
Map.entry(
191198
AuthorityInfoAccessCorrector.OID,
192199
AuthorityInfoAccessCorrector.INSTANCE
@@ -219,6 +226,14 @@ public final class OidCorrectorMapper {
219226
SubjectKeyIdentifierCorrector.OID,
220227
SubjectKeyIdentifierCorrector.INSTANCE
221228
),
229+
Map.entry(
230+
TimeStampCorrector.OID,
231+
TimeStampCorrector.INSTANCE
232+
),
233+
Map.entry(
234+
UbiquityRightsCorrector.OID,
235+
UbiquityRightsCorrector.INSTANCE
236+
),
222237
// X.509 Certificate Policies
223238
Map.entry(
224239
CpsPointerCorrector.OID,
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2025 Apryse Group NV
4+
Authors: Apryse Software.
5+
6+
This program is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License version 3
8+
as published by the Free Software Foundation with the addition of the
9+
following permission added to Section 15 as permitted in Section 7(a):
10+
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
11+
APRYSE GROUP. APRYSE GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
12+
OF THIRD PARTY RIGHTS
13+
14+
This program is distributed in the hope that it will be useful, but
15+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16+
or FITNESS FOR A PARTICULAR PURPOSE.
17+
See the GNU Affero General Public License for more details.
18+
You should have received a copy of the GNU Affero General Public License
19+
along with this program; if not, see http://www.gnu.org/licenses or write to
20+
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21+
Boston, MA, 02110-1301 USA, or download the license from the following URL:
22+
http://itextpdf.com/terms-of-use/
23+
24+
The interactive user interfaces in modified source and object code versions
25+
of this program must display Appropriate Legal Notices, as required under
26+
Section 5 of the GNU Affero General Public License.
27+
28+
In accordance with Section 7(b) of the GNU Affero General Public License,
29+
a covered work must retain the producer line in every PDF that is created
30+
or manipulated using iText.
31+
32+
You can be released from the requirements of the license by purchasing
33+
a commercial license. Buying such a license is mandatory as soon as you
34+
develop commercial activities involving the iText software without
35+
disclosing the source code of your own applications.
36+
These activities include: offering paid services to customers as an ASP,
37+
serving PDFs on the fly in a web application, shipping iText with a closed
38+
source product.
39+
40+
For more information, please contact iText Software Corp. at this
41+
42+
*/
43+
package com.itextpdf.rups.view.itext.treenodes.asn1.correctors.x509.extensions;
44+
45+
import com.itextpdf.rups.view.itext.treenodes.asn1.AbstractAsn1TreeNode;
46+
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.AbstractCorrector;
47+
48+
import org.bouncycastle.asn1.ASN1Integer;
49+
import org.bouncycastle.asn1.ASN1Primitive;
50+
import org.bouncycastle.asn1.ASN1Sequence;
51+
52+
/**
53+
* Corrector for the proprietary ArchiveRevInfo extension from Adobe.
54+
*
55+
* <pre>
56+
* ArchiveRevInfo ::= SEQUENCE {
57+
* version INTEGER { v1(1) }, -- extension version
58+
* }
59+
* </pre>
60+
*/
61+
public final class ArchiveRevInfoCorrector extends AbstractCorrector {
62+
/**
63+
* Singleton instance of the corrector.
64+
*/
65+
public static final ArchiveRevInfoCorrector INSTANCE = new ArchiveRevInfoCorrector();
66+
67+
private ArchiveRevInfoCorrector() {
68+
// singleton class
69+
}
70+
71+
/**
72+
* OBJECT IDENTIFIER for the type, which is handled by the corrector.
73+
*/
74+
public static final String OID = "1.2.840.113583.1.1.9.2";
75+
76+
/**
77+
* {@inheritDoc}
78+
*/
79+
@Override
80+
public String getDefaultVariableName() {
81+
return "archiveRevInfo";
82+
}
83+
84+
/**
85+
* {@inheritDoc}
86+
*/
87+
@Override
88+
public void correct(AbstractAsn1TreeNode node, ASN1Primitive obj, String variableName) {
89+
if (!isUniversalType(obj, ASN1Sequence.class)) {
90+
return;
91+
}
92+
node.setRfcFieldName(variableName);
93+
if (node.getChildCount() > 0) {
94+
correctVersion(node.getChildAt(0));
95+
}
96+
}
97+
98+
/**
99+
* <pre>
100+
* Version ::= INTEGER { v1(1) }
101+
* </pre>
102+
*/
103+
private static void correctVersion(AbstractAsn1TreeNode node) {
104+
if (!isUniversalType(node, ASN1Integer.class)) {
105+
return;
106+
}
107+
node.setRfcFieldName("version");
108+
final ASN1Integer nodeValue = (ASN1Integer) node.getAsn1Primitive();
109+
if (nodeValue.hasValue(1)) {
110+
node.setValueExplanation("v1");
111+
}
112+
}
113+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2025 Apryse Group NV
4+
Authors: Apryse Software.
5+
6+
This program is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License version 3
8+
as published by the Free Software Foundation with the addition of the
9+
following permission added to Section 15 as permitted in Section 7(a):
10+
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
11+
APRYSE GROUP. APRYSE GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
12+
OF THIRD PARTY RIGHTS
13+
14+
This program is distributed in the hope that it will be useful, but
15+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16+
or FITNESS FOR A PARTICULAR PURPOSE.
17+
See the GNU Affero General Public License for more details.
18+
You should have received a copy of the GNU Affero General Public License
19+
along with this program; if not, see http://www.gnu.org/licenses or write to
20+
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21+
Boston, MA, 02110-1301 USA, or download the license from the following URL:
22+
http://itextpdf.com/terms-of-use/
23+
24+
The interactive user interfaces in modified source and object code versions
25+
of this program must display Appropriate Legal Notices, as required under
26+
Section 5 of the GNU Affero General Public License.
27+
28+
In accordance with Section 7(b) of the GNU Affero General Public License,
29+
a covered work must retain the producer line in every PDF that is created
30+
or manipulated using iText.
31+
32+
You can be released from the requirements of the license by purchasing
33+
a commercial license. Buying such a license is mandatory as soon as you
34+
develop commercial activities involving the iText software without
35+
disclosing the source code of your own applications.
36+
These activities include: offering paid services to customers as an ASP,
37+
serving PDFs on the fly in a web application, shipping iText with a closed
38+
source product.
39+
40+
For more information, please contact iText Software Corp. at this
41+
42+
*/
43+
package com.itextpdf.rups.view.itext.treenodes.asn1.correctors.x509.extensions;
44+
45+
import com.itextpdf.rups.view.itext.treenodes.asn1.AbstractAsn1TreeNode;
46+
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.AbstractCorrector;
47+
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.x509.GeneralNameCorrector;
48+
49+
import org.bouncycastle.asn1.ASN1Boolean;
50+
import org.bouncycastle.asn1.ASN1Integer;
51+
import org.bouncycastle.asn1.ASN1Primitive;
52+
import org.bouncycastle.asn1.ASN1Sequence;
53+
54+
/**
55+
* Corrector for the proprietary TimeStamp extension from Adobe.
56+
*
57+
* <pre>
58+
* TimeStamp ::= SEQUENCE {
59+
* version INTEGER { v1(1) }, -- extension version
60+
* location GeneralName -- (In v1 GeneralName can be only uniformResourceIdentifier)
61+
* requiresAuth BOOLEAN DEFAULT FALSE
62+
* }
63+
* </pre>
64+
*/
65+
public final class TimeStampCorrector extends AbstractCorrector {
66+
/**
67+
* Singleton instance of the corrector.
68+
*/
69+
public static final TimeStampCorrector INSTANCE = new TimeStampCorrector();
70+
71+
private TimeStampCorrector() {
72+
// singleton class
73+
}
74+
75+
/**
76+
* OBJECT IDENTIFIER for the type, which is handled by the corrector.
77+
*/
78+
public static final String OID = "1.2.840.113583.1.1.9.1";
79+
80+
/**
81+
* {@inheritDoc}
82+
*/
83+
@Override
84+
public String getDefaultVariableName() {
85+
return "timeStamp";
86+
}
87+
88+
/**
89+
* {@inheritDoc}
90+
*/
91+
@Override
92+
public void correct(AbstractAsn1TreeNode node, ASN1Primitive obj, String variableName) {
93+
if (!isUniversalType(obj, ASN1Sequence.class)) {
94+
return;
95+
}
96+
node.setRfcFieldName(variableName);
97+
if (node.getChildCount() > 0) {
98+
correctVersion(node.getChildAt(0));
99+
}
100+
if (node.getChildCount() > 1) {
101+
GeneralNameCorrector.INSTANCE.correct(node.getChildAt(1), "location");
102+
}
103+
if (node.getChildCount() > 2) {
104+
correctPrimitiveUniversalType(node.getChildAt(2), ASN1Boolean.class, "requiresAuth");
105+
}
106+
}
107+
108+
/**
109+
* <pre>
110+
* Version ::= INTEGER { v1(1) }
111+
* </pre>
112+
*/
113+
private static void correctVersion(AbstractAsn1TreeNode node) {
114+
if (!isUniversalType(node, ASN1Integer.class)) {
115+
return;
116+
}
117+
node.setRfcFieldName("version");
118+
final ASN1Integer nodeValue = (ASN1Integer) node.getAsn1Primitive();
119+
if (nodeValue.hasValue(1)) {
120+
node.setValueExplanation("v1");
121+
}
122+
}
123+
}

0 commit comments

Comments
 (0)