Changeset 352a6b0
- Timestamp:
- 2013-08-01T19:32:24Z (11 years ago)
- Branches:
- master
- Children:
- 090c9b7
- Parents:
- 5d2bc9d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
otr.c
r5d2bc9d r352a6b0 84 84 void op_convert_free(void *opdata, ConnContext *ctx, char *msg); 85 85 86 void op_handle_smp_event(void *opdata, OtrlSMPEvent ev, ConnContext *ctx, 87 unsigned short percent, char *question); 86 88 87 89 /** otr sub-command handlers: **/ … … 159 161 returns NULL if not found */ 160 162 irc_user_t *peeruser(irc_t *irc, const char *handle, const char *protocol); 161 162 /* handle SMP TLVs from a received message */163 void otr_handle_smp(struct im_connection *ic, const char *handle, OtrlTLV *tlvs);164 163 165 164 /* combined handler for the 'otr smp' and 'otr smpq' commands */ … … 228 227 otr_ops.otr_error_message = NULL; // TODO? 229 228 otr_ops.otr_error_message_free = NULL; 230 otr_ops.resent_msg_prefix = NULL; // XXXdon't need?229 otr_ops.resent_msg_prefix = NULL; // don't need? 231 230 otr_ops.resent_msg_prefix_free = NULL; 232 otr_ops.handle_smp_event = NULL; // XXX replace smp state machine w/this231 otr_ops.handle_smp_event = &op_handle_smp_event; 233 232 otr_ops.handle_msg_event = NULL; // XXX 234 233 otr_ops.create_instag = NULL; // XXX … … 402 401 &tlvs, NULL, NULL, NULL); 403 402 404 otr_handle_smp(ic, iu->bu->handle, tlvs);405 406 403 if(ignore_msg) { 407 404 /* this was an internal OTR protocol message */ … … 761 758 } 762 759 760 /* Socialist Millionaires' Protocol */ 761 void op_handle_smp_event(void *opdata, OtrlSMPEvent ev, ConnContext *ctx, 762 unsigned short percent, char *question) 763 { 764 struct im_connection *ic = 765 check_imc(opdata, ctx->accountname, ctx->protocol); 766 irc_t *irc = ic->bee->ui_data; 767 OtrlUserState us = irc->otr->us; 768 irc_user_t *u = peeruser(irc, ctx->username, ctx->protocol); 769 770 if(!u) return; 771 772 switch(ev) { 773 case OTRL_SMPEVENT_ASK_FOR_SECRET: 774 irc_rootmsg(irc, "smp: initiated by %s" 775 " - respond with \x02otr smp %s <secret>\x02", 776 u->nick, u->nick); 777 break; 778 case OTRL_SMPEVENT_ASK_FOR_ANSWER: 779 irc_rootmsg(irc, "smp: initiated by %s with question: \x02\"%s\"\x02", u->nick, 780 question); 781 irc_rootmsg(irc, "smp: respond with \x02otr smp %s <answer>\x02", 782 u->nick); 783 break; 784 case OTRL_SMPEVENT_CHEATED: 785 irc_rootmsg(irc, "smp %s: opponent violated protocol, aborting", 786 u->nick); 787 otrl_message_abort_smp(us, &otr_ops, u->bu->ic, ctx); 788 otrl_sm_state_free(ctx->smstate); 789 break; 790 case OTRL_SMPEVENT_NONE: 791 break; 792 case OTRL_SMPEVENT_IN_PROGRESS: 793 break; 794 case OTRL_SMPEVENT_SUCCESS: 795 if(ctx->smstate->received_question) { 796 irc_rootmsg(irc, "smp %s: correct answer, you are trusted", 797 u->nick); 798 } else { 799 irc_rootmsg(irc, "smp %s: secrets proved equal, fingerprint trusted", 800 u->nick); 801 } 802 otrl_sm_state_free(ctx->smstate); 803 break; 804 case OTRL_SMPEVENT_FAILURE: 805 if(ctx->smstate->received_question) { 806 irc_rootmsg(irc, "smp %s: wrong answer, you are not trusted", 807 u->nick); 808 } else { 809 irc_rootmsg(irc, "smp %s: secrets did not match, fingerprint not trusted", 810 u->nick); 811 } 812 otrl_sm_state_free(ctx->smstate); 813 break; 814 case OTRL_SMPEVENT_ABORT: 815 irc_rootmsg(irc, "smp: received abort from %s", u->nick); 816 otrl_sm_state_free(ctx->smstate); 817 break; 818 case OTRL_SMPEVENT_ERROR: 819 irc_rootmsg(irc, "smp %s: protocol error, aborting", 820 u->nick); 821 otrl_message_abort_smp(us, &otr_ops, u->bu->ic, ctx); 822 otrl_sm_state_free(ctx->smstate); 823 break; 824 } 825 } 826 763 827 764 828 … … 1131 1195 /*** local helpers / subroutines: ***/ 1132 1196 1133 /* Socialist Millionaires' Protocol */1134 void otr_handle_smp(struct im_connection *ic, const char *handle, OtrlTLV *tlvs)1135 {1136 irc_t *irc = ic->bee->ui_data;1137 OtrlUserState us = irc->otr->us;1138 OtrlMessageAppOps *ops = &otr_ops;1139 OtrlTLV *tlv = NULL;1140 ConnContext *context;1141 NextExpectedSMP nextMsg;1142 irc_user_t *u;1143 bee_user_t *bu;1144 1145 bu = bee_user_by_handle(ic->bee, ic, handle);1146 if(!bu || !(u = bu->ui_data)) return;1147 context = otrl_context_find(us, handle,1148 ic->acc->user, ic->acc->prpl->name, OTRL_INSTAG_MASTER, 1, NULL, NULL, NULL);1149 if(!context) {1150 /* huh? out of memory or what? */1151 irc_rootmsg(irc, "smp: failed to get otr context for %s", u->nick);1152 otrl_message_abort_smp(us, ops, u->bu->ic, context);1153 otrl_sm_state_free(context->smstate);1154 return;1155 }1156 nextMsg = context->smstate->nextExpected;1157 1158 if (context->smstate->sm_prog_state == OTRL_SMP_PROG_CHEATED) {1159 irc_rootmsg(irc, "smp %s: opponent violated protocol, aborting",1160 u->nick);1161 otrl_message_abort_smp(us, ops, u->bu->ic, context);1162 otrl_sm_state_free(context->smstate);1163 return;1164 }1165 1166 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1Q);1167 if (tlv) {1168 if (nextMsg != OTRL_SMP_EXPECT1) {1169 irc_rootmsg(irc, "smp %s: spurious SMP1Q received, aborting", u->nick);1170 otrl_message_abort_smp(us, ops, u->bu->ic, context);1171 otrl_sm_state_free(context->smstate);1172 } else {1173 char *question = g_strndup((char *)tlv->data, tlv->len);1174 irc_rootmsg(irc, "smp: initiated by %s with question: \x02\"%s\"\x02", u->nick,1175 question);1176 irc_rootmsg(irc, "smp: respond with \x02otr smp %s <answer>\x02",1177 u->nick);1178 g_free(question);1179 /* smp stays in EXPECT1 until user responds */1180 }1181 }1182 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1);1183 if (tlv) {1184 if (nextMsg != OTRL_SMP_EXPECT1) {1185 irc_rootmsg(irc, "smp %s: spurious SMP1 received, aborting", u->nick);1186 otrl_message_abort_smp(us, ops, u->bu->ic, context);1187 otrl_sm_state_free(context->smstate);1188 } else {1189 irc_rootmsg(irc, "smp: initiated by %s"1190 " - respond with \x02otr smp %s <secret>\x02",1191 u->nick, u->nick);1192 /* smp stays in EXPECT1 until user responds */1193 }1194 }1195 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP2);1196 if (tlv) {1197 if (nextMsg != OTRL_SMP_EXPECT2) {1198 irc_rootmsg(irc, "smp %s: spurious SMP2 received, aborting", u->nick);1199 otrl_message_abort_smp(us, ops, u->bu->ic, context);1200 otrl_sm_state_free(context->smstate);1201 } else {1202 /* SMP2 received, otrl_message_receiving will have sent SMP3 */1203 context->smstate->nextExpected = OTRL_SMP_EXPECT4;1204 }1205 }1206 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP3);1207 if (tlv) {1208 if (nextMsg != OTRL_SMP_EXPECT3) {1209 irc_rootmsg(irc, "smp %s: spurious SMP3 received, aborting", u->nick);1210 otrl_message_abort_smp(us, ops, u->bu->ic, context);1211 otrl_sm_state_free(context->smstate);1212 } else {1213 /* SMP3 received, otrl_message_receiving will have sent SMP4 */1214 if(context->smstate->sm_prog_state == OTRL_SMP_PROG_SUCCEEDED) {1215 if(context->smstate->received_question) {1216 irc_rootmsg(irc, "smp %s: correct answer, you are trusted",1217 u->nick);1218 } else {1219 irc_rootmsg(irc, "smp %s: secrets proved equal, fingerprint trusted",1220 u->nick);1221 }1222 } else {1223 if(context->smstate->received_question) {1224 irc_rootmsg(irc, "smp %s: wrong answer, you are not trusted",1225 u->nick);1226 } else {1227 irc_rootmsg(irc, "smp %s: secrets did not match, fingerprint not trusted",1228 u->nick);1229 }1230 }1231 otrl_sm_state_free(context->smstate);1232 /* smp is in back in EXPECT1 */1233 }1234 }1235 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP4);1236 if (tlv) {1237 if (nextMsg != OTRL_SMP_EXPECT4) {1238 irc_rootmsg(irc, "smp %s: spurious SMP4 received, aborting", u->nick);1239 otrl_message_abort_smp(us, ops, u->bu->ic, context);1240 otrl_sm_state_free(context->smstate);1241 } else {1242 /* SMP4 received, otrl_message_receiving will have set fp trust */1243 if(context->smstate->sm_prog_state == OTRL_SMP_PROG_SUCCEEDED) {1244 irc_rootmsg(irc, "smp %s: secrets proved equal, fingerprint trusted",1245 u->nick);1246 } else {1247 irc_rootmsg(irc, "smp %s: secrets did not match, fingerprint not trusted",1248 u->nick);1249 }1250 otrl_sm_state_free(context->smstate);1251 /* smp is in back in EXPECT1 */1252 }1253 }1254 tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP_ABORT);1255 if (tlv) {1256 irc_rootmsg(irc, "smp: received abort from %s", u->nick);1257 otrl_sm_state_free(context->smstate);1258 /* smp is in back in EXPECT1 */1259 }1260 }1261 1262 1197 /* combined handler for the 'otr smp' and 'otr smpq' commands */ 1263 1198 void otr_smp_or_smpq(irc_t *irc, const char *nick, const char *question, … … 1278 1213 1279 1214 ctx = otrl_context_find(irc->otr->us, u->bu->handle, 1280 u->bu->ic->acc->user, u->bu->ic->acc->prpl->name, OTRL_INSTAG_MASTER, 0, NULL, NULL, NULL); 1215 u->bu->ic->acc->user, u->bu->ic->acc->prpl->name, OTRL_INSTAG_MASTER, 0, NULL, NULL, NULL); // XXX 1281 1216 if(!ctx || ctx->msgstate != OTRL_MSGSTATE_ENCRYPTED) { 1282 1217 irc_rootmsg(irc, "smp: otr inactive with %s, try \x02otr connect"
Note: See TracChangeset
for help on using the changeset viewer.