I am studying using ServiceStack as an alternative to WCF. One of my requirements is that the server and client must mutually authenticate using certificates. The client is a service, so I can’t use any type of authentication, which includes user input. In addition, the client must run on Linux using mono, so there is no Windows authentication.
I linked my server certificate to my server port using netsh.exe, confirmed that the client receives the server certificate, and the data is encrypted using wirehark. However, I can’t understand for life how to configure the server for a client certificate.
Some people have suggested using request filters to verify a client certificate, but this seems very inefficient as each request verifies a client certificate. Performance is a very high priority. Creating a custom IAuthProvider seems promising, but all of the documentation and examples focus on authentication types, which at some point are related to user interaction, not certificates.
https://github.com/ServiceStack/ServiceStack/wiki/Authentication-and-authorization
Can I use certificates for mutual authentication of client and server using my own ServiceStack?
Here is my test service for reference.
public class Host : AppHostHttpListenerBase { public Host() : base("Self-hosted thing", typeof(PutValueService).Assembly) { //TODO - add custom IAuthProvider to validate the client certificate? this.RequestFilters.Add(ValidateRequest); //add protobuf plugin //https://github.com/ServiceStack/ServiceStack/wiki/Protobuf-format Plugins.Add(new ProtoBufFormat()); //register protobuf base.ContentTypeFilters.Register(ContentType.ProtoBuf, (reqCtx, res, stream) => ProtoBuf.Serializer.NonGeneric.Serialize(stream, res), ProtoBuf.Serializer.NonGeneric.Deserialize); } public override void Configure(Funq.Container container) {} void ValidateRequest(IHttpRequest request, IHttpResponse response, object dto) { //TODO - get client certificate? } } [DataContract] [Route("/putvalue", "POST")] //dto public class PutValueMessage : IReturnVoid { [DataMember(Order=1)] public string StreamID { get; set; } [DataMember(Order=2)] public byte[] Data { get; set; } } //service public class PutValueService : Service { public void Any(PutValueMessage request) { //Comment out for performance testing Console.WriteLine(DateTime.Now); Console.WriteLine(request.StreamID); Console.WriteLine(Encoding.UTF8.GetString(request.Data)); } }
c # servicestack client-certificates mutual-authentication
r2_118
source share