Blank encrypted messages

Matthew Reeve matt@rangie.com
Fri May 2 18:15:02 2003


Found it!!

In the function below, I 'fopen' then 'fputs' to the file, but it's not
flushed until the file pointer goes out of scope at the end of the =
function.
At the time of calling gpg, the file is created but empty. By adding an
'fclose' call on that pointer prior to calling gpg the problem is =
solved!
That's why when running it from the command line there was no problem, =
even
when using the same files.

Anyway, thanks everyone for your help, both on and off list!

Matthew Reeve

> -----Original Message-----
> From: gnupg-users-admin@gnupg.org=20
> [mailto:gnupg-users-admin@gnupg.org] On Behalf Of Matthew Reeve
> Sent: 30 April 2003 08:26
> To: 'Joseph Bruni'
> Cc: gnupg-users@gnupg.org
> Subject: RE: Blank encrypted messages
>=20
>=20
>=20
> > Does the variable "$msg" exist in the subshell? If it's not=20
> > defined the=20
> > you would be just echoing nothing into the left-hand side=20
> of the pipe.
>=20
> It's an interesting thought - I rewrote the script to look=20
> like this, also
> addressing Adam's concerns about the security of echoing $msg.
>=20
> The file called $plainTxt is created and contains the correct=20
> data. The file
> called $crypted is also created and contains a PGP message. However,
> decrypting the contents of $crypted gives an empty string.
>=20
> The 'echo' shows the encryption command is the following.
>=20
> /usr/bin/gpg --encrypt -v -ao
> /var/www/tempFiles/1195e9ed7ad15a57907ff4b87bc4653aoutput=20
> --always-trust -r
> matt@rangie.com=20
> /var/www/tempFiles/1195e9ed7ad15a57907ff4b87bc4653adata
>=20
>=20
> If I copy and paste the encryption command into a shell running as the
> apache user (instead of calling it from PHP), an encrypted=20
> file is created
> containing a PGP message which contains the correct data when=20
> decrypted.
>=20
> Is there any way to see what is going on with gpg while it's running?=20
>=20
> *********
> function _encrypt($msg)=20
> {=20
> 	$oldhome =3D getEnv("HOME");=20
> 	putenv("HOME=3D/var/www");=20
>=20
> 	$tmpToken =3D md5(uniqid(rand()));
> 	$plainTxt =3D "/var/www/tempFiles/" . $tmpToken . "data";
> 	$crypted =3D "/var/www/tempFiles/" . $tmpToken . "output";
> 	$fp =3D fopen($plainTxt, "w+");
> 	fputs($fp, $msg);
>=20
> 	echo "/usr/bin/gpg --encrypt -v -ao $crypted --always-trust -r
> matt@rangie.com $plainTxt";
> 	passthru("/usr/bin/gpg --encrypt -v -ao $crypted=20
> --always-trust -r
> matt@rangie.com $plainTxt");
> 	putenv("HOME=3D$oldhome");=20
>=20
> 	$fd =3D fopen($crypted, "r");
> 	$message =3D fread($fd, filesize($crypted));
> 	fclose($fd);
>=20
> 	return $message;
> }=20
> ***************
>=20
> Thanks for the help!
>=20
> Matthew Reeve
>=20
>=20
> _______________________________________________
> Gnupg-users mailing list
> Gnupg-users@gnupg.org
> http://lists.gnupg.org/mailman/listinfo/gnupg-users
>=20