home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / srev13h.zip / de_srebf.cmd < prev    next >
OS/2 REXX Batch file  |  1999-10-31  |  7KB  |  224 lines

  1. /* 21 April 1999. Daniel Hellerstein (danielh@crosslink.net)
  2.  
  3.     DE_SREBF .CMD: The client-side component of the SRE_BF
  4.                    and SRE_BFC SRE-http encryption methods
  5.  
  6. This os/2 rexx program will decrypt responses from SRE-http servers
  7. that have been encrypted using the SRE_BF and SRE_BFC encryption methods,
  8. and either display them in a netscape window or save to a user
  9. specified file.
  10.  
  11. To use this program, you'll need to do the following (assuming
  12. you are running OS/2, and you have netscape for OS/2):
  13.  
  14. a)  Acquire a BlowFish executable.  In particular, 
  15.     BLOWFISH 1.63 for OS/2, which can be found on http://hobbes.nmsu.edu.
  16.  
  17. b) Copy this file to an applications directory (it does NOT need
  18.    to be in your path). For example, C:\OS2\APPS
  19.  
  20. c) Tell Netscape to use this DE_SREBF whenever it is recieves
  21.    a response from a server that has a mime type of
  22.    application/x-encrypt_SRE_BF
  23.   
  24.    To do this, you should set the following in NetScape:
  25.      1) Open NetScape "applications". 
  26.           for NS4.04 -- look in Edit-Preferences-Applications
  27.           for NS2.02 -- look in Options-General_Preferences-Applications
  28.  
  29.      2) Create a "new type" with:
  30.  
  31.            Mime Type: application/x-encrypt_SRE_BF
  32.            Application to Use: cmd.exe /c "x:\dir\DE_SREBF.cmd PWD:sspwd"
  33.  
  34.         where :
  35.            sspwd   : is your "shared-secret password"
  36.                      If you do NOT specify the PWD:sspwd, then
  37.                      DE_SREBF will ask you to provide a "shared-secret"
  38.                      password
  39.            x:\dir\ : is the path you copied this file to (for example,
  40.                      C:\OS2\APPS).
  41.  
  42.        Note: the  double quote (") characters MUST be included in 
  43.                 this definition!
  44.  
  45. After completing steps a through c, you are ready to recieve encrypted
  46. files from an SRE-http web server. 
  47.  
  48. When you do recieve an "SRE_BF encrypted" response from an SRE-http
  49. web server, NetScape should pop up a window that asks you to  
  50. "load" or"save" the file -- you should choose "load".  
  51. DE_SREBF.CMD will then be invoked.
  52.  
  53. DE_SREBF will decrypt the message, using the shared-secret
  54. you specified (in step 2 above), and will then ask you whether to display
  55. the message in a new NetScape window, or whether to save it to disk.
  56.  
  57. Although DE_SREBF.CMD was developed under OS/2, it might work under
  58. different flavors of REXX -- we'll be checking on that.
  59.  
  60. */
  61.  
  62. /* ---------- Begin user changeable parameters --------- */
  63.  
  64. /* set these to be  fully qualified default output and tempfile directories */
  65. default_outdir=''
  66.  
  67. /* ---------- END of user changeable parameters --------- */
  68.  
  69.  
  70. parse arg arglist
  71.  
  72. if arglist='' then do
  73.     say "This is meant to be used as plug-in for NetScape"
  74.     exit
  75. end /* do */
  76.  
  77. say "  <<<< The SRE-http BlowFish decryptor  >>>>"
  78. dafile=strip(word(arglist,words(arglist)))
  79. hispwd=''
  80. docompress=0
  81. arglist=delword(arglist,words(arglist))
  82. do forever
  83.    if arglist='' then leave
  84.    parse var arglist aword arglist
  85.    aword=strip(translate(aword))
  86.    if abbrev(aword,'PWD:')=1 then do
  87.         parse var aword . ':' hispwd
  88.    end
  89. end /* do */
  90.  
  91. if hispwd='' then do
  92.   call charout,' Please enter your "shared-secret" password: '
  93.   pull hispwd ; hispwd=space(hispwd,0)
  94. end
  95. say ' '
  96. if default_outdir='' then default_outdir=directory()
  97. outdir=strip(default_outdir,'t','\')||'\'
  98.  
  99. if default_tempdir='' then default_tempdir=directory()
  100. tempdir=strip(default_tempdir,'t','\')||'\'
  101.  
  102. crlf='0d0a'x
  103.  
  104. foo=rxfuncquery('sysloadfuncs') /* use rexxutil if it's available */
  105. if foo=1 then do
  106.   call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  107.   call SysLoadFuncs
  108. end
  109.  
  110. dafile=strip(dafile)
  111.  
  112. /* 1) read the file */
  113. ilen=stream(dafile,'c','query size')
  114. if ilen=0 | ilen='' then do
  115.     say "No such file: "dafile
  116.     call charout, ' (hit ENTER to continue)' ; pull foo
  117.     exit
  118. end /* do */
  119.  
  120.  
  121. foo=pos('.',dafile)
  122. if foo=0 then foo=length(dafile)+1
  123. tmpfile=left(dafile,foo-1)'.TMP'
  124.  
  125. address cmd 'BF 'dafile' 'tmpfile' "'||hispwd'"'
  126.  
  127. if stream(tmpfile,'c','query exists')='' then do
  128.     say "Could not create decrypted file: "dafile
  129.     call charout, ' (hit ENTER to continue)' ; pull foo
  130.     exit
  131. end /* do */
  132.  
  133. say
  134. say
  135. call charout, "Display in a new NetScape window (Y/N)? "
  136. pull yn
  137. if yn='Y' then do
  138.    address cmd '@NETSCAPE  file:///'tmpfile
  139. end
  140. else do
  141.    foo=stream(tmpfile,'c','open read')
  142.    if abbrev(translate(foo),'READY')<>1 then do
  143.            say "Problem accessing temporary file: "tmpfile
  144.            say " (hit  ENTER to continue) "
  145.            pull xx
  146.            exit
  147.    end /* do */
  148.    iin=stream(tmpfile,'c','query size')
  149.    if iin=0 | iin=''  then do
  150.            say "Problem reading temporary file: "tmpfile
  151.            say " (hit  ENTER to continue) "
  152.            pull xx
  153.            exit
  154.    end
  155.    aanew=charin(tmpfile,1,iin)
  156.  
  157.    oo=lastpos('\',dafile)
  158.    datemp=substr(dafile,oo+1)
  159.    oo=lastpos('.',datemp)
  160.    if oo=0 then oo=length(datemp)+1
  161.    datemp=left(datemp,oo-1)||'.'
  162.    useout=getofile(outdir||datemp)
  163.    if useout<>"" then do
  164.            foo=stream(useout,'c','open write')
  165.            foo=charout(useout,aanew,1)
  166.            if foo<>0 then do
  167.                 say "Problem writing "useout
  168.            end /* do */
  169.            else
  170.                 say "   .... "useout " written successfully "
  171.           foo=stream(useout,'c','close')
  172.            ill=lastpos('\',useout)
  173.            if ill>0 then  outdir=left(useout,ill)
  174.    end /* do */
  175. end /* do */
  176.  
  177. foo=deleteme(tmpfile)             /* cleanup */
  178.  
  179. exit
  180.  
  181. deleteme:procedure
  182. parse arg gfile
  183. if rxfuncquery('SYSFILEDELETE')=0 then foo=sysfiledelete(gfile)
  184. if stream(gfile,'c','query exists')<>''then return 0
  185. return 1
  186.  
  187.  
  188. /************** Ask for an output file *************/
  189. getofile:procedure
  190. parse arg defout
  191. do forever
  192.   aa="   Output to file (ENTER="defout"):"
  193.   if length(aa)>40 then do
  194.      say aa
  195.      call charout, "    ? "
  196.   end
  197.   else do
  198.     call charout,aa' ?'
  199.   end
  200.  
  201.   pull gfile2 ; gfile2=strip(gfile2)
  202.   if right(gfile2,1)='\' & defout<>'' then do
  203.      iu=lastpos('\',defout)
  204.      gfile2=gfile2||substr(defout,iu+1)
  205.   end
  206.   if gfile2='.'  then return ''
  207.   if gfile2="" then gfile2=defout
  208.   if gfile2="" then iterate
  209.   gfile0=stream(gfile2,'c','query exists')
  210.   if gfile0<>"" then do
  211.       call charout,'   'Gfile0 ' exists.  Overwrite (Y/N)'
  212.       pull anans
  213.       if abbrev(strip(anans),'Y')<>1 then iterate
  214.       foo=deleteme(gfile0)
  215.       if foo=1 then do
  216.          say "    Could not delete gfile0. Try a different file name"
  217.          iterate
  218.       end
  219.   end
  220.   return gfile2
  221. end /* do */
  222.  
  223.  
  224.