Skip to content

Allow multiple Certificates with the same SubjectDN in the store #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public boolean isName(final Name name) {
public boolean matches(final X509Object other) {
if (other instanceof Certificate) {
final Certificate that = (Certificate) other;
return X509AuxCertificate.equalSubjects(this.x509, that.x509);
if (X509AuxCertificate.equalSubjects(this.x509, that.x509)) {
return this.x509.hashCode() == that.x509.hashCode();
};
}
return false;
}
Expand Down
22 changes: 20 additions & 2 deletions src/main/java/org/jruby/ext/openssl/x509store/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.List;

import javax.net.ssl.X509TrustManager;
import javax.security.auth.x500.X500Principal;

import org.jruby.Ruby;
import org.jruby.ext.openssl.OpenSSL;
Expand Down Expand Up @@ -329,8 +330,25 @@ private synchronized int addObject(final X509Object xObject, final int prevLengt
return 0;
}
}
X509Object[] newObjects = Arrays.copyOf(objects, length + 1);
newObjects[ length ] = xObject;
X509Object[] newObjects = new X509Object[length + 1];

int idx = length;
if (xObject instanceof Certificate) {
final X500Principal p1 = ((Certificate) xObject).x509.getIssuerX500Principal();
final Name n1 = new Name(p1);

for (idx = 0; idx < objects.length; idx++) {
X509Object xMember = objects[idx];
if (xMember instanceof Certificate) {
X500Principal p2 = ((Certificate) xMember).x509.getIssuerX500Principal();
if(n1.equalTo(p2)) break;
}
}
}

System.arraycopy(objects, 0, newObjects, 0, idx);
System.arraycopy(objects, idx, newObjects, idx + 1, length-idx);
newObjects[idx] = xObject;
objects = newObjects;
return 1;
}
Expand Down