Add tests for malformed HelloRequests.

Change-Id: Iff053022c7ffe5b01c0daf95726cc7d49c33cbd6
Reviewed-on: https://boringssl-review.googlesource.com/6640
Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
David Benjamin 2015-12-06 13:17:07 -05:00 committed by Adam Langley
parent 8411b248c3
commit ef5dfd2980
3 changed files with 39 additions and 2 deletions

View File

@ -809,6 +809,10 @@ type ProtocolBugs struct {
// BadChangeCipherSpec, if not nil, is the body to be sent in
// ChangeCipherSpec records instead of {1}.
BadChangeCipherSpec []byte
// BadHelloRequest, if not nil, is what to send instead of a
// HelloRequest.
BadHelloRequest []byte
}
func (c *Config) serverInit() {

View File

@ -1201,8 +1201,11 @@ func (c *Conn) handleRenegotiation() error {
func (c *Conn) Renegotiate() error {
if !c.isClient {
helloReq := new(helloRequestMsg)
c.writeRecord(recordTypeHandshake, helloReq.marshal())
helloReq := new(helloRequestMsg).marshal()
if c.config.Bugs.BadHelloRequest != nil {
helloReq = c.config.Bugs.BadHelloRequest
}
c.writeRecord(recordTypeHandshake, helloReq)
}
c.handshakeComplete = false

View File

@ -2037,6 +2037,36 @@ func addBasicTests() {
shouldFail: true,
expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
},
{
name: "BadHelloRequest-1",
renegotiate: 1,
config: Config{
Bugs: ProtocolBugs{
BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
},
},
flags: []string{
"-renegotiate-freely",
"-expect-total-renegotiations", "1",
},
shouldFail: true,
expectedError: ":BAD_HELLO_REQUEST:",
},
{
name: "BadHelloRequest-2",
renegotiate: 1,
config: Config{
Bugs: ProtocolBugs{
BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
},
},
flags: []string{
"-renegotiate-freely",
"-expect-total-renegotiations", "1",
},
shouldFail: true,
expectedError: ":BAD_HELLO_REQUEST:",
},
}
testCases = append(testCases, basicTests...)
}