Simple Secure Indigo (HTTPS)

I've started looking at the various security options for the Indigo services and I decided to try plain HTTPS with the basicProfileBinding as a first stab. Once more I took a config based approach. It took me a while to get it working and I did need some help from some of the other folks on the Indigo security team to figure out the exact set of steps necessary to get SSL set up correctly.
 
The code for the client and service are as shown in my earlier entries. The config file for the service now looks like this;
 
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0" >
 <system.serviceModel>
  <bindings>
   <basicProfileBinding>
    <bindingconfigurationName="SecurityBasicServiceBinding" 
             
securityMode ="Https" />
   </basicProfileBinding>
  </bindings>
  <services>
   <serviceserviceType="Gudge.Samples.Service" >
    <endpoint address="https://gudgemachine:8088/securitybasic"
              bindingSectionName="basicProfileBinding"
              bindingConfiguration="SecurityBasicServiceBinding"
              contractType="Gudge.Samples.ISimple, Service" />
   </service>
  </services>
 </system.serviceModel>
</configuration>
 
The securityMode attribute on the binding element, along with the https URI in the address attribute on the endpoint element configure the service to use SSL. If these don't match ( e.g. http URI for address with Https securityMode ) then the service will throw an exception at Open time. The exception message is reasonably informative; "The provided URI scheme 'http' is invalid; expected 'https'."
 
The above config is not quite enough to configure the service completely, I also need to specify the certificate to identity the server in SSL exchange. I did this with httpcfg.exe, which can be used, amongst other things to tell http.sys which certificates to associate with which URIs. In this case the command line I used was;
 
  httpcfg add ssl -i 0.0.0.0:8088 -h abcdefabcdefabcdefabcdef
 
The add argument tells httpcfg that I'm adding a new mapping. The ssl argument indicates that the mapping I'm adding is an SSL certificate to URI mapping. The -i and following argument indicate the IP address and port number, the 0.0.0.0 indicates my local IP address ( it actually gets assigned by DHCP on my network, so I can't specify a fixed address). The -h and following argument indicate the thumbprint of the certificate to use. A couple of notes about that;
 
  1. The certificate needs to be in the LocalMachine store (not CurrentUser)
  2. The thumbprint is the SHA1 thumbprint, not the MD5 thumbprint.
 
I actually used my machine certificate, which is my case gets set up when I first pave my machine inside the big house. ( and no, gudgemachine is NOT my actual machine name neither is the above the real SHA1 of my cert ).
 
So that's the service configured, the client config looks like this;
 
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0" >
 <system.serviceModel>
  <bindings>
   <basicProfileBinding>
    <bindingconfigurationName="SecurityBasicClientBinding"
             securityMode ="Https" />
   </basicProfileBinding>
  </bindings>
  <client>
   <endpointconfigurationName="SecurityBasicEndpointConfig"
             address="https://gudgemachine:8088/securitybasic"
             bindingSectionName="basicProfileBinding"
             bindingConfiguration="SecurityBasicClientBinding"
             contractType="Gudge.Samples.ISimple, Client" />
  </client>
 </system.serviceModel>
</configuration>
 
The securityMode attribute on the binding element and the address attribute on the endpoint element perform the same function here as they did with the service (and you'll get the same exception if they don't match up).
 
With the above config files, httpcfg command line and an appropriate certificate you can successfully secure the communication between client and service using SSL.
 
As I indicated earlier, it wasn't actually a smooth path to this point of SSL nirvana; for my first attempt I tried to use localhost in the address URI (e.g. https://localhost:8088/securitybasic ) along with a certificate for localhost generated by makecert. It turns out that because certificates generated using makecert don't have a valid root issuer, the certificate fails SSL certificate checking on the client side. Unfortunately the exception you get at this point is not terribly informative; "The underlying connection was closed: An unexpected error occurred on a send." and on digging a little deeper into the exception chain; "Authentication failed because the remote party has closed the transport stream." neither of which gives much clue as to what the problem actually is. Having spoken to some of the folks here on the Indigo security team, I was faced with getting hold of a 'real' certificate with a valid trust root or using such a cert that I already had.
 
This led me to my next attempt which was to use my machine certificate but still use the localhost URI. This doesn't work either, because the DNS name in the certificate and that in the endpoint URI need to match. As my certificate, not unsurprisingly, does not contain the domain name 'localhost', they don't match. The exception that gets thrown here is somewhat helpful; "Could not establish secure channel for SSL/TLS with authority 'localhost:8088'." and again, on digging deeper; "The remote certificate is invalid according to the validation procedure." OK, so it's not quite as clear as "DNS name in server side certificate doesn't match URI of service" but it's close enough for government work, as they say.
 
So, make sure you use a 'proper' certificate, and make sure the domain name in that certificate matches the domain name you specify in the service endpoint.
 
It turns out that those exception messages do give some clue to another mechanism for addressing the 'localhost' problem, but that's the subject of another entry…

Posted Jun 01 2005, 10:13 AM by martin-gudgin

Comments

Keith Brown wrote re: Simple Secure Indigo (HTTPS)
on 06-02-2005 12:08 PM
Hey Gudge, it's pretty easy to get Cert Server setup and just issue your own certificates. Might save you some headaches in the future.
Gudge wrote re: Simple Secure Indigo (HTTPS)
on 06-02-2005 8:14 PM
Hi Keith!,

Yeah, getting an issued cert, either from my own cert server or someone else was one of my other options. But it was fun (for some definition of fun) to find out how to do it the hard way ;-)

Cheers

Gudge
Rodrigo Jordão wrote re: Simple Secure Indigo (HTTPS)
on 06-05-2005 8:46 PM
I believe makecert is a very viable option for testing scenarios.

To use makecert certificates in this testing scenario, just add the certificates you create (or the root used to create them, which could be created by makecert also) to the trusted root certificates (ROOT) on the Local Machine store of your server. You can also create a certificate with the subject 'localhost' with makecert, or just use your machine name (and access the resource as https://machineName/secureresource).

There's really no need for Cert Server for testing.
Musings from Gudge wrote Certificate Validation Callbacks in Indigo
on 07-13-2005 11:50 AM
NathanA's Web Services Blog wrote Quick links
on 08-10-2005 3:16 AM

Here's an interesting Black Hat paper&nbsp;detailing security considerations when deciding to use web...
Musings from Gudge wrote SSL mutual authentication and more httpcfg magic
on 08-29-2005 9:16 PM
Musings from Gudge wrote SSL mutual authentication and more httpcfg magic
on 09-26-2005 11:13 AM
Mike Taulty's Weblog wrote Indigo - Basic Http Profile with SSL in a self-hosted service (
on 11-17-2005 12:48 AM
Pedro Felix wrote Configuring http.sys server SSL certificate (and private key)
on 12-29-2005 11:58 AM
Having problems using&nbsp;transport layer security (SSL/TLS) with WCF (aka Indigo)?
Are you getting...
Venkat wrote re: Simple Secure Indigo (HTTPS)
on 02-05-2006 9:21 AM
good example.
I am wondering is about throwing exceptions in web service scenarions.
is there any blog which talks about exceptions in web services?
C K (udaybhatia@hotmail.com) wrote re: Simple Secure Indigo (HTTPS)
on 12-10-2006 10:25 PM
i was using the above code and i found the below error:

Setting environment for using Microsoft Visual Studio 2005 x86 tools.

C:\Program Files\Microsoft Visual Studio 8\VC>cd\

C:\>cd C:\Documents and Settings\bhatiach.SHLAD\My Documents\Visual Studio 2005\
Projects\BasicWCFService\BasicWCFService\bin\Debug

C:\Documents and Settings\bhatiach.SHLAD\My Documents\Visual Studio 2005\Project
s\BasicWCFService\BasicWCFService\bin\Debug>BasicWCFService
The service is ready.
Press <Enter> to terminate the service.



C:\Documents and Settings\bhatiach.SHLAD\My Documents\Visual Studio 2005\Project
s\BasicWCFService\BasicWCFService\bin\Debug>BasicWCFService

Unhandled Exception: System.TypeInitializationException: The type initializer fo
r 'System.ServiceModel.DiagnosticUtility' threw an exception. ---> System.Config
uration.ConfigurationErrorsException: Configuration system failed to initialize
---> System.Configuration.ConfigurationErrorsException: Unrecognized configurati
on section system.serviceModel/basicProfileBinding. (C:\Documents and Settings\b
hatiach.SHLAD\My Documents\Visual Studio 2005\Projects\BasicWCFService\BasicWCFS
ervice\bin\Debug\BasicWCFService.exe.config line 4)
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignor
eLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(Configurat
ionSchemaErrors schemaErrors)
at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey
)
--- End of inner exception stack trace ---
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey
)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Intern
al.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at System.Configuration.PrivilegedConfigurationManager.GetSection(String sect
ionName)
at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
at System.Diagnostics.DiagnosticsConfiguration.Initialize()
at System.Diagnostics.DiagnosticsConfiguration.get_Sources()
at System.Diagnostics.TraceSource.Initialize()
at System.Diagnostics.TraceSource.get_Listeners()
at System.ServiceModel.Diagnostics.DiagnosticTrace.CreateTraceSource()
at System.ServiceModel.Diagnostics.DiagnosticTrace..ctor(TraceSourceKind sour
ceType, String traceSourceName, String eventSourceName)
at System.ServiceModel.DiagnosticUtility.InitDiagnosticTraceImpl(TraceSourceK
ind sourceType, String traceSourceName)
at System.ServiceModel.DiagnosticUtility.InitializeTracing()
at System.ServiceModel.DiagnosticUtility..cctor()
--- End of inner exception stack trace ---
at System.ServiceModel.Channels.CommunicationObject.set_TraceOpenAndClose(Boo
lean value)
at System.ServiceModel.ServiceHostBase..ctor()
at System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresse
s)
at BasicWCFService.Program.Run() in C:\Documents and Settings\bhatiach.SHLAD\
My Documents\Visual Studio 2005\Projects\BasicWCFService\BasicWCFService\Program
.cs:line 48
at BasicWCFService.Program.Main(String[] args) in C:\Documents and Settings\b
hatiach.SHLAD\My Documents\Visual Studio 2005\Projects\BasicWCFService\BasicWCFS
ervice\Program.cs:line 37

C:\Documents and Settings\bhatiach.SHLAD\My Documents\Visual Studio 2005\Project
s\BasicWCFService\BasicWCFService\bin\Debug>BasicWCFService >>ERROR.txt

Unhandled Exception: System.TypeInitializationException: The type initializer fo
r 'System.ServiceModel.DiagnosticUtility' threw an exception. ---> System.Config
uration.ConfigurationErrorsException: Configuration system failed to initialize
---> System.Configuration.ConfigurationErrorsException: Unrecognized configurati
on section system.serviceModel/basicProfileBinding. (C:\Documents and Settings\b
hatiach.SHLAD\My Documents\Visual Studio 2005\Projects\BasicWCFService\BasicWCFS
ervice\bin\Debug\BasicWCFService.exe.config line 4)
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignor
eLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(Configurat
ionSchemaErrors schemaErrors)
at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey
)
--- End of inner exception stack trace ---
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey
)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Intern
al.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at System.Configuration.PrivilegedConfigurationManager.GetSection(String sect
ionName)
at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
at System.Diagnostics.DiagnosticsConfiguration.Initialize()
at System.Diagnostics.DiagnosticsConfiguration.get_Sources()
at System.Diagnostics.TraceSource.Initialize()
at System.Diagnostics.TraceSource.get_Listeners()
at System.ServiceModel.Diagnostics.DiagnosticTrace.CreateTraceSource()
at System.ServiceModel.Diagnostics.DiagnosticTrace..ctor(TraceSourceKind sour
ceType, String traceSourceName, String eventSourceName)
at System.ServiceModel.DiagnosticUtility.InitDiagnosticTraceImpl(TraceSourceK
ind sourceType, String traceSourceName)
at System.ServiceModel.DiagnosticUtility.InitializeTracing()
at System.ServiceModel.DiagnosticUtility..cctor()
--- End of inner exception stack trace ---
at System.ServiceModel.Channels.CommunicationObject.set_TraceOpenAndClose(Boo
lean value)
at System.ServiceModel.ServiceHostBase..ctor()
at System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresse
s)
at BasicWCFService.Program.Run() in C:\Documents and Settings\bhatiach.SHLAD\
My Documents\Visual Studio 2005\Projects\BasicWCFService\BasicWCFService\Program
.cs:line 48
at BasicWCFService.Program.Main(String[] args) in C:\Documents and Settings\b
hatiach.SHLAD\My Documents\Visual Studio 2005\Projects\BasicWCFService\BasicWCFS
ervice\Program.cs:line 37

C:\Documents and Settings\bhatiach.SHLAD\My Documents\Visual Studio 2005\Project
s\BasicWCFService\BasicWCFService\bin\Debug>BasicWCFService >>ERROR.txt

Unhandled Exception: System.TypeInitializationException: The type initializer fo
r 'System.ServiceModel.DiagnosticUtility' threw an exception. ---> System.Config
uration.ConfigurationErrorsException: Configuration system failed to initialize
---> System.Configuration.ConfigurationErrorsException: Unrecognized configurati
on section system.serviceModel/basicProfileBinding. (C:\Documents and Settings\b
hatiach.SHLAD\My Documents\Visual Studio 2005\Projects\BasicWCFService\BasicWCFS
ervice\bin\Debug\BasicWCFService.exe.config line 4)
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignor
eLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(Configurat
ionSchemaErrors schemaErrors)
at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey
)
--- End of inner exception stack trace ---
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey
)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Intern
al.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at System.Configuration.PrivilegedConfigurationManager.GetSection(String sect
ionName)
at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
at System.Diagnostics.DiagnosticsConfiguration.Initialize()
at System.Diagnostics.DiagnosticsConfiguration.get_Sources()
at System.Diagnostics.TraceSource.Initialize()
at System.Diagnostics.TraceSource.get_Listeners()
at System.ServiceModel.Diagnostics.DiagnosticTrace.CreateTraceSource()
at System.ServiceModel.Diagnostics.DiagnosticTrace..ctor(TraceSourceKind sour
ceType, String traceSourceName, String eventSourceName)
at System.ServiceModel.DiagnosticUtility.InitDiagnosticTraceImpl(TraceSourceK
ind sourceType, String traceSourceName)
at System.ServiceModel.DiagnosticUtility.InitializeTracing()
at System.ServiceModel.DiagnosticUtility..cctor()
--- End of inner exception stack trace ---
at System.ServiceModel.Channels.CommunicationObject.set_TraceOpenAndClose(Boo
lean value)
at System.ServiceModel.ServiceHostBase..ctor()
at System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresse
s)
at BasicWCFService.Program.Run() in C:\Documents and Settings\bhatiach.SHLAD\
My Documents\Visual Studio 2005\Projects\BasicWCFService\BasicWCFService\Program
.cs:line 48
at BasicWCFService.Program.Main(String[] args) in C:\Documents and Settings\b
hatiach.SHLAD\My Documents\Visual Studio 2005\Projects\BasicWCFService\BasicWCFS
ervice\Program.cs:line 37

How can we resolve this?
Gudge wrote re: Simple Secure Indigo (HTTPS)
on 12-11-2006 2:20 PM
C K,

This blog entry was written against a pre-release version of Indigo. The release version uses basicHttpBinding instead of basicProfileBinding. See http://msdn2.microsoft.com/ru-ru/library/ms731361.aspx

for more details.

Regards

Gudge
Mcse Certification wrote Mcse Certification
on 06-03-2007 4:29 PM
MCSE Certification could help a lot in career advancement in technology field. After the burst of Year 2000 techno. bubbles, most corporations start investing their money into IT again.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?