Using client certificates for authentication

The client machine has the "TicketSalesClient" certificate in "My" storage of current user and the "TicketSalesServer" certificate in "TrustedPeople" storage of current user. The server machine has "TicketSalesClient" certificate in "TrustedPeople" storage of local machine and the "TicketSalesServer" certificate in "My" storage of local machine.

The service runs under IIS 7. Below is the web.config file:

<system.serviceModel> 
<services>
  <service behaviorConfiguration="secureBehavior" name="InternetRailwayTicketSales.TicketSalesImplementations.TicketSalesService">
    <endpoint address="TicketSalesService" 
              binding="basicHttpBinding" 
              bindingConfiguration="secureHttpBinding" contract="InternetRailwayTicketSales.TicketSalesInterface.ITicketSales" />

    <endpoint address="TicketSalesServiceSecureMex" 
              binding="basicHttpBinding" 
              bindingConfiguration="secureHttpBinding" 
              contract="IMetadataExchange" />

    <host>
      <baseAddresses>
        <add baseAddress="https://localhost:443/TicketSales/" />            
      </baseAddresses>
    </host>

  </service>
</services>
<bindings>
  <basicHttpBinding>
    <binding name="secureHttpBinding">
      <security mode="Transport">
        <transport clientCredentialType="Certificate"/>
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

<behaviors>
  <serviceBehaviors>
    <behavior name="secureBehavior">
      <serviceThrottling maxConcurrentInstances="5000" maxConcurrentSessions="5000" />
      <serviceMetadata httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="True" />
      <serviceCredentials>
        <serviceCertificate findValue="TicketSalesServer" 
                            storeLocation="LocalMachine"
                            storeName="My"
                            x509FindType="FindBySubjectName"/>
        <clientCertificate>
          <authentication certificateValidationMode="PeerTrust"/>
        </clientCertificate>
      </serviceCredentials>
    </behavior>
  </serviceBehaviors>
</behaviors>

The service in IIS is configured for SSL and certificate requiring.

1)Now when I try to add service reference in the client I receieve: "The HTTP request was forbidden with client authentication scheme 'Anonymous'. The remote server returned an error: (403) Forbidden."

2)If I try to request the metadata endpoint using browser I firstly apply the SSL certificate and then receieve an error that "The credentials do not give the right to view this directory or page." As I understand this is because I can't give the client credentials through the browser.

3)I tried to use svcutil with configuration file which contains client credentials:

    <configuration>
  <system.serviceModel>
    <client>
      <endpoint 
        behaviorConfiguration="ClientCertificateBehavior"
        binding="basicHttpBinding"
        bindingConfiguration="Binding1" 
        contract="IMetadataExchange"
        name="https" />
    </client>
    <bindings>
      <basicHttpBinding>
        <binding name="Binding1">
          <security mode="Transport">
            <transport clientCredentialType="Certificate" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="ClientCertificateBehavior">
          <clientCredentials>
            <clientCertificate findValue="TicketSalesClient"
                               storeLocation="CurrentUser"
                               storeName="My"
                               x509FindType="FindBySubjectName" />
          </clientCredentials>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
    </configuration>

And then:

svcutil https://veryLongAddress.svc?wsdl /config:svcutilConf.config

And the response is that the "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. The remote certificate is invalid according to the validation procedure"

So what am I doing wrong?

Answers


Seems like your certificates installation is fine. Can you try as shown below and see the output. Try to browse to the service from IE and you should be able to see the service and its wsdl.

Go to IE and then

Tools --> Internet Options --> Security --> Internet --> Custom Level

Tools --> Internet Options --> Security --> Intranet --> Custom Level

Now scroll down to Misc section to find the option "Dont Prompt for client certificate selection when no certificate is present or only one certificate is present" to Diable.

Now restart IE and browse to the service and IE should ask you to select a client certificate from the personal store and you need to select mvc.localhost.

If TicketSalesClient cert is not visible then your client certificate is not in the appropriate store.

The reason for this is that the file you are using to install the certificates do matter as well as the purpose for which the certificate has been created. You can find the purpose of each certificate when you double click them in the certificate store you have a column that is called Intended Purpose. Make sure its for your client certificate.


Need Your Help

Playing with fonts in Wordpress

php css wordpress layout fonts

Recently installed new wordpress theme. The problem is, there are only following font options to choose.

Android: Why does View background draw in editor but not in app?

java android view

I have an Android project with an xml file representing a row for an Adapter.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.