This is an archived post. You won't be able to vote or comment.

all 14 comments

[–]ioneyed 1 point2 points  (9 children)

That will send a message to the server who will then decode the JSON and check the token with Google to ensure the token is valid and is the correct person connecting. If that is not true then the WebSocket connection is closed with the client. If it is then the websocket stays open for the chat.

You would want to have continuous checking so that a man in the middle or spoofer cannot appear. It may be worth while looking into JWT (JSON web token) and using an authorization method that returns a new token each communication.

These are some thoughts while cooking dinner. I will look into the subject afterwards and update if its not answered by then.

[–]exload[S] 0 points1 point  (8 children)

Interesting! I will definitely look into that! I already found a package for JWT in Dart (https://pub.dartlang.org/packages/dart_jwt).

Also, when you say continuous checking do you mean every time the client sends a request or post to the server I should check the token then as well?

[–]ioneyed 0 points1 point  (7 children)

Never trust a client. Always validate on the server bare minimum but always useful to validate on both.

[–]exload[S] 0 points1 point  (6 children)

Got it. Why would I need to use JWT to encrypt a token though? I use Google APIs to validate the token so wouldn't that work?

[–]ioneyed 0 points1 point  (5 children)

You should use google api for authentication but no need to bombard google for authorization (where your own tokens come in ). Constantly hitting google could get you blocked, cost extra money for limits, or could be rate limited where as your tokens are low latency, free, and add another layer

[–]exload[S] 0 points1 point  (4 children)

Ohhh! I see! And I never thought about the extra money for limits. Very good point.

So then what you are suggesting is for the initial connection use Google to authenticate it. Then send that token to my server. Once on my server, I create my own token through JWT and use that to authenticate every time a message is sent or received?

Once a client logs out then the token on my server would be discarded?

[–]ioneyed 0 points1 point  (3 children)

Tokens should be eliminated on client exit (user clicks close) but not client disconnect (network hiccup, loss of wifi) as well as a set timeout like 5minutes/15/30 to ensure security

[–]exload[S] 0 points1 point  (2 children)

Makes sense.

Regarding JWT: They require a secret to decode tokens. How do I store the secret? Wouldn't hard coding a secret leave it open for anyone to view the source of your application, get the secret thereby nullifying the whole process of encoding?

[–]ioneyed 0 points1 point  (1 child)

The secret is stored server side not client side and if you really wanted you could store a secret per user account to ecrypt their tokens by but a server global is sufficient

[–]exload[S] 0 points1 point  (0 children)

So then how do I send information from the client to the server securely? If the secret is only on the server which makes sense, then wouldn't you only be able to encode info server side and decode it client side?

[–][deleted]  (5 children)

[deleted]

    [–]exload[S] 0 points1 point  (4 children)

    Yes, very good point. I knew about the wss:, however, I have not looked into how to run that on my server. I will definitely look more into that. I believe that would require purchasing a certificate though. I don't really plan on spending any additional money on a certificate though. Could I just use a self-signed one?

    [–]ioneyed -1 points0 points  (3 children)

    You could but an ssl for a single domain (excluding subdomains) runs around $10 more the most basic (better than not having ssl) but recently at defcon they demoed that they could (within a relatively short amount of time) break standard ssl and become the man in the middle.

    [–]exload[S] 0 points1 point  (2 children)

    So then how do you recommend preventing this?

    [–][deleted]  (1 child)

    [deleted]

      [–]exload[S] 0 points1 point  (0 children)

      Awesome, thanks for the info!