Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CNG replacement for CryptQueryObject

I'm interested in trying to read fields out of a digital signature. I have code that calls CryptQueryObject, then CryptMsgGetParam to get some fields and finally CertFindCertificateInStore to load the certificate.

Any hints on how to do this using the Cryptography Next Generation APIs? Microsoft tells me CryptQueryObject is deprecated but doesn't point to its replacement.

like image 859
dockd Avatar asked Jan 11 '18 01:01

dockd


1 Answers

CryptDecodeObject[Ex] is not marked as deprecated. Just sayin'.

You can emulate the logic of detecting the blob type by calling CryptDecodeObjectEx in a loop with different object types to see which one doesn't error out.

That said, if you use CryptQueryObject to parse a file/data block (as opposed to detecting its type), and you have a good idea what that is, see if there's a subject type constant for your data block under https://learn.microsoft.com/en-us/windows/win32/seccrypto/constants-for-cryptencodeobject-and-cryptdecodeobject

In general, CryptoAPI functions that deal with ASN.1 data structures (certs, CSRs, CRLs and the like) are not deprecated and have no counterpart in CNG API. Maybe this one was marked as deprecated by mistake.

like image 104
Seva Alekseyev Avatar answered Nov 07 '22 05:11

Seva Alekseyev