2
$\begingroup$

Encrypted fields are loaded from disk file to process memory only after file's HMAC validation is successful. Data is still encrypted in memory and will be decrypted later, on demand, when it needs to be displayed to the user (cipher is initialized on process start). The system also allows user to add new data which will be encrypted to memory and later saved to disk. CBC mode is used.

Besides file's HMAC, does adding HMAC to each encrypted field and validating it before decryption makes sense? Or in other words, should I authenticate memory data which was loaded from authenticated disk file? The goal is to make make the app as secure as possible and minimize possibilities of tampering.

$\endgroup$
  • 1
    $\begingroup$ In such cases, the answer comes from an analysis of your threat model (unstated) and security objectives (only vaguely stated). Among the reasons to worry: if a file's HMAC is checked, then the file loaded in memory, is it really the same file, or could an adversary (or malfunction) have changed it in-between? Better practice would be loading the file in memory, then check its HMAC; as a bonus, that halves the amount of data read from file. $\endgroup$ – fgrieu Nov 27 '15 at 9:22
  • $\begingroup$ What does the file-HMAC prove? Has the software/actor that initially computed the HMAC verified that the field values are what is expected (e.g. by generating them in the first place)? If yes, then I can't see what advantage authenticating the fields again would have. (Assuming you authenticated it correctly, like fgrieu points out.) $\endgroup$ – otus Nov 27 '15 at 9:24
  • $\begingroup$ @fgrieu - The file is first loaded into memory, then HMAC is verified and if verification passes then file data is parsed into fields in memory (which are still encrypted). The application is similar to a password manager, where potential adversary has access to data file. $\endgroup$ – user29154 Nov 27 '15 at 10:30
  • $\begingroup$ @otus The file HMAC proves that file was not modified after it was saved, and was initially computed by the app on saving file. $\endgroup$ – user29154 Nov 27 '15 at 10:38
  • $\begingroup$ @user29154: " Encrypted fields are loaded from disk file to process memory only after file's HMAC validation is successful " is straight contradictory with " The file is first loaded into memory, then HMAC is verified and if verification passes then file data is parsed " (which is better). I suggest you update the question (although it will remain borderline on topic). $\endgroup$ – fgrieu Nov 27 '15 at 11:52
1
$\begingroup$

[D]oes adding HMAC to each encrypted field and validating it before decryption makes sense?

No. Since you authenticate the data once, you can trust that it is the same as was originally encrypted and authenticated. That is, authenticating the ciphertext also authenticates the plaintext.

The goal is to make make the app as secure as possible and minimize possibilities of tampering.

This may sound like a good goal, but it is really not. A good goal would be to have specific security objectives and types of attacks you want to prevent. For example, you should consider what kind of security you would expect in the case that an attacker 1) was able to read the disk image or 2) was able to write arbitrary data on disk.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.