Netty SocketIO如何支持客戶端發起的SSL訪問?

Netty SocketIO如何支持客戶端的SSL訪問還是比較簡單的,大體上分兩個步驟:

1)準備JKS密鑰庫;

keytool -genkey -alias websocket -keyalg RSA -keysize 4096 -keypass 123456 -keystore C:\keystore.jks -storepass 123456 -dname "cn=websocket,ou=mydept,o=mycompany,l=sh,st=sh,c=cn" -ext san=ip:10.10.10.10 -validity 3650 -storetype JKS

2)SocketIOServer啓動配置Configuration增加兩個設置:keyStorePassword和keyStore。

Configuration config = new Configuration();
config.setHostname("10.10.10.10");
config.setPort(8092);
log.info("hostAddress: {}, port: {}", hostAddress, port);
config.setKeyStorePassword("123456");
String keyStoreLocation = "C:/keystore.jks";
InputStream stream = null;
try {
    stream = new FileInputStream(keyStoreLocation);
} catch (Exception e) {
    log.error("Error in loading jks file from: {}", keyStoreLocation);
    e.printStackTrace();
    return null;
}
config.setKeyStore(stream);
return new SocketIOServer(config);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章