Skip to content

Commit 50702b8

Browse files
author
Eugene Bochilo
committed
Support qualified profile
DEVSIX-9481
1 parent 12109e4 commit 50702b8

File tree

261 files changed

+13616
-132
lines changed

Some content is hidden

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

261 files changed

+13616
-132
lines changed

bouncy-castle-adapter/src/main/java/com/itextpdf/bouncycastle/BouncyCastleFactory.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ This file is part of the iText (R) project.
8888
import com.itextpdf.bouncycastle.asn1.x509.SubjectPublicKeyInfoBC;
8989
import com.itextpdf.bouncycastle.asn1.x509.TBSCertificateBC;
9090
import com.itextpdf.bouncycastle.asn1.x509.TimeBC;
91+
import com.itextpdf.bouncycastle.asn1.x509.qualified.QCStatementBC;
9192
import com.itextpdf.bouncycastle.cert.X509CertificateHolderBC;
9293
import com.itextpdf.bouncycastle.cert.X509ExtensionUtilsBC;
9394
import com.itextpdf.bouncycastle.cert.X509v2CRLBuilderBC;
@@ -197,6 +198,7 @@ This file is part of the iText (R) project.
197198
import com.itextpdf.commons.bouncycastle.asn1.x509.ISubjectPublicKeyInfo;
198199
import com.itextpdf.commons.bouncycastle.asn1.x509.ITBSCertificate;
199200
import com.itextpdf.commons.bouncycastle.asn1.x509.ITime;
201+
import com.itextpdf.commons.bouncycastle.asn1.x509.qualified.IQCStatement;
200202
import com.itextpdf.commons.bouncycastle.cert.IX509CertificateHolder;
201203
import com.itextpdf.commons.bouncycastle.cert.IX509ExtensionUtils;
202204
import com.itextpdf.commons.bouncycastle.cert.IX509v2CRLBuilder;
@@ -240,6 +242,7 @@ This file is part of the iText (R) project.
240242
import com.itextpdf.commons.bouncycastle.tsp.ITimeStampToken;
241243
import com.itextpdf.commons.bouncycastle.tsp.ITimeStampTokenGenerator;
242244

245+
import java.io.ByteArrayInputStream;
243246
import java.io.ByteArrayOutputStream;
244247
import java.io.IOException;
245248
import java.io.InputStream;
@@ -257,15 +260,19 @@ This file is part of the iText (R) project.
257260
import java.security.cert.Certificate;
258261
import java.security.cert.CertificateEncodingException;
259262
import java.security.cert.X509Certificate;
263+
import java.util.ArrayList;
260264
import java.util.Date;
261265
import java.util.List;
262266
import java.util.Set;
263267
import javax.crypto.Cipher;
264268
import javax.crypto.Mac;
265269
import javax.crypto.spec.SecretKeySpec;
270+
266271
import org.bouncycastle.asn1.ASN1BitString;
272+
import org.bouncycastle.asn1.ASN1Encodable;
267273
import org.bouncycastle.asn1.ASN1Enumerated;
268274
import org.bouncycastle.asn1.ASN1GeneralizedTime;
275+
import org.bouncycastle.asn1.ASN1InputStream;
269276
import org.bouncycastle.asn1.ASN1Integer;
270277
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
271278
import org.bouncycastle.asn1.ASN1OctetString;
@@ -292,16 +299,19 @@ This file is part of the iText (R) project.
292299
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
293300
import org.bouncycastle.asn1.x509.BasicConstraints;
294301
import org.bouncycastle.asn1.x509.CRLDistPoint;
302+
import org.bouncycastle.asn1.x509.CertificatePolicies;
295303
import org.bouncycastle.asn1.x509.DistributionPointName;
296304
import org.bouncycastle.asn1.x509.Extension;
297305
import org.bouncycastle.asn1.x509.Extensions;
298306
import org.bouncycastle.asn1.x509.GeneralNames;
299307
import org.bouncycastle.asn1.x509.IssuingDistributionPoint;
300308
import org.bouncycastle.asn1.x509.KeyPurposeId;
301309
import org.bouncycastle.asn1.x509.KeyUsage;
310+
import org.bouncycastle.asn1.x509.PolicyInformation;
302311
import org.bouncycastle.asn1.x509.ReasonFlags;
303312
import org.bouncycastle.asn1.x509.TBSCertificate;
304313
import org.bouncycastle.asn1.x509.Time;
314+
import org.bouncycastle.asn1.x509.qualified.QCStatement;
305315
import org.bouncycastle.cert.jcajce.JcaCertStore;
306316
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
307317
import org.bouncycastle.cert.jcajce.JcaX509CertificateHolder;
@@ -1935,4 +1945,49 @@ public IGCMBlockCipher createGCMBlockCipher() {
19351945
GCMBlockCipher cipher = (GCMBlockCipher) GCMBlockCipher.newInstance(AESEngine.newInstance());
19361946
return new GCMBlockCipherBC(cipher);
19371947
}
1948+
1949+
/**
1950+
* {@inheritDoc}
1951+
*/
1952+
@Override
1953+
public List<String> getPoliciesIds(byte[] policyExtension) throws IOException {
1954+
try (ASN1InputStream inputStream = new ASN1InputStream(policyExtension)) {
1955+
ASN1OctetString octetString = (ASN1OctetString) inputStream.readObject();
1956+
try (ASN1InputStream innerInputStream = new ASN1InputStream(octetString.getOctets())) {
1957+
CertificatePolicies certificatePolicies =
1958+
CertificatePolicies.getInstance(innerInputStream.readObject());
1959+
1960+
PolicyInformation[] policies = certificatePolicies.getPolicyInformation();
1961+
List<String> policyIds = new ArrayList<>(policies.length);
1962+
for (PolicyInformation policy : policies) {
1963+
policyIds.add(policy.getPolicyIdentifier().getId());
1964+
}
1965+
return policyIds;
1966+
}
1967+
}
1968+
}
1969+
1970+
/**
1971+
* {@inheritDoc}
1972+
*/
1973+
@Override
1974+
public List<IQCStatement> parseQcStatement(byte[] qcStatementsExtensionValue) throws IOException {
1975+
List<IQCStatement> qcStatements = new ArrayList<>();
1976+
if (qcStatementsExtensionValue != null) {
1977+
ASN1OctetString octs;
1978+
try (ASN1InputStream aIn = new ASN1InputStream(qcStatementsExtensionValue)) {
1979+
octs = (ASN1OctetString) aIn.readObject();
1980+
}
1981+
ASN1Primitive primitive;
1982+
try (ASN1InputStream aIn = new ASN1InputStream(octs.getOctets())) {
1983+
primitive = aIn.readObject();
1984+
}
1985+
ASN1Sequence qcStatementsSequence = ASN1Sequence.getInstance(primitive);
1986+
for (ASN1Encodable qcStatementEncodable : qcStatementsSequence) {
1987+
QCStatement qcStatement = QCStatement.getInstance(qcStatementEncodable);
1988+
qcStatements.add(new QCStatementBC(qcStatement));
1989+
}
1990+
}
1991+
return qcStatements;
1992+
}
19381993
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
package com.itextpdf.bouncycastle.asn1.x509.qualified;
24+
25+
import com.itextpdf.bouncycastle.asn1.ASN1EncodableBC;
26+
import com.itextpdf.bouncycastle.asn1.ASN1ObjectIdentifierBC;
27+
import com.itextpdf.commons.bouncycastle.asn1.IASN1Encodable;
28+
import com.itextpdf.commons.bouncycastle.asn1.IASN1ObjectIdentifier;
29+
import com.itextpdf.commons.bouncycastle.asn1.x509.qualified.IQCStatement;
30+
import org.bouncycastle.asn1.x509.qualified.QCStatement;
31+
32+
/**
33+
* Wrapper class for QCStatement.
34+
*/
35+
public class QCStatementBC extends ASN1EncodableBC implements IQCStatement {
36+
/**
37+
* Creates a new wrapper instance for {@link QCStatement}.
38+
*
39+
* @param qcStatement {@link QCStatement} to be wrapped
40+
*/
41+
public QCStatementBC(QCStatement qcStatement) {
42+
super(qcStatement);
43+
}
44+
45+
/**
46+
* Gets actual {@link QCStatement} object being wrapped.
47+
*
48+
* @return wrapped {@link QCStatement}.
49+
*/
50+
public QCStatement getQCStatement() {
51+
return (QCStatement) getEncodable();
52+
}
53+
54+
/**
55+
* {@inheritDoc}
56+
*
57+
* @return {@inheritDoc}
58+
*/
59+
@Override
60+
public IASN1ObjectIdentifier getStatementId() {
61+
return new ASN1ObjectIdentifierBC(getQCStatement().getStatementId());
62+
}
63+
64+
/**
65+
* {@inheritDoc}
66+
*
67+
* @return {@inheritDoc}
68+
*/
69+
@Override
70+
public IASN1Encodable getStatementInfo() {
71+
return new ASN1EncodableBC(getQCStatement().getStatementInfo());
72+
}
73+
}

bouncy-castle-adapter/src/main/java/com/itextpdf/bouncycastle/cert/X509CertificateHolderBC.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.bouncycastle.cert;
2424

25+
import com.itextpdf.bouncycastle.asn1.ASN1ObjectIdentifierBC;
2526
import com.itextpdf.bouncycastle.asn1.x509.AlgorithmIdentifierBC;
27+
import com.itextpdf.commons.bouncycastle.asn1.IASN1ObjectIdentifier;
2628
import com.itextpdf.commons.bouncycastle.asn1.x509.IAlgorithmIdentifier;
2729
import com.itextpdf.commons.bouncycastle.cert.IX509CertificateHolder;
2830

2931
import java.io.IOException;
3032
import java.util.Objects;
3133

34+
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
3235
import org.bouncycastle.cert.X509CertificateHolder;
3336

3437
/**
@@ -75,6 +78,21 @@ public IAlgorithmIdentifier getSignatureAlgorithm() {
7578
return new AlgorithmIdentifierBC(certificateHolder.getSignatureAlgorithm());
7679
}
7780

81+
/**
82+
* {@inheritDoc}
83+
*
84+
* @return {@inheritDoc}
85+
*/
86+
@Override
87+
public IASN1ObjectIdentifier[] getSubjectAttributeTypes() {
88+
ASN1ObjectIdentifier[] subjectAttributeTypes = certificateHolder.getSubject().getAttributeTypes();
89+
IASN1ObjectIdentifier[] subjectAttributeTypesWrapper = new IASN1ObjectIdentifier[subjectAttributeTypes.length];
90+
for (int i = 0; i < subjectAttributeTypes.length; ++i) {
91+
subjectAttributeTypesWrapper[i] = new ASN1ObjectIdentifierBC(subjectAttributeTypes[i]);
92+
}
93+
return subjectAttributeTypesWrapper;
94+
}
95+
7896
/**
7997
* Indicates whether some other object is "equal to" this one. Compares wrapped objects.
8098
*/

bouncy-castle-adapter/src/sharpenconfig/java/com/itextpdf/bouncycastle/SharpenConfigMapping.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ public void applyMappingConfiguration(MappingConfigurator configurator) {
120120
configurator.mapType("com.itextpdf.bouncycastle.asn1.x509.CRLDistPointBC", "iText.Bouncycastle.Asn1.X509.CrlDistPointBC");
121121
configurator.mapType("com.itextpdf.bouncycastle.asn1.x509.CRLReasonBC", "iText.Bouncycastle.Asn1.X509.CrlReasonBC");
122122
configurator.mapType("com.itextpdf.bouncycastle.asn1.x509.KeyPurposeIdBC", "iText.Bouncycastle.Asn1.X509.KeyPurposeIDBC");
123+
configurator.mapProperty("org.bouncycastle.asn1.x509.qualified.QCStatement.getStatementId", "StatementId");
124+
configurator.mapProperty("org.bouncycastle.asn1.x509.qualified.QCStatement.getStatementInfo", "StatementInfo");
123125
}
124126

125127
@Override

bouncy-castle-connector/src/main/java/com/itextpdf/bouncycastleconnector/BouncyCastleDefaultFactory.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ This file is part of the iText (R) project.
9191
import com.itextpdf.commons.bouncycastle.asn1.x509.ISubjectPublicKeyInfo;
9292
import com.itextpdf.commons.bouncycastle.asn1.x509.ITBSCertificate;
9393
import com.itextpdf.commons.bouncycastle.asn1.x509.ITime;
94+
import com.itextpdf.commons.bouncycastle.asn1.x509.qualified.IQCStatement;
9495
import com.itextpdf.commons.bouncycastle.cert.IX509CertificateHolder;
9596
import com.itextpdf.commons.bouncycastle.cert.IX509ExtensionUtils;
9697
import com.itextpdf.commons.bouncycastle.cert.IX509v2CRLBuilder;
@@ -133,6 +134,7 @@ This file is part of the iText (R) project.
133134
import com.itextpdf.commons.bouncycastle.tsp.ITimeStampToken;
134135
import com.itextpdf.commons.bouncycastle.tsp.ITimeStampTokenGenerator;
135136

137+
import java.io.IOException;
136138
import java.io.InputStream;
137139
import java.io.OutputStream;
138140
import java.io.Reader;
@@ -1028,4 +1030,14 @@ public byte[] generateDecryptedKeyWithAES256NoPad(byte[] key, byte[] kek) {
10281030
public IGCMBlockCipher createGCMBlockCipher() {
10291031
throw new UnsupportedOperationException(BouncyCastleLogMessageConstant.BOUNCY_CASTLE_DEPENDENCY_MUST_PRESENT);
10301032
}
1033+
1034+
@Override
1035+
public List<String> getPoliciesIds(byte[] policyExtension) throws IOException {
1036+
throw new UnsupportedOperationException(BouncyCastleLogMessageConstant.BOUNCY_CASTLE_DEPENDENCY_MUST_PRESENT);
1037+
}
1038+
1039+
@Override
1040+
public List<IQCStatement> parseQcStatement(byte[] qcStatementsExtensionValue) throws IOException {
1041+
throw new UnsupportedOperationException(BouncyCastleLogMessageConstant.BOUNCY_CASTLE_DEPENDENCY_MUST_PRESENT);
1042+
}
10311043
}

bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/BouncyCastleFipsFactory.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ This file is part of the iText (R) project.
8888
import com.itextpdf.bouncycastlefips.asn1.x509.SubjectPublicKeyInfoBCFips;
8989
import com.itextpdf.bouncycastlefips.asn1.x509.TBSCertificateBCFips;
9090
import com.itextpdf.bouncycastlefips.asn1.x509.TimeBCFips;
91+
import com.itextpdf.bouncycastlefips.asn1.x509.qualified.QCStatementBCFips;
9192
import com.itextpdf.bouncycastlefips.cert.X509CertificateHolderBCFips;
9293
import com.itextpdf.bouncycastlefips.cert.X509ExtensionUtilsBCFips;
9394
import com.itextpdf.bouncycastlefips.cert.X509v2CRLBuilderBCFips;
@@ -198,6 +199,7 @@ This file is part of the iText (R) project.
198199
import com.itextpdf.commons.bouncycastle.asn1.x509.ISubjectPublicKeyInfo;
199200
import com.itextpdf.commons.bouncycastle.asn1.x509.ITBSCertificate;
200201
import com.itextpdf.commons.bouncycastle.asn1.x509.ITime;
202+
import com.itextpdf.commons.bouncycastle.asn1.x509.qualified.IQCStatement;
201203
import com.itextpdf.commons.bouncycastle.cert.IX509CertificateHolder;
202204
import com.itextpdf.commons.bouncycastle.cert.IX509ExtensionUtils;
203205
import com.itextpdf.commons.bouncycastle.cert.IX509v2CRLBuilder;
@@ -241,6 +243,7 @@ This file is part of the iText (R) project.
241243
import com.itextpdf.commons.bouncycastle.tsp.ITimeStampToken;
242244
import com.itextpdf.commons.bouncycastle.tsp.ITimeStampTokenGenerator;
243245

246+
import java.io.ByteArrayInputStream;
244247
import java.io.ByteArrayOutputStream;
245248
import java.io.IOException;
246249
import java.io.InputStream;
@@ -259,16 +262,20 @@ This file is part of the iText (R) project.
259262
import java.security.cert.Certificate;
260263
import java.security.cert.CertificateEncodingException;
261264
import java.security.cert.X509Certificate;
265+
import java.util.ArrayList;
262266
import java.util.Date;
263267
import java.util.List;
264268
import java.util.Set;
265269
import javax.crypto.Cipher;
266270
import javax.crypto.NoSuchPaddingException;
267271
import javax.crypto.Mac;
268272
import javax.crypto.spec.SecretKeySpec;
273+
269274
import org.bouncycastle.asn1.ASN1BitString;
275+
import org.bouncycastle.asn1.ASN1Encodable;
270276
import org.bouncycastle.asn1.ASN1Enumerated;
271277
import org.bouncycastle.asn1.ASN1GeneralizedTime;
278+
import org.bouncycastle.asn1.ASN1InputStream;
272279
import org.bouncycastle.asn1.ASN1Integer;
273280
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
274281
import org.bouncycastle.asn1.ASN1OctetString;
@@ -295,16 +302,19 @@ This file is part of the iText (R) project.
295302
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
296303
import org.bouncycastle.asn1.x509.BasicConstraints;
297304
import org.bouncycastle.asn1.x509.CRLDistPoint;
305+
import org.bouncycastle.asn1.x509.CertificatePolicies;
298306
import org.bouncycastle.asn1.x509.DistributionPointName;
299307
import org.bouncycastle.asn1.x509.Extension;
300308
import org.bouncycastle.asn1.x509.Extensions;
301309
import org.bouncycastle.asn1.x509.GeneralNames;
302310
import org.bouncycastle.asn1.x509.IssuingDistributionPoint;
303311
import org.bouncycastle.asn1.x509.KeyPurposeId;
304312
import org.bouncycastle.asn1.x509.KeyUsage;
313+
import org.bouncycastle.asn1.x509.PolicyInformation;
305314
import org.bouncycastle.asn1.x509.ReasonFlags;
306315
import org.bouncycastle.asn1.x509.TBSCertificate;
307316
import org.bouncycastle.asn1.x509.Time;
317+
import org.bouncycastle.asn1.x509.qualified.QCStatement;
308318
import org.bouncycastle.cert.jcajce.JcaCertStore;
309319
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
310320
import org.bouncycastle.cert.jcajce.JcaX509CertificateHolder;
@@ -1951,4 +1961,49 @@ public IGCMBlockCipher createGCMBlockCipher() {
19511961
}
19521962
return new GCMBlockCipherBCFips(cipher);
19531963
}
1964+
1965+
/**
1966+
* {@inheritDoc}
1967+
*/
1968+
@Override
1969+
public List<String> getPoliciesIds(byte[] policyExtension) throws IOException {
1970+
try (ASN1InputStream inputStream = new ASN1InputStream(policyExtension)) {
1971+
ASN1OctetString octetString = (ASN1OctetString) inputStream.readObject();
1972+
try (ASN1InputStream innerInputStream = new ASN1InputStream(octetString.getOctets())) {
1973+
CertificatePolicies certificatePolicies =
1974+
CertificatePolicies.getInstance(innerInputStream.readObject());
1975+
1976+
PolicyInformation[] policies = certificatePolicies.getPolicyInformation();
1977+
List<String> policyIds = new ArrayList<>(policies.length);
1978+
for (PolicyInformation policy : policies) {
1979+
policyIds.add(policy.getPolicyIdentifier().getId());
1980+
}
1981+
return policyIds;
1982+
}
1983+
}
1984+
}
1985+
1986+
/**
1987+
* {@inheritDoc}
1988+
*/
1989+
@Override
1990+
public List<IQCStatement> parseQcStatement(byte[] qcStatementsExtensionValue) throws IOException {
1991+
List<IQCStatement> qcStatements = new ArrayList<>();
1992+
if (qcStatementsExtensionValue != null) {
1993+
ASN1OctetString octs;
1994+
try (ASN1InputStream aIn = new ASN1InputStream(qcStatementsExtensionValue)) {
1995+
octs = (ASN1OctetString) aIn.readObject();
1996+
}
1997+
ASN1Primitive primitive;
1998+
try (ASN1InputStream aIn = new ASN1InputStream(octs.getOctets())) {
1999+
primitive = aIn.readObject();
2000+
}
2001+
ASN1Sequence qcStatementsSequence = ASN1Sequence.getInstance(primitive);
2002+
for (ASN1Encodable qcStatementEncodable : qcStatementsSequence) {
2003+
QCStatement qcStatement = QCStatement.getInstance(qcStatementEncodable);
2004+
qcStatements.add(new QCStatementBCFips(qcStatement));
2005+
}
2006+
}
2007+
return qcStatements;
2008+
}
19542009
}

0 commit comments

Comments
 (0)