mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 14:04:02 +03:00
Fix double TLS wrapping for noise
This commit is contained in:
@@ -54,7 +54,7 @@ func SendServerHello(w io.Writer, secret []byte, clientHello *ClientHello) ([]by
|
|||||||
|
|
||||||
_, err := w.Write(packet)
|
_, err := w.Write(packet)
|
||||||
|
|
||||||
return noise.Bytes(), err
|
return noise.Bytes()[tls.SizeHeader:], err
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateServerHello(buf *bytes.Buffer, hello *ClientHello) {
|
func generateServerHello(buf *bytes.Buffer, hello *ClientHello) {
|
||||||
|
|||||||
@@ -55,13 +55,8 @@ func (suite *SendServerHelloTestSuite) TestRecordStructure() {
|
|||||||
|
|
||||||
suite.Empty(suite.buf.Bytes())
|
suite.Empty(suite.buf.Bytes())
|
||||||
|
|
||||||
noiseBuf := bytes.NewReader(noise)
|
// noise is raw payload without TLS record header
|
||||||
rec.Reset()
|
suite.Len(noise, 1369)
|
||||||
|
|
||||||
recordType, _, err = tls.ReadRecord(noiseBuf, &rec)
|
|
||||||
suite.NoError(err)
|
|
||||||
suite.Equal(byte(tls.TypeApplicationData), recordType)
|
|
||||||
suite.Zero(noiseBuf.Len())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *SendServerHelloTestSuite) TestHMAC() {
|
func (suite *SendServerHelloTestSuite) TestHMAC() {
|
||||||
@@ -78,7 +73,13 @@ func (suite *SendServerHelloTestSuite) TestHMAC() {
|
|||||||
mac := hmac.New(sha256.New, suite.secret.Key[:])
|
mac := hmac.New(sha256.New, suite.secret.Key[:])
|
||||||
mac.Write(suite.hello.Random[:])
|
mac.Write(suite.hello.Random[:])
|
||||||
mac.Write(packet)
|
mac.Write(packet)
|
||||||
mac.Write(noise)
|
|
||||||
|
// HMAC is computed over the full noise TLS record (with header),
|
||||||
|
// but SendServerHello returns noise without the header,
|
||||||
|
// so we reconstruct the full record.
|
||||||
|
var fullNoise bytes.Buffer
|
||||||
|
tls.WriteRecord(&fullNoise, noise) //nolint: errcheck
|
||||||
|
mac.Write(fullNoise.Bytes())
|
||||||
|
|
||||||
suite.Equal(random, mac.Sum(nil))
|
suite.Equal(random, mac.Sum(nil))
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -204,7 +204,7 @@ func (p *Proxy) doFakeTLSHandshake(ctx *streamContext) ([]byte, bool) {
|
|||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.clientConn = tls.New(ctx.clientConn, true, true)
|
ctx.clientConn = tls.New(ctx.clientConn, true, false)
|
||||||
|
|
||||||
return noise, true
|
return noise, true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user