Index: skype/Makefile
===================================================================
--- skype/Makefile	(revision e65ceaa6ba982fbfe14cfa191a56279f61c58a91)
+++ skype/Makefile	(revision c7304b27f173fed8e2a68272186b1575937ef98b)
@@ -12,5 +12,5 @@
 	$(INSTALL) skype.so $(DESTDIR)$(plugindir)
 	$(INSTALL) skyped.py $(DESTDIR)$(bindir)/skyped
-	sed -i 's|/etc|$(sysconfdir)|' $(DESTDIR)$(bindir)/skyped
+	sed -i 's|/usr/local/etc/skyped|$(sysconfdir)|' $(DESTDIR)$(bindir)/skyped
 	$(INSTALL) -m644 skyped.conf.dist $(DESTDIR)$(sysconfdir)/skyped.conf
 
Index: skype/config.mak.in
===================================================================
--- skype/config.mak.in	(revision e65ceaa6ba982fbfe14cfa191a56279f61c58a91)
+++ skype/config.mak.in	(revision c7304b27f173fed8e2a68272186b1575937ef98b)
@@ -3,5 +3,5 @@
 INSTALL = @INSTALL@
 prefix = @prefix@
-sysconfdir = @sysconfdir@
+sysconfdir = @sysconfdir@/skyped
 exec_prefix = @exec_prefix@
 bindir = @bindir@
Index: skype/configure.ac
===================================================================
--- skype/configure.ac	(revision e65ceaa6ba982fbfe14cfa191a56279f61c58a91)
+++ skype/configure.ac	(revision c7304b27f173fed8e2a68272186b1575937ef98b)
@@ -17,2 +17,3 @@
 LDFLAGS="$LDFLAGS $BITLBEE_LIBS"
 AC_OUTPUT(config.mak)
+AC_OUTPUT(skyped.conf.dist)
Index: skype/skype.c
===================================================================
--- skype/skype.c	(revision e65ceaa6ba982fbfe14cfa191a56279f61c58a91)
+++ skype/skype.c	(revision c7304b27f173fed8e2a68272186b1575937ef98b)
@@ -28,4 +28,5 @@
 #include <poll.h>
 #include <bitlbee.h>
+#include <bitlbee/ssl_client.h>
 #include <glib.h>
 
@@ -63,4 +64,6 @@
 	 * we're connected and when we aren't. */
 	int bfd;
+	/* ssl_getfd() uses this to get the file desciptor. */
+	void *ssl;
 	/* When we receive a new message id, we query the properties, finally
 	 * the chatname. Store the properties here so that we can use
@@ -146,9 +149,8 @@
 	if(pfd[0].revents & POLLHUP)
 	{
-		imcb_error( ic, "Could not connect to server" );
 		imc_logout( ic, TRUE );
 		return FALSE;
 	}
-	write( sd->fd, buf, len );
+	ssl_write( sd->ssl, buf, len );
 
 	return TRUE;
@@ -210,5 +212,5 @@
 		return FALSE;
 	/* Read the whole data. */
-	st = read( sd->fd, buf, sizeof( buf ) );
+	st = ssl_read( sd->ssl, buf, sizeof( buf ) );
 	if( st > 0 )
 	{
@@ -720,4 +722,14 @@
 				}
 			}
+			else if(!strncmp(line, "PASSWORD ", 9))
+			{
+				if(!strncmp(line+9, "OK", 2))
+					imcb_connected(ic);
+				else
+				{
+					imcb_error(ic, "Authentication Failed");
+					imc_logout( ic, TRUE );
+				}
+			}
 			lineptr++;
 		}
@@ -766,8 +778,16 @@
 }
 
-gboolean skype_connected( gpointer data, gint source, b_input_condition cond )
+gboolean skype_connected( gpointer data, void *source, b_input_condition cond )
 {
 	struct im_connection *ic = data;
-	imcb_connected(ic);
+	struct skype_data *sd = ic->proto_data;
+	if(!source)
+	{
+		sd->ssl = NULL;
+		imcb_error( ic, "Could not connect to server" );
+		imc_logout( ic, TRUE );
+		return FALSE;
+	}
+	imcb_log( ic, "Connected to server, logging in" );
 	return skype_start_stream(ic);
 }
@@ -781,5 +801,6 @@
 
 	imcb_log( ic, "Connecting" );
-	sd->fd = proxy_connect(set_getstr( &acc->set, "server" ), set_getint( &acc->set, "port" ), skype_connected, ic );
+	sd->ssl = ssl_connect(set_getstr( &acc->set, "server" ), set_getint( &acc->set, "port" ), skype_connected, ic );
+	sd->fd = sd->ssl ? ssl_getfd( sd->ssl ) : -1;
 	sd->username = g_strdup( acc->user );
 
Index: ype/skyped.conf.dist
===================================================================
--- skype/skyped.conf.dist	(revision e65ceaa6ba982fbfe14cfa191a56279f61c58a91)
+++ 	(revision )
@@ -1,4 +1,0 @@
-[skyped]
-username = john
-# use `echo -n foo|sha1sum` to generate this hash for your password
-password = 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33
Index: skype/skyped.conf.dist.in
===================================================================
--- skype/skyped.conf.dist.in	(revision c7304b27f173fed8e2a68272186b1575937ef98b)
+++ skype/skyped.conf.dist.in	(revision c7304b27f173fed8e2a68272186b1575937ef98b)
@@ -0,0 +1,6 @@
+[skyped]
+username = john
+# use `echo -n foo|sha1sum` to generate this hash for your password
+password = 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33
+cert = @sysconfdir@/skyped/skyped.cert.pem
+key  = @sysconfdir@/skyped/skyped.key.pem
Index: skype/skyped.py
===================================================================
--- skype/skyped.py	(revision e65ceaa6ba982fbfe14cfa191a56279f61c58a91)
+++ skype/skyped.py	(revision c7304b27f173fed8e2a68272186b1575937ef98b)
@@ -37,4 +37,5 @@
 import sha
 from ConfigParser import ConfigParser
+from OpenSSL import SSL
 
 __version__ = "0.1.1"
@@ -67,5 +68,10 @@
 
 def server(host, port):
-	sock = socket.socket()
+	global options
+
+	ctx = SSL.Context(SSL.TLSv1_METHOD)
+	ctx.use_privatekey_file(options.config.sslkey)
+	ctx.use_certificate_file(options.config.sslcert)
+	sock = SSL.Connection(ctx, socket.socket())
 	sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
 	sock.bind((host, port))
@@ -76,23 +82,19 @@
 	global options
 	options.conn, addr = sock.accept()
-	lines = options.conn.recv(512).split('\n')
 	ret = 0
-	nlines = []
-	for i in lines:
-		if i.startswith("USERNAME") and i.split(' ')[1].strip() == options.config.username:
-			ret += 1
-		elif i.startswith("PASSWORD") and sha.sha(i.split(' ')[1].strip()).hexdigest() == options.config.password:
-			ret += 1
-		else:
-			nlines.append(i)
-	del lines
+	line = options.conn.recv(1024)
+	if line.startswith("USERNAME") and line.split(' ')[1].strip() == options.config.username:
+		ret += 1
+	line = options.conn.recv(1024)
+	if line.startswith("PASSWORD") and sha.sha(line.split(' ')[1].strip()).hexdigest() == options.config.password:
+		ret += 1
 	if ret == 2:
 		dprint("Username and password OK.")
-		options.buf = nlines
-		input_handler(None, None)
+		options.conn.send("PASSWORD OK\n")
 		gobject.io_add_watch(options.conn, gobject.IO_IN, input_handler)
 		return True
 	else:
 		dprint("Username and/or password WRONG.")
+		options.conn.send("PASSWORD KO\n")
 		return False
 
@@ -153,5 +155,5 @@
 class Options:
 	def __init__(self):
-		self.cfgpath = "/etc/skyped.conf"
+		self.cfgpath = "/usr/local/etc/skyped/skyped.conf"
 		self.daemon = True
 		self.debug = False
@@ -217,4 +219,6 @@
 	options.config.username = options.config.get('skyped', 'username').split('#')[0]
 	options.config.password = options.config.get('skyped', 'password').split('#')[0]
+	options.config.sslkey = options.config.get('skyped', 'key').split('#')[0]
+	options.config.sslcert = options.config.get('skyped', 'cert').split('#')[0]
 	dprint("Parsing config file '%s' done, username is '%s'." % (options.cfgpath, options.config.username))
 	if options.daemon:
