forked from saily/vnc2video
-
Notifications
You must be signed in to change notification settings - Fork 0
/
security_aten.go
107 lines (92 loc) · 2.34 KB
/
security_aten.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package vnc2video
import (
"bytes"
"encoding/binary"
"fmt"
)
type ClientAuthATEN struct {
Username []byte
Password []byte
}
func (*ClientAuthATEN) Type() SecurityType {
return SecTypeATEN
}
func (*ClientAuthATEN) SubType() SecuritySubType {
return SecSubTypeUnknown
}
func charCodeAt(s string, n int) rune {
for i, r := range s {
if i == n {
return r
}
}
return 0
}
func (auth *ClientAuthATEN) Auth(c Conn) error {
var definedAuthLen = 24
if len(auth.Username) > definedAuthLen || len(auth.Password) > definedAuthLen {
return fmt.Errorf("username/password is too long, allowed 0-23")
}
nt, err := readTightTunnels(c)
if err != nil {
return err
}
/*
fmt.Printf("tunnels %d\n", nt)
for i := uint32(0); i < nt; i++ {
code, vendor, signature, err := readTightCaps(c)
if err != nil {
return err
}
fmt.Printf("code %d vendor %s signature %s\n", code, vendor, signature)
}
*/
if ((nt&0xffff0ff0)>>0 == 0xaff90fb0) || (nt <= 0 || nt > 0x1000000) {
c.SetProtoVersion("aten1")
var skip [20]byte
binary.Read(c, binary.BigEndian, &skip)
//fmt.Printf("skip %v\n", skip)
}
username := make([]byte, definedAuthLen)
password := make([]byte, definedAuthLen)
copy(username, auth.Username)
copy(password, auth.Password)
challenge := bytes.Join([][]byte{username, password}, []byte(""))
if err := binary.Write(c, binary.BigEndian, challenge); err != nil {
return err
}
if err := c.Flush(); err != nil {
return err
}
/*
sendUsername := make([]byte, definedAuthLen)
for i := 0; i < definedAuthLen; i++ {
if i < len(auth.Username) {
sendUsername[i] = byte(charCodeAt(string(auth.Username), i))
} else {
sendUsername[i] = 0
}
}
sendPassword := make([]byte, definedAuthLen)
for i := 0; i < definedAuthLen; i++ {
if i < len(auth.Password) {
sendPassword[i] = byte(charCodeAt(string(auth.Password), i))
} else {
sendPassword[i] = 0
}
}
if err := binary.Write(c, binary.BigEndian, sendUsername); err != nil {
return err
}
if err := binary.Write(c, binary.BigEndian, sendPassword); err != nil {
return err
}
if err := c.Flush(); err != nil {
return err
}
*/
//var pp [10]byte
//binary.Read(c, binary.BigEndian, &pp)
//fmt.Printf("ddd %v\n", pp)
return nil
}