Skip to content

Commit

Permalink
Merge pull request #133 from bifurcation/draft-21
Browse files Browse the repository at this point in the history
Support draft-21
  • Loading branch information
bifurcation authored Jul 9, 2017
2 parents 4111e79 + 0cee267 commit 0b79b70
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion common.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mint

var (
supportedVersion uint16 = 0x7f14 // draft-20
supportedVersion uint16 = 0x7f15 // draft-21

// Flags for some minor compat issues
allowWrongVersionNumber = true
Expand Down
1 change: 1 addition & 0 deletions crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ const (
labelResumptionSecret = "res master"
labelDerived = "derived"
labelFinished = "finished"
labelResumption = "resumption"
)

// struct HkdfLabel {
Expand Down
11 changes: 8 additions & 3 deletions handshake-messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,27 +368,32 @@ func (cr *CertificateRequestBody) Unmarshal(data []byte) (int, error) {
// struct {
// uint32 ticket_lifetime;
// uint32 ticket_age_add;
// opaque ticket_nonce<1..255>;
// opaque ticket<1..2^16-1>;
// Extension extensions<0..2^16-2>;
// } NewSessionTicket;
type NewSessionTicketBody struct {
TicketLifetime uint32
TicketAgeAdd uint32
TicketNonce []byte `tls:"head=1,min=1"`
Ticket []byte `tls:"head=2,min=1"`
Extensions ExtensionList `tls:"head=2"`
}

const ticketNonceLen = 16

func NewSessionTicket(ticketLen int, ticketLifetime uint32) (*NewSessionTicketBody, error) {
buf := make([]byte, ticketLen+4)
buf := make([]byte, 4+ticketNonceLen+ticketLen)
_, err := prng.Read(buf)
if err != nil {
return nil, err
}

tkt := &NewSessionTicketBody{
TicketLifetime: ticketLifetime,
TicketAgeAdd: binary.BigEndian.Uint32(buf[ticketLen:]),
Ticket: buf[:ticketLen],
TicketAgeAdd: binary.BigEndian.Uint32(buf[:4]),
TicketNonce: buf[4 : 4+ticketNonceLen],
Ticket: buf[4+ticketNonceLen:],
}

return tkt, err
Expand Down
5 changes: 3 additions & 2 deletions handshake-messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,12 @@ var (
"000a000d0006000404030503" // extensions

// NewSessionTicket test cases
ticketValidHex = "00010203" + "04050607" + "000408090a0b" + "0006eeff00021122"
ticketValidHex = "00010203" + "04050607" + "0408090a0b" + "00040c0d0e0f" + "0006eeff00021122"
ticketValidIn = NewSessionTicketBody{
TicketLifetime: 0x00010203,
TicketAgeAdd: 0x04050607,
Ticket: []byte{0x08, 0x09, 0x0a, 0x0b},
TicketNonce: []byte{0x08, 0x09, 0x0a, 0x0b},
Ticket: []byte{0x0c, 0x0d, 0x0e, 0x0f},
Extensions: []Extension{
{
ExtensionType: 0xeeff,
Expand Down
10 changes: 8 additions & 2 deletions state-machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,14 @@ func (state *StateConnected) NewSessionTicket(length int, lifetime, earlyDataLif
return nil, AlertInternalError
}

resumptionKey := hkdfExpandLabel(state.cryptoParams.hash, state.resumptionSecret,
labelResumption, tkt.TicketNonce, state.cryptoParams.hash.Size())

newPSK := PreSharedKey{
CipherSuite: state.cryptoParams.suite,
IsResumption: true,
Identity: tkt.Ticket,
Key: state.resumptionSecret,
Key: resumptionKey,
NextProto: state.Params.NextProto,
ReceivedAt: time.Now(),
ExpiresAt: time.Now().Add(time.Duration(tkt.TicketLifetime) * time.Second),
Expand Down Expand Up @@ -196,11 +199,14 @@ func (state StateConnected) Next(hm *HandshakeMessage) (HandshakeState, []Handsh
return nil, nil, AlertUnexpectedMessage
}

resumptionKey := hkdfExpandLabel(state.cryptoParams.hash, state.resumptionSecret,
labelResumption, body.TicketNonce, state.cryptoParams.hash.Size())

psk := PreSharedKey{
CipherSuite: state.cryptoParams.suite,
IsResumption: true,
Identity: body.Ticket,
Key: state.resumptionSecret,
Key: resumptionKey,
NextProto: state.Params.NextProto,
ReceivedAt: time.Now(),
ExpiresAt: time.Now().Add(time.Duration(body.TicketLifetime) * time.Second),
Expand Down

0 comments on commit 0b79b70

Please sign in to comment.