diff --git a/include/neatvnc.h b/include/neatvnc.h index 9e68085..de202a5 100644 --- a/include/neatvnc.h +++ b/include/neatvnc.h @@ -158,6 +158,10 @@ bool nvnc_has_auth(void); int nvnc_enable_auth(struct nvnc* self, const char* privkey_path, 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, uint32_t fourcc_format, uint16_t stride); struct nvnc_fb* nvnc_fb_from_buffer(void* buffer, uint16_t width, diff --git a/src/server.c b/src/server.c index 9e569ad..69c11e9 100644 --- a/src/server.c +++ b/src/server.c @@ -1833,7 +1833,7 @@ void nvnc_set_name(struct nvnc* self, const char* name) } EXPORT -bool nvnc_has_auth(void) +bool nvnc_has_tls(void) { #ifdef ENABLE_TLS return true; @@ -1843,9 +1843,14 @@ bool nvnc_has_auth(void) } EXPORT -int nvnc_enable_auth(struct nvnc* self, const char* privkey_path, - const char* cert_path, nvnc_auth_fn auth_fn, - void* userdata) +bool nvnc_has_auth(void) +{ + return nvnc_has_tls(); +} + +EXPORT +int nvnc_load_tls_credentials(struct nvnc* self, const char* privkey_path, + const char* cert_path) { #ifdef ENABLE_TLS if (self->tls_creds) @@ -1876,8 +1881,7 @@ int nvnc_enable_auth(struct nvnc* self, const char* privkey_path, goto cert_set_failure; } - self->auth_fn = auth_fn; - self->auth_ud = userdata; + nvnc_log(NVNC_LOG_DEBUG, "Successfully loaded TLS credentials"); return 0; @@ -1890,6 +1894,19 @@ cert_alloc_failure: 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 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,