This repository has been archived by the owner on May 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement Rotate * clean up * Version bump for next release
- Loading branch information
Showing
1,082 changed files
with
245 additions
and
366,755 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.1.0 | ||
1.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package secretsejson | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/Shopify/ejson" | ||
ej "github.com/Shopify/ejson/json" | ||
"github.com/hashicorp/errwrap" | ||
"github.com/hashicorp/vault/sdk/framework" | ||
"github.com/hashicorp/vault/sdk/logical" | ||
) | ||
|
||
func ejsonRotatePaths(b *backend) []*framework.Path { | ||
return []*framework.Path{ | ||
&framework.Path{ | ||
Pattern: "rotate", | ||
Fields: map[string]*framework.FieldSchema{ | ||
"document": &framework.FieldSchema{ | ||
Type: framework.TypeString, | ||
Description: "EJSON Document", | ||
}, | ||
}, | ||
Callbacks: map[logical.Operation]framework.OperationFunc{ | ||
logical.CreateOperation: b.rotate, | ||
logical.UpdateOperation: b.rotate, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (b *backend) rotate(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) { | ||
inputData, ok := data.GetOk("document") | ||
if !ok { | ||
if len(data.Raw) == 0 { | ||
return logical.ErrorResponse("no data provided"), logical.ErrInvalidRequest | ||
} | ||
inputData = data.Raw | ||
} | ||
|
||
encData, err := MarshalInput(inputData) | ||
if err != nil { | ||
return nil, errwrap.Wrapf("failed to marshal json: {{err}}", err) | ||
} | ||
|
||
decDoc, err := DecryptEjsonDocument(ctx, req, encData) | ||
if err != nil { | ||
return nil, errwrap.Wrapf("failed to decrypt ejson: {{err}}", err) | ||
} | ||
|
||
public, private, err := ejson.GenerateKeypair() | ||
if err != nil { | ||
return nil, errwrap.Wrapf("failed to generate keypair ejson: {{err}}", err) | ||
} | ||
|
||
path := fmt.Sprintf("keys/%s", public) | ||
b.Logger().Info(fmt.Sprintf("New key pair at %s", path)) | ||
entry := &logical.StorageEntry{ | ||
Key: path, | ||
Value: []byte(private), | ||
} | ||
|
||
if err := req.Storage.Put(ctx, entry); err != nil { | ||
return nil, err | ||
} | ||
|
||
decDoc[ej.PublicKeyField] = public | ||
|
||
encDoc, err := EncryptEjsonDocument(ctx, decDoc) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to encrypt ejson") | ||
} | ||
|
||
return &logical.Response{ | ||
Data: map[string]interface{}{ | ||
"document": encDoc, | ||
}, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package secretsejson | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"reflect" | ||
"testing" | ||
|
||
ej "github.com/Shopify/ejson/json" | ||
"github.com/hashicorp/vault/sdk/logical" | ||
) | ||
|
||
func TestEJSON_Keys_Rotate_InlineDoc(t *testing.T) { | ||
b, storage := getTestBackend(t) | ||
EJSON_Keys_Setup(t, b, storage) | ||
|
||
publicKey := "15838c2f3260185ad2a8e1298bd507479ff2470b9e9c1fd89e0fdfefe2959f56" | ||
dataInput := map[string]interface{}{ | ||
ej.PublicKeyField: publicKey, | ||
"asecret": "EJ[1:sdseJpJ3BpP9PO5Qs8IB4urmmYil46edSTek8SjgVGA=:zl7mkBzL4g2d0PE3hPucmfbDjf3aDK7K:iryi3H7wRGWvUI8kjfWLtP3sFiw=]", | ||
"_bsecret": "intentionally_left_unencrypted", | ||
"anumber": 1, | ||
} | ||
|
||
reqRotate := &logical.Request{ | ||
Operation: logical.UpdateOperation, | ||
Path: "rotate", | ||
Storage: storage, | ||
Data: dataInput, | ||
} | ||
|
||
respRead, err := b.HandleRequest(context.Background(), reqRotate) | ||
if err != nil || (respRead != nil && respRead.IsError()) { | ||
t.Fatalf("err:%s resp:%#v\n", err, respRead) | ||
} | ||
|
||
rotatedDoc, ok := respRead.Data["document"].(map[string]interface{}) | ||
if !ok { | ||
t.Fatal("document missing from response", respRead) | ||
} | ||
|
||
if reflect.DeepEqual(rotatedDoc[ej.PublicKeyField], publicKey) { | ||
t.Fatalf("public keys did not change: \nPublicKey: %#v\n", rotatedDoc[ej.PublicKeyField]) | ||
} | ||
|
||
publicKeys, err := storage.List(context.Background(), "keys/") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if len(publicKeys) != 2 { | ||
t.Fatalf("keypairs for the rotated document missing from storage") | ||
} | ||
} | ||
|
||
func TestEJSON_Keys_Rotate_ExplicitDoc(t *testing.T) { | ||
b, storage := getTestBackend(t) | ||
EJSON_Keys_Setup(t, b, storage) | ||
|
||
publicKey := "15838c2f3260185ad2a8e1298bd507479ff2470b9e9c1fd89e0fdfefe2959f56" | ||
ejsonDoc := map[string]interface{}{ | ||
ej.PublicKeyField: publicKey, | ||
"asecret": "EJ[1:sdseJpJ3BpP9PO5Qs8IB4urmmYil46edSTek8SjgVGA=:zl7mkBzL4g2d0PE3hPucmfbDjf3aDK7K:iryi3H7wRGWvUI8kjfWLtP3sFiw=]", | ||
"_bsecret": "intentionally_left_unencrypted", | ||
"anumber": 1, | ||
} | ||
|
||
ejsonDocBytes, err := json.Marshal(ejsonDoc) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
dataInput := map[string]interface{}{ | ||
"document": string(ejsonDocBytes), | ||
} | ||
|
||
reqRotate := &logical.Request{ | ||
Operation: logical.UpdateOperation, | ||
Path: "rotate", | ||
Storage: storage, | ||
Data: dataInput, | ||
} | ||
|
||
respRead, err := b.HandleRequest(context.Background(), reqRotate) | ||
if err != nil || (respRead != nil && respRead.IsError()) { | ||
t.Fatalf("err:%s resp:%#v\n", err, respRead) | ||
} | ||
|
||
rotatedDoc, ok := respRead.Data["document"].(map[string]interface{}) | ||
if !ok { | ||
t.Fatal("document missing from response", respRead) | ||
} | ||
|
||
if reflect.DeepEqual(rotatedDoc[ej.PublicKeyField], publicKey) { | ||
t.Fatalf("public keys did not change: \nPublicKey: %#v\n", rotatedDoc[ej.PublicKeyField]) | ||
} | ||
|
||
publicKeys, err := storage.List(context.Background(), "keys/") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if len(publicKeys) != 2 { | ||
t.Fatalf("keypairs for the rotated document missing from storage") | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.