Changeset 8521b02
- Timestamp:
- 2008-02-10T16:46:10Z (17 years ago)
- Branches:
- master
- Children:
- 94e7eb3
- Parents:
- 52e6e17
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
otr.c
r52e6e17 r8521b02 48 48 /** otr sub-command handlers: **/ 49 49 50 /* TODO: void cmd_otr_keygen(irc_t *irc, char **args); */ 51 void cmd_otr_abort(irc_t *irc, char **args); /* TODO: does this cmd even make sense? */ 52 void cmd_otr_request(irc_t *irc, char **args); /* TODO: do we even need this? */ 50 void cmd_otr_connect(irc_t *irc, char **args); 51 void cmd_otr_disconnect(irc_t *irc, char **args); 53 52 void cmd_otr_smp(irc_t *irc, char **args); 54 53 void cmd_otr_trust(irc_t *irc, char **args); 55 /* TODO: void cmd_otr_affirm(irc_t *irc, char **args); */56 void cmd_otr_fprints(irc_t *irc, char **args);57 54 void cmd_otr_info(irc_t *irc, char **args); 58 void cmd_otr_policy(irc_t *irc, char **args); 55 /* void cmd_otr_forget(irc_t *irc, char **args); */ 59 56 60 57 const command_t otr_commands[] = { 61 { "abort", 1, &cmd_otr_abort, 0 }, 62 { "request", 1, &cmd_otr_request, 0 }, 63 { "smp", 2, &cmd_otr_smp, 0 }, 64 { "trust", 6, &cmd_otr_trust, 0 }, 65 { "fprints", 0, &cmd_otr_fprints, 0 }, 66 { "info", 1, &cmd_otr_info, 0 }, 67 { "policy", 0, &cmd_otr_policy, 0 }, 58 { "connect", 1, &cmd_otr_connect, 0 }, 59 { "disconnect", 1, &cmd_otr_disconnect, 0 }, 60 { "smp", 2, &cmd_otr_smp, 0 }, 61 { "trust", 6, &cmd_otr_trust, 0 }, 62 { "info", 0, &cmd_otr_info, 0 }, 63 /* 64 { "forget", 1, &cmd_otr_forget, 0 }, 65 */ 68 66 { NULL } 69 67 }; … … 101 99 const char *peernick(irc_t *irc, const char *handle, const char *protocol); 102 100 101 /* turn a hexadecimal digit into its numerical value */ 102 int hexval(char a); 103 103 104 /* determine the user_t for a given handle/protocol pair 104 105 returns NULL if not found */ … … 113 114 int otr_update_modeflags(irc_t *irc, user_t *u); 114 115 116 /* show general info about the OTR subsystem; called by 'otr info' */ 117 void show_general_otr_info(irc_t *irc); 118 119 /* show info about a given OTR context */ 120 void show_otr_context_info(irc_t *irc, ConnContext *ctx); 121 115 122 /* show the list of fingerprints associated with a given context */ 116 123 void show_fingerprints(irc_t *irc, ConnContext *ctx); 117 118 124 119 125 … … 489 495 if(!u) { 490 496 log_message(LOGLVL_ERROR, 491 "BUG: otr.c: op_gone_secure: user_t for %s/%s not found!",492 context->username, context->protocol );497 "BUG: otr.c: op_gone_secure: user_t for %s/%s/%s not found!", 498 context->username, context->protocol, context->accountname); 493 499 return; 494 500 } … … 512 518 if(!u) { 513 519 log_message(LOGLVL_ERROR, 514 "BUG: otr.c: op_gone_insecure: user_t for %s/%s not found!",515 context->username, context->protocol );520 "BUG: otr.c: op_gone_insecure: user_t for %s/%s/%s not found!", 521 context->username, context->protocol, context->accountname); 516 522 return; 517 523 } … … 533 539 if(!u) { 534 540 log_message(LOGLVL_ERROR, 535 "BUG: otr.c: op_still_secure: user_t for %s/%s not found!",536 context->username, context->protocol );541 "BUG: otr.c: op_still_secure: user_t for %s/%s/%s not found!", 542 context->username, context->protocol, context->accountname); 537 543 return; 538 544 } … … 574 580 /*** OTR sub-command handlers ***/ 575 581 576 void cmd_otr_ abort(irc_t *irc, char **args)582 void cmd_otr_disconnect(irc_t *irc, char **args) 577 583 { 578 584 user_t *u; … … 588 594 } 589 595 590 void cmd_otr_ request(irc_t *irc, char **args)596 void cmd_otr_connect(irc_t *irc, char **args) 591 597 { 592 598 user_t *u; … … 650 656 /* smp is now in EXPECT3 */ 651 657 } 652 }653 654 int hexval(char a)655 {656 int x=tolower(a);657 658 if(x>='a' && x<='f')659 x = x - 'a' + 10;660 else if(x>='0' && x<='9')661 x = x - '0';662 else663 return -1;664 665 return x;666 658 } 667 659 … … 726 718 } 727 719 728 void cmd_otr_fprints(irc_t *irc, char **args) 729 { 730 if(args[1]) { 731 /* list given buddy's fingerprints */ 732 user_t *u; 720 void cmd_otr_info(irc_t *irc, char **args) 721 { 722 if(!args[1]) { 723 show_general_otr_info(irc); 724 } else { 725 char *arg = g_strdup(args[1]); 726 char *myhandle, *handle, *protocol; 733 727 ConnContext *ctx; 734 735 u = user_find(irc, args[1]); 736 if(!u || !u->ic) { 737 irc_usermsg(irc, "%s: unknown user", args[1]); 738 return; 739 } 740 741 ctx = otrl_context_find(irc->otr_us, u->handle, 742 u->ic->acc->user, u->ic->acc->prpl->name, 0, NULL, NULL, NULL); 743 if(!ctx) { 744 irc_usermsg(irc, "no fingerprints"); 728 729 /* interpret arg as 'user/protocol/account' if possible */ 730 protocol = strchr(arg, '/'); 731 if(protocol) { 732 *(protocol++) = '\0'; 733 myhandle = strchr(protocol, '/'); 734 if(!myhandle) { 735 /* TODO: try to find a unique account for this context */ 736 } 737 } 738 if(protocol && myhandle) { 739 *(myhandle++) = '\0'; 740 handle = arg; 741 ctx = otrl_context_find(irc->otr_us, handle, myhandle, protocol, 0, NULL, NULL, NULL); 742 if(!ctx) { 743 irc_usermsg(irc, "no such context (%s %s %s)", handle, protocol, myhandle); 744 g_free(arg); 745 return; 746 } 745 747 } else { 746 show_fingerprints(irc, ctx); 747 } 748 } else { 749 /* list all known fingerprints */ 750 ConnContext *ctx; 751 for(ctx=irc->otr_us->context_root; ctx; ctx=ctx->next) { 752 irc_usermsg(irc, "[%s]", peernick(irc, ctx->username, ctx->protocol)); 753 show_fingerprints(irc, ctx); 754 } 755 if(!irc->otr_us->context_root) { 756 irc_usermsg(irc, "no fingerprints"); 757 } 758 } 759 } 760 761 void cmd_otr_info(irc_t *irc, char **args) 762 { 763 user_t *u; 764 ConnContext *ctx; 765 Fingerprint *fp; 766 char human[45]; 767 const char *offer_status; 768 const char *message_state; 769 const char *trust; 770 771 if(!args) { 772 irc_usermsg(irc, "no args?!"); 773 return; 774 } 775 if(!args[1]) { 776 irc_usermsg(irc, "no args[1]?!"); 777 return; 778 } 779 u = user_find(irc, args[1]); 780 if(!u || !u->ic) { 781 irc_usermsg(irc, "%s: unknown user", args[1]); 782 return; 783 } 784 785 ctx = otrl_context_find(irc->otr_us, u->handle, 786 u->ic->acc->user, u->ic->acc->prpl->name, 0, NULL, NULL, NULL); 787 if(!ctx) { 788 irc_usermsg(irc, "no otr context with %s", args[1]); 789 return; 790 } 791 792 switch(ctx->otr_offer) { 793 case OFFER_NOT: offer_status="none sent"; break; 794 case OFFER_SENT: offer_status="awaiting reply"; break; 795 case OFFER_ACCEPTED: offer_status="accepted our offer"; break; 796 case OFFER_REJECTED: offer_status="ignored our offer"; break; 797 default: offer_status="?"; 798 } 799 800 switch(ctx->msgstate) { 801 case OTRL_MSGSTATE_PLAINTEXT: message_state="cleartext"; break; 802 case OTRL_MSGSTATE_ENCRYPTED: message_state="encrypted"; break; 803 case OTRL_MSGSTATE_FINISHED: message_state="shut down"; break; 804 default: message_state="?"; 805 } 806 807 irc_usermsg(irc, "%s is %s/%s; we are %s/%s to them", args[1], 808 ctx->username, ctx->protocol, ctx->accountname, ctx->protocol); 809 irc_usermsg(irc, " otr offer status: %s", offer_status); 810 irc_usermsg(irc, " connection state: %s", message_state); 811 812 if(ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) { 813 irc_usermsg(irc, " protocol version: %d", ctx->protocol_version); 814 fp = ctx->active_fingerprint; 815 if(!fp) { 816 irc_usermsg(irc, " active f'print: none?"); 817 } else { 818 otrl_privkey_hash_to_human(human, fp->fingerprint); 819 if(!fp->trust || fp->trust[0] == '\0') { 820 trust="untrusted"; 821 } else { 822 trust=fp->trust; 748 user_t *u = user_find(irc, args[1]); 749 if(!u || !u->ic) { 750 irc_usermsg(irc, "%s: unknown user", args[1]); 751 g_free(arg); 752 return; 823 753 } 824 irc_usermsg(irc, " active f'print: %s (%s)", human, trust); 825 } 826 } 827 } 828 829 void cmd_otr_policy(irc_t *irc, char **args) 830 { 831 irc_usermsg(irc, "n/a: not implemented"); 754 ctx = otrl_context_find(irc->otr_us, u->handle, u->ic->acc->user, 755 u->ic->acc->prpl->name, 0, NULL, NULL, NULL); 756 if(!ctx) { 757 irc_usermsg(irc, "no otr context with %s", args[1]); 758 g_free(arg); 759 return; 760 } 761 } 762 763 /* show how we resolved the (nick) argument, if we did */ 764 if(handle!=arg) { 765 irc_usermsg(irc, "%s is %s/%s; we are %s/%s to them", args[1], 766 ctx->username, ctx->protocol, ctx->accountname, ctx->protocol); 767 } 768 show_otr_context_info(irc, ctx); 769 g_free(arg); 770 } 832 771 } 833 772 … … 953 892 user_t *u; 954 893 894 log_message(LOGLVL_DEBUG, "peeruser '%s' '%s'", handle, protocol); 895 955 896 for(u=irc->users; u; u=u->next) { 956 897 struct prpl *prpl; 957 898 if(!u->ic || !u->handle) 958 break;899 continue; 959 900 prpl = u->ic->acc->prpl; 960 901 if(strcmp(prpl->name, protocol) == 0 … … 965 906 966 907 return NULL; 908 } 909 910 int hexval(char a) 911 { 912 int x=tolower(a); 913 914 if(x>='a' && x<='f') 915 x = x - 'a' + 10; 916 else if(x>='0' && x<='9') 917 x = x - '0'; 918 else 919 return -1; 920 921 return x; 967 922 } 968 923 … … 1054 1009 } 1055 1010 if(fp == ctx->active_fingerprint) { 1056 irc_usermsg(irc, " \x02%s (%s)\x02", human, trust);1011 irc_usermsg(irc, " \x02%s (%s)\x02", human, trust); 1057 1012 } else { 1058 irc_usermsg(irc, " %s (%s)", human, trust);1013 irc_usermsg(irc, " %s (%s)", human, trust); 1059 1014 } 1060 1015 } 1061 1016 if(count==0) 1062 irc_usermsg(irc, "no fingerprints"); 1017 irc_usermsg(irc, " no fingerprints"); 1018 } 1019 1020 void show_general_otr_info(irc_t *irc) 1021 { 1022 ConnContext *ctx; 1023 OtrlPrivKey *key; 1024 char human[45]; 1025 1026 /* list all privkeys */ 1027 irc_usermsg(irc, "\x1fprivate keys:\x1f"); 1028 for(key=irc->otr_us->privkey_root; key; key=key->next) { 1029 const char *hash; 1030 1031 switch(key->pubkey_type) { 1032 case OTRL_PUBKEY_TYPE_DSA: 1033 irc_usermsg(irc, " %s/%s - DSA", key->accountname, key->protocol); 1034 break; 1035 default: 1036 irc_usermsg(irc, " %s/%s - type %d", key->accountname, key->protocol, 1037 key->pubkey_type); 1038 } 1039 1040 /* No, it doesn't make much sense to search for the privkey again by 1041 account/protocol, but libotr currently doesn't provide a direct routine 1042 for hashing a given 'OtrlPrivKey'... */ 1043 hash = otrl_privkey_fingerprint(irc->otr_us, human, key->accountname, key->protocol); 1044 if(hash) /* should always succeed */ 1045 irc_usermsg(irc, " %s", human); 1046 } 1047 1048 /* list all contexts */ 1049 irc_usermsg(irc, "%s", ""); 1050 irc_usermsg(irc, "\x1f" "connection contexts:\x1f (bold=currently encrypted)"); 1051 for(ctx=irc->otr_us->context_root; ctx; ctx=ctx->next) {\ 1052 user_t *u; 1053 char *userstring; 1054 1055 u = peeruser(irc, ctx->username, ctx->protocol); 1056 if(u) 1057 userstring = g_strdup_printf("%s/%s/%s (%s)", 1058 ctx->username, ctx->protocol, ctx->accountname, u->nick); 1059 else 1060 userstring = g_strdup_printf("%s/%s/%s", 1061 ctx->username, ctx->protocol, ctx->accountname); 1062 1063 if(ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) { 1064 otrl_privkey_hash_to_human(human, ctx->active_fingerprint->fingerprint); 1065 irc_usermsg(irc, " \x02%s\x02", userstring); 1066 irc_usermsg(irc, " %s", human); 1067 } else { 1068 irc_usermsg(irc, " %s", userstring); 1069 } 1070 1071 g_free(userstring); 1072 } 1073 } 1074 1075 void show_otr_context_info(irc_t *irc, ConnContext *ctx) 1076 { 1077 switch(ctx->otr_offer) { 1078 case OFFER_NOT: 1079 irc_usermsg(irc, " otr offer status: none sent"); 1080 break; 1081 case OFFER_SENT: 1082 irc_usermsg(irc, " otr offer status: awaiting reply"); 1083 break; 1084 case OFFER_ACCEPTED: 1085 irc_usermsg(irc, " otr offer status: accepted our offer"); 1086 break; 1087 case OFFER_REJECTED: 1088 irc_usermsg(irc, " otr offer status: ignored our offer"); 1089 break; 1090 default: 1091 irc_usermsg(irc, " otr offer status: %d", ctx->otr_offer); 1092 } 1093 1094 switch(ctx->msgstate) { 1095 case OTRL_MSGSTATE_PLAINTEXT: 1096 irc_usermsg(irc, " connection state: cleartext"); 1097 break; 1098 case OTRL_MSGSTATE_ENCRYPTED: 1099 irc_usermsg(irc, " connection state: encrypted (v%d)", ctx->protocol_version); 1100 break; 1101 case OTRL_MSGSTATE_FINISHED: 1102 irc_usermsg(irc, " connection state: shut down"); 1103 break; 1104 default: 1105 irc_usermsg(irc, " connection state: %d", ctx->msgstate); 1106 } 1107 1108 irc_usermsg(irc, " known fingerprints: (bold=active)"); 1109 show_fingerprints(irc, ctx); 1063 1110 } 1064 1111
Note: See TracChangeset
for help on using the changeset viewer.