From patchwork Wed May 22 18:42:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164866 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1234319ili; Wed, 22 May 2019 12:08:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqy1l6w8QHm9JGVn0BSyN0x0Vls0Kkx+LSRnZ8ti+m1PUbk13Yjgg/OvYJGbxPwy4BVKIxGY X-Received: by 2002:a17:906:b250:: with SMTP id ce16mr59385065ejb.99.1558552125020; Wed, 22 May 2019 12:08:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558552125; cv=none; d=google.com; s=arc-20160816; b=cYcOSwoy4B4pu1xLnhPjkQa6BaKSyI3AqtC38xNmf1XINkm2f+n1mkjLvgpS26MCR5 I8dRA/kaYKAL+bxrpPMgTvSIuOVPtqgkRM7TNN+OsK+fN3xbeB7JOlUfJCQIQhtV310m GJqOBeFCuThLyQZ6I8Li1pOpeYowT9Awbh3HoqDUBj/mo4Q1CO5rFQNaTa54/AiiRoU9 AVk1BdfYn4IE9JjCrFXUAYSbOPoCzlhKTuTWErDVkGcVYqjajtJMgErJSQKTX9XtHAGq 0vRlgwAgUJ5ZPf2RMKJ8lUtCil2y/7///YMzxIt31vCD0U/xXsQgFYPhqfRucIK5bk1p 2bSg== 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=XZ8RTKXIiwIclbBvMCB3TQrTZ041TneUAFznp3KKWGzwl/CABawREil6f1u2W67idr ELzJl4WLQXAbV6wCA/IhJitKoHjVMyXS9A3NumbonWi7BLKfaL9je+X2R6HD/nXEJ5u5 TJXkzcB3G5Gj0BgcsjR4vE7cBztXDgle0+8O/iIfv8OwqxAyBy1ZEZCHcpLhliEZ3Y9F iuua5YRHBFFpm17H9mZ8t+xG//5qGN8QmqQ4epLEDhSxiEofiif+ugGHsBzcWky0DRcX wYNCYClQJI8NmVBRhYodE9K6HQiGeyVxJdx1BCyReiq7dmLs9Rt9IYW/jyYJwB1WfrLR kxSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=mPRksRww; 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 r28si12717551eda.140.2019.05.22.12.08.44 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:08:45 -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=mPRksRww; 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]:49810 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWbT-00044t-Tc for patch@linaro.org; Wed, 22 May 2019 15:08:43 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOp-0008P8-TZ for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCG-00085H-1R for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:41 -0400 Received: from mail-yb1-xb42.google.com ([2607:f8b0:4864:20::b42]:43335) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCE-00084Z-Rk for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:39 -0400 Received: by mail-yb1-xb42.google.com with SMTP id n145so1243674ybg.10 for ; Wed, 22 May 2019 11:42:38 -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=mPRksRwwbN/3/077MRePyAeJDUS6P0OM8kpNYghC9BDh8iqyPbzDpUz7JyfVjKF2r5 PzO+ThcVIwNj4vkL+MISSptc13xDpdNrnH2Kk5xY7t6PsX1/Tdq+NzArtxpU+ZREwmOO avkBpZoy2WjVvfrc3sBnqDBrq/IYeXnX/7CF+VUbqx/v99zpLgoi7q6mQkeNa4FwvJe3 H/oV4yTJVwuPrWIAH9HMV4cqfTVDyVuVQ87KG9GpLqSLiS3Xl0VUmd4ppqayRC/mZbmE seTaha8kwb6oqvh0s753pOFFXw3cBz5Yu3n9gQe0VtrCyVokCIPawT8yycTe+COfw1Bo NzoQ== 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=Po3FnGmjc5GL919yeILDl2C1RbBHnA7KU8hpxDvsNhwuCpqWBmGde1jyI9r5lU/bCg FHEMW+WQI+t9UsgcwIl8bV1RUwDznNXjyPdRFujCP2txM/uwDeZS11W+n1gIxCZen2Hn 71Dm0ecSi1fVelz1GUKqsEnfYCWZIn364cb3RQ/DA94TrkVwZNzkOgf8SxbY7HbHBcOP qvSYlBhbOxvn8UUO9+1gsMuR2pMl9KI/SkyN1ES80L+cMNY1Po0hDqQ9Gix67np62Uld UJL7KoCn1aoDSx7W3JtX+J33V5W52g9O9Nz4eppZZ++zBJeG0bT3FalmHc3FetquOgJh W41g== X-Gm-Message-State: APjAAAVWLJ4KhKY+ih1P066gnANICVEQiW19SlGf3jahUeTJCW98c/Mz AWyQJ2UpOFi+KIu674enXKnkeAjXcwU= X-Received: by 2002:a25:b18e:: with SMTP id h14mr8631012ybj.18.1558550557978; Wed, 22 May 2019 11:42:37 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:10 -0400 Message-Id: <20190522184226.17871-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::b42 Subject: [Qemu-devel] [PULL 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: , Cc: peter.maydell@linaro.org 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);