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

Conversation

cconlon
Copy link
Member

@cconlon cconlon commented Jun 7, 2024

This PR adjusts SSLSession.getPeerCertificates() to return an array of typeX509Certificate rather than Certificate. Previously wolfJSSE created individual array elements as java.security.cert.X509Certificate objects, but returned them as a java.security.cert.Certificate[] to conform to the Javadoc specification for SSLSession.getPeerCertificates():

Certificate[] getPeerCertificates() throws SSLPeerUnverifiedException

Some callers of this API (for example Postgres) tries to cast this return back to an array of X509Certificate[], such as:

SSLSession session;
X509Certificate[] peerCerts;
...
peerCerts = (X509Certificate[]) session.getPeerCertificates();

This cast will throw an Exception similar to:

java.lang.ClassCastException: class [Ljava.security.cert.Certificate; cannot be cast to class [Ljava.security.cert.X509Certificate;

This PR adjusts WolfSSLImplementSSLSession.getPeerCertificates() to return a X509Certificate[] from the body of the method, to match SunJSSE behavior. Since X509Certificate is a subclass of Certificate, this should not break calling applications. Method signature is left intact as returning a Certificate[], so we still conform to SSLSession definition in general.

@cconlon cconlon force-pushed the sslSessionGetPeerCertificates branch from a2d4255 to 7486579 Compare June 7, 2024 18:24
@JacobBarthelmeh JacobBarthelmeh merged commit bb12cc9 into wolfSSL:master Jun 7, 2024
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants