Skip to content

Commit

Permalink
Merge pull request #51 from 99designs/session-key-tied-to-config
Browse files Browse the repository at this point in the history
Add a hash to the session key, tied to duration and mfa
  • Loading branch information
lox committed Oct 26, 2015
2 parents f876b69 + 4cd67bd commit c049524
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion sessions.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -30,7 +32,16 @@ func NewKeyringSessions(k keyring.Keyring) (*KeyringSessions, error) {
}

func (s *KeyringSessions) key(profile string, duration time.Duration) string {
return s.Profiles.sourceProfile(profile) + " session"
source := s.Profiles.sourceProfile(profile)
hasher := md5.New()
hasher.Write([]byte(duration.String()))

if p, ok := s.Profiles[profile]; ok {
enc := json.NewEncoder(hasher)
enc.Encode(p)
}

return fmt.Sprintf("%s session (%x)", source, hex.EncodeToString(hasher.Sum(nil))[0:10])
}

func (s *KeyringSessions) Retrieve(profile string, duration time.Duration) (session sts.Credentials, err error) {
Expand Down

0 comments on commit c049524

Please sign in to comment.