Skip to content

Commit a6e77ae

Browse files
committed
Correct certificate comparisons
DEVSIX-8629
1 parent 1156fe6 commit a6e77ae

File tree

45 files changed

+1815
-381
lines changed

Some content is hidden

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

45 files changed

+1815
-381
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
@@ -1586,6 +1586,15 @@ public IX500Name createX500Name(String s) {
15861586
return new X500NameBC(new X500Name(s));
15871587
}
15881588

1589+
/**
1590+
* {@inheritDoc}
1591+
*/
1592+
@Override
1593+
public IX500Name createX500Name(IASN1Sequence s) {
1594+
return new X500NameBC(X500Name.getInstance(((ASN1SequenceBC) s).getASN1Sequence()));
1595+
}
1596+
1597+
15891598
/**
15901599
* {@inheritDoc}
15911600
*/

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ This file is part of the iText (R) project.
2525
import com.itextpdf.bouncycastle.asn1.ASN1EncodableBC;
2626
import com.itextpdf.commons.bouncycastle.asn1.x500.IX500Name;
2727

28+
import java.io.IOException;
29+
import javax.security.auth.x500.X500Principal;
2830
import org.bouncycastle.asn1.x500.X500Name;
2931

3032
/**
@@ -48,4 +50,16 @@ public X500NameBC(X500Name x500Name) {
4850
public X500Name getX500Name() {
4951
return (X500Name) getEncodable();
5052
}
53+
54+
55+
// expected format CN=iTextTestOcspResponder,O=iText,C=BY
56+
@Override
57+
public String getName(){
58+
try {
59+
return new X500Principal(getX500Name().getEncoded()).getName();
60+
} catch (IOException e) {
61+
// should never happen
62+
throw new RuntimeException(e);
63+
}
64+
}
5165
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ This file is part of the iText (R) project.
3030
import com.itextpdf.commons.bouncycastle.asn1.IASN1ObjectIdentifier;
3131
import com.itextpdf.commons.bouncycastle.cert.IX509CertificateHolder;
3232
import com.itextpdf.commons.bouncycastle.cert.ocsp.IBasicOCSPResp;
33+
import com.itextpdf.commons.bouncycastle.cert.ocsp.IRespID;
3334
import com.itextpdf.commons.bouncycastle.cert.ocsp.ISingleResp;
3435
import com.itextpdf.commons.bouncycastle.operator.IContentVerifierProvider;
3536

@@ -135,6 +136,14 @@ public IASN1Encodable getExtensionParsedValue(IASN1ObjectIdentifier objectIdenti
135136
return new ASN1EncodableBC(extension == null ? null : extension.getParsedValue());
136137
}
137138

139+
/**
140+
* {@inheritDoc}
141+
*/
142+
@Override
143+
public IRespID getResponderId() {
144+
return new RespIDBC(basicOCSPResp.getResponderId());
145+
}
146+
138147
/**
139148
* Indicates whether some other object is "equal to" this one. Compares wrapped objects.
140149
*/

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ This file is part of the iText (R) project.
2525
import com.itextpdf.bouncycastle.asn1.x500.X500NameBC;
2626
import com.itextpdf.commons.bouncycastle.asn1.x500.IX500Name;
2727
import com.itextpdf.commons.bouncycastle.cert.ocsp.IRespID;
28+
import com.itextpdf.commons.bouncycastle.cert.ocsp.IResponderID;
2829

2930
import java.util.Objects;
3031
import org.bouncycastle.cert.ocsp.RespID;
@@ -62,6 +63,15 @@ public RespID getRespID() {
6263
return respID;
6364
}
6465

66+
/**
67+
* {@inheritDoc}
68+
*/
69+
@Override
70+
public IResponderID toASN1Primitive() {
71+
return new ResponderIDBC(respID.toASN1Primitive());
72+
}
73+
74+
6575
/**
6676
* Indicates whether some other object is "equal to" this one. Compares wrapped objects.
6777
*/
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2024 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.cert.ocsp;
24+
25+
import com.itextpdf.bouncycastle.asn1.x500.X500NameBC;
26+
import com.itextpdf.commons.bouncycastle.asn1.x500.IX500Name;
27+
import com.itextpdf.commons.bouncycastle.cert.ocsp.IResponderID;
28+
29+
import org.bouncycastle.asn1.ocsp.ResponderID;
30+
31+
public class ResponderIDBC implements IResponderID {
32+
private final ResponderID responderID;
33+
34+
/**
35+
* Creates new wrapper instance for {@link ResponderID}.
36+
*
37+
* @param responderID {@link ResponderID} to be wrapped
38+
*/
39+
public ResponderIDBC(ResponderID responderID) {
40+
this.responderID = responderID;
41+
}
42+
43+
/**
44+
* {@inheritDoc}
45+
*/
46+
@Override
47+
public IX500Name getName() {
48+
return new X500NameBC(responderID.getName());
49+
}
50+
51+
/**
52+
* Gets actual org.bouncycastle object being wrapped.
53+
*
54+
* @return wrapped {@link ResponderID}.
55+
*/
56+
public ResponderID getResponderID() {
57+
return responderID;
58+
}
59+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,11 @@ public IX500Name createX500Name(String s) {
832832
throw new UnsupportedOperationException(BouncyCastleLogMessageConstant.BOUNCY_CASTLE_DEPENDENCY_MUST_PRESENT);
833833
}
834834

835+
@Override
836+
public IX500Name createX500Name(IASN1Sequence s) {
837+
throw new UnsupportedOperationException(BouncyCastleLogMessageConstant.BOUNCY_CASTLE_DEPENDENCY_MUST_PRESENT);
838+
}
839+
835840
@Override
836841
public IRespID createRespID(IX500Name x500Name) {
837842
throw new UnsupportedOperationException(BouncyCastleLogMessageConstant.BOUNCY_CASTLE_DEPENDENCY_MUST_PRESENT);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,15 @@ public IX500Name createX500Name(String s) {
15911591
return new X500NameBCFips(new X500Name(s));
15921592
}
15931593

1594+
/**
1595+
* {@inheritDoc}
1596+
*/
1597+
@Override
1598+
public IX500Name createX500Name(IASN1Sequence s) {
1599+
return new X500NameBCFips(X500Name.getInstance(((ASN1SequenceBCFips) s).getASN1Sequence()));
1600+
1601+
}
1602+
15941603
/**
15951604
* {@inheritDoc}
15961605
*/

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ This file is part of the iText (R) project.
2525
import com.itextpdf.bouncycastlefips.asn1.ASN1EncodableBCFips;
2626
import com.itextpdf.commons.bouncycastle.asn1.x500.IX500Name;
2727

28+
import java.io.IOException;
29+
import javax.security.auth.x500.X500Principal;
2830
import org.bouncycastle.asn1.x500.X500Name;
2931

3032
/**
@@ -48,4 +50,14 @@ public X500NameBCFips(X500Name x500Name) {
4850
public X500Name getX500Name() {
4951
return (X500Name) getEncodable();
5052
}
53+
54+
@Override
55+
public String getName(){
56+
try {
57+
return new X500Principal(getX500Name().getEncoded()).getName();
58+
} catch (IOException e) {
59+
// should never happen
60+
throw new RuntimeException(e);
61+
}
62+
}
5163
}

bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/cert/ocsp/BasicOCSPRespBCFips.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ This file is part of the iText (R) project.
3030
import com.itextpdf.commons.bouncycastle.asn1.IASN1ObjectIdentifier;
3131
import com.itextpdf.commons.bouncycastle.cert.IX509CertificateHolder;
3232
import com.itextpdf.commons.bouncycastle.cert.ocsp.IBasicOCSPResp;
33+
import com.itextpdf.commons.bouncycastle.cert.ocsp.IRespID;
3334
import com.itextpdf.commons.bouncycastle.cert.ocsp.ISingleResp;
3435
import com.itextpdf.commons.bouncycastle.operator.IContentVerifierProvider;
3536

3637
import java.io.IOException;
3738
import java.util.Date;
3839
import java.util.Objects;
39-
4040
import org.bouncycastle.asn1.x509.Extension;
4141
import org.bouncycastle.cert.X509CertificateHolder;
4242
import org.bouncycastle.cert.ocsp.BasicOCSPResp;
@@ -134,6 +134,14 @@ public IASN1Encodable getExtensionParsedValue(IASN1ObjectIdentifier objectIdenti
134134
return new ASN1EncodableBCFips(extension == null ? null : extension.getParsedValue());
135135
}
136136

137+
/**
138+
* {@inheritDoc}
139+
*/
140+
@Override
141+
public IRespID getResponderId() {
142+
return new RespIDBCFips(basicOCSPResp.getResponderId());
143+
}
144+
137145
/**
138146
* Indicates whether some other object is "equal to" this one. Compares wrapped objects.
139147
*/

bouncy-castle-fips-adapter/src/main/java/com/itextpdf/bouncycastlefips/cert/ocsp/RespIDBCFips.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ This file is part of the iText (R) project.
2525
import com.itextpdf.bouncycastlefips.asn1.x500.X500NameBCFips;
2626
import com.itextpdf.commons.bouncycastle.asn1.x500.IX500Name;
2727
import com.itextpdf.commons.bouncycastle.cert.ocsp.IRespID;
28+
import com.itextpdf.commons.bouncycastle.cert.ocsp.IResponderID;
2829

2930
import java.util.Objects;
3031
import org.bouncycastle.cert.ocsp.RespID;
@@ -53,6 +54,14 @@ public RespIDBCFips(IX500Name x500Name) {
5354
this(new RespID(((X500NameBCFips) x500Name).getX500Name()));
5455
}
5556

57+
/**
58+
* {@inheritDoc}
59+
*/
60+
@Override
61+
public IResponderID toASN1Primitive() {
62+
return new ResponderIDBCFips(respID.toASN1Primitive());
63+
}
64+
5665
/**
5766
* Gets actual org.bouncycastle object being wrapped.
5867
*
@@ -92,4 +101,5 @@ public int hashCode() {
92101
public String toString() {
93102
return respID.toString();
94103
}
104+
95105
}

0 commit comments

Comments
 (0)