AnsweredAssumed Answered

GetEndpointData string in wrong format in SSLLabsApiWrapper

Question asked by Tihomir Metodiev on May 15, 2018
Latest reply on May 22, 2018 by Sam Friday

Hello Experts,

I am really sorry for posting a silly question once again but please assist me with this one.

 

I am doing a C# implementation of the SSL Labs Api and you can see my code below. When the Analyze() output resolves successfully the hostname provided I use the GetEndpointData() function to get the information from the analysis. However the string variable is noted to be in wrong format.

Unhandled Exception: System.FormatException: Input string was not in a correct format. at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args) at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args) at System.IO.TextWriter.WriteLine(String format, Object arg0) at System.IO.TextWriter.SyncTextWriter.WriteLine(String format, Object arg0) at System.Console.WriteLine(String format, Object arg0) at SSLExpirationStd.Program.Main(String[] args) in C:\Users\tihomir.metodiev\source\repos\SSLExpirationStd\SSLExpirationStd\Program.cs:line 102

I have tested the request with Postman Software and it works fine - "https://api.ssllabs.com/api/v3/getEndpointData?host=http://www.website.com&s=X.X.X.X"

 

var hostname = "http://www.website.com"
ssllService = new SSLLabsApiService("https://api.ssllabs.com/api/v3");
var sslAnalyze = ssllService.Analyze(hostname, SSLLabsApiService.Publish.Off, SSLLabsApiService.StartNew.On, SSLLabsApiService.FromCache.Off, 24, SSLLabsApiService.All.Done, SSLLabsApiService.IgnoreMismatch.On);
var sslAnalyzeStr = JsonConvert.SerializeObject(sslAnalyze, Formatting.Indented);
Console.WriteLine(sslAnalyzeStr);

 

while (sslAnalyzeStr.Contains("statusMessage\": \"Resolving domain names"))
{
    Thread.Sleep(8000);
    sslAnalyzeStr = JsonConvert.SerializeObject(ssllService.Analyze(hostname, SSLLabsApiService.Publish.Off, SSLLabsApiService.StartNew.Ignore, SSLLabsApiService.FromCache.Off, 24, SSLLabsApiService.All.Done, SSLLabsApiService.IgnoreMismatch.On), Formatting.Indented);
}

 

Console.WriteLine(sslAnalyzeStr);

 

string[] lines = sslAnalyzeStr.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
List<string> hostnameIPs = new List<string>();

 

for (int line = 1; line < lines.Length; line++)
{
    if (lines[line].IndexOf("ipAddress") != -1)
    {
        hostnameIPs.Add(lines[line].Trim().Split('"')[3]);
    }
}

 

Console.WriteLine(hostnameIPs[0]);
string IIPP = hostnameIPs[0];
Console.WriteLine(JsonConvert.SerializeObject(ssllService.GetEndpointData(hostname, IIPP,SSLLabsApiService.FromCache.On)), Formatting.Indented);

I will really appreciate any help provided.

 

Have a great day!

Outcomes