-
Notifications
You must be signed in to change notification settings - Fork 6
/
child_sa.go
66 lines (61 loc) · 2 KB
/
child_sa.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package ike
import (
"bytes"
"github.com/msgboxio/ike/protocol"
"github.com/pkg/errors"
)
// ChildSaFromSession creates CREATE_CHILD_SA messages
// HDR, SK {N(REKEY_SA), SA, Ni, [KEi,] TSi, TSr} -->
// <-- HDR, SK {SA, Nr, [KEr,] TSi, TSr}
func ChildSaFromSession(sess *Session, newTkm *Tkm, isInitiator bool, espSpi []byte) *Message {
no := newTkm.Nr
targetEspSpi := sess.EspSpiR
if isInitiator {
no = newTkm.Ni
targetEspSpi = sess.EspSpiI
}
prop := protocol.ProposalFromTransform(protocol.ESP, sess.cfg.ProposalEsp, espSpi)
return makeChildSa(
&childSaParams{
authParams: &authParams{
isResponse: !isInitiator,
isInitiator: isInitiator,
isTransportMode: sess.cfg.IsTransportMode,
spiI: sess.IkeSpiI,
spiR: sess.IkeSpiR,
proposals: prop,
tsI: sess.cfg.TsI,
tsR: sess.cfg.TsR,
lifetime: sess.cfg.Lifetime,
},
targetEspSpi: targetEspSpi,
nonce: no,
dhTransformId: newTkm.suite.DhGroup.TransformId(),
dhPublic: newTkm.DhPublic,
})
}
func checkIpsecRekeyRequest(sess *Session, params *childSaParams) (espSpiI protocol.Spi, err error) {
if params.tsI == nil || params.tsR == nil {
err = errors.Errorf("CREATE_CHILD_SA request: selectors are missing. Rekeying IKE SA unsupported")
return
}
if params.targetEspSpi == nil {
err = errors.Errorf("CREATE_CHILD_SA request: missing target ESP")
return
}
if !bytes.Equal(params.targetEspSpi, sess.EspSpiI) {
err = errors.Errorf("CREATE_CHILD_SA request: incorrect target ESP Spi: 0x%x, rx 0x%x",
params.targetEspSpi, sess.EspSpiI)
return
}
espSpiI, _, err = checkSelectorsForSession(sess, params.authParams)
return
}
func checkIpsecRekeyResponse(sess *Session, params *childSaParams) (espSpiR protocol.Spi, err error) {
if params.tsI == nil || params.tsR == nil {
err = errors.Errorf("CREATE_CHILD_SA response: selectors are missing")
return
}
espSpiR, _, err = checkSelectorsForSession(sess, params.authParams)
return
}