Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87274 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5511 invoked from network); 24 Jul 2015 16:36:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Jul 2015 16:36:09 -0000 Authentication-Results: pb1.pair.com smtp.mail=scott@paragonie.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=scott@paragonie.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain paragonie.com from 209.85.220.171 cause and error) X-PHP-List-Original-Sender: scott@paragonie.com X-Host-Fingerprint: 209.85.220.171 mail-qk0-f171.google.com Received: from [209.85.220.171] ([209.85.220.171:32778] helo=mail-qk0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BC/96-57278-67962B55 for ; Fri, 24 Jul 2015 12:36:07 -0400 Received: by qkdl129 with SMTP id l129so17626671qkd.0 for ; Fri, 24 Jul 2015 09:36:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=bHdnBpN4AJRVsuOc8WJgqP9I9pt/Sm7D6BX3RSgyYIk=; b=HRoCQ5Gr269mSRCzU02H1+BN3d7zWM90y3dmcnrY26Z/kA+YOZ5mdaF4ni9wL4C+nm Q4sUaH1g0rMnXbAEWmiScwMgdvcaABQGxoEZy2nKy04x2LAyQFFnwD9HV1Wli+dYstkP qIAjtNfOOyUrjnX/h+JyCz1FbNPXHMRmEHRaxq7MY9i9TJV+b38dnEBQMqZUj6llL9tu RQ3uiyAi7Zrt0eRQ/LOE7j+xYD3g/jKkF0bV8DLtTvq3YE7wa1LX5wakYM0QNjLlxmrp wm8yyctyAfJUKcJ9BEUN+sVPsDrARN9avT7eKlvbefQU8cTGUOG54lA9gyzvKilkboUY c++Q== X-Gm-Message-State: ALoCoQl6EDGK4P4Y4WY+qdxqlhTCgnfJjmy/ZXo1HJMbrW9BoC8dErknlyTHO4+UAbMz8TEYKIdB MIME-Version: 1.0 X-Received: by 10.55.41.84 with SMTP id p81mr21850449qkh.95.1437755763053; Fri, 24 Jul 2015 09:36:03 -0700 (PDT) Received: by 10.96.83.102 with HTTP; Fri, 24 Jul 2015 09:36:02 -0700 (PDT) In-Reply-To: <836BA21C-AE99-4E7B-AB06-EBC30E41BA0E@icicle.io> References: <836BA21C-AE99-4E7B-AB06-EBC30E41BA0E@icicle.io> Date: Fri, 24 Jul 2015 12:36:02 -0400 Message-ID: To: PHP Internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Core functions throwing exceptions in PHP7 From: scott@paragonie.com (Scott Arciszewski) On Thu, Jul 23, 2015 at 1:26 PM, Aaron Piotrowski wrote: > >> On Jul 14, 2015, at 4:04 PM, Sammy Kaye Powers wrote: >> >> Hello lovely PHP nerds, >> >> There are two open PR's for PHP7 to modify the behavior of the CSPRNG's: >> >> https://github.com/php/php-src/pull/1397 (main discussion) >> https://github.com/php/php-src/pull/1398 >> >> 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 ho= le >> in the event the RNG fails and returns false which gets evaluated as 0 i= n a >> cryptographic context. >> >> To prevent this exploit the proposed behavior will throw an Exception wh= en >> the RNG fails or certain argument validation fails. This also gives the >> developer a graceful way to fall back to an alternate CSPRNG. >> >> 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 err= or >> if the RNG fails. >> >> 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. = :) >> >> Thanks, >> Sammy Kaye Powers >> sammyk.me >> >> Chicago, IL 60604 > > How about instead of throwing an instance of Exception, the random_*() fu= nctions 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 t= hese functions to generate a random value could be handled at runtime, thro= wing 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 consisten= cy can be satisfied that other internal functions already can behave simila= rly, and those looking to fail closed can be satisfied that an exception wi= ll be thrown if securely generating a random value fails. > > Aaron Piotrowski I must have overlooked a detail here. According to https://github.com/tpunt/PHP7-Reference#throwable-interface there are Throwables called Error, as a separate designation from an exception. I didn't see this in the engine exceptions RFC, so I was unaware that was even a thing. In this case, yes, as long as you can wrap it in try/catch blocks, SecurityError which extends Error and/or implements Throwable is an excellent suggestion. Previously, I thought the suggestion was to stick to triggering errors (E_ERROR, E_RECOVERABLE_ERROR, etc.). Scott Arciszewski Chief Development Officer Paragon Initiative Enterprises