Merge pull request #204 from jackctj117/fix-getLocalPrincipal

Changed getLocalPrincipal to assume user cert is first in chain
pull/201/head
Chris Conlon 2024-06-17 11:56:44 -06:00 committed by GitHub
commit 910b6124f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 9 deletions

View File

@ -647,7 +647,7 @@ public class WolfSSLImplementSSLSession extends ExtendedSSLSession
@Override @Override
public Principal getLocalPrincipal() { public Principal getLocalPrincipal() {
/* Logic needs to be added to check for client auth when wrapper is made TODO */
X509KeyManager km = authStore.getX509KeyManager(); X509KeyManager km = authStore.getX509KeyManager();
java.security.cert.X509Certificate[] certs = java.security.cert.X509Certificate[] certs =
km.getCertificateChain(authStore.getCertAlias()); km.getCertificateChain(authStore.getCertAlias());
@ -657,12 +657,9 @@ public class WolfSSLImplementSSLSession extends ExtendedSSLSession
return null; return null;
} }
for (int i = 0; i < certs.length; i++) { if (certs.length > 0){
if (certs[i].getBasicConstraints() < 0) { /* When chain of certificates exceeds one, the user certifcate is the first */
/* is not a CA treat as end of chain */ localPrincipal = certs[0].getSubjectDN();
localPrincipal = certs[i].getSubjectDN();
break;
}
} }
/* free native resources earlier than garbage collection if /* free native resources earlier than garbage collection if

View File

@ -120,9 +120,10 @@ public class WolfSSLSessionTest {
/* test certificates */ /* test certificates */
System.out.print("\tTesting session cert"); System.out.print("\tTesting session cert");
session = client.getSession(); session = client.getSession();
if (session.getLocalPrincipal() != null) { /* TODO changes back to != null once we can check for client auth */
if (session.getLocalPrincipal() == null) {
error("\t... failed"); error("\t... failed");
fail("found unexpected principal"); fail("Principal is null when it should not be");
} }
try { try {