大家好,我正在尝试为 Cisco Unified Communications Manager 编写 AXL 客户端 (SOAP)。为此,我需要建立到 AXL 服务的 ssl 连接。不幸的是,我对所有那些 ssl 的东西知之甚少。
但是,我能够找到一个有效的 Java 示例,这正是我想要的。问题是,我需要在 C#.NET 中。所以我希望有人可以在 C# 版本中“翻译”以下 Java 代码。但它必须完全相同,尤其是身份验证和证书。
这是代码:
String sAXLSOAPRequest = "...";
byte[] bArray = null; // buffer for reading response from
Socket socket = null; // socket to AXL server
OutputStream out = null; // output stream to server
InputStream in = null; // input stream from server
X509TrustManager xtm = new MyTrustManager();
TrustManager[] mytm = { xtm };
SSLContext ctx = SSLContext.getInstance("SSL");
ctx.init(null, mytm, null);
SSLSocketFactory sslFact = (SSLSocketFactory) ctx.getSocketFactory();
socket = (SSLSocket) sslFact.createSocket("192.168.1.100", Integer.parseInt("8443"));
in = socket.getInputStream();
// send the request to the server
// read the response from the server
StringBuffer sb = new StringBuffer(2048);
bArray = new byte[2048];
int ch = 0;
int sum = 0;
out = socket.getOutputStream();
out.write(sAXLSOAPRequest.getBytes());
while ((ch = in.read(bArray)) != -1) {
sum += ch;
sb.append(new String(bArray, 0, ch));
}
socket.close();
// output the response to the standard output
System.out.println(sb.toString());
这是 MyTrustManager 类:
public class MyTrustManager implements X509TrustManager {
MyTrustManager() {
// create/load keystore
}
public void checkClientTrusted(X509Certificate chain[], String authType)
throws CertificateException {
}
public void checkServerTrusted(X509Certificate chain[], String authType)
throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
}
任何帮助,将不胜感激。
谢谢
编辑:对不起,我应该提到:你说得对,我可以生成一个代理类,但遗憾的是它不能正常工作。cisco 在这方面做得非常糟糕(更不用说非常糟糕的文档了)。解析某些响应时,代理类会引发一些 xml 错误。所以我必须手动完成这种情况......
我稍后会担心证书的安全性