How to verify that my orgainization signed a trusted windows binary?

前端 未结 1 1038
既然无缘
既然无缘 2020-12-30 10:38

This is a followup question to question 1072540, \'WinVerifyTrust to check for a specific signature?\'.

I want to write a C++ function Lets call it TrustedByUs

相关标签:
1条回答
  • 2020-12-30 11:24

    You want the CMSG_SIGNER_INFO_PARAM instead.

    You can use this to get the entire certificate by looking up the certificate in the certificate store returned by CryptQueryObject:

    CryptMsgGetParam(hMsg, 
                     CMSG_SIGNER_INFO_PARAM, 
                     0, 
                     NULL, 
                     &dwSignerInfo);
    PCMSG_SIGNER_INFO pSignerInfo = (PCMSG_SIGNER_INFO) malloc(dwSignerInfo);
    CryptMsgGetParam(hMsg, 
                     CMSG_SIGNER_INFO_PARAM, 
                     0, 
                     pSignerInfo, 
                     &dwSignerInfo);
    
    PCCERT_CONTEXT pCertContext = CertFindCertificateInStore(hStore,
                                              ENCODING,
                                              0,
                                              CERT_FIND_SUBJECT_CERT,
                                              (PVOID)pSignerInfo,
                                              NULL);
    // Compare with your certificate:
    // - check pCertContext->pbCertEncoded (length is pCertContext->cbCertEncoded)
    
    // *OR*
    // Compare with your public-key:
    // - check pCertContext->pCertInfo->SubjectPublicKeyInfo.Algorithm and
    //   pCertContext->pCertInfo->SubjectPublicKeyInfo.PublicKey
    
    0 讨论(0)
提交回复
热议问题