Skip to content

Commit 4d9fd5e

Browse files
authored
Merge pull request #198 from d-velopds/allow-multiple-certs-with-same-subject
Allow multiple Certificates with the same SubjectDN in the store
2 parents a9e6a03 + a239652 commit 4d9fd5e

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/main/java/org/jruby/ext/openssl/x509store/Certificate.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ public boolean isName(final Name name) {
5454
public boolean matches(final X509Object other) {
5555
if (other instanceof Certificate) {
5656
final Certificate that = (Certificate) other;
57-
return X509AuxCertificate.equalSubjects(this.x509, that.x509);
57+
if (X509AuxCertificate.equalSubjects(this.x509, that.x509)) {
58+
return this.x509.hashCode() == that.x509.hashCode();
59+
};
5860
}
5961
return false;
6062
}

src/main/java/org/jruby/ext/openssl/x509store/Store.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.util.List;
4040

4141
import javax.net.ssl.X509TrustManager;
42+
import javax.security.auth.x500.X500Principal;
4243

4344
import org.jruby.Ruby;
4445
import org.jruby.ext.openssl.OpenSSL;
@@ -329,8 +330,25 @@ private synchronized int addObject(final X509Object xObject, final int prevLengt
329330
return 0;
330331
}
331332
}
332-
X509Object[] newObjects = Arrays.copyOf(objects, length + 1);
333-
newObjects[ length ] = xObject;
333+
X509Object[] newObjects = new X509Object[length + 1];
334+
335+
int idx = length;
336+
if (xObject instanceof Certificate) {
337+
final X500Principal p1 = ((Certificate) xObject).x509.getIssuerX500Principal();
338+
final Name n1 = new Name(p1);
339+
340+
for (idx = 0; idx < objects.length; idx++) {
341+
X509Object xMember = objects[idx];
342+
if (xMember instanceof Certificate) {
343+
X500Principal p2 = ((Certificate) xMember).x509.getIssuerX500Principal();
344+
if(n1.equalTo(p2)) break;
345+
}
346+
}
347+
}
348+
349+
System.arraycopy(objects, 0, newObjects, 0, idx);
350+
System.arraycopy(objects, idx, newObjects, idx + 1, length-idx);
351+
newObjects[idx] = xObject;
334352
objects = newObjects;
335353
return 1;
336354
}

0 commit comments

Comments
 (0)