Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Option for Delegation to Any User #134

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/ro/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var owners, lefters, righters, inPath, labels, outPath, outEnv string

var uses, minUsers int

var anyUser bool

var duration, users string

var pollInterval time.Duration
Expand Down Expand Up @@ -52,6 +54,7 @@ func registerFlags() {
flag.StringVar(&users, "users", "", "comma separated user list")
flag.IntVar(&uses, "uses", 0, "number of delegated key uses")
flag.IntVar(&minUsers, "minUsers", 2, "minimum number of delegations")
flag.BoolVar(&anyUser, "anyUser", false, "whether any user can decrypt")
flag.StringVar(&duration, "time", "0h", "duration of delegated key uses")
flag.StringVar(&lefters, "left", "", "comma separated left owners")
flag.StringVar(&righters, "right", "", "comma separated right owners")
Expand Down Expand Up @@ -110,6 +113,7 @@ func runDelegate() {
Time: duration,
Users: processCSL(users),
Labels: processCSL(labels),
AnyUser: anyUser,
}
resp, err := roServer.Delegate(req)
processError(err)
Expand Down
39 changes: 32 additions & 7 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ type DelegateRequest struct {
Name string
Password string

Uses int
Time string
Slot string
Users []string
Labels []string
Uses int
Time string
Slot string
Users []string
Labels []string
AnyUser bool
}

type CreateUserRequest struct {
Expand Down Expand Up @@ -216,6 +217,26 @@ func validateName(name, password string) error {
return nil
}

// createCacheUsageFromDelegateRequest converts a DelegateRequest to a cache.Usage object.
func createCacheUsageFromDelegateRequest(s *DelegateRequest) (*keycache.Usage, error) {
var u keycache.Usage
u.Uses = s.Uses
u.AnyUser = s.AnyUser
// copy splices
u.Labels = make([]string, len(s.Labels))
u.Users = make([]string, len(s.Users))
copy(u.Labels, s.Labels)
copy(u.Users, s.Users)
// compute exipiration
duration, err := time.ParseDuration(s.Time)
if err != nil {
return &u, err
}
u.Expiry = time.Now().Add(duration)
fmt.Printf("%#v\n", u)
return &u, nil
}

// Init reads the records from disk from a given path
func Init(path, hcKey, hcRoom, hcHost, roHost string) error {
var err error
Expand Down Expand Up @@ -381,9 +402,9 @@ func Delegate(jsonIn []byte) ([]byte, error) {
return jsonStatusError(err)
}
}

// Find password record for user and verify that their password
// matches. If not found then add a new entry for this user.

pr, found := records.GetRecord(s.Name)
if found {
if err = pr.ValidatePassword(s.Password); err != nil {
Expand All @@ -396,7 +417,11 @@ func Delegate(jsonIn []byte) ([]byte, error) {
}

// add signed-in record to active set
if err = cache.AddKeyFromRecord(pr, s.Name, s.Password, s.Users, s.Labels, s.Uses, s.Slot, s.Time); err != nil {
u, err := createCacheUsageFromDelegateRequest(&s)
if err != nil {
return jsonStatusError(err)
}
if err = cache.AddKeyFromRecord(pr, s.Name, s.Password, s.Slot, u); err != nil {
return jsonStatusError(err)
}

Expand Down
Loading