Hiya,
I'm trying to use GNUPG and Crypt_GPG to encrypt data ready to be sent across email to a client server but i'm having problems setting it up.
- I've installed GNUPG on the server, and it works just fine, located in /home/myserver/.gnupg
- I've installed Crypt_GPG into /home/myserver/php/Crypt and edited the various files to have absolute link references to each other. They work fine.
- I've used my server CPanel to create a test public/secret key. The key generated fine.
Here is my test code (with debug mode left on)
<?php
require_once '/home/myserver/php/Crypt/GPG.php';
$gpg = new Crypt_GPG(array('homedir' => '/home/myserver/.gnupg', 'debug' => true));
echo "My public key is: ", $gpg->exportPublicKey('[email protected]'), "<br>";
echo "My key fingerprint is: ", $gpg->getFingerprint('[email protected]', Crypt_GPG::FORMAT_CANONICAL), "<br>";
$data = 'Hello, World!';
$gpg->addSignKey('[email protected]');
$signedData = $gpg->sign($data, Crypt_GPG::SIGN_MODE_CLEAR);
echo "<br><br>Clearsigned message is: ", $signedData, "\n";
?>
The first section of code works well - the public key is retrieved, displayed and the fingerprint shows too.
The problem is with the second block of code - actually trying to encrypt something. I get these errors in the debug output. I won't post the full output (its large) but I hope these are the salient points:
Crypt_GPG DEBUG: STATUS: GET_HIDDEN passphrase.enter
Crypt_GPG DEBUG: STATUS: GOT_IT
Crypt_GPG DEBUG: STATUS: MISSING_PASSPHRASE
Crypt_GPG DEBUG: STATUS: BAD_PASSPHRASE EEE2DCBB741D9730
Crypt_GPG DEBUG: STATUS: USERID_HINT EEE2DCBB741D9730 Test Key (Test Key)
Crypt_GPG DEBUG: STATUS: NEED_PASSPHRASE EEE2DCBB741D9730 EEE2DCBB741D9730 17 0
Crypt_GPG DEBUG: STATUS: GET_HIDDEN passphrase.enter
Crypt_GPG DEBUG: => closing GPG input pipe
Crypt_GPG DEBUG: selecting streams
Crypt_GPG DEBUG: => got 1
Crypt_GPG DEBUG: GPG is ready for command data
Crypt_GPG DEBUG: => about to write 1 bytes to GPG command
Crypt_GPG DEBUG: => wrote 1
Crypt_GPG DEBUG: => closing GPG input pipe
Crypt_GPG DEBUG: selecting streams
Crypt_GPG DEBUG: => got 1
Crypt_GPG DEBUG: GPG status stream ready for reading
Crypt_GPG DEBUG: => about to read 8192 bytes from GPG status
Crypt_GPG DEBUG: => read 44 bytes
Crypt_GPG DEBUG: STATUS: GOT_IT
Crypt_GPG DEBUG: STATUS: MISSING_PASSPHRASE
Crypt_GPG DEBUG: => closing GPG input pipe
Crypt_GPG DEBUG: selecting streams
Crypt_GPG DEBUG: => got 1
Crypt_GPG DEBUG: GPG status stream ready for reading
Crypt_GPG DEBUG: => about to read 8192 bytes from GPG status
Crypt_GPG DEBUG: => read 122 bytes
Crypt_GPG DEBUG: STATUS: BAD_PASSPHRASE EEE2DCBB741D9730
and then later:
Crypt_GPG DEBUG: END PROCESSING
Crypt_GPG DEBUG: CLOSING SUBPROCESS
Crypt_GPG DEBUG: => subprocess returned an unexpected exit code: 2
Fatal error: Uncaught <table border="1" cellspacing="0"> <tr><td colspan="3" bgcolor="#ff9999"> <b>Crypt_GPG_BadPassphraseException</b>: Cannot sign data. Incorrect passphrase provided. in <b>/home/myserver/php/Crypt/GPG.php</b> on line <b>1054</b></td></tr> <tr><td colspan="3" bgcolor="#aaaaaa" align="center"><b>Exception trace</b></td></tr> <tr><td align="center" bgcolor="#cccccc" width="20"><b>#</b></td><td align="center" bgcolor="#cccccc"><b>Function</b></td><td align="center" bgcolor="#cccccc"><b>Location</b></td></tr> <tr><td align="center">0</td><td>Crypt_GPG->_sign('Hello, World!', false, null, 2, true)</td><td>/home/myserver/php/Crypt/GPG.php:1054</td></tr> <tr><td align="center">1</td><td>Crypt_GPG->sign('Hello, World!', 2)</td><td>/home/myserver/public_html/email.php:7</td></tr> <tr><td align="center">2</td><td>{main}</td><td> </td></tr> </table> thrown in /home/myserver/php/Crypt/GPG.php on line 1837
To me it looks like the Crypt_GPG is having issues selecting what it needs from the GNUPG key? It appears to find the key correctly, but it falls over with the passphrase. Is this an error with my understanding and code, or is this because CPanel and Apache are different users or something?
Need a bit of guidance, thanks ;)