![]() |
#1 |
Senior Member
Join Date: Jul 2008
Posts: 157
|
![]()
Is there a way (or plugin) to test a digitally signed installer (with a code signing certificate), from within that installer, that the digital signature exists and valid?
That is, the the file has not been tampered with after it was signed? I know how to do it visually, by looking at the corresponding Properties tab. Is it possible to do this programmatically from within the installer? Thanks. |
![]() |
![]() |
![]() |
#2 |
Major Dude
Join Date: Oct 2006
Posts: 1,892
|
Wouldn't this be a chicken-egg problem? You can't enter the checksum in the installer without changing the installer's checksum...
Though I do seem to recall some signing solutions existing. Maybe someone else knows. |
![]() |
![]() |
![]() |
#3 | |
Senior Member
Join Date: Jul 2008
Posts: 157
|
Quote:
The nice thing about those digital certificates is that if anyone modifies anything inside the file (e.g. infecting with a virus), one could see immediately from the tab that it is no longer signed by so called "verified publisher". So, all we really need is a way to look at this "tab" and tell go/no-go. Any idea how to do that? |
|
![]() |
![]() |
![]() |
#4 | |
Junior Member
Join Date: Apr 2009
Location: St. Petersburg, Russia
Posts: 25
|
Quote:
|
|
![]() |
![]() |
![]() |
#5 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,976
|
There is really no point to do this, NSIS already checks itself with a CRC (And "pirates" will get around it anyways, or just extract the files without running the installer)
If you really want to do this, call Wintrust::CryptCATAdminCalcHashFromFileHandle (and WTHelperGetProvSignerFromChain or CryptCATAdminEnumCatalogFromHash?) and WinVerifyTrust with the system plugin See also: http://forum.sysinternals.com/forum_posts.asp?TID=19404 http://forum.sysinternals.com/forum_...6893&PID=83634 http://forum.sysinternals.com/forum_posts.asp?TID=19247 IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#6 |
Junior Member
Join Date: Apr 2014
Posts: 12
|
Anders, sorry for raising old topic, but how it can be done? I'll try this:
FileOpen $R0 "C:\Test.exe" r System::Call 'Kernel32::LoadLibrary(t "wintrust.dll")i.r0' System::Call 'Kernel32::GetProcAddress(i r0, m "CryptCATAdminCalcHashFromFileHandle")i.r1' System::Call "::$1(i R0, i 0, *i r2, i 0)?e" Pop $0 FileClose $R0 But $2 has no hash. Please help with this, if you can... |
![]() |
![]() |
![]() |
#7 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,976
|
You don't have to manually call LoadLibrary.
The parameters should look like (i,*i,i,i0). First call it as (i $handle,*i.r2,i0,i0) and $2 will contain the size. Then allocate and call again with the third parameter set to the address of the memory you allocated. If you are using NSIS3 you can try calling it once with something like System::Call 'wintrust::CryptCATAdminCalcHashFromFileHandle(p $handle,*i 999, @r3, i0)' IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#8 |
Junior Member
Join Date: Apr 2014
Posts: 12
|
Thank you, your answer really helped!
|
![]() |
![]() |
![]() |
#9 |
Junior Member
Join Date: Apr 2014
Posts: 12
|
Good day! Can't figure out the CryptCATAdminEnumCatalogFromHash function. If you can, please tell me what my mistake is. I simplified the code, there is no error checking.
FileOpen $0 "C:\test.exe" r System::Call 'wintrust::CryptCATAdminCalcHashFromFileHandle(p r0, *i 20, @r1, i0)' FileClose $0 ;$1 has hash System::Call 'wintrust::CryptCATAdminAcquireContext(*i r0, i0, i0)' System::Call 'wintrust::CryptCATAdminEnumCatalogFromHash(i r0, *p r1, i 20, i0, i0)i.r2' System::Call 'wintrust::CryptCATAdminReleaseContext(i r0)' $2 is always 0, i.e. not return handle to the catalog context. Thank you. |
![]() |
![]() |
![]() |
#10 |
Junior Member
Join Date: Apr 2014
Posts: 12
|
Maybe this helps, or this code:
code: |
![]() |
![]() |
![]() |
#11 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,976
|
PHP Code:
IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#12 |
Junior Member
Join Date: Apr 2014
Posts: 12
|
Anders, thank you very much, you are a genius!
|
![]() |
![]() |
![]() |
|
Tags |
cert, security, wintrust |
Thread Tools | Search this Thread |
Display Modes | |
|
|