一、关于ftp SSL(FTPS)
【服务器】
1、帐号开启
/etc/ftpuser里账号前加#
2、创建证书
#mkdir -p /user/share/ssl/certs
#openssl req -new -x509 -nodes -out vsftpd.pem -keyout vsftpd.pem
# cp vsftpd.pem /user/share/ssl/certs/vsftpd.pem
3、vsftp.conf
ssl_enable=YES
ssl_tlsv1=YES
allow_anno_ssl=YES
anon_root=/home/ftp/pub
force_local_data_ssl=YES
force_local_logins_ssl=YES
local_umask=077
rsa_cert_file=/user/share/ssl/certs/vsftpd.pem
【客户端】
导入证书
[方式1]直接导入,若-keystore不存在,则自动创建。
keytool -import -keystore mon.keystore -alias mon -storepass 111111 -file public.pem
[方式2]先创建mon.keystore,删除默认数据,最后导入
keytool -genkey -alias pp -keystore mon
keytool -list -v -keystore mon
keytool -delete -alias pp -keystore mon
keytool -import -keystore mon -alias public -storepass 111111 -file public.pem
注意:public.pem 只保留公钥,去掉私钥。
代码:
FtpsClient =FtpsClientFactory.getFtpsClient();
//导入证书
String type = keyStore.getDefaultType();
char[] passwordstore = "111111".toCharArray;
Keystore keystore = keyStore.getInstance(type);
java.io.InputStream fis = new java.io.InputStream("c:/mon.keystore");
keystore.load(fis, passwordstore);
fis.close();
//设置证书
FTPSX509TrustManagerImpl x509Trust = new FTPSX509TrustManger(keystore);
TrustManager trustCert = new TrustManager[]{x509Trust };
ftpsClient.setTrustManagers(trustCerts);
//设置管理器
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509", "SunJSSE");
kmf.init(keystore, passwordstore);
KeyManager[] km = (KeyManager[]) kmf.getKeyManagers();
ftpsClient.setKeyManager(km);
//连接
ftpsClient.connet();