Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easiest way to sign/certify text file in C++?

I want to verify if the text log files created by my program being run at my customer's site have been tampered with. How do you suggest I go about doing this? I searched a bunch here and google but couldn't find my answer. Thanks!

Edit: After reading all the suggestions so far here are my thoughts. I want to keep it simple, and since the customer isn't that computer savy, I think it is safe to embed the salt in the binary. I'll continue to search for a simple solution using the keywords "salt checksum hash" etc and post back here once I find one.

like image 772
user355008 Avatar asked Jun 01 '10 02:06

user355008


3 Answers

Obligatory preamble: How much is at stake here? You must assume that tampering will be possible, but that you can make it very difficult if you spend enough time and money. So: how much is it worth to you?

That said:

Since it's your code writing the file, you can write it out encrypted. If you need it to be human readable, you can keep a second encrypted copy, or a second file containing only a hash, or write a hash value for every entry. (The hash must contain a "secret" key, of course.) If this is too risky, consider transmitting hashes or checksums or the log itself to other servers. And so forth.

like image 110
egrunin Avatar answered Oct 04 '22 20:10

egrunin


This is a quite difficult thing to do, unless you can somehow protect the keypair used to sign the data. Signing the data requires a private key, and if that key is on a machine, a person can simply alter the data or create new data, and use that private key to sign the data. You can keep the private key on a "secure" machine, but then how do you guarantee that the data hadn't been tampered with before it left the original machine?

Of course, if you are protecting only data in motion, things get a lot easier.

Signing data is easy, if you can protect the private key.

Once you've worked out the higher-level theory that ensures security, take a look at GPGME to do the signing.

like image 35
WhirlWind Avatar answered Oct 04 '22 21:10

WhirlWind


You may put a checksum as a prefix to each of your file lines, using an algorithm like adler-32 or something. If you do not want to put binary code in your log files, use an encode64 method to convert the checksum to non binary data. So, you may discard only the lines that have been tampered.

like image 23
Jorg B Jorge Avatar answered Oct 04 '22 22:10

Jorg B Jorge