Decrypt returns the list of users used for delegation

When decrypting a chunk of data, red october will now report the users
whose keys were used in the decryption.
This commit is contained in:
Kyle Isom
2014-09-14 19:13:37 -07:00
committed by Kyle
parent 886bd0d623
commit 91cd67f267
5 changed files with 69 additions and 20 deletions
+19 -3
View File
@@ -8,10 +8,11 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"github.com/cloudflare/redoctober/cryptor"
"github.com/cloudflare/redoctober/keycache"
"github.com/cloudflare/redoctober/passvault"
"log"
)
// Each of these structures corresponds to the JSON expected on the
@@ -60,6 +61,11 @@ type decrypt struct {
Data []byte
}
type decryptWithDelegates struct {
Data []byte
Delegates []string
}
type modify struct {
Name string
Password string
@@ -283,13 +289,23 @@ func Decrypt(jsonIn []byte) ([]byte, error) {
return jsonStatusError(err)
}
resp, err := cryptor.Decrypt(s.Data)
data, names, err := cryptor.Decrypt(s.Data)
if err != nil {
log.Println("Error decrypting:", err)
return jsonStatusError(err)
}
return jsonResponse(resp)
resp := &decryptWithDelegates{
Data: data,
Delegates: names,
}
out, err := json.Marshal(resp)
if err != nil {
return jsonStatusError(err)
}
return jsonResponse(out)
}
// Modify processes a modify request.
+25 -5
View File
@@ -7,10 +7,11 @@ package core
import (
"bytes"
"encoding/json"
"github.com/cloudflare/redoctober/keycache"
"github.com/cloudflare/redoctober/passvault"
"os"
"testing"
"github.com/cloudflare/redoctober/keycache"
"github.com/cloudflare/redoctober/passvault"
)
func TestCreate(t *testing.T) {
@@ -449,8 +450,21 @@ func TestEncryptDecrypt(t *testing.T) {
if s.Status != "ok" {
t.Fatalf("Error in decrypt, %v", s.Status)
}
if string(s.Response) != "Hello Jello" {
t.Fatalf("Error in decrypt, %v", string(s.Response))
var d decryptWithDelegates
err = json.Unmarshal(s.Response, &d)
if err != nil {
t.Fatalf("Error in decrypt, %v", err)
}
if string(d.Data) != "Hello Jello" {
t.Fatalf("Error in decrypt, %v", string(d.Data))
}
if d.Delegates[0] != "Bob" && d.Delegates[1] != "Carol" {
if d.Delegates[1] != "Bob" && d.Delegates[0] != "Carol" {
t.Fatalf("Error in decrypt, %v", d.Delegates)
}
}
keycache.FlushCache()
@@ -707,7 +721,13 @@ func TestStatic(t *testing.T) {
t.Fatalf("Error in summary, %v", r.Status)
}
if bytes.Compare(expected, r.Response) != 0 {
var d decryptWithDelegates
err = json.Unmarshal(r.Response, &d)
if err != nil {
t.Fatalf("Error in decrypt, %v", err)
}
if bytes.Compare(expected, d.Data) != 0 {
t.Fatalf("Error in summary, %v, %v", expected, r.Response)
}