protected Socket socketConnect() throws IOException { if (config.getCertPhrase() == null) { return new Socket(config.getHostname(service), config.getPort(service)); } else { return secureConnect(); } }
private Socket secureConnect() throws IOException { if (socket_factory == null) { try { SSLContext context = SSLContext.getInstance("TLS"); context.init(getKeyManagers(config.getCertFile(), config.getCertPhrase()), null, sec_rnd); socket_factory = context.getSocketFactory(); } catch (GeneralSecurityException security_exception) { throw new IOException("Failed to create SSL socket factory."); } catch (IOException io_exception) { throw new IOException("Failed to read APNS certificate."); } } SSLSocket ssl_socket = null; ssl_socket = (SSLSocket) socket_factory.createSocket(config.getHostname(service), config.getPort(service)); ssl_socket.setUseClientMode(true); return ssl_socket; }