javax.net.ssl.SSLHandshakeException?











up vote
2
down vote

favorite












I'm trying to connect to a WCF server using HTTPS connection (UrlHttpsConnection class) and always get the error "Trust anchor for certification path not found".
I found thousands examples on the Web about that issue but nothing that really helps me.



My WCF service works with a certificate signed by an internal CA that has been added to the list of trusted CAs on my smartphone. If I call the url https://myserver/myservice/test from Chrome on my smartphone, I no longer have warning, the certificate is considered as valid. From my app, I keep getting the error message.



Do you know why my app does not consider the server certificate as valid while Chrome does ? How can I fix that ?



For security reasons, I don't want ignore the SSL verification.



Thank you in advance for your suggestions.










share|improve this question
























  • because when call api that time pass ssl certificate.
    – Android Team
    2 days ago















up vote
2
down vote

favorite












I'm trying to connect to a WCF server using HTTPS connection (UrlHttpsConnection class) and always get the error "Trust anchor for certification path not found".
I found thousands examples on the Web about that issue but nothing that really helps me.



My WCF service works with a certificate signed by an internal CA that has been added to the list of trusted CAs on my smartphone. If I call the url https://myserver/myservice/test from Chrome on my smartphone, I no longer have warning, the certificate is considered as valid. From my app, I keep getting the error message.



Do you know why my app does not consider the server certificate as valid while Chrome does ? How can I fix that ?



For security reasons, I don't want ignore the SSL verification.



Thank you in advance for your suggestions.










share|improve this question
























  • because when call api that time pass ssl certificate.
    – Android Team
    2 days ago













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I'm trying to connect to a WCF server using HTTPS connection (UrlHttpsConnection class) and always get the error "Trust anchor for certification path not found".
I found thousands examples on the Web about that issue but nothing that really helps me.



My WCF service works with a certificate signed by an internal CA that has been added to the list of trusted CAs on my smartphone. If I call the url https://myserver/myservice/test from Chrome on my smartphone, I no longer have warning, the certificate is considered as valid. From my app, I keep getting the error message.



Do you know why my app does not consider the server certificate as valid while Chrome does ? How can I fix that ?



For security reasons, I don't want ignore the SSL verification.



Thank you in advance for your suggestions.










share|improve this question















I'm trying to connect to a WCF server using HTTPS connection (UrlHttpsConnection class) and always get the error "Trust anchor for certification path not found".
I found thousands examples on the Web about that issue but nothing that really helps me.



My WCF service works with a certificate signed by an internal CA that has been added to the list of trusted CAs on my smartphone. If I call the url https://myserver/myservice/test from Chrome on my smartphone, I no longer have warning, the certificate is considered as valid. From my app, I keep getting the error message.



Do you know why my app does not consider the server certificate as valid while Chrome does ? How can I fix that ?



For security reasons, I don't want ignore the SSL verification.



Thank you in advance for your suggestions.







java android ssl ca






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago









Kling Klang

32.1k156287




32.1k156287










asked 2 days ago









n_stack

161




161












  • because when call api that time pass ssl certificate.
    – Android Team
    2 days ago


















  • because when call api that time pass ssl certificate.
    – Android Team
    2 days ago
















because when call api that time pass ssl certificate.
– Android Team
2 days ago




because when call api that time pass ssl certificate.
– Android Team
2 days ago












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Try this way but i used retrofit for api calling..



  public class ApiClient {
//public final static String BASE_URL = "https://prod.appowiz.com/app/services/";
public final static String BASE_URL_SECURE = "Pass your url";

public static ApiClient apiClient;

private Retrofit retrofit = null;
private static Retrofit storeRetrofit = null;

public Retrofit getClient(Context context) {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();

retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL_SECURE)
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();


return retrofit;
}
public static Retrofit getStore() {
if (storeRetrofit == null) {
final TrustManager trustAllCerts = new TrustManager{new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate chain, String authType) {

}


@Override
public void checkServerTrusted(java.security.cert.X509Certificate chain, String authType) {

}


@Override
public java.security.cert.X509Certificate getAcceptedIssuers() {

return new java.security.cert.X509Certificate[0];
}
}};

// Install the all-trusting trust manager
final SSLContext sslContext;
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
try {
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(interceptor)
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.sslSocketFactory(sslSocketFactory).hostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER)
.build();
storeRetrofit = new Retrofit.Builder()
.baseUrl(BASE_URL_SECURE)
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient)
.build();


} catch (NoSuchAlgorithmException | KeyManagementException e1) {
CustomLogHandler.printErrorlog(e1);
}

}

return storeRetrofit;
}


for api calling create interface..



public interface ApiInterface {

@POST("device/add_device_name")
Call<AddDeviceNameVo> addDeviceName(@Body JsonObject body);

}


called api into activity or fragment like this way..



        apiInterface = ApiClient.getStore().create(ApiInterface.class);





share|improve this answer





















  • more information refer this link square.github.io/retrofit
    – Android Team
    2 days ago











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409889%2fjavax-net-ssl-sslhandshakeexception%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Try this way but i used retrofit for api calling..



  public class ApiClient {
//public final static String BASE_URL = "https://prod.appowiz.com/app/services/";
public final static String BASE_URL_SECURE = "Pass your url";

public static ApiClient apiClient;

private Retrofit retrofit = null;
private static Retrofit storeRetrofit = null;

public Retrofit getClient(Context context) {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();

retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL_SECURE)
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();


return retrofit;
}
public static Retrofit getStore() {
if (storeRetrofit == null) {
final TrustManager trustAllCerts = new TrustManager{new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate chain, String authType) {

}


@Override
public void checkServerTrusted(java.security.cert.X509Certificate chain, String authType) {

}


@Override
public java.security.cert.X509Certificate getAcceptedIssuers() {

return new java.security.cert.X509Certificate[0];
}
}};

// Install the all-trusting trust manager
final SSLContext sslContext;
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
try {
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(interceptor)
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.sslSocketFactory(sslSocketFactory).hostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER)
.build();
storeRetrofit = new Retrofit.Builder()
.baseUrl(BASE_URL_SECURE)
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient)
.build();


} catch (NoSuchAlgorithmException | KeyManagementException e1) {
CustomLogHandler.printErrorlog(e1);
}

}

return storeRetrofit;
}


for api calling create interface..



public interface ApiInterface {

@POST("device/add_device_name")
Call<AddDeviceNameVo> addDeviceName(@Body JsonObject body);

}


called api into activity or fragment like this way..



        apiInterface = ApiClient.getStore().create(ApiInterface.class);





share|improve this answer





















  • more information refer this link square.github.io/retrofit
    – Android Team
    2 days ago















up vote
0
down vote













Try this way but i used retrofit for api calling..



  public class ApiClient {
//public final static String BASE_URL = "https://prod.appowiz.com/app/services/";
public final static String BASE_URL_SECURE = "Pass your url";

public static ApiClient apiClient;

private Retrofit retrofit = null;
private static Retrofit storeRetrofit = null;

public Retrofit getClient(Context context) {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();

retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL_SECURE)
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();


return retrofit;
}
public static Retrofit getStore() {
if (storeRetrofit == null) {
final TrustManager trustAllCerts = new TrustManager{new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate chain, String authType) {

}


@Override
public void checkServerTrusted(java.security.cert.X509Certificate chain, String authType) {

}


@Override
public java.security.cert.X509Certificate getAcceptedIssuers() {

return new java.security.cert.X509Certificate[0];
}
}};

// Install the all-trusting trust manager
final SSLContext sslContext;
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
try {
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(interceptor)
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.sslSocketFactory(sslSocketFactory).hostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER)
.build();
storeRetrofit = new Retrofit.Builder()
.baseUrl(BASE_URL_SECURE)
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient)
.build();


} catch (NoSuchAlgorithmException | KeyManagementException e1) {
CustomLogHandler.printErrorlog(e1);
}

}

return storeRetrofit;
}


for api calling create interface..



public interface ApiInterface {

@POST("device/add_device_name")
Call<AddDeviceNameVo> addDeviceName(@Body JsonObject body);

}


called api into activity or fragment like this way..



        apiInterface = ApiClient.getStore().create(ApiInterface.class);





share|improve this answer





















  • more information refer this link square.github.io/retrofit
    – Android Team
    2 days ago













up vote
0
down vote










up vote
0
down vote









Try this way but i used retrofit for api calling..



  public class ApiClient {
//public final static String BASE_URL = "https://prod.appowiz.com/app/services/";
public final static String BASE_URL_SECURE = "Pass your url";

public static ApiClient apiClient;

private Retrofit retrofit = null;
private static Retrofit storeRetrofit = null;

public Retrofit getClient(Context context) {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();

retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL_SECURE)
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();


return retrofit;
}
public static Retrofit getStore() {
if (storeRetrofit == null) {
final TrustManager trustAllCerts = new TrustManager{new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate chain, String authType) {

}


@Override
public void checkServerTrusted(java.security.cert.X509Certificate chain, String authType) {

}


@Override
public java.security.cert.X509Certificate getAcceptedIssuers() {

return new java.security.cert.X509Certificate[0];
}
}};

// Install the all-trusting trust manager
final SSLContext sslContext;
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
try {
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(interceptor)
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.sslSocketFactory(sslSocketFactory).hostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER)
.build();
storeRetrofit = new Retrofit.Builder()
.baseUrl(BASE_URL_SECURE)
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient)
.build();


} catch (NoSuchAlgorithmException | KeyManagementException e1) {
CustomLogHandler.printErrorlog(e1);
}

}

return storeRetrofit;
}


for api calling create interface..



public interface ApiInterface {

@POST("device/add_device_name")
Call<AddDeviceNameVo> addDeviceName(@Body JsonObject body);

}


called api into activity or fragment like this way..



        apiInterface = ApiClient.getStore().create(ApiInterface.class);





share|improve this answer












Try this way but i used retrofit for api calling..



  public class ApiClient {
//public final static String BASE_URL = "https://prod.appowiz.com/app/services/";
public final static String BASE_URL_SECURE = "Pass your url";

public static ApiClient apiClient;

private Retrofit retrofit = null;
private static Retrofit storeRetrofit = null;

public Retrofit getClient(Context context) {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();

retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL_SECURE)
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();


return retrofit;
}
public static Retrofit getStore() {
if (storeRetrofit == null) {
final TrustManager trustAllCerts = new TrustManager{new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate chain, String authType) {

}


@Override
public void checkServerTrusted(java.security.cert.X509Certificate chain, String authType) {

}


@Override
public java.security.cert.X509Certificate getAcceptedIssuers() {

return new java.security.cert.X509Certificate[0];
}
}};

// Install the all-trusting trust manager
final SSLContext sslContext;
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
try {
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(interceptor)
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.sslSocketFactory(sslSocketFactory).hostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER)
.build();
storeRetrofit = new Retrofit.Builder()
.baseUrl(BASE_URL_SECURE)
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient)
.build();


} catch (NoSuchAlgorithmException | KeyManagementException e1) {
CustomLogHandler.printErrorlog(e1);
}

}

return storeRetrofit;
}


for api calling create interface..



public interface ApiInterface {

@POST("device/add_device_name")
Call<AddDeviceNameVo> addDeviceName(@Body JsonObject body);

}


called api into activity or fragment like this way..



        apiInterface = ApiClient.getStore().create(ApiInterface.class);






share|improve this answer












share|improve this answer



share|improve this answer










answered 2 days ago









Android Team

7,17511033




7,17511033












  • more information refer this link square.github.io/retrofit
    – Android Team
    2 days ago


















  • more information refer this link square.github.io/retrofit
    – Android Team
    2 days ago
















more information refer this link square.github.io/retrofit
– Android Team
2 days ago




more information refer this link square.github.io/retrofit
– Android Team
2 days ago


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409889%2fjavax-net-ssl-sslhandshakeexception%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown