Re: API to access loaded assembly hash

From: William Stacey [MVP] (staceywREMOVE_at_mvps.org)
Date: 02/22/05

  • Next message: kiran & Dev: "WSE , encrypting signature using username token"
    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]
    > >
    >
    >
    

  • Next message: kiran & Dev: "WSE , encrypting signature using username token"

    Relevant Pages

    • Re: why in class Boolean, hashcode() of "true" is 1231 and of "false" is 1237?
      ... Including your insulting assertion that something I'd written was "nonsense"? ... We don' need no steenkin' evidence! ... This in turn affects the distribution of any naive hash function of same, ... since clumps are likely to be assigned to a relatively small subset of hash buckets and thus have relatively many bucket collisions internally. ...
      (comp.lang.java.programmer)
    • Re: Anti-Gun Hysteria!
      ... Hash: SHA1 ... you) argued that "mutli-barreled guns no longer existed"? ... So where is you evidence to back up your claim? ...
      (talk.politics.guns)
    • Re: md5 collisions and speeding tickets
      ... If integrity isn't required, then ... >>don't offer a hash. ... If it is and the hash is broken then the evidence is ... the record have not abused it and a proper procedure has been enforced in ...
      (sci.crypt)
    • Re: md5 collisions and speeding tickets
      ... >>don't offer a hash. ... The courts will tend to believe the police unless the ... unless evidence if brought in that they actually did so. ...
      (sci.crypt)
    • Re: I note that no one is mentioning Jim Bates this morning!
      ... hash values are not unique ... They claimed to have cast iron evidence of the presence of kp on the ... My husband was told that if he plead guilty our son would not be taken ... him as a sick pervert in public...in the name of child protection. ...
      (uk.legal)