0

これは私のサーバーコードです

import java.io.InputStream;

import java.io.OutputStream; 
import java.security.Key;

import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSocket;

public class SSLServer {
   final static String pathToStores = "C:/Users/Amee";
final static String keyStoreFile = "server.jks";
final static String passwd = "changeit";

final static int theServerPort = 8443;

static boolean debug = false;

public static void main(String args[]) throws Exception {

    String trustFilename = pathToStores + "/" + keyStoreFile;
    // System.out.println("Verifying KeyStore File of Client..");

    System.setProperty("javax.net.ssl.keyStore", trustFilename);
    System.setProperty("javax.net.ssl.keyStorePassword", passwd);
    if (debug)
        System.setProperty("javax.net.debug", "all");
    System.out.println("Setting up SSL parameters");

    // Initialize socket connection
    SSLServerSocketFactory sslssf = (SSLServerSocketFactory) SSLServerSocketFactory
            .getDefault();
    SSLServerSocket sslServerSocket = (SSLServerSocket) sslssf
            .createServerSocket(theServerPort);
    System.out.println("Server Started..Waiting for clients");
    //sslServerSocket.setNeedClientAuth(true);

    SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
    // sslSocket.startHandshake();
    System.out.println("Client Connected!");

    InputStream sslIS = sslSocket.getInputStream();

    OutputStream sslOS = sslSocket.getOutputStream();

    final int RSAKeySize = 1024;
    final String newline = "\n";

    Key pubKey = null;
    Key privKey = null;
    boolean flag = sslSocket.getNeedClientAuth();
    System.out.println("Flag value: " + flag);

    String messgae = "Hello Client!"; 
    sslOS.write(messgae.getBytes());
//  sslOS.close();
}

}

================================================== ===============

これは私のクライアントコードです

=============================================

import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

public class SSLClient{
    final static String pathToStores = "C:/Users/Amee";
    final static String trustStoreFile = "client.jks";
    final static String passwd = "changeit";
    final static String theServerName = "localhost";
    final static int theServerPort = 8443;

static boolean debug = false;

public static void main(String args[]) throws Exception {

    String trustFilename = pathToStores + "/" + trustStoreFile;
    System.out.println("Validating KeyStore file of Server..");

    System.setProperty("javax.net.ssl.trustStore", trustFilename);
    System.setProperty("javax.net.ssl.trustStorePassword", passwd);
    if (debug)
        System.setProperty("javax.net.debug", "all");


    SSLSocketFactory sslssf = (SSLSocketFactory) SSLSocketFactory.getDefault();
    SSLSocket sslSocket = (SSLSocket)sslssf.createSocket(theServerName, 8443);
    System.out.println("Connected to Server!");

    while (true) {

        if (sslSocket.getInputStream().available() > 0) {
            byte[] data = new byte[sslSocket.getInputStream().available()];
            sslSocket.getInputStream().read(data);
            System.out.println(new String(data));
        }
    }
}

}

================================================== ==============

いくつかの提案をしてください...どうすればチャネル経由でデータを転送できますか?

4

1 に答える 1