Could not establish trust relationship for SSL/TLS secure channel - Windows Server 2012 R22019 Community Moderator ElectionCould not establish trust relationship for SSL/TLS secure channel — SOAPThe request was aborted: Could not create SSL/TLS secure channelWebException Could not establish trust relationship for the SSL/TLS secure channelError: Could not establish trust relationship for the SSL/TLS secure channel with authorityRandomly throwing “Could not establish trust relationship for the SSL/TLS secure channel”C# application could not establish trust relationship for the SSL/TLS secure channelWCF: Could not establish trust relationship for the SSL/TLS secure channel with authoritySignalR - Could not establish trust relationship for the SSL/TLS secure channelC# clickonce Could not establish trust relationship for the SSL/TLS secure channelHow to handle SSL certificates for https / secure web sockets on dynamically launched Windows EC2 instances?

Do I need to be arrogant to get ahead?

Professor being mistaken for a grad student

Employee lack of ownership

Violin - Can double stops be played when the strings are not next to each other?

Gravity magic - How does it work?

How difficult is it to simply disable/disengage the MCAS on Boeing 737 Max 8 & 9 Aircraft?

Who is the 'designer'

My adviser wants to be the first author

How could a scammer know the apps on my phone / iTunes account?

Can a druid choose the size of its wild shape beast?

Why did it take so long to abandon sail after steamships were demonstrated?

Dice rolling probability game

How Could an Airship Be Repaired Mid-Flight

Python if-else code style for reduced code for rounding floats

Are ETF trackers fundamentally better than individual stocks?

Can a one-dimensional blade cut everything ? (chainsaw) (Sword)

How can I track script which gives me "command not found" right after the login?

Unexpected result from ArcLength

Is a lawful good "antagonist" effective?

Credit cards used everywhere in Singapore or Malaysia?

Brexit - No Deal Rejection

A Cautionary Suggestion

If the DM rolls initiative once for a group of monsters, how do end-of-turn effects work?

et qui - how do you really understand that kind of phraseology?



Could not establish trust relationship for SSL/TLS secure channel - Windows Server 2012 R2



2019 Community Moderator ElectionCould not establish trust relationship for SSL/TLS secure channel — SOAPThe request was aborted: Could not create SSL/TLS secure channelWebException Could not establish trust relationship for the SSL/TLS secure channelError: Could not establish trust relationship for the SSL/TLS secure channel with authorityRandomly throwing “Could not establish trust relationship for the SSL/TLS secure channel”C# application could not establish trust relationship for the SSL/TLS secure channelWCF: Could not establish trust relationship for the SSL/TLS secure channel with authoritySignalR - Could not establish trust relationship for the SSL/TLS secure channelC# clickonce Could not establish trust relationship for the SSL/TLS secure channelHow to handle SSL certificates for https / secure web sockets on dynamically launched Windows EC2 instances?










0















I know that there is a lot of information about this error on StackOverflow and other resources, but it's working perfectly on my dev machine and now working on the customer environment Windows Server 2012. Here is my code.



public sealed class Certificates

private static bool subscribed = false;

private static Certificates instance = null;

private static readonly object padlock = new object();

private Certificates()

public static Certificates Instance

get

lock (padlock)

if (instance == null)
instance = new Certificates();
return instance;




public void GetCertificatesAutomatically()

if (!subscribed)

SecurityProtocolType.Tls


private static bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)

// Return true if the server certificate is ok
if (sslPolicyErrors == SslPolicyErrors.None)
return true;

bool acceptCertificate = true;
StringBuilder msg = new StringBuilder("The server could not be validate for the following reason():");

// The server did not present a certificate
if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateNotAvailable) == SslPolicyErrors.RemoteCertificateNotAvailable)

msg.AppendLine(" - The server did not present a certificate.");
acceptCertificate = false;

else

// The certificate does not math the server name
if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateNameMismatch) == SslPolicyErrors.RemoteCertificateNameMismatch)

msg.AppendLine(" - The certificate name does not match the authenticated name.");
acceptCertificate = false;


// There is som other problem with certificate
if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateChainErrors) == SslPolicyErrors.RemoteCertificateChainErrors)

foreach (X509ChainStatus item in chain.ChainStatus)

if (item.Status != X509ChainStatusFlags.RevocationStatusUnknown &&
item.Status != X509ChainStatusFlags.OfflineRevocation)

SLICLog.Error($" - item.StatusInformation.");
break;

if (item.Status != X509ChainStatusFlags.NoError)

msg.AppendLine($" - item.StatusInformation.");
acceptCertificate = false;





// if validation failed, write log
if (!acceptCertificate)

acceptCertificate = true;


return acceptCertificate;




then I used the next code



 Host = new Uri(credential.Domain);

if (Host.Scheme.Contains("https"))
Certificates.Instance.GetCertificatesAutomatically();
using (HttpWebResponse httpWebResponse = httpRequest.GetResponse() as HttpWebResponse)
using (var response = httpWebResponse.GetResponseStream())
using (var sr = new StreamReader(response))

token = JsonConvert.DeserializeObject<SessionInternal>(sr.ReadToEnd());
if (token != null)

Authorized = true;
token.Exprired = DateTime.Now.AddSeconds(Convert.ToDouble(token.expires_in));




The problem is that ServerCertificateValidationCallback being ignored on the environment machine (I know it from log that I have added just for debugging).



On the one website, I read that Microsoft does not allow this to ignore self-signed certificates on Server machines, but not sure. The same code works on Windows10 and does not work on Windows Server 2012 and also settings for API server the same too, I mean the host url and credentials are identical.
.NET Framework 4.7.2



UPDATED:



I don't know why, but another server with a self-signed certificate works, I mean I run the code on the environment server to work with another API server (it's another kind of API) and ServerCertificateValidationCallback delegate is called. I have tried to research network via Wireshark and that is a part of a bad connection between client/serverenter image description here
And this is a normal connection with another serverenter image description here
I'm confused but same code and only different IP of API servers and different behavior










share|improve this question




























    0















    I know that there is a lot of information about this error on StackOverflow and other resources, but it's working perfectly on my dev machine and now working on the customer environment Windows Server 2012. Here is my code.



    public sealed class Certificates

    private static bool subscribed = false;

    private static Certificates instance = null;

    private static readonly object padlock = new object();

    private Certificates()

    public static Certificates Instance

    get

    lock (padlock)

    if (instance == null)
    instance = new Certificates();
    return instance;




    public void GetCertificatesAutomatically()

    if (!subscribed)

    SecurityProtocolType.Tls


    private static bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)

    // Return true if the server certificate is ok
    if (sslPolicyErrors == SslPolicyErrors.None)
    return true;

    bool acceptCertificate = true;
    StringBuilder msg = new StringBuilder("The server could not be validate for the following reason():");

    // The server did not present a certificate
    if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateNotAvailable) == SslPolicyErrors.RemoteCertificateNotAvailable)

    msg.AppendLine(" - The server did not present a certificate.");
    acceptCertificate = false;

    else

    // The certificate does not math the server name
    if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateNameMismatch) == SslPolicyErrors.RemoteCertificateNameMismatch)

    msg.AppendLine(" - The certificate name does not match the authenticated name.");
    acceptCertificate = false;


    // There is som other problem with certificate
    if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateChainErrors) == SslPolicyErrors.RemoteCertificateChainErrors)

    foreach (X509ChainStatus item in chain.ChainStatus)

    if (item.Status != X509ChainStatusFlags.RevocationStatusUnknown &&
    item.Status != X509ChainStatusFlags.OfflineRevocation)

    SLICLog.Error($" - item.StatusInformation.");
    break;

    if (item.Status != X509ChainStatusFlags.NoError)

    msg.AppendLine($" - item.StatusInformation.");
    acceptCertificate = false;





    // if validation failed, write log
    if (!acceptCertificate)

    acceptCertificate = true;


    return acceptCertificate;




    then I used the next code



     Host = new Uri(credential.Domain);

    if (Host.Scheme.Contains("https"))
    Certificates.Instance.GetCertificatesAutomatically();
    using (HttpWebResponse httpWebResponse = httpRequest.GetResponse() as HttpWebResponse)
    using (var response = httpWebResponse.GetResponseStream())
    using (var sr = new StreamReader(response))

    token = JsonConvert.DeserializeObject<SessionInternal>(sr.ReadToEnd());
    if (token != null)

    Authorized = true;
    token.Exprired = DateTime.Now.AddSeconds(Convert.ToDouble(token.expires_in));




    The problem is that ServerCertificateValidationCallback being ignored on the environment machine (I know it from log that I have added just for debugging).



    On the one website, I read that Microsoft does not allow this to ignore self-signed certificates on Server machines, but not sure. The same code works on Windows10 and does not work on Windows Server 2012 and also settings for API server the same too, I mean the host url and credentials are identical.
    .NET Framework 4.7.2



    UPDATED:



    I don't know why, but another server with a self-signed certificate works, I mean I run the code on the environment server to work with another API server (it's another kind of API) and ServerCertificateValidationCallback delegate is called. I have tried to research network via Wireshark and that is a part of a bad connection between client/serverenter image description here
    And this is a normal connection with another serverenter image description here
    I'm confused but same code and only different IP of API servers and different behavior










    share|improve this question


























      0












      0








      0








      I know that there is a lot of information about this error on StackOverflow and other resources, but it's working perfectly on my dev machine and now working on the customer environment Windows Server 2012. Here is my code.



      public sealed class Certificates

      private static bool subscribed = false;

      private static Certificates instance = null;

      private static readonly object padlock = new object();

      private Certificates()

      public static Certificates Instance

      get

      lock (padlock)

      if (instance == null)
      instance = new Certificates();
      return instance;




      public void GetCertificatesAutomatically()

      if (!subscribed)

      SecurityProtocolType.Tls


      private static bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)

      // Return true if the server certificate is ok
      if (sslPolicyErrors == SslPolicyErrors.None)
      return true;

      bool acceptCertificate = true;
      StringBuilder msg = new StringBuilder("The server could not be validate for the following reason():");

      // The server did not present a certificate
      if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateNotAvailable) == SslPolicyErrors.RemoteCertificateNotAvailable)

      msg.AppendLine(" - The server did not present a certificate.");
      acceptCertificate = false;

      else

      // The certificate does not math the server name
      if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateNameMismatch) == SslPolicyErrors.RemoteCertificateNameMismatch)

      msg.AppendLine(" - The certificate name does not match the authenticated name.");
      acceptCertificate = false;


      // There is som other problem with certificate
      if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateChainErrors) == SslPolicyErrors.RemoteCertificateChainErrors)

      foreach (X509ChainStatus item in chain.ChainStatus)

      if (item.Status != X509ChainStatusFlags.RevocationStatusUnknown &&
      item.Status != X509ChainStatusFlags.OfflineRevocation)

      SLICLog.Error($" - item.StatusInformation.");
      break;

      if (item.Status != X509ChainStatusFlags.NoError)

      msg.AppendLine($" - item.StatusInformation.");
      acceptCertificate = false;





      // if validation failed, write log
      if (!acceptCertificate)

      acceptCertificate = true;


      return acceptCertificate;




      then I used the next code



       Host = new Uri(credential.Domain);

      if (Host.Scheme.Contains("https"))
      Certificates.Instance.GetCertificatesAutomatically();
      using (HttpWebResponse httpWebResponse = httpRequest.GetResponse() as HttpWebResponse)
      using (var response = httpWebResponse.GetResponseStream())
      using (var sr = new StreamReader(response))

      token = JsonConvert.DeserializeObject<SessionInternal>(sr.ReadToEnd());
      if (token != null)

      Authorized = true;
      token.Exprired = DateTime.Now.AddSeconds(Convert.ToDouble(token.expires_in));




      The problem is that ServerCertificateValidationCallback being ignored on the environment machine (I know it from log that I have added just for debugging).



      On the one website, I read that Microsoft does not allow this to ignore self-signed certificates on Server machines, but not sure. The same code works on Windows10 and does not work on Windows Server 2012 and also settings for API server the same too, I mean the host url and credentials are identical.
      .NET Framework 4.7.2



      UPDATED:



      I don't know why, but another server with a self-signed certificate works, I mean I run the code on the environment server to work with another API server (it's another kind of API) and ServerCertificateValidationCallback delegate is called. I have tried to research network via Wireshark and that is a part of a bad connection between client/serverenter image description here
      And this is a normal connection with another serverenter image description here
      I'm confused but same code and only different IP of API servers and different behavior










      share|improve this question
















      I know that there is a lot of information about this error on StackOverflow and other resources, but it's working perfectly on my dev machine and now working on the customer environment Windows Server 2012. Here is my code.



      public sealed class Certificates

      private static bool subscribed = false;

      private static Certificates instance = null;

      private static readonly object padlock = new object();

      private Certificates()

      public static Certificates Instance

      get

      lock (padlock)

      if (instance == null)
      instance = new Certificates();
      return instance;




      public void GetCertificatesAutomatically()

      if (!subscribed)

      SecurityProtocolType.Tls


      private static bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)

      // Return true if the server certificate is ok
      if (sslPolicyErrors == SslPolicyErrors.None)
      return true;

      bool acceptCertificate = true;
      StringBuilder msg = new StringBuilder("The server could not be validate for the following reason():");

      // The server did not present a certificate
      if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateNotAvailable) == SslPolicyErrors.RemoteCertificateNotAvailable)

      msg.AppendLine(" - The server did not present a certificate.");
      acceptCertificate = false;

      else

      // The certificate does not math the server name
      if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateNameMismatch) == SslPolicyErrors.RemoteCertificateNameMismatch)

      msg.AppendLine(" - The certificate name does not match the authenticated name.");
      acceptCertificate = false;


      // There is som other problem with certificate
      if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateChainErrors) == SslPolicyErrors.RemoteCertificateChainErrors)

      foreach (X509ChainStatus item in chain.ChainStatus)

      if (item.Status != X509ChainStatusFlags.RevocationStatusUnknown &&
      item.Status != X509ChainStatusFlags.OfflineRevocation)

      SLICLog.Error($" - item.StatusInformation.");
      break;

      if (item.Status != X509ChainStatusFlags.NoError)

      msg.AppendLine($" - item.StatusInformation.");
      acceptCertificate = false;





      // if validation failed, write log
      if (!acceptCertificate)

      acceptCertificate = true;


      return acceptCertificate;




      then I used the next code



       Host = new Uri(credential.Domain);

      if (Host.Scheme.Contains("https"))
      Certificates.Instance.GetCertificatesAutomatically();
      using (HttpWebResponse httpWebResponse = httpRequest.GetResponse() as HttpWebResponse)
      using (var response = httpWebResponse.GetResponseStream())
      using (var sr = new StreamReader(response))

      token = JsonConvert.DeserializeObject<SessionInternal>(sr.ReadToEnd());
      if (token != null)

      Authorized = true;
      token.Exprired = DateTime.Now.AddSeconds(Convert.ToDouble(token.expires_in));




      The problem is that ServerCertificateValidationCallback being ignored on the environment machine (I know it from log that I have added just for debugging).



      On the one website, I read that Microsoft does not allow this to ignore self-signed certificates on Server machines, but not sure. The same code works on Windows10 and does not work on Windows Server 2012 and also settings for API server the same too, I mean the host url and credentials are identical.
      .NET Framework 4.7.2



      UPDATED:



      I don't know why, but another server with a self-signed certificate works, I mean I run the code on the environment server to work with another API server (it's another kind of API) and ServerCertificateValidationCallback delegate is called. I have tried to research network via Wireshark and that is a part of a bad connection between client/serverenter image description here
      And this is a normal connection with another serverenter image description here
      I'm confused but same code and only different IP of API servers and different behavior







      c# windows-services windows-server-2012-r2






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 11 at 15:43







      Sanprof

















      asked Mar 7 at 14:37









      SanprofSanprof

      94115




      94115






















          0






          active

          oldest

          votes











          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%2f55046351%2fcould-not-establish-trust-relationship-for-ssl-tls-secure-channel-windows-serv%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          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%2f55046351%2fcould-not-establish-trust-relationship-for-ssl-tls-secure-channel-windows-serv%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

          Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

          2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme