Changeset 9ceee9d


Ignore:
Timestamp:
Jul 4, 2003, 12:26:03 AM (21 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
3ba3af0
Parents:
5b85d19
Message:
There is now a zcrypt command
Replies to zcrypted messages now work
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r5b85d19 r9ceee9d  
    332.0.7-pre-2
    44        Don't allow zwrite if zephyr isn't present
     5        There is now a zcrypt command
     6        Replies to zcrypted messages now work
    57       
    682.0.7-pre-1
  • commands.c

    r5b85d19 r9ceee9d  
    127127              "Send an aim message to a user.\n"),
    128128
    129   /*
    130129  OWLCMD_ARGS("zcrypt", owl_command_zcrypt, OWL_CTX_INTERACTIVE,
    131130              "send an encrypted zephyr",
     
    133132              "Behaves like zwrite but uses encryption.  Not for use with\n"
    134133              "personal messages\n"),
    135   */
    136134 
    137135  OWLCMD_ARGS("reply", owl_command_reply,  OWL_CTX_INTERACTIVE,
     
    16601658char *owl_command_zcrypt(int argc, char **argv, char *buff)
    16611659{
     1660#ifdef OWL_ENABLE_ZCRYPT
    16621661  owl_zwrite z;
    16631662
    1664   /* check for a zwrite -m */
     1663  if (!owl_global_is_havezephyr(&g)) {
     1664    owl_function_makemsg("Zephyr is not available");
     1665    return(NULL);
     1666  }
     1667  /* check for a zcrypt -m */
    16651668  owl_zwrite_create_from_line(&z, buff);
    16661669  if (owl_zwrite_is_message_set(&z)) {
    1667     owl_zwrite_send_message(&z);
    1668     owl_function_make_outgoing_zephyr(owl_zwrite_get_message(&z), buff, owl_zwrite_get_zsig(&z));
     1670    owl_function_zcrypt(buff, NULL);
    16691671    owl_zwrite_free(&z);
    16701672    return (NULL);
     
    16771679  }
    16781680  return(NULL);
     1681#else
     1682  owl_function_makemsg("This Owl does not support zcrypt");
     1683#endif
    16791684}
    16801685
  • functions.c

    r5b85d19 r9ceee9d  
    255255}
    256256
    257 
    258 
    259 void owl_function_zcrypt_setup(char *line)
    260 {
    261   owl_editwin *e;
    262   char buff[1024];
    263   owl_zwrite z;
    264   int ret;
    265 
    266   /* check the arguments */
    267   ret=owl_zwrite_create_from_line(&z, line);
    268   if (ret) {
    269     owl_function_makemsg("Error in zwrite arugments");
    270     owl_zwrite_free(&z);
    271     return;
    272   }
    273 
    274   if (owl_zwrite_get_numrecips(&z)>0) {
    275     owl_function_makemsg("You may not specifiy a recipient for a zcrypt message");
    276     owl_zwrite_free(&z);
    277     return;
    278   }
    279 
    280   /* send a ping if necessary */
    281   if (owl_global_is_txping(&g)) {
    282     owl_zwrite_send_ping(&z);
    283   }
    284   owl_zwrite_free(&z);
    285 
    286   /* create and setup the editwin */
    287   e=owl_global_get_typwin(&g);
    288   owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE, owl_global_get_msg_history(&g));
    289 
    290   if (!owl_global_get_lockout_ctrld(&g)) {
    291     owl_function_makemsg("Type your zephyr below.  End with ^D or a dot on a line by itself.  ^C will quit.");
    292   } else {
    293     owl_function_makemsg("Type your zephyr below.  End with a dot on a line by itself.  ^C will quit.");
    294   }
    295 
    296   owl_editwin_clear(e);
    297   owl_editwin_set_dotsend(e);
    298   strcpy(buff, "----> ");
    299   strcat(buff, line);
    300   strcat(buff, "\n");
    301   owl_editwin_set_locktext(e, buff);
    302 
    303   /* make it active */
    304   owl_global_set_typwin_active(&g);
    305 
    306   owl_global_set_buffercommand(&g, line);
    307 }
    308 
    309257/* send, log and display an outgoing zephyr.  If 'msg' is NULL
    310258 * the message is expected to be set from the zwrite line itself
     
    341289
    342290  /* free the zwrite */
     291  owl_zwrite_free(&z);
     292}
     293
     294/* send, log and display an outgoing zcrypt zephyr.  If 'msg' is NULL
     295 * the message is expected to be set from the zwrite line itself
     296 */
     297void owl_function_zcrypt(char *line, char *msg)
     298{
     299  owl_zwrite z;
     300  int i, j, ret;
     301  char *mymsg;
     302  char *cryptmsg;
     303
     304  /* create the zwrite and send the message */
     305  owl_zwrite_create_from_line(&z, line);
     306  if (msg) {
     307    owl_zwrite_set_message(&z, msg);
     308  }
     309
     310  mymsg=owl_zwrite_get_message(&z);
     311#ifdef OWL_ENABLE_ZCRYPT
     312  cryptmsg=owl_malloc(strlen(mymsg)*4);
     313  ret=owl_zcrypt_encrypt(cryptmsg, mymsg, owl_zwrite_get_class(&z), owl_zwrite_get_instance(&z));
     314  if (ret) {
     315    owl_function_makemsg("Error in zcrypt, possibly no key found.  Message not sent.");
     316    owl_function_beep();
     317    owl_free(cryptmsg);
     318    return;
     319  }
     320#else
     321  cryptmsg=owl_strdup(mymsg);
     322#endif
     323
     324  owl_zwrite_set_message(&z, cryptmsg);
     325  owl_zwrite_set_opcode(&z, "crypt");
     326  mymsg=cryptmsg;
     327   
     328  owl_zwrite_send_message(&z);
     329  owl_function_makemsg("Waiting for ack...");
     330
     331  /* display the message as an outgoing message in the receive window */
     332  if (owl_global_is_displayoutgoing(&g) && owl_zwrite_is_personal(&z)) {
     333    owl_function_make_outgoing_zephyr(mymsg, line, owl_zwrite_get_zsig(&z));
     334  }
     335
     336  /* log it if we have logging turned on */
     337  if (owl_global_is_logging(&g) && owl_zwrite_is_personal(&z)) {
     338    j=owl_zwrite_get_numrecips(&z);
     339    for (i=0; i<j; i++) {
     340      owl_log_outgoing_zephyr(owl_zwrite_get_recip_n(&z, i), mymsg);
     341    }
     342  }
     343
     344  /* free the zwrite */
     345  owl_free(cryptmsg);
    343346  owl_zwrite_free(&z);
    344347}
     
    10871090  if (!strncmp(buff, "zwrite ", 7)) {
    10881091    owl_function_zwrite(buff, owl_editwin_get_text(owl_global_get_typwin(&g)));
     1092  } else if (!strncmp(buff, "zcrypt ", 7)) {
     1093    owl_function_zcrypt(buff, owl_editwin_get_text(owl_global_get_typwin(&g)));
    10891094  } else if (!strncmp(buff, "aimwrite ", 9)) {
    10901095    owl_function_aimwrite(buff+9);
     
    17741779    /* zephyr */
    17751780    if (owl_message_is_type_zephyr(m)) {
    1776       /* for now we disable replies to zcrypt messages, since we can't
    1777          support an encrypted reply */
    1778       if (!strcasecmp(owl_message_get_opcode(m), "crypt")) {
    1779         owl_function_makemsg("Replies to zcrypt messages are not enabled in this release");
    1780         return;
    1781       }
    1782 
    17831781      /* if it's a zephyr we sent, send it out the same way again */
    17841782      if (owl_message_is_direction_out(m)) {
     
    18241822       
    18251823      /* create the command line */
    1826       buff = owl_strdup("zwrite");
     1824      if (!strcasecmp(owl_message_get_opcode(m), "CRYPT")) {
     1825        buff=owl_strdup("zcrypt");
     1826      } else {
     1827        buff = owl_strdup("zwrite");
     1828      }
    18271829      if (strcasecmp(class, "message")) {
    18281830        buff = owl_sprintf("%s -c %s%s%s", oldbuff=buff, owl_getquoting(class), class, owl_getquoting(class));
  • message.c

    r09489b89 r9ceee9d  
    699699
    700700    out=owl_malloc(strlen(owl_message_get_body(m))*16+20);
    701     ret=zcrypt_decrypt(out, owl_message_get_body(m), owl_message_get_class(m), owl_message_get_instance(m));
     701    ret=owl_zcrypt_decrypt(out, owl_message_get_body(m), owl_message_get_class(m), owl_message_get_instance(m));
    702702    if (ret==0) {
    703703      owl_message_set_body(m, out);
     
    743743  owl_message_set_class(m, owl_zwrite_get_class(&z));
    744744  owl_message_set_instance(m, owl_zwrite_get_instance(&z));
    745   owl_message_set_recipient(m,
    746                             long_zuser(owl_zwrite_get_recip_n(&z, 0))); /* only gets the first user, must fix */
     745  if (owl_zwrite_get_numrecips(&z)>0) {
     746    owl_message_set_recipient(m,
     747                              long_zuser(owl_zwrite_get_recip_n(&z, 0))); /* only gets the first user, must fix */
     748  }
    747749  owl_message_set_opcode(m, owl_zwrite_get_opcode(&z));
    748750  owl_message_set_realm(m, owl_zwrite_get_realm(&z)); /* also a hack, but not here */
  • zcrypt.c

    r09489b89 r9ceee9d  
    267267}
    268268
    269 int zcrypt_decrypt(char *out, char *in, char *class, char *instance) {
    270   /* written by kretch for owl. */
    271   /* return 0 on success, otherwise -1 */
     269/* The 'owl_zcrypt_decrypt' function was written by kretch for Owl.
     270 * Decrypt the message in 'in' on class 'class' and instance
     271 * 'instance' and leave the result in 'out'.  Out must be a buffer
     272 * allocated by the caller.
     273 *
     274 * return 0 on success, otherwise -1
     275 */
     276int owl_zcrypt_decrypt(char *out, char *in, char *class, char *instance) {
    272277  char *fname, keystring[MAX_KEY], *inptr, *endptr;
    273278  FILE *fkey;
     
    278283 
    279284  fname=GetZephyrVarKeyFile("zcrypt", class, instance);
     285  if (!fname) return(-1);
    280286  fkey=fopen(fname, "r");
    281287  if (!fkey) return(-1);
     
    314320}
    315321
    316 int zcrypt_encrypt(char *out, char *in, char *class, char *instance) {
     322int owl_zcrypt_encrypt(char *out, char *in, char *class, char *instance) {
     323  /*  static int do_encrypt(char *keystring, int zephyr, char *class, char *instance, ZWRITEOPTIONS *zoptions, char* keyfile) { */
     324  char *fname, keystring[MAX_KEY];
     325  FILE *fkey;
     326  des_cblock key;
     327  des_key_schedule schedule;
     328  char input[8], output[8];
     329  int size, length, i;
     330  char *inbuff = NULL, *inptr;
     331  int use_buffer = FALSE;
     332  int num_blocks=0, last_block_size=0;
     333
     334  fname=GetZephyrVarKeyFile("zcrypt", class, instance);
     335  if (!fname) return(-1);
     336  fkey=fopen(fname, "r");
     337  if (!fkey) return(-1);
     338  fgets(keystring, MAX_KEY-1, fkey);
     339  fclose(fkey);
     340
     341  des_string_to_key(keystring, key);
     342  des_key_sched(key, schedule);
     343
     344  inbuff=in;
     345  length=strlen(inbuff);
     346  num_blocks=(length+7)/8;
     347  last_block_size=((length+7)%8)+1;
     348  use_buffer=TRUE;
     349
     350  strcpy(out, "");
     351 
     352  inptr=inbuff;
     353  while (TRUE) {
     354    /* Get 8 bytes from buffer */
     355    if (num_blocks > 1) {
     356      size = 8;
     357      memcpy(input, inptr, size);
     358      inptr+=8;
     359      num_blocks--;
     360    } else if (num_blocks == 1) {
     361      size=last_block_size;
     362      memcpy(input, inptr, size);
     363      num_blocks--;
     364    } else {
     365      size=0;
     366    }
     367
     368    /* Check for EOF and pad the string to 8 chars, if needed */
     369    if (size == 0) break;     /* END OF INPUT: BREAK FROM while LOOP! */
     370     
     371    if (size<8) memset(input + size, 0, 8 - size);
     372
     373    /* Encrypt and output the block */
     374    des_ecb_encrypt(input, output, schedule, TRUE);
     375
     376    for (i = 0; i < 8; i++) {
     377      sprintf(out, "%s%c", out, ((output[i] & 0xf0) >> 4) + BASE_CODE);
     378      sprintf(out, "%s%c", out, (output[i] & 0x0f)        + BASE_CODE);
     379    }
     380
     381    if (size < 8) break;
     382  }
    317383  return(0);
    318384}
     
    367433  /* Determine names to look for in .crypt-table */
    368434  if (instance) {
    369     sprintf(varname[numsearch++], "crypt-%s-%s:", (class?class:"message"),
    370             instance);
     435    sprintf(varname[numsearch++], "crypt-%s-%s:", (class?class:"message"), instance);
    371436  }
    372437  if (class) {
     
    413478
    414479    if (keyfile == NULL) {
    415       printf("Could not find key table entry.\n");
     480      /* printf("Could not find key table entry.\n"); */
    416481    } else {
    417482      /* Prepare result to be returned */
     
    421486        strcpy(keyfile, temp);
    422487      } else {
    423         printf("Memory allocation error.\n");
     488        /* printf("Memory allocation error.\n"); */
    424489      }
    425490    }
     
    427492    fclose(fsearch);
    428493  } else {
    429     printf("Could not open key table file: %s\n", filename);
     494    /* printf("Could not open key table file: %s\n", filename); */
    430495  }
    431496
  • zwrite.c

    r09489b89 r9ceee9d  
    306306}
    307307
     308void owl_zwrite_set_opcode(owl_zwrite *z, char *opcode)
     309{
     310  if (z->opcode) owl_free(z->opcode);
     311  z->opcode=owl_strdup(opcode);
     312}
     313
    308314char *owl_zwrite_get_realm(owl_zwrite *z)
    309315{
Note: See TracChangeset for help on using the changeset viewer.