We help IT Professionals succeed at work.

C# - Could not create SSL/TLS secure channel - Authentication Issues

CipherIS
CipherIS asked
on
180 Views
Last Modified: 2018-09-06
I am writing code and implementing the code sample in the below url from Silicon Expert.

https://www.siliconexpert.com/apidocs/content/list-part-search

The sample code produced error:  "The request was aborted: Could not create SSL/TLS secure channel."

Searching I found that the below code should be implemented.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(AllwaysGoodCertificate);

Open in new window

Below is the full example.  
String username = "MyUserName";
String password = "MyPassword";

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(AllwaysGoodCertificate);

string url = "https://app.siliconexpert.com/SearchService/search/authenticateUser?login=" + username + "&apiKey=" + password;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Credentials = CredentialCache.DefaultCredentials;
CookieContainer cookieContainer = request.CookieContainer = new CookieContainer();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
String searchUrl = "https://app.siliconexpert.com/SearchService/search/xref?parts=[{\"partNumber\":\"bav99\"}]&crossType=B";
request = (HttpWebRequest)WebRequest.Create(searchUrl);
request.CookieContainer = cookieContainer;
response = (HttpWebResponse)request.GetResponse();
String results = new System.IO.StreamReader(response.GetResponseStream(), ASCIIEncoding.ASCII).ReadToEnd();
Console.WriteLine(results);
Console.ReadLine();

Open in new window

I am receiving

<?xml version="1.0" encoding="UTF-8"?><ServiceResult><Status><Code>1</Code><Message>Invalid User Name Or Password</Message><Success>false</Success></Status></ServiceResult>

Yet, when I log into the site and perform a search there is no issue.

Anyone see anything that I'm missing?  Want to check to see if it is the code or the site.
Comment
Watch Question

Chinmay PatelChief Technology Ninja
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Hi CipherIS,

Which version of .Net Framework your app is using?

Regards,
Chinmay.

Author

Commented:
Framework I'm using is 4.5.  

I found the issue.  Apparently, another login is needed for the API.  Waiting for those credentials and then how it goes.
Kyle AbrahamsSenior .Net Developer
CERTIFIED EXPERT

Commented:
I would also remove  SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls as they are both already hacked.  If you end up transmitting with either of those protocols the information is public.
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION