2011-10-06 5 views
4

나는 많은 옵션을 시도했으며, 나는 미쳐 갈 것입니다. URL에 게시하려고 할 때마다 SSL 예외가 계속 발생합니다.Android HTTPS 요청

이것은 HttpWebRequest를 사용하는 C#의 꿈처럼 작동합니다. 내가 할

오류는 다음과 같습니다

Not trusted server certificate 
java.security.cert.CertPathValidatorException: TrustAnchor for CertPath not found. 

지금은 다음과 같은 방법을 시도하고있다,하지만, 모든 사용자 정의 SocketFactories을 시도했습니다. 도와주세요!

final String httpsURL = "https://..."; 
    final DefaultHttpClient client = new DefaultHttpClient(); 
    final HttpPost httppost = new HttpPost(httpsURL); 

    //authentication block: 
    final List<BasicNameValuePair> nvps = new ArrayList<BasicNameValuePair>(); 
    nvps.add(new BasicNameValuePair("mail", username)); 
    nvps.add(new BasicNameValuePair("password", password)); 
    UrlEncodedFormEntity p_entity = null; 
    try { 
     p_entity = new UrlEncodedFormEntity(nvps, HTTP.UTF_8); 
    } catch (UnsupportedEncodingException e1) { 
     // TODO Auto-generated catch block 
     e1.printStackTrace(); 
    } 
    httppost.setEntity(p_entity); 

    //sending the request and retrieving the response: 
    HttpResponse response = null; 
    try { 
     response = client.execute(httppost, _context); 
    } catch (ClientProtocolException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    HttpEntity responseEntity = response.getEntity(); 

    //handling the response: responseEntity.getContent() is your InputStream 
    try { 
     final InputSource inputSource = new InputSource(responseEntity.getContent()); 
    } catch (IllegalStateException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
+0

, 나는이 작품 같은 요청을하기 위해 자바 키 저장소에 인증서를 추가했다. – mikey

+0

@mikey, 내가 통과 한 인증서를 찾는 방법은 무엇입니까? – Benny

+0

나는 당신이 인증서를 건네 준다고 믿지 않습니다. 서버가 제공 한 인증서가 신뢰할 수 있는지 확인해야합니다. C# 및 HttpRequest는 java와 다른 인증서 저장소에 대한 https 요청의 유효성을 검사합니다. 이것은 좋은 리소스 인 것처럼 보입니다. http://blog.antoine.li/index.php/2010/10/android-trusting-ssl-certificates/ – mikey

답변

1

Android에서 인증서의 유효성을 어떻게 결정할 지 고려해야합니다. 인증서를 확인해야 할 때 서명 체인을 볼 것입니다. 맨 위에 신뢰할 수있는 권한을 찾을 수 있고 해지 목록에없는 인증서는 신뢰할 수 있습니다.

시간이 많이 소요되는 쿼리를 줄이기 위해 안드로이드는 신뢰할 수있는 일반적인 CA 목록을 번들로 제공합니다. 의견에서 언급했듯이 업그레이드 할 때 오류가 사라졌습니다. 이는 사용중인 CA가 제공되는 신뢰할 수있는 CA 목록에 추가되기 때문일 가능성이 큽니다.

인증서를 신뢰할 수 있으면 신뢰할 수있는 CA 목록에 추가 할 수 있습니다. accepted answer ~ this question에는 이전 버전에 대한이 절차에 대한 세부 정보가 있습니다! 최신 버전에는 필요한 인증서가 더 많이 제공됩니다. 최신 버전에서는 SD 카드에서 직접 인증서를 설치할 수 있습니다. Settings -> Security으로 이동하십시오. Credential storage 아래에 Install from device storage 옵션이 있습니다. 표준 형식을 사용하는 한 인증서를 설치해야합니다.

내 소스 : 과거 Security with HTTPS and SSL | Android Developers