많은 시간을 들인 게시글입니다. 

무단으로 복사해서 게시하지 말아 주세요.


1.에러발생 

앞선 글에서 자체 인증서를 통한 Retrofit 통신 시

발생하는 에러에 대한 해결을 올렸다. 

 

 

[Android] Retrofit - SSL 에러 해결 : Trust anchor for certification path not found.

 

[Android] Retrofit - SSL 에러 해결 : Trust anchor for certification path not found.

많은 시간을 들인 게시글입니다. 무단으로 복사해서 게시하지 말아 주세요. 앱과 서버를 만들어서 HTTP로 통신하게 만들었다. 만들고 나니 HTTPS로 통신하게 만들고 싶어 졌다. 그리고 문제가 생겼

kyome.tistory.com

 

이 문제의 연장선으로 자체인증서를 가진 서버에

Glide를 이용해 HTTPS URL로 이미지를 가져오려고 하면 

다음과 같은 에러가 발생한다.

 

 

 

 

 

"I/Glide: Root cause (1 of 1) javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found."

 

 

 

 

그리고 화면은 아래와 같이 아무 이미지도 가져오지 못한다.

 

 

 

 

 

 

2. 해결 방안

Glide에 지정한 OkHttpClient를 가지고

통신하게 코드를 변경해주면 된다.

 

OkHttpClient에 설정을 변경하여

자체 인증서를 사용하는 서버와 HTTPS 통신이

가능하게 해주고 (이전 게시글에서 적용했던 방식)

이렇게 만든 OkHttpClient를 Glide 통신할 때 사용하도록

지정해주면 해결할 수 있다.

 

 

 

 

3. 상세 방법 및 소스

1) OkHttpClient 세팅 클래스 선언

 

이전 게시글에서 

 

[Android] Retrofit - SSL 에러 해결 : Trust anchor for certification path not found.

많은 시간을 들인 게시글입니다. 무단으로 복사해서 게시하지 말아 주세요. 앱과 서버를 만들어서 HTTP로 통신하게 만들었다. 만들고 나니 HTTPS로 통신하게 만들고 싶어 졌다. 그리고 문제가 생겼

kyome.tistory.com

 

4. 상세 방법 및 소스

  1) raw 디렉터리에 crt 인증서 넣기

  2) 자체 인증 빌더 클래스 생성

  4) Hostname (ip) not verified 에러

 

까지 작업해두기 

 

 

 

 

 

 

 

 

 

 

 

2) build.grade 에 dependency 추가

 

// build.gradle (:app)

dependencies {
	...
	
    implementation 'com.github.bumptech.glide:okhttp3-integration:4.6.1'
	
    ...
}

 

 

 

 

3) GlideModule 클래스 생성

 

@GlideModule
public class SSLGlideModule extends AppGlideModule {
    @Override
    public void registerComponents(
    	@NonNull Context context,
        @NonNull Glide glide, 
        @NonNull Registry registry) {
        
          super.registerComponents(context, glide, registry);

          // OkHttpClient Builder에 
          // 자체인증서 HTTPS 통신하도록 설정
          SelfSigningHelper helper = SelfSigningHelper.getInstance();
          OkHttpClient.Builder builder = new OkHttpClient.Builder();
          helper.setSSLOkHttp( builder,"10.0.2.2");

          registry.replace(GlideUrl.class, InputStream.class,
          	new OkHttpUrlLoader.Factory(builder.build()));
    }
}

 

참고자료 : Gilide공식문서

 

Glide v4 : Configuration

Setup Starting in Glide 4.9.0, setup is required in a couple of cases. For applications, setup is only required if the application wants to: Use one or more integration libraries Change Glide’s configuration (disk cache size/location, memory cache size e

bumptech.github.io

 

 

 

 

5) 사용하기

 

이렇게 준비했다면 사용하는 건 완전히 동일하다.

 

Glide.with(getApplicationContext())
  .load(Config.BASE_URL).into(imageView);

 

 

 


 

 

 

 

도움이 되는 글이었다면

로그인이 필요없는 공감 버튼 꾹 눌러주세요! 

 

 

 

 

+ Recent posts

"여기"를 클릭하면 광고 제거.