CodeSignVerify.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef _RVC_CODESIGN_VERIFY_H_
  2. #define _RVC_CODESIGN_VERIFY_H_
  3. #pragma once
  4. #include "SpBase.h"
  5. #include "SimpleString.h"
  6. #if defined(_MSC_VER)
  7. #include <WinCrypt.h>
  8. #endif //_MSC_VER
  9. struct CVersionInfo
  10. {
  11. CVersion FileVersion;
  12. CVersion ProductVersion;
  13. CSimpleStringA strProductName;
  14. CSimpleStringA strAuthorName;
  15. CSimpleStringA strCompanyName;
  16. CSimpleStringA strDescription;
  17. CVersionInfo() :strProductName(""), strAuthorName(""), strCompanyName(""), strDescription(""){}
  18. };
  19. struct CSignInfo
  20. {
  21. CSimpleStringA strProgramName;
  22. CSimpleStringA strSignCertSerialNo;
  23. CSimpleStringA strSignCertIssuer;
  24. CSimpleStringA strSignCertSubject;
  25. CSmallDateTime dtSignTime;
  26. CSimpleStringA strSignCertHash;
  27. CSignInfo() :strProgramName(""), strSignCertIssuer(""), strSignCertSubject(""), strSignCertHash(""){}
  28. };
  29. #ifdef _WIN32
  30. // verify code signature & get file version
  31. class CCodeSignVerify
  32. {
  33. public:
  34. CCodeSignVerify(DWORD dwCodePage = 0x04b0, DWORD dwLangID = 0x0804);
  35. ~CCodeSignVerify();
  36. bool GetVersionInfo(const char *pszFileName, CVersionInfo &versionInfo);
  37. bool VerifySignature(const char *pszFileName, CSignInfo &signInfo);
  38. CSimpleStringA GetErrorMsg();
  39. private:
  40. bool IsSignFromTrust(const char *pszFileName);
  41. bool GetSignInfo(const char *pszFileName, CSignInfo &signInfo);
  42. void SetLastErrMsg(const char *pErrMsg = NULL);
  43. bool GetStringFileInfo(void *pVersionInfo, const char *pszKeyName, CSimpleStringA &strValue);
  44. bool GetTimeOfTimeStamp(HCERTSTORE hStore, PCMSG_SIGNER_INFO pSignerInfo, SYSTEMTIME *st);
  45. bool GetProgramName(PCMSG_SIGNER_INFO pSignerInfo, CSimpleStringA &strProgramName);
  46. bool GetSignCertInfo(HCERTSTORE hStore, PCMSG_SIGNER_INFO pSignerInfo, CSimpleStringA &strSerialNum,
  47. CSimpleStringA &strIssuer, CSimpleStringA &strSubject, CSimpleStringA &strCertHash);
  48. bool Sha1Hash(BYTE *pData, int nDataLen, BYTE hash[20]);
  49. private:
  50. CSimpleStringA m_strLastErrMsg;
  51. DWORD m_dwCodePage;
  52. DWORD m_dwLangID;
  53. };
  54. #endif //_WIN32
  55. #endif //_RVC_CODESIGN_VERIFY_H_