- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试通过 https 连接到我的后端。我有 2 个证书 *.p12 和 *.cer。我是用命令导入的(见代码)我使用命令导入 key :
keytool -v -importkeystore -srckeystore bonus-testagent.p12 -srcstoretype PKCS12 -destkeystore truststore.jks -deststoretype JKS
我的代码是(grails 服务):
private SSLSocketFactory getSSLFactory() throws Exception {
KeyStore keyStore = KeyStore.getInstance("JKS");
String keystoreFile = 'D:\\grails_wide\\certificates\\truststore.jks'
File binaryFile = new File(keystoreFile);
InputStream is = binaryFile.newInputStream()
if (is == null) {
return null;
}
String password = "****";
keyStore.load(is, password.toCharArray());
is.close();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keyStore);
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, tmf.getTrustManagers(), null);
return ctx.getSocketFactory();
}
def accountInfo(String cardNumber, Cookie[] cookies) {
String urlStr = "https://app-domain.com";
URL url = new URL(urlStr);
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
conn.setSSLSocketFactory(getSSLFactory());
conn.setRequestMethod("GET");
conn.setRequestProperty("Cookie", WebUtils.buildCookiesHeader(cookies))
InputStream is = conn.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer stringBuffer = new StringBuffer();
while ((line = rd.readLine()) != null) {
stringBuffer.append(line);
}
rd.close();
def response = stringBuffer.toString();
但是有错误:
ERROR errors.GrailsExceptionResolver - SunCertPathBuilderException occurred when processing request: [POST] /club/account
unable to find valid certification path to requested target. Stacktrace follows:
Message: unable to find valid certification path to requested target
在字符串中:
InputStream is = conn.getInputStream();
最佳答案
首先,您通常不需要将 PKCS#12 (.p12) 文件转换为 JKS 存储,您可以直接使用 PKCS12
keystore 类型。
其次,.p12
文件通常不用作信任库,而是用作 keystore 。 (例如,请参阅 this question 以了解 keystore 和信任库之间的区别。).p12
文件将包含不属于信任库的私钥 Material 。
您在这里所做的是用您的 .p12
文件替换默认的信任库,因此它只能在连接时根据您的 .p12
文件中的证书进行验证远程(而不是根据 CA 证书进行验证)。因此,它失败并显示“无法找到到所请求目标的有效证书路径”。
据推测,您正在尝试连接客户端证书。在这种情况下,您需要将该 .p12
文件用作 keystore。为此:
.p12
,请改用 KeyStore.getInstance("PKCS12")
。 (您不需要那个 keytool 转换。)KeyManagerFactory
一起使用,而不是 TrustManagerFactory
。初始密码将是 key 本身的密码,与 PKCS#12 中的存储 key 相同。ctx.init(kmf.getKeyManagers(), null, null)
。第二个 null
参数将使用 JRE 的默认信任库(假设您的服务器以这种方式受信任)。关于grails - 我如何在 grails 中使用 *.p12 证书来建立 https 连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22072463/
我正在尝试使用 Excel 中的间接函数来构建公式以在另一张纸上返回值。 在工作表 A 单元格 D3 的值为 B 我想使用值 B 从名为 App Summary 的工作表中的单元格 B6 返回一个值。
我目前正在使用 LumiSoft 的 SIP 堆栈,并且能够在我的 FreePBX 盒子上成功注册分机并调用另一个软电话。我现在需要做的就是通过调用流式传输 WAV 文件(或 RAW,或任何可行的文件
这个问题已经有答案了: How can I fix 'android.os.NetworkOnMainThreadException'? (65 个回答) 已关闭 8 年前。 我有一个安卓 Activ
我正在使用 ws npm 在服务器端,websocket 在客户端。 从 node-js 运行此代码时它工作正常,但从浏览器运行它会出现以下错误: failed: Error in connectio
当我将鼠标悬停在想要淡入和淡出的内容上多次时,它就会不断重复。即使我停止悬停它。我怎样才能阻止这个? $(".featured").hover(function(){ $(this).find
我需要建立一个 mysql 连接并取回一些数据。我可以使用此代码在 Java 中执行此操作 try{ String username;
不能制造愚蠢。具有下一个文件夹结构: /flint/double-conversion/src /燧石/愚蠢/愚蠢/ 其中/flint/folly 包含自述文件和许可证。作为in the readme
我想在编译主单元之前在程序集中嵌入本地引用。但书面目标不起作用。 WithMetadataValue( 'CopyLocal', 'true' )->Met
我不是软件专家,但我确实需要一些建议。 我正在编写一个 C 程序(在下面剪切/粘贴)以通过 LAN(以太网)建立从我的 Mac Pro 到位于它旁边的基于 Windows XP 的测试仪器的 TCP
我正在构建一个应用程序,我的手机经常将数据发送到我的服务器。由于我将使用我的移动数据,我想知道建立(和拆除?)到我的服务器的 TCP 连接需要多少数据。 最佳答案 TCP 三向握手 Device 1
我有一个带有登录表单的网站。当加载登录表单页面时,我创建一个新的 PDO 对象以查看连接是否正常工作。如果成功打开连接,查看者将看到一个登录表单。如果不成功,他们会收到一条消息,说明服务器已关闭。 然
构建我的Electron应用程序后,它将显示产品名称undefined。如何设置其他名称呢? 当前是这样的: 最佳答案 请尝试此操作。引用此链接 https://www.electronjs.org/
我有一个项目在哪里使用这个 jar 。 据我所知...发生 war 之后,文件夹WEB-INF/lib必须具有: mail-1.4.1.jar activation-1.1.jar mysql-con
代码: %{ #include #include #include #include "gener.h" #include "sym_tab.h" #include "scope.h" #inc
我需要将侧边栏小部件集成到我的高流量页面(称为SiteA)中。该小部件应包含我的其他页面之一(称为 SiteB)的最新文章。 在我看来,我有两种可能的解决方案。 SiteA 上的 cUrl 调用从 S
我正在尝试建立 Cortana 技能,以便能够使用 Surface 相机拍照。怎么做?目前我的技能是能够使用bot框架和使用nodejs来回答问题。代码看起来像 bot.dialog('ScanCar
这个问题在这里已经有了答案: Resolving javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorExce
当我与网络服务器建立 https 连接时出现 SSLProtocolException。我只在 Android 2.3 Gingebread 中有这个异常(exception);相同的代码在所有其他
我想做的是指定几个端口,然后检查它们是否已建立连接。我找到了以下脚本并运行了,但它只列出了 3 个端口,我不明白为什么。我验证了相关端口的事件规则(以及下面输出中未列出的许多其他端口)。 Set ob
使用 MySQL 我试图使用已经上传到数据库中的数据建立一对多关系。举个例子,假设我在一个表中有一个名字列表,我想将它们连接到一个他们去过的地方的列表。显然 1 个人可以去很多不同的地方,但我在设置时
我是一名优秀的程序员,十分优秀!