Skip to content

Commit

Permalink
Merge pull request #197 from mihirjham/mihir/sanitize-summary
Browse files Browse the repository at this point in the history
update(core): Sanitizied the output of Summary to remove key material
  • Loading branch information
eiginn authored Jan 15, 2020
2 parents 3f826ee + 672eef5 commit 1977696
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type DelegateRequest struct {
}

type CreateUserRequest struct {
Name string
Name string
Password string
UserType string
HipchatName string
Expand Down Expand Up @@ -113,7 +113,7 @@ type SSHSignWithRequest struct {
type SSHSignatureWithDelegates struct {
SignatureFormat string
Signature []byte
Secure bool
Secure bool
Delegates []string
}

Expand All @@ -135,13 +135,13 @@ type ExportRequest struct {
}

type OrderRequest struct {
Name string
Name string
Password string
Duration string
Uses int
Users []string
Uses int
Users []string
EncryptedData []byte
Labels []string
Labels []string
}

type OrderInfoRequest struct {
Expand Down Expand Up @@ -178,10 +178,17 @@ type ResponseData struct {
type SummaryData struct {
Status string
State string
Live map[string]keycache.ActiveUser
Live map[string]ActiveUser
All map[string]passvault.Summary
}

type ActiveUser struct {
keycache.Usage
AltNames map[string]string
Admin bool
Type string
}

type DecryptWithDelegates struct {
Data []byte
Secure bool
Expand Down Expand Up @@ -209,7 +216,7 @@ func jsonStatusError(err error) ([]byte, error) {
}
func jsonSummary() ([]byte, error) {
state := crypt.Status()
return json.Marshal(SummaryData{Status: "ok", State: state.State, Live: crypt.LiveSummary(), All: records.GetSummary()})
return json.Marshal(SummaryData{Status: "ok", State: state.State, Live: liveSummary(), All: records.GetSummary()})
}
func jsonResponse(resp []byte) ([]byte, error) {
return json.Marshal(ResponseData{Status: "ok", Response: resp})
Expand Down Expand Up @@ -253,6 +260,24 @@ func validateName(name, password string) error {
return nil
}

// liveSummary creates a sanitized version of cryptor.LiveSummary() without any key material
func liveSummary() map[string]ActiveUser {
currLiveSummary := crypt.LiveSummary()
summaryData := make(map[string]ActiveUser)

for summaryInfo, activeUser := range currLiveSummary {
sanitizedActiveUser := ActiveUser{
Usage: activeUser.Usage,
AltNames: activeUser.AltNames,
Admin: activeUser.Admin,
Type: activeUser.Type,
}
summaryData[summaryInfo] = sanitizedActiveUser
}

return summaryData
}

// Init reads the records from disk from a given path
func Init(path string, config *config.Config) error {
var err error
Expand Down Expand Up @@ -723,7 +748,6 @@ func Decrypt(jsonIn []byte) ([]byte, error) {
}
}


resp := &DecryptWithDelegates{
Data: data,
Secure: secure,
Expand Down Expand Up @@ -819,7 +843,6 @@ func SSHSignWith(jsonIn []byte) ([]byte, error) {
return jsonResponse(out)
}


// Modify processes a modify request.
func Modify(jsonIn []byte) ([]byte, error) {
var s ModifyRequest
Expand Down

0 comments on commit 1977696

Please sign in to comment.