[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 09/25] ui/vnc: Use gcrypto_random_bytes for start_aut
From: |
Richard Henderson |
Subject: |
[Qemu-devel] [PULL 09/25] ui/vnc: Use gcrypto_random_bytes for start_auth_vnc |
Date: |
Wed, 22 May 2019 14:42:10 -0400 |
Use a better interface for random numbers than rand().
Fail gracefully if for some reason we cannot use the crypto system.
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
Reviewed-by: Gerd Hoffmann <address@hidden>
Reviewed-by: Daniel P. Berrangé <address@hidden>
Signed-off-by: Richard Henderson <address@hidden>
---
ui/vnc.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/ui/vnc.c b/ui/vnc.c
index 785edf3af1..d83f4a6ff9 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -43,6 +43,7 @@
#include "crypto/hash.h"
#include "crypto/tlscredsanon.h"
#include "crypto/tlscredsx509.h"
+#include "crypto/random.h"
#include "qom/object_interfaces.h"
#include "qemu/cutils.h"
#include "io/dns-resolver.h"
@@ -2547,16 +2548,6 @@ static void authentication_failed(VncState *vs)
vnc_client_error(vs);
}
-static void make_challenge(VncState *vs)
-{
- int i;
-
- srand(time(NULL)+getpid()+getpid()*987654+rand());
-
- for (i = 0 ; i < sizeof(vs->challenge) ; i++)
- vs->challenge[i] = (int) (256.0*rand()/(RAND_MAX+1.0));
-}
-
static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len)
{
unsigned char response[VNC_AUTH_CHALLENGE_SIZE];
@@ -2628,7 +2619,16 @@ reject:
void start_auth_vnc(VncState *vs)
{
- make_challenge(vs);
+ Error *err = NULL;
+
+ if (qcrypto_random_bytes(vs->challenge, sizeof(vs->challenge), &err)) {
+ trace_vnc_auth_fail(vs, vs->auth, "cannot get random bytes",
+ error_get_pretty(err));
+ error_free(err);
+ authentication_failed(vs);
+ return;
+ }
+
/* Send client a 'random' challenge */
vnc_write(vs, vs->challenge, sizeof(vs->challenge));
vnc_flush(vs);
--
2.17.1
- [Qemu-devel] [PULL 00/25] Add qemu_getrandom and ARMv8.5-RNG etc, Richard Henderson, 2019/05/22
- [Qemu-devel] [PULL 19/25] hw/misc/bcm2835_rng: Use qemu_guest_getrandom_nofail, Richard Henderson, 2019/05/22
- [Qemu-devel] [PULL 09/25] ui/vnc: Use gcrypto_random_bytes for start_auth_vnc,
Richard Henderson <=
- [Qemu-devel] [PULL 03/25] crypto: Reverse code blocks in random-platform.c, Richard Henderson, 2019/05/22
- [Qemu-devel] [PULL 25/25] target/i386: Implement CPUID_EXT_RDRAND, Richard Henderson, 2019/05/22
- [Qemu-devel] [PULL 23/25] target/ppc: Use gen_io_start/end around DARN, Richard Henderson, 2019/05/22
- [Qemu-devel] [PULL 17/25] aspeed/scu: Use qemu_guest_getrandom_nofail, Richard Henderson, 2019/05/22
- [Qemu-devel] [PULL 11/25] cpus: Initialize pseudo-random seeds for all guest cpus, Richard Henderson, 2019/05/22
- [Qemu-devel] [PULL 22/25] target/arm: Implement ARMv8.5-RNG, Richard Henderson, 2019/05/22
- [Qemu-devel] [PULL 15/25] linux-user/aarch64: Use qemu_guest_getrandom for PAUTH keys, Richard Henderson, 2019/05/22
- [Qemu-devel] [PULL 16/25] linux-user: Remove srand call, Richard Henderson, 2019/05/22
- [Qemu-devel] [PULL 05/25] crypto: Use O_CLOEXEC in qcrypto_random_init, Richard Henderson, 2019/05/22
- [Qemu-devel] [PULL 06/25] crypto: Use getrandom for qcrypto_random_bytes, Richard Henderson, 2019/05/22