mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
将VMSConnection模块加入min-dev-java,以支持与VMS进行通信,执行注册、登录等功能
This commit is contained in:
1 parent
a26f908470
commit
ba105bdc3c
36 files changed
+2961
-2
No files matched your search
@@ -0,0 +1,75 @@
|
||||
package VMSConnection.TCPNet;
|
||||
|
||||
import VMSConnection.Security.BC_KeyManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
* @Description:
|
||||
* @Version: 1.0.0
|
||||
* @Date: 19:17 2021/6/23
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class TCPNet {
|
||||
public SocketChannel socketChannel; // 网络套接字
|
||||
public BC_KeyManager key; // 密钥管理
|
||||
public BC_KeyManager serverKey; //just pubkey can be used
|
||||
|
||||
public Conn Dials(String sslHost,Integer sslPort){
|
||||
// 1. 尝试连接TCP
|
||||
SocketChannel sk= null;
|
||||
try {
|
||||
sk = SocketChannel.open();
|
||||
sk.connect(new InetSocketAddress(sslHost,sslPort));
|
||||
// 设置超时时间
|
||||
sk.socket().setKeepAlive(true);
|
||||
sk.socket().setSoTimeout(5000);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
// 2. 创建一个conn,并返回
|
||||
return new TCPConn(sk, this.key,1);
|
||||
}
|
||||
|
||||
public Conn Dials(String host,Integer port,String sslHost,Integer sslPort,
|
||||
BC_KeyManager key,byte[] serverPubKey){
|
||||
// 2. 设置密钥serverKey
|
||||
this.key=key;
|
||||
BC_KeyManager serverK=new BC_KeyManager();
|
||||
serverK.SetPubkey(new String(serverPubKey, StandardCharsets.UTF_8));
|
||||
// 3. 尝试连接ssl,并获取密钥secretKey
|
||||
Conn sslConn=this.Dials(sslHost,sslPort);
|
||||
if(sslConn==null){
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
System.out.println("sslconn sk local: "+((TCPConn)sslConn).socketChannel.getLocalAddress());
|
||||
System.out.println("sslconn sk remote: "+((TCPConn)sslConn).socketChannel.getRemoteAddress());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String secretK=SSL.sslSetup(sslConn,key.GetPubkey(),key,serverK);
|
||||
if(secretK==null){
|
||||
return null;
|
||||
}
|
||||
// 1. 尝试连接TCP
|
||||
SocketChannel sk=null;
|
||||
try {
|
||||
sk = SocketChannel.open();
|
||||
sk.connect(new InetSocketAddress(host,port));
|
||||
// 设置超时时间
|
||||
sk.socket().setKeepAlive(true);
|
||||
sk.socket().setSoTimeout(5000);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
// 4. 返回一个TCPConn
|
||||
return new TCPConn(sk,this.key,serverK,true,secretK,1);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user