| 85 | } |
| 86 | |
| 87 | bool loadSystemCertificates([[maybe_unused]] mbedtls_x509_crt* x509crt, [[maybe_unused]] mbedtls_x509_crl* x509crl) |
| 88 | { |
| 89 | #if defined(SFML_SYSTEM_WINDOWS) |
| 90 | static const auto getErrorString = [](DWORD error) -> std::string |
| 91 | { |
| 92 | PTCHAR buffer = nullptr; |
| 93 | if (FormatMessage(FORMAT_MESSAGE_MAX_WIDTH_MASK | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, |
| 94 | nullptr, |
| 95 | error, |
| 96 | 0, |
| 97 | reinterpret_cast<PTCHAR>(&buffer), |
| 98 | 0, |
| 99 | nullptr) == 0) |
| 100 | { |
| 101 | return "Unknown error."; |
| 102 | } |
| 103 | |
| 104 | const sf::String message = buffer; |
| 105 | LocalFree(buffer); |
| 106 | return message.toAnsiString(); |
| 107 | }; |
| 108 | |
| 109 | const auto loadStore = [&](const char* store) |
| 110 | { |
| 111 | auto* systemStore = CertOpenSystemStoreA(0, store); |
| 112 | |
| 113 | if (systemStore == nullptr) |
| 114 | { |
| 115 | sf::err() << "Failed to open Windows certificate store: " << getErrorString(GetLastError()) << std::endl; |
| 116 | return false; |
| 117 | } |
| 118 | |
| 119 | const CERT_CONTEXT* cert{}; |
| 120 | cert = CertEnumCertificatesInStore(systemStore, cert); |
| 121 | |
| 122 | while (cert) |
| 123 | { |
| 124 | if (cert->dwCertEncodingType == X509_ASN_ENCODING) |
| 125 | { |
| 126 | // Certificate parsing might fail because a certificate makes use of intentionally removed features |
| 127 | // We can just ignore the certificate and move on to the next one |
| 128 | mbedtls_x509_crt_parse(x509crt, cert->pbCertEncoded, cert->cbCertEncoded); |
| 129 | } |
| 130 | |
| 131 | cert = CertEnumCertificatesInStore(systemStore, cert); |
| 132 | } |
| 133 | |
| 134 | const CRL_CONTEXT* crl{}; |
| 135 | crl = CertEnumCRLsInStore(systemStore, crl); |
| 136 | |
| 137 | while (crl) |
| 138 | { |
| 139 | if (crl->dwCertEncodingType == X509_ASN_ENCODING) |
| 140 | { |
| 141 | // CRL parsing might fail because a CRL makes use of intentionally removed features |
| 142 | // We can just ignore the CRL and move on to the next one |
| 143 | mbedtls_x509_crl_parse(x509crl, crl->pbCrlEncoded, crl->cbCrlEncoded); |
| 144 | } |
no test coverage detected