watchtower: add wtclient.ClientSession constructor

This commit is contained in:
Elle Mouton
2022-10-21 11:24:46 +02:00
parent 0ed5c750c8
commit 41e36c7ec7
2 changed files with 34 additions and 15 deletions

View File

@@ -435,27 +435,19 @@ func getTowerAndSessionCandidates(db DB, keyRing ECDHKeyRing,
}
for _, s := range sessions {
towerKeyDesc, err := keyRing.DeriveKey(
keychain.KeyLocator{
Family: keychain.KeyFamilyTowerSession,
Index: s.KeyIndex,
},
if !sessionFilter(s) {
continue
}
cs, err := NewClientSessionFromDBSession(
s, tower, keyRing,
)
if err != nil {
return nil, err
}
sessionKeyECDH := keychain.NewPubKeyECDH(
towerKeyDesc, keyRing,
)
// Add the session to the set of candidate sessions.
candidateSessions[s.ID] = &ClientSession{
ID: s.ID,
ClientSessionBody: s.ClientSessionBody,
Tower: tower,
SessionKeyECDH: sessionKeyECDH,
}
candidateSessions[s.ID] = cs
perActiveTower(tower)
}

View File

@@ -198,3 +198,30 @@ type ClientSession struct {
// key used to connect to the watchtower.
SessionKeyECDH keychain.SingleKeyECDH
}
// NewClientSessionFromDBSession converts a wtdb.ClientSession to a
// ClientSession.
func NewClientSessionFromDBSession(s *wtdb.ClientSession, tower *Tower,
keyRing ECDHKeyRing) (*ClientSession, error) {
towerKeyDesc, err := keyRing.DeriveKey(
keychain.KeyLocator{
Family: keychain.KeyFamilyTowerSession,
Index: s.KeyIndex,
},
)
if err != nil {
return nil, err
}
sessionKeyECDH := keychain.NewPubKeyECDH(
towerKeyDesc, keyRing,
)
return &ClientSession{
ID: s.ID,
ClientSessionBody: s.ClientSessionBody,
Tower: tower,
SessionKeyECDH: sessionKeyECDH,
}, nil
}