- Timestamp:
- 2011-12-17T13:50:01Z (13 years ago)
- Branches:
- master
- Children:
- 18c6d36
- Parents:
- 87dddee (diff), 17f057d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
otr.c
r87dddee r6e9ae72 8 8 OTR support (cf. http://www.cypherpunks.ca/otr/) 9 9 10 (c) 2008-201 0Sven Moritz Hallberg <pesco@khjk.org>10 (c) 2008-2011 Sven Moritz Hallberg <pesco@khjk.org> 11 11 (c) 2008 funded by stonedcoder.org 12 12 … … 163 163 const char *secret); 164 164 165 /* update flags within the irc_user structure to reflect OTR status of context */ 166 void otr_update_uflags(ConnContext *context, irc_user_t *u); 167 165 168 /* update op/voice flag of given user according to encryption state and settings 166 169 returns 0 if neither op_buddies nor voice_buddies is set to "encrypted", … … 182 185 /* find a private key by fingerprint prefix (given as any number of hex strings) */ 183 186 OtrlPrivKey *match_privkey(irc_t *irc, const char **args); 187 188 /* check whether a string is safe to use in a path component */ 189 int strsane(const char *s); 184 190 185 191 /* functions to be called for certain events */ … … 237 243 l = g_slist_prepend( l, "always" ); 238 244 s->eval_data = l; 245 246 s = set_add( &irc->b->set, "otr_does_html", "true", set_eval_bool, irc ); 239 247 240 248 return TRUE; … … 270 278 int kg=0; 271 279 272 g_snprintf(s, 511, "%s%s.otr_keys", global.conf->configdir, irc->user->nick); 273 e = otrl_privkey_read(irc->otr->us, s); 274 if(e && e!=enoent) { 275 irc_usermsg(irc, "otr load: %s: %s", s, gcry_strerror(e)); 276 } 277 g_snprintf(s, 511, "%s%s.otr_fprints", global.conf->configdir, irc->user->nick); 278 e = otrl_privkey_read_fingerprints(irc->otr->us, s, NULL, NULL); 279 if(e && e!=enoent) { 280 irc_usermsg(irc, "otr load: %s: %s", s, gcry_strerror(e)); 280 if(strsane(irc->user->nick)) { 281 g_snprintf(s, 511, "%s%s.otr_keys", global.conf->configdir, irc->user->nick); 282 e = otrl_privkey_read(irc->otr->us, s); 283 if(e && e!=enoent) { 284 irc_rootmsg(irc, "otr load: %s: %s", s, gcry_strerror(e)); 285 } 286 g_snprintf(s, 511, "%s%s.otr_fprints", global.conf->configdir, irc->user->nick); 287 e = otrl_privkey_read_fingerprints(irc->otr->us, s, NULL, NULL); 288 if(e && e!=enoent) { 289 irc_rootmsg(irc, "otr load: %s: %s", s, gcry_strerror(e)); 290 } 281 291 } 282 292 … … 286 296 } 287 297 if(kg) { 288 irc_ usermsg(irc, "Notice: "298 irc_rootmsg(irc, "Notice: " 289 299 "The accounts above do not have OTR encryption keys associated with them, yet. " 290 300 "These keys are now being generated in the background. " … … 301 311 gcry_error_t e; 302 312 303 g_snprintf(s, 511, "%s%s.otr_fprints", global.conf->configdir, irc->user->nick); 304 e = otrl_privkey_write_fingerprints(irc->otr->us, s); 305 if(e) { 306 irc_usermsg(irc, "otr save: %s: %s", s, gcry_strerror(e)); 307 } 308 chmod(s, 0600); 313 if(strsane(irc->user->nick)) { 314 g_snprintf(s, 511, "%s%s.otr_fprints", global.conf->configdir, irc->user->nick); 315 e = otrl_privkey_write_fingerprints(irc->otr->us, s); 316 if(e) { 317 irc_rootmsg(irc, "otr save: %s: %s", s, gcry_strerror(e)); 318 } 319 chmod(s, 0600); 320 } 309 321 } 310 322 … … 313 325 char s[512]; 314 326 315 g_snprintf(s, 511, "%s%s.otr_keys", global.conf->configdir, nick); 316 unlink(s); 317 g_snprintf(s, 511, "%s%s.otr_fprints", global.conf->configdir, nick); 318 unlink(s); 327 if(strsane(nick)) { 328 g_snprintf(s, 511, "%s%s.otr_keys", global.conf->configdir, nick); 329 unlink(s); 330 g_snprintf(s, 511, "%s%s.otr_fprints", global.conf->configdir, nick); 331 unlink(s); 332 } 319 333 } 320 334 … … 323 337 char s[512], t[512]; 324 338 325 g_snprintf(s, 511, "%s%s.otr_keys", global.conf->configdir, onick); 326 g_snprintf(t, 511, "%s%s.otr_keys", global.conf->configdir, nnick); 327 rename(s,t); 328 g_snprintf(s, 511, "%s%s.otr_fprints", global.conf->configdir, onick); 329 g_snprintf(t, 511, "%s%s.otr_fprints", global.conf->configdir, nnick); 330 rename(s,t); 339 if(strsane(nnick) && strsane(onick)) { 340 g_snprintf(s, 511, "%s%s.otr_keys", global.conf->configdir, onick); 341 g_snprintf(t, 511, "%s%s.otr_keys", global.conf->configdir, nnick); 342 rename(s,t); 343 g_snprintf(s, 511, "%s%s.otr_fprints", global.conf->configdir, onick); 344 g_snprintf(t, 511, "%s%s.otr_fprints", global.conf->configdir, nnick); 345 rename(s,t); 346 } 331 347 } 332 348 … … 343 359 k = otrl_privkey_find(irc->otr->us, a->user, a->prpl->name); 344 360 if(k) { 345 irc_ usermsg(irc, "otr: %s/%s ready", a->user, a->prpl->name);361 irc_rootmsg(irc, "otr: %s/%s ready", a->user, a->prpl->name); 346 362 return 0; 347 363 } if(keygen_in_progress(irc, a->user, a->prpl->name)) { 348 irc_ usermsg(irc, "otr: keygen for %s/%s already in progress", a->user, a->prpl->name);364 irc_rootmsg(irc, "otr: keygen for %s/%s already in progress", a->user, a->prpl->name); 349 365 return 0; 350 366 } else { 351 irc_ usermsg(irc, "otr: starting background keygen for %s/%s", a->user, a->prpl->name);367 irc_rootmsg(irc, "otr: starting background keygen for %s/%s", a->user, a->prpl->name); 352 368 otr_keygen(irc, a->user, a->prpl->name); 353 369 return 1; … … 360 376 char *newmsg = NULL; 361 377 OtrlTLV *tlvs = NULL; 362 char *colormsg;363 378 irc_t *irc = iu->irc; 364 379 struct im_connection *ic = iu->bu->ic; … … 380 395 } else if(!newmsg) { 381 396 /* this was a non-OTR message */ 382 return g_strdup(msg);397 return msg; 383 398 } else { 384 399 /* OTR has processed this message */ 385 400 ConnContext *context = otrl_context_find(irc->otr->us, iu->bu->handle, 386 401 ic->acc->user, ic->acc->prpl->name, 0, NULL, NULL, NULL); 387 if(context && context->msgstate == OTRL_MSGSTATE_ENCRYPTED && 388 set_getbool(&ic->bee->set, "otr_color_encrypted")) { 389 /* color according to f'print trust */ 390 int color; 391 const char *trust = context->active_fingerprint->trust; 392 if(trust && trust[0] != '\0') 393 color=3; /* green */ 394 else 395 color=5; /* red */ 396 397 if(newmsg[0] == ',') { 398 /* could be a problem with the color code */ 399 /* insert a space between color spec and message */ 400 colormsg = g_strdup_printf("\x03%.2d %s\x0F", color, newmsg); 401 } else { 402 colormsg = g_strdup_printf("\x03%.2d%s\x0F", color, newmsg); 402 403 /* we're done with the original msg, which will be caller-freed. */ 404 /* NB: must not change the newmsg pointer, since we free it. */ 405 msg = newmsg; 406 407 if(context && context->msgstate == OTRL_MSGSTATE_ENCRYPTED) { 408 /* HTML decoding */ 409 /* perform any necessary stripping that the top level would miss */ 410 if(set_getbool(&ic->bee->set, "otr_does_html") && 411 !(ic->flags & OPT_DOES_HTML) && 412 set_getbool(&ic->bee->set, "strip_html")) { 413 strip_html(msg); 403 414 } 404 } else { 405 colormsg = g_strdup(newmsg); 415 416 /* coloring */ 417 if(set_getbool(&ic->bee->set, "otr_color_encrypted")) { 418 int color; /* color according to f'print trust */ 419 char *pre="", *sep=""; /* optional parts */ 420 const char *trust = context->active_fingerprint->trust; 421 422 if(trust && trust[0] != '\0') 423 color=3; /* green */ 424 else 425 color=5; /* red */ 426 427 /* in a query window, keep "/me " uncolored at the beginning */ 428 if(g_strncasecmp(msg, "/me ", 4) == 0 429 && irc_user_msgdest(iu) == irc->user->nick) { 430 msg += 4; /* skip */ 431 pre = "/me "; 432 } 433 434 /* comma in first place could mess with the color code */ 435 if(msg[0] == ',') { 436 /* insert a space between color spec and message */ 437 sep = " "; 438 } 439 440 msg = g_strdup_printf("%s\x03%.2d%s%s\x0F", pre, 441 color, sep, msg); 442 } 443 } 444 445 if(msg == newmsg) { 446 msg = g_strdup(newmsg); 406 447 } 407 448 otrl_message_free(newmsg); 408 return colormsg;449 return msg; 409 450 } 410 451 } … … 414 455 int st; 415 456 char *otrmsg = NULL; 457 char *emsg = msg; /* the message as we hand it to libotr */ 416 458 ConnContext *ctx = NULL; 417 459 irc_t *irc = iu->irc; … … 422 464 return msg; 423 465 } 424 425 st = otrl_message_sending(irc->otr->us, &otr_ops, ic,426 ic->acc->user, ic->acc->prpl->name, iu->bu->handle,427 msg, NULL, &otrmsg, NULL, NULL);428 if(st) {429 return NULL;430 }431 466 432 467 ctx = otrl_context_find(irc->otr->us, 433 468 iu->bu->handle, ic->acc->user, ic->acc->prpl->name, 434 469 1, NULL, NULL, NULL); 470 471 /* HTML encoding */ 472 /* consider OTR plaintext to be HTML if otr_does_html is set */ 473 if(ctx && ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED && 474 set_getbool(&ic->bee->set, "otr_does_html") && 475 (g_strncasecmp(msg, "<html>", 6) != 0)) { 476 emsg = escape_html(msg); 477 } 478 479 st = otrl_message_sending(irc->otr->us, &otr_ops, ic, 480 ic->acc->user, ic->acc->prpl->name, iu->bu->handle, 481 emsg, NULL, &otrmsg, NULL, NULL); 482 if(emsg != msg) { 483 g_free(emsg); /* we're done with this one */ 484 } 485 if(st) { 486 return NULL; 487 } 435 488 436 489 if(otrmsg) { … … 480 533 481 534 if(!cmd->command) { 482 irc_ usermsg(irc, "%s: unknown subcommand \"%s\", see \x02help otr\x02",535 irc_rootmsg(irc, "%s: unknown subcommand \"%s\", see \x02help otr\x02", 483 536 args[0], args[1]); 484 537 return; … … 486 539 487 540 if(!args[cmd->required_parameters+1]) { 488 irc_ usermsg(irc, "%s %s: not enough arguments (%d req.)",541 irc_rootmsg(irc, "%s %s: not enough arguments (%d req.)", 489 542 args[0], args[1], cmd->required_parameters); 490 543 return; … … 558 611 if (strcmp(accountname, recipient) == 0) { 559 612 /* huh? injecting messages to myself? */ 560 irc_ usermsg(irc, "note to self: %s", message);613 irc_rootmsg(irc, "note to self: %s", message); 561 614 } else { 562 615 /* need to drop some consts here :-( */ … … 573 626 char *msg = g_strdup(message); 574 627 irc_t *irc = ic->bee->ui_data; 628 irc_user_t *u = peeruser(irc, username, protocol); 575 629 576 630 strip_html(msg); 577 irc_usermsg(irc, "otr: %s", msg); 631 if(u) { 632 /* display as a notice from this particular user */ 633 irc_usernotice(u, "%s", msg); 634 } else { 635 irc_rootmsg(irc, "[otr] %s", msg); 636 } 578 637 579 638 g_free(msg); … … 587 646 struct im_connection *ic = check_imc(opdata, accountname, protocol); 588 647 irc_t *irc = ic->bee->ui_data; 648 irc_user_t *u = peeruser(irc, username, protocol); 589 649 char hunam[45]; /* anybody looking? ;-) */ 590 650 591 651 otrl_privkey_hash_to_human(hunam, fingerprint); 592 irc_usermsg(irc, "new fingerprint for %s: %s", 593 peernick(irc, username, protocol), hunam); 652 if(u) { 653 irc_usernotice(u, "new fingerprint: %s", hunam); 654 } else { 655 /* this case shouldn't normally happen */ 656 irc_rootmsg(irc, "new fingerprint for %s/%s: %s", 657 username, protocol, hunam); 658 } 594 659 } 595 660 … … 608 673 irc_user_t *u; 609 674 irc_t *irc = ic->bee->ui_data; 610 const char *trust;611 675 612 676 u = peeruser(irc, context->username, context->protocol); … … 618 682 } 619 683 620 trust = context->active_fingerprint->trust; 621 if(trust && trust[0]) 622 u->flags |= IRC_USER_OTR_ENCRYPTED | IRC_USER_OTR_TRUSTED; 623 else 624 u->flags = ( u->flags & ~IRC_USER_OTR_TRUSTED ) | IRC_USER_OTR_ENCRYPTED; 625 if(!otr_update_modeflags(irc, u)) 626 irc_usermsg(irc, "conversation with %s is now off the record", u->nick); 684 otr_update_uflags(context, u); 685 if(!otr_update_modeflags(irc, u)) { 686 char *trust = u->flags & IRC_USER_OTR_TRUSTED ? "trusted" : "untrusted!"; 687 irc_usernotice(u, "conversation is now off the record (%s)", trust); 688 } 627 689 } 628 690 … … 641 703 return; 642 704 } 643 u->flags &= ~( IRC_USER_OTR_ENCRYPTED | IRC_USER_OTR_TRUSTED);705 otr_update_uflags(context, u); 644 706 if(!otr_update_modeflags(irc, u)) 645 irc_user msg(irc, "conversation with %s is now in the clear", u->nick);707 irc_usernotice(u, "conversation is now in cleartext"); 646 708 } 647 709 … … 660 722 return; 661 723 } 662 if(context->active_fingerprint->trust[0]) 663 u->flags |= IRC_USER_OTR_ENCRYPTED | IRC_USER_OTR_TRUSTED;664 else665 u->flags = ( u->flags & ~IRC_USER_OTR_TRUSTED ) | IRC_USER_OTR_ENCRYPTED;666 if(!otr_update_modeflags(irc, u))667 irc_usermsg(irc, "otr connection with %s has been refreshed", u->nick);724 725 otr_update_uflags(context, u); 726 if(!otr_update_modeflags(irc, u)) { 727 char *trust = u->flags & IRC_USER_OTR_TRUSTED ? "trusted" : "untrusted!"; 728 irc_usernotice(u, "otr connection has been refreshed (%s)", trust); 729 } 668 730 } 669 731 … … 708 770 u = irc_user_by_name(irc, args[1]); 709 771 if(!u || !u->bu || !u->bu->ic) { 710 irc_ usermsg(irc, "%s: unknown user", args[1]);772 irc_rootmsg(irc, "%s: unknown user", args[1]); 711 773 return; 712 774 } … … 733 795 u = irc_user_by_name(irc, args[1]); 734 796 if(!u || !u->bu || !u->bu->ic) { 735 irc_ usermsg(irc, "%s: unknown user", args[1]);797 irc_rootmsg(irc, "%s: unknown user", args[1]); 736 798 return; 737 799 } 738 800 if(!(u->bu->flags & BEE_USER_ONLINE)) { 739 irc_ usermsg(irc, "%s is offline", args[1]);801 irc_rootmsg(irc, "%s is offline", args[1]); 740 802 return; 741 803 } … … 764 826 u = irc_user_by_name(irc, args[1]); 765 827 if(!u || !u->bu || !u->bu->ic) { 766 irc_ usermsg(irc, "%s: unknown user", args[1]);828 irc_rootmsg(irc, "%s: unknown user", args[1]); 767 829 return; 768 830 } … … 771 833 u->bu->ic->acc->user, u->bu->ic->acc->prpl->name, 0, NULL, NULL, NULL); 772 834 if(!ctx) { 773 irc_ usermsg(irc, "%s: no otr context with user", args[1]);835 irc_rootmsg(irc, "%s: no otr context with user", args[1]); 774 836 return; 775 837 } … … 783 845 784 846 if(!*p || !*q) { 785 irc_ usermsg(irc, "failed: truncated fingerprint block %d", i+1);847 irc_rootmsg(irc, "failed: truncated fingerprint block %d", i+1); 786 848 return; 787 849 } … … 790 852 y = hexval(*q); 791 853 if(x<0) { 792 irc_ usermsg(irc, "failed: %d. hex digit of block %d out of range", 2*j+1, i+1);854 irc_rootmsg(irc, "failed: %d. hex digit of block %d out of range", 2*j+1, i+1); 793 855 return; 794 856 } 795 857 if(y<0) { 796 irc_ usermsg(irc, "failed: %d. hex digit of block %d out of range", 2*j+2, i+1);858 irc_rootmsg(irc, "failed: %d. hex digit of block %d out of range", 2*j+2, i+1); 797 859 return; 798 860 } … … 803 865 fp = otrl_context_find_fingerprint(ctx, raw, 0, NULL); 804 866 if(!fp) { 805 irc_ usermsg(irc, "failed: no such fingerprint for %s", args[1]);867 irc_rootmsg(irc, "failed: no such fingerprint for %s", args[1]); 806 868 } else { 807 869 char *trust = args[7] ? args[7] : "affirmed"; 808 870 otrl_context_set_trust(fp, trust); 809 irc_ usermsg(irc, "fingerprint match, trust set to \"%s\"", trust);871 irc_rootmsg(irc, "fingerprint match, trust set to \"%s\"", trust); 810 872 if(u->flags & IRC_USER_OTR_ENCRYPTED) 811 873 u->flags |= IRC_USER_OTR_TRUSTED; … … 835 897 ctx = otrl_context_find(irc->otr->us, handle, myhandle, protocol, 0, NULL, NULL, NULL); 836 898 if(!ctx) { 837 irc_ usermsg(irc, "no such context");899 irc_rootmsg(irc, "no such context"); 838 900 g_free(arg); 839 901 return; … … 842 904 irc_user_t *u = irc_user_by_name(irc, args[1]); 843 905 if(!u || !u->bu || !u->bu->ic) { 844 irc_ usermsg(irc, "%s: unknown user", args[1]);906 irc_rootmsg(irc, "%s: unknown user", args[1]); 845 907 g_free(arg); 846 908 return; … … 849 911 u->bu->ic->acc->prpl->name, 0, NULL, NULL, NULL); 850 912 if(!ctx) { 851 irc_ usermsg(irc, "no otr context with %s", args[1]);913 irc_rootmsg(irc, "no otr context with %s", args[1]); 852 914 g_free(arg); 853 915 return; … … 857 919 /* show how we resolved the (nick) argument, if we did */ 858 920 if(handle!=arg) { 859 irc_ usermsg(irc, "%s is %s/%s; we are %s/%s to them", args[1],921 irc_rootmsg(irc, "%s is %s/%s; we are %s/%s to them", args[1], 860 922 ctx->username, ctx->protocol, ctx->accountname, ctx->protocol); 861 923 } … … 872 934 n = atoi(args[1]); 873 935 if(n<0 || (!n && strcmp(args[1], "0"))) { 874 irc_ usermsg(irc, "%s: invalid account number", args[1]);936 irc_rootmsg(irc, "%s: invalid account number", args[1]); 875 937 return; 876 938 } … … 879 941 for(i=0; i<n && a; i++, a=a->next); 880 942 if(!a) { 881 irc_ usermsg(irc, "%s: no such account", args[1]);943 irc_rootmsg(irc, "%s: no such account", args[1]); 882 944 return; 883 945 } 884 946 885 947 if(keygen_in_progress(irc, a->user, a->prpl->name)) { 886 irc_ usermsg(irc, "keygen for account %d already in progress", n);948 irc_rootmsg(irc, "keygen for account %d already in progress", n); 887 949 return; 888 950 } … … 906 968 907 969 if(fp == fp->context->active_fingerprint) { 908 irc_ usermsg(irc, "that fingerprint is active, terminate otr connection first");970 irc_rootmsg(irc, "that fingerprint is active, terminate otr connection first"); 909 971 return; 910 972 } … … 922 984 923 985 if(ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) { 924 irc_ usermsg(irc, "active otr connection with %s, terminate it first",986 irc_rootmsg(irc, "active otr connection with %s, terminate it first", 925 987 peernick(irc, ctx->username, ctx->protocol)); 926 988 return; … … 954 1016 955 1017 if(!args[3]) { 956 irc_ usermsg(irc, "otr %s %s: not enough arguments (2 req.)", args[0], args[1]);1018 irc_rootmsg(irc, "otr %s %s: not enough arguments (2 req.)", args[0], args[1]); 957 1019 return; 958 1020 } … … 961 1023 u = irc_user_by_name(irc, args[2]); 962 1024 if(!u || !u->bu || !u->bu->ic) { 963 irc_ usermsg(irc, "%s: unknown user", args[2]);1025 irc_rootmsg(irc, "%s: unknown user", args[2]); 964 1026 return; 965 1027 } … … 968 1030 u->bu->ic->acc->prpl->name, 0, NULL, NULL, NULL); 969 1031 if(!ctx) { 970 irc_ usermsg(irc, "no otr context with %s", args[2]);1032 irc_rootmsg(irc, "no otr context with %s", args[2]); 971 1033 return; 972 1034 } … … 979 1041 980 1042 if(fp == ctx->active_fingerprint) { 981 irc_ usermsg(irc, "that fingerprint is active, terminate otr connection first");1043 irc_rootmsg(irc, "that fingerprint is active, terminate otr connection first"); 982 1044 return; 983 1045 } … … 1004 1066 u = irc_user_by_name(irc, args[2]); 1005 1067 if(!u || !u->bu || !u->bu->ic) { 1006 irc_ usermsg(irc, "%s: unknown user", args[2]);1068 irc_rootmsg(irc, "%s: unknown user", args[2]); 1007 1069 return; 1008 1070 } … … 1011 1073 u->bu->ic->acc->prpl->name, 0, NULL, NULL, NULL); 1012 1074 if(!ctx) { 1013 irc_ usermsg(irc, "no otr context with %s", args[2]);1075 irc_rootmsg(irc, "no otr context with %s", args[2]); 1014 1076 return; 1015 1077 } 1016 1078 1017 1079 if(ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) { 1018 irc_ usermsg(irc, "active otr connection with %s, terminate it first", args[2]);1080 irc_rootmsg(irc, "active otr connection with %s, terminate it first", args[2]); 1019 1081 return; 1020 1082 } … … 1049 1111 else 1050 1112 { 1051 irc_ usermsg(irc, "otr %s: unknown subcommand \"%s\", see \x02help otr forget\x02",1113 irc_rootmsg(irc, "otr %s: unknown subcommand \"%s\", see \x02help otr forget\x02", 1052 1114 args[0], args[1]); 1053 1115 } … … 1075 1137 if(!context) { 1076 1138 /* huh? out of memory or what? */ 1077 irc_ usermsg(irc, "smp: failed to get otr context for %s", u->nick);1139 irc_rootmsg(irc, "smp: failed to get otr context for %s", u->nick); 1078 1140 otrl_message_abort_smp(us, ops, u->bu->ic, context); 1079 1141 otrl_sm_state_free(context->smstate); … … 1083 1145 1084 1146 if (context->smstate->sm_prog_state == OTRL_SMP_PROG_CHEATED) { 1085 irc_ usermsg(irc, "smp %s: opponent violated protocol, aborting",1147 irc_rootmsg(irc, "smp %s: opponent violated protocol, aborting", 1086 1148 u->nick); 1087 1149 otrl_message_abort_smp(us, ops, u->bu->ic, context); … … 1093 1155 if (tlv) { 1094 1156 if (nextMsg != OTRL_SMP_EXPECT1) { 1095 irc_ usermsg(irc, "smp %s: spurious SMP1Q received, aborting", u->nick);1157 irc_rootmsg(irc, "smp %s: spurious SMP1Q received, aborting", u->nick); 1096 1158 otrl_message_abort_smp(us, ops, u->bu->ic, context); 1097 1159 otrl_sm_state_free(context->smstate); 1098 1160 } else { 1099 1161 char *question = g_strndup((char *)tlv->data, tlv->len); 1100 irc_ usermsg(irc, "smp: initiated by %s with question: \x02\"%s\"\x02", u->nick,1162 irc_rootmsg(irc, "smp: initiated by %s with question: \x02\"%s\"\x02", u->nick, 1101 1163 question); 1102 irc_ usermsg(irc, "smp: respond with \x02otr smp %s <answer>\x02",1164 irc_rootmsg(irc, "smp: respond with \x02otr smp %s <answer>\x02", 1103 1165 u->nick); 1104 1166 g_free(question); … … 1109 1171 if (tlv) { 1110 1172 if (nextMsg != OTRL_SMP_EXPECT1) { 1111 irc_ usermsg(irc, "smp %s: spurious SMP1 received, aborting", u->nick);1173 irc_rootmsg(irc, "smp %s: spurious SMP1 received, aborting", u->nick); 1112 1174 otrl_message_abort_smp(us, ops, u->bu->ic, context); 1113 1175 otrl_sm_state_free(context->smstate); 1114 1176 } else { 1115 irc_ usermsg(irc, "smp: initiated by %s"1177 irc_rootmsg(irc, "smp: initiated by %s" 1116 1178 " - respond with \x02otr smp %s <secret>\x02", 1117 1179 u->nick, u->nick); … … 1122 1184 if (tlv) { 1123 1185 if (nextMsg != OTRL_SMP_EXPECT2) { 1124 irc_ usermsg(irc, "smp %s: spurious SMP2 received, aborting", u->nick);1186 irc_rootmsg(irc, "smp %s: spurious SMP2 received, aborting", u->nick); 1125 1187 otrl_message_abort_smp(us, ops, u->bu->ic, context); 1126 1188 otrl_sm_state_free(context->smstate); … … 1133 1195 if (tlv) { 1134 1196 if (nextMsg != OTRL_SMP_EXPECT3) { 1135 irc_ usermsg(irc, "smp %s: spurious SMP3 received, aborting", u->nick);1197 irc_rootmsg(irc, "smp %s: spurious SMP3 received, aborting", u->nick); 1136 1198 otrl_message_abort_smp(us, ops, u->bu->ic, context); 1137 1199 otrl_sm_state_free(context->smstate); … … 1140 1202 if(context->smstate->sm_prog_state == OTRL_SMP_PROG_SUCCEEDED) { 1141 1203 if(context->smstate->received_question) { 1142 irc_ usermsg(irc, "smp %s: correct answer, you are trusted",1204 irc_rootmsg(irc, "smp %s: correct answer, you are trusted", 1143 1205 u->nick); 1144 1206 } else { 1145 irc_ usermsg(irc, "smp %s: secrets proved equal, fingerprint trusted",1207 irc_rootmsg(irc, "smp %s: secrets proved equal, fingerprint trusted", 1146 1208 u->nick); 1147 1209 } 1148 1210 } else { 1149 1211 if(context->smstate->received_question) { 1150 irc_ usermsg(irc, "smp %s: wrong answer, you are not trusted",1212 irc_rootmsg(irc, "smp %s: wrong answer, you are not trusted", 1151 1213 u->nick); 1152 1214 } else { 1153 irc_ usermsg(irc, "smp %s: secrets did not match, fingerprint not trusted",1215 irc_rootmsg(irc, "smp %s: secrets did not match, fingerprint not trusted", 1154 1216 u->nick); 1155 1217 } … … 1162 1224 if (tlv) { 1163 1225 if (nextMsg != OTRL_SMP_EXPECT4) { 1164 irc_ usermsg(irc, "smp %s: spurious SMP4 received, aborting", u->nick);1226 irc_rootmsg(irc, "smp %s: spurious SMP4 received, aborting", u->nick); 1165 1227 otrl_message_abort_smp(us, ops, u->bu->ic, context); 1166 1228 otrl_sm_state_free(context->smstate); … … 1168 1230 /* SMP4 received, otrl_message_receiving will have set fp trust */ 1169 1231 if(context->smstate->sm_prog_state == OTRL_SMP_PROG_SUCCEEDED) { 1170 irc_ usermsg(irc, "smp %s: secrets proved equal, fingerprint trusted",1232 irc_rootmsg(irc, "smp %s: secrets proved equal, fingerprint trusted", 1171 1233 u->nick); 1172 1234 } else { 1173 irc_ usermsg(irc, "smp %s: secrets did not match, fingerprint not trusted",1235 irc_rootmsg(irc, "smp %s: secrets did not match, fingerprint not trusted", 1174 1236 u->nick); 1175 1237 } … … 1180 1242 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP_ABORT); 1181 1243 if (tlv) { 1182 irc_ usermsg(irc, "smp: received abort from %s", u->nick);1244 irc_rootmsg(irc, "smp: received abort from %s", u->nick); 1183 1245 otrl_sm_state_free(context->smstate); 1184 1246 /* smp is in back in EXPECT1 */ … … 1195 1257 u = irc_user_by_name(irc, nick); 1196 1258 if(!u || !u->bu || !u->bu->ic) { 1197 irc_ usermsg(irc, "%s: unknown user", nick);1259 irc_rootmsg(irc, "%s: unknown user", nick); 1198 1260 return; 1199 1261 } 1200 1262 if(!(u->bu->flags & BEE_USER_ONLINE)) { 1201 irc_ usermsg(irc, "%s is offline", nick);1263 irc_rootmsg(irc, "%s is offline", nick); 1202 1264 return; 1203 1265 } … … 1206 1268 u->bu->ic->acc->user, u->bu->ic->acc->prpl->name, 0, NULL, NULL, NULL); 1207 1269 if(!ctx || ctx->msgstate != OTRL_MSGSTATE_ENCRYPTED) { 1208 irc_ usermsg(irc, "smp: otr inactive with %s, try \x02otr connect"1270 irc_rootmsg(irc, "smp: otr inactive with %s, try \x02otr connect" 1209 1271 " %s\x02", nick, nick); 1210 1272 return; … … 1221 1283 if(question) { 1222 1284 /* this was 'otr smpq', just initiate */ 1223 irc_ usermsg(irc, "smp: initiating with %s...", u->nick);1285 irc_rootmsg(irc, "smp: initiating with %s...", u->nick); 1224 1286 otrl_message_initiate_smp_q(irc->otr->us, &otr_ops, u->bu->ic, ctx, 1225 1287 question, (unsigned char *)secret, strlen(secret)); … … 1230 1292 is completed or aborted! */ 1231 1293 if(ctx->smstate->secret == NULL) { 1232 irc_ usermsg(irc, "smp: initiating with %s...", u->nick);1294 irc_rootmsg(irc, "smp: initiating with %s...", u->nick); 1233 1295 otrl_message_initiate_smp(irc->otr->us, &otr_ops, 1234 1296 u->bu->ic, ctx, (unsigned char *)secret, strlen(secret)); … … 1237 1299 /* if we're still in EXPECT1 but smstate is initialized, we must have 1238 1300 received the SMP1, so let's issue a response */ 1239 irc_ usermsg(irc, "smp: responding to %s...", u->nick);1301 irc_rootmsg(irc, "smp: responding to %s...", u->nick); 1240 1302 otrl_message_respond_smp(irc->otr->us, &otr_ops, 1241 1303 u->bu->ic, ctx, (unsigned char *)secret, strlen(secret)); … … 1312 1374 } 1313 1375 1376 void otr_update_uflags(ConnContext *context, irc_user_t *u) 1377 { 1378 const char *trust; 1379 1380 if(context->active_fingerprint) { 1381 u->flags |= IRC_USER_OTR_ENCRYPTED; 1382 1383 trust = context->active_fingerprint->trust; 1384 if(trust && trust[0]) 1385 u->flags |= IRC_USER_OTR_TRUSTED; 1386 else 1387 u->flags &= ~IRC_USER_OTR_TRUSTED; 1388 } else { 1389 u->flags &= ~IRC_USER_OTR_ENCRYPTED; 1390 } 1391 } 1392 1314 1393 int otr_update_modeflags(irc_t *irc, irc_user_t *u) 1315 1394 { 1316 return 1;1395 return 0; 1317 1396 } 1318 1397 … … 1335 1414 } 1336 1415 if(fp == ctx->active_fingerprint) { 1337 irc_ usermsg(irc, " \x02%s (%s)\x02", human, trust);1416 irc_rootmsg(irc, " \x02%s (%s)\x02", human, trust); 1338 1417 } else { 1339 irc_ usermsg(irc, " %s (%s)", human, trust);1418 irc_rootmsg(irc, " %s (%s)", human, trust); 1340 1419 } 1341 1420 } 1342 1421 if(count==0) 1343 irc_ usermsg(irc, " (none)");1422 irc_rootmsg(irc, " (none)"); 1344 1423 } 1345 1424 … … 1360 1439 1361 1440 if(n>=40) { 1362 irc_ usermsg(irc, "too many fingerprint digits given, expected at most 40");1441 irc_rootmsg(irc, "too many fingerprint digits given, expected at most 40"); 1363 1442 return NULL; 1364 1443 } … … 1367 1446 *(p++) = c; 1368 1447 } else { 1369 irc_ usermsg(irc, "invalid hex digit '%c' in block %d", args[i][j], i+1);1448 irc_rootmsg(irc, "invalid hex digit '%c' in block %d", args[i][j], i+1); 1370 1449 return NULL; 1371 1450 } … … 1388 1467 } 1389 1468 if(!fp) { 1390 irc_ usermsg(irc, "%s: no match", prefix);1469 irc_rootmsg(irc, "%s: no match", prefix); 1391 1470 return NULL; 1392 1471 } … … 1401 1480 } 1402 1481 if(fp2) { 1403 irc_ usermsg(irc, "%s: multiple matches", prefix);1482 irc_rootmsg(irc, "%s: multiple matches", prefix); 1404 1483 return NULL; 1405 1484 } … … 1424 1503 1425 1504 if(n>=40) { 1426 irc_ usermsg(irc, "too many fingerprint digits given, expected at most 40");1505 irc_rootmsg(irc, "too many fingerprint digits given, expected at most 40"); 1427 1506 return NULL; 1428 1507 } … … 1431 1510 *(p++) = c; 1432 1511 } else { 1433 irc_ usermsg(irc, "invalid hex digit '%c' in block %d", args[i][j], i+1);1512 irc_rootmsg(irc, "invalid hex digit '%c' in block %d", args[i][j], i+1); 1434 1513 return NULL; 1435 1514 } … … 1452 1531 } 1453 1532 if(!k) { 1454 irc_ usermsg(irc, "%s: no match", prefix);1533 irc_rootmsg(irc, "%s: no match", prefix); 1455 1534 return NULL; 1456 1535 } … … 1465 1544 } 1466 1545 if(k2) { 1467 irc_ usermsg(irc, "%s: multiple matches", prefix);1546 irc_rootmsg(irc, "%s: multiple matches", prefix); 1468 1547 return NULL; 1469 1548 } … … 1480 1559 1481 1560 /* list all privkeys (including ones being generated) */ 1482 irc_ usermsg(irc, "\x1fprivate keys:\x1f");1561 irc_rootmsg(irc, "\x1fprivate keys:\x1f"); 1483 1562 for(key=irc->otr->us->privkey_root; key; key=key->next) { 1484 1563 const char *hash; … … 1486 1565 switch(key->pubkey_type) { 1487 1566 case OTRL_PUBKEY_TYPE_DSA: 1488 irc_ usermsg(irc, " %s/%s - DSA", key->accountname, key->protocol);1567 irc_rootmsg(irc, " %s/%s - DSA", key->accountname, key->protocol); 1489 1568 break; 1490 1569 default: 1491 irc_ usermsg(irc, " %s/%s - type %d", key->accountname, key->protocol,1570 irc_rootmsg(irc, " %s/%s - type %d", key->accountname, key->protocol, 1492 1571 key->pubkey_type); 1493 1572 } … … 1498 1577 hash = otrl_privkey_fingerprint(irc->otr->us, human, key->accountname, key->protocol); 1499 1578 if(hash) /* should always succeed */ 1500 irc_ usermsg(irc, " %s", human);1579 irc_rootmsg(irc, " %s", human); 1501 1580 } 1502 1581 if(irc->otr->sent_accountname) { 1503 irc_ usermsg(irc, " %s/%s - DSA", irc->otr->sent_accountname,1582 irc_rootmsg(irc, " %s/%s - DSA", irc->otr->sent_accountname, 1504 1583 irc->otr->sent_protocol); 1505 irc_ usermsg(irc, " (being generated)");1584 irc_rootmsg(irc, " (being generated)"); 1506 1585 } 1507 1586 for(kg=irc->otr->todo; kg; kg=kg->next) { 1508 irc_ usermsg(irc, " %s/%s - DSA", kg->accountname, kg->protocol);1509 irc_ usermsg(irc, " (queued)");1587 irc_rootmsg(irc, " %s/%s - DSA", kg->accountname, kg->protocol); 1588 irc_rootmsg(irc, " (queued)"); 1510 1589 } 1511 1590 if(key == irc->otr->us->privkey_root && 1512 1591 !irc->otr->sent_accountname && 1513 1592 kg == irc->otr->todo) 1514 irc_ usermsg(irc, " (none)");1593 irc_rootmsg(irc, " (none)"); 1515 1594 1516 1595 /* list all contexts */ 1517 irc_ usermsg(irc, "%s", "");1518 irc_ usermsg(irc, "\x1f" "connection contexts:\x1f (bold=currently encrypted)");1596 irc_rootmsg(irc, "%s", ""); 1597 irc_rootmsg(irc, "\x1f" "connection contexts:\x1f (bold=currently encrypted)"); 1519 1598 for(ctx=irc->otr->us->context_root; ctx; ctx=ctx->next) {\ 1520 1599 irc_user_t *u; … … 1530 1609 1531 1610 if(ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) { 1532 irc_ usermsg(irc, " \x02%s\x02", userstring);1611 irc_rootmsg(irc, " \x02%s\x02", userstring); 1533 1612 } else { 1534 irc_ usermsg(irc, " %s", userstring);1613 irc_rootmsg(irc, " %s", userstring); 1535 1614 } 1536 1615 … … 1538 1617 } 1539 1618 if(ctx == irc->otr->us->context_root) 1540 irc_ usermsg(irc, " (none)");1619 irc_rootmsg(irc, " (none)"); 1541 1620 } 1542 1621 … … 1545 1624 switch(ctx->otr_offer) { 1546 1625 case OFFER_NOT: 1547 irc_ usermsg(irc, " otr offer status: none sent");1626 irc_rootmsg(irc, " otr offer status: none sent"); 1548 1627 break; 1549 1628 case OFFER_SENT: 1550 irc_ usermsg(irc, " otr offer status: awaiting reply");1629 irc_rootmsg(irc, " otr offer status: awaiting reply"); 1551 1630 break; 1552 1631 case OFFER_ACCEPTED: 1553 irc_ usermsg(irc, " otr offer status: accepted our offer");1632 irc_rootmsg(irc, " otr offer status: accepted our offer"); 1554 1633 break; 1555 1634 case OFFER_REJECTED: 1556 irc_ usermsg(irc, " otr offer status: ignored our offer");1635 irc_rootmsg(irc, " otr offer status: ignored our offer"); 1557 1636 break; 1558 1637 default: 1559 irc_ usermsg(irc, " otr offer status: %d", ctx->otr_offer);1638 irc_rootmsg(irc, " otr offer status: %d", ctx->otr_offer); 1560 1639 } 1561 1640 1562 1641 switch(ctx->msgstate) { 1563 1642 case OTRL_MSGSTATE_PLAINTEXT: 1564 irc_ usermsg(irc, " connection state: cleartext");1643 irc_rootmsg(irc, " connection state: cleartext"); 1565 1644 break; 1566 1645 case OTRL_MSGSTATE_ENCRYPTED: 1567 irc_ usermsg(irc, " connection state: encrypted (v%d)", ctx->protocol_version);1646 irc_rootmsg(irc, " connection state: encrypted (v%d)", ctx->protocol_version); 1568 1647 break; 1569 1648 case OTRL_MSGSTATE_FINISHED: 1570 irc_ usermsg(irc, " connection state: shut down");1649 irc_rootmsg(irc, " connection state: shut down"); 1571 1650 break; 1572 1651 default: 1573 irc_ usermsg(irc, " connection state: %d", ctx->msgstate);1574 } 1575 1576 irc_ usermsg(irc, " fingerprints: (bold=active)");1652 irc_rootmsg(irc, " connection state: %d", ctx->msgstate); 1653 } 1654 1655 irc_rootmsg(irc, " fingerprints: (bold=active)"); 1577 1656 show_fingerprints(irc, ctx); 1578 1657 } … … 1614 1693 1615 1694 if(pipe(to) < 0 || pipe(from) < 0) { 1616 irc_ usermsg(irc, "otr keygen: couldn't create pipe: %s", strerror(errno));1695 irc_rootmsg(irc, "otr keygen: couldn't create pipe: %s", strerror(errno)); 1617 1696 return; 1618 1697 } … … 1621 1700 fromf = fdopen(from[0], "r"); 1622 1701 if(!tof || !fromf) { 1623 irc_ usermsg(irc, "otr keygen: couldn't streamify pipe: %s", strerror(errno));1702 irc_rootmsg(irc, "otr keygen: couldn't streamify pipe: %s", strerror(errno)); 1624 1703 return; 1625 1704 } … … 1627 1706 p = fork(); 1628 1707 if(p<0) { 1629 irc_ usermsg(irc, "otr keygen: couldn't fork: %s", strerror(errno));1708 irc_rootmsg(irc, "otr keygen: couldn't fork: %s", strerror(errno)); 1630 1709 return; 1631 1710 } … … 1707 1786 myfgets(msg, 512, irc->otr->from); 1708 1787 1709 irc_ usermsg(irc, "%s", msg);1788 irc_rootmsg(irc, "%s", msg); 1710 1789 if(filename[0]) { 1711 char *kf = g_strdup_printf("%s%s.otr_keys", global.conf->configdir, irc->user->nick); 1712 char *tmp = g_strdup_printf("%s.new", kf); 1713 copyfile(filename, tmp); 1714 unlink(filename); 1715 rename(tmp,kf); 1716 otrl_privkey_read(irc->otr->us, kf); 1717 g_free(kf); 1718 g_free(tmp); 1790 if(strsane(irc->user->nick)) { 1791 char *kf = g_strdup_printf("%s%s.otr_keys", global.conf->configdir, irc->user->nick); 1792 char *tmp = g_strdup_printf("%s.new", kf); 1793 copyfile(filename, tmp); 1794 unlink(filename); 1795 rename(tmp,kf); 1796 otrl_privkey_read(irc->otr->us, kf); 1797 g_free(kf); 1798 g_free(tmp); 1799 } else { 1800 otrl_privkey_read(irc->otr->us, filename); 1801 unlink(filename); 1802 } 1719 1803 } 1720 1804 … … 1781 1865 1782 1866 if(keygen_in_progress(irc, acc->user, acc->prpl->name)) { 1783 irc_ usermsg(irc, "keygen for %s/%s already in progress",1867 irc_rootmsg(irc, "keygen for %s/%s already in progress", 1784 1868 acc->user, acc->prpl->name); 1785 1869 } else { 1786 irc_ usermsg(irc, "starting background keygen for %s/%s",1870 irc_rootmsg(irc, "starting background keygen for %s/%s", 1787 1871 acc->user, acc->prpl->name); 1788 irc_ usermsg(irc, "you will be notified when it completes");1872 irc_rootmsg(irc, "you will be notified when it completes"); 1789 1873 otr_keygen(irc, acc->user, acc->prpl->name); 1790 1874 } 1791 1875 } 1876 1877 /* check whether a string is safe to use in a path component */ 1878 int strsane(const char *s) 1879 { 1880 return strpbrk(s, "/\\") == NULL; 1881 } 1882 1883 /* vim: set noet ts=4 sw=4: */
Note: See TracChangeset
for help on using the changeset viewer.