home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / misc / PGPAmi26ui.lha / PGPAmiga / contrib / CED / EncypherPGP.ced < prev    next >
Encoding:
Text File  |  1994-11-02  |  5.8 KB  |  207 lines

  1. /********************************************************************/
  2. /*                                                                  */
  3. /* EncipherPGP.ced - ARexx macro for use with Cygnus Editor and PGP */
  4. /*                                                                  */
  5. /* Mark a block of text you want to be encrypted using PGP, then    */
  6. /* run this macro to encrypt it wit someone's public key. It works  */
  7. /* similar to builtin rot13 command. (Only MUCH slower).            */
  8. /* This macro was tested to work with Cygnus Editor 2.0 to 3.5.     */
  9. /*                                                                  */
  10. /* This code is in Public Domain under GNU General Public License   */
  11. /*                                                                  */
  12. /* author: Janusz A. Urbanowicz <alex@vm.cc.uni,torun.pl>           */
  13. /*                                                                  */
  14. /********************************************************************/
  15.  
  16. /*
  17.  *                $VER: EncipherPGP.ced 1.2 (30.10.1994)
  18.  */
  19.  
  20. Trace Off
  21.  
  22. Options Results
  23.  
  24. lf = '0A'X
  25. tempfile = 'T:ced$pgp.tmp'
  26. cmdline = ''
  27. cmdn = '-ca'
  28. cmdf = '<'||tempfile||' >'||tempfile||'.asc -fca'
  29. pgpt = 0 /* pgp 'type' 0 = 2.3a, 1 = 2.3a.?, 2 = 2.6<ui> */
  30. scrname = 'CygnusEdScreen'
  31. scrnum = 1
  32. portname = 'rexx_ced'
  33. portnum = 0
  34.  
  35. cmd = ''
  36. scratch = 0
  37. ID = ''
  38.  
  39. status portnumber
  40. portnum = result
  41. if (portnum ~= 0)&(portnum ~== 'RESULT') Then
  42. Do
  43.         scrnum = scrnum + portnum
  44.         portname = portname||portnum
  45. End
  46.  
  47. scrname = scrname||scrnum
  48.  
  49. Call Close 'STDOUT'             /* Thanx for that goes to Rick Younie*/
  50. Call Close 'STDIN'
  51. Call Open 'STDOUT','CON:16/24/620/130/PGPAmiga Output/CLOSE/WAIT/SCREEN'||scrname
  52. Call Pragma '*','STDOUT'
  53. Call Open 'STDIN','*'
  54.  
  55. Call checkf
  56. pgpt = result
  57. If pgpt > 0 then cmd = cmdf
  58. Else
  59. Do
  60.         cmd = cmdn
  61.         cmdline = tempfile||' '
  62. End
  63.  
  64. Address 'rexx_ced'
  65. If pgpt = 1 Then /* is PGP26_IMPERSONATE option avaliable ? */
  66. Do
  67.         okay2 "Do you want the enciphered packet to be"||lf,
  68.                 "in PGP 2.6 format ?"
  69.         If result = 1 Then
  70.         Do
  71.                 okay1 "WARNING: Packet created with this"||lf,
  72.                 ||"option set cannot be processed"||lf,
  73.                 ||"using 'standard' PGP 2.3a."||lf||lf,
  74.                 ||"You SHOULD NOT use this option"
  75.                 okay2 "Are you sure you want to use"||lf,
  76.                         ||"this option ?"
  77.                 If result = 1 Then cmdline = cmdline||' +PGP26_IMPERSONATE=on'
  78.         End
  79. End
  80. Else cmdline = cmdline||' +batchmode=on'
  81.  
  82. If cmd = cmdn Then Call ask
  83.  
  84. cmdline = cmd||' '||cmdline
  85.  
  86. cut block
  87. If result = 1 Then Call encrypt
  88. Else
  89. Do
  90.         okay2 "No area selected."||lf||"Encipher whole file ?"
  91.         If result = 1 Then
  92.         Do
  93.                 'beg of file'
  94.                 'mark block'
  95.                 'end of file'
  96.                 'cut block'
  97.                 Call encrypt
  98.         End
  99. End
  100. Call quit
  101.  
  102. encrypt:
  103. Do
  104.         menu 0 6 0 tempfile /* save block to file */
  105.         Address Command
  106.         'PGP '||cmdline
  107.         If ~Exists(tempfile||'.asc') Then Call wrongpass
  108.         Else
  109.         Do
  110. /* We check if the output file length is 0 what happens if PGP was in -f mode and passphrase was wrong */
  111.                 If Open('outf',tempfile||'.asc','R') Then
  112.                 Do
  113.                         If Seek('outf',100,'Begin') = 0 Then Call wrongpass
  114.                         Else
  115.                         Do
  116.                                 Address 'rexx_ced'
  117.                                 include file tempfile||'.asc'
  118.                                 status 21
  119.                         End
  120.                 End
  121.         End
  122. End
  123. Return
  124.  
  125. wrongpass:
  126. Address 'rexx_ced'
  127. undo
  128. okay1 "Encryption error !"
  129.  
  130. quit:
  131. Address Command
  132. If Exists(tempfile||'.info') Then 'Delete '||tempfile||'.info QUIET'
  133. If Exists(tempfile||'.asc') Then 'Delete '||tempfile||'.asc QUIET'
  134. If Exists(tempfile) Then 'Delete '||tempfile||' QUIET'
  135. If scratch == 1 Then 'Delete env:PGPPASS QUIET'
  136. If ~Close('STDOUT') Then Nop
  137. Exit 0
  138.  
  139. ask: Procedure Expose scratch lf
  140. Address Command
  141. 'GetEnv >NIL: PGPPASS'
  142. If rc ~= 0 Then
  143. Do
  144.         Address 'rexx_ced'
  145.         okay2 "Your passphrase is not set in PGPPASS variable."||lf||,
  146.         "It must be set temporarily for running PGP".||lf||,
  147.         "Should it be deleted (for higher security) after use ??"
  148.         If result = 1 then scratch = 1
  149.         else scratch = 0
  150.         okay1 'WARNING: Your passphrase will be visible when you type it in.'
  151.         getstring "'  '  'Please enter passphrase.'"
  152.         pgppass = result
  153.         pgppass = Strip(pgppass,'T')
  154.         Address Command
  155.         'SetEnv PGPPASS '||'"'||pgppass||'"'
  156. End
  157. Return
  158.  
  159. checkf: Procedure
  160. Address Command
  161. Call getpath
  162. path = result
  163. If path = "" Then Return 0
  164. Else
  165. Do
  166.         'Version >PIPE:PGPVERSION '||path
  167.         If Open('pvers','PIPE:PGPVERSION','R') Then
  168.         Do
  169.                 verstring = ReadLN('pvers')
  170.                 If Close('pvers') Then Nop
  171.         End
  172.         Parse Var verstring . version
  173.         Select
  174.                 When version = '2.6ui' Then Return 2
  175.                 When version = '2.3a.5' Then Return 1
  176.                 When version = '2.3a.4' Then Return 1
  177.                 When version = '2.3a.3' Then Return 1
  178.                 Otherwise Return 0
  179.         End
  180. End
  181.  
  182. getpath: procedure
  183. 'Which >PIPE:PGPPATH PGP'
  184. If rc = 0 Then
  185. Do
  186.         If Open('ppath','PIPE:PGPPATH','R') Then
  187.         Do
  188.                 path = ReadLN('ppath')
  189.                 If ~Close('ppath') Then Nop
  190.                 Return path
  191.         End
  192. End
  193. Else
  194. Do
  195.         'GetEnv >PIPE:PGPPATH PGPPATH'
  196.         If rc = 0 Then
  197.         Do
  198.                 If Open('ppath','PIPE:PGPPATH','R') Then
  199.                 Do
  200.                         path = ReadLN('ppath')
  201.                         If ~Close('ppath') Then Nop
  202.                         path = path||'/PGP'
  203.                         Return path
  204.                 End
  205.                 Else Return ""
  206.         End
  207.