Link to home
Start Free TrialLog in
Avatar of CipherIS
CipherISFlag for United States of America

asked on

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

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.
Avatar of Chinmay Patel
Chinmay Patel
Flag of India image

Hi CipherIS,

Which version of .Net Framework your app is using?

Regards,
Chinmay.
Avatar of CipherIS

ASKER

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.
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.
ASKER CERTIFIED SOLUTION
Avatar of CipherIS
CipherIS
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial