public KeyStore getKeyStore(){ SchemeRegistry registry = httpClient4.getConnectionManager().getSchemeRegistry(); if(! registry.getSchemeNames().contains("https")){ throw new IllegalStateException("Registry does not include an 'https' entry."); } SchemeSocketFactory awareSocketFactory = httpClient4.getConnectionManager().getSchemeRegistry().getScheme("https").getSchemeSocketFactory(); if(awareSocketFactory instanceof KeyStoreAwareSocketFactory){ return ((KeyStoreAwareSocketFactory) awareSocketFactory).getKeyStore(); }else{ throw new IllegalStateException("Cannot extract keystore from scheme socket factory of type: " + awareSocketFactory.getClass().getName()); } }