#613 C# (.NET) Haystack Authentication Failure on unsecure websites

Paul Virrey Thu 24 May 2018

Hi All,

I am currently using the C# library for creating requests from Haystack APIs and it works really well until the source URL changed its protocol from http to https. I noticed that since changing it from http to https, it had that red mark on its protocol in Chrome which means that the url has an invalid certificate. Since then my code that utilizes the Rest Client can't authenticate anymore and is returning this error:

"ProjectHaystack.Auth.AuthException: authenticate failed ---> System.NullReferenceException: Object reference not set to an instance of an object.\r\n at ProjectHaystack.Auth.AuthClientContext.Get(HttpWebRequest c)\r\n at ProjectHaystack.Auth.AuthClientContext.GetAuth(AuthMsg msg)\r\n at ProjectHaystack.Auth.AuthClientContext.SendHello()\r\n at ProjectHaystack.Auth.AuthClientContext.Open()\r\n --- End of inner exception stack trace ---\r\n at ProjectHaystack.Auth.AuthClientContext.Open()\r\n at ProjectHaystack.Client.HClient.Open()\r\n at ProjectHaystack.Client.HClient.Open(String uri, String user, String pass, Int32 connectTimeout, Int32 readTimeout)\r\n"

This is how I use the Rest Client Code from the Haystack library:

HClient client = HClient.Open(uri, username, pass, apiConnectTimeOut, apiReadTimeOut);

where apiConnectTimeout and apiReadTimeout are integers.

If there is no way that we can change the certificate issue, is there a way where we can bypass this and still be able to authenticate and pull data using the client?

Appreciate any help that I can get. Thank you!

Tyler B. Long Mon 18 Jun 2018

The following is not at all recommended for production use, however for testing you can register a cert validator to return all certs as valid. Put this just before creating an HClient:

using System.Net;
...

ServicePointManager.ServerCertificateValidationCallback +=
                (sender, certificate, chain, sslPolicyError) => true;

Login or Signup to reply.