Security and SQLite in android

2019-08-23 15:26发布

问题:

I'm developing a video game for Android. It will be an online game, which would save user's statistics, achievement, objects, etc. in the local SQLite database.

Thinking about the security... I read that a user can edit all his/her databases saved in a rooted Android device. I would not want the user to be able to edit the database of the game.

So, what can I do? Is there any option to make the DB really secure? Password? Encryption?

Thanks

回答1:

A determined attacker can get at any data on the device. If you're encrypting data on the device before putting it in the database, then you have to have keys on the device and a determined attacker can get at any keys that are stored in the devices memory or persisted.

The only way encryption would help is if neither the encryption nor the decryption happens on the untrusted device -- merely the storage. You can encrypt the sensitive data on a machine you trust, storing the encrypted bits in the database for later decrypting by a machine you trust.

You can't use a password to secure this either. Passwords stored in the device memory or persisted on the device can be read as easily as private encryption keys.

If you don't care whether the user reads data from the DB, but don't want them to be able to write data, you could have critical data signed by a trusted machine before being stored. Then if the device connects to a trusted machine, it can check the signature to verify that that critical data has not been tampered with.

EDIT:

You can't trust any computation performed on an untrusted device unless you're willing to go to fairly extraordinary lengths -- the only thing you can do is verify data routed through an untrusted system via signatures, and prevent eavesdropping by an untrusted system on data passing through it via encryption.



回答2:

If there's nothing online, I'm not sure what you can do. You can make it more difficult, but I'd say its unlikely to be absolutely secure. I think what I'd do is take a snapshop of the db at a checkpoint, and send that off to the server, and (basically) check that the data hasn't been changed by a user. If the hashes don't look right, you can cripple the account (or whatever).

I wouldn't get too crazy, though, unless you have a serious game.



回答3:

SQLite data encryption is possible, for more detail see this.

This may also help.