2

I've installed libsodium on Windows for PHP 7 and I'm developing my project with PHPStorm. I've also installed Halite from Paragonie which couldn't even be installable if the libsodium extension were not installed correctly. Also the IDE finds the used functions and when clicking on the variables and so on it opens up the fitting files of libsodium.

But unfortunately in my setup I get the following error:

Uncaught Error: Undefined constant 'Sodium\CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE' in C:\Server\nginx-1.11.1\html\mywebsite\vendor\paragonie\halite\src\KeyFactory.php:344

My index.php file looks like the following:

    <?php
    require_once 'vendor/autoload.php';

    spl_autoload_register(function ($class) {
        require_once $class . '.php';
    });

    $router = new AltoRouter();

    $router->setBasePath('/' . basename(__DIR__));

    require_once 'config/routes.php';

    $match = $router->match();

    $GLOBALS['db'] = new \config\database(true, null);

    try
    {
        if ($match) {
            $routeController = new Modules\Core\RouteController($match);
            echo $routeController->bootstrap();
        }
    }
    catch (Exception $ex)
    {
        //@todo log every Exception
    }

I'm also submitting my form with Jquery which leads successfully to the execution of the following function (which doesn't find the libsodium functions/variables):

public function hash($password)
{
    $this->setEncryptionKey();
    return Password::hash(
        $password, // string
        $this->encryption_key      // \ParagonIE\Halite\Symmetric\EncryptionKey
    );
}

public function check($stored_hash, $password)
{
    try {
        if (Password::verify(
            $password, // string
            $stored_hash,
            $this->encryption_key
        )) {
            return true;
        }
    } catch (\ParagonIE\Halite\Alerts\InvalidMessage $ex) {
        // Handle an invalid message here. This usually means tampered ciphertext.
        throw new \Exception($ex);
    }
}

I've installed the php_libsodium.dll in the extension directory and put the libsodium.dll in in the directory of the php server. Just for trying out i put it later also in system32 directory and in Syswow64 directory - both didn't change anything.

I just installed the halite library from paragonie with composer but using it is unfortunately harder than I thought. I also tried to use the libsodium extension without Halite but that lead to similar errors that the needed classes, constants and functions and so on were not found.

I've also tried to change my autoloader, but the strange thing anyway is that the IDE finds everything without problems but executing the script in the browser just don't.

hardking
  • 193
  • 2
  • 17
  • 1) Did you **enable** the extension in *php.ini* and 2) did you restart your web server? – Mjh Jun 07 '16 at 14:38
  • **yes** to both. I just thought a little bit about it: could it be a version problem, because I've installed version 1.0.6 of libsodium but there also exists version 1.0.10. I didn't compiled it myself but used pre-compiled dll-files for windows. Also I checked it with phpinfo() it says that libsodium support is enabled but library version is only 1.0.5 while compiled version is 1.0.6 – hardking Jun 07 '16 at 15:06

1 Answers1

5

In order to use Halite 2.x, you need to have:

  • Libsodium 1.0.9+ (preferably 1.0.10 if you have trouble compiling .9)
  • PECL Libsodium 1.0.3+ (preferably 1.0.6) compiled against libsodium 1.0.9+.

The easy way to verify that this is set up is:

<?php
use \ParagonIE\Halite\Halite;

var_dump(Halite::isLibsodiumSetupCorrectly());

If you want a little more specific information on what's failing, just run this instead:

<?php
use \ParagonIE\Halite\Halite;

// TRUE enables verbose output:
Halite::isLibsodiumSetupCorrectly(true);

Most likely, you'll need to uninstall/reinstall the PHP extension compiled against a newer version of the shared library.

There's an RFC under discussion for PHP 7.1 right now that will make this painless in the future, if accepted. The RFC passed, years later; libsodium will be in PHP 7.2.

Scott Arciszewski
  • 33,610
  • 16
  • 89
  • 206