Skip to content

Commit fd4063f

Browse files
committed
Add corrector for PdfMacData
Now you can properly see AttachedToSig MAC data in the signatures.
1 parent 2df94fe commit fd4063f

File tree

3 files changed

+165
-0
lines changed

3 files changed

+165
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ This file is part of the iText (R) project.
4444

4545
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.algorithms.Mgf1Corrector;
4646
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.algorithms.RsassaPssCorrector;
47+
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.pdf.PdfMacDataCorrector;
4748
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.pdf.PdfMacIntegrityInfoCorrector;
4849
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.pdf.RevocationInfoArchivalCorrector;
4950
import com.itextpdf.rups.view.itext.treenodes.asn1.correctors.x509.BasicOcspResponseCorrector;
@@ -113,6 +114,10 @@ public final class OidCorrectorMapper {
113114
RsassaPssCorrector.INSTANCE
114115
),
115116
// PDF
117+
Map.entry(
118+
PdfMacDataCorrector.OID,
119+
PdfMacDataCorrector.INSTANCE
120+
),
116121
Map.entry(
117122
PdfMacIntegrityInfoCorrector.OID,
118123
PdfMacIntegrityInfoCorrector.INSTANCE
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2026 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+
address: sales@itextpdf.com
42+
*/
43+
package com.itextpdf.rups.view.itext.treenodes.asn1.correctors.pdf;
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.ContentInfoCorrector;
48+
49+
import org.bouncycastle.asn1.ASN1Primitive;
50+
51+
/**
52+
* Corrector for the PdfMacData type, as it is defined in ISO/TS 32004:2024.
53+
*
54+
* <pre>
55+
* PdfMacData ::= ContentInfo
56+
* </pre>
57+
*/
58+
public final class PdfMacDataCorrector extends AbstractCorrector {
59+
/**
60+
* Singleton instance of the corrector.
61+
*/
62+
public static final PdfMacDataCorrector INSTANCE = new PdfMacDataCorrector();
63+
64+
private PdfMacDataCorrector() {
65+
// singleton class
66+
}
67+
68+
/**
69+
* OBJECT IDENTIFIER for the type, which is handled by the corrector.
70+
*/
71+
public static final String OID = "1.0.32004.1.2";
72+
73+
/**
74+
* {@inheritDoc}
75+
*/
76+
@Override
77+
public String getDefaultVariableName() {
78+
return "pdfMacData";
79+
}
80+
81+
/**
82+
* {@inheritDoc}
83+
*/
84+
@Override
85+
public void correct(AbstractAsn1TreeNode node, ASN1Primitive obj, String variableName) {
86+
ContentInfoCorrector.INSTANCE.correct(node, obj, variableName);
87+
}
88+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2026 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+
address: sales@itextpdf.com
42+
*/
43+
package com.itextpdf.rups.view.itext.treenodes.asn1.correctors.pdf;
44+
45+
import com.itextpdf.rups.view.itext.treenodes.asn1.AbstractAsn1TreeNode;
46+
import com.itextpdf.rups.view.itext.treenodes.asn1.Asn1TestUtil;
47+
import com.itextpdf.rups.view.itext.treenodes.asn1.Asn1TreeNodeFactory;
48+
49+
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
50+
import org.bouncycastle.asn1.DERSequence;
51+
import org.junit.jupiter.api.Tag;
52+
import org.junit.jupiter.api.Test;
53+
54+
@Tag("UnitTest")
55+
final class PdfMacDataCorrectorTest {
56+
@Test
57+
void correct() {
58+
// This is, pretty much, an alias to ContentInfo with a different
59+
// default name, so no need for anything fancy
60+
final AbstractAsn1TreeNode node = Asn1TreeNodeFactory.fromPrimitive(
61+
new DERSequence(new ASN1ObjectIdentifier("1.2.840.113549.1.9.16.1.2"))
62+
);
63+
PdfMacDataCorrector.INSTANCE.correct(node);
64+
Asn1TestUtil.assertNodeMatches(1, "pdfMacData", node);
65+
Asn1TestUtil.assertNodeMatches(
66+
0,
67+
"contentType: 1.2.840.113549.1.9.16.1.2 (/iso/member-body/us/rsadsi/pkcs/pkcs-9"
68+
+ "/smime/ct/id-ct-authData)",
69+
node.getChildAt(0)
70+
);
71+
}
72+
}

0 commit comments

Comments
 (0)