SSLHandshakeException - Chain chain validation failed, how to solve?
in my application I am trying to do a HTTPS POST request to my server.
However, I keep getting SSLHandshakeException - Chain chain validation failed, all the time. I tried to send a request using POSTMAN and I got a response from the server. What can be causing this error when I try to send the request from the application?
Here a code snippet where I try to send the post request:
public static JSONObject getDataLibConfiguration(Context context) throws HttpRequestException {
int statusCode = 0;
JSONObject commonInformation;
HttpsURLConnection connection = null;
try
commonInformation = ConfigurationProcessor.getCommonInformation(context);
if (commonInformation == null)
return null;
URL url = new URL(BuildConfig.SERVER_CONFIG_URL);
if (BuildConfig.DEBUG)
LogUtils.d(TAG, "url = " + url.getPath());
connection = getHttpsConnection(url);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
connection.setRequestProperty("Content-Encoding", "gzip");
byte gzipped = HttpUtils.gzip(commonInformation.toString());
cos = new CountingOutputStream(connection.getOutputStream()); //<-- This is where I get the exception
cos.write(gzipped);
cos.flush();
statusCode = connection.getResponseCode();
// More code her
private static HttpsURLConnection getHttpsConnection(URL url) throws IOException, GeneralSecurityException
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
try
SSLContext sslContext = SSLContext.getInstance("TLS");
MatchDomainTrustManager myTrustManager = new MatchDomainTrustManager(url.getHost());
TrustManager tms = new TrustManagermyTrustManager;
sslContext.init(null, tms, null);
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
connection.setSSLSocketFactory(sslSocketFactory);
catch (AssertionError ex)
if (BuildConfig.DEBUG)
LogFileUtils.e(TAG, "Exception in getHttpsConnection: " + ex.getMessage());
LogUtils.e(TAG, "Exception: " + ex.toString());
return connection;
add a comment |
in my application I am trying to do a HTTPS POST request to my server.
However, I keep getting SSLHandshakeException - Chain chain validation failed, all the time. I tried to send a request using POSTMAN and I got a response from the server. What can be causing this error when I try to send the request from the application?
Here a code snippet where I try to send the post request:
public static JSONObject getDataLibConfiguration(Context context) throws HttpRequestException {
int statusCode = 0;
JSONObject commonInformation;
HttpsURLConnection connection = null;
try
commonInformation = ConfigurationProcessor.getCommonInformation(context);
if (commonInformation == null)
return null;
URL url = new URL(BuildConfig.SERVER_CONFIG_URL);
if (BuildConfig.DEBUG)
LogUtils.d(TAG, "url = " + url.getPath());
connection = getHttpsConnection(url);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
connection.setRequestProperty("Content-Encoding", "gzip");
byte gzipped = HttpUtils.gzip(commonInformation.toString());
cos = new CountingOutputStream(connection.getOutputStream()); //<-- This is where I get the exception
cos.write(gzipped);
cos.flush();
statusCode = connection.getResponseCode();
// More code her
private static HttpsURLConnection getHttpsConnection(URL url) throws IOException, GeneralSecurityException
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
try
SSLContext sslContext = SSLContext.getInstance("TLS");
MatchDomainTrustManager myTrustManager = new MatchDomainTrustManager(url.getHost());
TrustManager tms = new TrustManagermyTrustManager;
sslContext.init(null, tms, null);
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
connection.setSSLSocketFactory(sslSocketFactory);
catch (AssertionError ex)
if (BuildConfig.DEBUG)
LogFileUtils.e(TAG, "Exception in getHttpsConnection: " + ex.getMessage());
LogUtils.e(TAG, "Exception: " + ex.toString());
return connection;
What is the error in LogCat?
– astric mobiles
Nov 12 '18 at 16:54
It just says: "java.security.cert.CertificateException: Chain validation failed"
– Keselme
Nov 12 '18 at 16:58
add a comment |
in my application I am trying to do a HTTPS POST request to my server.
However, I keep getting SSLHandshakeException - Chain chain validation failed, all the time. I tried to send a request using POSTMAN and I got a response from the server. What can be causing this error when I try to send the request from the application?
Here a code snippet where I try to send the post request:
public static JSONObject getDataLibConfiguration(Context context) throws HttpRequestException {
int statusCode = 0;
JSONObject commonInformation;
HttpsURLConnection connection = null;
try
commonInformation = ConfigurationProcessor.getCommonInformation(context);
if (commonInformation == null)
return null;
URL url = new URL(BuildConfig.SERVER_CONFIG_URL);
if (BuildConfig.DEBUG)
LogUtils.d(TAG, "url = " + url.getPath());
connection = getHttpsConnection(url);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
connection.setRequestProperty("Content-Encoding", "gzip");
byte gzipped = HttpUtils.gzip(commonInformation.toString());
cos = new CountingOutputStream(connection.getOutputStream()); //<-- This is where I get the exception
cos.write(gzipped);
cos.flush();
statusCode = connection.getResponseCode();
// More code her
private static HttpsURLConnection getHttpsConnection(URL url) throws IOException, GeneralSecurityException
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
try
SSLContext sslContext = SSLContext.getInstance("TLS");
MatchDomainTrustManager myTrustManager = new MatchDomainTrustManager(url.getHost());
TrustManager tms = new TrustManagermyTrustManager;
sslContext.init(null, tms, null);
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
connection.setSSLSocketFactory(sslSocketFactory);
catch (AssertionError ex)
if (BuildConfig.DEBUG)
LogFileUtils.e(TAG, "Exception in getHttpsConnection: " + ex.getMessage());
LogUtils.e(TAG, "Exception: " + ex.toString());
return connection;
in my application I am trying to do a HTTPS POST request to my server.
However, I keep getting SSLHandshakeException - Chain chain validation failed, all the time. I tried to send a request using POSTMAN and I got a response from the server. What can be causing this error when I try to send the request from the application?
Here a code snippet where I try to send the post request:
public static JSONObject getDataLibConfiguration(Context context) throws HttpRequestException {
int statusCode = 0;
JSONObject commonInformation;
HttpsURLConnection connection = null;
try
commonInformation = ConfigurationProcessor.getCommonInformation(context);
if (commonInformation == null)
return null;
URL url = new URL(BuildConfig.SERVER_CONFIG_URL);
if (BuildConfig.DEBUG)
LogUtils.d(TAG, "url = " + url.getPath());
connection = getHttpsConnection(url);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
connection.setRequestProperty("Content-Encoding", "gzip");
byte gzipped = HttpUtils.gzip(commonInformation.toString());
cos = new CountingOutputStream(connection.getOutputStream()); //<-- This is where I get the exception
cos.write(gzipped);
cos.flush();
statusCode = connection.getResponseCode();
// More code her
private static HttpsURLConnection getHttpsConnection(URL url) throws IOException, GeneralSecurityException
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
try
SSLContext sslContext = SSLContext.getInstance("TLS");
MatchDomainTrustManager myTrustManager = new MatchDomainTrustManager(url.getHost());
TrustManager tms = new TrustManagermyTrustManager;
sslContext.init(null, tms, null);
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
connection.setSSLSocketFactory(sslSocketFactory);
catch (AssertionError ex)
if (BuildConfig.DEBUG)
LogFileUtils.e(TAG, "Exception in getHttpsConnection: " + ex.getMessage());
LogUtils.e(TAG, "Exception: " + ex.toString());
return connection;
asked Nov 12 '18 at 15:25
KeselmeKeselme
350217
350217
What is the error in LogCat?
– astric mobiles
Nov 12 '18 at 16:54
It just says: "java.security.cert.CertificateException: Chain validation failed"
– Keselme
Nov 12 '18 at 16:58
add a comment |
What is the error in LogCat?
– astric mobiles
Nov 12 '18 at 16:54
It just says: "java.security.cert.CertificateException: Chain validation failed"
– Keselme
Nov 12 '18 at 16:58
What is the error in LogCat?
– astric mobiles
Nov 12 '18 at 16:54
What is the error in LogCat?
– astric mobiles
Nov 12 '18 at 16:54
It just says: "java.security.cert.CertificateException: Chain validation failed"
– Keselme
Nov 12 '18 at 16:58
It just says: "java.security.cert.CertificateException: Chain validation failed"
– Keselme
Nov 12 '18 at 16:58
add a comment |
1 Answer
1
active
oldest
votes
The problem was that the certificate was expired.
add a comment |
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',
autoActivateHeartbeat: false,
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265234%2fsslhandshakeexception-chain-chain-validation-failed-how-to-solve%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
The problem was that the certificate was expired.
add a comment |
The problem was that the certificate was expired.
add a comment |
The problem was that the certificate was expired.
The problem was that the certificate was expired.
answered Nov 14 '18 at 10:11
KeselmeKeselme
350217
350217
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265234%2fsslhandshakeexception-chain-chain-validation-failed-how-to-solve%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
What is the error in LogCat?
– astric mobiles
Nov 12 '18 at 16:54
It just says: "java.security.cert.CertificateException: Chain validation failed"
– Keselme
Nov 12 '18 at 16:58