SystemCertificates.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "os/c-api/il2cpp-config-platforms.h"
  2. #if IL2CPP_TARGET_WINDOWS_DESKTOP || IL2CPP_TARGET_WINRT || IL2CPP_TARGET_WINDOWS_GAMES
  3. #include "os/SystemCertificates.h"
  4. #include "WindowsHeaders.h"
  5. namespace il2cpp
  6. {
  7. namespace os
  8. {
  9. void* SystemCertificates::OpenSystemRootStore()
  10. {
  11. HCERTSTORE hStore = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, NULL, CERT_STORE_READONLY_FLAG, L"ROOT");
  12. if (hStore == NULL)
  13. return 0;
  14. return hStore;
  15. }
  16. int SystemCertificates::EnumSystemCertificates(void* certStore, void** iter, int *format, int* size, void** data)
  17. {
  18. HCERTSTORE hStore = (HCERTSTORE)certStore;
  19. *format = DATATYPE_INTPTR;
  20. // Build list of system certificates
  21. PCCERT_CONTEXT pContext = (PCCERT_CONTEXT)*iter;
  22. if (pContext = CertEnumCertificatesInStore(hStore, pContext))
  23. {
  24. *iter = (void*)pContext;
  25. *data = pContext->pbCertEncoded;
  26. *size = pContext->cbCertEncoded;
  27. return TRUE;
  28. }
  29. else if (*iter)
  30. {
  31. CertFreeCertificateContext((PCCERT_CONTEXT)*iter);
  32. }
  33. return FALSE;
  34. }
  35. void SystemCertificates::CloseSystemRootStore(void* cStore)
  36. {
  37. CertCloseStore((HCERTSTORE)cStore, 0);
  38. }
  39. }
  40. }
  41. #endif // IL2CPP_TARGET_WINDOWS_DESKTOP || IL2CPP_TARGET_WINRT || IL2CPP_TARGET_WINDOWS_GAMES