home *** CD-ROM | disk | FTP | other *** search
- /*
- * doPGP.ced
- *
- * $VER: Rick Younie 27 July 1994 Wednesday
- *
- * please send comments, questions or improvements:
- * rick@emma.panam.wimsey.com
- * rick@freenet.vancouver.bc.ca (faster)
- *
- * SYNOPSIS:
- * {de/en}crypt the mail message in CED with PGP
- * - bring up a requester to choose the recipient's public key
- * - add my public key at the end of the message
- *
- DOCS
- ----
- This script interfaces PGP and Cygnus Ed. I use it with AmigaElm to
- encrypt and decrypt PGP messages. Make sure it is in your REXX:
- directory and the script bit is set.
-
- Note: be sure to set the following variables under the 'constants
- and assigns' heading.
-
- keyFile - the name of your key in ascii format. This is appended
- to outgoing messages.
- pgp - the path and name of the PGP binary
-
-
- decrypt
- - send 'doPGP -d' with Cygnus Ed's Send Dos/ARexx command menu
- item. The first paragraph in CED is assumed to be the message
- header and is skipped. The rest of the message is cut to a temp
- file and passed to PGP. PGP does its magic and the result is
- pasted back into CED. If there is a key appended to the message,
- you are asked if you want to add it to your key file.
-
- encrypt
- - send 'doPGP -e'. The CED view must start with 'To: ' and the
- first paragraph is assumed to be the outgoing message header and
- is skipped. The body of the message is cut to a temp file and
- passed to PGP to encrypt, then pasted back. Your key file is
- added to the end of the message.
- */
-
- signal on NOVALUE
- signal on SYNTAX
- signal on BREAK_C
- signal on HALT
-
- /* -------------------------------------------------------------------
- * constants and assigns
- */
-
- lf = '0a'x
- tmpFile = 't:'pragma('ID')'doPGP' /* make a unique name */
-
- pgp = 'uucp:bin/pgp' /* path & filename of PGP binary */
- keyFile = 'PGP:keys/rick.asc' /* my public key */
-
- /* -------------------------------------------------------------------
- */
- Main:
- address 'rexx_ced'
- options Results
-
- /* parse input */
- select
- when arg(1) = '-e' then call Encrypt
- when arg(1) = '-d' then call Decrypt
- otherwise call Usage
- end
- exit
-
- /* -------------------------------------------------------------------
- *
- */
- Decrypt:
- call NewSTD /* reassign stdin, stdout */
- call BodyToTmp /* cut the message body and save it*/
- address 'COMMAND' pgp tmpFile '-o'tmpFile'.dec' /* decrypt it */
- 'include file' tmpFile'.dec' /* load it back into CED */
- address 'COMMAND' 'delete' tmpfile'*' /* cleanup */
- return
-
-
- /* -------------------------------------------------------------------
- *
- */
- Encrypt:
- call IsMsg /* really mail message? */
- call NewSTD /* reassign stdin, stdout */
- recip = CheckRecip() /* selected the right persons key? */
- call BodyToTmp /* cut the message body and save it*/
- address 'COMMAND' pgp '-ea' tmpFile recip /* encrypt that body */
- 'include file' tmpFile'.asc' /* load it back into CED */
- address 'COMMAND' 'delete' tmpFile'*' /* cleanup */
- call AppendKey /* add my key */
- return
-
- /* -------------------------------------------------------------------
- * append my key to encrypted message
- */
- AppendKey:
- 'end of file'
- 'return'
- 'include file' keyFile
- return
-
- /* -------------------------------------------------------------------
- * cut the message body to temp file
- */
- BodyToTmp:
- 'beg of file'
- 'search for' '"'lf || lf'"'
- 'beg of line'
- 'down'
- 'down'
- 'mark block'
- 'end of file'
- 'cut block'
- 'save block to file' tmpFile 1
- return
-
-
- /* -------------------------------------------------------------------
- * open a window on CED for pgp output/input
- */
- NewSTD:
- call close 'STDOUT'
- call close 'STDIN'
- call open 'STDOUT', 'CON:10/120/630/100/CED/SCREEN CygnusEdScreen1'
- call pragma '*','STDOUT'
- call open 'STDIN','*'
- return
-
-
- /* -------------------------------------------------------------------
- * make sure the recipient exists in keyfile and is the right one
- */
- CheckRecip: PROCEDURE EXPOSE pgp
-
- do forever
- options prompt "Enter recipient's name: "
- parse pull recip
-
- address 'COMMAND' pgp '-kv' recip
-
- /* error return from pgp - couldn''t find key for this guy */
- if RC > 0 then do
- say '..couldn''t find "'recip'" in keyfile.'
- options prompt "Try another? Y/q "
- pull ans
- if ans = 'Q' then call ErX '..user aborted'
- end
-
- /* found a key - the right one? */
- else do
- options prompt "Is this the right guy? Y/n/q "
- pull ans
- select
- when ans = 'Y' | ans = '' then leave
- when ans = 'Q' then call ErX '..user aborted'
- otherwise nop
- end /* select */
- end /* else */
-
- end /* forever */
-
- return recip
-
- /* -------------------------------------------------------------------
- * only attempt encrypt if 1st line begins with 'To:'
- */
- IsMsg:
- /* check that first word is 'To:' */
- 'beg of file'
- 'status 55'
- if ~abbrev(result,'To:') then
- call ErX '..file in CED must start with To:'
- return
-
- /* ----------------------------------------------------------------------
- */
- ErX:
- 'okay1' arg(1)
- exit
-
- /* ----------------------------------------------------------------------
- * minimal traps
- */
- NOVALUE: errtype = 'NOVALUE'
- SYNTAX: if symbol('errtype') = 'LIT' then errtype = 'SYNTAX'
- call ErX errtype 'error in doPGP; maybe line' SIGL'; maybe RC' RC
- HALT:
- BREAK_C:
- exit
-
- /* -------------------------------------------------------------------
- * in case program is invoked from cli
- */
- Usage:
- say 'Usage: dopgp [-e | -d] - encrypt | decrypt - use only in CED'
- exit
-