我正在尝试从我的 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 选项可以配置为 keystore/trustore 格式。我的任务是在 Vert.x 中实现它。谁能帮助我了解如何成功连接 PSK 和 vertx NetClient?