Changeset 5f4eede


Ignore:
Timestamp:
2008-02-11T23:16:23Z (16 years ago)
Author:
Sven Moritz Hallberg <sm@…>
Branches:
master
Children:
e2b15bb
Parents:
8bd697c
Message:
  • add nonfunctional 'otr forget key' implementation
  • add 'color_encrypted' setting
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • irc.c

    r8bd697c r5f4eede  
    109109        set_add( &irc->set, "buddy_sendbuffer_delay", "200", set_eval_int, irc );
    110110        set_add( &irc->set, "charset", "utf-8", set_eval_charset, irc );
     111        set_add( &irc->set, "color_encrypted", "true", set_eval_bool, irc );
    111112        set_add( &irc->set, "debug", "false", set_eval_bool, irc );
    112113        set_add( &irc->set, "default_target", "root", NULL, irc );
    113114        set_add( &irc->set, "display_namechanges", "false", set_eval_bool, irc );
    114115        set_add( &irc->set, "handle_unknown", "root", NULL, irc );
    115         set_add( &irc->set, "halfop_buddies", "false", set_eval_halfop_buddies, irc );
     116        set_add( &irc->set, "halfop_buddies", "encrypted", set_eval_halfop_buddies, irc );
    116117        set_add( &irc->set, "lcnicks", "true", set_eval_bool, irc );
    117         set_add( &irc->set, "op_buddies", "false", set_eval_op_buddies, irc );
     118        set_add( &irc->set, "op_buddies", "trusted", set_eval_op_buddies, irc );
    118119        set_add( &irc->set, "op_root", "true", set_eval_op_root, irc );
    119120        set_add( &irc->set, "op_user", "true", set_eval_op_user, irc );
  • otr.c

    r8bd697c r5f4eede  
    9494void yes_forget_fingerprint(gpointer w, void *data);
    9595void yes_forget_context(gpointer w, void *data);
     96void yes_forget_key(gpointer w, void *data);
    9697
    9798/* helper to make sure accountname and protocol match the incoming "opdata" */
     
    129130/* find a fingerprint by prefix (given as any number of hex strings) */
    130131Fingerprint *match_fingerprint(irc_t *irc, ConnContext *ctx, const char **args);
     132
     133/* find a private key by fingerprint prefix (given as any number of hex strings) */
     134OtrlPrivKey *match_privkey(irc_t *irc, const char **args);
    131135
    132136/* to log out accounts during keygen */
     
    288292                ConnContext *context = otrl_context_find(ic->irc->otr_us, handle,
    289293                        ic->acc->user, ic->acc->prpl->name, 0, NULL, NULL, NULL);
    290                 if(context && context->msgstate == OTRL_MSGSTATE_ENCRYPTED) {
     294                if(context && context->msgstate == OTRL_MSGSTATE_ENCRYPTED &&
     295                   set_getbool(&ic->irc->set, "color_encrypted")) {
    291296                        /* color according to f'print trust */
    292297                        char color;
     
    395400        log_message(LOGLVL_DEBUG, "op_create_privkey '%s' '%s'", accountname, protocol);
    396401
    397         s = g_strdup_printf("oops, no otr privkey for %s/%s - generate one now?",
    398                 accountname, protocol);
     402        s = g_strdup_printf("oops, no otr privkey for %s - generate one now?",
     403                accountname);
    399404        query_add(ic->irc, ic, s, yes_keygen, NULL, ic->acc);
    400405}
     
    794799        if(otrl_privkey_find(irc->otr_us, a->user, a->prpl->name)) {
    795800                char *s = g_strdup_printf("account %d already has a key, replace it?", n);
    796                 query_add(irc, a->ic, s, yes_keygen, NULL, a);
     801                query_add(irc, NULL, s, yes_keygen, NULL, a);
    797802        } else {
    798803                otr_keygen(irc, a->user, a->prpl->name);
     
    802807void yes_forget_fingerprint(gpointer w, void *data)
    803808{
    804         struct im_connection *ic = (struct im_connection *)w;
     809        irc_t *irc = (irc_t *)w;
    805810        Fingerprint *fp = (Fingerprint *)data;
    806811       
    807812        if(fp == fp->context->active_fingerprint) {
    808                 irc_usermsg(ic->irc, "that fingerprint is active, terminate otr connection first");
     813                irc_usermsg(irc, "that fingerprint is active, terminate otr connection first");
    809814                return;
    810815        }
     
    815820void yes_forget_context(gpointer w, void *data)
    816821{
    817         struct im_connection *ic = (struct im_connection *)w;
     822        irc_t *irc = (irc_t *)w;
    818823        ConnContext *ctx = (ConnContext *)data;
    819824       
    820825        if(ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) {
    821                 irc_usermsg(ic->irc, "active otr connection with %s, terminate it first",
    822                         peernick(ic->irc, ctx->username, ctx->protocol));
     826                irc_usermsg(irc, "active otr connection with %s, terminate it first",
     827                        peernick(irc, ctx->username, ctx->protocol));
    823828                return;
    824829        }
     
    827832                otrl_context_force_plaintext(ctx);
    828833        otrl_context_forget(ctx);
     834}
     835
     836void yes_forget_key(gpointer w, void *data)
     837{
     838        OtrlPrivKey *key = (OtrlPrivKey *)data;
     839       
     840        /* FIXME: For some reason which /completely eludes me/, this call keeps
     841           barfing on the gcry_sexp_release inside (invalid pointer free). */
     842        otrl_privkey_forget(key);
    829843}
    830844
     
    870884                otrl_privkey_hash_to_human(human, fp->fingerprint);
    871885                s = g_strdup_printf("about to forget fingerprint %s, are you sure?", human);
    872                 query_add(irc, u->ic, s, yes_forget_fingerprint, NULL, fp);
     886                query_add(irc, NULL, s, yes_forget_fingerprint, NULL, fp);
    873887        }
    874888       
     
    898912               
    899913                s = g_strdup_printf("about to forget otr data about %s, are you sure?", args[2]);
    900                 query_add(irc, u->ic, s, yes_forget_context, NULL, ctx);
     914                query_add(irc, NULL, s, yes_forget_context, NULL, ctx);
    901915        }
    902916       
    903917        else if(!strcmp(args[1], "key"))
    904918        {
    905                 irc_usermsg(irc, "n/a: TODO");
     919                OtrlPrivKey *key;
     920                char *s;
     921               
     922                key = match_privkey(irc, ((const char **)args)+2);
     923                if(!key) {
     924                        /* match_privkey does error messages */
     925                        return;
     926                }
     927               
     928                /* TODO: Find out why 'otr forget key' barfs (cf. yes_forget_key) */
     929                irc_usermsg(irc, "otr %s %s: not implemented, please edit \x02%s%s.otr_keys\x02 manually :-/",
     930                        args[0], args[1], global.conf->configdir, irc->nick);
     931                return;
     932
     933                s = g_strdup_printf("about to forget the private key for %s/%s, are you sure?",
     934                        key->accountname, key->protocol);
     935                query_add(irc, NULL, s, yes_forget_key, NULL, key);
    906936        }
    907937       
     
    12311261}
    12321262
     1263OtrlPrivKey *match_privkey(irc_t *irc, const char **args)
     1264{
     1265        OtrlPrivKey *k, *k2;
     1266        char human[45];
     1267        char prefix[45], *p;
     1268        int n;
     1269        int i,j;
     1270       
     1271        /* assemble the args into a prefix in standard "human" form */
     1272        n=0;
     1273        p=prefix;
     1274        for(i=0; args[i]; i++) {
     1275                for(j=0; args[i][j]; j++) {
     1276                        char c = toupper(args[i][j]);
     1277                       
     1278                        if(n>=40) {
     1279                                irc_usermsg(irc, "too many fingerprint digits given, expected at most 40");
     1280                                return NULL;
     1281                        }
     1282                       
     1283                        if( (c>='A' && c<='F') || (c>='0' && c<='9') ) {
     1284                                *(p++) = c;
     1285                        } else {
     1286                                irc_usermsg(irc, "invalid hex digit '%c' in block %d", args[i][j], i+1);
     1287                                return NULL;
     1288                        }
     1289                       
     1290                        n++;
     1291                        if(n%8 == 0)
     1292                                *(p++) = ' ';
     1293                }
     1294        }
     1295        *p = '\0';
     1296        log_message(LOGLVL_DEBUG, "match_privkey '%s'", prefix);
     1297        log_message(LOGLVL_DEBUG, "n=%d strlen(prefix)=%d", n, strlen(prefix));
     1298       
     1299        /* find first key which matches the given prefix */
     1300        n = strlen(prefix);
     1301        for(k=irc->otr_us->privkey_root; k; k=k->next) {
     1302                p = otrl_privkey_fingerprint(irc->otr_us, human, k->accountname, k->protocol);
     1303                if(!p) /* gah! :-P */
     1304                        continue;
     1305                if(!strncmp(prefix, human, n))
     1306                        break;
     1307        }
     1308        if(!k) {
     1309                irc_usermsg(irc, "%s: no match", prefix);
     1310                return NULL;
     1311        }
     1312       
     1313        /* make sure the match, if any, is unique */
     1314        for(k2=k->next; k2; k2=k2->next) {
     1315                p = otrl_privkey_fingerprint(irc->otr_us, human, k2->accountname, k2->protocol);
     1316                if(!p) /* gah! :-P */
     1317                        continue;
     1318                if(!strncmp(prefix, human, n))
     1319                        break;
     1320        }
     1321        if(k2) {
     1322                irc_usermsg(irc, "%s: multiple matches", prefix);
     1323                return NULL;
     1324        }
     1325       
     1326        return k;
     1327}
     1328
    12331329void show_general_otr_info(irc_t *irc)
    12341330{
  • query.c

    r8bd697c r5f4eede  
    148148                        irc_usermsg( irc, "Accepted: %s", q->question );
    149149                if(q->yes)
    150                         q->yes( q->ic ? q->ic : irc, q->data );
     150                        q->yes( q->ic ? (gpointer)q->ic : (gpointer)irc, q->data );
    151151        }
    152152        else
     
    157157                        irc_usermsg( irc, "Rejected: %s", q->question );
    158158                if(q->no)
    159                         q->no( q->ic ? q->ic : irc, q->data );
     159                        q->no( q->ic ? (gpointer)q->ic : (gpointer)irc, q->data );
    160160        }
    161161        q->data = NULL;
Note: See TracChangeset for help on using the changeset viewer.