pcSslContexts.forClient().trustManager( loadCert("server.cer")).build(); } catch (Exception ex) { throw new RuntimeException(ex); } InetAddress address; try { address = InetAddress.getByName(host); address = InetAddress.getByAddress("wancai", address.getAddress()); } catch (UnknownHostException ex) { throw new RuntimeException(ex); } channel = NettyChannelBuilder.forAddress(new InetSocketAddress(address, port)) .flowControlWindow(65 * 1024) .negotiationType(NegotiationType.TLS) .sslContext(sslContext) .build(); blockingStub = GreeterGrpc.newBlockingStub(channel);
最后,我们通过 wireshark,抓包看看使用TLS加密和不加密通信的信息。
当没有加密时,通信如下
参考资料
-
https://blog.helong.info/blog/2015/09/07/tls-protocol-analysis-and-crypto-protocol-design/
-
http://www.ruanyifeng.com/blog/2014/02/ssl_tls.html
-
http://www.barretlee.com/blog/2016/04/24/detail-about-ca-and-certs/
-
http://www.cnblogs.com/guogangj/p/4118605.html
-
https://my.oschina.net/itblog/blog/651434
-
http://blog.csdn.net/clementad/article/details/50620067
-
https://imququ.com/post/protocol-negotiation-in-http2.html
|