diff --git a/client.go b/client.go index b53585c..0956e33 100644 --- a/client.go +++ b/client.go @@ -41,7 +41,7 @@ type Client struct { disconnected bool lastResync int64 - crypt *cryptstate.CryptState + crypt cryptstate.CryptState codecs []int32 opus bool udp bool diff --git a/pkg/cryptstate/cryptstate.go b/pkg/cryptstate/cryptstate.go index 9298ebf..167ad0d 100644 --- a/pkg/cryptstate/cryptstate.go +++ b/pkg/cryptstate/cryptstate.go @@ -1,5 +1,4 @@ -// Grumble - an implementation of Murmur in Go -// Copyright (c) 2010 The Grumble Authors +// Copyright (c) 2010-2012 The Grumble Authors // The use of this source code is goverened by a BSD-style // license that can be found in the LICENSE-file. @@ -10,6 +9,7 @@ import ( "crypto/cipher" "crypto/rand" "errors" + "io" "mumbleapp.com/grumble/pkg/cryptstate/ocb2" "time" ) @@ -36,23 +36,28 @@ type CryptState struct { cipher cipher.Block } -func New() (cs *CryptState, err error) { - cs = new(CryptState) +func (cs *CryptState) GenerateKey() error { + _, err := io.ReadFull(rand.Reader, cs.RawKey[0:]) + if err != nil { + return err + } - return -} + _, err = io.ReadFull(rand.Reader, cs.EncryptIV[0:]) + if err != nil { + return err + } -func (cs *CryptState) GenerateKey() (err error) { - rand.Read(cs.RawKey[0:]) - rand.Read(cs.EncryptIV[0:]) - rand.Read(cs.DecryptIV[0:]) + _, err = io.ReadFull(rand.Reader, cs.DecryptIV[0:]) + if err != nil { + return err + } cs.cipher, err = aes.NewCipher(cs.RawKey[0:]) if err != nil { - return + return err } - return + return nil } func (cs *CryptState) SetKey(key []byte, eiv []byte, div []byte) (err error) { diff --git a/pkg/cryptstate/cryptstate_test.go b/pkg/cryptstate/cryptstate_test.go index 28248b2..643df3b 100644 --- a/pkg/cryptstate/cryptstate_test.go +++ b/pkg/cryptstate/cryptstate_test.go @@ -1,3 +1,7 @@ +// Copyright (c) 2010-2012 The Grumble Authors +// The use of this source code is goverened by a BSD-style +// license that can be found in the LICENSE-file. + package cryptstate import ( @@ -26,11 +30,7 @@ func TestEncrypt(t *testing.T) { 0x1f, 0x2a, 0x9b, 0xd0, 0x2d, 0xa6, 0x8e, 0x46, 0x26, 0x85, 0x83, 0xe9, 0x14, 0x2a, 0xff, 0x2a, } - cs, err := New() - if err != nil { - t.Errorf("%v", err) - } - + cs := CryptState{} out := make([]byte, 19) cs.SetKey(key[0:], eiv[0:], div[0:]) cs.Encrypt(out[0:], msg[0:]) @@ -64,11 +64,7 @@ func TestDecrypt(t *testing.T) { 0x1f, 0x2a, 0x9b, 0xd0, 0x2d, 0xa6, 0x8e, 0x46, 0x26, 0x85, 0x83, 0xe9, 0x14, 0x2a, 0xff, 0x2a, } - cs, err := New() - if err != nil { - t.Errorf("%v", err) - } - + cs := CryptState{} out := make([]byte, 15) cs.SetKey(key[0:], div[0:], eiv[0:]) cs.Decrypt(out[0:], crypted[0:]) diff --git a/pkg/cryptstate/ocb2/ocb2.go b/pkg/cryptstate/ocb2/ocb2.go index ce22a7b..55e45a0 100644 --- a/pkg/cryptstate/ocb2/ocb2.go +++ b/pkg/cryptstate/ocb2/ocb2.go @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Grumble Authors +// Copyright (c) 2010-2012 The Grumble Authors // The use of this source code is goverened by a BSD-style // license that can be found in the LICENSE-file. diff --git a/pkg/cryptstate/ocb2/ocb2_test.go b/pkg/cryptstate/ocb2/ocb2_test.go index 60d5a8f..e71feb6 100644 --- a/pkg/cryptstate/ocb2/ocb2_test.go +++ b/pkg/cryptstate/ocb2/ocb2_test.go @@ -1,6 +1,6 @@ -// Copyright (c) 2012 The Grumble Authors +// Copyright (c) 2010-2012 The Grumble Authors // The use of this source code is goverened by a BSD-style -// license that can be found in the LICENSE-file. +// license that can be found in the LICENSE-file.git l package ocb2 diff --git a/server.go b/server.go index e19877d..b700e4d 100644 --- a/server.go +++ b/server.go @@ -19,7 +19,6 @@ import ( "log" "mumbleapp.com/grumble/pkg/ban" "mumbleapp.com/grumble/pkg/blobstore" - "mumbleapp.com/grumble/pkg/cryptstate" "mumbleapp.com/grumble/pkg/freezer" "mumbleapp.com/grumble/pkg/htmlfilter" "mumbleapp.com/grumble/pkg/logtarget" @@ -505,11 +504,6 @@ func (server *Server) handleAuthenticate(client *Client, msg *Message) { } // Setup the cryptstate for the client. - client.crypt, err = cryptstate.New() - if err != nil { - client.Panicf("%v", err) - return - } err = client.crypt.GenerateKey() if err != nil { client.Panicf("%v", err)