Basic httpsbinding client certificate issues on Ubuntu, Centos, Fedora and Debian
I've got a strange issue and I hope this is the right place. I have some functionality that is working on windows, but fails on all of the unix droplets I've spun up. I'm seeing one type of failure message on ubuntu 14.04 and debian 8.5 and another type on fedora 23 and centos 7 when using BasicHttpsbinding and the connection factory. I've tried using the svcutil to generate the interface and I've also used the new WCF Connected Services utility. Both exhibit the same behavior.
Here is the code:
`private string invokeSsoSoapRequest(string xmlRequest)
{
ChannelFactory
var binding = new BasicHttpsBinding();
binding.Security.Mode = BasicHttpsSecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
var baseAddress = new Uri(mySettings.ClientUrl);
var endpointAddress = new EndpointAddress(baseAddress);
X509Certificate2Collection collection = new X509Certificate2Collection();
if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
{
//windows file location
collection.Import(mySettings.ClientPrivateKeyWindowsPath, mySettings.ClientPfxPass, X509KeyStorageFlags.PersistKeySet);
}else
{
collection.Import(mySettings.ClientPrivateKeyUnixPath, mySettings.ClientPfxPass, X509KeyStorageFlags.PersistKeySet);
}
//parse pfx for client auth key
factory = new ChannelFactory<SingleSignOnSoap>(binding, new EndpointAddress(baseAddress));
foreach (X509Certificate2 cert in collection)
{
if (cert.HasPrivateKey)
{
factory.Credentials.ClientCertificate.Certificate = cert;
}
}
serviceProxy = factory.CreateChannel();
RequestTicketRequest request = new RequestTicketRequest();
RequestTicketRequestBody body = new RequestTicketRequestBody();
request.Body = body;
request.Body.sRequestXML = xmlRequest;
return serviceProxy.RequestTicket(request).Body.RequestTicketResult;
}
}`
Here is the error I received on Fedora and Centos:
PlatformNotSupportedException: The libcurl library in use (7.43.0) and its SSL backend ("NSS/3.24 Basic ECC") do not support custom handling of certificates. A libcurl built with OpenSSL is required.
*As a note, I compiled 7.50 curl against openssl and still received the above error. I'm a little bit of a linux noob, so I'm not sure if there's a way to force dotnet core to use the 7.5 installation.
The errors I'm seeing on Debian and Ubuntu are a little stranger. Here's the actual message:
TimeoutException: The HTTP request to 'https://services.**********SingleSignOn.asmx' has exceeded the allotted timeout of 00:01:00. The time allotted to this operation may have been a portion of a longer timeout.
The dotnet error claims the service timed out while waiting for a response (00:01:00), but a tshark trace shows the SOAP response negotiation failed when the client sent [RST, ACK] back the the remote webservice. See image below. The same trace in windows environment shows no errors and the transaction works and as you can see a few lines above, the server hello, certificate, and key exchanges appear to be successful, so I don't think I'm dealing with a cert issue.

I would appreciate any help and know that it's more than plausible I've done something wrong here.
Lastly, if I can provide any other information, please let me know! Thanks!
Tonight I tried a few docker builds and received the same timeout messages as above. Here are the dockerfile details:
FROM microsoft/dotnet:1.0.0-preview2-sdk RUN mkdir -p /dotnetapp WORKDIR /dotnetapp
EXPOSE 5000
COPY . /dotnetapp RUN dotnet restore
ENTRYPOINT ["dotnet", "run"]`
Tried to bypass the system.servicemodel and use the httphandler with a manual request. Same results as above. Kestrel issue maybe?
` private async System.Threading.Tasks.Task
HttpClientHandler handler = new HttpClientHandler();
X509Certificate2Collection collection = new X509Certificate2Collection();
if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
{
//windows file location
collection.Import(mySettings.ClientPrivateKeyWindowsPath, mySettings.ClientPfxPass, X509KeyStorageFlags.PersistKeySet);
}
else
{
//on linux file locations
collection.Import(mySettings.ClientPrivateKeyUnixPath, mySettings.ClientPfxPass, X509KeyStorageFlags.PersistKeySet);
}
foreach (X509Certificate2 cert in collection)
{
handler.ClientCertificates.Add(cert);
}
//create client
HttpClient client = new HttpClient(handler);
string _ContentType = "text/xml";
HttpContent _Body = new StringContent(xmlRequest, Encoding.UTF8, "text/xml");
_Body.Headers.ContentType = new MediaTypeHeaderValue(_ContentType);
_Body.Headers.ContentType.CharSet = "utf8";
_Body.Headers.ContentLength = xmlRequest.Length;
_Body.Headers.TryAddWithoutValidation("SOAPAction", "url");
//create response object
HttpResponseMessage response = new HttpResponseMessage();
//execute
response = await client.PostAsync(new Uri(mySettings.ClientUrl), _Body);
string x = await response.Content.ReadAsStringAsync();
return x;
}`
Re:
Here is the error I received on Fedora and Centos:
PlatformNotSupportedException: The libcurl library in use (7.43.0) and its SSL backend ("NSS/3.24 Basic ECC") do not support custom handling of certificates. A libcurl built with OpenSSL is required.
Wondering if @stephentoub can help out here? I'm not familiar enough with the inner workings of Fedora/CentOS at the moment to know where it pulls the libcurl implementation from
The second issue you have is a little fishier though. That you're seeing this issue directly using httpClient is a little odd. Admittedly, one of the first things I do to debug is to remove all SSL and extra stuff, then add that on piecemeal (our Windows experience is not the same as the x-plat experience yet). Have you tried yanking things like SSL out of the system? Better yet, does a very simple "Hello World" work against your server?
I do suspect you're right that SSL probably isn't the culprit, but stranger things have happened. Offhand, I don't see anything wrong.
Hey thanks, @iamjasonp! I tried consuming an older SOAP service that just used uid/pwd authentication and it works fine. Unfortunately, the remote service isn't mine and I can't tweak it to test this specific service w/out a client certificate.
My understanding is that the CURL that ships w/ fedora and centos is compiled against the NSS libraries and doesn't support custom client certificates, whereas the curl version in Ubuntu and debian are compiled against openssl, which does.
Since I'm having the issue even using the httpclient, I've cross-posted this in corefx on the advice of some of the Kestrel devs.
As a note, I compiled 7.50 curl against openssl and still received the above error. I'm a little bit of a linux noob, so I'm not sure if there's a way to force dotnet core to use the 7.5 installation.
After you built and installed it locally, did you set the LD_LIBRARY_PATH environment variable to point to the right location? That should cause System.Net.Http.Native.so to pick up the libcurl you built.
Thanks @stephentoub! I will give that a shot. Right now I have the solution working by shelling out a ProcessStartInfo command w/ parameters to a bash script that calls curl directly. It feels bad and rigged and all of that, but works on all the linux distros I've tested, so at least we have a path to production for this API stack.
Hi @mwdavisii -- what's the latest status on this? Did stephentoub's recommendation work, or is having the bash script call curl directly still an adequate solution for you?