9

Can someone put my mind at rest and see if this setup will verify that a file has come from me. An idea of how secure this is would be great and any potential attack vectors.

  1. Create a public and private key with DSACryptoServiceProvider.
  2. Add public key as application resource
  3. Create an update
  4. Get dsa hash of update using private key
  5. Send hash and update to application(Presume these can be intercepted/changed)
  6. Verify hash is correct using public key.
  7. If verified apply update

The update is an exe and will be executed so I want to make sure it's not executed if someone replaces or tampers with it.

EDIT: Updated point 6 as the public key doesn't actually generate a hash, just verifies it. I think it's this part I'm struggling with the security of.

4
  • 2
    That's exactly the right algorithm, except that you don't hash with your private key; you generate a hash and then encrypt the hash with your private key. The recipient uses your public key to decrypt and verify the hash. I'm also assuming your private key resides on an isolated medium (a USB key or non-networked computer). :-) Your private key must be kept secret, but all of the other components (the update, the hash, and your public key) needn't be kept secure.
    – Adam Liss
    Commented May 15, 2012 at 2:41
  • Thanks Adam,Just of a couple of points I think I'm missing.How do I get the hash from DSACryptoProvider without the private key?I thought hash = DSACryptoServiceProvider.fromxmlstring(privatekey).signdata(fileToGetHashFrom) - Second point. I didn't think I could encrypt data with DSA, should I be using something else? Also don't you normally encrypt data with a public key and decrypt with a private key. My key's are the wrong way round in that case? Sorry if I'm being stupid here ;-)
    – Oli
    Commented May 15, 2012 at 2:53
  • 2
    @Oli creating digital signatures is often described as a 2-step process consisting of 1) generating a hash of the data to be signed, then 2) transforming the hash using the private key, in a way that it can be verified using the public key and can't be forged. The one-way nature of the generate/verify process bears similarities to encryption/decryption, only using the public and private keys "in reverse". DSACryptoServiceProvider will take care of all these details in exactly the way you've commented, but I think Adam's point is that the private key itself is not used to generate the hash. Commented May 15, 2012 at 8:22
  • 1
    @Anton Think it's just clicked. So you're saying the DSACryptoServiceProvider.SignData() method will first create the hash and then, using the private key, transforms the hash using the private key so it can only be made sense of using the public key. Thus if an attacker doesn't have the private key they can't generate a hash that will match when un transformed by the public key. I think my confusion was coming from the fact I had it in my head that the method was returning the actual hash. Please create an answer to I can accept.
    – Oli
    Commented May 15, 2012 at 10:08

1 Answer 1

1

Your approach looks good. The question remaining is how secure is your application on the client. Is there a chance that someone could tamper with the executable? Maybe switch the public key in the application resource?

It is getting theoretical here, but I wold suggest a small modification to step 6: Be specific which exact public key you want to use. If some attacker could switch the key in the application resource he could send an altered package with a correct hash for another private key. This may be only a minor concern since the attacker already modified your software. But if he only could replace the application resource and nothing else he would have then the ability to let your application update itself with his malicious code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.