forked from jphackworth/kestrel
-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.go
136 lines (120 loc) · 3.1 KB
/
types.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package main
import (
"github.com/sirupsen/logrus"
"net"
)
type ServerInfo struct {
//Conn *net.UDPConn
Server *UDPServer
Peers []PeerInfo
}
type Account struct {
username []byte
password string
secret [32]byte
secondHash [32]byte
restrictedToIPv6 *net.Addr
}
// TODO: Move the server-side credentials away from the *Peer
// particularly the accounts
type CryptoAuth_Auth struct {
//accounts []*Account
accounts map[[32]byte]*Account // key is the hashed version of the password
keyPair *KeyPair
log *logrus.Logger // go-logging
}
type PeerInfo struct {
PublicAddress *net.IPAddr
CjdnsAddress *net.IPAddr
Conn *net.UDPConn
Password []byte
PublicKey []byte
SharedKey []byte
}
type TomlConfig struct {
Server ServerConfig
}
type ServerConfig struct {
Listen string `toml:"listen"`
Device string `toml:"device"`
PublicKey string `toml:"public_key"`
PrivateKey string `toml:"private_key"`
IPv6 string `toml:"ipv6"`
Password string `toml:"password"`
}
type UDPServer struct {
conn *net.UDPConn
keyPair *KeyPair
config *ServerConfig
bufsz int
padsz int
log *logrus.Logger
//log *logging.Logger // go-logging
peers map[string]*Peer
accounts []*Account
auth *CryptoAuth_Auth
}
type InterfaceController struct {
ifaces []*UDPServer
}
// type Router struct {
// Iface *tun.Tun
// PublicKey [32]byte
// PrivateKey [32]byte
// UDPConn *net.UDPConn
// Config *ServerConfig
// BufSz int
// Log *logging.Logger // go-logging
// Peers3 map[string]*Peer
// Peers map[[32]byte]*Peer
// keyPair *KeyPair
// }
type Passwd struct {
user [32]byte // username string, max 32 bytes
password [32]byte // hashed form of password loaded from kestrel.toml
publicKey []byte // future use - allow only a given public key to use this password
addr *net.IPAddr // future use - allow on a given remote ip addr to use this password
}
type KeyPair struct {
publicKey [32]byte
privateKey [32]byte
}
type Peer struct {
name string
addr *net.UDPAddr
conn *net.UDPConn
//server *UDPServer
password []byte // static password for incoming / outgoing peers..?
state uint32 // handshake state or nonce
nextNonce uint32
tempKeyPair *KeyPair // This is our tempKeyPair, not actually the peers
sharedSecret [32]byte
passwordHash [32]byte
publicKey [32]byte // the remote peer's permanent public key
tempPublicKey [32]byte // This is the remote peer's temporary public key
//log *logging.Logger
log *logrus.Logger
//passwordHash [32]byte
initiator bool
established bool
requireAuth bool
timeOfLastPacket uint32
replayProtector *ReplayProtector
}
type ReplayProtector struct {
bitfield uint64
baseOffset uint32
duplicates uint32
lostPackets uint32
receivedOutOfRange uint32
}
// type Message struct {
// length uint32
// padding uint32
// payload []byte
// capacity uint32
// }
type EncryptedMessage2 struct {
handshake [120]byte
payload []byte
}