mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-20 06:01:10 +02:00
vault: Improve error when unseal key is wrong
This commit is contained in:
parent
e3fbe54a04
commit
6c88eae73e
@ -14,6 +14,9 @@ var (
|
|||||||
// ErrBarrierNotInit is returned if a non-initialized barrier
|
// ErrBarrierNotInit is returned if a non-initialized barrier
|
||||||
// is attempted to be unsealed.
|
// is attempted to be unsealed.
|
||||||
ErrBarrierNotInit = errors.New("Vault is not initialized")
|
ErrBarrierNotInit = errors.New("Vault is not initialized")
|
||||||
|
|
||||||
|
// ErrBarrierInvalidKey is returned if the Unseal key is invalid
|
||||||
|
ErrBarrierInvalidKey = errors.New("Unseal failed, invalid key")
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/hashicorp/vault/physical"
|
"github.com/hashicorp/vault/physical"
|
||||||
@ -163,6 +164,9 @@ func (b *AESGCMBarrier) Unseal(key []byte) error {
|
|||||||
// Decrypt the barrier init key
|
// Decrypt the barrier init key
|
||||||
plain, err := b.decrypt(gcm, out.Value)
|
plain, err := b.decrypt(gcm, out.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if strings.Contains(err.Error(), "message authentication failed") {
|
||||||
|
return ErrBarrierInvalidKey
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer memzero(plain)
|
defer memzero(plain)
|
||||||
|
@ -219,4 +219,17 @@ func testBarrier(t *testing.T, b SecurityBarrier) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reseal should prevent any updates
|
||||||
|
if err := b.Seal(); err != nil {
|
||||||
|
t.Fatalf("err: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modify the key
|
||||||
|
key[0]++
|
||||||
|
|
||||||
|
// Unseal should fail
|
||||||
|
if err := b.Unseal(key); err != ErrBarrierInvalidKey {
|
||||||
|
t.Fatalf("err: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user