2018-07-27 16:55:06 +03:00
|
|
|
package rfb
|
2017-06-26 14:22:27 +03:00
|
|
|
|
|
|
|
import (
|
2017-06-29 00:09:31 +03:00
|
|
|
"bytes"
|
2017-06-26 14:22:27 +03:00
|
|
|
"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
|
|
|
|
|
2017-06-29 00:09:31 +03:00
|
|
|
if len(auth.Username) > definedAuthLen || len(auth.Password) > definedAuthLen {
|
|
|
|
return fmt.Errorf("username/password is too long, allowed 0-23")
|
|
|
|
}
|
|
|
|
|
2017-06-26 14:22:27 +03:00
|
|
|
nt, err := readTightTunnels(c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-06-29 00:09:31 +03:00
|
|
|
/*
|
|
|
|
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) {
|
2017-07-04 14:24:41 +03:00
|
|
|
c.SetProtoVersion("aten1")
|
2017-06-26 14:22:27 +03:00
|
|
|
var skip [20]byte
|
|
|
|
binary.Read(c, binary.BigEndian, &skip)
|
2017-07-04 14:24:41 +03:00
|
|
|
//fmt.Printf("skip %v\n", skip)
|
2017-06-29 00:09:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2017-06-26 14:22:27 +03:00
|
|
|
}
|
|
|
|
/*
|
2017-06-29 00:09:31 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2017-06-26 14:22:27 +03:00
|
|
|
}
|
|
|
|
|
2017-06-29 00:09:31 +03:00
|
|
|
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
|
|
|
|
}
|
2017-06-26 14:22:27 +03:00
|
|
|
}
|
|
|
|
|
2017-06-29 00:09:31 +03:00
|
|
|
if err := binary.Write(c, binary.BigEndian, sendUsername); err != nil {
|
2017-06-26 14:22:27 +03:00
|
|
|
return err
|
|
|
|
}
|
2017-06-29 00:09:31 +03:00
|
|
|
if err := binary.Write(c, binary.BigEndian, sendPassword); err != nil {
|
|
|
|
return err
|
2017-06-26 14:22:27 +03:00
|
|
|
}
|
|
|
|
|
2017-06-29 00:09:31 +03:00
|
|
|
if err := c.Flush(); err != nil {
|
|
|
|
return err
|
2017-06-26 14:22:27 +03:00
|
|
|
}
|
2017-06-29 00:09:31 +03:00
|
|
|
*/
|
2017-06-26 14:22:27 +03:00
|
|
|
//var pp [10]byte
|
|
|
|
//binary.Read(c, binary.BigEndian, &pp)
|
|
|
|
//fmt.Printf("ddd %v\n", pp)
|
|
|
|
return nil
|
|
|
|
}
|