home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Security / Security.zip / pgpsign.zip / PGPSign.CMD < prev    next >
OS/2 REXX Batch file  |  1998-10-29  |  7KB  |  166 lines

  1. /******************************* REXX *********************************/
  2. /*  This REXX program is used to sign plain text files with PGP 5.0   */
  3. /*  for OS/2.  It can also work as a "SEND EXIT" for Southside        */
  4. /*  Software's PlusPak:PMINews 2.0 to sign outgoing messages to       */
  5. /*  Usenet.  This program was written by Jaime A. Cruz, Jr. and       */
  6. /*  released to the public domain in hopes that others find it        */
  7. /*  useful and can improve upon it.                                   */
  8. /**********************************************************************/
  9. '@ECHO OFF'
  10. Parse Arg fn .
  11. passphrase = ''              /* You can hardcode your passphrase here */
  12. switch = 1
  13.  
  14. /**********************************************************************/
  15. /*            Initialize REXXUtil environment (if not present)        */
  16. /**********************************************************************/
  17. rxload = RxFuncQuery('SysLoadFuncs')
  18. If rxload Then
  19.    Do
  20.       Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  21.       Call sysloadfuncs
  22.    End
  23.  
  24. /**********************************************************************/
  25. /*  This program assumes you have a "SET TEMP=temporary directory"    */
  26. /*  directive in your CONFIG.SYS (as on my system).  If you do not,   */
  27. /*  you may want to add one, or adjust the next statement             */
  28. /*  accordingly.                                                      */
  29. /**********************************************************************/
  30. tempdir = Value('TEMP', ,'OS2ENVIRONMENT')
  31.  
  32. /**********************************************************************/
  33. /*        Create two temporary files in the \TEMP directory.          */
  34. /**********************************************************************/
  35. tmpfl.0 = 2
  36. tmpfl.1 = SysTempFileName(tempdir || '\PGP?????.TMP')
  37. tmpfl.1.ctr = 0
  38. tmpfl.2 = SysTempFileName(tempdir || '\PGP?????.TMP')
  39. tmpfl.2.ctr = 0
  40.  
  41. /**********************************************************************/
  42. /*  Read in the input file until we hit the "Subject:" line.  If we   */
  43. /*  never hit this line, continue till the end.                       */
  44. /**********************************************************************/
  45. input.0 = 0
  46. Do While Lines(fn) > 0
  47.    input.0 = input.0 + 1
  48.    x = input.0
  49.    input.x = Linein(fn)
  50.    Parse Value input.x With 1 header 10 ,
  51.                             .
  52.    Call Lineout tmpfl.switch, input.x
  53.    tmpfl.switch.ctr = tmpfl.switch.ctr + 1
  54.  
  55. /**********************************************************************/
  56. /*  If we hit the "Subject:" line, copy it and the next (assumed to   */
  57. /*  be blank) line to the first temporary file, and then switch over  */
  58. /*  to the second temporary file.  It is this file which will be      */
  59. /*  signed (don't sign the PMINews header information, it confuses    */
  60. /*  the program).                                                     */
  61. /**********************************************************************/
  62.    If header = 'Subject: ' Then
  63.       Do
  64.          input.0 = input.0 + 1
  65.          x = input.0
  66.          input.x = Linein(fn)
  67.          Call Lineout tmpfl.switch, input.x
  68.          tmpfl.switch.ctr = tmpfl.switch.ctr + 1
  69.          switch = 2
  70.       End
  71. End
  72.  
  73. /**********************************************************************/
  74. /*  Close the two (possibly three) files.  Again, if we never found   */
  75. /*  a "Subject:" line, then sign the entire document, otherwise       */
  76. /*  we will just sign the message portion of the file.                */
  77. /**********************************************************************/
  78. Call Lineout fn
  79. Call Lineout tmpfl.1
  80. If switch = 2 Then
  81.    Call Lineout tmpfl.2
  82.  
  83. /**********************************************************************/
  84. /*  If the "passphrase" variable is left blank above, this section    */
  85. /*  will prompt the user for his PGP passphrase.  This is the only    */
  86. /*  section of this program that will require IBM's Visual REXX       */
  87. /*  extensions package (VREXX2.ZIP on most OS/2 download sites).      */
  88. /**********************************************************************/
  89. If Length(passphrase) = 0 Then
  90.    Do
  91.       Call RxFuncAdd 'VInit', 'VREXX', 'VINIT'
  92.       initcode = VInit()
  93.       If initcode \= 'ERROR' Then
  94.          Do
  95.             Call VDialogPos 50, 50
  96.             p.0 = 1                          /* Number of prompts     */
  97.             p.1 = 'Enter your PGP Passphrase:'
  98.             w.0 = p.0                        /* Width of each prompt  */
  99.             w.1 = 80
  100.             h.0 = p.0                        /* Which replies to hide */
  101.             h.1 = 1
  102.             r.0 = p.0                        /* Response defaults     */
  103.             r.1 = ''
  104.             button = VMultBox('PGPSign', p, w, h, r, 1)
  105.             passphrase = r.1
  106.          End
  107.       Call VExit
  108.    End
  109.  
  110. /**********************************************************************/
  111. /*  Place the passphrase in the local OS/2 environment for PGP 5.0    */
  112. /*  to find.                                                          */
  113. /**********************************************************************/
  114. Call Value 'PGPPASS', passphrase, 'OS2ENVIRONMENT'
  115.  
  116. /**********************************************************************/
  117. /*  Use PGP 5.0 to sign the file.  The signed file is created in      */
  118. /*  another temporary file.                                           */
  119. /**********************************************************************/
  120. sgnfull = SysTempFileName(tempdir || '\PGP?????.TMP')
  121. 'PGP s -aqt' tmpfl.switch '-o' sgnfull
  122.  
  123. /**********************************************************************/
  124. /*       Read the signed file into compound variable record.x         */
  125. /**********************************************************************/
  126. record.0 = 0
  127. Do While Lines(sgnfull) > 0
  128.    record.0 = record.0 + 1
  129.    x = record.0
  130.    record.x = Linein(sgnfull)
  131. End
  132. Call Lineout sgnfull
  133.  
  134. /**********************************************************************/
  135. /*  Now, overwrite the original file with the signed information.     */
  136. /*  If the file was split, first copy in the unsigned portion of the  */
  137. /*  data (the PMINews header information).                            */
  138. /**********************************************************************/
  139. Call SysFileDelete fn
  140. If switch = 2 Then
  141.    Do x = 1 To tmpfl.1.ctr
  142.       Call Lineout fn, input.x
  143.    End
  144.  
  145. /**********************************************************************/
  146. /*                   Now copy in the signed file.                     */
  147. /**********************************************************************/
  148. Do x = 1 To record.0
  149.    Call Lineout fn, record.x
  150. End
  151. Call Lineout fn
  152.  
  153. /**********************************************************************/
  154. /*           Delete all of the temporary files we created.            */
  155. /**********************************************************************/
  156. Call SysFileDelete sgnfull
  157. Call SysFileDelete tmpfl.1
  158. Call SysFileDelete tmpfl.2
  159.  
  160. /**********************************************************************/
  161. /*      If we loaded the REXX Utils functions, drop them here.        */
  162. /**********************************************************************/
  163. If rxload Then
  164.    Call SysDropFuncs
  165. Exit
  166.