gpt4 book ai didi

java - SSL异常 : Could not find any key store entries to support the enabled cipher suites

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

我想实现一个小型 android 应用程序,作为 SSL 服务器。在 keystore 的正确格式出现很多问题之后,我解决了这个问题并遇到了下一个问题。

我的 keystore 文件已由 KeyStore 类正确加载。但是当我尝试打开服务器套接字 (socket.accept()) 时,会出现以下错误:

javax.net.ssl.SSLException: Could not find any key store entries to support the enabled cipher suites.

我用这个命令生成了我的 keystore :

keytool -genkey -keystore test.keystore -keyalg RSA -keypass ssltest -storepass ssltest -storetype BKS -provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath bcprov.jar

将 Java SE6 的无限强度管辖策略应用于我的 jre6。

我通过调用获得了支持的密码套件列表

socket.getSupportedCipherSuites()

打印 long list有非常不同的组合。但我不知道如何获得支持的 key 。在使用 portecle 将其转换为 BKS 格式后,我还尝试了 android 调试 keystore ,但仍然出现相同的错误。

任何人都可以帮助并告诉我如何生成与其中一个密码套件兼容的 key 吗?

版本信息:

targetSDK: 15
在运行 4.0.3 的模拟器和运行 2.3.3 的真实设备上测试
弹跳城堡 1.46
可移植 1.7

我的测试应用程序代码:

public class SSLTestActivity extends Activity implements Runnable {
SSLServerSocket mServerSocket;
ToggleButton tglBtn;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

this.tglBtn = (ToggleButton)findViewById(R.id.toggleButton1);

tglBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
new Thread(SSLTestActivity.this).run();
} else {
try {
if (mServerSocket != null)
mServerSocket.close();
} catch (IOException e) {
Log.e("SSLTestActivity", e.toString());
}
}
}
});
}

@Override
public void run() {
try {
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(getAssets().open("test.keystore"), "ssltest".toCharArray());

ServerSocketFactory socketFactory = SSLServerSocketFactory.getDefault();
mServerSocket = (SSLServerSocket) socketFactory.createServerSocket(8080);
while (!mServerSocket.isClosed()) {
Socket client = mServerSocket.accept();
PrintWriter output = new PrintWriter(client.getOutputStream(), true);
output.println("So long, and thanks for all the fish!");
client.close();
}
} catch (Exception e) {
Log.e("SSLTestActivity", e.toString());
}
}
}

最佳答案

Keystore does not support enabled cipher suites

keystore 是否支持密码套件并不是真正的决定。支持它们的是 SSLSocket(或引擎)。它正在寻找的是 keystore 中的 key ,该 key 的类型适合其支持的密码套件之一。通常,启用的密码套件是基于 RSA 或 DSS 的,因此它将分别查找 RSA 或 DSA key 。

在下面的代码中:

KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(getAssets().open("test.keystore"), "ssltest".toCharArray());

ServerSocketFactory socketFactory = SSLServerSocketFactory.getDefault();
mServerSocket = (SSLServerSocket) socketFactory.createServerSocket(8080);

您没有对您的 keyStore 做任何事情。在这种情况下,您可能根本不加载它(顺便说一下,您应该始终关闭您从中读取的输入流)。

在这里,您仍在使用默认的 SSLServerSocketFactory,您没有专门配置它(并且没有默认的 keystore ):这就是为什么您得到“Could not find any key store entries to support the enabled cipher suites”:它找不到合适的 key 存储条目,因为它甚至找不到 key 存储。

您需要配置一个 SSLContext,使用从您的 keystore 构建的 KeyManager 对其进行初始化,然后从中获取一个服务器套接字工厂。

关于java - SSL异常 : Could not find any key store entries to support the enabled cipher suites,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10010126/

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