Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
PHP Programming Software

PHP Becomes First Programming Language To Add 'Modern' Cryptography Library In Its Core (bleepingcomputer.com) 204

An anonymous reader writes from a report via BleepingComputer: The PHP team has unanimously voted to integrate the Libsodium library in the PHP core, and by doing so, becoming the first programming language to support a modern cryptography library by default. Developers approved a proposal with a vote of 37 to 0 and decided that Libsodium will be added to the upcoming PHP 7.2 release that will be launched towards the end of 2017. Scott Arciszewski, the cryptography expert who made the proposal, says that by supporting modern crypto in the PHP core, the PHP team will force the WordPress team to implement better security in its CMS, something they avoided until now. Additionally, it will allow PHP and CMS developers to add advanced cryptography features to their apps that run on shared hosting providers, where until now they weren't able to install custom PHP extensions to support modern cryptography. Other reasons on why he made the proposal are detailed here. Arciszewski also says that PHP is actually "the first" programming language to support a "modern" cryptography library in its core, despite Erlang and Go including similar libraries, which he claims are not as powerful and up-to-date as PHP's upcoming Libsodium implementation.
This discussion has been archived. No new comments can be posted.

PHP Becomes First Programming Language To Add 'Modern' Cryptography Library In Its Core

Comments Filter:
  • Oh please (Score:5, Insightful)

    by Anonymous Coward on Tuesday February 21, 2017 @05:07PM (#53907929)

    Any language where the default equality comparison operator is *true* given two string-type variables with values "0E54321" and "0E12345" is not a cryptographically secure language. In fact there is a nonzero chance of the default equality operator returning true between two different MD5 or SHA256 hashes if they happen to fall into a hexadecimal form that is all digits except for one E or F.

    Anyone who claims that PHP is somehow more secure as a language because it has added *new optional library calls* without doing anything about the fundamental language defects is demented.

    • Re:Oh please (Score:5, Informative)

      by Vairon ( 17314 ) on Tuesday February 21, 2017 @05:43PM (#53908121)

      PHP has a comparison operator === that evaluates if the two things it is comparing are equal and of the same type.

      $ php -r "if (\"0E54321\" === \"0E12345\") { echo 'equal'; } else { echo 'not equal'; } "
      not equal

      Without ===, variable type conversion can cause a string containing numbers to be converted to an integer. See these links for details:

      http://php.net/manual/en/langu... [php.net]
      http://php.net/manual/en/langu... [php.net]

      • Re:Oh please (Score:5, Interesting)

        by Lisandro ( 799651 ) on Tuesday February 21, 2017 @05:54PM (#53908185)

        Except for objects, where a === b is true only if a and b are the same object. Such a beautifully designed language.

        • by deKernel ( 65640 )

          Please tell me you are kidding me on this? I haven't touched PHP so this is all new to me...if it is true.

          • Oh, how i wish i was: https://developers.slashdot.or... [slashdot.org]

        • Except for objects, where a === b is true only if a and b are the same object

          In Java, a == b is true if a and b references are identical, which is probably what does PHP under the hood.

      • Is there also a "less than and of the same type" operator? Or is calling strcmp() the best practice for this?

      • if ("0E54321" === "0E12345") { echo 'equal'; } else { echo 'not equal'; }

        Too bad your example is useless (like 80% of PHP's doc examples anyway), since if ("0E54321" == "0E12345") (only 2 '=') yields also 'not equal'. A more relevant example is if ("123" === 123) (yields false but '==' yields true).

        • Re: Oh please (Score:5, Informative)

          by Edgewize ( 262271 ) on Tuesday February 21, 2017 @07:45PM (#53908629)

          Or more relevantly, I think this is what the original poster was referring to:
          https://www.whitehatsec.com/bl... [whitehatsec.com]

          Here are some examples of PHP doing mind boggling things with md5 and sha1 hashes.

          https://3v4l.org/tT4l8 [3v4l.org]

        • by Vairon ( 17314 )

          You are wrong. In my example, using ==, it will report equal. Using ===, it will report not equal.

          $ php -r "if (\"0E54321\" === \"0E12345\") { echo \"equal\n\"; } else { echo \"not equal\n\"; } "
          not equal
          $ php -r "if (\"0E54321\" == \"0E12345\") { echo \"equal\n\"; } else { echo \"not equal\n\"; } "
          equal

          The string "0E54321" and "0E12345" both get converted into the integer 0 for comparison purposes when you only use ==.

          The documentation clearly explains this behavior. I'll link it again for you.
          Type Jugglin [php.net]

      • Without ===, variable type conversion can cause a string containing numbers to be converted to an integer.

        Yep, and as much as I like php, I'll be the first to say that php's "converting a string to an integer" as a default behavior is idiotic. It's just an accident waiting to happen.

        • by gweihir ( 88907 )

          It is a sign of very junior and inexperienced language designers with very big egos. And no concept of personal responsibility.

          Writing good code is hard enough with good tools.

      • by fahrbot-bot ( 874524 ) on Tuesday February 21, 2017 @07:43PM (#53908625)

        PHP has a comparison operator === that evaluates if the two things it is comparing are equal and of the same type.

        The next version will support "====" for things are really, *really* equal.

        • by sconeu ( 64226 )

          It was needed for Animal Farm Simulation support, because some objects are more equal than others.

    • Re:Oh please (Score:5, Interesting)

      by Dogtanian ( 588974 ) on Tuesday February 21, 2017 @06:05PM (#53908249) Homepage

      Any language where the default equality comparison operator is *true* given two string-type variables with values "0E54321" and "0E12345" is not a cryptographically secure language. In fact there is a nonzero chance of the default equality operator returning true between two different MD5 or SHA256 hashes if they happen to fall into a hexadecimal form that is all digits except for one E or F.

      Technically, that (in itself) doesn't necessarily mean that the built-in cryptography nor the language itself are inherently insecure. In theory, that is, provided you understand the language and use it correctly.

      And that's the problem. Because in practice, PHP's design philosophy of trying to be clever- often too clever by half- when it comes to comparisons, equality, automatic coercion, data types, etc. etc. too often gives unpredictable and unexpected results from people who weren't aware of that behaviour.

      You absolutely do *not* want any risk of this happening when you're designing a system that has to be secure. You want boringly explicit and utterly predictable data and type handling.

      My prediction is that far, *far* more security holes will be down to bugs caused by unforeseen subtle aspects- i.e. pitfalls- of PHP's type handling and equality behaviour (etc.) in the apps using it rather than bugs in the cryptographic module itself.

      PHP being a language more favoured by inexperienced users, this is likely to be made far worse. Expect lots of newbies with misplaced confidence designing what they think are "secure" apps that are in fact full of holes- either because they've misused or misunderstood the cryptographic module, or because they've overlooked some basic aspect of computer security elsewhere (e.g. failure to parse input securely) that makes the use of cryptography irrelevant.

      And those are the sorts of mistakes newbies would make when using any language- with PHP's language design issues on top of that, it has the potential to be far worse.

      So, yeah. I trust that the module will be secure. The main problems- I guarantee- will be caused by caused by overlooked (or not known about) aspects of PHP's too-clever-by-half data handling (in client apps using it) leading to exploitable holes, and by the fact that too many of PHP's newbie-skewing userbase will overconfidently assume it makes their apps foolproof while using it incorrectly and ignoring security holes elsewhere that make it redundant.

      • Agreed. The problem is not the library - PHP is intrinsically insecure. I'm not aware of any other language out there that can reliably be made to segfault [php.net] and whose developers argue such behavior is working as intended.

        • by Ksevio ( 865461 )
          I can get a segfault pretty reliably in C with this code:
          char *s = "hello world"; *s = 'H';
          • I think you meant s = 'H'; there....

            But again, this is to be expected. C is a low level language without memory management; PHP is neither. There is no sane reason why it is supposed to segfault (according to the developers, "infinite recursion crashes") and i'm not aware of any other high level language which does the same. How hard is to add a recursion counter?

            • I think you meant s = 'H'; there....

              No, he is correct that *s = 'H' can segfault. You aren't allowed to modify string literals, only char arrays.

              • Oh, it can. It just won't do it reliably. Setting a string pointer to 0x72 will certainly do.

                • Oh, it can. It just won't do it reliably. Setting a string pointer to 0x72 will certainly do.

                  It can. It might not though. It depends, actually, on whether it is ever deferenced or not. The original *s = 'H' can crash without ever needing any more derefencing. Your correction can (not 'will', but 'can') crash only if it is dereferenced.

                  Setting it is not enough, you have to dereference it as well. Although now that I think about it, depending on the platform, simply dereferencing it may still not be enough.

                  For example, I just tried it now, verbatim, in the OS kernel I hobby-developed and it worked ju

            • by djinn6 ( 1868030 )
              If s = 'H' actually compiled, it would be very bad, because s is a pointer, and 'H', being a char, can be converted to an int value of 72. What this code would do is to set the pointer s to a memory address of 72.

              What's can you find at byte #72 in memory? Who knows! But it's probably not the character "H".
          • by gweihir ( 88907 )

            C is not an interpreted language with memory safety.Your example does not apply and it is completely clueless in addition.

          • But that depends on many things like operating system and Compiler, and I would not wonder if you forgot a 'const' to force the crash ;D

          • $ gcc -Wwrite-strings -Werror a.c
            a.c: In function ‘main’:
            a.c:3:12: error: initialization discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
                char *s = "hello world";
                                    ^~~~~~~~~~~~~
            cc1: all warnings being treated as errors

        • To repeat: quit blaming the language for the lack of skills of the programmer.

          Programmers who are incompetent in PHP should not attempt to build secure systems with it. Those who do attempt to do so should really not be involved in making secure systems in any language, since they have demonstrated that they do not know how to assess the limitations of their tools, let alone work properly within those limitations.

          It is a poor craftsman who blames his tools for his shoddy workmanship.

          • Re:Oh please (Score:5, Insightful)

            by gweihir ( 88907 ) on Wednesday February 22, 2017 @02:19AM (#53909969)

            It is a poor craftsman that uses shoddy tools in the first place. Selecting good tools is a core skill for any craftsman. Those that do not have it will never amount to anything.

            • It is a poor craftsman who blames his tools for his shoddy workmanship.

              It is a poor craftsman that uses shoddy tools in the first place. Selecting good tools is a core skill for any craftsman.

              Same thing.

              The take-away: If you don't know how to use PHP to build secure systems, use some other tool. If you don't know how to use any other tool, don't try to do secure systems.

              In every case, the fault is with the programmer, not PHP.

              • by gweihir ( 88907 )

                Actually, quite a bit of fault is with PHP, as novices may just not know any better without really being at fault. Poor tools play a role in creating poor craftsmen. It can also not be disputed by anybody sane that the makers of PHP are exceptionally poor craftsmen.

        • by gweihir ( 88907 )

          And there we have the core problem: Clueless language designers with big egos. A segfault is like scramming a reactor. It is an absolute least resort, it may do significant damage, it is always a sign of something having gone terribly wrong and it should never, ever happen in normal operation.

    • by Anonymous Coward

      Came for the PHP haters, was not disappointed.

    • In my opinion, dynamic languages should require, or at least encourage, one to specify what comparison type to use rather than rely on parameter (operand) analysis. The hard part is coming up with a nice syntax for such. I've had various discussion groups consider different suggestions, and found no consensus.

      In the shorter term, one can roll their own functions and hope staff coders follow along. Example:

      if (strCompare(a, '>', b)) {...}
      if (numCompare(a, '<=', b)) {...}

    • Call me an idiot, but if programming something that needs to be secure in PHP, you simply don't rely on the default equality comparator. It's there for simpler noncritical issues where it's behaviour is expected. So yeah, working around the "fundamental language defects" is something unfortunately most (all?) programmers need to do regardless of language. Adding better tools can only help.
  • SubjectsSuck (Score:5, Informative)

    by aardvarkjoe ( 156801 ) on Tuesday February 21, 2017 @05:09PM (#53907935)

    Arciszewski also says that PHP is actually "the first" programming language to support a "modern" cryptography library in its core, despite Erlang and Go including similar libraries, which he claims are not as powerful and up-to-date as PHP's upcoming Libsodium implementation.

    So it's the first to support a modern cryptography library, as long as you define "modern" to mean "the one that we're using."

    It's easy to be first to do something if you place enough arbitrary restrictions on what that something is.

    • Re:SubjectsSuck (Score:4, Insightful)

      by NotInHere ( 3654617 ) on Tuesday February 21, 2017 @05:13PM (#53907953)

      "Modern" is for CS people like "Alternative facts" is for politicians.

    • Re:SubjectsSuck (Score:4, Interesting)

      by MightyMartian ( 840721 ) on Tuesday February 21, 2017 @05:18PM (#53907979) Journal

      I don't even understand the point of the claim. So the interpreter has a baked-in crypto library? And how is that different than simply #including a crypto library, which has the added bonus that you can pick any number of crypto libraries.

      • And how is that different than simply #including a crypto library, which has the added bonus that you can pick any number of crypto libraries.

        I can see three ways to proceed:

        A built-in crypto library
        This runs at full speed and is available by default to the shared hosting customer.
        An add-on crypto library compiled to native code and distributed as a PHP extension
        This runs at full speed but requires the shared hosting customer to convince the hosting provider to install it.
        An add-on crypto library written in pure PHP
        This is available by default to the shared hosting customer but can run unacceptably slowly due to interpreter overhead.
      • Re: (Score:2, Insightful)

        by Anonymous Coward

        Libsodium is an extended fork of Daniel J. Bernstein's [wikipedia.org] original NaCl [cr.yp.to] project (not to be confused with Google Native Client), which is a cryptography library developed with the overarching aim of simplifying (and improving the implementation-level safety of) the practical use of strong cryptographic constructs. The "big idea" behind NaCl was to abstract away many of the low-level choices and technical details associated with various cryptographic primitives in favor of more "generic" interfaces, utilizing im

      • It's different in that if a vulnerability is discovered in the underlaying library an new release of PHP is required to fix it. Note you will need to convince the hosting provider/infrastructure team to test and deploy the latest release. This is the reason the cryptography library for Python (and requests) don't want to be made part of the core so they can be agile and respond quickly to security problems.

      • Well, it certainly makes things easier for us hobby programmers that make redistributable projects designed to run on shared servers. I can't count on people installing a framework or keeping a library up to date if they have no admin access to the server. A lot of PHP projects, like Wordpress, still aren't aimed at serious, large-scale enterprises. Don't assume the owners have shell access with enough permission to install dependencies.

        I started working with PHP over a decade ago because it had a graphi

      • I don't even understand the point of the claim. So the interpreter has a baked-in crypto library? And how is that different than simply #including a crypto library, which has the added bonus that you can pick any number of crypto libraries.

        More to the point - this is the main problem with PHP. The idiots who "design" it think that something like this should be compiled into their interpreter and made into even more built-in function calls. The better way to handle it is exactly as you describe - allow people to add their own code and make your language robust enough to allow them to code the crypto library (or whatever) in your language.

        Historically, PHP was terrible at handling binary data and such, so there was no way to do a lot of these

    • It's easy to be first to do something if you place enough arbitrary restrictions on what that something is.

      Hey, you're the first user in this thread whose user id starts with 15680 to say THAT.

    • Tomorrow there may be a new security library and the first language that uses it will be the "first" language to use a "modern" security library.

      Pity the person who's been campaigning to include SSL into a language only to be told "we're deferring this because it's no longer modern enough so we will continue providing no security library."

    • More ridiculous is the claim that including crypto will force WordPress to implement better security. WordPress can just ignore this; and getting hacked by shitty REST API authentication verification isn't fixed by pouring on more crypto sauce.

      This guy is a crypto nerd who thinks crypto solves all problems. It doesn't. He probably has databases with columns (UserID, UserName, CryptedPassword, AESKey) so the password is AES-encrypted with an individual key per-user.

  • by OverlordQ ( 264228 ) on Tuesday February 21, 2017 @05:14PM (#53907955) Journal

    I'll stick to every other language that has had libsodium bindings for a while now.

  • by Anonymous Coward

    ... let's get proper multibyte support.

  • For those who don't know, libsodium is a C library [github.com] that PHP will be utilizing. It is not a PHP library.
    • by Anonymous Coward

      That's actually a good point. PHP is a bit unlike most other "interpreted" languages in that there are two kinds of libraries. There are the mods, written in native C, and included in the PHP+Apache runtime environment. That reflects PHP's basic structure as more-or-less a fancy wrapper around a bunch of C libraries. Then there are libraries written in PHP, such as the stuff in the PEAR libraries.

      AFAIK (but I'm ignorant on this topic), Java, Javascript/node.js, etc. don't have a way to include C libraries i

  • by __aaclcg7560 ( 824291 ) on Tuesday February 21, 2017 @05:20PM (#53908001)
    I got tired of script kiddies banging down my PHP/MySQL servers. I'm using Pelican (Python) to convert my websites into static websites. With nothing to hack, script kiddies go away.
    • by tepples ( 727027 )

      I'm using Pelican (Python) to convert my websites into static websites. With nothing to hack, script kiddies go away.

      How do you edit your Pelican-powered website while away from your home PC? Skiddies can hack through that.

      • How do you edit your Pelican-powered website while away from your home PC? Skiddies can hack through that.

        I don't allow outside access to my file server at home. From my file server I can make whatever changes needed to the website, run pelican to generate the static files, and rsync the output directory to the hosting server. Since I don't use PHP or MySQL, the script kiddies have no attack vector into my website.

        • by tepples ( 727027 )

          I don't allow outside access to my file server at home. From my file server I can make whatever changes needed to the website

          If you get an idea for an update while away from home, particularly for an extended period, what do you do with that idea?

          • If you get an idea for an update while away from home, particularly for an extended period, what do you do with that idea?

            I write it down in my dead tree notebook.

          • I don't allow outside access to my file server at home. From my file server I can make whatever changes needed to the website

            If you get an idea for an update while away from home, particularly for an extended period, what do you do with that idea?

            Sorry but this is a silly thread. Security is an inconvenience and you have to live with it. That said your problem is not solvable:

            1) write it down.
            2) email it to myself.
            3) ssh.
            4) outright VPN.

            Me I take the last option. There's no dynamic content accessible on my site which isn't behind at the least HTTP auth. There's no dynamic content on my website which takes user input that doesn't also limit it's scope to the local network.

            And despite all of these restrictions, content is still easier to update than i

  • PHP, the "Speak 'n Spell" of programming languages.... More marketing fluff.

  • by allo ( 1728082 ) on Tuesday February 21, 2017 @05:24PM (#53908017)

    BULLSHIT! BULLSHIT! BULLSHIT!

    PHP is one of the programming languages, which load all stuff into the core (which can be quite a disadvantage), but other languages use a library by a single include. So what?
    And even php has it into a .so file, which can be loaded, but isn't required to be used. So the "core" is relative as well. Actually its a bundled module.

  • .... a kitchen sink into the core, they could have instead done a *sane* way to include additional modules.

    Perl and Python for example have no problem loading user-specific or script-specific modules, not like the "system wide or nothing" approach of PHP. ( which of course doesn't work with shared hosting. )

  • by MobyDisk ( 75490 ) on Tuesday February 21, 2017 @05:32PM (#53908063) Homepage

    I remember when Java was the first language to do this. Shortly after that, C# was the first language to do this. Now PHP is the first language to do this. So who will be the next one to do it first?

    • by Agripa ( 139780 )

      I remember when Java was the first language to do this. Shortly after that, C# was the first language to do this. Now PHP is the first language to do this. So who will be the next one to do it first?

      It is not first until Apple does it.

  • I'm torn on the idea of having one particular crypto implementation having first class citizen status in the language. It should help adoption and alleviate deployment headaches, but if that library turns out to have problems or just becomes obsolete it's even more of a hassle to work around it. Crypto algorithms are unusual in computer science in that they come with use-by dates. Most algorithms are timeless, but crypto changes constantly. What are the odds that in 5 years this becomes "that thing you
    • by gweihir ( 88907 )

      This is PHP. The language is saturated with bad decisions. This is just one more of those.

  • by Qbertino ( 265505 ) <moiraNO@SPAMmodparlor.com> on Tuesday February 21, 2017 @06:04PM (#53908235)

    I'm smiling while I read this.

    Every single bit of this news is sooo PHP and one of the reasons this awkward mess of a PL is so successful. [slashdot.org]

    They find something new or something they need and bolt it on. Just like that. End of story. A vote on the core team, a little coding and *BAM* PHP has a new inner API function with what has to be the most over-the-top all-out-PHP-style name for an inner API function ever - sodium_crypto_box_keypair_from_secretkey_and_publickey($ecdh_secret, $ecdh_public); (seriously, this is no joke).

    Totally LOL. Takes the cake for inner function names ten times over, even by PHP standards, which is quite a stunt. And right away PHP has up-to-date hard crypto that even a simpleton can use.

    You have to hand it to the PHP crew - they actually get shit done, no matter what. :-)

    • You have to hand it to the PHP crew - they actually get shit done, no matter what. :-)

      They should make that their motto: "Getting shit done, no matter what!"

  • by MostAwesomeDude ( 980382 ) on Tuesday February 21, 2017 @06:04PM (#53908237) Homepage

    My beloved Monte https://monte.rtfd.org/ [rtfd.org] beat PHP to this by a wide stretch. While it's true that PHP is a big established language, that doesn't mean that they get to claim sudden leaps in innovation which didn't happen. I've tweeted at the author of the blog post https://twitter.com/corbinsimpson/status/834175224736157696 [twitter.com] with timestamped commits from the Monte codebase.

  • by Lisandro ( 799651 ) on Tuesday February 21, 2017 @06:06PM (#53908251)

    ...which effectively prevents me from updating it. Great choice for a security library guys.

    • by Anonymous Coward

      Most software is (or should be) subject to maintenance updates for various reasons. Embedding libsodium in an application simply shifts the distribution point for updates. If you're using software (PHP in this case) distributed as a package in a common Linux or BSD distribution, you'll have the ability to install updates/fixes whenever the distribution's package maintainers make them available from new or patched upstream sources. If you're compiling from source, you'll have the option of tracking updates a

      • Sorry, that is not enough. There's a vast difference from updating a crypto library (which can happen, f.ex, due to security updates) to updating the whole damn language, which can have system-wide implications.

  • "...man, you guys must have some serious technical debt"

    I built a startup's entire stack on PHP back in the 2003-2006 time, now I look back and SMH at the foolishness. If you want a quick'n'weakly-typed language (which I often do), Python beats the crap out of PHP, as well as being ten times more readable.

  • by thogard ( 43403 ) on Tuesday February 21, 2017 @07:34PM (#53908595) Homepage

    The cryptography algorithms are the easy part. The vary hard part is protecting keys so I hope someone provides plenty of examples of how to do that properly. I hope they don't go down the Java route of showing how to use the functions without proper key management.

  • Sneak preview of the API:

    crypto_really_encode(plaintext, algorithm); // Simplest
    crypto_really_encode(plaintext, mode, algorithm); // Next arg goes in the middle
    crypto_really_encode(block_size, plaintext, algorithm, mode); // Switch it up yo lol

    ...where AES will somehow be a valid value for both mode and algorithm (which will silently override to "NULL" if plaintext starts with a zero or the letter "p").

    • Lots of gold in this thread, but this one should be a 5. The PHP API design decisions are the shittiest I've ever seen in my life.

Every nonzero finite dimensional inner product space has an orthonormal basis. It makes sense, when you don't think about it.

Working...