Networking Protocol - RednibCoding/Rpi_Home_Automation GitHub Wiki

Networking Protocol

Concept of network communication between app and server


NOT FINAL:

Until we haven't reached a stable 1.0 release, this can and WILL be changed without announcement.


Technical:

  • TCP sockets are used

  • Messages are formated as encoded json

  • If a client wants Authorisation: Section -> Client Authorisation

  • After the client is authorised, it has to encrypt it's messages with the servers public key

  • The server uses different public and private keys each time

  • Client keys should be generated/used device bound.

  • Each REQUEST gets an ANSWER

Client                  Server

REQUEST    ----->
           <-----       RESPONSE

Json fields:

Here we define, what fields the message can/must contain

code
  • required: True
  • type: int
  • content: Defined at Status Codes section
error
  • required: False
  • type: dict
  • content: If an error occurred, this contains 2 fields
  • required-dict-fields:
    • msg: Error message which client can display to user
    • type: The exception class name
data
  • required: False
  • type: dict
  • content: Data is another dict which will then contain all the values needed

Status codes:

100 codes (Info-Codes):

101: Request Authorization
102: Not Authorised
103: Authorised

200 codes
300 codes
400 codes (Errors caused by client):
500 codes (Errors caused by server):

Client Authorisation:

Client  ---->   Server
{
    'code': 101,
    'data': {
        'key': CLIENT-PUBLIC-KEY
    }
}

If the client is not in "trusted clients" (Their key is used for checking this)

Server  ---->   Client
{
    'code': 102
}

if the client is in "trusted clients" (Their key is used for checking this)

Server  ---->   Client
{
    'code': 103,
    'data': {
        'key': SERVER-PUBLIC-KEY
    }
}

If the client was in "trusted clients" the server will now accept and process the encrypted messages from this client


Sending an action to server:

  • TODO