2017-02-26 6 views
6

मेरे पास एंड्रॉइड एप्लिकेशन है जो अधिकांश उपकरणों के लिए ठीक काम कर रहा था हाल ही में कुछ हैकर्स ने हमारे सर्वर पर डीडीओएस हमला करने की कोशिश की जो हमें कुछ सुरक्षा जोड़ने के लिए मजबूर करता है और कुछ फायरवॉलjavax.net.ssl.SSLException: एंड्रॉइड पुराने डिवाइस पर एसएसएल हैंडशेक निरस्त

नहीं कुछ उपकरणों काम कर रहा है और मुझे निम्न अपवाद

javax.net.ssl.SSLException: SSL handshake aborted: ssl=0x63eb8240: I/O error during system call, Connection reset by peer 

देना नहीं कर रहे हैं कर सकते हैं किसी भी एक कृपया मुझे बताओ अब क्या समस्या है और मैं इसे कैसे हल कर सकते हैं?

संपादित

यह मेरा निष्पादित विधि का कोड

public static BaseResponse execute(Context context, BaseRequest request) { 

    mStartTime = System.nanoTime(); 

    BaseResponse response = new BaseResponse(); 
    DataOutputStream outputStream; 
    try { 
     URL url = new URL(request.getURL()); 
     HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection(); 
     urlConnection.setConnectTimeout(TIMEOUT_DURATION); 
     urlConnection.setReadTimeout(TIMEOUT_DURATION); 
     urlConnection.setRequestMethod(request.getRequestType().getValue()); 
     urlConnection.addRequestProperty("Accept", "application/json"); 
     urlConnection.addRequestProperty("Content-Type","application/json"); 
     urlConnection.setRequestProperty("Accept-Charset", CHARACTER_SET); 
     urlConnection.addRequestProperty("Device-Id", PhoneUtils.getDeviceId(context)); 
     urlConnection.addRequestProperty("Version-Number", PhoneUtils.getAppVersion(context)); 


     TLSSocketFactory socketFactory = new TLSSocketFactory(); 
     urlConnection.setSSLSocketFactory(socketFactory); 

     switch (request.getRequestType()) { 
      case POST: 
      case PUT: 
       urlConnection.setDoOutput(true); 
       if (request.getStringEntity() != null) { 
        outputStream = new DataOutputStream(urlConnection.getOutputStream()); 
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream, CHARACTER_SET)); 
        writer.write(request.getStringParam()); 
        writer.close(); 
        outputStream.flush(); 
        outputStream.close(); 
       } 

       break; 
      case GET: 
       urlConnection.setDoOutput(false); 
       break; 
     } 

     urlConnection.connect(); 

     try { 
      if (urlConnection.getResponseCode() == STATUS_OK) { 
       InputStream inputStream = new BufferedInputStream(urlConnection.getInputStream()); 
       BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); 
       StringBuilder result = new StringBuilder(); 
       String line; 
       while ((line = reader.readLine()) != null) { 
        result.append(line); 
       } 

       inputStream.close(); 
       response.setResponse(convertStringToJSONObject(result.toString())); 
      } else { 
       response.setResponse(null); 
      } 
     } catch (Exception ex) { 
      response.setAppError(AppError.DATA_ERROR); 
     } 
    } catch (MalformedURLException e) { 
     e.printStackTrace(); 
     response.setAppError(AppError.PARSING_ERROR); 
    } catch (IOException e) { 
     e.printStackTrace(); 
     response.setAppError(AppError.DATA_ERROR); 
    } catch (Exception e) { 
     e.printStackTrace(); 
     response.setAppError(AppError.DATA_ERROR); 
    } 

    return response; 
} 
+0

[javax.net.ssl.SSLException का संभावित डुप्लिकेट: त्रुटि पढ़ें: एसएसएल = 0x9524b800: सिस्टम कॉल के दौरान I/O त्रुटि, सहकर्मी द्वारा कनेक्शन रीसेट] (http://stackoverflow.com/questions/30538640/javax-net-ssl-sslexception-read-error-ssl-0x9524b800-io-error-during-system) – halileohalilei

उत्तर

16

उपयोग और कोड के इस टुकड़े मेरी समस्या हल । एफवाईआई: मैं नेटवर्क कॉल बनाने के लिए रेट्रोफिट लाइब्रेरी का उपयोग कर रहा था

+0

आपको बहुत धन्यवाद, आपने मेरा दिन बचाया :) –

+3

@ अरशद क्या आप समझा सकते हैं कि यह समस्या क्यों हल करता है और समस्या का कारण क्या है? – sasuke

2

विभिन्न Android API लेवल एसएसएल के लिए अलग अलग समर्थन है/TLS संस्करणों प्रोटोकॉल, विवरण के लिए Android documention में देखते हैं - https://developer.android.com/reference/javax/net/ssl/SSLSocket.html

टीएलएस 1.1 और 1.2 को सक्षम करने के लिए आपको एक कस्टम SSLSocketFactory बनाने की आवश्यकता है - https://blog.dev-area.net/2015/08/13/android-4-1-enable-tls-1-1-and-tls-1-2/

public class TLSSocketFactory extends SSLSocketFactory { 

    private SSLSocketFactory internalSSLSocketFactory; 

    public TLSSocketFactory() throws KeyManagementException, NoSuchAlgorithmException { 
     SSLContext context = SSLContext.getInstance("TLS"); 
     context.init(null, null, null); 
     internalSSLSocketFactory = context.getSocketFactory(); 
    } 

    @Override 
    public String[] getDefaultCipherSuites() { 
     return internalSSLSocketFactory.getDefaultCipherSuites(); 
    } 

    @Override 
    public String[] getSupportedCipherSuites() { 
     return internalSSLSocketFactory.getSupportedCipherSuites(); 
    } 

    @Override 
    public Socket createSocket() throws IOException { 
     return enableTLSOnSocket(internalSSLSocketFactory.createSocket()); 
    } 

    @Override 
    public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException { 
     return enableTLSOnSocket(internalSSLSocketFactory.createSocket(s, host, port, autoClose)); 
    } 

    @Override 
    public Socket createSocket(String host, int port) throws IOException, UnknownHostException { 
     return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port)); 
    } 

    @Override 
    public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException, UnknownHostException { 
     return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port, localHost, localPort)); 
    } 

    @Override 
    public Socket createSocket(InetAddress host, int port) throws IOException { 
     return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port)); 
    } 

    @Override 
    public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException { 
     return enableTLSOnSocket(internalSSLSocketFactory.createSocket(address, port, localAddress, localPort)); 
    } 

    private Socket enableTLSOnSocket(Socket socket) { 
     if(socket != null && (socket instanceof SSLSocket)) { 
      ((SSLSocket)socket).setEnabledProtocols(new String[] {"TLSv1.1", "TLSv1.2"}); 
     } 
     return socket; 
    } 
} 

और फिर अपने संबंध में इसका इस्तेमाल करते हैं यह किसी भी नेटवर्क कॉल

/** 
* Initialize SSL 
* @param mContext 
*/ 
public static void initializeSSLContext(Context mContext){ 
    try { 
     SSLContext.getInstance("TLSv1.2"); 
    } catch (NoSuchAlgorithmException e) { 
     e.printStackTrace(); 
    } 
    try { 
     ProviderInstaller.installIfNeeded(mContext.getApplicationContext()); 
    } catch (GooglePlayServicesRepairableException e) { 
     e.printStackTrace(); 
    } catch (GooglePlayServicesNotAvailableException e) { 
     e.printStackTrace(); 
    } 
} 

करने से पहले अपने कोड में मैं एक ही समस्या थी

HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); 
TLSSocketFactory socketFactory = new TLSSocketFactory(); 
conn.setSSLSocketFactory(socketFactory); 
conn.connect(); 
+0

मैं इसे आज़माउंगा और आपको वापस ले जाऊंगा –

+0

HttpURLConnection में कोई विधि नहीं है setSSLSocketFactory कहा जाता है, एंड्रॉइड का संस्करण क्या है जिसे आप लक्षित कर रहे हैं? –

+0

HttpsURLConnection - https://developer.android.com/reference/javax/net/ssl/HttpsURLConnection.html – kb0

संबंधित मुद्दे