프로그래밍/Android

Android 4.4 에서 TLS 1.2 사용하기

freemmer 2019. 1. 24. 10:46
보안상의 이슈로 TLS 1.0 / 1.1 을 점점 더 지원하지 않는 서버가 많아지고 있습니다.
이때, TLS 1.2만을 지원하는 서버에는 Android 4.4가 접속하지 못하는 경우가 발생하고 있습니다. (SSL handshake aborted)

아래와 같이, Android 4.4도 스팩상으로는 TLS 1.2를 지원하지만 버그로 인해 SSLHandshakeException이 발생합니다.
(자세한 내용은 아래 Reference를 참고해 주세요)
그동안은 SSLSocketFactory를 상속받아 TLS1.2를 활성화한 SSLSocketFactory를 사용했지만 Chipher Suites의 종류에 따라 코딩하기가 번거로웠습니다.
그런데 Google에서 보안 공급자를 제공하는 방식으로 쉽게 해결이 가능하여 포스팅합니다.
위의 설명을 보면 TLS라는 단어는 나오지 않습니다만! 됩니다. 되요!
아래 코드를 앱 실행시에 호출해 주시면 됩니다. 간단하죠? :)
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.google.android.gms.security.ProviderInstaller;
try {
ProviderInstaller.installIfNeeded(getApplicationContext());
/**
* https://developer.android.com/training/articles/security-gms-provider.html
* this can take anywhere from 30-50 milliseconds (on more recent devices) to 350 ms (on older devices)
* keywords: installIfNeeded(), installIfNeededAsync()
*
* Once the Provider is updated, all calls to security APIs (including SSL APIs) are routed through it.
* (However, this does not apply to android.net.SSLCertificateSocketFactory,
* which remains vulnerable to such exploits as CVE-2014-0224.)
*
*/
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}


반응형