2023-03-15 19:00:52 +03:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2024-01-02 21:36:20 +03:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-15 19:00:52 +03:00
|
|
|
|
2022-02-17 22:43:07 +03:00
|
|
|
package vault
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-09-13 20:03:19 +03:00
|
|
|
"github.com/hashicorp/go-uuid"
|
2022-06-28 00:41:56 +03:00
|
|
|
"github.com/hashicorp/vault/command/server"
|
2022-02-17 22:43:07 +03:00
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
|
|
|
)
|
|
|
|
|
2022-06-28 00:41:56 +03:00
|
|
|
// GetCoreConfigInternal returns the server configuration
|
|
|
|
// in struct format.
|
|
|
|
func (c *Core) GetCoreConfigInternal() *server.Config {
|
|
|
|
conf := c.rawConfig.Load()
|
|
|
|
if conf == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return conf.(*server.Config)
|
|
|
|
}
|
|
|
|
|
2022-02-17 22:43:07 +03:00
|
|
|
func (c *Core) loadHeaderHMACKey(ctx context.Context) error {
|
|
|
|
ent, err := c.barrier.Get(ctx, indexHeaderHMACKeyPath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if ent != nil {
|
|
|
|
c.IndexHeaderHMACKey.Store(ent.Value)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Core) headerHMACKey() []byte {
|
|
|
|
key := c.IndexHeaderHMACKey.Load()
|
|
|
|
if key == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return key.([]byte)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Core) setupHeaderHMACKey(ctx context.Context, isPerfStandby bool) error {
|
|
|
|
if c.IsPerfSecondary() || c.IsDRSecondary() || isPerfStandby {
|
|
|
|
return c.loadHeaderHMACKey(ctx)
|
|
|
|
}
|
|
|
|
ent, err := c.barrier.Get(ctx, indexHeaderHMACKeyPath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if ent != nil {
|
|
|
|
c.IndexHeaderHMACKey.Store(ent.Value)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
key, err := uuid.GenerateUUID()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = c.barrier.Put(ctx, &logical.StorageEntry{
|
|
|
|
Key: indexHeaderHMACKeyPath,
|
|
|
|
Value: []byte(key),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
c.IndexHeaderHMACKey.Store([]byte(key))
|
|
|
|
return nil
|
|
|
|
}
|