Using client certificates for authentication
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.
EngineerSpock
Updated on June 04, 2022Comments
-
EngineerSpock almost 2 years
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?
-
EngineerSpock over 12 yearsAnd what is the problem with my configuartion of metadata exchange endpoint?
-
EngineerSpock over 12 yearsIE didnt ask me for certificate selection. And the client certificate is for all purposes. How the IIS should be configured? Which authentication mode should be chosen at service and server level? There are many modes. Which modes should be turned on and which modes should be turned off?
-
Rajesh over 12 yearsIf you follow the steps to change the options in IE as said above for Internet and Intranet it should prompt for a client certificate selection. You can have anonymous authentication mode enabled.
-
Ladislav Mrnka over 12 yearsMEX ednpoint is not used when accessing WSDL from the browser.
-
EngineerSpock over 12 yearsOK. I have changed the setting for intranet. The same error. But then I decided to add certificates to the Root storage. It hepled. Now the request from IE involves to the confirmation of client certificate. When I confirm it I receive new error: "Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service".
-
EngineerSpock over 12 yearsIf I try to connect from the client I receive "The HTTP request was forbidden with client authentication scheme 'Anonymous'. The authentication header received from the server "Negotiate, NTLM"".
-
EngineerSpock over 12 yearsOK. I have turned on anonymous authentication in IIS and now all is OK. But the question is why the client certificate must me inside the Root store but not inside the TrustedPeople. Why?
-
Rajesh over 12 yearsThe client certificate on client machines needs to be in the Current User --> Personal folder for IE to pick up to send it On server machine needs to be in Local machine --> Trusted People Store Who issued the client certificate? If you double click on your client certificate in the store you can see the "Issued By" This issuers certificate needs to be present in the Root store for the server to know that it has been issued by a trusted authority
-
EngineerSpock over 12 yearsOops. It works only with System.Net.ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback( delegate { return true; }); If I comment this then I receive: Could not establish trust relationship for the SSL/TLS secure channel with authority "192.168.0.64".
-
Rajesh over 12 yearsThat is because you are using a self signed certificate. Once you have a certificate issued by a proper authority you would not need that code.
-
EngineerSpock over 12 yearsBut how can I avoid the requsting of a certificate issued by a trusted authority?
-
Rajesh over 12 yearsIf you do not wish to purchase a certificate then you can switch to username password autentication mechanism.