Re: API to access loaded assembly hash
From: William Stacey [MVP] (staceywREMOVE_at_mvps.org)
Date: 02/22/05
- Previous message: Joe Kaplan \(MVP - ADSI\): "Re: Check group membership, the sequel"
- In reply to: Nicole Calinoiu: "Re: API to access loaded assembly hash"
- Next in thread: Nicole Calinoiu: "Re: API to access loaded assembly hash"
- Reply: Nicole Calinoiu: "Re: API to access loaded assembly hash"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Tue, 22 Feb 2005 00:55:55 -0500
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@TK2MSFTNGP14.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@mvps.org> wrote in message > news:uvrDLJtFFHA.3728@TK2MSFTNGP14.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@pleasepleasenospamdevelop.com> > > wrote in message news:#L1zzqnFFHA.1348@TK2MSFTNGP14.phx.gbl... > >> 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@microsoft.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] > > > >
- Previous message: Joe Kaplan \(MVP - ADSI\): "Re: Check group membership, the sequel"
- In reply to: Nicole Calinoiu: "Re: API to access loaded assembly hash"
- Next in thread: Nicole Calinoiu: "Re: API to access loaded assembly hash"
- Reply: Nicole Calinoiu: "Re: API to access loaded assembly hash"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|