| 225 | } |
| 226 | |
| 227 | bool DoesCertificateExist(std::string expectedThumbprint) |
| 228 | { |
| 229 | bool exist = false; |
| 230 | HCERTSTORE hCertStore = CertOpenStore( |
| 231 | CERT_STORE_PROV_SYSTEM, |
| 232 | 0, |
| 233 | NULL, |
| 234 | CERT_SYSTEM_STORE_LOCAL_MACHINE, |
| 235 | L"MY" |
| 236 | ); |
| 237 | |
| 238 | if (!hCertStore) |
| 239 | { |
| 240 | return exist; |
| 241 | } |
| 242 | |
| 243 | DWORD dwPropId = 0; |
| 244 | char pszNameString[256]; |
| 245 | char pszStoreName[256]; |
| 246 | void* pvData; |
| 247 | DWORD cbData; |
| 248 | PCCERT_CONTEXT pCertContext = NULL; |
| 249 | while (pCertContext = CertEnumCertificatesInStore( |
| 250 | hCertStore, |
| 251 | pCertContext)) |
| 252 | { |
| 253 | while (dwPropId = CertEnumCertificateContextProperties( |
| 254 | pCertContext, |
| 255 | dwPropId)) |
| 256 | { |
| 257 | if (dwPropId != CERT_SHA1_HASH_PROP_ID) |
| 258 | { |
| 259 | continue; |
| 260 | } |
| 261 | |
| 262 | if (!CertGetCertificateContextProperty( |
| 263 | pCertContext, |
| 264 | dwPropId, |
| 265 | NULL, |
| 266 | &cbData)) |
| 267 | { |
| 268 | printf("Call #1 to GetCertContextProperty failed."); |
| 269 | fflush(stdout); |
| 270 | continue; |
| 271 | } |
| 272 | |
| 273 | pvData = (void*)malloc(cbData); |
| 274 | if (!CertGetCertificateContextProperty( |
| 275 | pCertContext, |
| 276 | dwPropId, |
| 277 | pvData, |
| 278 | &cbData)) |
| 279 | { |
| 280 | free(pvData); |
| 281 | continue; |
| 282 | } |
| 283 | |
| 284 | std::string value = hex_encode((BYTE*)pvData, cbData); |
no test coverage detected