• Welcome to Valhalla Legends Archive.
 

D2 Logon

Started by Jaquio, February 06, 2007, 09:59 PM

Previous topic - Next topic

Jaquio

#15
Quote from: MyndFyre[vL] on February 07, 2007, 05:18 PM
Investigate BNLS_CDKEY and BNLS_CDKEY_EX.

They both return the same thing? The Hashed CDKey data but 0x0C returns the Session key. Which I have no clue what it is used for...


'Recv'd 0x0C
                .rDWORD
                intI = .rBYTE
                intX = .rBYTE
                .rDWORD

                If intX = 2 Then
                    BD.CDKeySes1 = .rDWORD
                    BD.CDKeyHash1 = .rVOID(36)
                    BD.CDKeySes2 = .rDWORD
                    BD.CDKeyHash2 = .rVOID(36)
                Else
                    BD.CDKeySes1 = .rDWORD
                    BD.CDKeyHash1 = .rVOID(36)
                End If

                .InsertDWORD BD.ClientToken '(DWORD)      Client Token
                .InsertDWORD BD.Version '(DWORD)      EXE Version
                .InsertDWORD BD.Checksum '(DWORD)      EXE Hash
                .InsertDWORD &H2 '(DWORD)      Number of keys in this packet
                .InsertDWORD &H0 '(BOOLEAN)    Using Spawn (32-bit)
               
                'For Each Key:
                .InsertDWORD Len(BD.CDKey1) '(DWORD)      Key Length
                '(DWORD)      CD key's product value
                '(DWORD)      CD key's public value
                '.InsertDWORD &H0 '(DWORD)      Unknown (0)
                .InsertNonNTString BD.CDKeyHash1 '(DWORD[5])   Hashed Key Data
               
                .InsertDWORD Len(BD.CDKey2) '(DWORD)      Key Length
                '.InsertDWORD &H0 '(DWORD)      Unknown (0)
                .InsertNonNTString BD.CDKeyHash2 '(DWORD[5])   Hashed Key Data
               
                .InsertNTString BD.EXEInfo '(STRING)     Exe Information
                .InsertNTString "Jaquio" '(STRING)     CD Key owner name
                .SendBNCSPacket &H51

'Sent 0x0C
            Case &H1A
                If .rDWORD > 0 Then
                    BD.Version = .rDWORD
                    BD.Checksum = .rDWORD
                    BD.EXEInfo = .rNTString
                    .rDWORD 'Cookie
                    .rDWORD 'Verbyte

                    .InsertDWORD BD.ClientToken
                    .InsertBYTE 2
                    .InsertDWORD &H1
                    .InsertDWORD BD.ServerToken
                    .InsertDWORD BD.ServerToken
                    .InsertNTString BD.CDKey1
                    .InsertNTString BD.CDKey2
                    .SendBNLSPacket &HC
                   
                Else
                    Debug.Print GetPacketName(strPID, "BNLS") & " FAILED!"
                    GlobalDisc
                End If

brew

I'm not sure what the "Session Key" is, but it sounds like a "cookie" in most bnls packets, and in bncs profile requests, it's called a session key too. basically its just no specific value which is echo'd back in the S > C packet.
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

Skywing

Quote from: Jaquio on February 07, 2007, 05:49 PM
They both return the same thing? The Hashed CDKey data but 0x0C returns the Session key. Which I have no clue what it is used for...

Did you read the documentation in the BNLS protocol specification (linked previously by MyndFyre) as it pertains to BNLS_CDKEY and BNLS_CDKEY_EX (in particular)?  It makes clear what the usage of that field is.

Virtually all of the questions that have been asked in this thread could have been solved easier (and much faster!) by simply taking five or ten minutes to read the BNLS protocol specification and the BnetDocs documentation relating to Battle.net logon.

Clever readers may note that it would be to their advantage to spend a couple of minutes researching the available documentation instead of wasting a day or more on rehash forum posts of previously covered topics.

In general, you'll get much further much faster in programming (and life) if you do a bit of research on your own before relying on others to give you the information that you believe you need.

MyndFyre

Quote from: Skywing on February 07, 2007, 07:55 PM
Virtually all of the questions that have been asked in this thread could have been solved easier (and much faster!) by simply taking five or ten minutes to read the BNLS protocol specification and the BnetDocs documentation relating to Battle.net logon.

I'm glad you said so Skywing.  I feel like it validated the fact that I posted the URL.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Jaquio

#19
Quote from: Skywing on February 07, 2007, 07:55 PM
Quote from: Jaquio on February 07, 2007, 05:49 PM
They both return the same thing? The Hashed CDKey data but 0x0C returns the Session key. Which I have no clue what it is used for...

Did you read the documentation in the BNLS protocol specification (linked previously by MyndFyre) as it pertains to BNLS_CDKEY and BNLS_CDKEY_EX (in particular)?  It makes clear what the usage of that field is.

How is that when it says the same shit BNetDocs does? Am I missing something?

Quote from: BNLS Protocol Spec
BNLS_CDKEY_EX (0x0c)
--------------------

This message will encrypt your CD-key or CD-keys using the given flags.

(DWORD) Cookie. This value has no special meaning to the server and will simply be echoed to the client in the response.
(BYTE) Amount of CD-keys to encrypt. Must be between 1 and 32.
(DWORD) Flags.*
(DWORD or DWORDs) Server session key(s), depending on the flags.
(Optional DWORD or DWORDs) Client session key(s), depending on the flags.
(String or strings) CD-keys. No dashes or spaces. The client can use multiple types of CD-keys in the same packet.

* The flags may be zero, or any bitwise combination of the defined flags.
Currently, the following flags are defined:

#define CDKEY_SAME_SESSION_KEY          (0x01)
#define CDKEY_GIVEN_SESSION_KEY         (0x02)
#define CDKEY_MULTI_SERVER_SESSION_KEYS (0x04)
#define CDKEY_OLD_STYLE_RESPONSES       (0x08)

CDKEY_SAME_SESSION_KEY (0x01):
This flag specifies that all the returned CD-keys will use the same client session key.
When used in combination with CDKEY_GIVEN_SESSION_KEY (0x02), a single client session key is specified immediately after the server session key(s).
When used without CDKEY_GIVEN_SESSION_KEY (0x02), a client session key isn't sent in the request, and the server will create one.
When not used, each CD-key gets its own client session key.
This flag has no effect if the amount of CD-keys to encrypt is 1.

CDKEY_GIVEN_SESSION_KEY (0x02):
This flag specifies that the client session keys to be used are specified in the request.
When used in combination with CDKEY_SAME_SESSION_KEY (0x01), a single client session key is specified immediately after the server session key(s).
When used without CDKEY_SAME_SESSION_KEY (0x01), an array of client session keys (as many as the amount of CD-keys) is specified.
When not used, client session keys aren't included in the request.

CDKEY_MULTI_SERVER_SESSION_KEYS (0x04):
This flag specifies that each CD-key has its own server session key.
When specified, an array of server session keys (as many as the amount of CD-keys) is specified.
When not specified, a single server session key is specified.
This flag has no effect if the amount of CD-keys to encrypt is 1.

CDKEY_OLD_STYLE_RESPONSES (0x08):
Specifies that the response to this packet is a number of BNLS_CDKEY (0x01) responses, instead of a BNLS_CDKEY_EX (0x0c) response.
The responses are guaranteed to be in the order of the CD-keys' appearance in the request.
Note that when this flag is specified, the Cookie cannot be echoed. (It must still be included in the request.)



Note: When using Lord of Destruction, two CD-keys are encrypted, and they must share the same client session key.
There are several ways to do this:
One way is to provide both CD-keys in BNLS_CDKEY_EX (0x0c) using the flag CDKEY_SAME_SESSION_KEY (0x01).
Another way is to use BNLS_CDKEY (0x01) to encrypt the first CD-key, then use BNLS_CDKEY_EX (0x0c) using the flag CDKEY_GIVEN_SESSION_KEY (0x02) to encrypt the second CD-key with the same client session key.



Response:
---------

When the flags don't contain CDKEY_OLD_STYLE_RESPONSES (0x08), the response is a BNLS_CDKEY_EX (0x0c) message:

(DWORD) Cookie. Same as the value sent to the server in the request.
(BYTE) Amount of CD-keys that were requested.
(BYTE) Amount of CD-keys that were successfully encrypted.
(DWORD) Bit mask for the success code of each CD-key. Each bit of the 32 bits in this DWORD is 1 for success or 0 for failure. The least significant bit specifies the success code of the first CD-key provided. Bits that exceed the amount of CD-keys provided are set to 0.

The following fields repeat for each successful CD-key (they do not exist for failed CD-keys):

(DWORD) Client session key.
(9 DWORDs) CD-key data.

Where does it say what it is used for? I have never set Key Public and Key Product before. It has worked fine, but now it don't.


Connected to bnls.valhallalegends.com:9367
Sent:BNLS_REQUESTVERSIONBYTE(0x10)
Received:BNLS_REQUESTVERSIONBYTE(0x10)
Connected to useast.battle.net:6112
Sent:SID_AUTH_INFO(0x50)
Received:SID_PING(0x25)
Sent:SID_PING(0x25)
Received:SID_AUTH_INFO(0x50)
Sent:BNLS_VERSIONCHECKEX2(0x1A)
Received:BNLS_VERSIONCHECKEX2(0x1A)
Sent:BNLS_CDKEY_EX(0x0C)
Received:BNLS_CDKEY_EX(0x0C)
Sent:SID_AUTH_CHECK(0x51)
Received:SID_AUTH_CHECK(0x51)
CDKey is for wrong product!
GLOBAL DISCONNECT!


And..


Public Function PBNET(strData As String, lngLength As Long)
Dim strPID As Byte, lngPLen As Long, strExtra As String
    With PD
        lngPLen = 0
        .SetData strData
       
        If .rBYTE = &HFF Then
            strPID = .rBYTE 'PacketID
            Debug.Print "Received:" & GetPacketName(strPID, "BNCS") & "(" & Hex(strPID) & ")"
            lngPLen = .rWORD 'Packet Length
           
            If lngLength > lngPLen Or lngPLen > lngLength Then
                If lngLength > lngPLen Then
                    strExtra = Right(strData, (lngLength - lngPLen))
                Else
                    strExtra = Right(strData, (lngPLen - lngLength))
                End If
            End If
        End If
       
        Select Case strPID
            Case &H25
                .InsertDWORD .rDWORD
                .SendBNCSPacket &H25
               
            Case &H50
                If .rDWORD = 0 Then BD.UseNLS = False Else BD.UseNLS = True 'Logon Type
                BD.ServerToken = .rDWORD 'ServerToken
                BD.UDPValue = .rDWORD 'UDPValue
                BD.MPQFT = .rFILETIME(True)  'MPQ Filetime
                BD.MPQName = .rNTString 'MPQ Filename
                BD.ValueString = .rNTString 'ValueString
               
                .InsertDWORD &H5
                .InsertDWORD &H0
                .InsertDWORD BD.ClientToken
                .InsertNonNTString BD.MPQFT
                .InsertNTString BD.MPQName
                .InsertNTString BD.ValueString
                .SendBNLSPacket &H1A
            Case &H51
                Select Case .rDWORD
                    Case &H0
                        Debug.Print "Success!"
                    Case &H100
                        Debug.Print "Old Game Version!"
                        GlobalDisc
                    Case &H101
                        Debug.Print "Invalid Version!"
                        GlobalDisc
                    Case &H102
                        Debug.Print "Game version must be downgraded!"
                        GlobalDisc
                    Case &H200
                        Debug.Print "Invalid CDKey!"
                        GlobalDisc
                    Case &H201
                        Debug.Print "CDKey is in use by " & .rNTString
                        GlobalDisc
                    Case &H202
                        Debug.Print "CDKey is banned!"
                        GlobalDisc
                    Case &H203
                        Debug.Print "CDKey is for wrong product!"
                        GlobalDisc
                End Select
        End Select
    End With

    If Len(strExtra) >= 1 Then
        PBNET strExtra, Len(strExtra)
    End If
End Function

Public Function PBNLS(strData As String, lngLength As Long)
Dim strPID As Byte, lngPLen As Long, strExtra As String, intI As Integer, intX As Integer, intY As Integer
    With PD
        lngPLen = 0
        .SetData strData

        lngPLen = .rWORD
        strPID = .rBYTE
        Debug.Print "Received:" & GetPacketName(strPID, "BNLS") & "(" & Hex(strPID) & ")"
       
        If lngLength > lngPLen Or lngPLen > lngLength Then
            If lngLength > lngPLen Then
                strExtra = Right(strData, (lngLength - lngPLen))
            Else
                strExtra = Right(strData, (lngPLen - lngLength))
            End If
        End If
       
        Select Case strPID
            Case &HC
                .rDWORD
                intI = .rBYTE
                intX = .rBYTE
                .rDWORD

                If intX = 2 Then
                    BD.CDKeySes1 = .rDWORD
                    BD.CDKeyHash1 = .rVOID(36)
                    BD.CDKeySes2 = .rDWORD
                    BD.CDKeyHash2 = .rVOID(36)
                Else
                    BD.CDKeySes1 = .rDWORD
                    BD.CDKeyHash1 = .rVOID(36)
                End If
               
                .InsertDWORD BD.ClientToken '(DWORD)      Client Token
                .InsertDWORD BD.Version '(DWORD)      EXE Version
                .InsertDWORD BD.Checksum '(DWORD)      EXE Hash
                .InsertDWORD &H2 '(DWORD)      Number of keys in this packet
                .InsertDWORD &H0 '(BOOLEAN)    Using Spawn (32-bit)
               
                'For Each Key:
                .InsertDWORD Len(BD.CDKey1) '(DWORD)      Key Length
                '.InsertDWORD &H10 '(DWORD)      CD key's product value
                '.InsertDWORD &HA '(DWORD)      CD key's public value
                '.InsertDWORD &H0 '(DWORD)      Unknown (0)
                .InsertNonNTString BD.CDKeyHash1 '(DWORD[5])   Hashed Key Data
               
                .InsertDWORD Len(BD.CDKey2) '(DWORD)      Key Length
                '.InsertDWORD &H11 '(DWORD)      CD key's product value
                '.InsertDWORD &HA '(DWORD)      CD key's public value
                '.InsertDWORD &H0 '(DWORD)      Unknown (0)
                .InsertNonNTString BD.CDKeyHash2 '(DWORD[5])   Hashed Key Data
               
                .InsertNTString BD.EXEInfo '(STRING)     Exe Information
                .InsertNTString "Jaquio" '(STRING)     CD Key owner name
                .SendBNCSPacket &H51
            Case &H10
                If .rDWORD > 0 Then
                    BD.VersionByte = .rDWORD
                    frmMain.sckBNET.Connect BD.BNETServ, 6112
                Else
                    Debug.Print GetPacketName(strPID, "BNLS") & " FAILED!"
                    GlobalDisc
                End If
            Case &H1A
                If .rDWORD > 0 Then
                    BD.Version = .rDWORD
                    BD.Checksum = .rDWORD
                    BD.EXEInfo = .rNTString
                    .rDWORD 'Cookie
                    .rDWORD 'Verbyte

                    .InsertDWORD BD.ClientToken
                    .InsertBYTE 2
                    .InsertDWORD &H0
                    .InsertDWORD BD.ServerToken
                    '.InsertDWORD BD.ServerToken
                    .InsertNTString BD.CDKey1
                    .InsertNTString BD.CDKey2
                    .SendBNLSPacket &HC
                   
                Else
                    Debug.Print GetPacketName(strPID, "BNLS") & " FAILED!"
                    GlobalDisc
                End If
        End Select
    End With
   
    If Len(strExtra) >= 1 Then
        PBNLS strExtra, Len(strExtra)
    End If
End Function


Could someone help me? So I could know what not to do next time. For one I know you will all say, "Don't use Visual Basic" but you know what? I happen to like it... I know C/C++ but just not enough which is why I am LEARNING. Anyways... Could someone help me get to the problem here? I am sorry I am not as smart of as everyone else... But atleast I am TRYING to learn stuff here...

MyndFyre

Quote from: Jaquio on February 07, 2007, 09:51 PM
Could someone help me? So I could know what not to do next time. For one I know you will all say, "Don't use Visual Basic" but you know what? I happen to like it... I know C/C++ but just not enough which is why I am LEARNING. Anyways... Could someone help me get to the problem here? I am sorry I am not as smart of as everyone else... But atleast I am TRYING to learn stuff here...
It certainly does not look like you're "TRYING" to learn stuff here.

Quote from: Jaquio on February 07, 2007, 09:51 PM
Quote from: Skywing on February 07, 2007, 07:55 PM
Quote from: Jaquio on February 07, 2007, 05:49 PM
They both return the same thing? The Hashed CDKey data but 0x0C returns the Session key. Which I have no clue what it is used for...

Did you read the documentation in the BNLS protocol specification (linked previously by MyndFyre) as it pertains to BNLS_CDKEY and BNLS_CDKEY_EX (in particular)?  It makes clear what the usage of that field is.

How is that when it says the same shit BNetDocs does? Am I missing something?
Have you read what BnetDocs says the session keys are?  There are two of them - the client and server tokens:

Client token: "A 32-bit value, decided by the client, which is included in the input hash functions to improve their security.  Many developers use the GetTickCount API to retrieve a suitable value for this field."
Server token: "A 32-bit value, decided by the server, which is included in the input hash functions to improve their security."

If you look at 0x51 C->S, you'll see that for each key, there are 9 DWORD values.  Curiously, the BNLS_CDKEY_EX packet indicates that there are 9 DWORD values provided, labeled "CD key data".  I just wonder....

The BNLS connection sequence is well-documented in the BNLS protocol specification.  To again let you know where this is, it's http://www.valhallalegends.com/yoni/BNLSProtocolSpec.txt.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Jaquio

Okay... I think I get it now. Are the 9 dwords sent back still in the same order for 0x51, or what is the order of the 9Dwords? It is not in the bnls proto spec.. I looked..

UserLoser

Quote from: Jaquio on February 08, 2007, 07:38 PM
Okay... I think I get it now. Are the 9 dwords sent back still in the same order for 0x51, or what is the order of the 9Dwords? It is not in the bnls proto spec.. I looked..

Yes..they're sent back in the correct order