SAP PI 配置SSL链接接口报错问题处理Peer certificate rejected by ChainVerifier

文章讲述了在SAPNetWeaverAdministrator中遇到证书导入问题的解决办法,包括未导入证书、证书过期以及证书冲突的情况,并提到了使用XPI_inspector工具进行故障诊断。

出现这种情况一般无非是没有正确导入证书或者证书过期的情况

第一种,如果没有导入证书的话,需要在NWA中的证书与验证-》CAs中导入管理员提供的证书,这里需要注意的是,需要导入完整的证书链。

第二种如果是证书过期的,可以直接导入新的证书,如果出现冲突的情况需要把对应的证书删除,然后再导入新的证书,以下是SAP提供的原因解释3076281:

  1. Make sure that backend server's certificate chain has correct hostname and does not include unsupported characters. Also make sure there is no other certificate with the same value of Subject existing in TrustedCAs. Two certificates with the same Subject value can't co-exist in one keystore view. If it exists, then at runtime, during SSL handshake, a lookup is done only once based on Subject value thus can results in titled error, finally cause SSL failure.
    For example:
    AS Java AAA is SSL client. AS ABAP BBB is SSL server and AS ABAP CCC is another SSL server. Both BBB and CCC has SSL certificate with same Subject value but the serial number is different. Such as:
    --------------------
    BBB:<
在 HarmonyOS 开发过程中,网络请求时如果遇到类似 **SSL peer certificate 或 SSH remote key 无效** 的错误,通常表示客户端无法验证服务器SSL 证书或 SSH 密钥。这类问题常见于使用了自签名证书、证书链不完整或未被系统信任的情况。 ### 1. 检查并配置服务器端的 SSL 证书 确保服务器使用的 SSL 证书是由可信 CA 签发的,并且证书链完整。如果是自签名证书,则需要将该证书添加到设备的信任存储中。对于 HarmonyOS 应用来说,可以将证书打包进应用资源中,并通过代码配置信任该证书[^2]。 #### 示例:在应用中信任特定证书 ```java OkHttpClient createClientWithTrustedCert(Context context) { try { Certificate certificate = CertificateFactory.getInstance("X.509") .generateCertificate(context.getAssets().open("your_certificate.cer")); KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(null, null); keyStore.setCertificateEntry("server", certificate); TrustManagerFactory tmf = TrustManagerFactory .getInstance(TrustManagerFactory.getDefaultAlgorithm()); tmf.init(keyStore); SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, tmf.getTrustManagers(), null); return new OkHttpClient.Builder() .sslSocketFactory(sslContext.getSocketFactory(), (X509TrustManager) tmf.getTrustManagers()[0]) .build(); } catch (Exception e) { throw new RuntimeException(e); } } ``` ### 2. 在 HarmonyOS 中启用系统级证书验证 类似于 PyCharm 中的“使用 Windows 证书存储”功能,在 HarmonyOS 中可以通过设置使应用信任系统的根证书存储,从而避免手动管理证书。默认情况下,大多数网络库(如 OkHttp)会自动使用系统证书存储进行验证,但如果在开发过程中使用了自定义 `TrustManager`,则需确保其包含系统默认的信任策略[^2]。 ### 3. 关闭 SSL 验证(仅限测试环境) 虽然可以通过关闭 SSL 验证快速绕过问题,但此方法存在严重安全风险,**仅适用于开发和测试阶段**,绝对不应出现在生产环境中。 #### 示例:禁用 SSL 验证(不推荐) ```java OkHttpClient getInsecureClient() { try { final SSLContext sslContext = SSLContext.getInstance("SSL"); sslContext.init(null, new TrustManager[]{new X509TrustManager() { @Override public void checkClientTrusted(X509Certificate[] chain, String authType) {} @Override public void checkServerTrusted(X509Certificate[] chain, String authType) {} @Override public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } }}, new SecureRandom()); return new OkHttpClient.Builder() .sslSocketFactory(sslContext.getSocketFactory(), this) .hostnameVerifier((hostname, session) -> true) .build(); } catch (Exception e) { throw new RuntimeException(e); } } ``` ### 4. 使用 SSH 密钥认证(如适用) 若网络请求涉及 Git 仓库或其他基于 SSH 的服务,应确保 SSH 密钥已正确生成并部署到设备上。可通过以下命令检查密钥是否可用: ```bash ssh -i /path/to/private_key git@your-git-server.com ``` ### 5. 调整网络请求库的安全策略 部分网络请求库(如 Apache HttpClient、OkHttp)允许自定义安全策略。应确保其配置与后端服务器的 TLS 版本、加密套件等保持一致,以避免握手失败。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值