Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 93213 | Differences between
and this patch

Collapse All | Expand All

(-)kdenetwork-3.4.0.orig/kopete/protocols/msn/Makefile.am (-1 / +2 lines)
Lines 13-19 Link Here
13
libkopete_msn_shared_la_SOURCES = msnprotocol.cpp msnaccount.cpp msnaddcontactpage.cpp msncontact.cpp \
13
libkopete_msn_shared_la_SOURCES = msnprotocol.cpp msnaccount.cpp msnaddcontactpage.cpp msncontact.cpp \
14
	msnsocket.cpp msnmessagemanager.cpp msndebugrawcmddlg.cpp \
14
	msnsocket.cpp msnmessagemanager.cpp msndebugrawcmddlg.cpp \
15
	msnnotifysocket.cpp msnswitchboardsocket.cpp msnfiletransfersocket.cpp msninvitation.cpp \
15
	msnnotifysocket.cpp msnswitchboardsocket.cpp msnfiletransfersocket.cpp msninvitation.cpp \
16
	msnp2p.cpp msnp2pdisplatcher.cpp msnp2pincoming.cpp msnp2poutgoing.cpp sha1.cpp
16
	msnp2p.cpp msnp2pdisplatcher.cpp msnp2pincoming.cpp msnp2poutgoing.cpp sha1.cpp \
17
	sslloginhandler.cpp
17
18
18
libkopete_msn_shared_la_LIBADD  = ./ui/libkopetemsnui.la ../../libkopete/libkopete.la $(LIB_KIO)
19
libkopete_msn_shared_la_LIBADD  = ./ui/libkopetemsnui.la ../../libkopete/libkopete.la $(LIB_KIO)
19
libkopete_msn_shared_la_LDFLAGS = -version-info 0:0:0 -no-undefined $(all_libraries)
20
libkopete_msn_shared_la_LDFLAGS = -version-info 0:0:0 -no-undefined $(all_libraries)
(-)kdenetwork-3.4.0.orig/kopete/protocols/msn/msnnotifysocket.cpp (-88 / +24 lines)
Lines 23-28 Link Here
23
#include "msnnotifysocket.h"
23
#include "msnnotifysocket.h"
24
#include "msncontact.h"
24
#include "msncontact.h"
25
#include "msnaccount.h"
25
#include "msnaccount.h"
26
#include "sslloginhandler.h"
26
27
27
#include <qregexp.h>
28
#include <qregexp.h>
28
29
Lines 48-54 Link Here
48
: MSNSocket( account )
49
: MSNSocket( account )
49
{
50
{
50
	m_newstatus = MSNProtocol::protocol()->NLN;
51
	m_newstatus = MSNProtocol::protocol()->NLN;
51
	
52
	m_sslLoginHandler=0l;
53
52
	m_isHotmailAccount=false;
54
	m_isHotmailAccount=false;
53
	m_ping=false;
55
	m_ping=false;
54
56
Lines 65-70 Link Here
65
67
66
MSNNotifySocket::~MSNNotifySocket()
68
MSNNotifySocket::~MSNNotifySocket()
67
{
69
{
70
	delete m_sslLoginHandler;
68
	kdDebug(14140) << k_funcinfo << endl;
71
	kdDebug(14140) << k_funcinfo << endl;
69
}
72
}
70
73
Lines 248-254 Link Here
248
	
251
	
249
	if ( cmd == "VER" )
252
	if ( cmd == "VER" )
250
	{
253
	{
251
		sendCommand( "CVR", "0x0409 winnt 5.1 i386 MSNMSGR 6.0.0602 MSMSGS " + m_account->accountId() );
254
		sendCommand( "CVR", "0x0409 winnt 5.1 i386 MSNMSGR 6.2.0205 MSMSGS " + m_account->accountId() );
252
/*
255
/*
253
		struct utsname utsBuf;
256
		struct utsname utsBuf;
254
		uname ( &utsBuf );
257
		uname ( &utsBuf );
Lines 266-291 Link Here
266
	{
269
	{
267
		if( data.section( ' ', 1, 1 ) == "S" )
270
		if( data.section( ' ', 1, 1 ) == "S" )
268
		{
271
		{
269
			m_authData=data.section( ' ' , 2 , 2 );
272
			m_sslLoginHandler = new SslLoginHandler();
270
			m_kv=QString::null;
273
			QObject::connect( m_sslLoginHandler, SIGNAL(       loginFailed()        ),
274
					 this,            SLOT  (    sslLoginFailed()        ) );
275
			QObject::connect( m_sslLoginHandler, SIGNAL(    loginIncorrect()        ),
276
					 this,            SLOT  ( sslLoginIncorrect()        ) );
277
			QObject::connect( m_sslLoginHandler, SIGNAL(    loginSucceeded(QString) ),
278
					 this,            SLOT  ( sslLoginSucceeded(QString) ) );
271
279
272
			if( m_account->accountId().contains("@hotmail.") )
280
			m_sslLoginHandler->login( data.section( ' ' , 2 , 2 ), m_account->accountId() , m_password );
273
				m_sid="loginnet.passport.com";
274
			else if( m_account->accountId().contains("@msn.") ||  m_account->accountId().contains("@compaq.net") ||  m_account->accountId().contains("@webtv.net") )
275
				m_sid="msnialogin.passport.com";
276
			else
277
				m_sid="login.passport.com";
278
279
			QString authURL="https://"+m_sid+"/login.srf?" + m_authData;
280
			authURL.replace("," , "&" ) ;
281
282
			kdDebug(14140) << k_funcinfo << "downlaod URL: " << authURL << endl;
283
284
			KIO::Job *job = KIO::get( KURL( authURL ), true, false );
285
			job->addMetaData("cookies", "manual");
286
			// This should force kio to download the page even is we are in the konqueror offline mode.  [see bug #68483]
287
			job->addMetaData("cache", "reload");
288
			QObject::connect( job, SIGNAL(result( KIO::Job *)), this, SLOT(slotAuthJobDone( KIO::Job *)) );
289
		}
281
		}
290
		else
282
		else
291
		{
283
		{
Lines 582-657 Link Here
582
}
574
}
583
575
584
576
585
void MSNNotifySocket::slotAuthJobDataReceived ( KIO::Job */*job*/,const  QByteArray &data)
577
void MSNNotifySocket::sslLoginFailed()
586
{
578
{
587
	m_authData += QCString( data, data.size()+1 );
579
	disconnect();
588
//	kdDebug(14140) << "MSNNotifySocket::slotAuthJobDataReceived: " << data << endl;
589
}
580
}
590
581
void MSNNotifySocket::sslLoginIncorrect()
591
void MSNNotifySocket::slotAuthJobDone ( KIO::Job *job)
592
{
582
{
593
//	kdDebug(14140) << "MSNNotifySocket::slotAuthJobDone: "<< m_authData << endl;
583
	m_badPassword = true;
594
584
	disconnect();
595
	if(job->error())
585
}
596
	{
586
void MSNNotifySocket::sslLoginSucceeded(QString a)
597
		//FIXME: Shouldn't we say that we are the MSN plugin?
587
{
598
		job->showErrorDialog();
588
	sendCommand("USR" , "TWN S " + a);
599
		disconnect();
589
	m_sslLoginHandler->deleteLater();
600
		return;
590
	m_sslLoginHandler=0;
601
	}
602
603
	if(m_kv.isNull())
604
	{
605
		QStringList cookielist=QStringList::split("\n", job->queryMetaData("setcookies") );
606
		QString cookies="Cookie: ";
607
		for ( QStringList::Iterator it = cookielist.begin(); it != cookielist.end(); ++it )
608
		{
609
			QRegExp rx("Set-Cookie: ([^;]*)");
610
			rx.search(*it);
611
			cookies+=rx.cap(1)+";";
612
		}
613
614
		//QRegExp rx("lc=([1-9]*),id=([1-9]*),tw=([1-9]*),fs=[1-9]*,ru=[1-9a-zA-Z%]*,ct=[1-9]*,kpp=[1-9]*,kv=([1-9]*),");
615
		QRegExp rx("lc=([0-9]*),id=([0-9]*),tw=([0-9]*),.*kv=([0-9]*),");
616
		rx.search(m_authData);
617
618
		QString authURL = "https://" + m_sid + "/ppsecure/post.srf?lc=" + rx.cap( 1 ) + "&id=" +
619
			rx.cap( 2 ) + "&tw=" + rx.cap( 3 ) + "&cbid=" + rx.cap( 2 ) + "&da=passport.com&login=" +
620
			KURL::encode_string( m_account->accountId()) + "&domain=passport.com&passwd=";
621
622
		kdDebug( 14140 ) << k_funcinfo << "Download URL: " << authURL << "(*******)" << endl;
623
624
		m_authData = QString::null;
625
		m_kv=rx.cap(4);
626
		if(m_kv.isNull()) m_kv="";
627
628
		authURL += KURL::encode_string( m_password ) ;
629
		job = KIO::get( KURL( authURL ), false, false );
630
		job->addMetaData("cookies", "manual");
631
		job->addMetaData("setcookies", cookies);
632
		job->addMetaData("cache", "reload");
633
634
		QObject::connect( job, SIGNAL(data( KIO::Job *,const QByteArray&)), this, SLOT(slotAuthJobDataReceived( KIO::Job *,const QByteArray&)) );
635
		QObject::connect( job, SIGNAL(result( KIO::Job *)), this, SLOT(slotAuthJobDone( KIO::Job *)) );
636
	}
637
	else
638
	{
639
		if(m_authData.contains("CookiesDisabled"))
640
		{
641
			// FIXME: is this still possible now we add our meta data? - Martijn
642
			disconnect();
643
			KMessageBox::queuedMessageBox( Kopete::UI::Global::mainWidget(), KMessageBox::Error,
644
				i18n( "Unable to connect to the MSN Network.\nYour Web browser options are currently set to disable cookies.\n"
645
				"To use .NET Passport, you must enable cookies at least for the passport.com domain" ), i18n( "MSN Plugin" ) );
646
			return;
647
		}
648
649
		QRegExp rx(/*URL=http://memberservices.passport.net/memberservice.srf*/"\\?did=[0-9]*&(t=[0-9A-Za-z!$*]*&p=[0-9A-Za-z!$*]*)\"");
650
		rx.search(m_authData);
651
652
		m_badPassword=true;  //if this disconnect, that mean the password was bad
653
		sendCommand("USR" , "TWN S " + rx.cap(1));
654
	}
655
}
591
}
656
592
657
593
(-)kdenetwork-3.4.0.orig/kopete/protocols/msn/msnnotifysocket.h (-4 / +5 lines)
Lines 29-34 Link Here
29
class MSNDispatchSocket;
29
class MSNDispatchSocket;
30
class MSNAccount;
30
class MSNAccount;
31
class KTempFile;
31
class KTempFile;
32
class SslLoginHandler;
32
33
33
#include <kio/job.h>
34
#include <kio/job.h>
34
35
Lines 137-145 Link Here
137
	void slotResetKeepAlive();
138
	void slotResetKeepAlive();
138
139
139
140
140
141
	void sslLoginFailed();
141
	void slotAuthJobDataReceived ( KIO::Job *, const QByteArray &data);
142
	void sslLoginIncorrect();
142
	void slotAuthJobDone ( KIO::Job *);
143
	void sslLoginSucceeded(QString);
143
144
144
145
145
private:
146
private:
Lines 170-176 Link Here
170
	QString m_kv;
171
	QString m_kv;
171
	QString m_sid;
172
	QString m_sid;
172
	QString m_loginTime;
173
	QString m_loginTime;
173
	QString m_authData;
174
	SslLoginHandler *m_sslLoginHandler;
174
175
175
	QTimer *m_keepaliveTimer;
176
	QTimer *m_keepaliveTimer;
176
177
(-)kdenetwork-3.4.0.orig/kopete/protocols/msn/msnsocket.cpp (-1 / +1 lines)
Lines 133-139 Link Here
133
133
134
void MSNSocket::slotSocketError( int error )
134
void MSNSocket::slotSocketError( int error )
135
{
135
{
136
	kdWarning( 14140 ) << k_funcinfo << "Error: " << error << endl;
136
	kdWarning( 14140 ) << k_funcinfo << "Error: " << error << " (" << m_socket->errorString() << ")" << endl;
137
137
138
	if(!KSocketBase::isFatalError(error))
138
	if(!KSocketBase::isFatalError(error))
139
		return;
139
		return;
(-)kdenetwork-3.4.0.orig/kopete/protocols/msn/sslloginhandler.cpp (+453 lines)
Line 0 Link Here
1
//Imported from KMess (2005-05-19)
2
3
/***************************************************************************
4
                          sslloginhandler.cpp  -  description
5
                             -------------------
6
    begin                : Sat Jun 28 2003
7
    copyright            : (C) 2003 by Mike K. Bennett
8
    email                : mkb137b@hotmail.com
9
 ***************************************************************************/
10
11
/***************************************************************************
12
 *                                                                         *
13
 *   This program is free software; you can redistribute it and/or modify  *
14
 *   it under the terms of the GNU General Public License as published by  *
15
 *   the Free Software Foundation; either version 2 of the License, or     *
16
 *   (at your option) any later version.                                   *
17
 *                                                                         *
18
 ***************************************************************************/
19
20
#include "sslloginhandler.h"
21
22
#include <qstringlist.h>
23
#include <qregexp.h>
24
#include <qsocket.h>
25
#include <qurl.h>
26
27
#include <kdebug.h>
28
#include <kextsock.h>
29
#include <kssl.h>
30
#include <kurl.h>
31
32
#if 0
33
#include "../kmessdebug.h"
34
#include "mimemessage.h"
35
#else
36
//i didn't want to import the whole MimeMessage from Kmess for Kopete so i
37
// reimplemented the base here  -Olivier
38
39
class MimeMessage
40
{
41
	public:
42
		MimeMessage(const QString &msg) : message(msg) {}
43
44
		QString getValue(const QString &key)
45
		{
46
			QRegExp rx(key+": (.*)\n");
47
			rx.search(message);
48
			return rx.cap(1);
49
		}
50
	private:
51
		QString message;
52
};
53
54
#include "sslloginhandler.moc"
55
#endif
56
//there is nothing modified from here.  this is exactly the kmerlin code
57
58
59
60
/*
61
 * Great documentation about this can be found at
62
 * http://siebe.bot2k3.net/docs/
63
 */
64
65
66
// The constructor
67
SslLoginHandler::SslLoginHandler()
68
 : mode_(NONE)
69
{
70
  // Create the SSL handler
71
  ssl_ = new KSSL( true );
72
73
  // Create and set up the socket.
74
  socket_ = new KExtendedSocket( );
75
76
  //socket_->setSocketFlags( 0x00 | 0x600000 ); // 0x00 = anySocket | 0x600000 = bufferedSocket
77
  socket_->setSocketFlags( 0x00 ); // 0x00 = anySocket | 0x600000 = bufferedSocket
78
  socket_->setTimeout( 30   );
79
  socket_->enableRead( true );
80
  connect( socket_, SIGNAL(         readyRead()    ),
81
           this,    SLOT  (      dataReceived()    ) );
82
  connect( socket_, SIGNAL(  connectionFailed(int) ),
83
           this,    SLOT  (       socketError(int) ) );
84
}
85
86
87
88
// The destructor
89
SslLoginHandler::~SslLoginHandler()
90
{
91
  delete ssl_;
92
  delete socket_;
93
}
94
95
96
97
// Data was received over the socket
98
void SslLoginHandler::dataReceived()
99
{
100
#ifdef KMESSDEBUG_SSLLOGINHANDLER
101
  kdDebug() << "SslLoginHandler - ******************** Data received ********************" << endl;
102
  kdDebug() << "SslLoginHandler - " << socket_->bytesAvailable() << " bytes available." << endl;
103
  kdDebug() << "SslLoginHandler - SSL says " << ssl_->pending() << " bytes available." << endl;
104
#endif
105
106
  QString   data;
107
  int       breakOut = 0;
108
  const int maxIterations = 1000;
109
  while ( ( !data.contains( QRegExp("\r\n") ) ) && ( breakOut < maxIterations ) )
110
  {
111
    // Read data via SSL
112
    data = readSslData();
113
    breakOut ++;
114
  }
115
116
  // Output the data for debugging
117
#ifdef KMESSDEBUG_SSLLOGINHANDLER
118
  kdDebug() << "SslLoginHandler - ********************   Contents    ********************" << endl;
119
  kdDebug() << data << endl;
120
  kdDebug() << "SslLoginHandler - ********************  End of data  ********************" << endl;
121
#endif
122
123
  // Warn if timed out
124
  if ( breakOut >= maxIterations )
125
  {
126
    kdDebug() << "WARNING - SSL read timed out." << endl;
127
    emit loginFailed();
128
    return;
129
  }
130
131
  if ( data.length() > 0 )
132
  {
133
    parseHttpResponse(data);
134
  }
135
  else
136
  {
137
    kdDebug() << "WARNING - Available data wasn't read from the SSL socket." << endl;
138
    emit loginFailed();
139
  }
140
}
141
142
143
144
// Start the login process
145
void SslLoginHandler::login( QString parameters, QString handle, QString password )
146
{
147
#ifdef KMESSDEBUG_SSLLOGINHANDLER
148
  kdDebug() << "SslLoginHandler - Starting login with parameters " << parameters << "." << endl;
149
#endif
150
151
  // Store the given data
152
  authenticationParameters_ = parameters;
153
  handle_                   = handle;
154
  password_                 = password;
155
156
  // Get the login server
157
  sendLoginServerRequest("nexus.passport.com");
158
  dataReceived();
159
}
160
161
162
163
// Get the authentication data from a string
164
void SslLoginHandler::parseAuthenticationData( QString data )
165
{
166
  QString twnData;
167
168
  // Pull TWN data out of the message
169
  twnData = data.right( data.length() - data.find(QRegExp("from-PP='")) - 9 );
170
  twnData = twnData.left( twnData.find(QRegExp("',")) );
171
172
#ifdef KMESSDEBUG_SSLLOGINHANDLER
173
  kdDebug() << "SslLoginHandler - data for TWN is " << twnData << "." << endl;
174
#endif
175
176
  // Notify the MsnNotificationConnection
177
  emit loginSucceeded(twnData);
178
}
179
180
181
182
// Parse the HTTP response from the server
183
void SslLoginHandler::parseHttpResponse(QString data)
184
{
185
  KURL    location;
186
  int     headerEnd;
187
  QString header;
188
  int     headerCode;
189
  QString headerText;
190
191
  // Parse the HTTP status header
192
  QRegExp re("HTTP/\\d+\\.\\d+ (\\d+) ([^\r\n]+)");
193
  headerEnd  = data.find("\r\n");
194
  header     = data.left( (headerEnd == -1) ? 20 : headerEnd );
195
196
  re.search(header);
197
  headerCode = re.cap(1).toUInt();
198
  headerText = re.cap(2);
199
200
  // Create a MimeMessage, removing the HTTP status header
201
  MimeMessage message( data.section( ",", 1 ) );
202
203
204
  switch(mode_)
205
  {
206
    case GETLOGINSERVER:
207
    {
208
      // Step 1. This data describes the login server to use.
209
      if(headerCode == 302)
210
      {
211
        // HTTP Redirect
212
        location = KURL( message.getValue( "Location" ) );
213
        sendLoginServerRequest(location.host());
214
      }
215
      else
216
      {
217
        // Parse the data
218
        QString loginServer;
219
        QString page;
220
        parseLoginServerData( loginServer, page, message.getValue("PassportURLs") );
221
222
        // Send the authentication request
223
        sendAuthenticationRequest( loginServer, page );
224
      }
225
      break;
226
    }
227
    case GETAUTHENTICATIONDATA:
228
    {
229
      // Step 2. Get the authentication data
230
      if(headerCode == 200)
231
      {
232
        // Login success
233
        parseAuthenticationData(message.getValue("Authentication-Info"));
234
      }
235
      else if(headerCode == 302)
236
      {
237
        // HTTP Redirect
238
        location = KURL( message.getValue( "Location" ) );
239
        sendAuthenticationRequest(location.host(), location.path());
240
      }
241
      else if(headerCode == 401)
242
      {
243
        // Got a HTTP "401 Unauthorized"; Login failed
244
        emit loginIncorrect();
245
      }
246
      else
247
      {
248
        kdDebug() << "SslLoginHandler::parseHttpResponse: WARNING "
249
                  << "- Unhandled response code " << headerCode << " " << headerText << endl;
250
        emit loginFailed();
251
      }
252
      break;
253
    }
254
    default:
255
    {
256
      kdDebug() << "SslLoginHandler::parseHttpResponse: WARNING - Entered illegal state" << endl;
257
      emit loginFailed();
258
    }
259
  }
260
}
261
262
263
// Get login server data from a string
264
void SslLoginHandler::parseLoginServerData( QString &host, QString &page, QString serverData )
265
{
266
  int slashIndex;
267
268
  // Get everything between "DLLogin=" and to the comma.
269
  serverData = serverData.right( serverData.length() - serverData.find( "DALogin=" ) - 8 );
270
  serverData = serverData.left( serverData.find( "," ) );
271
272
#ifdef KMESSDEBUG_SSLLOGINHANDLER
273
  kdDebug() << "SslLoginHandler - host/page=" << serverData << endl;
274
#endif
275
276
  // Separate the "host/page" string.
277
  slashIndex = serverData.find( "/" );
278
  host = serverData.left( slashIndex );
279
  page = serverData.right( serverData.length() - slashIndex );
280
281
#ifdef KMESSDEBUG_SSLLOGINHANDLER
282
  kdDebug() << "SslLoginHandler - host=" << host << " page=" << page << endl;
283
#endif
284
}
285
286
287
288
// Read data from the socket via SSL
289
QString SslLoginHandler::readSslData()
290
{
291
  char       rawblock[1024];
292
  QCString   block;
293
  QString    data        = "";
294
  int        noBytesRead = 1;
295
296
  // Read data from the SSL socket.
297
  if ( ssl_ != 0 )
298
  {
299
//    while( ( ssl_->pending() > 0 ) && ( noBytesRead > 0 ) )
300
//    while( ( socket_->bytesAvailable() > 0 ) && ( noBytesRead > 0 ) )
301
    while(noBytesRead > 0)
302
    {
303
      noBytesRead = ssl_->read( rawblock, 1024 );
304
#ifdef KMESSDEBUG_SSLLOGINHANDLER
305
      kdDebug() << "SslLoginHandler - " << noBytesRead << " bytes read." << endl;
306
#endif
307
      block = rawblock;
308
      block = block.left( noBytesRead );
309
      data += QString::fromUtf8( block );
310
    }
311
  }
312
313
  return data;
314
}
315
316
317
318
// Send the authenticationn request
319
void SslLoginHandler::sendAuthenticationRequest( QString loginServer, QString page )
320
{
321
#ifdef KMESSDEBUG_SSLLOGINHANDLER
322
  kdDebug() << "SslLoginHandler - Step 2. Requesting authentication data." << endl;
323
#endif
324
325
  QString request;
326
  QString encodedHandle   = handle_;
327
  QString encodedPassword = password_;
328
329
  QUrl::encode(encodedHandle);
330
  QUrl::encode(encodedPassword);
331
332
  request = "GET " + page + " HTTP/1.1\r\n"
333
            "Authorization: Passport1.4"
334
              " OrgVerb=GET"
335
              ",OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom"
336
              ",sign-in=" + encodedHandle +
337
              ",pwd="     + encodedPassword +
338
              ","         + authenticationParameters_ + "\r\n"
339
            "User-Agent: MSMSGS\r\n"     // Make sure the server won't discriminate
340
            "Host: " + loginServer + "\r\n"
341
            "Connection: Keep-Alive\r\n"
342
            "Cache-Control: no-cache\r\n\r\n";
343
344
  // Step 2. Send the authorisation request
345
  mode_ = GETAUTHENTICATIONDATA;
346
  sendHttpRequest( request, loginServer, 443 );
347
}
348
349
350
351
// Send a HTTP request to the server
352
void SslLoginHandler::sendHttpRequest( QString request, QString host, int port )
353
{
354
  QString response;
355
  QString responseBody;
356
357
  if ( socket_ == 0 )
358
  {
359
    kdDebug() << "SslLoginHandler::sendHttpRequest - WARNING "
360
              << "- Trying to login using a null socket." << endl;
361
    return;
362
  }
363
364
  // Configure the socket
365
#ifdef KMESSDEBUG_SSLLOGINHANDLER
366
  kdDebug() << "SslLoginHandler - Close and reset the socket." << endl;
367
#endif
368
  ssl_->setAutoReconfig( true );
369
  ssl_->reInitialize();
370
  socket_->closeNow();
371
  socket_->reset();
372
373
  // Try to connect
374
#ifdef KMESSDEBUG_SSLLOGINHANDLER
375
  kdDebug() << "SslLoginHandler - Connecting to " << host << ":" << port << "." << endl;
376
#endif
377
  socket_->setAddress( host, port );
378
  socket_->lookup();
379
  int connectionSuccess = socket_->connect();
380
  if ( connectionSuccess != 0 )
381
  {
382
    kdDebug() << "SslLoginHandler::sendHttpRequest - WARNING "
383
              << "- Connection failed, giving " << connectionSuccess << endl;
384
    return;
385
  }
386
387
  // Try to wrap the SSL handler
388
#ifdef KMESSDEBUG_SSLLOGINHANDLER
389
  kdDebug() << "SslLoginHandler - Connection success, binding SSL to socket fd " << socket_->fd() << endl;
390
#endif
391
  int sslConnectionSuccess = ssl_->connect( socket_->fd() );
392
  if ( sslConnectionSuccess != 1 )
393
  {
394
    kdDebug() << "SslLoginHandler::sendHttpRequest - WARNING "
395
              << "- SSL Connection failed, giving " << sslConnectionSuccess << endl;
396
    return;
397
  }
398
399
  // Send the request
400
#ifdef KMESSDEBUG_SSLLOGINHANDLER
401
  kdDebug() << "SslLoginHandler - SSL connected OK, sending the request." << endl;
402
  kdDebug() << request;
403
#endif
404
  writeSslData( request );
405
}
406
407
408
409
// Request the name of the login server
410
void SslLoginHandler::sendLoginServerRequest(QString hostname)
411
{
412
#ifdef KMESSDEBUG_SSLLOGINHANDLER
413
  kdDebug() << "SslLoginHandler - Step 1. Requesting the login server." << endl;
414
#endif
415
416
  // Step 1. Send the login server request
417
  // The server will respond with the location of the main SSL server.
418
  mode_ = GETLOGINSERVER;
419
  sendHttpRequest( "GET /rdr/pprdr.asp\r\n\r\n", hostname, 443 );
420
}
421
422
423
424
// Detect a socket error
425
void SslLoginHandler::socketError(int error)
426
{
427
  kdDebug() << "SslLoginHandler : WARNING - Received error " << error << " from the socket." << endl;
428
}
429
430
431
432
// Write data to the socket via SSL
433
void SslLoginHandler::writeSslData( QString data )
434
{
435
  int noBytesWritten;
436
437
  if(socket_ != 0 && ssl_ != 0)
438
  {
439
    noBytesWritten = ssl_->write( data.latin1(), data.length() );
440
    if(noBytesWritten != (int)data.length())
441
    {
442
      kdDebug() << "WARNING - Wanted to write " << data.length() << " to the socket, "
443
                << " wrote " << noBytesWritten << "." << endl;
444
    }
445
#ifdef KMESSDEBUG_SSLLOGINHANDLER
446
    else
447
    {
448
      kdDebug() << "SslLoginHandler - Sent " << noBytesWritten << " bytes via SSL." << endl;
449
    }
450
#endif
451
  }
452
}
453
(-)kdenetwork-3.4.0.orig/kopete/protocols/msn/sslloginhandler.h (+96 lines)
Line 0 Link Here
1
//Imported from KMess  - 2005-05-19
2
3
/***************************************************************************
4
                          sslloginhandler.h  -  description
5
                             -------------------
6
    begin                : Sat Jun 28 2003
7
    copyright            : (C) 2003 by Mike K. Bennett
8
    email                : mkb137b@hotmail.com
9
 ***************************************************************************/
10
11
/***************************************************************************
12
 *                                                                         *
13
 *   This program is free software; you can redistribute it and/or modify  *
14
 *   it under the terms of the GNU General Public License as published by  *
15
 *   the Free Software Foundation; either version 2 of the License, or     *
16
 *   (at your option) any later version.                                   *
17
 *                                                                         *
18
 ***************************************************************************/
19
20
#ifndef SSLLOGINHANDLER_H
21
#define SSLLOGINHANDLER_H
22
23
#include <qobject.h>
24
#include <qstringlist.h>
25
26
// Forward declarations
27
class KExtendedSocket;
28
class KSSL;
29
class MimeMessage;
30
31
/**This class handles the SSL portion of the login.
32
  *@author Mike K. Bennett
33
  */
34
35
class SslLoginHandler : public QObject
36
{
37
   Q_OBJECT
38
39
  public:
40
    // The constructor
41
                         SslLoginHandler();
42
    // The destructor
43
                        ~SslLoginHandler();
44
    // Start the login process
45
    void                 login( QString parameters, QString handle, QString password );
46
47
  private : // Private methods
48
    // Get the authentication data from a string
49
    void                 parseAuthenticationData( QString data );
50
    // Parse the HTTP response from the server
51
    void                 parseHttpResponse(QString data);
52
    // Get login server data from a string
53
    void                 parseLoginServerData( QString &host, QString &page, QString serverData );
54
    // Read data from the socket via SSL
55
    QString              readSslData();
56
    // Send the authenticationn request
57
    void                 sendAuthenticationRequest( QString loginServer, QString page );
58
    // Send a HTTP request to the server
59
    void                 sendHttpRequest( QString request, QString host, int port );
60
    // Request the name of the login server
61
    void                 sendLoginServerRequest(QString hostname);
62
    // Write data to the socket via SSL
63
    void                 writeSslData( QString data );
64
65
  private slots : // Private slots
66
    // Data was received over the socket
67
    void                 dataReceived();
68
    // Detect a socket error
69
    void                 socketError(int error);
70
71
  private : // Private attributes
72
    // The mode of the transfer.
73
    enum Mode          { NONE = 0, GETLOGINSERVER = 1, GETAUTHENTICATIONDATA = 2 } mode_;
74
    // The list of parameters sent by the notification server
75
    QString              authenticationParameters_;
76
    // The cookies we received from the server
77
    QStringList          cookies_;
78
    // The user's handle
79
    QString              handle_;
80
    // The user's password
81
    QString              password_;
82
    // The socket over which the SSL data is written and read
83
    KExtendedSocket     *socket_;
84
    // The SSL handler
85
    KSSL                *ssl_;
86
87
  signals : // Public signals
88
    // Signal that the login was aborted because an internal error occured
89
    void                 loginFailed();
90
    // Signal that the login failed, username/password was incorrect
91
    void                 loginIncorrect();
92
    // Signal that the login succeeded
93
    void                 loginSucceeded( QString authentication );
94
};
95
96
#endif

Return to bug 93213