-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathconnect.go
73 lines (58 loc) · 1.8 KB
/
connect.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package nex
import (
"time"
"github.com/PretendoNetwork/friends/globals"
"github.com/PretendoNetwork/friends/types"
nex "github.com/PretendoNetwork/nex-go"
)
func connect(packet *nex.PacketV0) {
// * We aren't making any replies here because the common Secure Protocol already does that
// *
// * We only want to check that the data given is right so that we don't register a client
// * with an invalid request
payload := packet.Payload()
stream := nex.NewStreamIn(payload, globals.SecureServer)
ticketData, err := stream.ReadBuffer()
if err != nil {
return
}
requestData, err := stream.ReadBuffer()
if err != nil {
return
}
serverKey := nex.DeriveKerberosKey(2, []byte(globals.SecureServer.KerberosPassword()))
ticket := nex.NewKerberosTicketInternalData()
err = ticket.Decrypt(nex.NewStreamIn(ticketData, globals.SecureServer), serverKey)
if err != nil {
return
}
ticketTime := ticket.Timestamp().Standard()
serverTime := time.Now().UTC()
timeLimit := ticketTime.Add(time.Minute * 2)
if serverTime.After(timeLimit) {
return
}
sessionKey := ticket.SessionKey()
kerberos, err := nex.NewKerberosEncryption(sessionKey)
if err != nil {
return
}
decryptedRequestData := kerberos.Decrypt(requestData)
checkDataStream := nex.NewStreamIn(decryptedRequestData, globals.SecureServer)
userPID, err := checkDataStream.ReadUInt32LE()
if err != nil {
return
}
_, err = checkDataStream.ReadUInt32LE() // CID of secure server station url
if err != nil {
return
}
_, err = checkDataStream.ReadUInt32LE() // Response check
if err != nil {
return
}
connectedUser := types.NewConnectedUser()
connectedUser.PID = userPID
connectedUser.Client = packet.Sender()
globals.ConnectedUsers[userPID] = connectedUser
}