Strong names question ..

  • Thread starter Thread starter Leonardo D'Ippolito
  • Start date Start date
L

Leonardo D'Ippolito

Hello sirs,

I am trying to understand how strong names work.

Suppose I have lib.dll (a .net library), and also MyApplication.exe (a .NET
WinApp) . MyApplication uses lib.dll . Suppose someone decompiles lib.dll
and replaces code parts, and then recompiles again. When MyApplication.exe
will load lib.dll the next time, will it detect that it is a different dll
if they have strong names?

How can I implement this procedure? If someone can give me an example I
would appreciate!

Thanks a lot!
 
Leonardo,

If the hashvalue will be the same, the utilizing program may not
distringuish. Typically the hash value will not be the same, but if their
objective is to get the same hashvalue it's feasible. You could take
advantage of an Authenticode certificate as well.


Best regards,

Henrik Dahl
 
hi
The combination of hashing and digital signing allows .NET to protect your
assemblies from tampering. Here's how it works. First, a hash value is
created from the assembly. Then, the hash value is encrypted with your
private key and placed, along with your public key, in the assembly itself.

The CLR validates assemblies at runtime by comparing two sets of hash
values. First, the public key is used to decrypt the encoded version of the
hash. Second, a new hash is computed from the current contents of the
assembly. If the two hashes match, all is well

What happens if an assembly has been tampered with after it was signed? In
this case, the new hash value calculated at runtime won't match the stored
hash value that was encrypted with your private key. Under those
circumstances, the CLR will refuse to load the assembly.

regards
Ansil

Dimensions
Technopark
Trivandrum
(e-mail address removed)
 
Strong naming an assembly uses public/private key cryptography. So this involves two keys that are mathematically related but not derivable from eachother. Anything encrypted with one can be decrypted with the other. The idea is that one of these keys is in the public domain, the other you keep secret (the private one). When two people generate a key pair (using the strong name utility sn.exe) the key pairs they generate will be different - including the public keys.

When you sign an assembly with a key pair thet compiler put the public key oin the assembly manifest - this gives the assembly a unique name. It also calculates a hash of the file (using the algorithm that will be identified by the HashAlgortihm entry in the assembly manifest) and encrypts this with the private key. This encrypted signature is stored in the assembly as well.

When you build against a string named assembly, a hash of the public key of that assembly (the PublicKeyToken) is put in the applications manifest in an external assembly reference. Now when the app;ication runs, at some point the JIT compiler compiles a type in that assembly. When it does so it needs to locate the assembly that houses the type and so the Assembly Resolver kicks in. This pushes the assembly name and configuration information to specifiy a physical localtion from which to load the assembly.

The Assembly Loader then loads the assembly. It notices that it has a strong name - the public key is in the manifest remember. So it decrypts the signature with the public key and rehashes the assembly if the decrypted hash and the one just calculated match then the assembly hasn't been tampered with, if they differ then it does.

One caveat: the above description does not take account of various other things that may have been done to try to get around this mechanism which we can discuss if you want to go deeper.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hello sirs,

I am trying to understand how strong names work.

Suppose I have lib.dll (a .net library), and also MyApplication.exe (a .NET
WinApp) . MyApplication uses lib.dll . Suppose someone decompiles lib.dll
and replaces code parts, and then recompiles again. When MyApplication.exe
will load lib.dll the next time, will it detect that it is a different dll
if they have strong names?

How can I implement this procedure? If someone can give me an example I
would appreciate!

Thanks a lot!
 
Back
Top