Skip to content

Export of HMAC key returns the wrong values #20804

@rzimmerman

Description

@rzimmerman

Describe the bug
The Transit Export endpoint returns erroneous values for HMAC keys. For Vault-generated keys, the Export endpoint returns random 32-byte values (regardless of the requested key size). For imported keys, the Export endpoint returns a blank (empty) key.

To Reproduce
Steps to reproduce the behavior:

  1. Run vault server -dev -dev-root-token-id root
  2. Run this gist
  3. AES keys return the expected value when imported + exported
  4. HMAC keys that are created are the wrong length (always 32 bytes)
  5. HMAC keys that are imported do not match the imported key

Expected behavior
Per the Gist above, I'd expect the exported key length to match the key_size parameter.
Also, I'd expect the exported HMAC key to match the imported key value. Output on my machine:

> Test create HMAC key of desired length:
Key length: 32, expected 64
> Test import HMAC key:
expected key: 3031323334353637383961626364656630313233343536373839616263646566
got:
> Test import AES key:
expected key: 3031323334353637383961626364656630313233343536373839616263646566
got:          3031323334353637383961626364656630313233343536373839616263646566

And directly querying the endpoints:

➜  vault read transit/export/hmac-key/hmac-test1
Key     Value
---     -----
keys    map[1:Z4DAJFsjCEVRgyjFFqjVcdrwvPhTuPLYiqqrUEFFK0U=]
name    hmac-test1
type    hmac
➜  vault read transit/export/hmac-key/hmac-test2
Key     Value
---     -----
keys    map[1:]
name    hmac-test2
type    hmac

Environment:

  • Vault Server Version (retrieve with vault status): 1.13.2
  • Vault CLI Version (retrieve with vault version): Vault v1.13.2 (b9b773f), built 2023-04-25T13:02:50Z (though this happens with github.com/hashicorp/vault-client-go v0.3.2)
  • Server Operating System/Architecture: MacOS (M1)

Vault server configuration file(s): N/A

Additional context

It looks like the Export endpoint is erroneously using the HMACKey "supplementary" key for hmac key types. This line should probably be returning key.Key rather than key.HMACKey:

case exportTypeHMACKey:
return strings.TrimSpace(base64.StdEncoding.EncodeToString(key.HMACKey)), nil

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions