Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Secret connection read buffer #124

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion p2p/conn/evil_secret_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ func TestMakeSecretConnection(t *testing.T) {
{"share bad ethimeral key", newEvilConn(true, true, false, false), "wrong wireType"},
{"refuse to share auth signature", newEvilConn(true, false, false, false), "EOF"},
{"share bad auth signature", newEvilConn(true, false, true, true), "failed to decrypt SecretConnection"},
{"all good", newEvilConn(true, false, true, false), ""},
}

for _, tc := range testCases {
Expand Down
5 changes: 3 additions & 2 deletions p2p/conn/secret_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ var (
// Otherwise they are vulnerable to MITM.
// (TODO(ismail): see also https://github.com/tendermint/tendermint/issues/3010)
type SecretConnection struct {

// immutable
recvAead cipher.AEAD
sendAead cipher.AEAD
Expand All @@ -73,6 +72,7 @@ type SecretConnection struct {

conn io.ReadWriteCloser
connWriter *bufio.Writer
connReader io.Reader

// net.Conn must be thread safe:
// https://golang.org/pkg/net/#Conn.
Expand Down Expand Up @@ -155,6 +155,7 @@ func MakeSecretConnection(conn io.ReadWriteCloser, locPrivKey crypto.PrivKey) (*
sc := &SecretConnection{
conn: conn,
connWriter: bufio.NewWriterSize(conn, defaultWriteBufferSize),
connReader: bufio.NewReaderSize(conn, defaultReadBufferSize),
recvBuffer: nil,
recvNonce: new([aeadNonceSize]byte),
sendNonce: new([aeadNonceSize]byte),
Expand Down Expand Up @@ -250,7 +251,7 @@ func (sc *SecretConnection) Read(data []byte) (n int, err error) {

// read off the conn
sealedFrame := sc.recvSealedFrame
_, err = io.ReadFull(sc.conn, sealedFrame)
_, err = io.ReadFull(sc.connReader, sealedFrame)
if err != nil {
return
}
Expand Down
Loading