Wulf2k / DaS-PC-MPChan

77 stars 30 forks source link

Check signature when auto-updating #104

Open Chronial opened 8 years ago

Chronial commented 8 years ago

46 has information about strong name signing

Chronial commented 8 years ago

Ok, this seems to be quite difficult: http://stackoverflow.com/questions/21754960/how-to-use-iclrstrongnamestrongnamesignatureverificationex-method-to-identify

An easier quick-fix for this would be for you to enable https on your server. Certificates for that are free nowadays via let's encrypt.

Apart from that we should probably just implement our own signing. Dotnet seems to have frameworks for that: https://msdn.microsoft.com/en-us/library/system.security.cryptography%28v=vs.110%29.aspx

Something like:

Chronial commented 8 years ago

Microsoft recommends against using strong names for security: https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/strong-name-signing.md.

Wulf2k commented 8 years ago

Having the hash of the binary downloaded from the web is counterproductive. Anybody replacing the EXE download via DNS hijack would just report the hash of their own EXE in the update check.

I know it can be difficult to get right so I'll do some serious research before doing anything. Getting it right the first time is more important than stuff with security holes, so nobody has false security.

Chronial commented 8 years ago

Anybody replacing the EXE download via DNS hijack would just report the hash of their own EXE in the update check.

I wrote:

Add the encrypted hash of the binary to the update txt

They would need your private key to encrypt their changed hash.

Wulf2k commented 8 years ago

Ah, I missed encrypted in that sentence.

Wulf2k commented 8 years ago

I'll look into a free https cert as well. If that can be done securely for free, then awesome.

Probably would be good to do both though.

gpotter2 commented 8 years ago

Small note:

After download check that hash of downloaded zip file = decrypted hash

It's of course a way better to do it the other way: (encrypt the downloaded zip hash and check if it matches with the crypted correct hash), so you may use asymetrical crypting methods...

Chronial commented 8 years ago

It's of course a way better to do it the other way: (encrypt the downloaded zip hash and check if it matches with the crypted correct hash), so you may use asymetrical crypting methods...

You seem to have a misunderstand of how asymmetric cryptography works. The idea is:

hash => privatekey => encrypted_hash => publickey => hash

What has been encrypted with the private key can only be decrypted with the public key and vice versa.

If you encrypt the hash once with the private key and once with the public key, you will get different results.

gpotter2 commented 8 years ago

Oh yeah of course ... Sorry I misunderstood the way you were doing it.

Le 10 juin 2016 à 13:53, Chronial notifications@github.com a écrit :

It's of course a way better to do it the other way: (encrypt the downloaded zip hash and check if it matches with the crypted correct hash), so you may use asymetrical crypting methods...

You seem to have a misunderstand of how asymmetric cryptography works. The idea is:

hash => privatekey => encrypted_hash => publickey => hash What has been encrypted with the private key can only be decrypted with the public key and vice versa.

If you encrypt the hash once with the private key and once with the public key, you will get different results.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

Chronial commented 8 years ago

So I had a look at this and here are the options:

I personally prefer the custom approach. It feels less hacky and we have more control over it, and if we use a PKCS #1 signature with SHA-256, I am also very certain that it will be secure. Regarding security of strong names, I am feeling a little bit uneasy about the fact that ms recommends against it. But my research showed that while the implementation was sloppy before, it actually should be secure in .Net 4.5.

@Wulf2k What's your opinion on this?

Chronial commented 8 years ago

@Wulf2k ping :)

Wulf2k commented 8 years ago

Sorry for not responding sooner. I'm leaning towards (3) but haven't fully wrapped my head around all the encryption options.

I understand encryption/signing on a conceptual level but not at the implementation level. I'm currently ranking this as a slightly lower priority than the namecrash. Depending on how much time I have this weekend I might get into it after working through all of that, but figure we should definitely be doing something about update security before the end of the month. (aka, the weekend after next weekend, but sounding slightly more professional than my usual "get to it on the weekend" stance.)