randomly generate the server config ID and check whether it matches

This commit is contained in:
Lucas Clemente
2016-04-16 00:09:50 +02:00
parent 06a4201d65
commit 13c0445bb4
3 changed files with 16 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ package handshake
import (
"bytes"
"crypto/rand"
"github.com/lucas-clemente/quic-go/crypto"
)
@@ -10,13 +11,20 @@ import (
type ServerConfig struct {
kex crypto.KeyExchange
kd *crypto.KeyData
ID []byte
}
// NewServerConfig creates a new server config
func NewServerConfig(kex crypto.KeyExchange, kd *crypto.KeyData) *ServerConfig {
id := make([]byte, 16)
_, err := rand.Reader.Read(id)
if err != nil {
panic(err)
}
return &ServerConfig{
kex: kex,
kd: kd,
ID: id,
}
}
@@ -24,7 +32,7 @@ func NewServerConfig(kex crypto.KeyExchange, kd *crypto.KeyData) *ServerConfig {
func (s *ServerConfig) Get() []byte {
var serverConfig bytes.Buffer
WriteHandshakeMessage(&serverConfig, TagSCFG, map[Tag][]byte{
TagSCID: []byte{0xC5, 0x1C, 0x73, 0x6B, 0x8F, 0x48, 0x49, 0xAE, 0xB3, 0x00, 0xA2, 0xD4, 0x4B, 0xA0, 0xCF, 0xDF},
TagSCID: s.ID,
TagKEXS: []byte("C255"),
TagAEAD: []byte("CC20"),
TagPUBS: append([]byte{0x20, 0x00, 0x00}, s.kex.PublicKey()...),