23#include <freerdp/config.h> 
   25#include <winpr/assert.h> 
   31#include <winpr/crypto.h> 
   33#include <winpr/file.h> 
   34#include <winpr/path.h> 
   36#include <freerdp/settings.h> 
   38#include <freerdp/crypto/crypto.h> 
   39#include <freerdp/crypto/certificate_store.h> 
   40#include <freerdp/log.h> 
   42struct rdp_certificate_store
 
   48static const char certificate_store_dir[] = 
"certs";
 
   49static const char certificate_server_dir[] = 
"server";
 
   51static char* freerdp_certificate_store_file_path(
const rdpCertificateStore* store, 
const char* hash)
 
   53  const char* hosts = freerdp_certificate_store_get_hosts_path(store);
 
   58  return GetCombinedPath(hosts, hash);
 
   61freerdp_certificate_store_result
 
   62freerdp_certificate_store_contains_data(rdpCertificateStore* store, 
const rdpCertificateData* data)
 
   64  freerdp_certificate_store_result rc = CERT_STORE_NOT_FOUND;
 
   65  const char* host = freerdp_certificate_data_get_host(data);
 
   66  const UINT16 port = freerdp_certificate_data_get_port(data);
 
   68  rdpCertificateData* loaded = freerdp_certificate_store_load_data(store, host, port);
 
   72  rc = freerdp_certificate_data_equal(data, loaded) ? CERT_STORE_MATCH : CERT_STORE_MISMATCH;
 
   75  freerdp_certificate_data_free(loaded);
 
   79BOOL freerdp_certificate_store_remove_data(rdpCertificateStore* store,
 
   80                                           const rdpCertificateData* data)
 
   86  const char* hash = freerdp_certificate_data_get_hash(data);
 
   89  char* path = freerdp_certificate_store_file_path(store, hash);
 
   94  if (winpr_PathFileExists(path))
 
   95    rc = winpr_DeleteFile(path);
 
  100BOOL freerdp_certificate_store_save_data(rdpCertificateStore* store, 
const rdpCertificateData* data)
 
  103  const char* base = freerdp_certificate_store_get_hosts_path(store);
 
  104  const char* hash = freerdp_certificate_data_get_hash(data);
 
  105  char* path = freerdp_certificate_store_file_path(store, hash);
 
  108  if (!winpr_PathFileExists(base))
 
  110    if (!winpr_PathMakePath(base, NULL))
 
  114  fp = winpr_fopen(path, 
"w");
 
  118  (void)fprintf(fp, 
"%s", freerdp_certificate_data_get_pem_ex(data, FALSE));
 
  128rdpCertificateData* freerdp_certificate_store_load_data(rdpCertificateStore* store,
 
  129                                                        const char* host, UINT16 port)
 
  132  rdpCertificateData* data = NULL;
 
  136  path = freerdp_certificate_store_get_cert_path(store, host, port);
 
  140  data = freerdp_certificate_data_new_from_file(host, port, path);
 
  147rdpCertificateStore* freerdp_certificate_store_new(
const rdpSettings* settings)
 
  149  rdpCertificateStore* store = (rdpCertificateStore*)calloc(1, 
sizeof(rdpCertificateStore));
 
  158  store->certs_path = GetCombinedPath(base, certificate_store_dir);
 
  159  store->server_path = GetCombinedPath(base, certificate_server_dir);
 
  160  if (!store->certs_path || !store->server_path)
 
  166  WINPR_PRAGMA_DIAG_PUSH
 
  167  WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
 
  168  freerdp_certificate_store_free(store);
 
  169  WINPR_PRAGMA_DIAG_POP
 
  173void freerdp_certificate_store_free(rdpCertificateStore* store)
 
  178  free(store->certs_path);
 
  179  free(store->server_path);
 
  183const char* freerdp_certificate_store_get_certs_path(
const rdpCertificateStore* store)
 
  186  return store->certs_path;
 
  189const char* freerdp_certificate_store_get_hosts_path(
const rdpCertificateStore* store)
 
  192  return store->server_path;
 
  195char* freerdp_certificate_store_get_cert_path(
const rdpCertificateStore* store, 
const char* host,
 
  200  char* hash = freerdp_certificate_data_hash(host, port);
 
  203  char* path = freerdp_certificate_store_file_path(store, hash);
 
FREERDP_API const char * freerdp_settings_get_string(const rdpSettings *settings, FreeRDP_Settings_Keys_String id)
Returns a immutable string settings value.