tags:

views:

83

answers:

3

Hi everyone, I've been working on a project in C++ using openGL and am looking to save the current scene to a text file. Something simple along the lines of, cube at x,y,z and its color etc.

My question is about how to make sure that the file has not been changed by a user. I thought about calculating a checksum of the string and including that in the file.

e.g. checksum, string

But again this is open to the user modifying the values.

Any recommendations or is this just a case of writing a good parser?

Cheers

+3  A: 

theoretically: you can't.

practically: encrypt it and obfuscate the key within your program (this is how much of DRM works)

although you will never be able to stop a determined user. Why is it so important that the user can't modify it?

If you want users to be able to read, but not modify make the last line a HMAC of the file and a secret key.

cobbal
The idea was to ensure that the file loaded was correctly formatted and was not going to cause a problem during loading. I guess it really is a case of writing a decent parser after all. Thanks for your input anyways.
Laurence Dawson
If you only want to ensure a correct format then definitely go with the "decent parser" route.
Laurynas Biveinis
A: 

How strict is your requirement that the file not be user-modifiable? That is, how much effort are you willing to expend to make sure the user can't tinker with the file? Does the file need to be user-readable? If you really don't want the user to change the file, maybe encryption of some sort is the answer (provided the user doesn't need to be able to read the file). Something like this trivial XOR encryption scheme might be enough.

mrkj
+1  A: 

Instead of preventing the user from changing the file is better to validate file's content before using it. Create a good parser that is able to detect (and repair?) errors.

Let the user do whatever he wants because some errors might be fixable. Give warnings. With hashing you will prevent your users to do anything.

Victor Hurdugaci