방금이 문제를 해결했습니다. 안드로이드 용 Parse SDK는 SelfSigned 인증서의 상자 지원과 함께 제공되지 않습니다. 코드를 직접 수정해야합니다.
첫 번째 단계는 - 대상 지원은 다음 버전에 대한 KITKAT 더 고급 인 경우 코드의 관련 부분은 ParseHttpClient
public static ParseHttpClient createClient(int socketOperationTimeout,
SSLSessionCache sslSessionCache) {
String httpClientLibraryName;
ParseHttpClient httpClient;
if (hasOkHttpOnClasspath()) {
httpClientLibraryName = OKHTTP_NAME;
httpClient = new ParseOkHttpClient(socketOperationTimeout, sslSessionCache);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
httpClientLibraryName = URLCONNECTION_NAME;
httpClient = new ParseURLConnectionHttpClient(socketOperationTimeout, sslSessionCache);
} else {
httpClientLibraryName = APACHE_HTTPCLIENT_NAME;
httpClient = new ParseApacheHttpClient(socketOperationTimeout, sslSessionCache);
}
PLog.i(TAG, "Using " + httpClientLibraryName + " library for networking communication.");
return httpClient; }
에 - 은 그럼 당신은 ParseURLConnectionHttpClient 생성자에 추가해야합니다
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier(){
public boolean verify(String hostname, SSLSession session) {
if(hostname.equals("YOUR TARGET SERVER")) {
return true;
}
return false;
}});
다른 경우 (이전 버전) 코드가 아파치로 떨어질 것이므로 그 코드로 작업 할 수 없었습니다. 따라서 다음을 수행했습니다. 내 앱에 okhttp 라이브러리를 추가했습니다 (버전 2.4 사용 - 동일한 구문 분석이 그 빌드, 가장 최근의 패키지 이름이 다른 경우) 경로에서 okhttp를 찾을 것이므로 코드가 첫 번째 조건으로 이동합니다. if 조건 순서를 바꿔서 KITKAT보다 적은 버전에서만 발생할 수 있습니다. ParseOkHttpClient는 다음과 같은 자체 서명 된 인증서 코드 추가에
:
public void initCert() {
try {
Log.i("PARSE","initCert");
CertificateFactory cf = CertificateFactory.getInstance("X.509");
String yairCert = "-----BEGIN CERTIFICATE-----\n" +
YOUR CERTIFICATE HERE
"-----END CERTIFICATE-----\n";
InputStream caInput = new ByteArrayInputStream(yairCert.getBytes());
Certificate ca = null;
try {
ca = cf.generateCertificate(caInput);
System.out.println("ca=" + ((X509Certificate) ca).getSubjectDN());
} catch (CertificateException e) {
e.printStackTrace();
} finally {
try {
caInput.close();
} catch (IOException e) {
Log.e("PARSE_BUG","Failure on Cert installing",e);
e.printStackTrace();
}
}
// Create a KeyStore containing our trusted CAs
String keyStoreType = KeyStore.getDefaultType();
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
keyStore.load(null, null);
keyStore.setCertificateEntry("ca", ca);
// Create a TrustManager that trusts the CAs in our KeyStore
String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
tmf.init(keyStore);
// Create an SSLContext that uses our TrustManager
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, tmf.getTrustManagers(), null);
Log.i("PARSE","Initiating Self Signed cert");
okHttpClient.setSslSocketFactory(context.getSocketFactory());
try {
cf = CertificateFactory.getInstance("X.509");
} catch (CertificateException e) {
Log.e("PARSE_BUG","Failure on Cert installing",e);
e.printStackTrace();
}
} catch (IOException e) {
Log.e("PARSE_BUG","Failure on Cert installing",e);
e.printStackTrace();
} catch (CertificateException e) {
Log.e("PARSE_BUG","Failure on Cert installing",e);
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
Log.e("PARSE_BUG","Failure on Cert installing",e);
e.printStackTrace();
} catch (KeyStoreException e) {
Log.e("PARSE_BUG","Failure on Cert installing",e);
e.printStackTrace();
} catch (KeyManagementException e) {
Log.e("PARSE_BUG","Failure on Cert installing",e);
e.printStackTrace();
}
그리고 마지막 부분은, 그것은 너무 생성자에서 발생해야이 메서드를 호출 + 호스트 이름을 확인합니다. initCert(); } false를 반환 (대해서는 s.equals ("대상 서버")) 사실 { 반환하는 경우 okHttpClient.setHostnameVerifier (새의 HostnameVerifier() { @Override 공공 부울() { 를 문자열의, SSLSession에있는 SSLSession을 확인; } });
그게 전부입니다. PARSE를 로컬에서 빌드하고 앱에 배포하면 매력처럼 작동합니다.
즐기기
제목에 오타를 수정해야합니다. – Croc