how to add basicHttpBinding to the custombinding code - wcf

I need to authenticate an endpoint using certificate in WCF Config file
I have tried adding with the various authenticationMode setting
but its not working in customBinding
could you please help me to convert the below code to the custom binding
<basicHttpBinding>
<binding name="certBinding">
<security mode="Message">
<message clientCredentialType="Certificate" />
</security>
</binding>
</basicHttpBinding>
This is the code i have tried in custom binding
<customBinding>
<binding name="OutbBinding1" closeTimeout="00:02:00" openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:02:00">
<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Soap11" writeEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="20000000" maxArrayLength="20000000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</textMessageEncoding>
<security authenticationMode="SecureConversation">
<secureConversationBootstrap authenticationMode="AnonymousForCertificate" />
</security>
</binding>
</customBinding>

As we know, if we use the message security of BasicHttpbinding, we should set up the certificate both in the client and the server. In addition, we should also establish a certificate trust relationship between the server and the client.
One more thing needs to note is, different from the authentication mode of the transport layer security, we need to set a default service certificate (non-client certificate, use the trusted server certificates for signing messages) on the client side.
So anyway, the below configuration could achieve the same goal that authenticates the client with a certificate. please refer to the below configuration.
<customBinding>
<binding name="TehRealBinding">
<textMessageEncoding />
<security authenticationMode="MutualCertificate" />
<httpTransport />
</binding>
</customBinding>
Besides, the following document might be useful to you.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/securitybindingelement-authentication-modes
Feel free to let me know if there is anything I can help you.

Related

WCF net.tcp issued token

Does anyone have a current example of using net.tcp with message security mode of issued token. I currently have a security token service that issues tokens but not sure how to configure it with net.tcp. I only see examples of using ws2007FederationHttpBinding
<customBinding>
<binding name="wsFed">
<security authenticationMode="SecureConversation" requireSecurityContextCancellation="true">
<secureConversationBootstrap authenticationMode="IssuedToken">
<issuedTokenParameters tokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1">
<issuer address="http://localhost/STSWebHost/STSService.svc" binding="ws2007HttpBinding" />
</issuedTokenParameters>
</secureConversationBootstrap>
</security>
<tcpTransport />
</binding>
</customBinding>
I keep getting Crypto algorith not supported error? Works fine with ws2007FederationHttpBinding but I am required to use net.tcp. Anyone?
I have a working version by setting allowInsecureTransport=true. I also removed secureconversation since I don't want sessions.
<customBinding>
<binding
name="netTcpFederated">
<security
authenticationMode="IssuedTokenOverTransport"
allowInsecureTransport="true" >
<issuedTokenParameters keyType="BearerKey" />
</security>
<binaryMessageEncoding>
<readerQuotas
maxStringContentLength="1048576"
maxArrayLength="2097152" />
</binaryMessageEncoding>
<tcpTransport
maxReceivedMessageSize="2162688" />
</binding>
</customBinding>`

Lax SecurityHeaderLayout doesn't seem to be allowing timestamp to come last

I am using the following binding for my service:
<customBinding>
<binding closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00">
<textMessageEncoding messageVersion="Soap12">
<readerQuotas maxDepth="2147483647" maxBytesPerRead="2147483647" maxArrayLength="2147483647"
maxStringContentLength="2147483647" maxNameTableCharCount="2147483647" />
</textMessageEncoding>
<security authenticationMode="CertificateOverTransport" allowInsecureTransport="true" />
<httpTransport maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />
</binding>
</customBinding>
This defaults securityHeaderLayout on the security node to Strict, which requires the Timestamp node in the message to come first. I am working with another part of the corporation that does not use WCF, so the individual with whom I am working is trying to use SoapUI to test the service. SoapUI adds the Timestamp node at the end of the message. This can be moved manually, but, apparently, it gets moved back once you sign the node - so you can either have the node come first, or you can have it signed, but not both.
I've tried setting the security node to use Lax or LaxTimestampLast, but it doesn't seem to make a difference:
<security authenticationMode="CertificateOverTransport" allowInsecureTransport="true" securityHeaderLayout="Lax|LaxTimestampLast" />
When I call with my own (WCF) client using LaxTimestampLast, it fails (MessageSecurityException: Signing without primary signature requires timestamp.). Any direction would be greatly appreciated.
I had this same issue recently and I solved it by setting the messageSecurityVersion in my customBinding to a WSSecurity10 version, it had previously had a WSSecurity11 version. Here is my custom binding that works with both my WCF Client and SoapUI:
<customBinding>
<binding name="CustomBinding">
<security authenticationMode="MutualCertificate"
messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"
requireDerivedKeys="false" securityHeaderLayout="Lax" />
<textMessageEncoding messageVersion="Soap11" />
<httpsTransport />
</binding>
</customBinding>

Can't run WCF service on Local Machine

I have a wcf service that will only work once I deploy it to a server and configure through IIS. there error message I get when running it through IIS express is:
The authentication schemes configured on the host ('Ntlm, Anonymous') do not allow those configured on the binding 'BasicHttpBinding' ('Negotiate'). Please ensure that the SecurityMode is set to Transport or TransportCredentialOnly. Additionally, this may be resolved by changing the authentication schemes for this application through the IIS management tool, through the ServiceHost.Authentication.AuthenticationSchemes property, in the application configuration file at the element, by updating the ClientCredentialType property on the binding, or by adjusting the AuthenticationScheme property on the HttpTransportBindingElement.
My web.config services binging looks like this:
<services>
<service name="LMS.Services.Services.AppService" behaviorConfiguration="LargeDataRequestBehavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttp_LargeDataRequestBinding" contract="LMS.Services.Services.AppService" />
<endpoint address="mex" binding="basicHttpBinding" bindingConfiguration="basicHttp_LargeDataRequestBinding" contract="IMetadataExchange" />
</service> </services>
and my binding looks like this:
<bindings>
<basicHttpBinding>
<binding name="basicHttp_LargeDataRequestBinding" receiveTimeout="01:00:00" sendTimeout="01:00:00" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" >
</transport>
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<basicHttpBinding>
</bindings>
Any Help would be greatly appreciated.
Try changing this part. The issue is that the enum for Credential Type Windows maps to a protocol called Negotiate. IIS is informing you that Negotiate has not been enabled on your website, only Basic (no security) and Ntlm (another form of Windows Security) is allowed.
<bindings>
<basicHttpBinding>
<binding>
<security >
<transport clientCredentialType="Ntlm" >
</transport>
</security>
</binding>
</basicHttpBinding>
</bindings>
The WTF here is that there is a mismatch between "Negotiate" and "Windows".
Updating IIS Authentication settings as below fixed it in my case:
Anonymous Authentication: Disabled
Windows Authentication: Enabled

WCF Message body encryption with SSL

I am new to WCF. I am investigating the right way to have message body encryption over HTTPS (mixing both transport and message level security at the moment)
I have HttpsGetEnabled.
Using WsHttpBinding, I still see the message body unencrypted
<wsHttpBinding>
<binding name="myCustomWsHttpBinding">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None"/>
<message clientCredentialType="Certificate" />
</security>
</binding>
</wsHttpBinding>
I have also tried using custom binding but same result
<binding name="myCustomBinding">
<security authenticationMode="CertificateOverTransport"
messageProtectionOrder="EncryptBeforeSign"
includeTimestamp="true"
protectTokens="true"
>
</security>
<textMessageEncoding messageVersion="Soap11WSAddressing10" />
<httpsTransport/>
</binding>
How can we have message body encrypted when using Https? If I understand correctly message level security is independent of transport so using https is possible in this case?
In the custom binding, set authenticationMode to "mutualCertificate"

how to create nettcpbinding of this custombinding

I am new at WCF programming model and I want to use netTcpBinding. Before I ask my question below this is my custom binding :
<customBinding>
<binding name="basic">
<security authenticationMode="UserNameForCertificate"/>
<binaryMessageEncoding/>
<httpsTransport/>
</binding>
</customBinding>
When I create a service reference using a simple console application it finds a certificate and ask me to use it. And this way I can use the webservice ...
But when I change binding to netTcpBinding with TransportWithMessageCredential the service is looking for certificate and could not find it like this :
<netTcpBinding>
<binding name ="sdfsd">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
<transport clientCredentialType="None"/>
</security>
</binding>
</netTcpBinding>
ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByIssuerName, "Contoso.com").
At this point I use a CustomNameValidator and I do it programmatically.
So when I use netTcpBinding with TransportWithMessageCredential, why does the call to SetCertificate not find the installed certificate? Am I missing something ? Or do I have to add something?
ok guys...sorry but some of the message is miising ...
my custom binding is
customBinding
<customBinding>
<binding name="basic">
<security authenticationMode="UserNameForCertificate"/>
<binaryMessageEncoding/>
<httpsTransport/>
</binding>
</customBinding>
and netTcpBing that i tried to convert is :
<netTcpBinding>
<binding name ="sdfsd">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
<transport clientCredentialType="None"/>
</security>
</binding>
</netTcpBinding>