Changeset c7304b2


Ignore:
Timestamp:
2008-01-12T20:07:10Z (16 years ago)
Author:
Miklos Vajna <vmiklos@…>
Branches:
master
Children:
55664fc
Parents:
e65ceaa
Message:

auth via ssl

  • move the config file to sysconfdir/skyped/skyped.conf as there will other config files there, too
  • autogenerate the ssl paths in skyped.conf.dist
  • skype plugin: connect via ssl
  • skyped: listen via ssl
Location:
skype
Files:
5 edited
1 moved

Legend:

Unmodified
Added
Removed
  • skype/Makefile

    re65ceaa rc7304b2  
    1212        $(INSTALL) skype.so $(DESTDIR)$(plugindir)
    1313        $(INSTALL) skyped.py $(DESTDIR)$(bindir)/skyped
    14         sed -i 's|/etc|$(sysconfdir)|' $(DESTDIR)$(bindir)/skyped
     14        sed -i 's|/usr/local/etc/skyped|$(sysconfdir)|' $(DESTDIR)$(bindir)/skyped
    1515        $(INSTALL) -m644 skyped.conf.dist $(DESTDIR)$(sysconfdir)/skyped.conf
    1616
  • skype/config.mak.in

    re65ceaa rc7304b2  
    33INSTALL = @INSTALL@
    44prefix = @prefix@
    5 sysconfdir = @sysconfdir@
     5sysconfdir = @sysconfdir@/skyped
    66exec_prefix = @exec_prefix@
    77bindir = @bindir@
  • skype/configure.ac

    re65ceaa rc7304b2  
    1717LDFLAGS="$LDFLAGS $BITLBEE_LIBS"
    1818AC_OUTPUT(config.mak)
     19AC_OUTPUT(skyped.conf.dist)
  • skype/skype.c

    re65ceaa rc7304b2  
    2828#include <poll.h>
    2929#include <bitlbee.h>
     30#include <bitlbee/ssl_client.h>
    3031#include <glib.h>
    3132
     
    6364         * we're connected and when we aren't. */
    6465        int bfd;
     66        /* ssl_getfd() uses this to get the file desciptor. */
     67        void *ssl;
    6568        /* When we receive a new message id, we query the properties, finally
    6669         * the chatname. Store the properties here so that we can use
     
    146149        if(pfd[0].revents & POLLHUP)
    147150        {
    148                 imcb_error( ic, "Could not connect to server" );
    149151                imc_logout( ic, TRUE );
    150152                return FALSE;
    151153        }
    152         write( sd->fd, buf, len );
     154        ssl_write( sd->ssl, buf, len );
    153155
    154156        return TRUE;
     
    210212                return FALSE;
    211213        /* Read the whole data. */
    212         st = read( sd->fd, buf, sizeof( buf ) );
     214        st = ssl_read( sd->ssl, buf, sizeof( buf ) );
    213215        if( st > 0 )
    214216        {
     
    720722                                }
    721723                        }
     724                        else if(!strncmp(line, "PASSWORD ", 9))
     725                        {
     726                                if(!strncmp(line+9, "OK", 2))
     727                                        imcb_connected(ic);
     728                                else
     729                                {
     730                                        imcb_error(ic, "Authentication Failed");
     731                                        imc_logout( ic, TRUE );
     732                                }
     733                        }
    722734                        lineptr++;
    723735                }
     
    766778}
    767779
    768 gboolean skype_connected( gpointer data, gint source, b_input_condition cond )
     780gboolean skype_connected( gpointer data, void *source, b_input_condition cond )
    769781{
    770782        struct im_connection *ic = data;
    771         imcb_connected(ic);
     783        struct skype_data *sd = ic->proto_data;
     784        if(!source)
     785        {
     786                sd->ssl = NULL;
     787                imcb_error( ic, "Could not connect to server" );
     788                imc_logout( ic, TRUE );
     789                return FALSE;
     790        }
     791        imcb_log( ic, "Connected to server, logging in" );
    772792        return skype_start_stream(ic);
    773793}
     
    781801
    782802        imcb_log( ic, "Connecting" );
    783         sd->fd = proxy_connect(set_getstr( &acc->set, "server" ), set_getint( &acc->set, "port" ), skype_connected, ic );
     803        sd->ssl = ssl_connect(set_getstr( &acc->set, "server" ), set_getint( &acc->set, "port" ), skype_connected, ic );
     804        sd->fd = sd->ssl ? ssl_getfd( sd->ssl ) : -1;
    784805        sd->username = g_strdup( acc->user );
    785806
  • skype/skyped.conf.dist.in

    re65ceaa rc7304b2  
    33# use `echo -n foo|sha1sum` to generate this hash for your password
    44password = 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33
     5cert = @sysconfdir@/skyped/skyped.cert.pem
     6key  = @sysconfdir@/skyped/skyped.key.pem
  • skype/skyped.py

    re65ceaa rc7304b2  
    3737import sha
    3838from ConfigParser import ConfigParser
     39from OpenSSL import SSL
    3940
    4041__version__ = "0.1.1"
     
    6768
    6869def server(host, port):
    69         sock = socket.socket()
     70        global options
     71
     72        ctx = SSL.Context(SSL.TLSv1_METHOD)
     73        ctx.use_privatekey_file(options.config.sslkey)
     74        ctx.use_certificate_file(options.config.sslcert)
     75        sock = SSL.Connection(ctx, socket.socket())
    7076        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    7177        sock.bind((host, port))
     
    7682        global options
    7783        options.conn, addr = sock.accept()
    78         lines = options.conn.recv(512).split('\n')
    7984        ret = 0
    80         nlines = []
    81         for i in lines:
    82                 if i.startswith("USERNAME") and i.split(' ')[1].strip() == options.config.username:
    83                         ret += 1
    84                 elif i.startswith("PASSWORD") and sha.sha(i.split(' ')[1].strip()).hexdigest() == options.config.password:
    85                         ret += 1
    86                 else:
    87                         nlines.append(i)
    88         del lines
     85        line = options.conn.recv(1024)
     86        if line.startswith("USERNAME") and line.split(' ')[1].strip() == options.config.username:
     87                ret += 1
     88        line = options.conn.recv(1024)
     89        if line.startswith("PASSWORD") and sha.sha(line.split(' ')[1].strip()).hexdigest() == options.config.password:
     90                ret += 1
    8991        if ret == 2:
    9092                dprint("Username and password OK.")
    91                 options.buf = nlines
    92                 input_handler(None, None)
     93                options.conn.send("PASSWORD OK\n")
    9394                gobject.io_add_watch(options.conn, gobject.IO_IN, input_handler)
    9495                return True
    9596        else:
    9697                dprint("Username and/or password WRONG.")
     98                options.conn.send("PASSWORD KO\n")
    9799                return False
    98100
     
    153155class Options:
    154156        def __init__(self):
    155                 self.cfgpath = "/etc/skyped.conf"
     157                self.cfgpath = "/usr/local/etc/skyped/skyped.conf"
    156158                self.daemon = True
    157159                self.debug = False
     
    217219        options.config.username = options.config.get('skyped', 'username').split('#')[0]
    218220        options.config.password = options.config.get('skyped', 'password').split('#')[0]
     221        options.config.sslkey = options.config.get('skyped', 'key').split('#')[0]
     222        options.config.sslcert = options.config.get('skyped', 'cert').split('#')[0]
    219223        dprint("Parsing config file '%s' done, username is '%s'." % (options.cfgpath, options.config.username))
    220224        if options.daemon:
Note: See TracChangeset for help on using the changeset viewer.