private SavingTrustManager openSocketWithCert() throws IOException
	{
		try
		{
			// Load the default KeyStore or a saved one
			KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
			File file = new File("certs/" + server + ".cert");
			if (!file.exists() || !file.isFile())
				file = new File(System.getProperty("java.home") + "/lib/security/cacerts");
			
			InputStream in = new FileInputStream(file);
			ks.load(in, passphrase);
			
			// Set up the socket factory with the KeyStore
			SSLContext context = SSLContext.getInstance("TLS");
			TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
			tmf.init(ks);
			X509TrustManager defaultTrustManager = (X509TrustManager)tmf.getTrustManagers()[0];
			SavingTrustManager tm = new SavingTrustManager(defaultTrustManager);
			context.init(null, new TrustManager[] { tm }, null);
			SSLSocketFactory factory = context.getSocketFactory();
			
			sslsocket = (SSLSocket)factory.createSocket(server, port);
			
			return tm;
		}
		catch (Exception e)
		{
			// Hitting an exception here is very bad since we probably won't recover
			// (unless it's a connectivity issue)

			// Rethrow as an IOException
			throw new IOException(e.getMessage());
		}
	}