26#include <winpr/wtypes.h>
27#include <winpr/path.h>
28#include <winpr/tools/makecert.h>
30static const char testCredentialsName[] =
"TestFuzzServerCerts";
33static inline BOOL server_create_certificate(
const char* filepath,
const char* name)
36 char* makecert_argv[6] = {
"makecert",
"-rdp",
"-live",
"-silent",
"-y",
"5" };
38 if (!winpr_PathFileExists(filepath))
40 if (!winpr_PathMakePath(filepath,
nullptr))
44 WINPR_STATIC_ASSERT(ARRAYSIZE(makecert_argv) <= INT_MAX);
45 const size_t makecert_argc = ARRAYSIZE(makecert_argv);
47 char* fcert = GetCombinedPathV(filepath,
"%s.%s", name,
"crt");
48 char* fkey = GetCombinedPathV(filepath,
"%s.%s", name,
"key");
49 const BOOL res = winpr_PathFileExists(fcert) && winpr_PathFileExists(fkey);
55 MAKECERT_CONTEXT* makecert = makecert_context_new();
60 if (makecert_context_process(makecert, (
int)makecert_argc, makecert_argv) < 0)
63 if (makecert_context_set_output_file_name(makecert, name) != 1)
66 WINPR_ASSERT(filepath);
67 if (makecert_context_output_certificate_file(makecert, filepath) != 1)
70 if (makecert_context_output_private_key_file(makecert, filepath) != 1)
75 makecert_context_free(makecert);
79WINPR_ATTR_MALLOC(free, 1)
80static inline
char* getTestCredentialsFilePath(
void)
82 char* path = GetKnownSubPath(KNOWN_PATH_TEMP, testCredentialsName);
85 if (!server_create_certificate(path, testCredentialsName))
93WINPR_ATTR_MALLOC(free, 1)
94static inline
char* getTestCredentialsFileNameFor(const
char* ext)
99 char* path = getTestCredentialsFilePath();
103 char* name = GetCombinedPathV(path,
"%s.%s", testCredentialsName, ext);