gpt4 book ai didi

java - 没有加密的 sslengine 密码套件

转载 作者:太空宇宙 更新时间:2023-11-03 15:09:57 25 4
gpt4 key购买 nike


我在使用 SSLEngine 时遇到了一个小问题 java 。我用它来创建客户端和服务器之间的 SSL 连接。这不是基于 Web 的应用程序。

我正在为我的产品开发人员创建一个框架,以便在客户端和服务器之间进行通信。根据他们的配置,我必须创建连接。如果需要加密,我必须创建一个加密 channel 并提供给他们;如果没有,我只需要创建一个没有加密但有消息摘要的 SSL channel ,所以我需要启用的密码套件是 SSL_RSA_WITH_NULL_MD5 .如果需要加密,我会使用SSL_RSA_WITH_<some encryption algo>_SHA/MD5 .

我可以配置第二个……但无法配置 SSL_RSA_WITH_NULL_MD5 .它给我一个异常消息 No cypher suites in common .我开发这个的框架是Netty(jboss-netty)。

谁能帮我解决这个问题??

代码::

public static ChannelFuture doHandshake(Channel channel,boolean isServer){
if (isServer) {
SSLEngine engine = SslContextFactory.getServerContext().createSSLEngine();
engine.setUseClientMode(false);
//engine.setWantClientAuth(true);
engine.setNeedClientAuth(true);

System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true");

String[] enabledSuites = engine.getEnabledCipherSuites();
//String[] sdf = engine.getSupportedCipherSuites();
engine.setEnabledCipherSuites(getWantedCyphers(enabledSuites, true));
engine.setEnableSessionCreation(true);
channel.getPipeline().addFirst(SSL_SERVER_HANDLER_NAME, new SslHandler(engine));

SslHandler sslHandler = (SslHandler) channel.getPipeline().get(SSL_SERVER_HANDLER_NAME);

sslHandler.setEnableRenegotiation(true);
return sslHandler.handshake();
} else {
SSLEngine engine = SslContextFactory.getClientContext().createSSLEngine();
engine.setUseClientMode(true);
engine.setEnableSessionCreation(true);
//engine.setWantClientAuth(true);
//engine.setNeedClientAuth(true);

System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true");

String[] enabledSuites=engine.getEnabledCipherSuites();
//String[] sdf=engine.getSupportedCipherSuites();
engine.setEnabledCipherSuites(getWantedCyphers(enabledSuites,true));
channel.getPipeline().addFirst(SSL_CLIENT_HANDLER_NAME, new SslHandler(engine));

SslHandler sslHandler = (SslHandler) channel.getPipeline().get(SSL_CLIENT_HANDLER_NAME);

sslHandler.setEnableRenegotiation(true);
return sslHandler.handshake();
}
}

public static String[] getWantedCyphers(String[] enabledSuites,boolean isEnabled) {
List<String> wantedCyphers = new LinkedList<String>();
String[] finalEnabledCyphers = null;
if (!isEnabled) {
finalEnabledCyphers = new String[1];
finalEnabledCyphers[0] = "SSL_RSA_WITH_NULL_MD5";
return finalEnabledCyphers;
}
String configFilePath = TestConstants.CONFIG_FILE;
ConfigSAXParser configParser = new ConfigSAXParser();
<OurOwnConfigClass>config = null;
try {
config = (<OurOwnConfigClass>(configParser.parseFile(configFilePath));
} catch (SAXParserException spe){
}
<ourOwnConfigSubClass> communicationConfig = config.getCommunicationConfig();
String[] requestedCyphers = communicationConfig.getEncryptionAlgorithms();
for (int i=0;i<requestedCyphers.length;i++){
requestedCyphers[i] = "SSL_RSA_WITH_"+requestedCyphers[i]+"_SHA";
}
List<String> stList = new LinkedList<String>();
for (int i=0;i<enabledSuites.length;i++) {
stList.add(enabledSuites[i]);
}
for (int j=0;j<requestedCyphers.length;j++) {
if (stList.contains(requestedCyphers[j])) {
wantedCyphers.add(requestedCyphers[j]);
}
}

Object[] strings = wantedCyphers.toArray();
finalEnabledCyphers = new String[strings.length];
for (int k=0;k<strings.length;k++) {
finalEnabledCyphers[k] = (String)strings[k];
}
return finalEnabledCyphers;
}

最佳答案

您是否已将其添加到已启用的密码套件中?

关于java - 没有加密的 sslengine 密码套件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4363632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com