質問

I have a C program that makes a system call (centOS 6.0) to encrypt a file, my code is:

#include <stdlib.h>
int main () {
 system ("gpg -c --batch --passphrase mypass file.txt");
 return 0;
}

The executable object is called encrypt_file When I run ./encrypt_file directly through CLI it runs perfectly I obtain my file.txt.gpg, but when I try to execute it via browser I get no response. Code in php:

shell_exec("./encrypt_file");

The reason I chose to make a c program is that I need the passphrase to be in the code but not visible, when I delete the .c file that contains the passphrase all I have left is my .exe and no visible passphrase.

I already changed permissions to apache user by issuing the following:

chown apache.apache /var/www/html/

And added the next line in /etc/sudoers:

apache   ALL=(ALL)    NOPASSWD:ALL

NOTE: The only command I have issues is gpg, I can make a system call with any other command that I needed to use, I can even run python scripts, and other C programs that doesn't contain anything related to gpg.

I hope a fast reply! I need to use a lot this encrypt_file!

役に立ちましたか?

解決

Checking the error_log in /var/log/httpd/error_log I saw this line:

gpg: Fatal: can't create directory `/var/www/.gnupg': Permission denied

Then I found a solution at this site -> http://gnupg.10057.n7.nabble.com/Exi...pt-td7342.html

I added the --homedir option with the PATH that I found in the error.log of apache to the gpg command and it works perfectly!

Thanks to all!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top