home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / applications / wp / cedpgp.lha / SignPGP.rexx < prev   
Encoding:
OS/2 REXX Batch file  |  1980-01-06  |  5.9 KB  |  220 lines

  1. /********************************************************************/
  2. /*                                                                  */
  3. /*  SignPGP.ced - ARexx macro for use with Cygnus Editor and PGP    */
  4. /*                                                                  */
  5. /*  Mark a block of text you want to be signed using PGP, then run  */
  6. /*  this macro. If no block was marked, you may choose to use whole */
  7. /*  file instead. This macro was tested to work with CED 3.5, but   */
  8. /*  should work also with lower versions. It also takes advantage   */
  9. /*  of some PGP non-standard options avaliable in official Amiga    */
  10. /*  port by Peter Simons, but should work also with other versions, */
  11. /*  like the PGP 2.6ui, or plain 2.3a.                              */
  12. /*                                                                  */
  13. /*  This code is in Public Domain under GNU General Public License  */
  14. /*                                                                  */
  15. /*  author: Janusz A. Urbanowicz <alex@vm.cc.uni.torun.pl>          */
  16. /*                                                                  */
  17. /*  See CEDPGP.guide for more info                                  */
  18. /*                                                                  */
  19. /********************************************************************/
  20.  
  21. /*
  22.  *                $VER: SignPGP.ced 1.7.1 (31.01.1995)
  23.  */
  24.  
  25. Trace Off
  26.  
  27. Options Results
  28.  
  29. lf = '0A'X
  30. tempfile = 'T:ced$pgp.tmp'
  31. scrname = 'CygnusEdScreen'
  32. scrnum = 1
  33. portname = 'rexx_ced'
  34. portnum = 0
  35.  
  36. pgpt = 0 /* pgp 'type' 0 = 2.3a, 1 = 2.3a.?, 2 = 2.6<ui> */
  37.  
  38. cmdn = '-sat ' /* command for NORMAL PGP */
  39. cmdf = '<'||tempfile||' -fast -o '||tempfile||'.asc' /* command for Peter's patchlevel 3,4 and 5 versions */
  40. scratch = 0
  41.  
  42. /*                            main ()                          */
  43.  
  44. status portnumber
  45. portnum = result 
  46. if (portnum ~= 0)&(portnum ~== 'RESULT') Then
  47. Do
  48.  scrnum = scrnum + portnum
  49.  portname = portname||portnum
  50. End
  51.  
  52. scrname = scrname||scrnum
  53.  
  54.  
  55. Call Close 'STDOUT'        /* Thanx for that goes to Rick Younie*/
  56. Call Close 'STDIN'
  57. Call Open 'STDOUT','CON:16/24/620/130/PGPAmiga Output/CLOSE/WAIT/SCREEN'||scrname
  58. Call Pragma '*','STDOUT'
  59. Call Open 'STDIN','*'
  60.  
  61. Call checkf
  62. pgpt = result
  63. If pgpt > 0  Then
  64. Do
  65.     cmd = cmdf
  66.     cmdline = ''
  67. End
  68. Else 
  69. Do
  70.     Call ask
  71.     cmd = cmdn
  72.     cmdline = tempfile||' +batchmode=on'
  73. End
  74.  
  75.  
  76. Address Command
  77. 'GetEnv >PIPE:PGPUSER PGPUSER'
  78. If rc == 0 Then 
  79. Do
  80.     If Open('user','PIPE:PGPUSER','R') Then
  81.     Do
  82.         userid = ReadLN('user')
  83.         If ~Close('user') Then Nop
  84.         cmdline = cmdline||' -u '||'"'||userid||'"'
  85.     End
  86.     Else
  87.     Do
  88.         Address porname
  89.         Okay1 "Problem while opening PGPUSER environmental variable"||lf||,
  90.         "Fatal error, macro execution aborted."
  91.         Call quit
  92.     End
  93. End
  94.  
  95. address value portname
  96. cmdline = cmd||cmdline
  97. okay2 "Do you want the text you sign to be readable"||lf,
  98.     ||"after signing ( +clearsig=on ) ?"
  99. If result = 1 Then cmdline = cmdline||' +clearsig=on'
  100. If pgpt = 1 Then /* is PGP26_IMPERSONATE option avaliable ? */
  101. Do
  102.     okay2 "Do you want the encrypted packet to be"||lf,
  103.         "in PGP 2.6 format ?"
  104.     If result = 1 Then 
  105.     Do
  106.         okay1 "WARNING: Packet created with this"||lf,
  107.         ||"option set cannot be processed"||lf,
  108.         ||"using 'standard' PGP 2.3a."||lf||lf,
  109.         ||"You SHOULD NOT use this option"
  110.         okay2 "Are you sure you want to use"||lf,
  111.             ||"this option ?"
  112.         If result = 1 Then cmdline = cmdline||' +PGP26_IMPERSONATE=on'
  113.     End
  114. End
  115. cut block
  116. If result = 1 Then Call sign
  117. Else
  118. Do
  119.     okay2 "No area selected."||lf||"Sign whole file ?"
  120.     If result = 1 Then 
  121.     Do
  122.         'beg of file'
  123.         'mark block'
  124.         'end of file'
  125.         'cut block'
  126.         Call sign
  127.     End
  128. End
  129. Call quit
  130.  
  131. sign:
  132. menu 0 6 0 tempfile      /* save block to file */
  133. Address Command
  134. 'PGP '||cmdline 
  135. If rc == 0 Then
  136. Do
  137.     If Exists(tempfile||'.asc') Then
  138.     Do
  139.         If Open('outf',tempfile||'.asc','R') Then 
  140.         Do /* we check if the file has length 0 what happens if PGP in -f mode encountered wrong password */
  141.             If Seek('outf',100,'Begin') = 0 Then
  142.             Do
  143.                 If ~Close('outf') Then Nop
  144.                 Call wrongpass
  145.             End
  146.             Else
  147.             Do
  148.                 address value portname
  149.                 i74642211876884E+0002
  150.  9.73000000000000E-0001   1.74912750989940E+0002
  151.  9.74000000000000E-0001   1.75182228134243E+0002
  152.  9.75000000000000E-0001   1.75450642627152E+0002
  153.  9.76000000000000E-0001   1.75717993812639E+0002
  154.  9.77000000000000E-0001   1.75984281061144E+0002
  155.  9.78000000000000E-0001   1.76249503769412E+0002
  156.  9.79000000000000E-0001   1.76513661360344E+0002
  157.  9.80000000000000E-0001   1.76776753282837E+0002
  158.  9.81000000000000E-0001   1.77038779011634E+0002
  159.  9.82000000000000E-0001   1.772997380471nclude file tempfile||'.asc'
  160.                 status 21
  161.              End
  162.         End
  163.     End
  164.     Else Call wrongpass
  165. End
  166. Else Call wrongpass
  167. Return
  168.  
  169. wrongpass:
  170. address value portname
  171. undo
  172. okay1 "Wrong passphrase !"
  173.  
  174. quit:
  175. Address Command
  176. If Exists(tempfile||'.info') Then 'Delete '||tempfile||'.info QUIET'
  177. If Exists(tempfile||'.asc') Then 'Delete '||tempfile||'.asc QUIET'
  178. If Exists(tempfile) Then 'Delete '||tempfile||' QUIET'
  179. If scratch == 1 Then 'Delete env:PGPPASS QUIET'
  180. If Close('STDOUT') Then Nop
  181. Exit 0 
  182.  
  183. ask: Procedure Expose scratch lf portname
  184. Address Command
  185. 'GetEnv >NIL: PGPPASS'
  186. If rc ~= 0 Then
  187. Do
  188.     address value portname
  189.     okay2 "Your passphrase is not set in PGPPASS variable."||lf||,
  190.     "It must be set temporarily for running PGP".||lf||,
  191.     "Should it be deleted (for higher security) after use ??"
  192.     If result = 1 then scratch = 1
  193.     else scratch = 0
  194.     okay1 'WARNING: Your passphrase will be visible when you type it in.'
  195.     getstring "'  '  'Please enter passphrase.'" 
  196.     pgppass = result
  197.     pgppass = Strip(pgppass,'T')
  198.     Address Command
  199.     'SetEnv PGPPASS '||'"'||pgppass||'"'
  200. End
  201. Return
  202.  
  203. checkf: Procedure 
  204. Address Command
  205. Call getpath
  206. path = result
  207. If path = "" Then Return 0
  208. Else
  209. Do
  210.     'Version >PIPE:PGPVERSION '||path
  211.     If Open('pvers','PIPE:PGPVERSION','R') Then
  212.     Do
  213.         verstring = ReadLN('pvers')
  214.         If Close('pvers') Then Nop
  215.     End
  216.     Parse Var verstring . version
  217.     Select
  218.         When version = '2.6ui' Then Return 2
  219.         When version = '2.3a.5' Then Return 1
  220.         When version = '2.3