Closed krwq closed 4 years ago
Also what I found useful is size of: DOS Header + PeHeader + PEOptionalHeader + DataDirectory headers (after this point there is padding and then sections) as the padding is not being hashed when calculating hash for the strong name signing.
We exposed more APIs, perhaps not sufficient yet, but I think close. See TestChecksumAndAuthenticodeSignature test in https://source.dot.net/#System.Reflection.Metadata.Tests/PortableExecutable/PEBuilderTests.cs,663
Nice! Thanks @tmat!
We need to find out if the scenario of signing built binary has good enough API. Maybe we do not need any API at all.
Looking forward about signing API (sign/verify) for PE/COFF formats. The SignTool.exe is windows only and has no switch to turn off revocation check.
This library does not implement signing, the discussion was about exposing enough API so that one could implement strong name signing on top of this API. This issue remains only about exposing offsets. Note that strong-name signing is different from Authenticode signing, which is what signtool does. We aren't discussing authenticode at all in this issue.
I took a look at what was exposed and it looks like it covers @krwq's suggestion.
checksum offset (and optionally a size)
blob headers
peHeaders.PEHeaderStartOffset
I believe MetadataReader should have more APIs which tell me about offsets.
I. e.: Let's say I'm writing strong name signer, there are few steps required (assuming that assembly is already delayed signed):
to calculate hash you need to skip some parts of the PE file like:
so I need to have offsets and sizes for each of those. For blobs there are already APIs: i.e.:
what is missing is:
for blob headers we can do simple change in System.Reflection.PortableExecutable.DirectoryEntry which is:
For stuff like CheckSum offset we need something like this:
cc: @nguerrera @tmat
What are your thoughts? With good modifications we could probably reuse some of those types when writing MetadataWriter (assuming we are planning to do that)