Debian Codegraph @

handshake/patterns.go

raw
1 package handshake
2
3 import (
4 "fmt"
5
6 "github.com/flynn/noise"
7 "github.com/slackhq/nebula/header"
8 )
9
10 // msgFlags tracks what application data a handshake message carries.
11 type msgFlags struct {
12 expectsPayload bool // message carries indexes and time
13 expectsCert bool // message carries the certificate
14 }
15
16 // subtypeInfo bundles the noise pattern with the per-message flags for a
17 // given handshake subtype.
18 type subtypeInfo struct {
19 pattern noise.HandshakePattern
20 msgs []msgFlags
21 }
22
23 // subtypeInfos defines the noise pattern and message content layout for each
24 // handshake subtype.
25 var subtypeInfos = map[header.MessageSubType]subtypeInfo{
26 // IX: 2 messages, both carry payload and cert
27 header.HandshakeIXPSK0: {
28 pattern: noise.HandshakeIX,
29 msgs: []msgFlags{
30 {expectsPayload: true, expectsCert: true},
31 {expectsPayload: true, expectsCert: true},
32 },
33 },
34
35 // XX: 3 messages
36 // msg1 (I->R): payload only
37 // msg2 (R->I): payload + cert
38 // msg3 (I->R): cert only
39 //header.HandshakeXXPSK0: {
40 // pattern: noise.HandshakeXX,
41 // msgs: []msgFlags{
42 // {expectsPayload: true, expectsCert: false},
43 // {expectsPayload: true, expectsCert: true},
44 // {expectsPayload: false, expectsCert: true},
45 // },
46 //},
47 }
48
49 func subtypeInfoFor(subtype header.MessageSubType) (subtypeInfo, error) {
50 if info, ok := subtypeInfos[subtype]; ok {
51 return info, nil
52 }
53 return subtypeInfo{}, fmt.Errorf("%w: %d", ErrUnknownSubtype, subtype)
54 }