2011-09-01 4 views
9

सबसे पहले, मैं सारांश के साथ शुरू करूंगा। मैं अपाचे सीएक्सएफ क्लाइंट का उपयोग एक अपाचे सीएक्सएफ सेवा प्रदाता के साथ एसएसएल पर संवाद करने के लिए कर रहा हूं जो एक स्व-हस्ताक्षरित प्रमाणपत्र का उपयोग कर रहा है। मैंने क्लाइंट सर्वर पर वेबस्पेयर ट्रस्टस्टोर में प्रमाण पत्र आयात किया, लेकिन मुझे अभी भी एक "javax.net.ssl.SSLHandshakeException प्राप्त होता है: SSLHandshakeException https://somesvcprovider.com/appname/svc/myservice का आविष्कार: com.ibm.jsse2.util.h: कोई विश्वसनीय प्रमाणपत्र नहीं मिला" अपवाद।वेबशेयर ट्रस्टस्टोर का उपयोग करने के लिए अपाचे सीएक्सएफ क्लाइंट को कैसे सेट अप करें? ("कोई भरोसेमंद प्रमाणपत्र नहीं मिला" अपवाद प्राप्त करना।)

अब, यहाँ विवरण है:

मैं एक अपाचे CXF वेब सेवा ग्राहक है कि मैं वसंत का उपयोग कर रहा हूँ को विन्यस्त है, और ग्राहक एक WebSphere 6.1 आवेदन सर्वर के लिए तैनात किया गया है। सीएक्सएफ क्लाइंट एक अलग वेबस्फेयर सर्वर पर अपाचे सीएक्सएफ सेवा प्रदाता के साथ संचार करता है। संचार एसएसएल का उपयोग करता है।

सेवा प्रदाता एक स्व-हस्ताक्षरित प्रमाणपत्र का उपयोग कर रहा है। मैंने प्रदाता प्रमाणपत्र को क्लाइंट सर्वर पर व्यवस्थापकीय कंसोल के माध्यम से वेबस्पेयर ट्रस्टस्टोर में आयात किया है। मैंने SSL प्रमाणपत्र और कुंजी प्रबंधन> SSL कॉन्फ़िगरेशन> NodeDefaultSSLSettings> कुंजी स्टोर और प्रमाणपत्र> NodeDefaultTrustStore> हस्ताक्षर प्रमाणपत्र पर जाकर इसे पूरा किया; तो मैंने प्रमाण पत्र आयात करने के लिए "बंदरगाह से पुनर्प्राप्त" टूल का उपयोग किया। "Javax.net.ssl.SSLHandshakeException: SSLHandshakeException लागू https://somesvcprovider.com/appname/svc/myservice: com.ibm.jsse2.util.h: नहीं विश्वसनीय प्रमाणपत्र मिला"

हालांकि, मैं अब भी इस त्रुटि जब सेवा प्रदाता से संपर्क करने का प्रयास कर प्राप्त करते हैं।

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:sec="http://cxf.apache.org/configuration/security" 
    xmlns:http="http://cxf.apache.org/transports/http/configuration" 
    xmlns:jaxws="http://cxf.apache.org/jaxws" 
    xsi:schemaLocation=" 
     http://cxf.apache.org/configuration/security 
     http://cxf.apache.org/schemas/configuration/security.xsd 
     http://cxf.apache.org/transports/http/configuration 
     http://cxf.apache.org/schemas/configuration/http-conf.xsd 
     http://cxf.apache.org/jaxws 
     http://cxf.apache.org/schemas/jaxws.xsd 
     http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans.xsd"> 
    <http:conduit name="*.http-conduit"> 
     <!-- deactivate HTTPS url hostname verification (localhost, etc) --> 
     <!-- WARNING ! disableCNcheck=true should not used in production. --> 
     <http:tlsClientParameters disableCNCheck="true" /> 
    </http:conduit> 
    <!-- Read properties from property file(s). --> 
    <bean id="propertyPlaceholderConfigurer" 
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
     <property name="locations"> 
      <list> 
       <!-- The *.spring.properties files are prefixed with a system property 
        that is set on the WebSphere server. --> 
       <value>classpath:spring.${my.env}.properties</value> 
      </list> 
     </property> 
    </bean> 
    <jaxws:client id="myServiceClient" 
     serviceClass="com.client.stub.cxf.IMyService" 
     address="${my.svc.url}" /> 
    <bean id="myReport" class="com.client.MyReportRequestor"> 
     <property name="client" ref="myServiceClient"/> 
    </bean> 
</beans> 

जैसा कि ऊपर दिखाया गया है, CXF ग्राहक स्प्रिंग द्वारा एक सेटर के माध्यम से इंजेक्ट किया जाता है:

स्प्रिंग विन्यास फाइल इस प्रकार है। सेवा से संपर्क करने के लिए कोड के नीचे है:

List<String> formNames = client.retrieveNames(formIdsList); 

इसके अलावा, मैं अगर यह संबंधित है पता नहीं है, लेकिन कोई भरोसा प्रबंधकों लौटा दिए जाते हैं जब मैं निरीक्षण TLSClientParameters रनटाइम पर CXF ग्राहक पर आपत्ति है। निरीक्षण करने के लिए कोड के नीचे है:

// Get the trust managers for this client. 
Client proxy = ClientProxy.getClient(client); 
HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); 
TLSClientParameters tls = conduit.getTlsClientParameters(); 
TrustManager[] trustManagers = tls.getTrustManagers(); // trustManagers is null 

ऐसा कुछ हो जिसमें मैं स्व-हस्ताक्षरित प्रमाणपत्र पर भरोसा करने अपाचे CXF ग्राहक पाने के लिए क्या करने की जरूरत है?

मैं कॉन्फ़िगरेशन फ़ाइल में पासवर्ड के साथ ट्रस्टस्टोर के पथ को निर्दिष्ट करने की आवश्यकता नहीं है।

धन्यवाद!

उत्तर

0

मुझे नहीं लगता कि आप बाहरी घटक (अपाचे सीएक्सएफ) के साथ WAS कीस्टस्टोर का उपयोग कर सकते हैं। आपको शायद your own TrustManager का निर्माण और उपयोग करना होगा। इसके लिए कई काम examples प्रतीत होते हैं।

+0

मुझे डब्ल्यूएएस ट्रस्टस्टोर का उपयोग करने का कोई तरीका नहीं मिल रहा है, इसलिए मुझे लगता है कि आपको कॉन्फ़िगरेशन फ़ाइल में ट्रस्टस्टोर निर्दिष्ट करना होगा जैसा आपने बताया था। –

+0

मुझे @kjetil समाधान अधिक व्यवहार्य लगता है, क्योंकि इसे कस्टम विकास –

2

सीएक्सएफ और डब्ल्यूएएस कैसे काम करते हैं, यह देखते हुए, यह वेबस्पेयर के SSLSocketFactory तक पहुंचने के लिए काफी सरल है और इसे आउटबाउंड इंटरसेप्टर का उपयोग करके सीएक्सएफ में पास करना है।

आप निम्नलिखित वर्ग का उपयोग करते हैं:

public class WebsphereSslOutInterceptor extends AbstractPhaseInterceptor<Message> { 

    private String sslAlias = null; 

    public WebsphereSslOutInterceptor() { 
    super(Phase.SETUP); 
    } 

    public void handleMessage(Message message) throws Fault { 
    Conduit conduit = message.getExchange().getConduit(message); 
    if (conduit instanceof HTTPConduit) { 
     HTTPConduit httpConduit = (HTTPConduit)conduit; 
     String endpoint = (String) message.get(Message.ENDPOINT_ADDRESS); 
     if (endpoint != null) { 
     try { 
      URL endpointUrl = new URL(endpoint); 
      Map<String, String> connectionInfo = new HashMap<String, String>(); 

      connectionInfo.put(
      JSSEHelper.CONNECTION_INFO_REMOTE_HOST, 
      endpointUrl.getHost()); 
      connectionInfo.put(
      JSSEHelper.CONNECTION_INFO_REMOTE_PORT, 
      Integer.toString(endpointUrl.getPort())); 
      connectionInfo.put(
      JSSEHelper.CONNECTION_INFO_DIRECTION, 
      JSSEHelper.DIRECTION_OUTBOUND); 
      SSLSocketFactory factory = 
      JSSEHelper.getInstance().getSSLSocketFactory(
       sslAlias, 
       connectionInfo, 
       null); 

      TLSClientParameters tlsClientParameters = httpConduit.getTlsClientParameters(); 
      if (tlsClientParameters != null) { 
      tlsClientParameters.setSSLSocketFactory(factory); 
      } 
     } catch (MalformedURLException e) { 
      throw new Fault(e); 
     } catch (SSLException e) { 
      throw new Fault(e); 
     } 
     } 
    } 
    } 

    public void setSslAlias(String sslAlias) { 
    this.sslAlias = sslAlias; 
    } 
} 

तो फिर तुम और वैकल्पिक रूप से, किसी भी ग्राहक प्रमाणपत्र निर्दिष्ट करने के लिए "गतिशील आउटबाउंड Endpoint एसएसएल विन्यास" सेटिंग्स का उपयोग कर सकते द्वारा Websphere के SSLSocketFactory अप करने के लिए हुक करने में सक्षम हो जाएगा jaxws:client टैग में इंटरसेप्टर को निर्दिष्ट:,

<jaxws:client id="proxyName" 
     serviceClass="proxyClass" 
     address="${web.service.endpointaddress}"> 

    <jaxws:outInterceptors> 
     <bean class="my.pkg.WebsphereSslOutInterceptor" /> 
    </jaxws:outInterceptors> 
</jaxws:client> 

एक अलग रूप में के रूप में अगर sslAlias संपत्ति WebsphereSslOutInterceptor में घोषित किया जाता है, क्लाइंट प्रमाणपत्र इसके उर्फ ​​के आधार पर चुना जा सकता है।

क्योंकि यह वेबस्पेयर से SSLSocketFactory का उपयोग कर रहा है, ट्रस्ट स्टोर का भी वेबस्पेयर से उपयोग किया जाएगा।

संपादित करें:

मैं शायद गलत एसएसएल सॉकेट कारखाना उपयोग कर रहा है CXF 2.3.6 और Websphere 6.1

+0

की आवश्यकता नहीं है, यह समाधान तब तक मेरे लिए काम करता है जब तक मैं एंडपॉइंट कॉन्फ़िगरेशन में इंटरसेप्टर परिभाषा को रखता हूं। हालांकि, अगर मैं इसे बस पर डालता हूं, तो हैंडल मैसेज विधि को कॉल नहीं किया जाता है। क्या कोई जानता है कि वह क्यों है? मुझे हर एंडपॉइंट के लिए एक ही इंटरसेप्टर निर्दिष्ट करने की आवश्यकता नहीं है। – Sandman

+0

@ beny23 अगर मैं वेबस्पेयर डायनामिक एंडपॉइंट्स का उपयोग कर रहा हूं, तो क्या मुझे अभी भी सभी इंटरसेप्टर और SSLSocketFactory सामान की आवश्यकता है? मेरी समझ यह है कि मैं अपने कोड से एक सरल एसएसएल कॉल कर सकता हूं और डायनामिक एंडपॉइंट को यूआरएल मिलान के आधार पर सभी आउटगोइंग अनुरोधों को रोकना चाहिए। क्या वो सही है? – CodeClimber

7

CXF इस्तेमाल किया। (: HttpConduit.getTlsClientParameters() अशक्त हो सकता है कारण):

कोशिश अपने स्प्रिंग config को यह जोड़ने

<http-conf:conduit name="*.http-conduit"> 
    <http-conf:tlsClientParameters useHttpsURLConnectionDefaultSslSocketFactory="true"/> 
</http-conf:conduit> 
+0

धन्यवाद, यह मेरे लिए काम करता है! - [WAS 8] [सीएक्सएफ 2.7.18] – DaniEll

+0

मेरे लिए भी काम करता है ... क्लाइंट डायनामिक रूप से क्लाइंट बनाने के लिए प्रॉक्सी फैक्ट्रीबीन का उपयोग करते समय भी [WAS 8.5] [सीएक्सएफ 3.1.8] –

2

beny23 के समाधान WAS7 पर मेरे लिए अच्छा काम करता है, तो निम्न संशोधनों के साथ

बदलें इस भाग:

TLSClientParameters tlsClientParameters = httpConduit.getTlsClientParameters(); 
    if (tlsClientParameters != null) { 
     tlsClientParameters.setSSLSocketFactory(factory); 
    } 
इस के साथ

:

TLSClientParameters tlsClientParameters = httpConduit.getTlsClientParameters(); 
    if (tlsClientParameters == null) { 
     tlsClientParameters = new TLSClientParameters(); 
     httpConduit.setTlsClientParameters(tlsClientParameters); 
    } 
    tlsClientParameters.setSSLSocketFactory(factory); 
संबंधित मुद्दे