1*4882a593SmuzhiyunFrom fa768720e76360248ac125ecab2efe515d573eb3 Mon Sep 17 00:00:00 2001 2*4882a593SmuzhiyunFrom: Philipp Zabel <p.zabel@pengutronix.de> 3*4882a593SmuzhiyunDate: Thu, 6 Oct 2022 12:18:04 +0200 4*4882a593SmuzhiyunSubject: [PATCH 88/93] backend-vnc: enable TLS support 5*4882a593Smuzhiyun 6*4882a593SmuzhiyunAdd TLS key and certificate parameters to enable encryption support. 7*4882a593Smuzhiyun 8*4882a593SmuzhiyunSigned-off-by: Philipp Zabel <p.zabel@pengutronix.de> 9*4882a593Smuzhiyun(cherry picked from commit 1a027e63cb4dda7a7483034e89314bd8b064ed1b) 10*4882a593SmuzhiyunSigned-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> 11*4882a593Smuzhiyun--- 12*4882a593Smuzhiyun compositor/main.c | 6 ++++++ 13*4882a593Smuzhiyun include/libweston/backend-vnc.h | 2 ++ 14*4882a593Smuzhiyun libweston/backend-vnc/vnc.c | 24 ++++++++++++++++++++++++ 15*4882a593Smuzhiyun man/weston-vnc.man | 33 ++++++++++++++++++++++++++++++--- 16*4882a593Smuzhiyun 4 files changed, 62 insertions(+), 3 deletions(-) 17*4882a593Smuzhiyun 18*4882a593Smuzhiyundiff --git a/compositor/main.c b/compositor/main.c 19*4882a593Smuzhiyunindex e30f27e..ed5c818 100644 20*4882a593Smuzhiyun--- a/compositor/main.c 21*4882a593Smuzhiyun+++ b/compositor/main.c 22*4882a593Smuzhiyun@@ -730,6 +730,8 @@ usage(int error_code) 23*4882a593Smuzhiyun " --width=WIDTH\t\tWidth of desktop\n" 24*4882a593Smuzhiyun " --height=HEIGHT\tHeight of desktop\n" 25*4882a593Smuzhiyun " --port=PORT\t\tThe port to listen on\n" 26*4882a593Smuzhiyun+ " --vnc-tls-cert=FILE\tThe file containing the certificate for TLS encryption\n" 27*4882a593Smuzhiyun+ " --vnc-tls-key=FILE\tThe file containing the private key for TLS encryption\n" 28*4882a593Smuzhiyun "\n"); 29*4882a593Smuzhiyun #endif 30*4882a593Smuzhiyun 31*4882a593Smuzhiyun@@ -3253,6 +3255,8 @@ load_vnc_backend(struct weston_compositor *c, 32*4882a593Smuzhiyun { WESTON_OPTION_INTEGER, "height", 0, &parsed_options->height }, 33*4882a593Smuzhiyun { WESTON_OPTION_STRING, "address", 0, &config.bind_address }, 34*4882a593Smuzhiyun { WESTON_OPTION_INTEGER, "port", 0, &config.port }, 35*4882a593Smuzhiyun+ { WESTON_OPTION_STRING, "vnc-tls-cert", 0, &config.server_cert }, 36*4882a593Smuzhiyun+ { WESTON_OPTION_STRING, "vnc-tls-key", 0, &config.server_key }, 37*4882a593Smuzhiyun }; 38*4882a593Smuzhiyun 39*4882a593Smuzhiyun parse_options(vnc_options, ARRAY_LENGTH(vnc_options), argc, argv); 40*4882a593Smuzhiyun@@ -3267,6 +3271,8 @@ load_vnc_backend(struct weston_compositor *c, 41*4882a593Smuzhiyun &config.base); 42*4882a593Smuzhiyun 43*4882a593Smuzhiyun free(config.bind_address); 44*4882a593Smuzhiyun+ free(config.server_cert); 45*4882a593Smuzhiyun+ free(config.server_key); 46*4882a593Smuzhiyun 47*4882a593Smuzhiyun return ret; 48*4882a593Smuzhiyun } 49*4882a593Smuzhiyundiff --git a/include/libweston/backend-vnc.h b/include/libweston/backend-vnc.h 50*4882a593Smuzhiyunindex 0085df5..3495c0e 100644 51*4882a593Smuzhiyun--- a/include/libweston/backend-vnc.h 52*4882a593Smuzhiyun+++ b/include/libweston/backend-vnc.h 53*4882a593Smuzhiyun@@ -62,6 +62,8 @@ struct weston_vnc_backend_config { 54*4882a593Smuzhiyun char *bind_address; 55*4882a593Smuzhiyun int port; 56*4882a593Smuzhiyun int refresh_rate; 57*4882a593Smuzhiyun+ char *server_cert; 58*4882a593Smuzhiyun+ char *server_key; 59*4882a593Smuzhiyun }; 60*4882a593Smuzhiyun 61*4882a593Smuzhiyun #ifdef __cplusplus 62*4882a593Smuzhiyundiff --git a/libweston/backend-vnc/vnc.c b/libweston/backend-vnc/vnc.c 63*4882a593Smuzhiyunindex 190fe92..e57e377 100644 64*4882a593Smuzhiyun--- a/libweston/backend-vnc/vnc.c 65*4882a593Smuzhiyun+++ b/libweston/backend-vnc/vnc.c 66*4882a593Smuzhiyun@@ -997,6 +997,30 @@ vnc_backend_create(struct weston_compositor *compositor, 67*4882a593Smuzhiyun nvnc_set_userdata(backend->server, backend, NULL); 68*4882a593Smuzhiyun nvnc_set_name(backend->server, "Weston VNC backend"); 69*4882a593Smuzhiyun 70*4882a593Smuzhiyun+ if (config->server_cert || config->server_key) { 71*4882a593Smuzhiyun+ if (!nvnc_has_auth()) { 72*4882a593Smuzhiyun+ weston_log("Neat VNC built without TLS support\n"); 73*4882a593Smuzhiyun+ goto err_output; 74*4882a593Smuzhiyun+ } 75*4882a593Smuzhiyun+ if (!config->server_cert) { 76*4882a593Smuzhiyun+ weston_log("Missing TLS certificate (--vnc-tls-cert)\n"); 77*4882a593Smuzhiyun+ goto err_output; 78*4882a593Smuzhiyun+ } 79*4882a593Smuzhiyun+ if (!config->server_key) { 80*4882a593Smuzhiyun+ weston_log("Missing TLS key (--vnc-tls-key)\n"); 81*4882a593Smuzhiyun+ goto err_output; 82*4882a593Smuzhiyun+ } 83*4882a593Smuzhiyun+ 84*4882a593Smuzhiyun+ ret = nvnc_enable_auth(backend->server, config->server_key, 85*4882a593Smuzhiyun+ config->server_cert, NULL, NULL); 86*4882a593Smuzhiyun+ if (ret) { 87*4882a593Smuzhiyun+ weston_log("Failed to enable TLS support\n"); 88*4882a593Smuzhiyun+ goto err_output; 89*4882a593Smuzhiyun+ } 90*4882a593Smuzhiyun+ 91*4882a593Smuzhiyun+ weston_log("TLS support activated\n"); 92*4882a593Smuzhiyun+ } 93*4882a593Smuzhiyun+ 94*4882a593Smuzhiyun ret = weston_plugin_api_register(compositor, WESTON_VNC_OUTPUT_API_NAME, 95*4882a593Smuzhiyun &api, sizeof(api)); 96*4882a593Smuzhiyun if (ret < 0) { 97*4882a593Smuzhiyundiff --git a/man/weston-vnc.man b/man/weston-vnc.man 98*4882a593Smuzhiyunindex 6491097..582fe28 100644 99*4882a593Smuzhiyun--- a/man/weston-vnc.man 100*4882a593Smuzhiyun+++ b/man/weston-vnc.man 101*4882a593Smuzhiyun@@ -19,9 +19,8 @@ the graphical content, depending on what is supported by the VNC client. 102*4882a593Smuzhiyun The VNC backend is not multi-seat aware, so if a second client connects to the 103*4882a593Smuzhiyun backend, the first client will be disconnected. 104*4882a593Smuzhiyun 105*4882a593Smuzhiyun-Note that authentication and encryption are not supported yet. Anyone with 106*4882a593Smuzhiyun-access to the port can get control of the desktop via the VNC output, and 107*4882a593Smuzhiyun-all data is transferred in plaintext. 108*4882a593Smuzhiyun+Note that authentication is not supported yet. Anyone with access to the port 109*4882a593Smuzhiyun+can get control of the desktop via the VNC output. 110*4882a593Smuzhiyun 111*4882a593Smuzhiyun .\" *************************************************************** 112*4882a593Smuzhiyun .SH CONFIGURATION 113*4882a593Smuzhiyun@@ -50,7 +49,35 @@ The height of the framebuffer. It defaults to 480. 114*4882a593Smuzhiyun .TP 115*4882a593Smuzhiyun \fB\-\-port\fR=\fIport\fR 116*4882a593Smuzhiyun The TCP port to listen on for connections. It defaults to 5900. 117*4882a593Smuzhiyun+.TP 118*4882a593Smuzhiyun+\fB\-\-vnc\-tls\-key\fR=\fIfile\fR 119*4882a593Smuzhiyun+The file containing the key for doing TLS security. To have TLS security you also need 120*4882a593Smuzhiyun+to ship a file containing a certificate. 121*4882a593Smuzhiyun+.TP 122*4882a593Smuzhiyun+\fB\-\-vnc\-tls\-cert\fR=\fIfile\fR 123*4882a593Smuzhiyun+The file containing the certificate for doing TLS security. To have TLS security you also need 124*4882a593Smuzhiyun+to ship a key file. 125*4882a593Smuzhiyun+ 126*4882a593Smuzhiyun+ 127*4882a593Smuzhiyun+.\" *************************************************************** 128*4882a593Smuzhiyun+.SH Generating cryptographic material for the VNC backend 129*4882a593Smuzhiyun+. 130*4882a593Smuzhiyun+You can generate a key and certificate file to use with TLS security using typical 131*4882a593Smuzhiyun+.B openssl 132*4882a593Smuzhiyun+invocations: 133*4882a593Smuzhiyun 134*4882a593Smuzhiyun+.nf 135*4882a593Smuzhiyun+$ openssl genrsa -out tls.key 2048 136*4882a593Smuzhiyun+Generating RSA private key, 2048 bit long modulus 137*4882a593Smuzhiyun+[...] 138*4882a593Smuzhiyun+$ openssl req -new -key tls.key -out tls.csr 139*4882a593Smuzhiyun+[...] 140*4882a593Smuzhiyun+$ openssl x509 -req -days 365 -signkey tls.key -in tls.csr -out tls.crt 141*4882a593Smuzhiyun+[...] 142*4882a593Smuzhiyun+.fi 143*4882a593Smuzhiyun+ 144*4882a593Smuzhiyun+You will get the tls.key and tls.crt files to use with the VNC backend. 145*4882a593Smuzhiyun+. 146*4882a593Smuzhiyun .\" *************************************************************** 147*4882a593Smuzhiyun .SH "SEE ALSO" 148*4882a593Smuzhiyun .BR weston (1) 149*4882a593Smuzhiyun-- 150*4882a593Smuzhiyun2.20.1 151*4882a593Smuzhiyun 152