| 54 | PCMSG_SIGNER_INFO* pCounterSignerInfo); |
| 55 | |
| 56 | int GetCommonName(LPCWSTR szFileName, std::wstring& common_name) |
| 57 | { |
| 58 | |
| 59 | HCERTSTORE hStore = NULL; |
| 60 | HCRYPTMSG hMsg = NULL; |
| 61 | PCCERT_CONTEXT pCertContext = NULL; |
| 62 | BOOL fResult; |
| 63 | DWORD dwEncoding, dwContentType, dwFormatType; |
| 64 | PCMSG_SIGNER_INFO pSignerInfo = NULL; |
| 65 | PCMSG_SIGNER_INFO pCounterSignerInfo = NULL; |
| 66 | DWORD dwSignerInfo; |
| 67 | CERT_INFO CertInfo; |
| 68 | SPROG_PUBLISHERINFO ProgPubInfo; |
| 69 | //SYSTEMTIME st; |
| 70 | |
| 71 | int ret = 0; |
| 72 | |
| 73 | ZeroMemory(&ProgPubInfo, sizeof(ProgPubInfo)); |
| 74 | __try |
| 75 | { |
| 76 | |
| 77 | // Get message handle and store handle from the signed file. |
| 78 | fResult = CryptQueryObject(CERT_QUERY_OBJECT_FILE, |
| 79 | szFileName, |
| 80 | CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED, |
| 81 | CERT_QUERY_FORMAT_FLAG_BINARY, |
| 82 | 0, |
| 83 | &dwEncoding, |
| 84 | &dwContentType, |
| 85 | &dwFormatType, |
| 86 | &hStore, |
| 87 | &hMsg, |
| 88 | NULL); |
| 89 | if (!fResult) |
| 90 | { |
| 91 | //_tprintf(_T("CryptQueryObject failed with %x\n"), GetLastError()); |
| 92 | ret = -1; |
| 93 | __leave; |
| 94 | } |
| 95 | |
| 96 | // Get signer information size. |
| 97 | fResult = CryptMsgGetParam(hMsg, |
| 98 | CMSG_SIGNER_INFO_PARAM, |
| 99 | 0, |
| 100 | NULL, |
| 101 | &dwSignerInfo); |
| 102 | if (!fResult) |
| 103 | { |
| 104 | //_tprintf(_T("CryptMsgGetParam failed with %x\n"), GetLastError()); |
| 105 | ret = -1; |
| 106 | __leave; |
| 107 | } |
| 108 | |
| 109 | // Allocate memory for signer information. |
| 110 | pSignerInfo = (PCMSG_SIGNER_INFO)LocalAlloc(LPTR, dwSignerInfo); |
| 111 | if (!pSignerInfo) |
| 112 | { |
| 113 | //_tprintf(_T("Unable to allocate memory for Signer Info.\n")); |
no test coverage detected