summaryrefslogtreecommitdiffstats
path: root/libfreerdp/crypto/certificate_data.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:25:12 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:25:12 +0000
commit827a4c3faa27e0c186452585b15094eee1119085 (patch)
treee6a08b0c767863d66f7d4a9de80db5edc7db29be /libfreerdp/crypto/certificate_data.c
parentReleasing progress-linux version 3.3.0+dfsg1-1~progress7.99u1. (diff)
downloadfreerdp3-827a4c3faa27e0c186452585b15094eee1119085.tar.xz
freerdp3-827a4c3faa27e0c186452585b15094eee1119085.zip
Merging upstream version 3.5.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libfreerdp/crypto/certificate_data.c')
-rw-r--r--libfreerdp/crypto/certificate_data.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/libfreerdp/crypto/certificate_data.c b/libfreerdp/crypto/certificate_data.c
index a48beb4..04b5432 100644
--- a/libfreerdp/crypto/certificate_data.c
+++ b/libfreerdp/crypto/certificate_data.c
@@ -50,11 +50,21 @@ struct rdp_certificate_data
char* cached_pem;
};
+/* ensure our hostnames (and therefore filenames) always use the same capitalization.
+ * the user might have input random case, but we always need to have a sane
+ * baseline to compare against. */
+static char* ensure_lowercase(char* str, size_t length)
+{
+ const size_t len = strnlen(str, length);
+ for (size_t x = 0; x < len; x++)
+ str[x] = tolower(str[x]);
+ return str;
+}
static const char* freerdp_certificate_data_hash_(const char* hostname, UINT16 port, char* name,
size_t length)
{
_snprintf(name, length, "%s_%" PRIu16 ".pem", hostname, port);
- return name;
+ return ensure_lowercase(name, length);
}
static BOOL freerdp_certificate_data_load_cache(rdpCertificateData* data)
@@ -107,8 +117,7 @@ static rdpCertificateData* freerdp_certificate_data_new_nocopy(const char* hostn
certdata->hostname = _strdup(hostname);
if (!certdata->hostname)
goto fail;
- for (size_t i = 0; i < strlen(hostname); i++)
- certdata->hostname[i] = tolower(certdata->hostname[i]);
+ ensure_lowercase(certdata->hostname, strlen(certdata->hostname));
certdata->cert = xcert;
if (!freerdp_certificate_data_load_cache(certdata))
@@ -176,43 +185,44 @@ void freerdp_certificate_data_free(rdpCertificateData* data)
const char* freerdp_certificate_data_get_host(const rdpCertificateData* cert)
{
- WINPR_ASSERT(cert);
+ if (!cert)
+ return NULL;
return cert->hostname;
}
UINT16 freerdp_certificate_data_get_port(const rdpCertificateData* cert)
{
- WINPR_ASSERT(cert);
+ if (!cert)
+ return 0;
return cert->port;
}
const char* freerdp_certificate_data_get_pem(const rdpCertificateData* cert)
{
- WINPR_ASSERT(cert);
- WINPR_ASSERT(cert->cached_pem);
-
+ if (!cert)
+ return NULL;
return cert->cached_pem;
}
const char* freerdp_certificate_data_get_subject(const rdpCertificateData* cert)
{
- WINPR_ASSERT(cert);
- WINPR_ASSERT(cert->cached_subject);
+ if (!cert)
+ return NULL;
return cert->cached_subject;
}
const char* freerdp_certificate_data_get_issuer(const rdpCertificateData* cert)
{
- WINPR_ASSERT(cert);
- WINPR_ASSERT(cert->cached_issuer);
+ if (!cert)
+ return NULL;
return cert->cached_issuer;
}
const char* freerdp_certificate_data_get_fingerprint(const rdpCertificateData* cert)
{
- WINPR_ASSERT(cert);
- WINPR_ASSERT(cert->cached_fingerprint);
+ if (!cert)
+ return NULL;
return cert->cached_fingerprint;
}
@@ -241,8 +251,8 @@ BOOL freerdp_certificate_data_equal(const rdpCertificateData* a, const rdpCertif
const char* freerdp_certificate_data_get_hash(const rdpCertificateData* cert)
{
- WINPR_ASSERT(cert);
- WINPR_ASSERT(cert->cached_hash);
+ if (!cert)
+ return NULL;
return cert->cached_hash;
}