Skip to content
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

Return X509Certificate[] from SSLSession.getPeerCertificates() #199

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 @@ -75,7 +75,7 @@ public class WolfSSLImplementSSLSession extends ExtendedSSLSession
* SSLSocket.getSession().getPeerCertificates() will return the peer
* certificate even on a resumed connection where the cert has not been
* sent during the handshake. */
private Certificate[] peerCerts = null;
private X509Certificate[] peerCerts = null;

/**
* Is this object currently inside the WolfSSLAuthStore session cache table?
Expand Down Expand Up @@ -456,7 +456,8 @@ public String[] getValueNames() {
* ssl.getPeerCertificate() fails, then we return the cached cert if
* we have it.
*
* @return Certificate array of peer certs for session
* @return Certificate array of peer certs for session. Actual subclass
* type returned is X509Certificate[] to match SunJSSE behavior
*
* @throws SSLPeerUnverifiedException if handshake is not complete,
* or error getting certificates
Expand Down Expand Up @@ -546,7 +547,7 @@ public synchronized Certificate[] getPeerCertificates()
cert.free();

/* cache peer cert for use by app in resumed session */
this.peerCerts = new Certificate[] { exportCert };
this.peerCerts = new X509Certificate[] { exportCert };

return this.peerCerts.clone();
}
Expand Down
13 changes: 13 additions & 0 deletions src/test/com/wolfssl/provider/jsse/test/WolfSSLSessionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.junit.Assert.fail;

import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.security.NoSuchProviderException;
import java.security.Principal;
import java.security.Provider;
Expand Down Expand Up @@ -276,6 +277,18 @@ public void testBinding() {
error("\t\t... failed");
fail("unexpected cert type found");
}

/* Check that Certificate[] returned from getPeerCertificates()
* is actually of subclass type X509Certificate[]. If not and
* we try to cast back to it, we should get a
* ClassCastException */
try {
X509Certificate[] xCerts = (X509Certificate[])certs;
} catch (ClassCastException e) {
error("\t\t... failed");
fail("getPeerCertificates() did not return array of type " +
"X509Certificate[]");
}
}
} catch (SSLPeerUnverifiedException e) {
error("\t\t... failed");
Expand Down