Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87250 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5308 invoked from network); 23 Jul 2015 17:26:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Jul 2015 17:26:43 -0000 Authentication-Results: pb1.pair.com smtp.mail=aaron@icicle.io; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=aaron@icicle.io; sender-id=pass Received-SPF: pass (pb1.pair.com: domain icicle.io designates 199.38.81.6 as permitted sender) X-PHP-List-Original-Sender: aaron@icicle.io X-Host-Fingerprint: 199.38.81.6 mercury.negativeion.net Received: from [199.38.81.6] ([199.38.81.6:59339] helo=mercury.negativeion.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4B/A0-00531-2D321B55 for ; Thu, 23 Jul 2015 13:26:42 -0400 Received: from localhost (localhost [127.0.0.1]) by mercury.negativeion.net (Postfix) with ESMTP id CB87C2898AB0; Thu, 23 Jul 2015 13:26:39 -0400 (EDT) X-Virus-Scanned: amavisd-new at negativeion.net Received: from mercury.negativeion.net ([127.0.0.1]) by localhost (mercury.negativeion.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WfNKttoDvWKQ; Thu, 23 Jul 2015 13:26:39 -0400 (EDT) Received: from macpro.local (unknown [173.225.158.77]) by mercury.negativeion.net (Postfix) with ESMTPSA id B11A72898AA2; Thu, 23 Jul 2015 13:26:38 -0400 (EDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\)) In-Reply-To: Date: Thu, 23 Jul 2015 12:26:31 -0500 Cc: scott@paragonie.com, Yasuo Ohgaki , rowan.collins@gmail.com, pierre.php@gmail.com, brian@moonspot.net, PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: <836BA21C-AE99-4E7B-AB06-EBC30E41BA0E@icicle.io> References: To: Sammy Kaye Powers X-Mailer: Apple Mail (2.2098) Subject: Re: [PHP-DEV] Core functions throwing exceptions in PHP7 From: aaron@icicle.io (Aaron Piotrowski) > On Jul 14, 2015, at 4:04 PM, Sammy Kaye Powers wrote: >=20 > Hello lovely PHP nerds, >=20 > There are two open PR's for PHP7 to modify the behavior of the = CSPRNG's: >=20 > https://github.com/php/php-src/pull/1397 (main discussion) > https://github.com/php/php-src/pull/1398 >=20 > Currently the random_*() functions will issue a warning and return = false if > a good source of random cannot be found. This is a potential security = hole > in the event the RNG fails and returns false which gets evaluated as 0 = in a > cryptographic context. >=20 > To prevent this exploit the proposed behavior will throw an Exception = when > the RNG fails or certain argument validation fails. This also gives = the > developer a graceful way to fall back to an alternate CSPRNG. >=20 > Since the core functions in PHP don't throw Exceptions, there is = debate on > whether or not this change should be implemented. Some say the = CSPRNG's > should get a special pass since they will be relied on for = cryptography. If > we can't throw Exceptions, there were suggestions of raising a fatal = error > if the RNG fails. >=20 > I think the argument can be boiled down to consistency vs security. = We'd > love to hear your feedback to decide what we should do in this = context. :) >=20 > Thanks, > Sammy Kaye Powers > sammyk.me >=20 > Chicago, IL 60604 How about instead of throwing an instance of Exception, the random_*() = functions throw an instance of Error on failure. A subclass of Error, = such as SecurityError could also be added. As it is unlikely that the = failure of these functions to generate a random value could be handled = at runtime, throwing an instance of Error makes the most sense imho. Many internal functions can result in an instance of Error being thrown, = particularly with declare(strict_types=3D1). So those looking for = consistency can be satisfied that other internal functions already can = behave similarly, and those looking to fail closed can be satisfied that = an exception will be thrown if securely generating a random value fails. Aaron Piotrowski=