7

It seems to me that the main advantage of a JWT is that any client can read the claims and verify that you were the one who generated them. However, if you're using a symmetric key to calculate the signature, then the client has to know your signing key to verify the JWT, at which point they could generate whatever claims they wanted. Why would someone choose a symmetric algorithm over an asymmetric one?

One user's answer on a different question says:

Symmetric keys are only to be used in a peer-to-peer way so it would be pointless for the receiver to modify JWTs for which only he and the sender have a shared key

If the communication is peer-to-peer, they must have been using a secure protocol to exchange the key at some point, so what is the use of a JWT in this scenario?

The reason I ask this is because most of the examples I have seen for implementing JWT-based security in ASP.Net use symmetric keys.

Andrew Williamson
  • 8,299
  • 3
  • 34
  • 62
  • Consider JWT tokens used for login and authentication. A server that issues tokens "signed" (encrypted) with a symmetric key has the benefit that it is fast (or faster than asymmetric) and only ever needs to be verified server-side, so that the server can confirm that it, itself, was the host that generated that token. You've correctly identified that a symmetric key is silly if parties other than the generating server need to verify the token. – Luke Joshua Park Sep 24 '17 at 19:12
  • So there isn't a rule that tokens always have to be verified by the client? (I may have just assumed this was a thing) – Andrew Williamson Sep 24 '17 at 19:14
  • Nope! It is very common for servers to just use an HMAC that they can later verify to determine if it was them that issued the JWT. Simple but effective and doesn't require database access to verify. – Luke Joshua Park Sep 24 '17 at 19:29
  • @LukePark Would you like to write that up as an answer? – Andrew Williamson Sep 25 '17 at 18:48

1 Answers1

2

Tokens do not always have to be verified by the client.

As an example, in a basic Asp.Net application, the server acts as both the authentication server and the authorization server:

  • The server creates the token and gives it to the user when they log in
  • The user sends that token back to the server with every request
  • The server verifies the token, and authorizes the user

In this example, if the client is verifying the server's authenticity through a separate means (such as TLS/SSL) then the client doesn't need to verify the token returned by the server. There's no problem with the server using a symmetric encryption algorithm in this case.

Andrew Williamson
  • 8,299
  • 3
  • 34
  • 62