mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-08 09:07:44 +00:00
control/noise: don't panic when handling ciphertext.
Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
parent
4004b22fe5
commit
a63c4ab378
@ -7,6 +7,7 @@
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash"
|
"hash"
|
||||||
"io"
|
"io"
|
||||||
@ -282,7 +283,7 @@ type symmetricState struct {
|
|||||||
ck [blake2s.Size]byte // chaining key used to construct session keys at the end of the handshake
|
ck [blake2s.Size]byte // chaining key used to construct session keys at the end of the handshake
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *symmetricState) checkFinished() {
|
func (s *symmetricState) checkFinished() error {
|
||||||
if s.finished {
|
if s.finished {
|
||||||
panic("attempted to use symmetricState after Split was called")
|
panic("attempted to use symmetricState after Split was called")
|
||||||
}
|
}
|
||||||
@ -352,7 +353,7 @@ func (s *symmetricState) EncryptAndHash(cipher *singleUseCHP, ciphertext, plaint
|
|||||||
func (s *symmetricState) DecryptAndHash(cipher *singleUseCHP, plaintext, ciphertext []byte) error {
|
func (s *symmetricState) DecryptAndHash(cipher *singleUseCHP, plaintext, ciphertext []byte) error {
|
||||||
s.checkFinished()
|
s.checkFinished()
|
||||||
if len(ciphertext) != len(plaintext)+chp.Overhead {
|
if len(ciphertext) != len(plaintext)+chp.Overhead {
|
||||||
panic("plaintext is wrong size for given ciphertext")
|
return errors.New("plaintext is wrong size for given ciphertext")
|
||||||
}
|
}
|
||||||
if _, err := cipher.Open(plaintext[:0], ciphertext, s.h[:]); err != nil {
|
if _, err := cipher.Open(plaintext[:0], ciphertext, s.h[:]); err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user