Skip to content
⌘ NSIS Forum Archive

Crypto Plugin

46 posts

GAG#edited
NSIS sub forum @Winamp.com

Anders,
I mean NSIS sub forum, if it's backuped, then OK
Nemehy#
CryptAcquireContext NTE_BAD_KEYSET (0x80090016)

Hi,

I use this plugin to compute MD5 of some files.
It works well on Windows 7 & Windows 10.
But it does not work with Windows Server 2008, neither Windows Server 2012.
The error returned is "CryptAcquireContext=0x80090016"
I try to run with administrator rights, but the same error is returned

Microsoft gives this solution: https://support.microsoft.com/en-us/kb/238187
I don't know if it was apply in the previous release?

Is there someone who still maintains this plugin?

Thank you by advance !
Anders#
Originally Posted by Nemehy View Post
But it does not work with Windows Server 2008, neither Windows Server 2012.
The error returned is "CryptAcquireContext=0x80090016"
Did you try the plugin attached in this thread? The release notes say it fixes 0x80090016.
Nemehy#
I use the following one http://nsis.sourceforge.net/Crypto_plug-in.
It seems to be the same.
(I check: the URL to download plugin are identical)
GAG#
Nemehy,
I assume that you installed latest version: Crypto Plugin 1.2 build 1030 (cryptoplg12.zip).
And you are testing with Crypto Hash Calculator::Crypto Plugin Test (hashcalc12.zip)

Please, confirm.
Nemehy#
Hi Gag,

Sorry for the delay of my response.
I use example "HashCalc" (download form your link hashcalc12.zip) on Windows Server 2008, and I obtain the same error code, either with a text or a file:
For a file:
Hash of file 'C:\Users\Administrateur\Documents\test.txt':
MD5: [Error: CryptAcquireContext=0x80090016.]
For a text:
Hash of 19 bytes string 'String to be hashed':
MD5: [Error: CryptAcquireContext=0x80090016.]
My second try is to install NSIS on Windows Server 2008, then compile the example hashcalc given with the crypto plugin (download from your link cryptoplg12.zip). But I have same error.

Do not hesitate if you wish other tests.

Thank you by advance
Anders#
To me it does not look like the problem has been fixed, it should be calling CryptAcquireContext with CRYPT_VERIFYCONTEXT or the more complex version; call with 0 and if it fails with NTE_BAD_KEYSET, call again with CRYPT_NEWKEYSET. The plugin in these zip files seems to be packed and not with UPX as noted in the docs? Packing such small plugins is pointless.

@Nemehy: Please try this and paste the output:
!include LogicLib.nsh
!define PROV_RSA_FULL 1
!define CALG_SHA1 0x00008004 
!define HP_HASHVAL 2
!define CRYPT_NEWKEYSET     0x00000008
!define CRYPT_VERIFYCONTEXT 0xf0000000
Section
!macro HashAnsiStringWithCryptoContext cctx alg string
System::Store S
Push ${cctx}
StrCpy $9 "${string}"
System::Call 'ADVAPI32::CryptCreateHash(i${cctx},i${alg},i0,i0,*i.r1)i.r0'
${If} $0 <> 0
    StrLen $0 $9
    System::Call 'ADVAPI32::CryptHashData(ir1,mr9,ir0,i0)i.r0'
    System::Call 'ADVAPI32::CryptGetHashParam(ir1,i${HP_HASHVAL},i0,*i0r9,i0)i.r0'
    ${If} $0 <> 0
        System::Alloc $9
        Pop $0
        System::Call 'ADVAPI32::CryptGetHashParam(ir1,i${HP_HASHVAL},ir0,*ir9,i0)'
        StrCpy $2 ""
        IntOp $9 $9 - 1
        ${For} $1 0 $9
            System::Call '*$0(&i$1,&i1.r3)'
            IntFmt $3 "%02X" $3
            StrCpy $2 $2$3
            ${Next}
        DetailPrint Hash=$2
        System::Free $0
    ${EndIf}
    System::Call 'ADVAPI32::CryptDestroyHash(ir1)'
${EndIf}
System::Call 'ADVAPI32::CryptReleaseContext(is,i0)'
System::Store L
!macroend
System::Call 'ADVAPI32::CryptAcquireContext(*i.r1,i0,i0,i${PROV_RSA_FULL},i${CRYPT_VERIFYCONTEXT})i.r0?e'
Pop $2
DetailPrint "CryptAcquireContext(...,CRYPT_VERIFYCONTEXT) returned $0 with handle $1 GLE=$2"
${If} $0 <> 0
    !insertmacro HashAnsiStringWithCryptoContext $1 ${CALG_SHA1} "The quick brown fox jumps over the lazy dog"
${EndIf}
System::Call 'ADVAPI32::CryptAcquireContext(*i.r1,i0,i0,i${PROV_RSA_FULL},i0)i.r0?e'
Pop $2
DetailPrint "CryptAcquireContext(...,0) returned $0 with handle $1 GLE=$2"
${If} $0 = 0
    System::Call 'ADVAPI32::CryptAcquireContext(*i.r1,i0,i0,i${PROV_RSA_FULL},i${CRYPT_NEWKEYSET})i.r0?e'
    Pop $2
    DetailPrint "CryptAcquireContext(...,CRYPT_NEWKEYSET) returned $0 with handle $1 GLE=$2"
${EndIf}
${If} $0 <> 0
    !insertmacro HashAnsiStringWithCryptoContext $1 ${CALG_SHA1} "The quick brown fox jumps over the lazy dog"
${EndIf}
SectionEnd 
Nemehy#
@Anders,
Your analyze seems correct:

The result on Windows 2008:
CryptAcquireContext(...,CRYPT_VERIFYCONTEXT) returned 1 with handle 5385368 GLE=0
Hash=2FD4E1C67A2D28FCED849EE1BB76E7391B93EB12
CryptAcquireContext(...,0) returned 0 with handle 0 GLE=-2146893802
CryptAcquireContext(...,CRYPT_NEWKEYSET) returned 1 with handle 5385368 GLE=0
Hash=2FD4E1C67A2D28FCED849EE1BB76E7391B93EB12
Completed
Same result on Windows server 2012:
CryptAcquireContext(...,CRYPT_VERIFYCONTEXT) returned 1 with handle 5366808 GLE=0
Hash=2FD4E1C67A2D28FCED849EE1BB76E7391B93EB12
CryptAcquireContext(...,0) returned 0 with handle 0 GLE=-2146893802
CryptAcquireContext(...,CRYPT_NEWKEYSET) returned 1 with handle 5366808 GLE=0
Hash=2FD4E1C67A2D28FCED849EE1BB76E7391B93EB12
Completed
Anders#
I threw something together but did not test much so please report back if it works or not.

Since the source was lost this is a complete rewrite. I added SHA2 support (Only works on XP.SP3 and later) and the Unicode version has an extra function (HashUTF16LE) that works like HashData except the string is hashed as UTF16LE and not a ANSI string.

Edit: Removed attachment and moved the experimental v1.3 download to the wiki page.
CritterNYC#
Is there any chance we can get the source code released for this under an open source license?
Anders#
I might have it on another machine somewhere but this is not really my plug-in, I just had to take action quickly because the old plug-in was broken.

I don't think there is anything special going on in the source, it is just a thin wrapper around the Windows Crypto API pretty much the same as http://forums.winamp.com/showpost.ph...8&postcount=37. Do you have a specific problem you are trying to solve?
CritterNYC#
No, but I'd like to use it with an open source project. While the license defaults to zlib for files hosted on the NSIS project pages including plugins, the source didn't seem to be included with this one. I always ensure the source is available (and included with my bundles) for the open source components I use in my projects.
CritterNYC#
Ah, so it does. That's a shame. I'll look into either writing my own or handling it in our companion Delphi app via the open source Indy framework.