private synchronized SSLContext ctx() {
        if (ctx == null) {
            TrustManagerFactory tmf;
            KeyManagerFactory kmf;
            try {
                ctx = SSLContext.getInstance("TLS");
                tmf = TrustManagerFactory.getInstance("PKIX");
                kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
                KeyManager[] kms = null;
                tmf.init(trusted);
                if (creds != null) {
                    kmf.init(creds, pw);
                    kms = kmf.getKeyManagers();
                }
                ctx.init(kms, tmf.getTrustManagers(), new SecureRandom());
            } catch (NoSuchAlgorithmException e) {
                throw (new Error(e));
            } catch (KeyStoreException e) {
                throw (new RuntimeException(e));
            } catch (UnrecoverableKeyException e) {
        /* The key should be recoverable at this stage, since
         * it was loaded successfully. */
                throw (new RuntimeException(e));
            } catch (KeyManagementException e) {
                throw (new RuntimeException(e));
            }
        }
        return (ctx);
    }