Parcourir la source

Add a test to assert parsing V2ClientHellos works.

Should have test coverage there as long as we care about supporting it.

Change-Id: Ic67539228b550f2ebd0b543d5a58640913b0474b
Reviewed-on: https://boringssl-review.googlesource.com/1371
Reviewed-by: Adam Langley <agl@google.com>
kris/onging/CECPQ3_patch15
David Benjamin il y a 10 ans
committed by Adam Langley
Parent
révision
d86c7671a8
5 fichiers modifiés avec 99 ajouts et 5 suppressions
  1. +4
    -0
      ssl/test/runner/common.go
  2. +9
    -0
      ssl/test/runner/conn.go
  3. +16
    -2
      ssl/test/runner/handshake_client.go
  4. +54
    -0
      ssl/test/runner/handshake_messages.go
  5. +16
    -3
      ssl/test/runner/runner.go

+ 4
- 0
ssl/test/runner/common.go Voir le fichier

@@ -383,6 +383,10 @@ type ProtocolBugs struct {
// SkipNewSessionTicket causes the server to skip sending the
// NewSessionTicket message despite promising to in ServerHello.
SkipNewSessionTicket bool

// SendV2ClientHello causes the client to send a V2ClientHello
// instead of a normal ClientHello.
SendV2ClientHello bool
}

func (c *Config) serverInit() {


+ 9
- 0
ssl/test/runner/conn.go Voir le fichier

@@ -700,6 +700,15 @@ func (c *Conn) sendAlert(err alert) error {
return c.sendAlertLocked(err)
}

// writeV2Record writes a record for a V2ClientHello.
func (c *Conn) writeV2Record(data []byte) (n int, err error) {
record := make([]byte, 2+len(data))
record[0] = uint8(len(data)>>8) | 0x80
record[1] = uint8(len(data))
copy(record[2:], data)
return c.conn.Write(record)
}

// writeRecord writes a TLS record with the given type and payload
// to the connection and updates the record layer state.
// c.out.Mutex <= L.


+ 16
- 2
ssl/test/runner/handshake_client.go Voir le fichier

@@ -126,7 +126,21 @@ NextCipherSuite:
}
}

c.writeRecord(recordTypeHandshake, hello.marshal())
var helloBytes []byte
if c.config.Bugs.SendV2ClientHello {
v2Hello := &v2ClientHelloMsg{
vers: hello.vers,
cipherSuites: hello.cipherSuites,
// No session resumption for V2ClientHello.
sessionId: nil,
challenge: hello.random,
}
helloBytes = v2Hello.marshal()
c.writeV2Record(helloBytes)
} else {
helloBytes = hello.marshal()
c.writeRecord(recordTypeHandshake, helloBytes)
}

msg, err := c.readHandshake()
if err != nil {
@@ -162,7 +176,7 @@ NextCipherSuite:
session: session,
}

hs.finishedHash.Write(hs.hello.marshal())
hs.finishedHash.Write(helloBytes)
hs.finishedHash.Write(hs.serverHello.marshal())

if c.config.Bugs.EarlyChangeCipherSpec > 0 {


+ 54
- 0
ssl/test/runner/handshake_messages.go Voir le fichier

@@ -1314,6 +1314,60 @@ func (m *newSessionTicketMsg) unmarshal(data []byte) bool {
return true
}

type v2ClientHelloMsg struct {
raw []byte
vers uint16
cipherSuites []uint16
sessionId []byte
challenge []byte
}

func (m *v2ClientHelloMsg) equal(i interface{}) bool {
m1, ok := i.(*v2ClientHelloMsg)
if !ok {
return false
}

return bytes.Equal(m.raw, m1.raw) &&
m.vers == m1.vers &&
eqUint16s(m.cipherSuites, m1.cipherSuites) &&
bytes.Equal(m.sessionId, m1.sessionId) &&
bytes.Equal(m.challenge, m1.challenge)
}

func (m *v2ClientHelloMsg) marshal() []byte {
if m.raw != nil {
return m.raw
}

length := 1 + 2 + 2 + 2 + 2 + len(m.cipherSuites)*3 + len(m.sessionId) + len(m.challenge)

x := make([]byte, length)
x[0] = 1
x[1] = uint8(m.vers >> 8)
x[2] = uint8(m.vers)
x[3] = uint8((len(m.cipherSuites) * 3) >> 8)
x[4] = uint8(len(m.cipherSuites) * 3)
x[5] = uint8(len(m.sessionId) >> 8)
x[6] = uint8(len(m.sessionId))
x[7] = uint8(len(m.challenge) >> 8)
x[8] = uint8(len(m.challenge))
y := x[9:]
for i, spec := range m.cipherSuites {
y[i*3] = 0
y[i*3+1] = uint8(spec >> 8)
y[i*3+2] = uint8(spec)
}
y = y[len(m.cipherSuites)*3:]
copy(y, m.sessionId)
y = y[len(m.sessionId):]
copy(y, m.challenge)

m.raw = x

return x
}

func eqUint16s(x, y []uint16) bool {
if len(x) != len(y) {
return false


+ 16
- 3
ssl/test/runner/runner.go Voir le fichier

@@ -347,7 +347,7 @@ var testCases = []testCase{
name: "FalseStart",
config: Config{
CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
NextProtos: []string{"foo"},
NextProtos: []string{"foo"},
},
flags: []string{
"-false-start",
@@ -358,8 +358,8 @@ var testCases = []testCase{
{
name: "FalseStart-SessionTicketsDisabled",
config: Config{
CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
NextProtos: []string{"foo"},
CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
NextProtos: []string{"foo"},
SessionTicketsDisabled: true,
},
flags: []string{
@@ -367,6 +367,19 @@ var testCases = []testCase{
"-select-next-proto", "foo",
},
},
{
testType: serverTest,
name: "SendV2ClientHello",
config: Config{
// Choose a cipher suite that does not involve
// elliptic curves, so no extensions are
// involved.
CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
Bugs: ProtocolBugs{
SendV2ClientHello: true,
},
},
},
}

func doExchange(testType testType, config *Config, conn net.Conn, messageLen int) error {


Chargement…
Annuler
Enregistrer