public static function isLibsodiumSetupCorrectly(bool $echo = false) : bool { // Require libsodium 1.0.9 $major = \Sodium\library_version_major(); $minor = \Sodium\library_version_minor(); if ($major < 9 || $major === 9 && $minor < 2) { if ($echo) { echo 'Halite needs libsodium 1.0.9 or higher. You have: ', \Sodium\version_string(), "\n"; } return false; } // Added in version 1.0.3 of the PHP extension if (!\function_exists('\\Sodium\\crypto_pwhash_str')) { if ($echo) { echo 'Halite needs version 1.0.3 or higher of the PHP extension installed.', "\n"; } return false; } return true; }
/** * @route help */ public function helpPage() { if ($this->isLoggedIn()) { $this->storeLensVar('showmenu', true); // $cabins = $this->getCabinNamespaces(); // Get debug information. $helpInfo = ['cabins' => [], 'cabin_names' => \array_values($cabins), 'gears' => [], 'universal' => []]; /** * This might reveal "sensitive" information. By default, it's * locked out of non-administrator users. You can grant access to * other users/groups via the Permissions menu. */ if ($this->can('read')) { $state = State::instance(); if (\is_readable(ROOT . '/config/gadgets.json')) { $helpInfo['universal']['gadgets'] = \Airship\loadJSON(ROOT . '/config/gadgets.json'); } if (\is_readable(ROOT . '/config/content_security_policy.json')) { $helpInfo['universal']['content_security_policy'] = \Airship\loadJSON(ROOT . '/config/content_security_policy.json'); } foreach ($cabins as $cabin) { $cabinData = ['config' => \Airship\loadJSON(ROOT . '/Cabin/' . $cabin . '/manifest.json'), 'content_security_policy' => [], 'gadgets' => [], 'motifs' => [], 'user_motifs' => \Airship\LensFunctions\user_motif($this->getActiveUserId(), $cabin)]; $prefix = ROOT . '/Cabin/' . $cabin . '/config/'; if (\is_readable($prefix . 'gadgets.json')) { $cabinData['gadgets'] = \Airship\loadJSON($prefix . 'gadgets.json'); } if (\is_readable($prefix . 'motifs.json')) { $cabinData['motifs'] = \Airship\loadJSON($prefix . 'motifs.json'); } if (\is_readable($prefix . 'content_security_policy.json')) { $cabinData['content_security_policy'] = \Airship\loadJSON($prefix . 'content_security_policy.json'); } $helpInfo['cabins'][$cabin] = $cabinData; } $helpInfo['gears'] = []; foreach ($state->gears as $gear => $latestGear) { $helpInfo['gears'][$gear] = \Airship\get_ancestors($latestGear); } // Only grab data likely to be pertinent to common issues: $keys = ['airship', 'auto-update', 'debug', 'guzzle', 'notary', 'rate-limiting', 'session_config', 'tor-only', 'twig_cache']; $helpInfo['universal']['config'] = \Airship\keySlice($state->universal, $keys); $helpInfo['php'] = ['halite' => Halite::VERSION, 'libsodium' => ['major' => \Sodium\library_version_major(), 'minor' => \Sodium\library_version_minor(), 'version' => \Sodium\version_string()], 'version' => \PHP_VERSION, 'versionid' => \PHP_VERSION_ID]; } $this->lens('help', ['active_link' => 'bridge-link-help', 'airship' => \AIRSHIP_VERSION, 'helpInfo' => $helpInfo]); } else { // Not a registered user? Go read the docs. No info leaks for you! \Airship\redirect('https://github.com/paragonie/airship-docs'); } }
$errCol->registerError('files', 'privKey', 'Not all constants are defined.'); } else { if (MSGAPI_PRIVATE_KEY == '' || !KeyCheck(MSGAPI_PRIVATE_KEY, 'private:')) { $errCol->registerError('files', 'privKey', '\'MSGAPI_PRIVATE_KEY\' is invalid.'); } } } //libsodium: private key $errCol->registerGenericMessages('libsodium', 'state', 'Libsodium is loaded.', 'Libsodium is not loaded.'); $errCol->registerGenericMessages('libsodium', 'version', 'You use a recent version of libsodium.', 'You use an old outdated version of libsodium. It is very much recommend to update it.'); if (extension_loaded('libsodium')) { $errCol->registerSuccess('libsodium', 'state'); if (method_exists('Sodium', 'sodium_version_string')) { $errCol->registerWarning('libsodium', 'version', 'Sodium version: ' . Sodium::sodium_version_string()); } else { $errCol->registerSuccess('libsodium', 'version', 'Sodium version: ' . \Sodium\version_string()); } } else { $errCol->registerWarning('libsodium', 'state', 'It is very much recommend to install and load it.'); if (PHP_INT_SIZE < 8) { $errCol->registerError('libsodium', '64bit', 'To use the SDK without libsodium you have to use a 64bit version of PHP.'); } } //evaluate checks and prepare for an output of the results $fileCheckResults = $errCol->evaluateChecks('files'); $libsodiumCheckResults = $errCol->evaluateChecks('libsodium', false); ?> <!DOCTYPE html> <html> <head>
<?php // Libsodium PECL test echo "\nlibsodium major and minor version: "; var_dump([\Sodium\library_version_major(), \Sodium\library_version_minor(), \Sodium\version_string()]); echo "\ncurrent version of the sodium library: "; var_dump([\Sodium\version_string()]); // Libsodium password hashing tests: // https://download.libsodium.org/doc/password_hashing/index.html // https://paragonie.com/book/pecl-libsodium/read/07-password-hashing.md echo "\nCurrent hash keybytes: " . \Sodium\CRYPTO_GENERICHASH_KEYBYTES; echo "\nCurrent salt keybytes: " . \Sodium\CRYPTO_PWHASH_SCRYPTSALSA208SHA256_SALTBYTES; echo "\nOPSLIMIT: " . \Sodium\CRYPTO_PWHASH_SCRYPTSALSA208SHA256_OPSLIMIT_INTERACTIVE; echo "\nMEMLIMIT (bytes): " . \Sodium\CRYPTO_PWHASH_SCRYPTSALSA208SHA256_MEMLIMIT_INTERACTIVE; // Predis. A PHP binding for Redis database. echo "\n";
if (!Halite::isLibsodiumSetupCorrectly()) { // Easiest way to grab this info: \ob_start(); \phpinfo(); $data = \ob_get_clean(); $version = ''; foreach (\explode("\n", $data) as $line) { if (empty($line)) { continue; } if (\strpos($line, 'libsodium compiled version') !== false) { $version = \trim(\substr(\trim($line), -6)); break; } } die("Your libsodium is not setup correctly. Please make sure you have at least:\n\n" . "\tlibsodium v1.0.10 (Installed: " . \Sodium\version_string() . ")\n" . "\tlibsodium-php v1.0.6 (Installed: " . $version . ")\n"); } /** * 3. Process the CLI parameters */ $showAll = true; if ($argc < 2) { // Default behavior: Display the help menu $argv[1] = 'help'; $showAll = false; $argc = 2; } // Create a little cache for the Help command, if applicable. Doesn't contain objects. $commands = []; foreach (\glob(__DIR__ . '/Commands/*.php') as $file) { // Let's build a queue of all the file names
/** * Description of the CryptTool * @return string */ public function getDescription() { /** @noinspection PhpUndefinedNamespaceInspection @noinspection PhpUndefinedFunctionInspection */ return 'Sodium implementation ' . \Sodium\version_string() . ' with PHP binding ' . phpversion('libsodium'); }
<?php /** * @author rugk * @copyright Copyright (c) 2015-2016 rugk * @license MIT */ // check load state if (extension_loaded('libsodium')) { echo 'libsodium is loaded<br/>'; } else { echo 'libsodium is not loaded<br/>'; exit; } // check version if (method_exists('Sodium', 'sodium_version_string')) { echo 'you use an old version of libsodium (<0.2.0)<br/>'; echo 'Sodium version: ' . Sodium::sodium_version_string(); } else { echo 'you use a recent version of libsodium<br/>'; echo 'Sodium version: ' . \Sodium\version_string(); }
function ShowLibsodiumVersion() { if (method_exists('Sodium', 'sodium_version_string')) { echo Sodium::sodium_version_string(); } else { echo \Sodium\version_string(); } }