From 5190b87714df527aba3041b53fbf8032fd25d7b2 Mon Sep 17 00:00:00 2001 From: Matthew Irish Date: Thu, 8 Jun 2017 13:07:18 -0500 Subject: [PATCH] add min_encryption_version to the transit key response (#2838) --- builtin/logical/transit/backend_test.go | 30 ++++++++++++++++++++++--- builtin/logical/transit/path_keys.go | 1 + 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/builtin/logical/transit/backend_test.go b/builtin/logical/transit/backend_test.go index ec582532a5..689e2d5a52 100644 --- a/builtin/logical/transit/backend_test.go +++ b/builtin/logical/transit/backend_test.go @@ -129,7 +129,9 @@ func TestBackend_rotation(t *testing.T) { testAccStepLoadVX(t, "test", decryptData, 4, encryptHistory), testAccStepDecrypt(t, "test", testPlaintext, decryptData), testAccStepDeleteNotDisabledPolicy(t, "test"), - testAccStepAdjustPolicy(t, "test", 3), + testAccStepAdjustPolicyMinDecryption(t, "test", 3), + testAccStepAdjustPolicyMinEncryption(t, "test", 4), + testAccStepReadPolicyWithVersions(t, "test", false, false, 3, 4), testAccStepLoadVX(t, "test", decryptData, 0, encryptHistory), testAccStepDecryptExpectFailure(t, "test", testPlaintext, decryptData), testAccStepLoadVX(t, "test", decryptData, 1, encryptHistory), @@ -140,7 +142,8 @@ func TestBackend_rotation(t *testing.T) { testAccStepDecrypt(t, "test", testPlaintext, decryptData), testAccStepLoadVX(t, "test", decryptData, 4, encryptHistory), testAccStepDecrypt(t, "test", testPlaintext, decryptData), - testAccStepAdjustPolicy(t, "test", 1), + testAccStepAdjustPolicyMinDecryption(t, "test", 1), + testAccStepReadPolicyWithVersions(t, "test", false, false, 1, 4), testAccStepLoadVX(t, "test", decryptData, 0, encryptHistory), testAccStepDecrypt(t, "test", testPlaintext, decryptData), testAccStepLoadVX(t, "test", decryptData, 1, encryptHistory), @@ -221,7 +224,7 @@ func testAccStepListPolicy(t *testing.T, name string, expectNone bool) logicalte } } -func testAccStepAdjustPolicy(t *testing.T, name string, minVer int) logicaltest.TestStep { +func testAccStepAdjustPolicyMinDecryption(t *testing.T, name string, minVer int) logicaltest.TestStep { return logicaltest.TestStep{ Operation: logical.UpdateOperation, Path: "keys/" + name + "/config", @@ -230,6 +233,15 @@ func testAccStepAdjustPolicy(t *testing.T, name string, minVer int) logicaltest. }, } } +func testAccStepAdjustPolicyMinEncryption(t *testing.T, name string, minVer int) logicaltest.TestStep { + return logicaltest.TestStep{ + Operation: logical.UpdateOperation, + Path: "keys/" + name + "/config", + Data: map[string]interface{}{ + "min_encryption_version": minVer, + }, + } +} func testAccStepDisableDeletion(t *testing.T, name string) logicaltest.TestStep { return logicaltest.TestStep{ @@ -276,6 +288,10 @@ func testAccStepDeleteNotDisabledPolicy(t *testing.T, name string) logicaltest.T } func testAccStepReadPolicy(t *testing.T, name string, expectNone, derived bool) logicaltest.TestStep { + return testAccStepReadPolicyWithVersions(t, name, expectNone, derived, 1, 0) +} + +func testAccStepReadPolicyWithVersions(t *testing.T, name string, expectNone, derived bool, minDecryptionVersion int, minEncryptionVersion int) logicaltest.TestStep { return logicaltest.TestStep{ Operation: logical.ReadOperation, Path: "keys/" + name, @@ -297,6 +313,8 @@ func testAccStepReadPolicy(t *testing.T, name string, expectNone, derived bool) KDF string `mapstructure:"kdf"` DeletionAllowed bool `mapstructure:"deletion_allowed"` ConvergentEncryption bool `mapstructure:"convergent_encryption"` + MinDecryptionVersion int `mapstructure:"min_decryption_version"` + MinEncryptionVersion int `mapstructure:"min_encryption_version"` } if err := mapstructure.Decode(resp.Data, &d); err != nil { return err @@ -315,6 +333,12 @@ func testAccStepReadPolicy(t *testing.T, name string, expectNone, derived bool) if d.Keys == nil { return fmt.Errorf("bad: %#v", d) } + if d.MinDecryptionVersion != minDecryptionVersion { + return fmt.Errorf("bad: %#v", d) + } + if d.MinEncryptionVersion != minEncryptionVersion { + return fmt.Errorf("bad: %#v", d) + } if d.DeletionAllowed == true { return fmt.Errorf("bad: %#v", d) } diff --git a/builtin/logical/transit/path_keys.go b/builtin/logical/transit/path_keys.go index 18e0c57020..8cf97a3555 100644 --- a/builtin/logical/transit/path_keys.go +++ b/builtin/logical/transit/path_keys.go @@ -183,6 +183,7 @@ func (b *backend) pathPolicyRead( "derived": p.Derived, "deletion_allowed": p.DeletionAllowed, "min_decryption_version": p.MinDecryptionVersion, + "min_encryption_version": p.MinEncryptionVersion, "latest_version": p.LatestVersion, "exportable": p.Exportable, "supports_encryption": p.Type.EncryptionSupported(),