Changeset 99a01b9


Ignore:
Timestamp:
2010-09-19T18:23:05Z (9 years ago)
Author:
Sven Moritz Hallberg <pesco@…>
Branches:
master
Children:
2171044
Parents:
51e9a1d
Message:

add 'otr smpq' command for q&a-style smp authentication

File:
1 edited

Legend:

Unmodified
Added
Removed
  • otr.c

    r51e9a1d r99a01b9  
    88  OTR support (cf. http://www.cypherpunks.ca/otr/)
    99 
    10   2008, Sven Moritz Hallberg <pesco@khjk.org>
     10  2008-2010, Sven Moritz Hallberg <pesco@khjk.org>
    1111  (c) and funded by stonedcoder.org
    1212   
     
    8888void cmd_otr_disconnect(irc_t *irc, char **args);
    8989void cmd_otr_smp(irc_t *irc, char **args);
     90void cmd_otr_smpq(irc_t *irc, char **args);
    9091void cmd_otr_trust(irc_t *irc, char **args);
    9192void cmd_otr_info(irc_t *irc, char **args);
     
    9798        { "disconnect",  1, &cmd_otr_disconnect, 0 },
    9899        { "smp",         2, &cmd_otr_smp,        0 },
     100        { "smpq",        3, &cmd_otr_smpq,       0 },
    99101        { "trust",       6, &cmd_otr_trust,      0 },
    100102        { "info",        0, &cmd_otr_info,       0 },
     
    155157/* handle SMP TLVs from a received message */
    156158void otr_handle_smp(struct im_connection *ic, const char *handle, OtrlTLV *tlvs);
     159
     160/* combined handler for the 'otr smp' and 'otr smpq' commands */
     161void otr_initiate_smp(irc_t *irc, const char *nick, const char *question,
     162                const char *secret);
    157163
    158164/* update op/voice flag of given user according to encryption state and settings
     
    729735void cmd_otr_smp(irc_t *irc, char **args)
    730736{
    731         irc_user_t *u;
    732         ConnContext *ctx;
    733        
    734         u = irc_user_by_name(irc, args[1]);
    735         if(!u || !u->bu || !u->bu->ic) {
    736                 irc_usermsg(irc, "%s: unknown user", args[1]);
    737                 return;
    738         }
    739         if(!(u->bu->flags & BEE_USER_ONLINE)) {
    740                 irc_usermsg(irc, "%s is offline", args[1]);
    741                 return;
    742         }
    743        
    744         ctx = otrl_context_find(irc->otr->us, u->bu->handle,
    745                 u->bu->ic->acc->user, u->bu->ic->acc->prpl->name, 1, NULL, NULL, NULL);
    746         if(!ctx) {
    747                 /* huh? out of memory or what? */
    748                 return;
    749         }
    750 
    751         if(ctx->smstate->nextExpected != OTRL_SMP_EXPECT1) {
    752                 log_message(LOGLVL_INFO,
    753                         "SMP already in phase %d, sending abort before reinitiating",
    754                         ctx->smstate->nextExpected+1);
    755                 otrl_message_abort_smp(irc->otr->us, &otr_ops, u->bu->ic, ctx);
    756                 otrl_sm_state_free(ctx->smstate);
    757         }
    758        
    759         /* warning: the following assumes that smstates are cleared whenever an SMP
    760            is completed or aborted! */
    761         if(ctx->smstate->secret == NULL) {
    762                 irc_usermsg(irc, "smp: initiating with %s...", u->nick);
    763                 otrl_message_initiate_smp(irc->otr->us, &otr_ops,
    764                         u->bu->ic, ctx, (unsigned char *)args[2], strlen(args[2]));
    765                 /* smp is now in EXPECT2 */
    766         } else {
    767                 /* if we're still in EXPECT1 but smstate is initialized, we must have
    768                    received the SMP1, so let's issue a response */
    769                 irc_usermsg(irc, "smp: responding to %s...", u->nick);
    770                 otrl_message_respond_smp(irc->otr->us, &otr_ops,
    771                         u->bu->ic, ctx, (unsigned char *)args[2], strlen(args[2]));
    772                 /* smp is now in EXPECT3 */
    773         }
     737        otr_initiate_smp(irc, args[1], NULL, args[2]);  /* no question */
     738}
     739
     740void cmd_otr_smpq(irc_t *irc, char **args)
     741{
     742        otr_initiate_smp(irc, args[1], args[2], args[3]);
    774743}
    775744
     
    11871156}
    11881157
     1158/* combined handler for the 'otr smp' and 'otr smpq' commands */
     1159void otr_initiate_smp(irc_t *irc, const char *nick, const char *question,
     1160                const char *secret)
     1161{
     1162        irc_user_t *u;
     1163        ConnContext *ctx;
     1164
     1165        u = irc_user_by_name(irc, nick);
     1166        if(!u || !u->bu || !u->bu->ic) {
     1167                irc_usermsg(irc, "%s: unknown user", nick);
     1168                return;
     1169        }
     1170        if(!(u->bu->flags & BEE_USER_ONLINE)) {
     1171                irc_usermsg(irc, "%s is offline", nick);
     1172                return;
     1173        }
     1174       
     1175        ctx = otrl_context_find(irc->otr->us, u->bu->handle,
     1176                u->bu->ic->acc->user, u->bu->ic->acc->prpl->name, 1, NULL, NULL, NULL);
     1177        if(!ctx) {
     1178                /* huh? out of memory or what? */
     1179                return;
     1180        }
     1181
     1182        if(ctx->smstate->nextExpected != OTRL_SMP_EXPECT1) {
     1183                log_message(LOGLVL_INFO,
     1184                        "SMP already in phase %d, sending abort before reinitiating",
     1185                        ctx->smstate->nextExpected+1);
     1186                otrl_message_abort_smp(irc->otr->us, &otr_ops, u->bu->ic, ctx);
     1187                otrl_sm_state_free(ctx->smstate);
     1188        }
     1189       
     1190        /* warning: the following assumes that smstates are cleared whenever an SMP
     1191           is completed or aborted! */
     1192        if(ctx->smstate->secret == NULL) {
     1193                irc_usermsg(irc, "smp: initiating with %s...", u->nick);
     1194                if(question) {
     1195                        otrl_message_initiate_smp_q(irc->otr->us, &otr_ops,
     1196                                u->bu->ic, ctx, question,
     1197                                (unsigned char *)secret, strlen(secret));
     1198                } else {
     1199                        otrl_message_initiate_smp(irc->otr->us, &otr_ops,
     1200                                u->bu->ic, ctx, (unsigned char *)secret, strlen(secret));
     1201                }
     1202                /* smp is now in EXPECT2 */
     1203        } else {
     1204                /* if we're still in EXPECT1 but smstate is initialized, we must have
     1205                   received the SMP1, so let's issue a response */
     1206                irc_usermsg(irc, "smp: responding to %s...", u->nick);
     1207                otrl_message_respond_smp(irc->otr->us, &otr_ops,
     1208                        u->bu->ic, ctx, (unsigned char *)secret, strlen(secret));
     1209                /* smp is now in EXPECT3 */
     1210        }
     1211}
     1212
    11891213/* helper to assert that account and protocol names given to ops below always
    11901214   match the im_connection passed through as opdata */
Note: See TracChangeset for help on using the changeset viewer.