Topic: WolfSSL JSSE PSK - propagate TLS Identity Hint to HTTP
I am trying to use WolfSSL JSSE Provider in a Vert.x application.
Part of the requirement is to be able to propagate the PSK Identity Hint from the Client TLS negotiation to the HTTP layer
The approach I have taken is:
- Implemented a custom WolfSSLPskServerCallback handler class
- This class adds the hint to a ThreadLocal like:
@Override
public long pskServerCallback(WolfSSLSession ssl, String identity, byte[] key, long keyMaxLen) {
....
PSKThreadLocal.setPskIdentityHint(identity);
}- Modified the engineInit method of the com.wolfssl.provider.jsse.WolfSSLContext class to set the handler dynamically:
@Override
protected void engineInit(KeyManager[] km, TrustManager[] tm,SecureRandom sr) throws KeyManagementException {
....
Class<?> targetClass = Class.forName(className);
Constructor<?> constructor = targetClass.getDeclaredConstructor();
Object instance = constructor.newInstance();
if (instance instanceof WolfSSLPskServerCallback) {
ctx.setPskServerCb((WolfSSLPskServerCallback)instance);
}- Modified the updateStoredSessionValues() method of the com.wolfssl.provider.jsse.WolfSSLImplementSSLSession to add the hint to bindings
protected synchronized void updateStoredSessionValues() {
...
if(PSKThreadLocal.getPskIdentityHint()!=null) {
binding.put("psk.identity", PSKThreadLocal.getPskIdentityHint());
}This works in a simple openssl cmd line tests, but I am not sure if this approach works in a multi-threaded concurrent situation. So my questions are:
- Do we need to modify the WolfSSLContext in order to register a custom callback
- IS there a better approach to get the Identity hint in the SSL session without using this ThreadLocal approach