![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
You can iterate through the evidence collection of a loaded assembly which gives you the hash. see the code attached. --- Dominick Baier - DevelopMentor http://www.leastprivilege.com try { Assembly a = Assembly.LoadFrom(args[0]); IEnumerator it = a.Evidence.GetEnumerator(); while (it.MoveNext()) { Console.WriteLine(it.Current); } } catch (Exception ex) { Console.WriteLine(ex.Message); } nntp://news.microsoft.com/microsoft.public.dotnet.security/<3211D764-E2EC-454A-A067-D46F6451E742 (AT) microsoft (DOT) com Hi, I'm not able to find any API to retrieve at runtime the hash of an assembly. 1/ is there any existing API (I might not have looked in the correct namespaces/classes) ? 2/ if not, why is'nt there any ? any security implication ? is it planned to have one in .Net 2.0 ? Note: I know that I can compute the hash manually (using interop or not). [microsoft.public.dotnet.security] |
#3
| |||
| |||
|
|
You can iterate through the evidence collection of a loaded assembly which gives you the hash. see the code attached. --- Dominick Baier - DevelopMentor http://www.leastprivilege.com try { Assembly a = Assembly.LoadFrom(args[0]); IEnumerator it = a.Evidence.GetEnumerator(); while (it.MoveNext()) { Console.WriteLine(it.Current); } } catch (Exception ex) { Console.WriteLine(ex.Message); } nntp://news.microsoft.com/microsoft.public.dotnet.security/<3211D764-E2EC-454A-A067-D46F6451E742 (AT) microsoft (DOT) com Hi, I'm not able to find any API to retrieve at runtime the hash of an assembly. 1/ is there any existing API (I might not have looked in the correct namespaces/classes) ? 2/ if not, why is'nt there any ? any security implication ? is it planned to have one in .Net 2.0 ? Note: I know that I can compute the hash manually (using interop or not). [microsoft.public.dotnet.security] |
#4
| |||
| |||
|
|
Thanks Dominick. Based from that, here is how to get the sha1 hash. Assembly a = Assembly.GetExecutingAssembly(); foreach(object o in a.Evidence) { Hash aHash = o as Hash; if ( aHash == null ) continue; byte[] sha1Hash = aHash.SHA1; string base64 = Convert.ToBase64String(sha1Hash); Console.WriteLine("SHA1 Hash:{0}", base64); } I have one question. Is this doing a sha1 hash over the assembly bytes as they exist or some other metadata stored in the Evidence? -- William Stacey, MVP http://mvp.support.microsoft.com "Dominick Baier [DevelopMentor]" <dbaier (AT) pleasepleasenospamdevelop (DOT) com wrote You can iterate through the evidence collection of a loaded assembly which gives you the hash. see the code attached. --- Dominick Baier - DevelopMentor http://www.leastprivilege.com try { Assembly a = Assembly.LoadFrom(args[0]); IEnumerator it = a.Evidence.GetEnumerator(); while (it.MoveNext()) { Console.WriteLine(it.Current); } } catch (Exception ex) { Console.WriteLine(ex.Message); } nntp://news.microsoft.com/microsoft.public.dotnet.security/<3211D764-E2EC-454A-A067-D46F6451E742 (AT) microsoft (DOT) com Hi, I'm not able to find any API to retrieve at runtime the hash of an assembly. 1/ is there any existing API (I might not have looked in the correct namespaces/classes) ? 2/ if not, why is'nt there any ? any security implication ? is it planned to have one in .Net 2.0 ? Note: I know that I can compute the hash manually (using interop or not). [microsoft.public.dotnet.security] |
#5
| |||
| |||
|
|
It's stored separately in runtime evidence and is subject to spoofing in the same way as the strong name public key used in evidence. If you're trying to use it to verify code identity, it would be at least somewhat safer to read it directly out of the PE file. However, if it's possible to fake the assembly load path, that won't be particularly reliable either since you could end up reading the data from the wrong (or, actually, the right <g>) file. "William Stacey [MVP]" <staceywREMOVE (AT) mvps (DOT) org> wrote in message news:uvrDLJtFFHA.3728 (AT) TK2MSFTNGP14 (DOT) phx.gbl... Thanks Dominick. Based from that, here is how to get the sha1 hash. Assembly a = Assembly.GetExecutingAssembly(); foreach(object o in a.Evidence) { Hash aHash = o as Hash; if ( aHash == null ) continue; byte[] sha1Hash = aHash.SHA1; string base64 = Convert.ToBase64String(sha1Hash); Console.WriteLine("SHA1 Hash:{0}", base64); } I have one question. Is this doing a sha1 hash over the assembly bytes as they exist or some other metadata stored in the Evidence? -- William Stacey, MVP http://mvp.support.microsoft.com "Dominick Baier [DevelopMentor]" <dbaier (AT) pleasepleasenospamdevelop (DOT) com wrote You can iterate through the evidence collection of a loaded assembly which gives you the hash. see the code attached. --- Dominick Baier - DevelopMentor http://www.leastprivilege.com try { Assembly a = Assembly.LoadFrom(args[0]); IEnumerator it = a.Evidence.GetEnumerator(); while (it.MoveNext()) { Console.WriteLine(it.Current); } } catch (Exception ex) { Console.WriteLine(ex.Message); } nntp://news.microsoft.com/microsoft.public.dotnet.security/<3211D764-E2EC-454A-A067-D46F6451E742 (AT) microsoft (DOT) com Hi, I'm not able to find any API to retrieve at runtime the hash of an assembly. 1/ is there any existing API (I might not have looked in the correct namespaces/classes) ? 2/ if not, why is'nt there any ? any security implication ? is it planned to have one in .Net 2.0 ? Note: I know that I can compute the hash manually (using interop or not). [microsoft.public.dotnet.security] |
#6
| |||
| |||
|
|
Based on some tests, it would seem the GetRawData() internal method returns the data from the assembly that is used to sign the assem. So it seems it read directly from the file so changing the file will change the rawdata and hence a md5 or sha1 hash. Are you seeing something different? -- William Stacey, MVP http://mvp.support.microsoft.com "Nicole Calinoiu" <calinoiu REMOVETHIS AT gmail DOT com> wrote in message news:uj7qaxzFFHA.3608 (AT) TK2MSFTNGP14 (DOT) phx.gbl... It's stored separately in runtime evidence and is subject to spoofing in the same way as the strong name public key used in evidence. If you're trying to use it to verify code identity, it would be at least somewhat safer to read it directly out of the PE file. However, if it's possible to fake the assembly load path, that won't be particularly reliable either since you could end up reading the data from the wrong (or, actually, the right g>) file. "William Stacey [MVP]" <staceywREMOVE (AT) mvps (DOT) org> wrote in message news:uvrDLJtFFHA.3728 (AT) TK2MSFTNGP14 (DOT) phx.gbl... Thanks Dominick. Based from that, here is how to get the sha1 hash. Assembly a = Assembly.GetExecutingAssembly(); foreach(object o in a.Evidence) { Hash aHash = o as Hash; if ( aHash == null ) continue; byte[] sha1Hash = aHash.SHA1; string base64 = Convert.ToBase64String(sha1Hash); Console.WriteLine("SHA1 Hash:{0}", base64); } I have one question. Is this doing a sha1 hash over the assembly bytes as they exist or some other metadata stored in the Evidence? -- William Stacey, MVP http://mvp.support.microsoft.com "Dominick Baier [DevelopMentor]" <dbaier (AT) pleasepleasenospamdevelop (DOT) com wrote You can iterate through the evidence collection of a loaded assembly which gives you the hash. see the code attached. --- Dominick Baier - DevelopMentor http://www.leastprivilege.com try { Assembly a = Assembly.LoadFrom(args[0]); IEnumerator it = a.Evidence.GetEnumerator(); while (it.MoveNext()) { Console.WriteLine(it.Current); } } catch (Exception ex) { Console.WriteLine(ex.Message); } nntp://news.microsoft.com/microsoft.public.dotnet.security/<3211D764-E2EC-454A-A067-D46F6451E742 (AT) microsoft (DOT) com Hi, I'm not able to find any API to retrieve at runtime the hash of an assembly. 1/ is there any existing API (I might not have looked in the correct namespaces/classes) ? 2/ if not, why is'nt there any ? any security implication ? is it planned to have one in .Net 2.0 ? Note: I know that I can compute the hash manually (using interop or not). [microsoft.public.dotnet.security] |
#7
| |||
| |||
|
|
Yes, but only when I deliberately spoof the hash. <g |
#8
| |||
| |||
|
|
Yes, but only when I deliberately spoof the hash. <g How would you spoof data in my Hash object (other then debugger). You could load an assem in your appdomain and update private vars in your Hash object, but wouldn't you need to ref my Hash object to spoof anything? tia -- William Stacey, MVP http://mvp.support.microsoft.com |
#9
| |||
| |||
|
|
Spoofing of the non-evidence approach would depend on how the private GetRawData method is implemented. For example, if it reads the data from |
#10
| |||
| |||
|
|
From: "William Stacey [MVP]" <staceywREMOVE (AT) mvps (DOT) org References: <#L1zzqnFFHA.1348 (AT) TK2MSFTNGP14 (DOT) phx.gbl uvrDLJtFFHA.3728 (AT) TK2MSFTNGP14 (DOT) phx.gbl |
|
Subject: Re: API to access loaded assembly hash Date: Tue, 22 Feb 2005 11:07:21 -0500 Lines: 10 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.224 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.224 Message-ID: <OPZrsmPGFHA.1264 (AT) TK2MSFTNGP12 (DOT) phx.gbl Newsgroups: microsoft.public.dotnet.security NNTP-Posting-Host: 24.247.172.74.bay.mi.chartermi.net 24.247.172.74 Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGP08.phx.gbl!TK2MSFTNGP1 |
|
Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.security:9198 X-Tomcat-NG: microsoft.public.dotnet.security Spoofing of the non-evidence approach would depend on how the private GetRawData method is implemented. For example, if it reads the data from Yeh, I guess we need to see how GetRawData is implemented. Cheers. -- William Stacey, MVP http://mvp.support.microsoft.com |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |