Search code examples
encryptioncryptographyphoton

Mandate encryption on photon server


The photon docs state that

In the application frameworks we provide (Lite, LoadBalancing, etc.), the server automatically responds encrypted, if an operation was sent encrypted. This makes it safe to fetch critical data by simply requesting with encryption turned on.

Can it be made mandatory on the server side? So that Photon doesn't process certain events if the operation is invoked or received un-encrypted?


Solution

  • Yes - you can check if the client sent the request encrypted in OnOperationRequest in the peer:

    protected override void OnOperationRequest(OperationRequest request, SendParameters sendParameters)
    {
    ...
    if (!sendParameters.Encrypted)
    {
        string message = string.Format("Only encrypted operations allowed.");
        var response = new OperationResponse { ReturnCode = (short)ErrorCode.OperationDenied, DebugMessage = message, OperationCode = request.OperationCode };
        this.SendOperationResponse(response, sendParameters);
        return;
    }
    

    You would implement your own peer and inherit from the frameworks peer, have a look at MyAppliction in Lite.