Skip to content

Commit 244cfd2

Browse files
committed
Introduce separate class for two-step signing
DEVSIX-7972
1 parent c9bfbdc commit 244cfd2

File tree

41 files changed

+826
-505
lines changed

Some content is hidden

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

41 files changed

+826
-505
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,15 @@ public ITBSCertificate createTBSCertificate(IASN1Encodable encodable) {
12981298
return new TBSCertificateBC(TBSCertificate.getInstance(((ASN1EncodableBC) encodable).getEncodable()));
12991299
}
13001300

1301+
/**
1302+
* {@inheritDoc}
1303+
*/
1304+
@Override
1305+
public ITBSCertificate createTBSCertificate(byte[] bytes) {
1306+
return new TBSCertificateBC(TBSCertificate.getInstance((bytes)));
1307+
}
1308+
1309+
13011310
/**
13021311
* {@inheritDoc}
13031312
*/

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,37 @@ public void add(IAlgorithmIdentifier element) {
9090
encodableVector.add(elementBc.getAlgorithmIdentifier());
9191
}
9292

93+
/**
94+
* {@inheritDoc}
95+
*/
96+
@Override
97+
public void addOptional(IASN1Primitive primitive) {
98+
if (primitive != null) {
99+
add(primitive);
100+
}
101+
}
102+
103+
/**
104+
* {@inheritDoc}
105+
*/
106+
@Override
107+
public void addOptional(IAttribute attribute) {
108+
if (attribute != null) {
109+
add(attribute);
110+
}
111+
}
112+
113+
114+
/**
115+
* {@inheritDoc}
116+
*/
117+
@Override
118+
public void addOptional(IAlgorithmIdentifier element) {
119+
if (element != null) {
120+
add(element);
121+
}
122+
}
123+
93124
/**
94125
* Indicates whether some other object is "equal to" this one. Compares wrapped objects.
95126
*/

bouncy-castle-adapter/src/main/java/com/itextpdf/bouncycastle/asn1/x509/AlgorithmIdentifierBC.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public IASN1ObjectIdentifier getAlgorithm() {
6565
*/
6666
@Override
6767
public IASN1Encodable getParameters() {
68+
if (getAlgorithmIdentifier().getParameters() == null) {
69+
return null;
70+
}
6871
return new ASN1EncodableBC(getAlgorithmIdentifier().getParameters());
6972
}
7073
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,10 @@ public ITBSCertificate createTBSCertificate(IASN1Encodable encodable) {
684684
throw new UnsupportedOperationException(BouncyCastleLogMessageConstant.BOUNCY_CASTLE_DEPENDENCY_MUST_PRESENT);
685685
}
686686

687+
@Override
688+
public ITBSCertificate createTBSCertificate(byte[] bytes) {
689+
throw new UnsupportedOperationException(BouncyCastleLogMessageConstant.BOUNCY_CASTLE_DEPENDENCY_MUST_PRESENT);
690+
}
687691
@Override
688692
public IIssuerAndSerialNumber createIssuerAndSerialNumber(IX500Name issuer, BigInteger value) {
689693
throw new UnsupportedOperationException(BouncyCastleLogMessageConstant.BOUNCY_CASTLE_DEPENDENCY_MUST_PRESENT);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,14 @@ public ITBSCertificate createTBSCertificate(IASN1Encodable encodable) {
13081308
return new TBSCertificateBCFips(TBSCertificate.getInstance(((ASN1EncodableBCFips) encodable).getEncodable()));
13091309
}
13101310

1311+
/**
1312+
* {@inheritDoc}
1313+
*/
1314+
@Override
1315+
public ITBSCertificate createTBSCertificate(byte[] bytes) {
1316+
return new TBSCertificateBCFips(TBSCertificate.getInstance((bytes)));
1317+
}
1318+
13111319
/**
13121320
* {@inheritDoc}
13131321
*/

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,36 @@ public void add(IAlgorithmIdentifier element) {
9090
encodableVector.add(elementBCFips.getAlgorithmIdentifier());
9191
}
9292

93+
/**
94+
* {@inheritDoc}
95+
*/
96+
@Override
97+
public void addOptional(IASN1Primitive primitive) {
98+
if (primitive != null) {
99+
add(primitive);
100+
}
101+
}
102+
103+
/**
104+
* {@inheritDoc}
105+
*/
106+
@Override
107+
public void addOptional(IAttribute attribute) {
108+
if (attribute != null) {
109+
add(attribute);
110+
}
111+
}
112+
113+
/**
114+
* {@inheritDoc}
115+
*/
116+
@Override
117+
public void addOptional(IAlgorithmIdentifier element) {
118+
if (element != null) {
119+
add(element);
120+
}
121+
}
122+
93123
/**
94124
* Indicates whether some other object is "equal to" this one. Compares wrapped objects.
95125
*/

bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/asn1/x509/AlgorithmIdentifierBCFips.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public IASN1ObjectIdentifier getAlgorithm() {
6565
*/
6666
@Override
6767
public IASN1Encodable getParameters() {
68+
if (getAlgorithmIdentifier().getParameters() == null) {
69+
return null;
70+
}
6871
return new ASN1EncodableBCFips(getAlgorithmIdentifier().getParameters());
6972
}
7073
}

commons/src/main/java/com/itextpdf/commons/bouncycastle/IBouncyCastleFactory.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,15 @@ IEncryptedContentInfo createEncryptedContentInfo(IASN1ObjectIdentifier data,
11011101
*/
11021102
ITBSCertificate createTBSCertificate(IASN1Encodable encodable);
11031103

1104+
/**
1105+
* Create TBS Certificate wrapper from ASN1 Encoded data.
1106+
*
1107+
* @param bytes ASN1 Encoded TBS Certificate
1108+
*
1109+
* @return created TBS Certificate wrapper
1110+
*/
1111+
ITBSCertificate createTBSCertificate(byte[] bytes);
1112+
11041113
/**
11051114
* Create issuer and serial number wrapper from X500 Name wrapper and {@link BigInteger}.
11061115
*

commons/src/main/java/com/itextpdf/commons/bouncycastle/asn1/IASN1EncodableVector.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,25 @@ public interface IASN1EncodableVector {
5050
* @param element AlgorithmIdentifier wrapper.
5151
*/
5252
void add(IAlgorithmIdentifier element);
53+
54+
/**
55+
* Calls actual {@code add} method for the wrapped ASN1EncodableVector object if the primitive is not null.
56+
*
57+
* @param primitive ASN1Primitive wrapper.
58+
*/
59+
void addOptional(IASN1Primitive primitive);
60+
61+
/**
62+
* Calls actual {@code add} method for the wrapped ASN1EncodableVector object if the attribute is not null.
63+
*
64+
* @param attribute Attribute wrapper.
65+
*/
66+
void addOptional(IAttribute attribute);
67+
68+
/**
69+
* Calls actual {@code add} method for the wrapped ASN1EncodableVector object if the element is not null.
70+
*
71+
* @param element AlgorithmIdentifier wrapper.
72+
*/
73+
void addOptional(IAlgorithmIdentifier element);
5374
}

sharpenConfiguration.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,9 @@
437437
</fileset>
438438
<!-- sign -->
439439
<file path="com/itextpdf/signatures/IExternalDigest.java"/>
440+
<fileset reason="IExternalDigest class exists only on Java.">
441+
<file path="com/itextpdf/signatures/PdfTwoPhaseSigner.java"/>
442+
</fileset>
440443
<file path="com/itextpdf/signatures/ProviderDigest.java"/>
441444
<fileset reason="ProviderDigest class exists only on Java.">
442445
<file path="com/itextpdf/signatures/ProviderDigestUnitTest.java"/>

0 commit comments

Comments
 (0)