github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/service/session.go (about) 1 // Copyright 2015 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 package service 5 6 import ( 7 "golang.org/x/net/context" 8 9 "github.com/keybase/client/go/libkb" 10 keybase1 "github.com/keybase/client/go/protocol/keybase1" 11 "github.com/keybase/go-framed-msgpack-rpc/rpc" 12 ) 13 14 // SessionHandler is the RPC handler for the session interface. 15 type SessionHandler struct { 16 libkb.Contextified 17 *BaseHandler 18 } 19 20 // NewSessionHandler creates a SessionHandler for the xp transport. 21 func NewSessionHandler(xp rpc.Transporter, g *libkb.GlobalContext) *SessionHandler { 22 return &SessionHandler{ 23 BaseHandler: NewBaseHandler(g, xp), 24 Contextified: libkb.NewContextified(g), 25 } 26 } 27 28 // CurrentSession uses the global session to find the session. If 29 // the user isn't logged in, it returns libkb.NoSessionError. 30 // 31 // This function was modified to use cached information instead 32 // of loading the full self user. 33 // 34 // This does do a full call to sesscheck and ensures that the 35 // session token is valid. 36 func (h *SessionHandler) CurrentSession(ctx context.Context, sessionID int) (keybase1.Session, error) { 37 var s keybase1.Session 38 39 nist, uid, _, err := h.G().ActiveDevice.NISTAndUIDDeviceID(ctx) 40 if nist == nil { 41 return s, libkb.NoSessionError{} 42 } 43 if err != nil { 44 return s, err 45 } 46 47 un, err := h.G().GetUPAKLoader().LookupUsername(ctx, uid) 48 if err != nil { 49 return s, err 50 } 51 sibkey, err := h.G().ActiveDevice.SigningKey() 52 if err != nil { 53 return s, err 54 } 55 subkey, err := h.G().ActiveDevice.EncryptionKey() 56 if err != nil { 57 return s, err 58 } 59 60 s.Uid = uid 61 s.Username = un.String() 62 s.Token = nist.Token().String() 63 s.DeviceSubkeyKid = subkey.GetKID() 64 s.DeviceSibkeyKid = sibkey.GetKID() 65 66 return s, nil 67 } 68 69 // SessionPing can be used by keepalives for connected services. 70 func (h *SessionHandler) SessionPing(context.Context) error { 71 return nil 72 }