mirror of
https://github.com/cloudflare/redoctober.git
synced 2026-01-09 15:44:04 +00:00
Update owners API and README with predicates.
This commit is contained in:
@@ -110,7 +110,7 @@ Example query:
|
||||
$ curl --cacert cert/server.crt https://localhost:8080/delegate \
|
||||
-d '{"Name":"Dodo","Password":"Dodgson","Time":"2h34m","Uses":3}'
|
||||
{"Status":"ok"}
|
||||
|
||||
|
||||
### Create User
|
||||
|
||||
Create Users creates a new user account. Allows an optional "UserType"
|
||||
@@ -174,6 +174,13 @@ Example query:
|
||||
-d '{"Name":"Alice","Password":"Lewis","Minimum":2, "Owners":["Alice","Bill","Cat","Dodo"],"Data":"V2h5IGlzIGEgcmF2ZW4gbGlrZSBhIHdyaXRpbmcgZGVzaz8K"}'
|
||||
{"Status":"ok","Response":"eyJWZXJzaW9uIj...NSSllzPSJ9"}
|
||||
|
||||
Example query with a predicate:
|
||||
|
||||
$ curl --cacert cert/server.crt https://localhost:8080/encrypt \
|
||||
-d '{"Name":"Alice","Password":"Lewis","Predicate":"Alice & (Bob | Carl)",
|
||||
Data":"V2h5IGlzIGEgcmF2ZW4gbGlrZSBhIHdyaXRpbmcgZGVzaz8K"}'
|
||||
{"Status":"ok","Response":"eyJWZXJzaW9uIj...NSSllzPSJ9"}
|
||||
|
||||
The data expansion is not tied to the size of the input.
|
||||
|
||||
### Decrypt
|
||||
|
||||
@@ -125,8 +125,9 @@ type DecryptWithDelegates struct {
|
||||
}
|
||||
|
||||
type OwnersData struct {
|
||||
Status string
|
||||
Owners []string
|
||||
Status string
|
||||
Owners []string
|
||||
Predicate string
|
||||
}
|
||||
|
||||
// Helper functions that create JSON responses sent by core
|
||||
@@ -619,12 +620,12 @@ func Owners(jsonIn []byte) ([]byte, error) {
|
||||
return jsonStatusError(err)
|
||||
}
|
||||
|
||||
names, err := crypt.GetOwners(s.Data)
|
||||
names, predicate, err := crypt.GetOwners(s.Data)
|
||||
if err != nil {
|
||||
return jsonStatusError(err)
|
||||
}
|
||||
|
||||
return json.Marshal(OwnersData{Status: "ok", Owners: names})
|
||||
return json.Marshal(OwnersData{Status: "ok", Owners: names, Predicate: predicate})
|
||||
}
|
||||
|
||||
// Export returns a backed up vault.
|
||||
|
||||
@@ -567,7 +567,7 @@ func (c *Cryptor) Decrypt(in []byte, user string) (resp []byte, names []string,
|
||||
|
||||
// GetOwners returns the list of users that can delegate their passwords
|
||||
// to decrypt the given encrypted secret.
|
||||
func (c *Cryptor) GetOwners(in []byte) (names []string, err error) {
|
||||
func (c *Cryptor) GetOwners(in []byte) (names []string, predicate string, err error) {
|
||||
// unwrap encrypted file
|
||||
var encrypted EncryptedData
|
||||
if err = json.Unmarshal(in, &encrypted); err != nil {
|
||||
@@ -605,7 +605,7 @@ func (c *Cryptor) GetOwners(in []byte) (names []string, err error) {
|
||||
}
|
||||
|
||||
addedNames := make(map[string]bool)
|
||||
for _, mwKey := range encrypted.KeySet {
|
||||
for _, mwKey := range encrypted.KeySet { // names from the combinatorial method
|
||||
for _, mwName := range mwKey.Name {
|
||||
if !addedNames[mwName] {
|
||||
names = append(names, mwName)
|
||||
@@ -614,5 +614,14 @@ func (c *Cryptor) GetOwners(in []byte) (names []string, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
for name, _ := range encrypted.ShareSet { // names from the secret splitting method
|
||||
if !addedNames[name] {
|
||||
names = append(names, name)
|
||||
addedNames[name] = true
|
||||
}
|
||||
}
|
||||
|
||||
predicate = encrypted.Predicate
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -528,7 +528,7 @@
|
||||
submit( $form, {
|
||||
data : data,
|
||||
success : function(d){
|
||||
$form.find('.feedback').empty().append( makeAlert({ type: 'success', message: '<p>Owners: '+d.Owners.sort().join(', ')+'</p>' }) );
|
||||
$form.find('.feedback').empty().append( makeAlert({ type: 'success', message: '<p>Owners: '+d.Owners.sort().join(', ')+(d.Predicate == '' ? '' : '<br />Predicate: '+d.Predicate)+'</p>' }) );
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -801,7 +801,7 @@ var indexHtml = []byte(`<!DOCTYPE html>
|
||||
submit( $form, {
|
||||
data : data,
|
||||
success : function(d){
|
||||
$form.find('.feedback').empty().append( makeAlert({ type: 'success', message: '<p>Owners: '+d.Owners.sort().join(', ')+'</p>' }) );
|
||||
$form.find('.feedback').empty().append( makeAlert({ type: 'success', message: '<p>Owners: '+d.Owners.sort().join(', ')+(d.Predicate == '' ? '' : '<br />Predicate: '+d.Predicate)+'</p>' }) );
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user