Changeset 608f8cf


Ignore:
Timestamp:
2007-11-24T18:02:39Z (16 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
221a273
Parents:
3a80471
Message:

Added some random hash to the id= for cached XMPP packets so that packets
from other BitlBees won't be picked up accidentally. Might also want to
randomize the per-packet IDs because they're still predictable.

Location:
protocols/jabber
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/iq.c

    r3a80471 r608f8cf  
    5050               
    5151                if( ( s = xt_find_attr( node, "id" ) ) == NULL ||
    52                     strncmp( s, JABBER_CACHED_ID, strlen( JABBER_CACHED_ID ) ) != 0 )
     52                    strncmp( s, jd->cached_id_prefix, strlen( jd->cached_id_prefix ) ) != 0 )
    5353                {
    5454                        /* Silently ignore it, without an ID (or a non-cache
  • protocols/jabber/jabber.c

    r3a80471 r608f8cf  
    3232#include "bitlbee.h"
    3333#include "jabber.h"
     34#include "md5.h"
     35#include "base64.h"
    3436
    3537static void jabber_init( account_t *acc )
     
    5961        s->flags |= ACC_SET_OFFLINE_ONLY;
    6062}
     63
     64static void jabber_generate_id_hash( struct jabber_data *jd );
    6165
    6266static void jabber_login( account_t *acc )
     
    200204                imcb_add_buddy( ic, JABBER_XMLCONSOLE_HANDLE, NULL );
    201205        }
     206       
     207        jabber_generate_id_hash( jd );
     208}
     209
     210static void jabber_generate_id_hash( struct jabber_data *jd )
     211{
     212        md5_state_t id_hash;
     213        md5_byte_t binbuf[16];
     214        char *s;
     215       
     216        md5_init( &id_hash );
     217        md5_append( &id_hash, (unsigned char *) jd->username, strlen( jd->username ) );
     218        md5_append( &id_hash, (unsigned char *) jd->server, strlen( jd->server ) );
     219        s = set_getstr( &jd->ic->acc->set, "resource" );
     220        md5_append( &id_hash, (unsigned char *) s, strlen( s ) );
     221        random_bytes( binbuf, 16 );
     222        md5_append( &id_hash, binbuf, 16 );
     223        md5_finish( &id_hash, binbuf );
     224       
     225        s = base64_encode( binbuf, 9 );
     226        jd->cached_id_prefix = g_strdup_printf( "%s%s", JABBER_CACHED_ID, s );
     227        g_free( s );
     228       
     229        printf( "%s\n", jd->cached_id_prefix );
    202230}
    203231
  • protocols/jabber/jabber.h

    r3a80471 r608f8cf  
    7878        char *away_message;
    7979       
     80        char *cached_id_prefix;
    8081        GHashTable *node_cache;
    8182        GHashTable *buddies;
     
    132133   first one should be used, but when storing a packet in the cache, a
    133134   "special" kind of ID is assigned to make it easier later to figure out
    134    if we have to do call an event handler for the response packet. */
     135   if we have to do call an event handler for the response packet. Also
     136   we'll append a hash to make sure we won't trigger on cached packets from
     137   other BitlBee users. :-) */
    135138#define JABBER_PACKET_ID "BeeP"
    136139#define JABBER_CACHED_ID "BeeC"
  • protocols/jabber/jabber_util.c

    r3a80471 r608f8cf  
    133133{
    134134        struct jabber_data *jd = ic->proto_data;
    135         char *id = g_strdup_printf( "%s%05x", JABBER_CACHED_ID, ( next_id++ ) & 0xfffff );
    136135        struct jabber_cache_entry *entry = g_new0( struct jabber_cache_entry, 1 );
    137        
     136        char *id;
     137       
     138        id = g_strdup_printf( "%s%05x", jd->cached_id_prefix, ( next_id++ ) & 0xfffff );
    138139        xt_add_attr( node, "id", id );
    139140        g_free( id );
Note: See TracChangeset for help on using the changeset viewer.