일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- PageControl
- FlexiblePageView
- V8 Engine
- so file
- Google V8 Engine
- v8 engine xcode build
- java
- embedd
- 안드로이드
- sha1 convert hashkey
- android log dump
- SO 파일
- Push
- 인증서 정보 뽑아내기
- appbarlayout
- 공인인증서 정보
- apns
- Android NDK시스템
- IMAGE
- ios
- Magnify Anim
- apache
- Objective C
- IOS10
- Status Bar
- 공인인증서 만료일
- ios framework
- JavaScript Engine
- apk 다운사이징
- Android
- Today
- Total
caTea 블로그
Android SSL 처리 클래스(https) 본문
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.security.cert.X509Certificate;
import javax.net.SocketFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
public class HTTPSSocketFactory extends SSLSocketFactory {
private SSLSocketFactory factory;
String suites[] = {//서버에 설정된 키 넣어주면된다.
"SSL_RSA_WITH_RC4_128_MD5",
};
public HTTPSSocketFactory() {
try {
SSLContext sslcontext = null;
if (sslcontext == null) {
sslcontext = SSLContext.getInstance("TLSv1");
sslcontext.init(null, new TrustManager[] { new CustomTrustManager() }, new java.security.SecureRandom());
}
factory = (SSLSocketFactory) sslcontext.getSocketFactory();
} catch (Exception e) {
e.printStackTrace();
}
}
public static SocketFactory getDefault() {
return new HTTPSSocketFactory();
}
public Socket createSocket(Socket socket, String s, int i, boolean flag) throws IOException {
SSLSocket sock = (SSLSocket)factory.createSocket(socket, s, i, flag);
sock.setEnabledCipherSuites(suites);
return sock;
}
public Socket createSocket(InetAddress inaddr, int i, InetAddress inaddr1, int j) throws IOException {
SSLSocket sock = (SSLSocket)factory.createSocket(inaddr, i, inaddr1, j);
sock.setEnabledCipherSuites(suites);
return sock;
}
public Socket createSocket(InetAddress inaddr, int i) throws IOException {
SSLSocket sock = (SSLSocket)factory.createSocket(inaddr, i);
sock.setEnabledCipherSuites(suites);
return sock;
}
public Socket createSocket(String s, int i, InetAddress inaddr, int j) throws IOException {
SSLSocket sock = (SSLSocket)factory.createSocket(s, i, inaddr, j);
sock.setEnabledCipherSuites(suites);
return sock;
}
public Socket createSocket(String s, int i) throws IOException {
SSLSocket sock = (SSLSocket)factory.createSocket(s, i);
sock.setEnabledCipherSuites(suites);
return sock;
}
public String[] getDefaultCipherSuites() {
return suites;
}
public String[] getSupportedCipherSuites() {
return suites;
}
public class CustomTrustManager implements X509TrustManager {
public void checkClientTrusted(X509Certificate[] cert, String authType) {
return;
}
public void checkServerTrusted(X509Certificate[] cert, String authType) {
return;
}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
}
}
요즘 롤리팝에 문제가 많다고한다.
보안이 강화되었다는건데 https통신을 할때 이 클래스가 필요하다고 한다.
나중에 자세하게 분석해야겠다
HttpsURLConnection conn1 = (HttpsURLConnection) new URL(m_context.getResources().getString(R.string.op_server_url_oper)).openConnection();
conn1.setSSLSocketFactory(new HTTPSSocketFactory());
요렇게 사용하면된다
'android' 카테고리의 다른 글
android status bar color 변경(4.4)버전 이상 (0) | 2015.06.23 |
---|---|
Android 인앱결제 구현하기 (0) | 2015.06.22 |
Android ListView 마지막 도착시 데이터 불러오기 코드 (0) | 2015.06.17 |
Android Null Check 코드 (0) | 2015.06.17 |
Android 버튼 duplicate 방지코드 (0) | 2015.06.17 |