- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我尝试通过 SSL 连接到我的 JAX-WS 服务。没有 SSL 一切正常。
AsyncTask 中的方法:
HttpsTransportSE androidHttpTransport = new HttpsTransportSE("10.0.2.2", 8181, "/Server/?wsdl", 10000);
((HttpsServiceConnectionSE) androidHttpTransport.getServiceConnection()).setSSLSocketFactory(trustAllHosts()
.getSocketFactory());
//androidHttpTransport.debug=true;
androidHttpTransport.call(getSoapAction(method), envelope);
获取SSL上下文
public SSLContext allowAllSSL() {
SSLContext context = null;
TrustManager[] trustManagers = null;
try{
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyStore keyStore = KeyStore.getInstance("pkcs12");
InputStream in = cntx.getResources().openRawResource(R.raw.client_keystore);
try {
keyStore.load(in, "password".toCharArray());
} catch (CertificateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
in.close();
}
tmf.init(keyStore);
if (trustManagers == null) {
trustManagers = new TrustManager[] { new FakeX509TrustManager() };
}
try {
context = SSLContext.getInstance("SSL");
context.init(null, tmf.getTrustManagers(), new SecureRandom());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
}catch(Exception ex)
{
Log.e(TAG,"allowAllSSL failed: "+ex.toString());
}
return context;
}
我得到这个错误日志:
12-18 07:51:42.161: E/Example:LogOnAsync(3161): doInBackground failed: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
12-18 07:51:42.161: W/System.err(3161): javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
12-18 07:51:42.169: W/System.err(3161): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:401)
12-18 07:51:42.169: W/System.err(3161): at libcore.net.http.HttpConnection.setupSecureSocket(HttpConnection.java:209)
12-18 07:51:42.169: W/System.err(3161): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:478)
12-18 07:51:42.169: W/System.err(3161): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
最佳答案
有人问我的问题:在 MainAsync 中:
HttpsTransportSE androidHttpTransport = new HttpsTransportSE(10.0.2.2, 8181, "/server/?wsdl", 10000);
((HttpsServiceConnectionSE) androidHttpTransport.getServiceConnection()).setSSLSocketFactory(trustAllHosts().getSocketFactory());
protected SSLContext trustAllHosts()
{
return allowAllSSL();
}
public SSLContext allowAllSSL() {
SSLContext context = null;
TrustManager[] trustManagers = null;
KeyManagerFactory mgrFact;
try{
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
mgrFact = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
KeyStore keyStore = KeyStore.getInstance("pkcs12");
InputStream in = cntx.getResources().openRawResource(R.raw.keystore);
try {
keyStore.load(in, "password".toCharArray());
mgrFact.init(keyStore, "password".toCharArray());
} catch (CertificateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
in.close();
}
tmf.init(keyStore);
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier()
{
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
if (trustManagers == null) {
trustManagers = new TrustManager[] { new FakeX509TrustManager() };
}
final TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
System.out.println("getAcceptedIssuers");
return null;
}
public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
System.out.println("Сведения о сертификате : " + chain[0].getIssuerX500Principal().getName() + "\n Тип авторизации : " + authType);
}
public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
System.out.println("checkClientTrusted : " + authType);
}
} };
//tmf.getTrustManagers()
try {
context = SSLContext.getInstance("TLS");
context.init(mgrFact.getKeyManagers(), trustAllCerts, new SecureRandom());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
}catch(Exception ex)
{
Log.e(TAG,"allowAllSSL failed: "+ex.toString());
}
return context;
}
关于Android KSOAP2 SSL java.security.cert.CertPathValidatorException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20658849/
你发现标题的不同了吗? (对我来说,花了一些时间) 所以我按顺序使用了连接到 java.security.cert.X509Certificate 的充气城堡创建证书。现在我正在寻找一种从原始字节创建
我有一整天都在努力解决的问题,但就是无法重建。我遇到了引发 CertificateNotYetValidException 异常的问题: java.security.cert.CertificateN
我有一个服务器和一个客户端。我让他们都在同一台机器上运行。我正在尝试在客户端和服务器之间建立 SSL 连接。我已经使用以下 keytool 命令为服务器和客户端生成了证书。 对于客户keytool -
在本地,我一直在使用一个 Nginx 容器进行开发,该容器在一个目录中包含所有 ssl 配置和 ssl 证书。 但是,既然我即将转向生产,我很好奇将证书放在 nginx 容器中是否是一种好的做法? 或
我想根据 CRL 验证客户端提供的 X509 证书是否已被吊销。我已经成功地实例化了一个 java.security.cert.X509CRL,但是我在检索 session 证书时遇到了问题: try
我在使用 X509TrustManager 检查服务器是否可信时收到异常错误。我按照开发人员的说明进行操作:https://developer.android.com/training/article
我正在尝试使用 Java 代码从安全(即 SSL)网页中读取内容。我正在尝试同时使用 URLConnection (java.net) 和 Apache 的 HTTPClient。在这两种情况下,当我
如果我仅使用证书(带链)和私钥发出 openssl 调用,我会遇到服务器拒绝握手中的客户端证书的问题。 如果我还设置了 cafile 参数并将其指向与证书相同的文件,这个问题就会消失。 即使信息已经在
我正在使用由 CA 文件签名的证书来保护 kubernetes API。为此,我将我的 CA 文件 sa.crt 添加到 /etc/pki/ca-trust/source/anchors/ 并使用命令
我使用facepy与python进行GAE 我遇到了一个错误,当我跟踪该错误时,我发现 from . import certs 在utils.py文件中 点(.)是什么意思? certs.py 与 u
本文整理了Java中org.bouncycastle.cert.X509CRLHolder类的一些代码示例,展示了X509CRLHolder类的具体用法。这些代码示例主要来源于Github/Stack
本文整理了Java中org.bouncycastle.cert.X509v2CRLBuilder类的一些代码示例,展示了X509v2CRLBuilder类的具体用法。这些代码示例主要来源于Github
本文整理了Java中org.bouncycastle.cert.X509ExtensionUtils类的一些代码示例,展示了X509ExtensionUtils类的具体用法。这些代码示例主要来源于Gi
本文整理了Java中org.bouncycastle.cert.X509AttributeCertificateHolder类的一些代码示例,展示了X509AttributeCertificateHo
我按照此说明在我的 EKS 集群上设置了一个证书管理器 https://cert-manager.io/docs/tutorials/acme/ingress/ . 这是我的入口 apiVersion
遵循https://cert-manager.io/docs/installation/kubernetes/中提到的步骤 # Kubernetes 1.16+ $ kubectl apply --v
我按照此说明在我的 EKS 集群上设置了一个证书管理器 https://cert-manager.io/docs/tutorials/acme/ingress/ . 这是我的入口 apiVersion
过去 2 天我遇到了此错误。这似乎是 python requests 库的问题,但我已经重新安装了好几次了,但没有成功。 Traceback (most recent call last):
我有一台运行 Debian 8.1、Apache 2.4.10 和 OpenSSL 1.0.1k 的服务器。我有一个域 example.com,其中包含几个子域,例如 www.example.com、
我正在使用 cUrl 从公司网站请求数据,使用他们发送给我的 .cer 证书。这是命令: cUrl --header "Content-Type: text/xml;charset=UTF-8" \
我是一名优秀的程序员,十分优秀!