views:

266

answers:

3

In order to prevent somebody from grabbing my data easily, I cache data from my service as encrypted files (copy protection, basically).

However, in order to do this, I must store the encryption key within the .NET assembly so it is able to encrypt and decrypt these files.

Being aware of tools like Red Gate's .NET Reflector which can pull my key right out, I get a feeling that this is not a very safe way of doing it... are there any best practices to doing this?

+5  A: 

You have to decide what is an acceptable level of risk. There is no "safe" way of doing this.

If the risk of someone using reflector, or just opening up the assembly using the System.Reflection.Assembly class and grabbing the resource that way, is too great, then your next step is probably to download the key from the server when you start up.

Then someone will have to do something like debug while using your code and grab the key that way. You can expire stuff that is cached and swap out the keys. You can make it so that individuals each have their own keys to protect one user's data from another user.

You can do a lot of stuff but if your goal is to keep someone from being able to decrypt information that an assembly you are putting on their machine has the ability to decrypt, you should know it's pretty much impossible. All you can really do is elevate the cost of pirating your keys/data; you can't stop it.

+1 for pointing out the futility and the cost to the hacker, but he should also try to minimize the impact (see my answer for an attempt at explaining what I mean here)
lexu
Yeah, after reading your post, and giving it some thought, I figured it all comes down to a cost/risk evaluation. I came up with a scheme that probably discourages most people from trying, save the top 5-10% of computer savvy users, which is an "acceptable" risk.
Alex
I'm glad. You probably made the right decision and, if not, you can always change it. ;)
A: 

You cannot prevent decription, but you can prevent re-encryption of falsified data:

As long as your code runs on a computer accessible by others, there is no way you can prevent them from examining the program. Decompiling and Analysis does cost time however. As MaxGuernseyIII points out, it is all about acceptable threat levels.

In your case the problem is not so much that that a hacker can decompile your code, but much more that they can change the data you want to protect (who owns the license).

So you can use a public key cryptography method to encrypt the data. That way the hacker can read, but he cannot re-encrypt.

lexu
Public Key Cryptography won't help here, as far as I can tell (and also, you never directly use a PK system (at least RSA) to encrypt data; it should only be used to encrypt keys to a symmetric algorithm (such as AES)).
Noon Silk
Even then, a sufficiently skilled hacker can get around it. Disassemble, swap in your own key, boom. Encrypted stuff is suddenly readable. You can prevent that data from being fed back up to the server by signing it on the server side, though... you are right about that. It all depends on what the actual need is; as is the case with so many of these questions.
There are no re-encryption concerns, the cached files are sound bites that users pay to get access to, and when their subscription expires, I don't want them to be able to access them anymore.
Alex
@MaxGuernseyIII: You are correct about the local (to the client) implications... the moment code runs in a unprotected environment, it must be considered suspect... 'thread' :-) level and all that.
lexu
A: 

As Max hints at, you need to consider a threat model.

What sort of attackers are you worried about? (It's legitimate to be concerned about some, and not so legitimate to be concerned about others). Typical categories could be "non-computer savvy user who purchased program", "dedicated person willing to spend hours on a solution", "casual user who knows how to find cracks online", etc.

Depending on your exact scenario, solutions may be different.

One interesting/sad item to note, is that if your product is popular, then it takes only one or two dedicated people to sit down and break it and then release the patch for all. This is the nature of software, I suppose, and it's an unsolved problem when your entire application runs on their machine.

Clearly, the implication is that it isn't an issue if your application runs as a website - i.e. it's on a machine of your control.

I know this isn't a particularly useful answer.

Noon Silk
Did you mean I hinted at considering a "threat" model? ;)
@MaxGuernseyIII: Oops .. No prizes for guessing what I was working on while writing that post :P
Noon Silk
Dang. I was hoping for a ribbon...