Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 970877c

Browse files
committed
Removed some unnecessary imports. Fixed bugs in tests where Java path handlers don't properly deal with platform differences (e.g. /C:/ path). Fixed bugs in certificate and other generators because bouncy castle doesn't properly handle whitespace per RFC7468. Fixed typos in comments. Set default signature algorithm to SHA256.
1 parent 321873b commit 970877c

7 files changed

Lines changed: 30 additions & 16 deletions

File tree

src/main/java/com/venafi/vcert/sdk/Config.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99

1010
import java.io.IOException;
1111
import java.nio.file.Path;
12-
import java.util.Arrays;
1312
import java.util.List;
1413
import java.util.Objects;
15-
import java.util.Set;
1614

1715
import static java.util.Arrays.asList;
1816

src/main/java/com/venafi/vcert/sdk/connectors/ServerPolicy.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public Policy toPolicy() {
145145
public ZoneConfiguration toZoneConfig() {
146146
return new ZoneConfiguration()
147147
.customAttributeValues(new HashMap<>())
148+
.hashAlgorithm(SignatureAlgorithm.SHA256WithRSA)
148149
.country(subject.country().value())
149150
.organization(subject.organization().value())
150151
.organizationalUnit(subject.organizationalUnit().values())

src/main/java/com/venafi/vcert/sdk/connectors/tpp/ZoneConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class ZoneConfiguration {
3333

3434

3535
/**
36-
* UpdateCertificateRequest updates a certificate request based on the zone configurataion retrieved from the remote endpoint
36+
* UpdateCertificateRequest updates a certificate request based on the zone configuration retrieved from the remote endpoint
3737
* @return
3838
*/
3939
public void updateCertificateRequest(CertificateRequest request) {

src/test/java/com/venafi/vcert/sdk/TestUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public static byte[] getCertificateAsBytes(X509Certificate certificate) throws I
7070
outputStream.write("-----BEGIN CERTIFICATE-----".getBytes());
7171
outputStream.write(System.lineSeparator().getBytes());
7272
outputStream.write(Base64.getEncoder().encode(certificate.getEncoded()));
73+
outputStream.write(System.lineSeparator().getBytes());
7374
outputStream.write("-----END CERTIFICATE-----".getBytes());
7475
return outputStream.toByteArray();
7576
}

src/test/java/com/venafi/vcert/sdk/certificate/CertificateRequestTest.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@
22

33
import com.venafi.vcert.sdk.SignatureAlgorithm;
44
import com.venafi.vcert.sdk.VCertException;
5-
import org.bouncycastle.jce.provider.BouncyCastleProvider;
6-
import org.bouncycastle.openssl.PEMParser;
7-
import org.bouncycastle.pkcs.PKCS10CertificationRequest;
8-
import org.junit.jupiter.api.Test;
95

10-
import java.io.IOException;
11-
import java.io.StringReader;
126
import java.net.*;
137
import java.security.KeyPair;
148
import java.security.Security;
@@ -29,7 +23,6 @@
2923
import java.io.ByteArrayOutputStream;
3024
import java.io.IOException;
3125
import java.io.StringReader;
32-
import java.net.*;
3326
import java.nio.file.Files;
3427
import java.nio.file.Paths;
3528
import java.security.*;
@@ -175,13 +168,19 @@ private static CertificateRequest createCertSigningRequestFor(PKCS10Certificatio
175168
outputStream.write("-----BEGIN CERTIFICATE REQUEST-----".getBytes());
176169
outputStream.write(System.lineSeparator().getBytes());
177170
outputStream.write(Base64.getEncoder().encode(certSigningReq.getEncoded()));
171+
outputStream.write(System.lineSeparator().getBytes());
178172
outputStream.write("-----END CERTIFICATE REQUEST-----".getBytes());
179173
return new CertificateRequest().csr(outputStream.toByteArray());
180174
}
181175

182176
private static KeyPair loadKeyPairFromFile(String name) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
183177
ClassLoader classLoader = CertificateRequestTest.class.getClassLoader();
184-
String body = new String(Files.readAllBytes(Paths.get(classLoader.getResource("certificates/" + name).getPath())));
178+
String path = classLoader.getResource("certificates/" + name).getPath();
179+
// windows platform: if it starts with /C: then remove the leading slash
180+
if (path.charAt(0) == '/' && path.charAt(2) == ':') {
181+
path = path.substring(1);
182+
}
183+
String body = new String(Files.readAllBytes( Paths.get(path).toAbsolutePath() ));
185184
PEMParser pemParser = new PEMParser(new StringReader(body));
186185
JcaPEMKeyConverter keyConverter = new JcaPEMKeyConverter();
187186
Object object = pemParser.readObject();
@@ -195,7 +194,12 @@ private static KeyPair loadKeyPairFromFile(String name) throws IOException, NoSu
195194

196195
private static Certificate loadCertificateFromFile(String name) throws IOException, CertificateException {
197196
ClassLoader classLoader = CertificateRequestTest.class.getClassLoader();
198-
String body = new String(Files.readAllBytes(Paths.get(classLoader.getResource("certificates/" + name).getPath())));
197+
String path = classLoader.getResource("certificates/" + name).getPath();
198+
// windows platform: if it starts with /C: then remove the leading slash
199+
if (path.charAt(0) == '/' && path.charAt(2) == ':') {
200+
path = path.substring(1);
201+
}
202+
String body = new String(Files.readAllBytes( Paths.get(path).toAbsolutePath() ));
199203
PEMParser pemParser = new PEMParser(new StringReader(body));
200204
JcaX509CertificateConverter certificateConverter = new JcaX509CertificateConverter();
201205
Object object = pemParser.readObject();
@@ -204,7 +208,12 @@ private static Certificate loadCertificateFromFile(String name) throws IOExcepti
204208

205209
private static PKCS10CertificationRequest loadCertificateSigningRequestFromFile(String name) throws IOException {
206210
ClassLoader classLoader = CertificateRequestTest.class.getClassLoader();
207-
String body = new String(Files.readAllBytes(Paths.get(classLoader.getResource("certificates/" + name).getPath())));
211+
String path = classLoader.getResource("certificates/" + name).getPath();
212+
// windows platform: if it starts with /C: then remove the leading slash
213+
if (path.charAt(0) == '/' && path.charAt(2) == ':') {
214+
path = path.substring(1);
215+
}
216+
String body = new String(Files.readAllBytes( Paths.get(path).toAbsolutePath() ));
208217
StringReader reader = new StringReader(body);
209218
try(PEMParser pemParser = new PEMParser(reader)) {
210219
return (PKCS10CertificationRequest) pemParser.readObject();

src/test/java/com/venafi/vcert/sdk/certificate/PEMCollectionTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ class PEMCollectionTest {
1414
@Test
1515
void fromResponse() throws VCertException, IOException {
1616
ClassLoader classLoader = getClass().getClassLoader();
17-
String body = new String(Files.readAllBytes(Paths.get(classLoader.getResource("certificates/certWithKey.pem").getPath())));
17+
String path = classLoader.getResource("certificates/certWithKey.pem").getPath();
18+
// windows platform: if it starts with /C: then remove the leading slash
19+
if (path.charAt(0) == '/' && path.charAt(2) == ':') {
20+
path = path.substring(1);
21+
}
22+
String body = new String(Files.readAllBytes( Paths.get(path).toAbsolutePath() ));
1823
PEMCollection pemCollection = PEMCollection.fromResponse(body, ChainOption.ChainOptionIgnore);
1924
assertThat(pemCollection.certificate()).isNotNull();
2025
assertThat(pemCollection.chain()).hasSize(0);

src/test/java/com/venafi/vcert/sdk/connectors/tpp/TppConnectorIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import org.junit.jupiter.api.Test;
1111
import org.junit.jupiter.api.extension.ExtendWith;
1212

13-
import static com.venafi.vcert.sdk.SignatureAlgorithm.MD2withRSA;
13+
import static com.venafi.vcert.sdk.SignatureAlgorithm.*;
1414
import static com.venafi.vcert.sdk.certificate.EllipticCurve.*;
1515
import static com.venafi.vcert.sdk.certificate.KeyType.ECDSA;
1616
import static com.venafi.vcert.sdk.certificate.KeyType.RSA;
@@ -80,7 +80,7 @@ void readZoneConfiguration() throws VCertException {
8080
assertThat(zoneConfiguration.policy().upnSanRegExs()).containsExactly(".*");
8181
assertThat(zoneConfiguration.policy().allowWildcards()).isTrue();
8282
assertThat(zoneConfiguration.policy().allowKeyReuse()).isFalse();
83-
assertThat(zoneConfiguration.hashAlgorithm()).isEqualTo(MD2withRSA);
83+
assertThat(zoneConfiguration.hashAlgorithm()).isEqualTo(SHA256WithRSA);
8484
assertThat(zoneConfiguration.customAttributeValues()).isNotNull();
8585
assertThat(zoneConfiguration.customAttributeValues()).isEmpty();
8686
}

0 commit comments

Comments
 (0)