title: Problem with “Trust anchor for certification path not found.”
body: <p>Hello i didn't found solution for my problem. In new OkHttp and Retrofit is some function:</p>
  <pre><code> HandshakeCertificates certificates =  new HandshakeCertificates.Builder()
                          .addPlatformTrustedCertificates()
                          .addInsecureHost(&quot;192.168.0.150&quot;)
                          .build();
  </code></pre>
  <p>I am trying to connect my Android App to Spring Boot Server. This Server must use HTTPS - not my idea.
  On this server i generated self-sign certyficate, but still i got error, now i don't have any ideas. Here is a full error:
  <code>java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.</code>
  Below i insert code of Retrofit generator:</p>
  <pre><code>public class ServiceGenerator {
      public static final String API_BASE_URL = &quot;https://192.168.0.150:8443/&quot;;
      private static OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
      // private static OkHttpClient httpClient = getUnsafeOkHttpClient();
  
      private static Retrofit.Builder builder =
              new Retrofit.Builder()
                      .baseUrl(API_BASE_URL)
                      .addConverterFactory(GsonConverterFactory.create());
  
      private static Retrofit retrofit = builder.build();
  
      public static &lt;S&gt; S createService(Class&lt;S&gt; serviceClass) {
          return createService(serviceClass, null);
      }
  
      static public &lt;S&gt; S createService(
              Class&lt;S&gt; serviceClass, final String authToken) {
          if (!TextUtils.isEmpty(authToken)) {
              AuthenticationInterceptor interceptor =
                      new AuthenticationInterceptor(authToken);
  
              if (!httpClient.interceptors().contains(interceptor)) {
                  httpClient.addInterceptor(interceptor);
  
                  HandshakeCertificates certificates =  new HandshakeCertificates.Builder()
                          .addPlatformTrustedCertificates()
                          .addInsecureHost(&quot;192.168.0.150&quot;)
                          .build();
                  httpClient.sslSocketFactory(certificates.sslSocketFactory(), certificates.trustManager());
  
                  OkHttpClient okHttpClient = httpClient.build();
  
                  builder.client(okHttpClient);
                  retrofit = builder.build();
              }
          }
  
          return retrofit.create(serviceClass);
      }
  }
  </code></pre>
  <p>Request Code:</p>
  <pre><code> private void doLoginRequest() {
          DeviceAPI deviceAPI = ServiceGenerator.createService(DeviceAPI.class);
          Call&lt;JWTResponse&gt; call = deviceAPI.login(new Login(usernameEditText.getText().toString(), passwordEditText.getText().toString()));
          call.enqueue(new Callback&lt;JWTResponse&gt;() {
              @Override
              public void onResponse(Call&lt;JWTResponse&gt; call, Response&lt;JWTResponse&gt; response) {
                  if (response.isSuccessful()) {
                      Toast.makeText(LoginActivity.this, response.body().toString(), Toast.LENGTH_SHORT).show();
                  } else {
                      Toast.makeText(LoginActivity.this, response.message(), Toast.LENGTH_SHORT).show();
                  }
              }
  
              @Override
              public void onFailure(Call&lt;JWTResponse&gt; call, Throwable t) {
                  System.out.println(t.getCause());
                  Toast.makeText(LoginActivity.this, t.getMessage() , Toast.LENGTH_SHORT).show();
              }
          });
      }
  </code></pre>
  <p>Api Code:</p>
  <pre><code>public interface DeviceAPI {
      @POST(&quot;api/auth/signin&quot;)
      Call&lt;JWTResponse&gt; login(@Body Login login);
  }
  
  </code></pre>
  <p>If you need more information give me feedback!</p>