From patchwork Fri May 10 17:30:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163910 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2670266ilr; Fri, 10 May 2019 10:35:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqy+Y2bHVfMQSHg4MVFxHO45QHxikYoTtvvRRkjb7QTMALO0bMVbC7G4a6QF7PsQuxYE7cft X-Received: by 2002:a50:a3a2:: with SMTP id s31mr12478767edb.254.1557509700228; Fri, 10 May 2019 10:35:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557509700; cv=none; d=google.com; s=arc-20160816; b=VHggPFLUuQvZjuRrHcdHPxVD9mIL/i/C5ZN7V3za/yeYAZHc90dFvACKwM/HgYc61o /4ozDUweg6PpEo1/jQNwoGFcrCeSzQ4Unaeqp695QP7/R9kCTRIL3sS2e1Fmpj/RDqqb t8LUc93rGvYKFH6aQjiy7/fuOeLwaD3s3SujaNEY3fsXTZ94bXQAqv4GD7NdDxZoXLK2 n3PepwaMWZwlThQPdkXJCEddBRCRixzqVwcmnYPVgfVXCBFQtpm+GQmqEw5JWopgPYNT +YbO9q7pw+wLyQZmnI+gM/Xmz7yTrbFbuqEz2cXjo3Zfv/6tQIhsvuSlmXMlc08SJst/ Om0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=/ZYAcflQLE8QxLnv1PzgjeCpnaQ2OAMJAHbK0JDJ8Y8=; b=I5rf4UZO5M7jzIf5OuYrD0+OIAqPeyA8/gMGGOaGTrKvKy/3C+gXR0dpRMiny5/wd4 Kl2kYLKY0COUgK8VPhdIAkrymf+BNGwZtwEvuwzh+jluppkH2nukN2ugXy9vUxLCmCxY B/p4ulKxEyyksL4Ynf7UIRHcn2lWpR5kQ+bldFUjs3j12z1TLss0lsxVIi7yMGefxUYR VpKQeHqAlna7pnM68ZEvSfdxxXgRbuty6gtYqToOuiaEXu2r6KTb3Co85/IfEyseEP1A 2fVdfxZnKtNEXC4v/09clUJXZur3JsuZaIn3RnAueWbVkodWHDIhOGanCf0xaoyELM6s ah7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=comklrI7; 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 z19si3641513ejp.198.2019.05.10.10.35.00 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:35:00 -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=comklrI7; 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]:47512 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9QB-0002Be-43 for patch@linaro.org; Fri, 10 May 2019 13:34:59 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59063) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9MO-0007OC-T7 for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9MN-000644-V1 for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:04 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:38802) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9MN-00063b-OR for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:03 -0400 Received: by mail-pf1-x444.google.com with SMTP id 10so3578722pfo.5 for ; Fri, 10 May 2019 10:31:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=/ZYAcflQLE8QxLnv1PzgjeCpnaQ2OAMJAHbK0JDJ8Y8=; b=comklrI7vJRFkDR9OWFu6hwuKVFU1zNt6vn/glu/slrjyzVypYPxPtSUORzW9gLIjW mGmGbPusUItMMbzgTQ1Ki5BgWQatG5y5+NxnZ1NtwgD6VMdLDhm2GN7qyoUa7sOxchnL ydwFyWN3HHpOKZP3mVO4/+BbAsELB6j580cGVQdhzipVPUsRjycy6qof1ezw9p6TpNiJ 0fVohOg38OnEhJdMhrqvMlvWOXW9JqLUga0M6mzDZqGh0IycE3lC9rPLFJHuJjAo23Wu u1Q/hMhIi7fAJqKtr2sgHiOhVYph+d7kOdVqidz80CcK9lslw+XxMHprd+XrJMCgNQdX Is/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/ZYAcflQLE8QxLnv1PzgjeCpnaQ2OAMJAHbK0JDJ8Y8=; b=lDLXbCvlRvBCM0vPp37lL5zqv2oKc63cGlQG/Rl3nSvzQBzx1WSegWg3GqCz11CEbj 42L8MlkjqRIcNUm0tMLgHbGbzcalUkil+4r/0p9+tUyxhoFTwmRKIMqYHfZwVfCOU3z9 FtFkWcKP6bt5oByoqqFf9IxMjW0Mj5zf1wC4UMhEjgmZ442iVOHniOnUs6guydy0PoRc 8Z/KLqJ4jX5e+upesZYTSQWEF4THFyX5LfWTjVHjV+dhy1jX3Mkpd5wsAoYX+Yg0IYQg aAo+a5grCUbHdsQANGjICUWkddW7eszFVX2OZG8ZbK/HT8B1klCNA+TkwGbBgC1dxKhw s66Q== X-Gm-Message-State: APjAAAVcN/24vV/lApcXj6CZ4WiTentXeNDE9h49GzEyczhpwGhpaIl4 CCJHMA3tnH0Brn0mUyyvnDHpg8L67jU= X-Received: by 2002:a63:7989:: with SMTP id u131mr6596432pgc.180.1557509462453; Fri, 10 May 2019 10:31:02 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.31.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:31:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:33 -0700 Message-Id: <20190510173049.28171-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-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::444 Subject: [Qemu-devel] [PATCH v6 09/25] 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: , 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 --- v2: Use qcrypto_random_bytes, not qemu_getrandom, as there is no need for deterministic results for this interface. v3: Fail gracefully in the event qcrypto_random_bytes fails. --- 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);