Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two quick problems (beginner inside) 2

Status
Not open for further replies.

Numbski

MIS
Mar 27, 2001
56
US
I have two tasks that I'm sure aren't all that difficult to implement.

The first is that when someone calls the cgi script, I want to be able to test some of the form values, and if they pass my test, respond by send a binary file from the server for them to download, and if it fails respond with hyptertext (the latter of which I already know how to do), so I need to know how to 'print' a binary file as a response (I think).

The second is that the end user won't be using a web browser to access this, but a custom win32 binary. We are wishing to use an encryption module that's available for both c++ and PERL which I imagine isn't terribly difficult. We were just going to encrypt the filenames and leave the binary files alone, but now we'd really like to encrypt the binary, then go back and encrypt the name of the file. I was wondering if you had any suggestions offhand, and perhaps the syntax for doing the encryption. We were thinking PGP, but I've never used PGP before, and everything I find only deals with encrypting text, not binary files. Help?

Numbski
 
I need to clarify here...

We have hundreds of small, binary files on the server that we wish to serve only to users whom have paid for access. We encrypt the files server side, download them via the client software, then decrypt client side, thus the need for the module to be available for both PERL and C++.

Like I said, we were thinking that we'd encrypt the binary to keep it from being opened, and then encrypt the filenames so that if the end user tries to get too smart and attempts to just download directly, they wouldn't recognize any of the files. The client can then download the file, decrypt the filename, and then finally decrypt the binary. Make a little more sense?

Numbski
 
Okay, I'm reading it....I don't know if Blowfish exists for c++, as it claims to be pure PERL. But assuming that it does, from the examples they give on


It's encrypting text once again. Let's say I've got the binary file pacman.zip. How would I go about encrypting the binary file, keeping the filename itself the same?
 
Okay, I'm reading it....I don't know if Blowfish exists for c++, as it claims to be pure PERL. But assuming that it does, from the examples they give on


It's encrypting text once again. Let's say I've got the binary file pacman.zip. How would I go about encrypting the binary file, keeping the filename itself the same? Could someone show me a mockup construct?
 
Try this little program. I have a web script that takes user input, converts it to a PDF document and then sends the PDF to the user. I didn't use any special modules, just CGI, Time::Localtime (for logging the time and date), and File::Copy.

binmode STDOUT;

print header( -type => 'application/pdf');

open (CASHOUTPDF, "d:\\webdb\\cashout\\" . param('ACCOUNT_MANAGER') . ".pdf") or die "Can't open PDF file: $!";
binmode CASHOUTPDF;
while (<CASHOUTPDF>)
{
print;
}
close CASHOUTPDF;
close STDOUT;


Let me know if this isn't what you're looking for.
 
Well, except that you're calling a function 'header' in there, and setting -type => 'application/pdf'. How do I set it to just send raw binary data? Or just a binary zip file if I must? Also, that line just prints the header. If I'm reading right, you're opening a file (I notice you don't specify read or write with > or < or >>) and assigning it the name ACCOUNT_MANAGER.pdf (am I reading that right?), setting binmode to the file so that PERL knows you're not reading an ascii file, and you're saying while that file is open, print, but you're not printing anything....? Or is it that when you're in binmode, print; prints the currently loaded binary data? I think I'm lost on that part. :)

Numbski
 
Sorry, I added the header information by mistake. (That's for piping it through an HTML file) Allow me to try to explain a little further:

binmode STDOUT; # sets STDOUT to a binary mode

open (CASHOUTPDF, &quot;d:\\webdb\\cashout\\&quot; .
param('ACCOUNT_MANAGER') . &quot;.pdf&quot;) or die &quot;Can't open PDF file: $!&quot;; # opens the file created earlier.
# The file was named by the Account Manager who logged into the script
# you can grab any file you wish here
binmode CASHOUTPDF; # sets CASHOUTPDF to binary mode
while (<CASHOUTPDF>) #while there's a line in CASHOUTPDF
{
print; # print it. Without stating where to print, Perl will
# print the file to STDOUT which is now in binary mode
}
close CASHOUTPDF; # closing the file
close STDOUT; # closing STDOUT to end the binary session

I took this from a script I wrote to create a cashout worksheet. Since more than 50 people could use this script I had to make the filename dynamic and dependant on the user who logged in. To do that, param('ACCOUNT_MANAGER') is the user who is logged into the script at that time requesting the worksheet be created and sent to them. If you're just sending one zip file to every user, remove the file name/directory I used and hardcode the filename into that spot.

- George
 
Thank you. That's precisely what I needed of the binary file print. :) Now I need to see a contruct using Blowfish (or PGP if it can be used)....I've read the docs on it and the only example given is using it on text, which is fine, but can it be used to encrypt binary data as well?
 
Sorry, don't know -- try it and see. :) Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
I have one more issue with this. This is my code sample. I have files on the server with encrypted file names. The binaries themselves aren't encrypted mind you, just the names. A person inputs the URL:

dl.cgi?005

This person wishes to download 005.zip from the server. Here's my code thus far:

$command = $ENV{QUERY_STRING};
$command = $command.&quot;zip&quot;;
$crypted=$crypto->encode($command,&quot;yomom&quot;);

binmode STDOUT; # sets STDOUT to a binary mode

open (ROM, $romdir.$crypted) or die &quot;Can't open file: $!&quot;;

binmode ROM; # sets ROM to binary mode
while (<ROM>) {
print;
}
close ROM;
close STDOUT;


I have defined $crypto earlier in the script. Just trust me in the fact that the line takes my 005.zip command and encrypts it, so that it is now the same value as the filename on the server. When it goes to send the file though, IE prompts you save dl.htm.zip, which is not even close to what I'm wanting to save. I haven't tried any other browsers. Is there any way send a different filename without making a complete copy of the file on the server (which during heavy traffic would cause considerable strain on the server)?
 
Correction:

$command = $command.&quot;\.zip&quot;;

Minor mistake. :)
 
question: if you accept the false name and download the file anyway, is it the correct file? also, what is the 'Content-type:' header the script sends?
i'd also like to clarify, are you just asking how to get a browser to save a file under a name different than the name it is on your system? would that be enough? &quot;If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito.&quot;
 
That's precisely what I'm asking. The files are all encrypted, so whatever $command is, I encrypt that also, and attempt to open it and send it to the user. If it fails, then the user gets a blank screen for the moment. I'm not sure how to send otherwise.

As far as the content type header....um, don't have one. :) Told you, beginner.... ;)

What would you suggest?
 
Well, what I want to do is simplier
I want to include a gif file in the form string arguments. The gif will be encoded by a script, and put as a value of a hidden field.
On the server side, the script extracts the encoded gif and write it in a regular spare gif file.
That's because I could'nt use ftp, neither mail attachment.
Want to find anything similar to uuencode, to include the gif binary file in the html ascii ?
 
Convert::UU on would seem to do what you need. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top