I'm currently developing an Android game which saves data into a SQLite database. This is not really "sensitive" data, but I don't want users to be able to modify it (for obvious reasons of game balance, as it would be cheating). And it's quite easy to access and modify a SQLite db when your phone is rooted (there are plenty of applications for that in the market).
So should I even worry about that, or consider users with a rooted phone can do whatever they want including cheating and that's their choice? Or could I somehow encrypt the data I don't want them to modify, or add a MD5 checksum or something similar?
Another approach would be to abandon SQLite altogether and use some kind of binary files with game data.
Please let me know if some of you already encountered similar issues, and what are the approaches you followed, as well as the "good practices" in the Android gaming development community.
Thanks.
Root access for everybody and security are mutually exclusive.
Any application or user with root permissions can read and modify each and every file on your system, as well as all of the main memory. That doesn't leave many places to store a potential encryption key for the database.
You could hide parts of the key in the executables, configuration files etc, but everything you could come up with would be nothing more than obfuscation and security by obscurity.
If a user opts to grant root access to everybody, that's their decision, and it's not your job as an app developer to prevent any harm that might be caused.
Update:
Storing API keys in Android, is obfustication enough? is a pretty similar issue - it's about protecting API keys, but it's the same situation with regards to your options.
sqlcipher for Android might help here.
https://guardianproject.info/code/sqlcipher/
I think based on your requirement the best method is using consistency of data,
for example MD5 the score and time, then put score and time and MD5 in to the table, then every time wanting to use that row of DB check the MD5 of the score and time if the one in DB and the one which calculated are same, the row is consistent otherwise it was hacked!
You may find your happiness on Preferences Files Look here
Related
I read many tutorial and topic about this about SqlCipher , but I didn't understand what should I do exactly!
I have ready database in my assets folder . My database contains about 4 tables and 5000 records .I want to make it more secure.How I can do it ? Could somebody help me with this problem ? As I am novice with android , I need step by step solution . At the moment I use sqliteasset.SQLiteAssetHelper library to read database from assets folder.
Do not waste development time on encryption of client-side data - the data which should be accessible by the application in unattended manner (i.e. decrypted by application without user's input of any kind of password).
Here is an explanation of my statement:
Lets assume that you managed to protect(encrypt) your database by some encryption key and application upon startup should read all encrypted data.
It means that your application should have built-in key required for the decryption.
And any person with minimal reverse-enginering knowledge can extract both key and the database from your apk file and decrypt it.
When you design security mechanism to protect the data one of the first questions which you need to answer is:
How much time adversary will need to spend to open the data?
If your answer is something like "It will require 10,000 years to brute force my protection" then your protection is probably ok.
But right now you are trying to implement security through obscurity and it newer works.
Determined person can easily extract encryption key from your own code and decrypt your database in almost no time.
When you design client-server architecture there is only one way to protect trade secrets - place everything sensitive to the server side.
If your client-side application relies on some business sensitive information (like calling some paid APIs with your own API key) then your application has design flaw.
If your application relies on information which is not business sensitive then it does not make sense to encrypt this information.
I have an app on android. I use facebook keys,twitterkeys on my strings.xml file.
I use proguard. But when a man which want to see real code, decompile myapp , yes it is complex because I use proguard. But my strings value is seen. Is it a securty problem. I want to hide them or how can I encrypt them.
thanks
As far as I know only possible way how to achieve your goal is to physically check every user. It could be some kind of form which user has to fill with some personal data so term "physically" is maybe not the best choice here. I guess you could do that semi automatically.
Other methods are just slowing down the reverse engineer and making his life harder.
If you have the controll over your users (for example if your app is for some company employees only), you can control people who download the app by providing password secured download site and provide that password only to company employees by mail or some other way.
But after all - every secure user can be the bad guy who provide apk to some reverse engineer, so you will be never 100% safe, until .apk format change in some way.
create one encrypted file with your text data and store in assets & read it from assets by decrypting it , is one of the better solution
It encrypts the SQLLite database at page level, ok thats fine, nothing wrong with that!
but what about your source code? its compiled, but even if its compiled someone could decompile it, retrieve your password and decrypt the database?
How safe is SQLCipher?
According to the SQLCipher design documentation, it is based on secure components (AES, OpenSSL, HMAC_SHA1, PBKDF2,...). If those claims are correct, it sounds good to me.
What is a bit unusual (to me, at least) is that there is a random IV per page. This is somewhat different to the typical file system encryption mode AES-XTS. The design used by SQLCipher has certain advantages over AES-XTS, for example writing the same data again will not result in the same encrypted page. However, possibly there are disadvantages, for example I'm not quite sure if with SQLCipher it is possible to move or copy pages (copy encrypted pages to another page). It might not be possible, however from the design document I don't see how this is prevented. Such is the risk if a non-standard encryption mode is used :-) But even if this is a problem, it wouldn't allow an attacker to read the data; it would only allow certain types of attacks. Even with AES-XTS certain types of attacks are possible, so I wouldn't be worried too much.
What about your source code?
To keep things save, don't store the password in the code. Instead, let the user enter the password, or store it in a key-chain. This is possible for both Android and iOS as far as I see, but I don't know the details.
Note: this is in relation to android specifically, but the best answer might not be platform specific, hence the other tags.
Consider a game similar to angry birds: you have a bunch of levels. Each time you finish a level, the next level is available for play, but not before. How can I make it harder for players to hack my game files and unlock levels that shouldn't be available? Assume that progression data is stored locally.
My thoughts:
On android, all app files are stored in a folder that the user can only access if they have root access (by default, they never do, but it's usually very easy to get as long as you google a little). Right now, I am using an sqlite database that looks something like this:
LevelId = pk | UnlockStatus = int, 0 = locked, 1 = unlocked, 2 = completed with 1 star, ...
This is fine as long as the user doesn't have root or is not at all familiar with where app files are stored. If they have root however, this file is very easy to edit.
As far as I can tell, angry birds stores its level data in a .lua file, at least according to its name. I can find no text file or db file that contains level info. Opening this .lua in a text editor displays nothing but gibberish. I haven't tried a hex editor.
Using an sql table is very convenient. Is there an easy way to store the progression data in the sql table such that the user will have a harder time making sense of it? Ideally, it should also not be too time-consuming to implement. Being an offline game, I don't care THAT much if the player hacks it or not, so I'm looking for the best quality - implementation time trade-off. Theoretical answers that yield a lot more implementation time for considerably more quality are also appreciated however.
You best bet would be saving data using some sort of encryption. In android, SQLite doesn't offer encryption at database level. However, you may encrypt the values (records) in table and decrypt them after querying.
Another way could be saving your data as key/value pair in some sort of text file (example of .lua in angrybirds) in internal or external memory and perform encryption on the file contents. On the other hand, decrypt it at run-time and read your key/value pairs.
Tadaaa! problemo solved :)
Hacking your data (game binaries/level-data/highscore-tables etc.) which is stored locally on the device (or eventually remotely) will always be accessible (and decodable) by someone who really wants to and knows how to do it.
Each layer of security you add will only make it more difficult (and such take a longer time) for the hacker. Sometimes even adding an additional layer of security takes more time to implement on your side than for the hacker to understand it. (There are famous examples in computing history, one is the XBox IIRC).
Security by obscurity is what you try to do when encrypting the data in your case. This is not sufficient in the long term. Especially when you project meets big audience.
a simple method: store differet level data for each player.
code less than 5 lines:
//encrypt code:
save_level = "level_txt" + "#"+ md5("gamename" + "playername" + level_txt)
//decrypt code:
level_plaintxt, md5_level = save_level.split("#")
if (md5_level == md5("gamename" + "playername" + level_plaintxt))
return level_plaintxt
I need to find a way to encrypt/decrypt an images in Android.I'm new in Android programming and never been encrypt/decrypt on any other platform,so please provide me a good example,because I need to learn how to do it.I'm working on a project which needs to encrypt/decrypt images.I'll be really happy if you can help me about this.
Thanks anyway!
You can take a look at this Stackoverflow Encryption Accepted Answer
Keep in mind that this is probably going to take a lot of time to encrypt/decrypt images. You also have not set any security standards (how secure must this be) so it's hard to give an authoritative answer
Update
After your comment here are a few more things to think about. Typically faster = less secure. Are you really trying to secure the images or just make them unavailable to unauthorized users.
For instance do you only want the images to be viewable on an authorized device or are you worried about them falling into the wrong hands?
I had a problem where the images should only be shown on a device that was an authorized account, that was fairly easy to solve, a unique ID associated with the users account was used to encrypt the data, so each user had their own (unique) key on the device and on the server, encryption was done on the fly on the server side. I also only needed to encrypt part of the data (header - first 4096 bytes) to make it unusable, I wasn't trying to keep the NSA from decrypting the images, just keep them from being easily decrypted and passed around.
So that was fast and secure enough, this is why I am suggesting you figure out what you are trying to do and protect against before picking a implementation plan.