SSLHandshakeException - Chain chain validation failed, how to solve?










1















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;










share|improve this question






















  • 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















1















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;










share|improve this question






















  • 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













1












1








1








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;










share|improve this question














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;







android https sslhandshakeexception






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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

















  • 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












1 Answer
1






active

oldest

votes


















0














The problem was that the certificate was expired.






share|improve this answer






















    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
    );



    );













    draft saved

    draft discarded


















    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









    0














    The problem was that the certificate was expired.






    share|improve this answer



























      0














      The problem was that the certificate was expired.






      share|improve this answer

























        0












        0








        0







        The problem was that the certificate was expired.






        share|improve this answer













        The problem was that the certificate was expired.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 10:11









        KeselmeKeselme

        350217




        350217



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Kleinkühnau

            Makov (Slowakei)

            Deutsches Schauspielhaus