Skip to content

Commit 8557ed1

Browse files
committed
Implement static 1.3 CID negotiation
1 parent ae4a3f4 commit 8557ed1

4 files changed

Lines changed: 15 additions & 5 deletions

File tree

conn.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,6 @@ func (c *Conn) Write(payload []byte) (int, error) {
591591
return 0, err
592592
}
593593

594-
//nolint:godox
595-
// TODO: check for version
596594
ctx, cancel := c.contextWithClose(c.writeDeadline)
597595
defer cancel()
598596

@@ -606,7 +604,7 @@ func (c *Conn) Write(payload []byte) (int, error) {
606604
Data: payload,
607605
},
608606
},
609-
ShouldWrapCID: len(dtlsstate.CommonState(c.state).RemoteConnectionID) > 0,
607+
ShouldWrapCID: c.state.ShouldWrapConnectionID(),
610608
ShouldEncrypt: true,
611609
},
612610
})
@@ -2269,7 +2267,6 @@ func (c *Conn) notify(ctx context.Context, level alert.Level, desc alert.Descrip
22692267
}
22702268
}
22712269

2272-
// This should be updated with DTLS 1.3 record encoding.
22732270
return c.writePackets(ctx, []*dtlsflight.Packet{
22742271
{
22752272
Record: &recordlayer.RecordLayer{
@@ -2282,7 +2279,7 @@ func (c *Conn) notify(ctx context.Context, level alert.Level, desc alert.Descrip
22822279
Description: desc,
22832280
},
22842281
},
2285-
ShouldWrapCID: len(common.RemoteConnectionID) > 0,
2282+
ShouldWrapCID: c.state.ShouldWrapConnectionID(),
22862283
ShouldEncrypt: c.isHandshakeCompletedSuccessfully(),
22872284
},
22882285
})

internal/state/active_state.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
// Active is a concrete DTLS version state that shares common connection fields.
1212
type Active interface {
1313
CommonFields() *Common
14+
ShouldWrapConnectionID() bool
1415
}
1516

1617
// NewActive creates a DTLS 1.2 active state with initialized common fields.

internal/state/state12.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ type State12 struct {
3838
PeerCertificatesVerified bool
3939
}
4040

41+
// ShouldWrapConnectionID reports whether outgoing DTLS 1.2 records should
42+
// use CID record encoding.
43+
func (s *State12) ShouldWrapConnectionID() bool {
44+
return s != nil && s.Common != nil && len(s.RemoteConnectionID) > 0
45+
}
46+
4147
func (s *State12) InitCipherSuite() error {
4248
if s.CipherSuite == nil {
4349
return dtlserrors.ErrCipherSuiteNotSet

internal/state/state13.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,9 @@ type State13 struct {
119119
RemoteSignatureSchemes []signaturehash.Algorithm // signature_algorithms from peer
120120
RemoteCertSignatureSchemes []signaturehash.Algorithm // signature_algorithms_cert from peer
121121
}
122+
123+
// ShouldWrapConnectionID reports whether outgoing records should use the
124+
// legacy DTLS 1.2 CID record encoding.
125+
func (*State13) ShouldWrapConnectionID() bool {
126+
return false
127+
}

0 commit comments

Comments
 (0)