jjzjj

Android kSOAP2 SSL 自签名证书 "Security Requirements not met - No Security header in message"

coder 2023-12-24 原文

连接到 SSL WebServices Apache Tomcat 时出现问题,Java SE 客户端连接正常,但 Android 客户端不想连接并显示以下错误之一:1.“未满足安全要求 - 中没有安全 header 消息”,2。“Java.lang.RuntimeException:java.lang.RuntimeException:错误:0407006A:rsa例程:RSA_padding_check_PKCS1_type_1: block 类型不是01(SHA-1) . “为了连接,我描述了以下代码:

private SSLSocketFactory getSSLSocketFactory() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
    KeyStore trusted = KeyStore.getInstance("PKCS12");
    InputStream in = activity.getResources().openRawResource(R.raw.client_keystore);
    try {
        trusted.load(in, "blablabla".toCharArray());
    } catch (CertificateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        try {
            in.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509");
    tmf.init(trusted);
    SSLContext context = SSLContext.getInstance("SSLv3");
    context.init(null, tmf.getTrustManagers(), null);
    return context.getSocketFactory();
}

public String SendRecieveMessage(String xmlData, String nameXML, String methodName, String methodAction) {

    HttpsTransportSE httpTransport = new KeepAliveHttpsTransportSE("hostname", 8443, "/blablabla/blablabla?wsdl", 1000);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    SoapObject request = new SoapObject(activity.getResources().getString(R.string.SOAP_NAMESPACE), methodName); // set
    // request
    Log.e("Sending SOAP", xmlData);
    String base64 = base64Coder.encodeString(xmlData);
    request.addProperty(nameXML, base64); 
    envelope.setOutputSoapObject(request); // prepare request
    try {
        ((HttpsServiceConnectionSE) httpTransport.getServiceConnection()).setSSLSocketFactory(getSSLSocketFactory());
    } catch (KeyManagementException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (KeyStoreException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (NoSuchAlgorithmException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    SoapPrimitive result = null;
    try {
        httpTransport.call(methodAction, envelope);
        result = (SoapPrimitive) envelope.getResponse(); // get
        if (result != null) {
            base64 = base64Coder.decodeString(result.toString());
        } else {
            base64 = null;
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        Log.e("ERROR", "SOAPSendRecieve: " + e.getMessage());
        base64 = null;
    } catch (XmlPullParserException e) {
        // TODO Auto-generated catch block
        Log.e("ERROR", "SOAPSendRecieve: " + e.getMessage());
        base64 = null;
    } catch (IllegalArgumentException e) {
        Log.e("ERROR", "SOAPSendRecieve: " + e.getMessage());
        base64 = null;
        }
    } finally {
        request = null;
        result = null;
    }
    return base64;
}

由 blablabla.jks 中的服务器转换为 blablabla.pfx (PKCS # 12),我尝试使用两个程序:“KeyStore Explorer”和“Portecle”,还尝试了格式“BKS”,结果相同,SSL官网Example中描述的kSOAP2,可能是什么问题,是客户端设置不正确还是客户端设置有问题?

示例请求和响应转储:

最佳答案

问题解决了,服务器部署了库WSIT,要求保护Security Header,也就是“User”和“Password”,一个SOAP消息,因为我没有指定这些参数,所以我没有连接到服务器在消息标题中描述感谢大家的帮助。

关于Android kSOAP2 SSL 自签名证书 "Security Requirements not met - No Security header in message",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13558670/

有关Android kSOAP2 SSL 自签名证书 "Security Requirements not met - No Security header in message"的更多相关文章

随机推荐