key gen to server stock
===

I put together some code, I think I'm getting close.  I'm trying to generate a key programmatically and use it to open a server SSL socket (fyi, part of my project involves forcing the user to verify fingerprints).  Other than that, I want it to be completely automated.  So, I just need to configure the server socket factory (bottom) with the new key pair (top).  I left some keystore code in there, I think I have to do all this through the key store.  I do need to store the key protected to disk.  


        KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
		keyGen.initialize(1024, new SecureRandom());
		KeyPair keypair = keyGen.generateKeyPair();

		System.setProperty("javax.net.ssl.keyStore", System.getProperty("user.home")
			+ File.separator +
				+ "/keystore.jks");
		System.setProperty("javax.net.ssl.keyStorePassword", "xyz");

		KeyManagerFactory keyManagerFactory = KeyManagerFactory
				.getInstance("SunX509");
		KeyStore keyStore = KeyStore.getInstance("JKS");
		keyStore.load(null, "xyz".toCharArray());
		// keyStore.
		keyManagerFactory.init(keyStore, "xyz".toCharArray());
		// keyStore.load
		SSLContext context = SSLContext.getInstance("TLS");// "SSLv3"
		context.init(keyManagerFactory.getKeyManagers(), null,
				new SecureRandom());
		ServerSocketFactory socketFactory = context.getServerSocketFactory();
		ServerSocket ssocket = socketFactory.createServerSocket(1443);
		Socket socket = ssocket.accept();