Do not set two CNs

pull/147/head
Richard Körber 2023-11-24 11:38:29 +01:00
parent 50a74251e0
commit 67a90df47f
No known key found for this signature in database
GPG Key ID: AAB9FD19C78AA3E0
2 changed files with 7 additions and 2 deletions

View File

@ -64,6 +64,7 @@ public class CSRBuilder {
private final List<String> namelist = new ArrayList<>();
private final List<InetAddress> iplist = new ArrayList<>();
private @Nullable PKCS10CertificationRequest csr = null;
private boolean hasCnSet = false;
/**
* Adds a domain name to the CSR. All domain names will be added as <em>Subject
@ -212,6 +213,10 @@ public class CSRBuilder {
public void addValue(ASN1ObjectIdentifier oid, String value) {
if (requireNonNull(oid, "OID must not be null").equals(BCStyle.CN)) {
addDomain(value);
if (hasCnSet) {
return;
}
hasCnSet = true;
}
namebuilder.addRDN(oid, requireNonNull(value, "attribute value must not be null"));
}

View File

@ -189,7 +189,7 @@ public class CSRBuilderTest {
builder.addValue("CN", "firstcn.example.com");
assertThat(builder.toString()).isEqualTo("C=DE,E=contact@example.com,CN=firstcn.example.com,DNS=firstcn.example.com");
builder.addValue("CN", "scnd.example.com");
assertThat(builder.toString()).isEqualTo("C=DE,E=contact@example.com,CN=firstcn.example.com,CN=scnd.example.com,DNS=firstcn.example.com,DNS=scnd.example.com");
assertThat(builder.toString()).isEqualTo("C=DE,E=contact@example.com,CN=firstcn.example.com,DNS=firstcn.example.com,DNS=scnd.example.com");
builder = new CSRBuilder();
builder.addValue(BCStyle.C, "DE");
@ -199,7 +199,7 @@ public class CSRBuilderTest {
builder.addValue(BCStyle.CN, "firstcn.example.com");
assertThat(builder.toString()).isEqualTo("C=DE,E=contact@example.com,CN=firstcn.example.com,DNS=firstcn.example.com");
builder.addValue(BCStyle.CN, "scnd.example.com");
assertThat(builder.toString()).isEqualTo("C=DE,E=contact@example.com,CN=firstcn.example.com,CN=scnd.example.com,DNS=firstcn.example.com,DNS=scnd.example.com");
assertThat(builder.toString()).isEqualTo("C=DE,E=contact@example.com,CN=firstcn.example.com,DNS=firstcn.example.com,DNS=scnd.example.com");
}
private CSRBuilder createBuilderWithValues() throws UnknownHostException {