render / rpms / qemu

Forked from rpms/qemu 10 months ago
Clone
Glauber Costa 47b075
Index: qemu-kvm-0.10/qemu/vnc-tls.c
Glauber Costa 47b075
===================================================================
Glauber Costa 47b075
--- qemu-kvm-0.10.orig/qemu/vnc-tls.c
Glauber Costa 47b075
+++ qemu-kvm-0.10/qemu/vnc-tls.c
Glauber Costa 47b075
@@ -241,6 +241,22 @@ int vnc_tls_validate_certificate(struct 
Glauber Costa 47b075
 	    return -1;
Glauber Costa 47b075
 	}
Glauber Costa 47b075
 
Glauber Costa 47b075
+	if (i == 0) {
Glauber Costa 47b075
+	    size_t dnameSize = 1024;
Glauber Costa 47b075
+	    vs->tls.dname = qemu_malloc(dnameSize);
Glauber Costa 47b075
+	requery:
Glauber Costa 47b075
+	    if ((ret = gnutls_x509_crt_get_dn (cert, vs->tls.dname, &dnameSize)) != 0) {
Glauber Costa 47b075
+		if (ret == GNUTLS_E_SHORT_MEMORY_BUFFER) {
Glauber Costa 47b075
+		    vs->tls.dname = qemu_realloc(vs->tls.dname, dnameSize);
Glauber Costa 47b075
+		    goto requery;
Glauber Costa 47b075
+		}
Glauber Costa 47b075
+		gnutls_x509_crt_deinit (cert);
Glauber Costa 47b075
+		VNC_DEBUG("Cannot get client distinguished name: %s",
Glauber Costa 47b075
+			  gnutls_strerror (ret));
Glauber Costa 47b075
+		return -1;
Glauber Costa 47b075
+	    }
Glauber Costa 47b075
+	}
Glauber Costa 47b075
+
Glauber Costa 47b075
 	gnutls_x509_crt_deinit (cert);
Glauber Costa 47b075
     }
Glauber Costa 47b075
 
Glauber Costa 47b075
@@ -347,6 +363,7 @@ void vnc_tls_client_cleanup(struct VncSt
Glauber Costa 47b075
 	vs->tls.session = NULL;
Glauber Costa 47b075
     }
Glauber Costa 47b075
     vs->tls.wiremode = VNC_WIREMODE_CLEAR;
Glauber Costa 47b075
+    free(vs->tls.dname);
Glauber Costa 47b075
 }
Glauber Costa 47b075
 
Glauber Costa 47b075
 
Glauber Costa 47b075
Index: qemu-kvm-0.10/qemu/vnc-tls.h
Glauber Costa 47b075
===================================================================
Glauber Costa 47b075
--- qemu-kvm-0.10.orig/qemu/vnc-tls.h
Glauber Costa 47b075
+++ qemu-kvm-0.10/qemu/vnc-tls.h
Glauber Costa 47b075
@@ -55,6 +55,9 @@ struct VncStateTLS {
Glauber Costa 47b075
     /* Whether data is being TLS encrypted yet */
Glauber Costa 47b075
     int wiremode;
Glauber Costa 47b075
     gnutls_session_t session;
Glauber Costa 47b075
+
Glauber Costa 47b075
+    /* Client's Distinguished Name from the x509 cert */
Glauber Costa 47b075
+    char *dname;
Glauber Costa 47b075
 };
Glauber Costa 47b075
 
Glauber Costa 47b075
 int vnc_tls_client_setup(VncState *vs, int x509Creds);
Glauber Costa 47b075
Index: qemu-kvm-0.10/qemu/vnc.c
Glauber Costa 47b075
===================================================================
Glauber Costa 47b075
--- qemu-kvm-0.10.orig/qemu/vnc.c
Glauber Costa 47b075
+++ qemu-kvm-0.10/qemu/vnc.c
Glauber Costa 47b075
@@ -156,6 +156,21 @@ static void do_info_vnc_client(VncState 
Glauber Costa 47b075
     term_puts("Client:\n");
Glauber Costa 47b075
     term_puts(clientAddr);
Glauber Costa 47b075
     free(clientAddr);
Glauber Costa 47b075
+
Glauber Costa 47b075
+#ifdef CONFIG_VNC_TLS
Glauber Costa 47b075
+    if (client->tls.session &&
Glauber Costa 47b075
+	client->tls.dname)
Glauber Costa 47b075
+	term_printf("  x509 dname: %s\n", client->tls.dname);
Glauber Costa 47b075
+    else
Glauber Costa 47b075
+	term_puts("  x509 dname: none\n");
Glauber Costa 47b075
+#endif
Glauber Costa 47b075
+#ifdef CONFIG_VNC_SASL
Glauber Costa 47b075
+    if (client->sasl.conn &&
Glauber Costa 47b075
+	client->sasl.username)
Glauber Costa 47b075
+	term_printf("    username: %s\n", client->sasl.username);
Glauber Costa 47b075
+    else
Glauber Costa 47b075
+	term_puts("    username: none\n");
Glauber Costa 47b075
+#endif
Glauber Costa 47b075
 }
Glauber Costa 47b075
 
Glauber Costa 47b075
 void do_info_vnc(void)
Glauber Costa 47b075
@@ -1823,7 +1838,7 @@ static int protocol_client_auth(VncState
Glauber Costa 47b075
     /* We only advertise 1 auth scheme at a time, so client
Glauber Costa 47b075
      * must pick the one we sent. Verify this */
Glauber Costa 47b075
     if (data[0] != vs->vd->auth) { /* Reject auth */
Glauber Costa 47b075
-       VNC_DEBUG("Reject auth %d\n", (int)data[0]);
Glauber Costa 47b075
+       VNC_DEBUG("Reject auth %d because it didn't match advertized\n", (int)data[0]);
Glauber Costa 47b075
        vnc_write_u32(vs, 1);
Glauber Costa 47b075
        if (vs->minor >= 8) {
Glauber Costa 47b075
            static const char err[] = "Authentication failed";
Glauber Costa 47b075
@@ -1863,7 +1878,7 @@ static int protocol_client_auth(VncState
Glauber Costa 47b075
 #endif /* CONFIG_VNC_SASL */
Glauber Costa 47b075
 
Glauber Costa 47b075
        default: /* Should not be possible, but just in case */
Glauber Costa 47b075
-           VNC_DEBUG("Reject auth %d\n", vs->vd->auth);
Glauber Costa 47b075
+           VNC_DEBUG("Reject auth %d server code bug\n", vs->vd->auth);
Glauber Costa 47b075
            vnc_write_u8(vs, 1);
Glauber Costa 47b075
            if (vs->minor >= 8) {
Glauber Costa 47b075
                static const char err[] = "Authentication failed";