Skip to content

Commit

Permalink
Honor nonce use warning in non-FIPS modes
Browse files Browse the repository at this point in the history
  • Loading branch information
sgmiller committed Aug 31, 2023
1 parent 428d55b commit 2aee3db
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
5 changes: 2 additions & 3 deletions builtin/logical/transit/path_datakey.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/base64"
"fmt"

"github.com/hashicorp/vault/helper/constants"
"github.com/hashicorp/vault/sdk/framework"
"github.com/hashicorp/vault/sdk/helper/errutil"
"github.com/hashicorp/vault/sdk/helper/keysutil"
Expand Down Expand Up @@ -170,8 +169,8 @@ func (b *backend) pathDatakeyWrite(ctx context.Context, req *logical.Request, d
},
}

if constants.IsFIPS() && shouldWarnAboutNonceUsage(p, nonce) {
resp.AddWarning("A provided nonce value was used within FIPS mode, this violates FIPS 140 compliance.")
if shouldWarnAboutNonceUsage(p, nonce) {
resp.AddWarning("A provided nonce value was ignored where a user supplied nonce cannot be specified.")
}

if plaintextAllowed {
Expand Down
7 changes: 3 additions & 4 deletions builtin/logical/transit/path_encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"net/http"
"reflect"

"github.com/hashicorp/vault/helper/constants"

"github.com/hashicorp/vault/sdk/framework"
"github.com/hashicorp/vault/sdk/helper/errutil"
"github.com/hashicorp/vault/sdk/helper/keysutil"
Expand Down Expand Up @@ -473,6 +471,7 @@ func (b *backend) pathEncryptWrite(ctx context.Context, req *logical.Request, d

if !warnAboutNonceUsage && shouldWarnAboutNonceUsage(p, item.DecodedNonce) {
warnAboutNonceUsage = true
item.DecodedNonce = nil
}

var factory interface{}
Expand Down Expand Up @@ -555,8 +554,8 @@ func (b *backend) pathEncryptWrite(ctx context.Context, req *logical.Request, d
}
}

if constants.IsFIPS() && warnAboutNonceUsage {
resp.AddWarning("A provided nonce value was used within FIPS mode, this violates FIPS 140 compliance.")
if warnAboutNonceUsage {
resp.AddWarning("A provided nonce value was ignored where a user supplied nonce cannot be specified.")
}

if req.Operation == logical.CreateOperation && !upserted {
Expand Down
6 changes: 3 additions & 3 deletions builtin/logical/transit/path_rewrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/base64"
"fmt"

"github.com/hashicorp/vault/helper/constants"
"github.com/hashicorp/vault/sdk/framework"
"github.com/hashicorp/vault/sdk/helper/errutil"
"github.com/hashicorp/vault/sdk/helper/keysutil"
Expand Down Expand Up @@ -166,6 +165,7 @@ func (b *backend) pathRewrapWrite(ctx context.Context, req *logical.Request, d *

if !warnAboutNonceUsage && shouldWarnAboutNonceUsage(p, item.DecodedNonce) {
warnAboutNonceUsage = true
item.DecodedNonce = nil
}

ciphertext, err := p.Encrypt(item.KeyVersion, item.DecodedContext, item.DecodedNonce, plaintext)
Expand Down Expand Up @@ -217,8 +217,8 @@ func (b *backend) pathRewrapWrite(ctx context.Context, req *logical.Request, d *
}
}

if constants.IsFIPS() && warnAboutNonceUsage {
resp.AddWarning("A provided nonce value was used within FIPS mode, this violates FIPS 140 compliance.")
if warnAboutNonceUsage {
resp.AddWarning("A provided nonce value was ignored where a user supplied nonce cannot be specified.")
}

p.Unlock()
Expand Down

0 comments on commit 2aee3db

Please sign in to comment.