remove the force and duration options

This commit is contained in:
Aaron Bieber 2024-08-26 19:32:40 -06:00
parent 912cb41798
commit ec38dea803
No known key found for this signature in database
3 changed files with 14 additions and 24 deletions

View File

@ -31,12 +31,10 @@ type Traygent struct {
passphrase []byte passphrase []byte
locked bool locked bool
addChan chan ssh.PublicKey addChan chan ssh.PublicKey
rmChan chan string rmChan chan string
sigReq chan ssh.PublicKey sigReq chan ssh.PublicKey
sigResp chan bool sigResp chan bool
force bool
forceDuration int
} }
func (t *Traygent) log(_, msgFmt string, msg ...any) { func (t *Traygent) log(_, msgFmt string, msg ...any) {
@ -238,7 +236,7 @@ func (t *Traygent) Add(key agent.AddedKey) error {
return err return err
} }
p := NewPrivKey(signer, key, t.force, t.forceDuration) p := NewPrivKey(signer, key)
t.mu.RLock() t.mu.RLock()
for _, k := range t.keys { for _, k := range t.keys {

14
main.go
View File

@ -24,8 +24,6 @@ func init() {
func main() { func main() {
sock := flag.String("s", path.Join(os.Getenv("HOME"), ".traygent"), "Socket path to create") sock := flag.String("s", path.Join(os.Getenv("HOME"), ".traygent"), "Socket path to create")
cmdList := flag.String("c", "/etc/traygent.json", "List of commands to execute") cmdList := flag.String("c", "/etc/traygent.json", "List of commands to execute")
force := flag.Bool("f", true, "force expiration of keys")
forceDuration := flag.Int("d", 300, "seconds for forced expiration")
flag.Parse() flag.Parse()
os.Remove(*sock) os.Remove(*sock)
@ -48,13 +46,11 @@ func main() {
cmds := LoadCommands(*cmdList) cmds := LoadCommands(*cmdList)
tagent := Traygent{ tagent := Traygent{
listener: l, listener: l,
addChan: make(chan ssh.PublicKey), addChan: make(chan ssh.PublicKey),
rmChan: make(chan string), rmChan: make(chan string),
sigReq: make(chan ssh.PublicKey), sigReq: make(chan ssh.PublicKey),
sigResp: make(chan bool), sigResp: make(chan bool),
force: *force,
forceDuration: *forceDuration,
} }
trayApp := app.NewWithID("com.bolddaemon.traygent") trayApp := app.NewWithID("com.bolddaemon.traygent")

View File

@ -40,22 +40,18 @@ func (p *privKey) GetComment() string {
return p.comment return p.comment
} }
func (p *privKey) setExpire(key agent.AddedKey, force bool, duration int) { func (p *privKey) setExpire(key agent.AddedKey) {
exp := key.LifetimeSecs exp := key.LifetimeSecs
if force && exp <= 0 {
exp = uint32(duration)
}
t := time.Now().Add(time.Duration(exp) * time.Second) t := time.Now().Add(time.Duration(exp) * time.Second)
key.LifetimeSecs = exp
p.lifetime = key.LifetimeSecs p.lifetime = key.LifetimeSecs
if exp > 0 { if exp > 0 {
p.expireTime = &t p.expireTime = &t
} }
} }
func NewPrivKey(signer ssh.Signer, key agent.AddedKey, force bool, duration int) privKey { func NewPrivKey(signer ssh.Signer, key agent.AddedKey) privKey {
pub := signer.PublicKey() pub := signer.PublicKey()
pk := privKey{ pk := privKey{
signer: signer, signer: signer,
@ -63,7 +59,7 @@ func NewPrivKey(signer ssh.Signer, key agent.AddedKey, force bool, duration int)
pubKey: pub, pubKey: pub,
fingerPrint: ssh.FingerprintSHA256(pub), fingerPrint: ssh.FingerprintSHA256(pub),
} }
pk.setExpire(key, force, duration) pk.setExpire(key)
return pk return pk
} }