Skip to content

Instantly share code, notes, and snippets.

@mttjohnson
Created September 3, 2020 22:24
Show Gist options
  • Save mttjohnson/5f42a19cbd4cfcc0dbbdd835a39f6eef to your computer and use it in GitHub Desktop.
Save mttjohnson/5f42a19cbd4cfcc0dbbdd835a39f6eef to your computer and use it in GitHub Desktop.
Troubleshooting diagnosing sodium libsodium with PHP

Check for polyfill use on specific algorithms

# Testing
set +H # disable history expansion
PHP_CODE=$(cat <<'PHP_CODE'
<?php
require_once "/var/www/html/magento/vendor/paragonie/sodium_compat/autoload.php";
if (ParagonIE_Sodium_Compat::polyfill_is_fast()) {
    // Use libsodium now
    echo "polyfill_is_fast", PHP_EOL;
} else {
    // Defer to a cron job or other sort of asynchronous process
    echo "not fast", PHP_EOL;
}
if (ParagonIE_Sodium_Compat::crypto_pwhash_is_available()) {
  echo "Argon2i Support Detected", PHP_EOL;
}

if (extension_loaded("sodium")) {
  echo "SODIUM_LIBRARY_VERSION:", SODIUM_LIBRARY_VERSION, PHP_EOL;
}

PHP_CODE
)
set -H # re-enable history expansion
echo "${PHP_CODE}" | php
php -i | grep sodium



# Testing
set +H # disable history expansion
PHP_CODE=$(cat <<'PHP_CODE'
<?php
if (extension_loaded("sodium")) {
  echo "SODIUM_LIBRARY_VERSION:", SODIUM_LIBRARY_VERSION, PHP_EOL;
}
PHP_CODE
)
set -H # re-enable history expansion
echo "${PHP_CODE}" | php
php -i | grep sodium

dnf -y install php-pear php-devel libsodium-devel make
pecl channel-update pecl.php.net
pecl install libsodium
echo 'extension=sodium.so' > /etc/php.d/20-sodium.ini
php -i | grep sodium
yum list \*sodium\*

repoquery --list php73-sodium
yum provides "/usr/lib64/php/modules/sodium.so"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment