powered by Jive Software

RFE: upgrade socket to STARTTLS with custom SSLSocketFactory as alternative


In some use cases I have a custom SSLSocketFactory instead of an SSLContext. This RFE is for the purpose of upgrading to STARTTLS using a custom SSLSocketFactory as an alternative to the (current) SSLContext.

The only time we use getCustomSSLContext() is to get the context to get the factory, therefore it is useful if we could inject the factory directly.

More detailed use case: with smartcards it is easier to create a SSLSocketFactory than a custom SSLContext.

Proposed API


public B setCustomSSLSocketFactory(SSLSocketFactory factory) {
this.customSSLSocketFactory = Objects.requireNonNull(factory, “The SSLSocketFactory must not be null”);
return getThis();
etc etc


private void proceedTLSReceived() {

SSL factory = this.config.getCustomSSLSocketFactory();
if (factory == null) {
// then set the SSLContext context var

Socket plain = socket;
// Secure the plain connection
if (factory != null) {
socket = factory.createSocket(plain,
config.getXMPPServiceDomain().toString(), plain.getPort(), true);
else {
socket = context.getSocketFactory().createSocket(plain,
config.getXMPPServiceDomain().toString(), plain.getPort(), true);

Happy to do a PR if you think this RFE is workable.