Add API functions to enable TLS without auth

This is useful if you want to enable TLS for WebSocket without
requiring authentication.
websocket-tls
Andri Yngvason 2023-04-30 16:38:51 +00:00
parent 08f01afee4
commit c8d9dcaa2c
2 changed files with 27 additions and 6 deletions

View File

@ -158,6 +158,10 @@ bool nvnc_has_auth(void);
int nvnc_enable_auth(struct nvnc* self, const char* privkey_path, int nvnc_enable_auth(struct nvnc* self, const char* privkey_path,
const char* cert_path, nvnc_auth_fn, void* userdata); const char* cert_path, nvnc_auth_fn, void* userdata);
bool nvnc_has_tls(void);
int nvnc_load_tls_credentials(struct nvnc* self, const char* privkey_path,
const char* cert_path);
struct nvnc_fb* nvnc_fb_new(uint16_t width, uint16_t height, struct nvnc_fb* nvnc_fb_new(uint16_t width, uint16_t height,
uint32_t fourcc_format, uint16_t stride); uint32_t fourcc_format, uint16_t stride);
struct nvnc_fb* nvnc_fb_from_buffer(void* buffer, uint16_t width, struct nvnc_fb* nvnc_fb_from_buffer(void* buffer, uint16_t width,

View File

@ -1833,7 +1833,7 @@ void nvnc_set_name(struct nvnc* self, const char* name)
} }
EXPORT EXPORT
bool nvnc_has_auth(void) bool nvnc_has_tls(void)
{ {
#ifdef ENABLE_TLS #ifdef ENABLE_TLS
return true; return true;
@ -1843,9 +1843,14 @@ bool nvnc_has_auth(void)
} }
EXPORT EXPORT
int nvnc_enable_auth(struct nvnc* self, const char* privkey_path, bool nvnc_has_auth(void)
const char* cert_path, nvnc_auth_fn auth_fn, {
void* userdata) return nvnc_has_tls();
}
EXPORT
int nvnc_load_tls_credentials(struct nvnc* self, const char* privkey_path,
const char* cert_path)
{ {
#ifdef ENABLE_TLS #ifdef ENABLE_TLS
if (self->tls_creds) if (self->tls_creds)
@ -1876,8 +1881,7 @@ int nvnc_enable_auth(struct nvnc* self, const char* privkey_path,
goto cert_set_failure; goto cert_set_failure;
} }
self->auth_fn = auth_fn; nvnc_log(NVNC_LOG_DEBUG, "Successfully loaded TLS credentials");
self->auth_ud = userdata;
return 0; return 0;
@ -1890,6 +1894,19 @@ cert_alloc_failure:
return -1; return -1;
} }
EXPORT
int nvnc_enable_auth(struct nvnc* self, const char* privkey_path,
const char* cert_path, nvnc_auth_fn auth_fn,
void* userdata)
{
if (nvnc_load_tls_credentials(self, privkey_path, cert_path) < 0)
return -1;
self->auth_fn = auth_fn;
self->auth_ud = userdata;
return 0;
}
EXPORT EXPORT
void nvnc_set_cursor(struct nvnc* self, struct nvnc_fb* fb, uint16_t width, void nvnc_set_cursor(struct nvnc* self, struct nvnc_fb* fb, uint16_t width,
uint16_t height, uint16_t hotspot_x, uint16_t hotspot_y, uint16_t height, uint16_t hotspot_x, uint16_t hotspot_y,