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

  1. /*******************************************************************/
  2. /*                                                                 */
  3. /* EncryptPGP.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. /* See CEDPGP.guide for more info                                  */
  15. /*                                                                 */
  16. /*******************************************************************/
  17.  
  18. /*
  19.  *                $VER: EncryptPGP.ced 1.3.1 (31.01.1995)
  20.  */
  21.  
  22. /* This macro uses PGPUSER environmental variable to determine */
  23. /* which private key should be used to sign the text. If there is no */
  24. /* PGPUSER variable it uses the default key to sign (if needed) */
  25.  
  26. Trace Off
  27.  
  28. Options Results
  29.  
  30. lf = '0A'X
  31. tempfile = 'T:ced$pgp.tmp'
  32. cmdn = '-ea'
  33. cmdf = '<'||tempfile||' -o '||tempfile||'.asc -fea'
  34. pgpt = 0 /* pgp 'type' 0 = 2.3a, 1 = 2.3a.?, 2 = 2.6<ui> */
  35. scratch = 0
  36. ID = ''
  37.  
  38. scrname = 'CygnusEdScreen'
  39. scrnum = 1
  40. portname = 'rexx_ced'
  41. portnum = 0
  42.  
  43. /*                               main()                           */
  44.  
  45. status portnumber
  46. portnum = result 
  47. if (portnum ~= 0)&(portnum ~== 'RESULT') Then
  48. Do
  49.     scrnum = scrnum + portnum
  50.     portname = portname||portnum
  51. End
  52.  
  53. scrname = scrname||scrnum
  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.  
  62. Call checkf
  63. pgpt = result
  64. If pgpt > 0 Then
  65. Do
  66.     cmd = cmdf
  67.     cmdline = ''
  68. End
  69. Else
  70. Do
  71.     cmd = cmdn
  72.     cmdline = tempfile||' '
  73. End
  74.  
  75. Address Value portname
  76. getstring '" "  "Please enter recipient`s userid:"'
  77. ID = result
  78. ID = Strip(ID,'B')
  79.  
  80. Address Command
  81. 'GetEnv >PIPE:PGPUSER PGPUSER'
  82. If rc = 0 Then 
  83. Do
  84.     If ~Open('user','PIPE:PGPUSER','R') Then
  85.     Do
  86.         Address value portname
  87.         Okay1 "Problem while opening PGPUSER environmental variable"||lf||,
  88.         "Fatal error, macro execution aborted."
  89.         Call quit
  90.     End
  91.     Else
  92.     Do
  93.         userid = ReadLN('user')
  94.         If ~Close('user') Then Nop
  95.         cmdline = cmdline||ID||' -u '||'"'||userid||'"'
  96.     End
  97. End
  98. Else cmdline = cmdline||ID
  99.  
  100. Address Value portname
  101. If pgpt = 1 Then /* is PGP26_IMPERSONATE option avaliable ? */
  102. Do
  103.     okay2 "Do you want the encrypted packet to be"||lf,
  104.         "in PGP 2.6 format ?"
  105.     If result = 1 Then 
  106.     Do
  107.         okay1 "WARNING: Packet created with this"||lf,
  108.         ||"option set cannot be processed"||lf,
  109.         ||"using 'standard' PGP 2.3a."||lf||lf,
  110.         ||"You SHOULD NOT use this option"
  111.         okay2 "Are you sure you want to use"||lf,
  112.             ||"this option ?"
  113.         If result = 1 Then cmdline = cmdline||' +PGP26_IMPERSONATE=on'
  114.     End
  115. End
  116. Else cmdline = cmdline||' +batchmode=on'
  117.  
  118. okay2 "Do you want to sign the text with"||lf||" your private key ??"
  119. If result = 1 Then 
  120. Do
  121.     If cmd = cmdn Then Call ask
  122.     cmd = cmd||'st '
  123. End
  124. Else cmd = cmd||'t '
  125.  
  126. cmdline = cmd||cmdline
  127.  
  128. cut block
  129. If result = 1 Then Call encrypt
  130. Else
  131. Do
  132.     okay2 "No area selected."||lf||"Encrypt whole file ?"
  133.     If result = 1 Then 
  134.     Do
  135.         'beg of file'
  136.         'mark block'
  137.         'end of file'
  138.         'cut block'
  139.         Call encrypt
  140.     End
  141. End
  142. Call quit
  143.  
  144. encrypt:
  145. Do
  146.     menu 0 6 0 tempfile /* save block to file */
  147.     Address Command
  148.     'PGP '||cmdline 
  149.     If ~Exists(tempfile||'.asc') Then Call wrongpass
  150.     Else
  151.     Do
  152. /* We check if the output file length is 0 what happens if PGP was in -f mode and passphrase was wrong */
  153.         If Open('outf',tempfile||'.asc','R') Then 
  154.         Do
  155.             If Seek('outf',100,'Begin') = 0 Then
  156.             Do
  157.                 If ~Close('outf') Then Nop
  158.                 Call wrongpass
  159.             End
  160.             Else
  161.             Do
  162.                 Address value portname
  163.                 include file tempfile||'.asc'
  164.                 status 21
  165.             End
  166.         End
  167.     End
  168. End
  169. Return
  170.  
  171. wrongpass:
  172. Address value portname
  173. undo
  174. okay1 "Wrong passphrase !"
  175.  
  176. quit:
  177. Address Command
  178. If Exists(tempfile||'.info') Then 'Delete '||tempfile||'.info QUIET'
  179. If Exists(tempfile||'.asc') Then 'Delete '||tempfile||'.asc QUIET'
  180. If Exists(tempfile) Then 'Delete '||tempfile||' QUIET'
  181. If scratch == 1 Then 'Delete env:PGPPASS QUIET'
  182. If ~Close('STDOUT') Then Nop
  183. Exit 0 
  184.  
  185. ask: Procedure Expose scratch lf portname
  186. Address Command
  187. 'GetEnv >NIL: PGPPASS'
  188. If rc ~= 0 Then
  189. Do
  190.     Address value portname
  191.     okay2 "Your passphrase is not set in PGPPASS variable."||lf||,
  192.     "It must be set temporarily for running PGP".||lf||,
  193.     "Should it be deleted (for higher security) after use ??"
  194.     If result = 1 then scratch = 1
  195.     else scratch = 0
  196.     okay1 'WARNING: Your passphrase will be visible when you type it in.'
  197.     getstring "'  '  'Please enter passphrase.'" 
  198.     pgppass = result
  199.     pgppass = Strip(pgppass,'T')
  200.     Address Command
  201.     'SetEnv PGPPASS '||'"'||pgppass||'"'
  202. End
  203. Return
  204.  
  205. checkf: Procedure 
  206. Address Command
  207. Call getpath
  208. path = result
  209. If path = "" Then Return 0
  210. Else
  211. Do
  212.     'Version >PIPE:PGPVERSION '||path
  213.     If Open('pvers','PIPE:PGPVERSION','R') Then
  214.     Do
  215.         verstring = ReadLN('pvers')
  216.         If Close('pvers') Then Nop
  217.     End
  218.     Parse Var verstring . version
  219.     Select
  220.         When version = '2.6ui' Then Return 2
  221.         When version = '2.3a.5' Then Return 1
  222.         When version = '2.3a.4' Then Return 1
  223.         When version = '2.3a.3' Then Return 1
  224.         Otherwise Return 0
  225.     End
  226. End
  227.  
  228. getpath: procedure
  229. 'Which >PIPE:PGPPATH PGP'
  230. If rc = 0 Then
  231. Do
  232.     If Open('ppath','PIPE:PGPPATH','R') Then
  233.     Do
  234.         path = ReadLN('ppath')
  235.         If ~Close('ppath') Then Nop
  236.         Return path
  237.     End
  238. End
  239. Else
  240. Do
  241.     'GetEnv >PIPE:PGPPATH PGPPATH'
  242.     If rc = 0 Then
  243.     Do
  244.         If Open('ppath','PIPE:PGPPATH','R') Then
  245.         Do
  246.             path = ReadLN('ppath')
  247.             If ~Close('ppath') Then Nop
  248.             path = path||'/PGP'
  249.             Return path
  250.         End
  251.         Else Return ""
  252.     End
  253. End
  254.