mIRC Homepage
Posted By: pouncer using ssl -e with sockopen - 10/05/09 09:13 PM
everytime i use sockopen -e .. the socket always ends up closing.i need to use ssl to connect to a messenger switchboard server for an msn messenger bot. any ideas why the socket would keep closing?
Posted By: argv0 Re: using ssl -e with sockopen - 11/05/09 12:54 AM
Probably because the remote host is closing the connection, either because it's not accepting SSL connections or mIRC doesn't support the handshake mechanism (there are subtle variations to the SSL protocol that mirc does not support)
Posted By: The_JD Re: using ssl -e with sockopen - 11/05/09 01:09 AM
Make sure you are using the latest version of mIRC.
When SSL was introduced to mIRC, if you attempted to send anything on sockopen, the connection would die.

The solution was to use a signal (without -n switch) to allow the sockopen event to complete before sending any data.
It was fixed in the next version
Posted By: pouncer Re: using ssl -e with sockopen - 15/05/09 12:39 PM
well i don't know what im doing wrong then. the msn server just isnt responding back correctly to me
Posted By: The_JD Re: using ssl -e with sockopen - 16/05/09 06:59 AM
Are you using mIRC v6.35?
Do you have the required DLL's in the mirc directory when mIRC loaded?

try this and post the output

//echo -a RES: 1 $version 2 $sslready 3 $isfile($mircdirssleay32.dll) 4 $isfile($mircdirlibeay32.dll)
Posted By: pouncer Re: using ssl -e with sockopen - 19/05/09 10:14 AM
Sorry for the late reply but it gives me

RES: 1 6.35 2 $true 3 $true 4 $true
Posted By: The_JD Re: using ssl -e with sockopen - 19/05/09 02:53 PM
Very strange, have you tried using one of the mIRC MSN clients from mIRCscripts.org?

My only guess is that you must be scripting something wrong, I guess you're having issues connecting to the switchboard... do you see the certificate acceptance dialog?
Posted By: pouncer Re: using ssl -e with sockopen - 19/05/09 03:15 PM
I'm not sure what it is, but after opening a socket using sockopen -e, i'm just not getting any response back from the server. i'm wanting to connect to messenger using the protocol 15.

Code:
alias email return bzerk_10@msn.com

alias msnlogin {
  sockopen initial messenger.hotmail.com 1863
}

on *:SOCKOPEN:initial: {
  sockwrite -n $sockname VER 0 MSNP15 CVR0
}

on *:SOCKREAD:initial: {
  var %x | sockread %x | tokenize 32 %x

  echo -a %x

  if ($1-3 == VER 0 MSNP15) {
    sockwrite -n $sockname CVR 1 0x0409 winnt 5.1 i386 MSNMSGR 8.0.0328 msmsgs bzerk_10@msn.com   
  }

  elseif ($1-2 == CVR 1) {
    sockwrite -n $sockname USR 2 TWN I bzerk_10@msn.com
  }

  ; redirection (need to use ssl when connecting to switchboard server - sockopen -e)
  elseif ($1 == XFR) {
    var %ip = $gettok($4,1,58)

    sockopen -e switchboard %ip 1863
  }
}

on *:SOCKOPEN:switchboard: {
  sockwrite -n $sockname VER 0 MSNP15 CVR0
}

on *:SOCKREAD:switchboard: {
  var %x | sockread %x | tokenize 32 %x

  echo -a %x
}


The switchboard socket just seems to close after i send:

sockwrite -n $sockname VER 0 MSNP15 CVR0

This is the documentation that I'm following:
http://209.85.229.132/search?q=cache:mvF1xSZB0IcJ:www.csse.monash.edu.au/courseware/cse1370/2006/Chat/mosim.doc+msnp14+authentication&cd=8&hl=en&ct=clnk&gl=uk

I hope someone can help me out here
Posted By: The_JD Re: using ssl -e with sockopen - 20/05/09 09:12 PM
Originally Posted By: pouncer

alias msnlogin {
sockopen initial messenger.hotmail.com 1863
}


err, that should be
Code:
sockopen -e initial...


edit: actually, I don't think the switchboard uses SSL at all, so both your sockopens shouldn't have -e

Sorry, I'm running from memory.
Basically, if the first sockopen is working, then the second one (redirect) dosn't need SSL.
If the first one isn't working - then you should be using -e for both sockopens.
The authentication server will require '-e' though.
Posted By: hixxy Re: using ssl -e with sockopen - 24/05/09 11:40 PM
MSNP15 returns an IP and a port to connect to in the XFR response.

Change this:

Code:
  elseif ($1 == XFR) {
    var %ip = $gettok($4,1,58)

    sockopen -e switchboard %ip 1863
  }


To this:

Code:
  elseif ($1 == XFR) {
    var %ip = $gettok($4,1,58), %port = $gettok($4,2,58)

    sockopen -e notification %ip %port
  }


Also, you are not connecting to the switchboard in the XFR response, you are connecting to the notification server.

The notification server is the server which sends details of your online contacts, where you send your status, personal message, etc.

The switchboard is a server that you connect to when you begin a conversation with a contact. You open a new switchboard connection for each conversation.
Posted By: pouncer Re: using ssl -e with sockopen - 25/05/09 11:07 AM
ok, thanks for the response guys. This is the code I have now:

Code:
alias email return bzerk_10@msn.com

alias msnlogin {
  sockopen initial messenger.hotmail.com 1863
}

on *:SOCKOPEN:initial: {
  sockwrite -n $sockname VER 0 MSNP15 CVR0
}

on *:SOCKREAD:initial: {
  var %x | sockread %x | tokenize 32 %x

  echo -a %x

  if ($1-3 == VER 0 MSNP15) {
    sockwrite -n $sockname CVR 1 0x0409 winnt 5.1 i386 MSNMSGR 8.0.0328 msmsgs bzerk_10@msn.com   
  }

  elseif ($1-2 == CVR 1) {
    sockwrite -n $sockname USR 2 TWN I bzerk_10@msn.com
  }

  ; redirection (need to use ssl when connecting to switchboard server - sockopen -e)
  elseif ($1 == XFR) {
    var %ip = $gettok($4,1,58)

    sockopen notification %ip 1863
  }
}

on *:SOCKOPEN:notification: {
  sockwrite -n $sockname VER 0 MSNP15 CVR0
}

on *:SOCKREAD:notification: {
  var %x | sockread %x | tokenize 32 %x

  echo -a %x

  if ($1-3 == VER 0 MSNP15) {
    sockwrite -n $sockname CVR 1 0x0409 winnt 5.1 i386 MSNMSGR 8.0.0328 msmsgs bzerk_10@msn.com   
  }

  elseif ($1-2 == CVR 1) {
    sockwrite -n $sockname USR 2 TWN I bzerk_10@msn.com
  }
}


The server is sending back GCF 0 6735 but i keep getting line too long erros after that:

Quote:

GCF 0 6735
-
* /tokenize: line too long (line 37, Test.mrc)
-
* /echo: insufficient parameters (line 39, Test.mrc)
-
* /tokenize: line too long (line 37, Test.mrc)
-
* /tokenize: line too long (line 37, Test.mrc)
-
* /tokenize: line too long (line 37, Test.mrc)
-


The GCF return from the server is something lie this:

GCF 0 6735\r\n
<some xml policy command here blah blah>\r\n
ticket=blah&profile=blah\r\n

and i need to pick out the ticket and profile to send the next USR command
Posted By: hixxy Re: using ssl -e with sockopen - 25/05/09 11:37 AM
You didn't do what I said:

Code:
  elseif ($1 == XFR) {
    var %ip = $gettok($4,1,58)

    sockopen notification %ip 1863
  }


Should be:

Code:
  elseif ($1 == XFR) {
    var %ip = $gettok($4,1,58), %port = $gettok($4,2,58)

    sockopen notification %ip %port
  }


MSN can and have been known to change the ports before, so I would advise you use the port the server tells you to use and not a hardcoded one.

As for your new problem, as soon as you receive the GCF response you need to start reading data into a binary variable, like this:

Code:
elseif ($1 == GCF) {
  sockread -f $3 &data
  var %start = $calc($bfind(&data,1,ticket=) + 7), %end = $calc($bfind(&data,%start,&profile=) - 1), %ticket = $bvar(&data,$+(%start,-,%end)).text
  var %start = $calc($bfind(&data,1,&profile=) + 9), %end = $calc($bfind(&data,%start,$crlf) - 1), %profile = $bvar(&data,$+(%start,-,%end)).text
  ; Do whatever you need to with %ticket and %profile here.
}


I'm not too sure how long the ticket and profile data is going to be, so you might still get line too long errors. If you do let me know and I'll try to make a full binary variable solution instead.

Also, general tip, when working with MSNPxx protocols it's important to make sure you always get the right TRiD when communicating with the server otherwise you will be disconnected. Use this alias to make sure you always have an accurate TRiD:

Code:
alias trid {
  inc %msn. $+ $1
  return $($+(%,msn.,$1),2)
}


Then you would use it like this:

Code:
  if ($1 $3 == VER MSNP15) {
    sockwrite -n $sockname CVR $trid($sockname) 0x0409 winnt 5.1 i386 MSNMSGR 8.0.0328 msmsgs bzerk_10@msn.com   
  }

  elseif ($1 == CVR) {
    sockwrite -n $sockname USR $trid($sockname) TWN I bzerk_10@msn.com
  }


Then just make sure you unset the variables when the sockets are closed:

Code:
on *:sockclose:*:{
  if ($istok(initial notification,$sockname,32)) unset %msn. $+ $sockname
}
Posted By: pouncer Re: using ssl -e with sockopen - 25/05/09 03:47 PM
Thanks hixxy. i'm still having trouble however capturing the ticket and profile. here is the full code so far:

Quote:

GCF 0 6735
ticket is:
profile is:
-
* /echo: insufficient parameters (line 54, Test.mrc)
-
* /tokenize: line too long (line 52, Test.mrc)
-


Code:
alias email return bzerk_10@msn.com

alias msnlogin {
  sockopen initial messenger.hotmail.com 1863
}

alias reset {
  sockclose initial
  sockclose notification
  unset %msn.*
}

alias trid {
  inc %msn. $+ $1
  return $($+(%,msn.,$1),2)
}

on *:sockclose:*:{
  if ($istok(initial notification,$sockname,32)) unset %msn. $+ $sockname
}

on *:SOCKOPEN:initial: {
  sockwrite -n $sockname VER $trid($sockname) MSNP15 CVR0
}

on *:SOCKREAD:initial: {
  var %x | sockread %x | tokenize 32 %x

  echo -a %x

  if ($1-3 == VER 1 MSNP15) {
    sockwrite -n $sockname CVR $trid($sockname) 0x0409 winnt 5.1 i386 MSNMSGR 8.0.0328 msmsgs bzerk_10@msn.com   
  }

  elseif ($1-2 == CVR 2) {
    sockwrite -n $sockname USR $trid($sockname) TWN I bzerk_10@msn.com
  }

  ; redirection (need to use ssl when connecting to switchboard server - sockopen -e)
  elseif ($1 == XFR) {
    var %ip = $gettok($4,1,58), %port = $gettok($4,2,58)

    sockopen notification %ip %port
  }
}

on *:SOCKOPEN:notification: {
  sockwrite -n $sockname VER $trid($sockname) MSNP15 CVR0
}

on *:SOCKREAD:notification: {
  var %x | sockread %x | tokenize 32 %x

  echo -a %x

  if ($1-3 == VER 1 MSNP15) {
    sockwrite -n $sockname CVR $trid($sockname) 0x0409 winnt 5.1 i386 MSNMSGR 8.0.0328 msmsgs bzerk_10@msn.com   
  }

  elseif ($1-2 == CVR 2) {
    sockwrite -n $sockname USR $trid($sockname) TWN I bzerk_10@msn.com
  }

  elseif ($1 == GCF) {
    sockread -f $3 &data
    var %start = $calc($bfind(&data,1,t=) + 7), %end = $calc($bfind(&data,%start,&p=) - 1), %ticket = $bvar(&data,$+(%start,-,%end)).text
    var %start = $calc($bfind(&data,1,&p=) + 9), %end = $calc($bfind(&data,%start,$crlf) - 1), %profile = $bvar(&data,$+(%start,-,%end)).text
    ; Do whatever you need to with %ticket and %profile here.

    echo -a ticket is: %ticket
    echo -a profile is: %profile

    ; sockwrite -n $sockname USR $trid($sockname) TWN S t= $+ %ticket $+ &profile= $+ %profile
  }
}


I'm following this for msn documentation

http://209.85.229.132/search?q=cache:mvF1xSZB0IcJ:www.csse.monash.edu.au/courseware/cse1370/2006/Chat/mosim.doc+msnp14+authentication&cd=8&hl=en&ct=clnk&gl=uk
Posted By: hixxy Re: using ssl -e with sockopen - 25/05/09 05:49 PM
I've tried everything and it's not sending the ticket and profile... I have no idea why. It may be some kind of socket limitation.
Posted By: pouncer Re: using ssl -e with sockopen - 25/05/09 09:36 PM
Could this possibly be a mirc socket bug?
Posted By: hixxy Re: using ssl -e with sockopen - 25/05/09 09:53 PM
Possibly yeah. I haven't done a lot of scripting lately so I could just be doing something stupid without realising.
Posted By: The_JD Re: using ssl -e with sockopen - 27/05/09 02:03 PM
I'm quiet sure this isn't a mIRC socket bug...

And i'm also sure (unless its changed very recently), that you're meant to get the ticket from a HTTP authentication server, and you send that to the MSNPXX servers.

Specifically: sockopen -e msn.authserver login.live.com 443

I'm quiet confident in this, because when MSN Chat was open, it was faster to use the Messenger authentication server to receive the encoded passportticket and passportprofile authentication keys
Posted By: hixxy Re: using ssl -e with sockopen - 28/05/09 10:51 PM
pouncer's doing it the right way for MSNP15. Well, he's connecting to the right server at least.. but for whatever reason, we're not getting the correct response.

msnfanatic.com might help.. I haven't worked with the MSN Messenger protocol in-depth since MSNP11 so I'm not an expert grin
Posted By: The_JD Re: using ssl -e with sockopen - 29/05/09 12:18 PM
Possibly it's changed as you suggested, but how can he expect to receive the passportprofile and passportticket without first sending a password?

The passportticket and passportprofile can be used to log you into almost any MSN website, so I don't imagine they'd now allow you to get it without connecting to the authentication server first, and even if you can now use the normal servers for auth, you would need to send the password somewhere, wouldn't you?
Posted By: The_JD Re: using ssl -e with sockopen - 29/05/09 12:22 PM
Just went looking for an old passport updater I made when mIRC first enabled SSL.

Unfortunately, the links at http://www.google.com.au/search?q=jd+sslupdatefix have the URL of my old site.
Posted By: pouncer Re: using ssl -e with sockopen - 31/05/09 08:06 AM
One thing I noticed on http://209.85.229.132/search?q=cache:mvF1xSZB0IcJ:www.csse.monash.edu.au/courseware/cse1370/2006/Chat/mosim.doc+msnp14+authentication&cd=8&hl=en&ct=clnk&gl=uk

Sent authentication SOAP


that's after the server sends back the full GCF load. but nowhere in that debug do i see the guy sending his email/password anywhere and that's exactly how im doing it too
Posted By: hixxy Re: using ssl -e with sockopen - 31/05/09 09:50 AM
You may want to look at this >> http://msnpiki.msnfanatic.com/index.php/MSNP15:SSO

God, MSNP9 was so much simpler laugh
Posted By: The_JD Re: using ssl -e with sockopen - 31/05/09 11:33 AM
After the initial XML data, You might notice this:

USR 2 TWN S lc=1033,id=507,tw=40,ru=http%3A%2F%2Fmessenger%2Emsn%2Ecom,ct=1161813852,kpp=1,kv=9,ver=2.1.6000.1,rn=zZI5qkYo,tpf=b0550c1ce641da84fe791088ac5effd9

That's the line i'd be keeping an eye on, i'm pretty sure that contains some of the data you need to sent to the authentication server.

As I said above, they couldn't just send you the ticket and profile data based on an email, as those two keys are as good as an email and password to a hacker.
Also, you might notice that the the t=* and the p=* do not show <<< at the beginning, which indicates to me that they didn't come in through that socket.
Posted By: The_JD Re: using ssl -e with sockopen - 31/05/09 11:38 AM
See: http://msnpiki.msnfanatic.com/index.php/MSNP13:SOAPTweener
Posted By: pouncer Re: using ssl -e with sockopen - 31/05/09 11:42 AM
Originally Posted By: The_JD

Also, you might notice that the the t=* and the p=* do not show <<< at the beginning, which indicates to me that they didn't come in through that socket.


i thought it was just 1 whole chunk the server sends back, split into seperate parts by crlf's

i was looking at that SSO soap stuff, it talks about sending xml soap requests to the server. i dont think we can do this via mirc sockets right? (line too long stuff?)
Posted By: hixxy Re: using ssl -e with sockopen - 31/05/09 08:31 PM
Not true.

You could send an extra long var by doing this:

bset -t &t 1 $str(a,4000)
bset -t &t $calc($bvar(&a,0) + 1) $str(a,4000)
bset -t &t $calc($bvar(&a,0) + 1) $str(a,4000)
bset -t &t $calc($bvar(&a,0) + 1) $str(a,4000)
sockwrite sockname &t
Posted By: The_JD Re: using ssl -e with sockopen - 01/06/09 09:35 AM
Yeh, as above, mIRC can send an unlimited amount of data.
Also, these two will do the same things in alot of circumstances:

1.
sockwrite -n this.socket an example line

2.
sockwrite this.socket an exam
sockwrite -n this.socket ple line
Posted By: pouncer Re: using ssl -e with sockopen - 03/09/09 08:27 PM
Hixxy and JD are you still around because im back and have started working on this again
Posted By: The_JD Re: using ssl -e with sockopen - 03/09/09 10:48 PM
I pop in quite often (2 times a week?)... but mostly check out the Developer/Bugs/Features sections... post up your issue and someone might help smile
© mIRC Discussion Forums