Contenu | Rechercher | Menus

Annonce

DVD, clés USB et t-shirts Ubuntu-fr disponibles sur la boutique En Vente Libre

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 28/09/2021, à 10:19

denebe

[Résolu] php sodium chiffrement

Bonjour,

je suis à la fin d'un cours sur la cryptographie - Sécurisez vos données avec la cryptographie, aussi j'essaie de mettre tout cela en pratique…

Il s'agit du hachage des mots de passe à l'aide php et sodium.

Ce que j'ai fait:

sudo apt-get install php

Ce qui n'est pas passé:

thierry@thierry-VirtualBox:~/Dokumente/php$ sudo pecl install -f libsodium
[sudo] Mot de passe de thierry : 
sudo: pecl : commande introuvable

De plus j'ai décommenté extension=sodium:

thierry@thierry-VirtualBox:~/Dokumente/php$ cat /etc/php/7.4/cli/php.ini | grep sodium
extension=sodium

Ensuite j'ai copié le code proposé dans le cours ici ,et j'ai essayé de le lancer:

thierry@thierry-VirtualBox:~/Dokumente/php$ sudo php -f /home/thierry/Dokumente/php/prog1.php 
PHP Warning:  PHP Startup: Unable to load dynamic library 'sodium' (tried: /usr/lib/php/20190902/sodium (/usr/lib/php/20190902/sodium: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/sodium.so (/usr/lib/php/20190902/sodium.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
55eed5b8a36a8e39c77a6b80bc6515582dd7e01a94f7f83b42242614ad7e5d55
e55cad32fe8af7734495934dd141e1ad5c7d79545f4c22d6b46e79
Hello World

thierry@thierry-VirtualBox:~/Dokumente/php$ php -f /home/thierry/Dokumente/php/prog1.php 
PHP Warning:  PHP Startup: Unable to load dynamic library 'sodium' (tried: /usr/lib/php/20190902/sodium (/usr/lib/php/20190902/sodium: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/sodium.so (/usr/lib/php/20190902/sodium.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
d73335f7b9c0c62ad62039a4f8957410f77d971b845635d8d81b88050554ac0f
becbf38c259633d9cfc6b49495122eee916786a91497709bd06b8c
Hello World

Je ne connais pas bien php, mais je ne suis pas une quiche. Sans en avoir jamais fait j'arrive à peu près à lire le petit programme.
echo (comme en bash…)
.    (pour appliquer echo deux fois de suite)
PHP_EOL (end of line…)
D'où les trois lignes qui s'affichent en dessous, ok.

Apparemment la librairie sodium ne se charge pas dynamiquement, c'est grave ?

J'aimerais bien réaliser ces TP et que ça se passe bien. smile
Merci pour votre aide.

Dernière modification par denebe (Le 28/09/2021, à 12:32)


Opensuse Leap 15.3 Plasma 5.18.6
Dimensions Moebius transf.
Sésamath

Hors ligne

#2 Le 28/09/2021, à 10:34

abelthorne

Re : [Résolu] php sodium chiffrement

Si tu n'installes pas ta bibli (commande #2) et que tu la désactives dans la config de PHP, si ton code essaie ensuite de l'utiliser ça ne passe pas, forcément.

Ta commande 2 essaie d'installer libsodium via pecl mais tu n'as pas pecl d'installé. Apparemment, il fait partie du paquet php-pear, essaie de l'installer :

sudo apt-get install php-pear

Ensuite, retente ta commande #2.

Puis, si tu as effectivement modifié php.ini (je ne suis pas sûr que tu l'aies fait, ta commande #3 ne fait qu'afficher le contenu du fichier et filtrer les lignes contenant "sodium", ce qui te dit juste qu'il y a une ligne "extension=sodium" dedans), remodifie-le à l'état précédent.

En ligne

#3 Le 28/09/2021, à 11:29

denebe

Re : [Résolu] php sodium chiffrement

Effectivement, php-pear manquait, plus maintenant.

thierry@thierry-VirtualBox:~$ dpkg-query -l | grep php-pear
ii  php-pear                                   1:1.10.9+submodules+notgz-1ubuntu0.20.04.3 all          PEAR Base System

Maintenant j'obtiens:

thierry@thierry-VirtualBox:~$ sudo pecl install -f libsodium
PHP Warning:  PHP Startup: Unable to load dynamic library 'sodium' (tried: /usr/lib/php/20190902/sodium (/usr/lib/php/20190902/sodium: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/sodium.so (/usr/lib/php/20190902/sodium.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading libsodium-2.0.23.tgz ...
Starting to download libsodium-2.0.23.tgz (28,505 bytes)
.........done: 28,505 bytes
4 source files, building
running: phpize
sh: 1: phpize: not found
ERROR: `phpize' failed

Concernant php.ini , l'indication que j'ai suivi était succincte.

J'ai cherché dans /etc/php… et j'ai changé (avec vim) les fichiers /etc/php/7.4/cli/php.ini et /etc/php/7.4/apache2/php.ini , i.e. dans lesquels j'ai décommenté la ligne ;extension=sodium  .


Opensuse Leap 15.3 Plasma 5.18.6
Dimensions Moebius transf.
Sésamath

Hors ligne

#4 Le 28/09/2021, à 11:45

denebe

Re : [Résolu] php sodium chiffrement

abelthorne a écrit :

Puis, si tu as effectivement modifié php.ini (je ne suis pas sûr que tu l'aies fait, ta commande #3 ne fait qu'afficher le contenu du fichier et filtrer les lignes contenant "sodium", ce qui te dit juste qu'il y a une ligne "extension=sodium" dedans), remodifie-le à l'état précédent.

Je viens de commenter à nouveau extension=sodium par ;extension=sodium dans /etc/php/7.4/{cli, apache2}/php.ini .

J'obtiens presque la même erreur:

thierry@thierry-VirtualBox:~$ sudo pecl install -f libsodium
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading libsodium-2.0.23.tgz ...
Starting to download libsodium-2.0.23.tgz (28,505 bytes)
.........done: 28,505 bytes
4 source files, building
running: phpize
sh: 1: phpize: not found
ERROR: `phpize' failed

Dernière modification par denebe (Le 28/09/2021, à 11:46)


Opensuse Leap 15.3 Plasma 5.18.6
Dimensions Moebius transf.
Sésamath

Hors ligne

#5 Le 28/09/2021, à 11:55

denebe

Re : [Résolu] php sodium chiffrement

Il y a du nouveau, il faut installer php-dev pour avoir phpize:

sudo apt install php-dev

et maintenant:

thierry@thierry-VirtualBox:~$ sudo pecl install -f libsodium
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading libsodium-2.0.23.tgz ...
Starting to download libsodium-2.0.23.tgz (28,505 bytes)
.........done: 28,505 bytes
4 source files, building
running: phpize
Configuring for:
PHP Api Version:         20190902
Zend Module Api No:      20190902
Zend Extension Api No:   320190902
building in /tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23
running: /tmp/pear/temp/libsodium/configure --with-php-config=/usr/bin/php-config
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib
checking for PHP extension directory... /usr/lib/php/20190902
checking for PHP installed headers prefix... /usr/include/php/20190902
checking if debug is enabled... no
checking if zts is enabled... no
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking for sodium support... yes, shared
checking for pkg-config... /usr/bin/pkg-config
checking for libsodium... version 1.0.18 found using pkg-config
checking for sodium_add in -lsodium... yes
checking for a sed that does not truncate output... /usr/bin/sed
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 1572864
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
configure: patching config.h.in
configure: creating ./config.status
config.status: creating config.h
running: make
/bin/bash /tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/libtool --mode=compile cc  -I. -I/tmp/pear/temp/libsodium -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/include -I/tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/main -I/tmp/pear/temp/libsodium -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/libsodium/libsodium.c -o libsodium.lo
mkdir .libs
 cc -I. -I/tmp/pear/temp/libsodium -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/include -I/tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/main -I/tmp/pear/temp/libsodium -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/libsodium/libsodium.c  -fPIC -DPIC -o .libs/libsodium.o
/bin/bash /tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/libtool --mode=link cc -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/include -I/tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/main -I/tmp/pear/temp/libsodium -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib  -DHAVE_CONFIG_H  -g -O2    -o sodium.la -export-dynamic -avoid-version -prefer-pic -module -rpath /tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/modules  libsodium.lo -lsodium
cc -shared  .libs/libsodium.o  -lsodium  -Wl,-soname -Wl,sodium.so -o .libs/sodium.so
creating sodium.la
(cd .libs && rm -f sodium.la && ln -s ../sodium.la sodium.la)
/bin/bash /tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/libtool --mode=install cp ./sodium.la /tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/modules
cp ./.libs/sodium.so /tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/modules/sodium.so
cp ./.libs/sodium.lai /tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/modules/sodium.la
PATH="$PATH:/sbin" ldconfig -n /tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /tmp/pear/temp/pear-build-rooty6wLIe/libsodium-2.0.23/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

running: make INSTALL_ROOT="/tmp/pear/temp/pear-build-rooty6wLIe/install-libsodium-2.0.23" install
Installing shared extensions:     /tmp/pear/temp/pear-build-rooty6wLIe/install-libsodium-2.0.23/usr/lib/php/20190902/
running: find "/tmp/pear/temp/pear-build-rooty6wLIe/install-libsodium-2.0.23" | xargs ls -dils
672022   4 drwxr-xr-x 3 root root   4096 Sep 28 12:52 /tmp/pear/temp/pear-build-rooty6wLIe/install-libsodium-2.0.23
672043   4 drwxr-xr-x 3 root root   4096 Sep 28 12:52 /tmp/pear/temp/pear-build-rooty6wLIe/install-libsodium-2.0.23/usr
672044   4 drwxr-xr-x 3 root root   4096 Sep 28 12:52 /tmp/pear/temp/pear-build-rooty6wLIe/install-libsodium-2.0.23/usr/lib
672045   4 drwxr-xr-x 3 root root   4096 Sep 28 12:52 /tmp/pear/temp/pear-build-rooty6wLIe/install-libsodium-2.0.23/usr/lib/php
672046   4 drwxr-xr-x 2 root root   4096 Sep 28 12:52 /tmp/pear/temp/pear-build-rooty6wLIe/install-libsodium-2.0.23/usr/lib/php/20190902
672041 368 -rwxr-xr-x 1 root root 375152 Sep 28 12:52 /tmp/pear/temp/pear-build-rooty6wLIe/install-libsodium-2.0.23/usr/lib/php/20190902/sodium.so

Build process completed successfully
Installing '/usr/lib/php/20190902/sodium.so'
install ok: channel://pecl.php.net/libsodium-2.0.23
configuration option "php_ini" is not set to php.ini location
You should add "extension=sodium.so" to php.ini

Opensuse Leap 15.3 Plasma 5.18.6
Dimensions Moebius transf.
Sésamath

Hors ligne

#6 Le 28/09/2021, à 12:29

denebe

Re : [Résolu] php sodium chiffrement

Ça fonctionne smile

thierry@thierry-VirtualBox:~$ php -f /home/thierry/Dokumente/php/prog1.php 
235bb30ce23d123231c2753667bb953d9cb5ef76f90519b6d71f58f2752ed3e7
3c63694ecc0b57afa7a148f6c84b609eccdd4831d7946acd1fcf52
Hello World

PS: si on décommente extension=sodium dans php.ini, on obtient un Warning comme quoi le module sodium est déjà chargé, alors j'ai laissé cette ligne décommentée


Opensuse Leap 15.3 Plasma 5.18.6
Dimensions Moebius transf.
Sésamath

Hors ligne