views:

261

answers:

3

Through the years I've come across this scenario more than once. You have a bunch of user-related data that you want to send from one application to another. The second application is expected to "trust" this "token" and use the data within it. A timestamp is included in the token to prevent a theft/re-use attack. For whatever reason (let's not worry about it here) a custom solution has been chosen rather than an industry standard like SAML.

To me it seems like digitally signing the data is what you want here. If the data needs to be secret, then you can also encrypt it.

But what I see a lot is that developers will use symmetric encryption, e.g. AES. They are assuming that in addition to making the data "secret", the encryption also provides 1) message integrity and 2) trust (authentication of source).

Am I right to suspect that there is an inherent weakness here? At face value it does seem to work, if the symmetric key is managed properly. Lacking that key, I certainly wouldn't know how to modify an encrypted token, or launch some kind of cryptographic attack after intercepting several tokens. But would a more sophisticated attacker be able to exploit something here?

A: 

A symmetric encryption approach is as secure as the key. If both systems can be given the key and hold the key securely, this is fine. Public key cryptography is certainly a more natural fit.

Draemon
Its true, symmetric encryption IS as secure as its key - BUT the question you should be asking is "secure for what?" As the OP pointed out, symetric encryption is great for CONFIDENTIALITY, but does not help at all with INTEGRITY.
AviD
Of course it does. You cannot construct a fake message from the sender without the symmetric key, just as in public key cryptography you cannot fake a message from the sender without their private key.
Draemon
I think you meant it doesn't help with AUTHENTICATION, which it doesn't, but since the OP talked about two applications communicating, I'm not sure how relevant that is.
Draemon
AUTHENTICATION is important because the communication channel is public, i.e. the token is part of an HTTP request. Anyone on the internet can attempt to construct a fake token and submit it to the token-processing component of the application.Along with the AES encryption, we used an HMAC to authenticate the token, and ensure message integrity. (as suggested by Avid, Accipitridae, and Tom)
Michael Lucas
@Michael I think you misunderstood me. If there are a number of apps/machines authorised to communicate using this channel, symmetric encryption provides no way to distinguish their identity. The very fact they can construct a valid token is enough to guarantee secure AUTHORIZATION. Although I'm not 100% clear from your comment if that's what you're driving at.
Draemon
+4  A: 

Part of it depends on the Encryption Mode. If you use ECB (shame on you!) I could swap blocks around, altering the message. Stackoverflow got hit by this very bug.

Less threatening - without any integrity checking, I could perform a man-in-the-middle attack, and swap all sorts of bits around, and you would receive it and attempt to decrypt it. You'd fail of course, but the attempt may be revealing. There are side-channel attacks by "Bernstein (exploiting a combination of cache and microarchitectural characteristics) and Osvik, Shamir, and Tromer (exploiting cache collisions) rely on gaining statistical data based on a large number of random tests." 1 The footnoted article is by a cryptographer of greater note than I, and he advises reducing the attack surface with a MAC:

if you can make sure that an attacker who doesn't have access to your MAC key can't ever feed evil input to a block of code, however, you dramatically reduce the chance that he will be able to exploit any bugs

Tom Ritter
Well put! In addition, the point of using a MAC instead of digital signature (integrity protection via symmetric encryption instead of public key cyrptography) is an excellent one - no point in all that overhead for RSA/DSA and the like, since your system is the only one that needs to verify it.
AviD
Footnoted article is definitely worth reading.
Todd Owen
+2  A: 

Yup. Encryption alone does not provide authentication. If you want authentication then you should use an message authentication code such as HMAC or digital signatures (depending on your requirements).

There are quite a large number of attacks that are possible if messages are just encrypted, but not authenticated. Here is just a very simple example. Assume that messages are encrypted using CBC. This mode uses an IV to randomize the ciphertext so that encrypting the same message twice does not result in the same ciphertext. Now look what happens during decryption if the attacker just modifies the IV but leaves the remainder of the ciphertext as is. Only the first block of the decrypted message will change. Furthermore exactly those bits changed in the IV change in the message. Hence the attacker knows exactly what will change when the receiver decrypts the message. If that first block was for example a timestamp an the attacker knows when the original message was sent, then he can easily fix the timestamp to any other time, just by flipping the right bits.

Other blocks of the message can also be manipulated, though this is a little trickier. Note also, that this is not just a weakness of CBC. Other modes like OFB, CFB have similiar weaknesses. So expecting that encryption alone provides authentication is just a very dangerous assumption

Accipitridae