head 1.2; access; symbols; locks; comment @:: @; 1.2 date 2007.11.14.20.37.52; author pkern; state Exp; branches; next 1.1; 1.1 date 2007.11.14.17.52.27; author pkern; state Exp; branches; next ; desc @@ 1.2 log @more efficient(?) @ text @@@echo off rem # The submission server. set server=viper.utcs.utoronto.ca rem # The file to be submitted. set datfil=%1 if "%datfil%" == "" set /p datfil= File to submit: rem # Temp file prefix. set pfx=%Temp%\xpta rem # Detect openssl. set osslcmd=openssl %osslcmd% version > NUL 2> NUL if errorlevel 2 set osslcmd="%ProgramFiles%\OpenSSL\bin\openssl.exe" %osslcmd% version > NUL 2> NUL if errorlevel 2 ( @@echo ######################################################## @@echo # @@echo # Cannot find openssl.exe. Please check your PATH. @@echo # @@echo # If OpenSSL is not installed then you can download @@echo # a recent copy of Win32OpenSSL-0_9_NN.exe from .... @@echo # http://cns.utoronto.ca/ftp/pub/openssl/ @@echo # @@echo ######################################################## set /p junk=[ hit Enter to finish ] goto:EOF ) rem # Fetch a public key and a jobid from the server. rem # Use that public key to encrypt the data file and "print" rem # the results to the server using the given jobid. rem # Get OpenSSL version. for /f "tokens=" %%A in ('%osslcmd% version') do set overs=%%A rem # Send preferred key type and preferred key bit length. set info=rsa 1024 %overs% echo _ Contacting server. finger -l "%info%"@@%server% > %pfx%-finger.txt rem #debug# type %pfx%-finger.txt echo _ Parsing server reply. set pubkey=%pfx%-pubkey if EXIST %pubkey% del %pubkey% set jobid= set digest= set printq= for /f "tokens=1,2" %%A in ('type %pfx%-finger.txt') do ( if "%%A" == "j" set jobid=%%B if "%%A" == "d" set digest=%%B if "%%A" == "q" set printq=%%B if "%%A" == "p" echo %%B >> %pubkey% ) rem #debug# type %pubkey% rem # Encrypt the data using the public key. echo _ Encrypting file "%datfil%" %osslcmd% enc -a -kfile %pubkey% -in %datfil% -out %pfx%-xmit rem # Generate a checksum of the original file. for /f "tokens=1,2" %%A in ('%osslcmd% dgst -%digest% %datfil%') do set cksum=%%B rem # Send the encrypted data. echo _ Submitting encrypted file. lpr -S %server% -P %printq% -J %jobid% -C %cksum%:%datfil% %pfx%-xmit rem # Clean up. del %pfx%-*.* echo _ Done. set /p junk=[ hit Enter to finish ] @ 1.1 log @Initial revision @ text @d32 6 a37 20 rem # Generate RSA private and public keys. The public key is sent to rem # the server for the server to encrypt the passphrase it generates rem # The encrypted server passphrase is sent back to the client. The rem # client uses its private key to decrypt the server-generated rem # passphrase. The decrypted server-generated passphrase is used rem # in encrypting the data file before it's "printed" to the server. if EXIST %pfx%-priv.pem ( @@echo ######################################################## @@echo # @@echo # Private key file already exists. @@echo # File submission cancelled. @@echo # @@echo # Before trying again, remove all files with ... @@echo # %pfx%-*.* @@echo # @@echo ######################################################## set /p junk=[ hit Enter to finish ] goto:EOF ) d39 2 a40 18 rem # Generate a reasonably-sized private key. echo _ Generating an RSA private key. set bits=768 %osslcmd% genrsa -out %pfx%-priv.pem %bits% 2> NUL rem # Generate a public key for the new private key. echo _ Generating an RSA public key. %osslcmd% rsa -pubout -in %pfx%-priv.pem -out %pfx%-pub.pem 2> NUL rem #debug# type %pfx%-pub.pem rem # Send public key to the server by way of the "finger" command. rem # Get usage parameters and an encrypted password in return. setlocal enabledelayedexpansion for /f "tokens=1" %%A in ('type %pfx%-pub.pem') do ( if NOT "%%A" == "-----END" set info=!info! %%A if "%%A" == "-----BEGIN" set info=%bits% ) d48 2 a49 1 if EXIST %pfx%-pw.b64 del %pfx%-pw.b64 a50 1 set cipher= a54 1 if "%%A" == "c" set cipher=%%B d57 1 a57 1 if "%%A" == "p" echo %%B >> %pfx%-pw.b64 d59 1 a59 6 rem #debug# type %pfx%-pw.b64 rem # Use private key to unscramble the passphrase. echo _ Extracting passphrase. %osslcmd% enc -base64 -d -in %pfx%-pw.b64 -out %pfx%-pw.bin %osslcmd% rsautl -inkey %pfx%-priv.pem -in %pfx%-pw.bin -out %pfx%-pw.use -decrypt 2> NUL d61 1 a61 1 rem # Encrypt the data using the passphrase. d63 1 a63 1 %osslcmd% enc -%cipher% -a -pass file:%pfx%-pw.use -in %datfil% -out %pfx%-xmit @