1
0
Fork 0
forked from External/grumble

grumble: allow for other ciphers than OCB2-AES128.

This commit is contained in:
Mikkel Krautz 2012-12-08 23:50:32 +01:00
parent eacf839182
commit cd363d197e
3 changed files with 12 additions and 8 deletions

View file

@ -367,7 +367,7 @@ func (client *Client) udpRecvLoop() {
// through the client's control channel (TCP). // through the client's control channel (TCP).
func (client *Client) SendUDP(buf []byte) error { func (client *Client) SendUDP(buf []byte) error {
if client.udp { if client.udp {
crypted := make([]byte, len(buf)+4) crypted := make([]byte, len(buf)+client.crypt.Overhead())
client.crypt.Encrypt(crypted, buf) client.crypt.Encrypt(crypted, buf)
return client.server.SendUDP(crypted, client.udpaddr) return client.server.SendUDP(crypted, client.udpaddr)
} else { } else {

View file

@ -109,8 +109,8 @@ func (cs *CryptState) Decrypt(dst, src []byte) error {
} }
plain_len := len(src) - cs.Overhead() plain_len := len(src) - cs.Overhead()
if len(dst) != plain_len { if len(dst) < plain_len {
return errors.New("cryptstate: plain_len and src len mismatch") return errors.New("cryptstate: not enough space in dst for plain text")
} }
ivbyte := src[0] ivbyte := src[0]

View file

@ -514,9 +514,9 @@ func (server *Server) handleAuthenticate(client *Client, msg *Message) {
// if it wishes. // if it wishes.
client.lastResync = time.Now().Unix() client.lastResync = time.Now().Unix()
err = client.sendMessage(&mumbleproto.CryptSetup{ err = client.sendMessage(&mumbleproto.CryptSetup{
Key: client.crypt.RawKey[0:], Key: client.crypt.Key,
ClientNonce: client.crypt.DecryptIV[0:], ClientNonce: client.crypt.DecryptIV,
ServerNonce: client.crypt.EncryptIV[0:], ServerNonce: client.crypt.EncryptIV,
}) })
if err != nil { if err != nil {
client.Panicf("%v", err) client.Panicf("%v", err)
@ -989,7 +989,7 @@ func (server *Server) udpListenLoop() {
func (server *Server) handleUdpPacket(udpaddr *net.UDPAddr, buf []byte, nread int) { func (server *Server) handleUdpPacket(udpaddr *net.UDPAddr, buf []byte, nread int) {
var match *Client var match *Client
plain := make([]byte, nread-4) plain := make([]byte, nread)
// Determine which client sent the the packet. First, we // Determine which client sent the the packet. First, we
// check the map 'hpclients' in the server struct. It maps // check the map 'hpclients' in the server struct. It maps
@ -1001,7 +1001,7 @@ func (server *Server) handleUdpPacket(udpaddr *net.UDPAddr, buf []byte, nread in
defer server.hmutex.Unlock() defer server.hmutex.Unlock()
client, ok := server.hpclients[udpaddr.String()] client, ok := server.hpclients[udpaddr.String()]
if ok { if ok {
err := client.crypt.Decrypt(plain[0:], buf[0:nread]) err := client.crypt.Decrypt(plain, buf)
if err != nil { if err != nil {
client.cryptResync() client.cryptResync()
return return
@ -1029,6 +1029,10 @@ func (server *Server) handleUdpPacket(udpaddr *net.UDPAddr, buf []byte, nread in
return return
} }
// Resize the plaintext slice now that we know
// the true encryption overhead.
plain = plain[:len(plain)-match.crypt.Overhead()]
match.udp = true match.udp = true
match.udprecv <- plain match.udprecv <- plain
} }