Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject supplied nonces for non-convergent encryption operations #22852

Merged
merged 27 commits into from Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
428d55b
Ignore nonces when encrypting without convergence or with convergence…
sgmiller Aug 31, 2023
2aee3db
Honor nonce use warning in non-FIPS modes
sgmiller Aug 31, 2023
cebb858
Revert "Honor nonce use warning in non-FIPS modes"
sgmiller Aug 31, 2023
7b82f58
Add a test func that removes a nonce when not needed
sgmiller Aug 31, 2023
8e66f6a
Merge remote-tracking branch 'origin/main' into sgm/transit-nonce-guard
sgmiller Aug 31, 2023
9ef1561
err out rather than ignore the nonce
sgmiller Aug 31, 2023
d1dee03
Merge remote-tracking branch 'origin/main' into sgm/transit-nonce-guard
sgmiller Sep 7, 2023
9de75fa
Alter unit test to cover, also cover convergent version 3
sgmiller Sep 7, 2023
0f6819e
More unit test work
sgmiller Sep 7, 2023
e505737
Fix test 14
sgmiller Sep 7, 2023
958298f
changelog
sgmiller Sep 7, 2023
ecf30f4
Merge branch 'main' into transit-nonce-guard
sgmiller Sep 7, 2023
17160a9
tests not already in a nonce present path
sgmiller Sep 7, 2023
8a503f3
Merge branch 'transit-nonce-guard' of github.com:/hashicorp/vault int…
sgmiller Sep 7, 2023
68a988d
Merge remote-tracking branch 'origin/main' into transit-nonce-guard
sgmiller Sep 7, 2023
7dd93c1
Update unit test to not assume warning when nonce provided incorrectly
sgmiller Sep 7, 2023
fef7429
Merge branch 'main' into transit-nonce-guard
sgmiller Sep 7, 2023
eb68659
remove unused test field
sgmiller Sep 7, 2023
d498e5e
Merge branch 'transit-nonce-guard' of github.com:/hashicorp/vault int…
sgmiller Sep 7, 2023
c09d54d
Merge branch 'main' into transit-nonce-guard
sgmiller Sep 7, 2023
6d869ec
Fix auto-squash events experiments
Sep 7, 2023
92b8341
Merge branch 'main' into transit-nonce-guard
sgmiller Sep 7, 2023
88ff4dd
Merge remote-tracking branch 'origin/vault-19136/events-b-expr-test-f…
sgmiller Sep 7, 2023
a3a588d
Merge branch 'transit-nonce-guard' of github.com:/hashicorp/vault int…
sgmiller Sep 7, 2023
1c0ee3d
Merge branch 'main' into transit-nonce-guard
sgmiller Sep 7, 2023
7fd3c00
Allow nonces for managed keys, because we have no way of knowing if t…
sgmiller Sep 7, 2023
b85d990
Merge branch 'transit-nonce-guard' of github.com:/hashicorp/vault int…
sgmiller Sep 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions builtin/logical/transit/path_datakey.go
Expand Up @@ -170,6 +170,10 @@ func (b *backend) pathDatakeyWrite(ctx context.Context, req *logical.Request, d
},
}

if !nonceAllowed(p) {
return nil, ErrNonceNotAllowed
}

if constants.IsFIPS() && shouldWarnAboutNonceUsage(p, nonce) {
resp.AddWarning("A provided nonce value was used within FIPS mode, this violates FIPS 140 compliance.")
}
Expand Down
22 changes: 22 additions & 0 deletions builtin/logical/transit/path_encrypt.go
Expand Up @@ -471,6 +471,11 @@ func (b *backend) pathEncryptWrite(ctx context.Context, req *logical.Request, d
continue
}

if !nonceAllowed(p) {
batchResponseItems[i].Error = ErrNonceNotAllowed
continue
}

if !warnAboutNonceUsage && shouldWarnAboutNonceUsage(p, item.DecodedNonce) {
warnAboutNonceUsage = true
}
Expand Down Expand Up @@ -568,6 +573,23 @@ func (b *backend) pathEncryptWrite(ctx context.Context, req *logical.Request, d
return batchRequestResponse(d, resp, req, successesInBatch, userErrorInBatch, internalErrorInBatch)
}

func nonceAllowed(p *keysutil.Policy) bool {
sgmiller marked this conversation as resolved.
Show resolved Hide resolved
var supportedKeyType bool
switch p.Type {
case keysutil.KeyType_AES128_GCM96, keysutil.KeyType_AES256_GCM96, keysutil.KeyType_ChaCha20_Poly1305:
supportedKeyType = true
default:
supportedKeyType = false
}

if supportedKeyType && p.ConvergentEncryption && p.ConvergentVersion == 1 {
// We only use the user supplied nonce for v1 convergent encryption keys
return true
}

return false
}

// Depending on the errors in the batch, different status codes should be returned. User errors
// will return a 400 and precede internal errors which return a 500. The reasoning behind this is
// that user errors are non-retryable without making changes to the request, and should be surfaced
Expand Down
7 changes: 7 additions & 0 deletions builtin/logical/transit/path_rewrap.go
Expand Up @@ -16,6 +16,8 @@
"github.com/mitchellh/mapstructure"
)

var ErrNonceNotAllowed = errors.New("provided nonce not allowed for this key")

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests tagged with testonly / test-go (0)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests tagged with testonly / test-go (0)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests tagged with testonly / test-go (1)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests tagged with testonly / test-go (1)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (6)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (6)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (1)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (1)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (0)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (0)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (10)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (10)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (2)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (2)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (7)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (7)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (0)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (0)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (1)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (1)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (11)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (11)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (5)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (5)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Linux (linux, 386) / Vault linux 386 v1.16.0-beta1

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Other (freebsd, 386) / Vault freebsd 386 v1.16.0-beta1

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Linux (linux, arm) / Vault linux arm v1.16.0-beta1

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (2)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (2)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Darwin (darwin, arm64) / Vault darwin arm64 v1.16.0-beta1

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Linux (linux, arm64) / Vault linux arm64 v1.16.0-beta1

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (14)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (14)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (10)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (10)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Darwin (darwin, amd64) / Vault darwin amd64 v1.16.0-beta1

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Linux (linux, amd64) / Vault linux amd64 v1.16.0-beta1

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Other (freebsd, arm) / Vault freebsd arm v1.16.0-beta1

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (13)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (13)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Other (freebsd, amd64) / Vault freebsd amd64 v1.16.0-beta1

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Other (netbsd, 386) / Vault netbsd 386 v1.16.0-beta1

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Other (openbsd, 386) / Vault openbsd 386 v1.16.0-beta1

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (4)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (4)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Other (netbsd, arm) / Vault netbsd arm v1.16.0-beta1

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (6)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (6)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (8)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (8)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (7)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (7)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (9)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests with data race detection / test-go (9)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (13)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (13)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (16)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (14)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (14)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (11)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (11)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (9)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (9)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (5)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (5)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (8)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (8)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (4)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Run Go tests / test-go (4)

undefined: errors

Check failure on line 19 in builtin/logical/transit/path_rewrap.go

View workflow job for this annotation

GitHub Actions / Deprecated functions

undefined: errors (compile)
schultz-is marked this conversation as resolved.
Show resolved Hide resolved

func (b *backend) pathRewrap() *framework.Path {
return &framework.Path{
Pattern: "rewrap/" + framework.GenericNameRegex("name"),
Expand Down Expand Up @@ -164,6 +166,11 @@
}
}

if !nonceAllowed(p) {
batchResponseItems[i].Error = ErrNonceNotAllowed
continue
}

if !warnAboutNonceUsage && shouldWarnAboutNonceUsage(p, item.DecodedNonce) {
warnAboutNonceUsage = true
}
Expand Down
5 changes: 4 additions & 1 deletion sdk/helper/keysutil/policy.go
Expand Up @@ -2013,9 +2013,12 @@ func (p *Policy) EncryptWithFactory(ver int, context []byte, nonce []byte, value

encBytes := 32
hmacBytes := 0
if p.convergentVersion(ver) > 2 {
convergentVersion := p.convergentVersion(ver)
if convergentVersion > 2 {
deriveHMAC = true
hmacBytes = 32
} else if !p.ConvergentEncryption || convergentVersion != 1 {
return "", errutil.UserError{Err: "nonce provided when not allowed"}
}
if p.Type == KeyType_AES128_GCM96 {
encBytes = 16
Expand Down