Encryption - Cryptography has not been initialized

Options
ddks
edited March 2012 in Photon Server
Hi there,

Struggling getting the encryption to work.

Here is what I have done so far:
(1) in the client (unity) I do in the onStatusChanged event:
if (statusCode.ToString() == "Connect")
peer.EstablishEncryption();
Then to check I do a debug log of peer.IsEncryptionAvailable value

I am seeing what I was expecting:
- initial connection, encryptionavalailable = false
- in the connect status, the encryption is triggered and then encryptionavailable = true

(2) But when I do a OpCustom with encrypt = true I get this on the server log:
2012-03-13 10:21:12,650 [55] WARN Photon.SocketServer.ServerToServer.ServerPeerBase [(null)] - SendEvent - Cryptography has not been initialized.

Am I missing a step?

Thanks
Dan

Comments

  • Tobias
    Options
    Which server SDK are you using?

    You establish encryption between the Unity client and the server. So much is ok. Then, it seems you are using the server-to-server classes to communicate?
    Is server to server what you need? Or do you just want to send something encrypted to the Unity client?

    Let us know what you want to achieve.
  • ddks
    Options
    Hi,

    I am just setting up a simple load-balancing model from scratch. So the client connecting to a master which does the routing to a sub server. Using the latest Photon3Unity3D.dll and Server SDK v3-0-19-2868-RC8.

    There error is logged inside my Master but I guess it could be the routing call to the sub server, I was assuming this would nbe handled by Photon internally. Do I need to specifically decryp or something before passing it back onto the sub server and would the response back to the client be automatically be decrypted again?

    Thanks for the help
    Dan
  • Tobias
    Options
    You don't need to handle encryption nor decrypting. But you need to set it up once per connection, as it's so far not automatically done (most connections do fine without).
    Most likely, the client is sending something encrypted to your master which then tries to forward the message with the same settings - namely: encryption. If this is not established between servers, it will cause this problem.
    I will ask a colleague to for code how to turn it on server-to-server.
  • ddks
    Options
    Ok, thanks.

    alternatively I don't think encryption is needed between the servers (master-subservers) as these would be in a private network. As long as the response back to the client across the internet will be encrypted. Wouldn't having some insight in how to do this as well?

    So client <--> master is encrypted but master <-->subserver is not encrypted

    Dan
  • Tobias
    Options
    I pointed a colleague to this thread, as I'm not too deep into the server coding.
    Check the SendParameters. They should include the option for encryption. Usually we apply those of a request also to a response (which is why encrypted requests get encrypted answers by default).
  • BenStahl
    Options
    The waning is logged by the ServerPeerBase class. So i assume you are sending an encrypted operation from the unity client and than forwarding this operation to the master using the ServerPeerBase class. As Tobias noticed you should check the send SendParameters. If you are using the send paramters passed by the client the operation will be send to the master using encryption also. And if the encryption on the ServerPeerBase class was not initialized you get the warning you have described.

    Hope this helps
  • ddks
    Options
    Hi,

    My flow is as followed (and in general it seems to be working fine):

    1 client connects to "master" and establishes encryption
    2 client does a OpCustom e.g. Login which is send to the master
    3 master then routes this request to a sub server e.g. Login server
    4 Login server handles the request and sends repsonse back to master
    5 master routes response back to client

    Now i really only need encryption in step 1 and step 5, everything in between can be unencrypted. So if I follow the comments of resetting the SendParameters in step 2, I would have to reset them back in Step 5 to include encryption I assume?

    Also is this a valid overall design or should Step 4 send the response back directly to the client?

    Thanks,
    Dan
  • BenStahl
    Options
    Sorry for the late reply.

    In step 3 you should set the Encrypted property of the SendParameters to false so the operation will be sent unencypted to trhe master.
    In step on the other side you should set the property to true, so response is sent back to client encrypted.
    Also is this a valid overall design or should Step 4 send the response back directly to the client?
    You can send the reponse back directly to the client, because the master has no connection established to the client.