예제 #1
0
파일: Store.java 프로젝트: em881g/DFS2
 public static void main(String[] args) throws Exception {
   Properties properties = new Properties();
   FileInputStream propFile = new FileInputStream("store.properties");
   properties.load(propFile);
   final String id = properties.getProperty("ID");
   final String placeForFiles = properties.getProperty("FilePlace");
   int servicePort = Integer.parseInt(properties.getProperty("ServicePort"));
   int tcpPort = Integer.parseInt(properties.getProperty("TCPPort"));
   String ksName = properties.getProperty("KeyStore");
   KeyStore ks = KeyStore.getInstance(properties.getProperty("KeyStoreType"));
   char[] password = properties.getProperty("Password").toCharArray();
   char[] passwordForKey = properties.getProperty("PasswordForKey").toCharArray();
   ks.load(new FileInputStream(ksName), password);
   KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
   kmf.init(ks, passwordForKey);
   SSLContext context = SSLContext.getInstance("TLS");
   context.init(kmf.getKeyManagers(), null, null);
   SSLServerSocketFactory ssf = context.getServerSocketFactory();
   SSLServerSocket serverSocket = (SSLServerSocket) ssf.createServerSocket(tcpPort);
   ServiceThread serviceThread = new ServiceThread(servicePort, id);
   serviceThread.start();
   while (!serverSocket.isClosed()) {
     ClientThread client = new ClientThread(placeForFiles);
     SSLSocket socket = (SSLSocket) serverSocket.accept();
     socket.startHandshake();
     client.setSocket(socket);
     client.start();
   }
 }
 public boolean isClosed() {
   return s.isClosed();
 }