처음에 비슷한 질문이 있음을 알고 있습니다.하지만 의심의 여지가 없습니다. SSL로 구성된 FTPS 서버 (vsftpd)가 있습니다.apache-commons net에서 생성 된 인증서를 사용하여 클라이언트 인증을 구성하는 방법
나는 함께 해당 키 생성했습니다
openssl req -x509 -nodes -days 1825 -newkey rsa:2048 \
-keyout private/vsftpd.key \
-out certs/vsftpd.crt
를 그리고 서버의 각 conf의 파일을 구성. ,
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.ftp.FTPSClient;
public class CommonsNetFTPSTest {
public static void main(String[] args) throws Exception {
System.setProperty("javax.net.debug", "ssl");
String server = "XXX.XXX.XXX.XXX";
String username = "USER_TEST";
String password = "ABCD1234";
String remoteFile = "/Data/Input/PH240819";
String localFile = "PH240819";
String protocol = "SSL"; // TLS/null (SSL)
int port = 990;
int timeoutInMillis = 10000;
boolean isImpicit = true;
FTPSClient client = new FTPSClient(protocol, isImpicit);
client.setDataTimeout(timeoutInMillis);
client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
System.out.println("################ Connecting to Server ################################");
try
{
int reply;
System.out.println("################ Connect Call ################################");
client.connect(server, port);
client.login(username, password);
System.out.println("################ Login Success ################################");
//client.setFileType(FTP.BINARY_FILE_TYPE);
client.setFileType(FTP.NON_PRINT_TEXT_FORMAT);
client.execPBSZ(0); // Set protection buffer size
client.execPROT("P"); // Set data channel protection to private
client.enterLocalPassiveMode();
System.out.println("Connected to " + server + ".");
reply = client.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply))
{
client.disconnect();
System.err.println("FTP server refused connection.");
System.exit(1);
}
client.listFiles();
boolean retrieved = client.retrieveFile(remoteFile, new FileOutputStream(localFile));
}
catch (Exception e)
{
if (client.isConnected())
{
try
{
client.disconnect();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
System.err.println("Could not connect to server.");
e.printStackTrace();
return;
}
finally
{
//client.disconnect();
client.logout();
System.out.println("# client disconnected");
}
}
}
하지만 내 클라이언트는 모든 인증서를 받고있다 그런 식으로 :
지금, 아파치 평민의 그물 자바 클라이언트 코드에서,이 같은 뭔가 SSL을 통해 서버와 통신 할 수 있어요 중간자 공격이 가능할 수도 있습니다. 그래서 내 고객에게 어떤 인증서를 수락할지 알려주고 인증서가 유효 할 때만 연결합니다. vsftpd.key 및 vsftpd.crt을, 나는 다음과 같은 로컬 키 스토어에서 CRT 파일을 가져온 :
는 지금, 나는이 두 파일은 이전에 생성 한
내 질문은keytool -import -alias alias -file vsftps.crt -keypass keypass -keystore mykeystore.jks -storepass Hello1
, 어떻게 할 내 고객에게 mykeystore의 인증서를 사용하도록 알려주십시오. 내가 뭘 놓치고 있니?. 감사합니다