From patchwork Tue May 14 19:16:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164231 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3003250ili; Tue, 14 May 2019 12:20:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqz532E32EndTaU6fvGqaWs58cqG5iDSwTICmSrLPXbRJkgFhlsdla+v7S5SG6ZAqsx5AbdD X-Received: by 2002:a50:86c9:: with SMTP id 9mr37898228edu.216.1557861635801; Tue, 14 May 2019 12:20:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557861635; cv=none; d=google.com; s=arc-20160816; b=wrJ7v6z1qiJjaV6GrGYmmk/npmzsjmcXBi2sIE3xnshmJfsBeytc3RSWVUiGBZTk3s P7HFCI/9Mzb7APEK2R9ZeZEzgv2mMZFAITFJINy9gMGIiJzgO+2cANpq5Ygx9TahRt0k MxaPddn/jKgl9PdktYOjJweUrafBS/iDGDM05cZFGnydqfx5tbOT1Q9D29g5bbCZ69O7 NOK0rSmzlxpsZ4h6TJeQnOK6+Qn9O4wDQWPDB5JCPXlcIJ1UhTXQ7fya6ATjQ7UWFyqq uWkDNar4ya99ED1RSbuhF8YECKKFg3nqSHKPjuqcbq4JdVa0Vm55HedZmQ+3PZrFTcCv pfdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=DHS+azgDjOz9872pwx2wjM+spw3T8bEncaHuHvbQJSc=; b=p11Np1nho9DaPOJQjV225e9BIfF9eu8Z8JO55oOZy0zbxdK/2xHmRKEXEc4arZ2dWk oW5v2sV+Kk+FwcN0uGwCh0jwV1u/yPxVZpFLbh+/r+mMhZjioUptjD66Ul+i1AkzdEts HgPUzLnkQXx5/rIehXhgUPDDSyFHZKmqrDAlAO6ME0ICN7Qzp29NvCZd1FacS2A1M/iP 9Pxo+0CiDI1AIXuj1h9xvplf0Xa1SoZSm+TwBGZsWxCp2vmc9hSjYxDN0TPm1KIhgSud HflSl3eWtDef/JerqrTsElgHnUgnkFiCAGOeod6LOBmx9XVBweA1f80wESCEPMKPJ6ee jdyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Vw6Ht19C; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bp18si9801281ejb.23.2019.05.14.12.20.35 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:20:35 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Vw6Ht19C; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:52966 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcyY-0004vm-OG for patch@linaro.org; Tue, 14 May 2019 15:20:34 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48807) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvE-0002Tq-L9 for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvD-0006oQ-M5 for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:08 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:45593) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcvD-0006nl-Gn for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:07 -0400 Received: by mail-pf1-x441.google.com with SMTP id s11so9612709pfm.12 for ; Tue, 14 May 2019 12:17:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DHS+azgDjOz9872pwx2wjM+spw3T8bEncaHuHvbQJSc=; b=Vw6Ht19Cc2d0O99O4y9E/m6n5DH1o3Gac4gmuvKoHF6mzIIIqJX0fcbmXRNwQSku5V nw3E/OYtCeUDzGZQGlauJfh3ObBRa5XThIIkw7XVaCifv6N6CLNJKu6Mp+h2goGyNinl lZMEeFM8jSPfw8c8iIyG3lXULeRpIi87TMKS2oGeJfjjPslGhwlRygEM14LuD1kY9PN7 9jp0fdmo0SX7RFvapzFktNuGurDrTowL15YtjQYGg2i8R/LVPycYvHlw9AC0guZf1co/ COc6R+1D8W6c9ksEa/i2VOsoUqO1VmFalq2O4PBP4oHdqEpGlpT2IYsbRh/O3KK7H/nS 1lWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DHS+azgDjOz9872pwx2wjM+spw3T8bEncaHuHvbQJSc=; b=uHcjQidl/Hh4sHhbFiYqnjeCGjtf6NVnQAKbDerakY4ULqDPS8QGqpc/fX60ORlo6S yL7IVU6UjL6te7PVIjiDPEI1NoNoSRrExRf6eyy+cb0n1V//djbNXeu+6qyWlUXHwnzG eMyC/+HMsuXp64Df7KODnJzkHL3I3j9kkTYLleTa4zBgetgS+jteoJPyJd1iksqe9Xes ZZJ4xiRGl8qZKy6PQ//K9z3noK9PpO1ElRMOHn4KeTeX58zSGUqnwHMd/7wpGfCacclO Mew8cG4Ta4vrIRJQDYjBzXYGo+GDsJeZBuFxAGj8l7fXMMkvxZMueUJig7004YLnrfZ5 r+aw== X-Gm-Message-State: APjAAAWh/UZ7tRdAdv4uQfGoabGfnDamCqvZpmYW0aWqxljZAn+6PC6v zS/uf8VdiInbYPfvgY/5bxAvi+5o8q8= X-Received: by 2002:a63:690:: with SMTP id 138mr39216636pgg.415.1557861426286; Tue, 14 May 2019 12:17:06 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id o6sm18682982pfa.88.2019.05.14.12.17.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:37 -0700 Message-Id: <20190514191653.31488-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::441 Subject: [Qemu-devel] [PATCH v7 08/24] ui/vnc: Use gcrypto_random_bytes for start_auth_vnc X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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é Reviewed-by: Gerd Hoffmann Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- ui/vnc.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) -- 2.17.1 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);