Skip to content

Security: theRainbird/CoreRemoting

Security

docs/Security.md

What about HTTPS?

The built-in channels (TCP, WebSocket and Named Pipe) don't use SSL/TLS. Instead of encrypting on transport layer, CoreRemoting has integrated support for encryption on message layer, which works the same way on .NET Framework 4.x and .NET Core/.NET 5+ on Windows and Linux.
Please see next section for details.

If you want transport-level encryption, use the QUIC channel (CoreRemoting.Channels.Quic). It runs on top of TLS 1.3 provided by System.Net.Quic and requires an X.509 certificate on the server. Note that this channel targets .NET 9.0 only.

Alternatively you can implement custom CoreRemoting communication channels. Implement IServerChannel and IClientChannel to accomplish this (Have a look at Configuration to find out how you can tell CoreRemoting to use your custom channels).

Message Encryption

If message encryption is enabled (default setting), the serialized messages are signed and encrypted, before sent over the network.

RSA is used for asymmetric encryption, signing and secure key exchange.
AES is used for symmetric encryption of the message data.

No certificate files are needed. CoreRemoting uses the BCL Cryto APIs directly.

Message encryption configuration must be set the same on server and client (e.g. if server has message encryption on and client has not, the client will not be able to establish a connection). The same goes for key size. Both client and server create their own key public/private key pair. The keys must have the same key size (default is 4096).

Session Key Derivation

The symmetric shared secret used for AES message encryption is derived during the handshake.

By default a cryptographically random session key is generated per session and exchanged securely with the client during the handshake. This is the recommended and most secure approach.

Setting ServerConfig.UseLegacySessionKeyDerivation to true switches to legacy behavior, where the shared secret is derived directly from the session ID. This is only intended to keep older clients, that cannot negotiate a random session key, working with a newer server. Legacy derivation is less secure and should be avoided whenever possible.

Authentication

CoreRemoting has a built in extensible authentication system. Implement the IAuthenticationProvider interface to add authentication support to your CoreRemoting server. It has a single method that takes an AuthenticationRequestMessage (which carries the Credential array provided by the calling client) and returns an AuthenticationResponseMessage that contains the authentication state and, on success, the RemotingIdentity:

Task<AuthenticationResponseMessage> Authenticate(AuthenticationRequestMessage request);

The response message exposes IsAuthenticated, IsCompleted, AuthenticatedIdentity, optional Parameters (for multi-phase protocols) and an optional NegotiatedSharedKey. Use the static helper AuthenticationResponseMessage.Error(...) to build a failure response.

The following code shows an example implementation of IAuthenticationProvider (In a real application in most cases a database is queried in order to check credentials):

    public class SimpleAuthenticationProvider : CoreRemoting.Authentication.IAuthenticationProvider
    {
        public Task<AuthenticationResponseMessage> Authenticate(AuthenticationRequestMessage request)
        {
            var credentials = request.Credentials;

            if (credentials == null)
                return Task.FromResult(AuthenticationResponseMessage.Error());

            var userName = credentials.FindByName("username");
            var password = credentials.FindByName("password");

            //TODO: Replace with database or LDAP query in your application
            var isAuthenticated =
                userName == "admin" &&
                password == "secret";

            if (!isAuthenticated)
                return Task.FromResult(AuthenticationResponseMessage.Error("Invalid credentials"));

            return Task.FromResult(new AuthenticationResponseMessage
            {
                IsAuthenticated = true,
                IsCompleted = true,
                AuthenticatedIdentity = new RemotingIdentity
                {
                    Name = userName,
                    IsAuthenticated = true
                }
            });
        }
    }

The authentication provider must be set to the AuthenticationProvider property of the ServerConfig.

    using var server = new RemotingServer(new ServerConfig()
    {
        HostName = "localhost",
        NetworkPort = 9090,
        AuthenticationRequired = true, // <== Only authenticated clients will be able to establish a connection
        AuthenticationProvider = new SimpleAuthenticationProvider(), // <== Tell the CoreRemoting server to use your custom authentication provider
        RegisterServicesAction = container =>
        {
            ...
        }
    });

    server.Start();         

Multi-phase authentication

The authentication protocol supports multiple rounds within a single connection. A provider that needs another round (e.g. a challenge/response) returns a response with IsCompleted = false and the challenge data in Parameters. The client's IAuthenticator then sends another request, and so on, until the provider returns IsCompleted = true.

A provider can also return a NegotiatedSharedKey in its final response. As soon as authentication completes, both endpoints switch to that key for symmetric message encryption, replacing the session key from the handshake. This is used by the password-authenticated key-exchange providers (SRP, J-PAKE) and optionally by OIDC.

On the client side the protocol is driven by the IAuthenticator interface (ClientConfig.Authenticator). For simple single-phase username/password authentication the built-in DefaultAuthenticator is used automatically, so no client configuration is needed. Advanced protocols plug in their own authenticator (see the SRP, J-PAKE and OIDC packages).

Predefined Authentication Providers

The following predefined authentication providers are available as nuget packages:

LinuxPamAuthProvider Checks credentials against local Linux users (uses PAM) Credentials: username, password https://www.nuget.org/packages/CoreRemoting.Authentication.LinuxPamAuthProvider/

WindowsAuthProvider Checks credentials against Windows users Credentials: username, password, domain (optional) https://www.nuget.org/packages/CoreRemoting.Authentication.WindowsAuthProvider/

GenericOsAuthProvider Automatically detects OS (Windows/Linux) and selects the proper authentication provider for authentication of local OS users Credentials: username, password https://www.nuget.org/packages/CoreRemoting.Authentication.GenericOsAuthProvider/

SrpAuthenticationProvider Secure Remote Password (SRP) key-exchange provider. The password is never sent over the wire; instead a shared session key is negotiated and used to replace the handshake session key. Requires the matching SrpAuthenticator on the client (ClientConfig.Authenticator). Credentials: username, password https://www.nuget.org/packages/CoreRemoting.Authentication.SecureRemotePassword/

JPakeAuthenticationProvider J-PAKE password-authenticated key-exchange provider (with matching JPakeAuthenticator for the client). Like SRP, the password is never transmitted and a fresh session key is negotiated. Credentials: username, password https://www.nuget.org/packages/CoreRemoting.Authentication.JPake/

OidcAuthenticationProvider Validates OpenID Connect tokens (JWT) issued by an external identity provider such as Keycloak. The client acquires the token via the Authorization Code flow with PKCE and submits it as a credential. See OIDC for details. Credential: OIDC_TOKEN (and STEP_UP_CODE for step-up) https://www.nuget.org/packages/CoreRemoting.Authentication.Oidc/

Provide Client Credentials

Client credentials must be provided as Credential array to the Credentials property of the ClientConfig object. This must be done before the client is connected. For the simple username/password example above the built-in DefaultAuthenticator is used automatically. For multi-phase protocols (SRP, J-PAKE, OIDC) you must also set the matching ClientConfig.Authenticator.

The following code shows how to provide credentials for the SimpleAuthenticationProvider example shown above:

    using var client = new RemotingClient(new ClientConfig()
    {
        ServerHostName = "localhost",
        ServerPort = 9090,
        Credentials = new []
        {
            new Credential("username", "admin"),
            new Credential("password", "secret")
        }
    });
    
    client.Connect();

There aren't any published security advisories