mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 14:04:02 +03:00
Have a noise of variable size
This commit is contained in:
@@ -7,15 +7,17 @@ import (
|
|||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"io"
|
"io"
|
||||||
|
"math"
|
||||||
|
rnd "math/rand/v2"
|
||||||
|
|
||||||
|
"github.com/9seconds/mtg/v2/mtglib/internal/doppel"
|
||||||
"github.com/9seconds/mtg/v2/mtglib/internal/tls"
|
"github.com/9seconds/mtg/v2/mtglib/internal/tls"
|
||||||
"golang.org/x/crypto/curve25519"
|
"golang.org/x/crypto/curve25519"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TypeHandshakeServer = 0x02
|
TypeHandshakeServer = 0x02
|
||||||
|
ChangeCipherValue = 0x01
|
||||||
ChangeCipherValue = 0x01
|
|
||||||
|
|
||||||
EllipticCurveLen = 32
|
EllipticCurveLen = 32
|
||||||
)
|
)
|
||||||
@@ -125,7 +127,8 @@ func generateChangeCipherValue(buf *bytes.Buffer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func generateNoise(buf *bytes.Buffer) {
|
func generateNoise(buf *bytes.Buffer) {
|
||||||
data := [1369]byte{}
|
minSize := int(math.Round(0.75 * float64(doppel.TLSRecordSizeMax)))
|
||||||
|
data := make([]byte, minSize+rnd.IntN(doppel.TLSRecordSizeMax-minSize))
|
||||||
|
|
||||||
if _, err := rand.Read(data[:]); err != nil {
|
if _, err := rand.Read(data[:]); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/9seconds/mtg/v2/mtglib"
|
"github.com/9seconds/mtg/v2/mtglib"
|
||||||
|
"github.com/9seconds/mtg/v2/mtglib/internal/doppel"
|
||||||
"github.com/9seconds/mtg/v2/mtglib/internal/tls"
|
"github.com/9seconds/mtg/v2/mtglib/internal/tls"
|
||||||
"github.com/9seconds/mtg/v2/mtglib/internal/tls/fake"
|
"github.com/9seconds/mtg/v2/mtglib/internal/tls/fake"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
@@ -58,7 +59,7 @@ func (suite *SendServerHelloTestSuite) TestRecordStructure() {
|
|||||||
recordType, length, err := tls.ReadRecord(suite.buf, &rec)
|
recordType, length, err := tls.ReadRecord(suite.buf, &rec)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.Equal(byte(tls.TypeApplicationData), recordType)
|
suite.Equal(byte(tls.TypeApplicationData), recordType)
|
||||||
suite.Equal(int64(1369), length)
|
suite.Greater(length, int64(doppel.TLSRecordSizeStart))
|
||||||
|
|
||||||
suite.Empty(suite.buf.Bytes())
|
suite.Empty(suite.buf.Bytes())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user