我正在尝试从我的Verticle连接到实现TLS-PSK加密算法TLS_PSK_WITH_AES_128_CBC_SHA和协议" TLSv1.2"的设备。我有一个代码示例,我们使用BouncyCastle库进行通信。
TlsPSKIdentity pskIdentity = new BasicTlsPSKIdentity("identity", Hex.decode("/*psk key*/d901308ef9c6997fabf3a88d80954e17ecfef43f5ad9a1fc780fdd07e5494ae6"));
Security.addProvider(new BouncyCastleProvider());
Socket socket = new Socket(InetAddress.getByName("some host"), 12345);
SecureRandom secureRandom = new SecureRandom();
MockPSKTlsClient client = new MockPSKTlsClient(null, pskIdentity);
TlsClientProtocol protocol = new TlsClientProtocol(
socket.getInputStream(),
socket.getOutputStream(),
secureRandom
);
protocol.connect(client);
OutputStream output = protocol.getOutputStream();
output.write("someMessage".getBytes("UTF-8"));
InputStream input = protocol.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(">>> " + line);
}
output.close();
input.close();
socket.close();
protocol.close();
我知道Vert.x Ssl选项可以以密钥库/可信任格式配置。 我的任务是在Vert.x中实现它。任何人都可以帮助我理解如何成功连接PSK和vertx NetClient?