Repository navigation
Description
CreateKey accepts any string as KeySpec and any string as KeyUsage, and no cryptographic operation checks either one against the operation it is being used for. Found while fixing #969, which needed the KeySpec → encryption-algorithm table and so had to establish what a key spec can legally be.
What substrate does today
createKey (emulator/kms_plugin.go) decodes both members, defaults them, and stores whatever it was handed:
if input.KeyUsage == "" {
input.KeyUsage = "ENCRYPT_DECRYPT"
}
if input.KeySpec == "" {
input.KeySpec = "SYMMETRIC_DEFAULT"
}So CreateKey with KeySpec: "MADEUP" or KeyUsage: "SIGN_VERIFY" both answer 200, and DescribeKey reports the value back.
What AWS publishes
API_CreateKey gives both members a Valid Values line:
KeyUsage:SIGN_VERIFY | ENCRYPT_DECRYPT | GENERATE_VERIFY_MAC | KEY_AGREEMENTKeySpec:SYMMETRIC_DEFAULT | RSA_2048 | RSA_3072 | RSA_4096 | ECC_NIST_P256 | ECC_NIST_P384 | ECC_NIST_P521 | ECC_SECG_P256K1 | ECC_NIST_EDWARDS25519 | ML_DSA_44 | ML_DSA_65 | ML_DSA_87 | SM2 | HMAC_224 | HMAC_256 | HMAC_384 | HMAC_512— verify this list verbatim against the page before implementing, since it grows as AWS adds key types.
The pairing is constrained too, and the constraint is what makes the enum check worth more than a spelling test. The developer guide's key spec reference states which usages each spec admits: an RSA spec is "encryption and decryption -or- signing and verification"; the ECC specs are "signing and verification -or- deriving shared secrets"; ECC_NIST_EDWARDS25519 is "signing and verification only"; the HMAC specs are MAC generation only; the ML-DSA specs are signing only; SM2 admits all three. API_CreateKey publishes UnsupportedOperationException/400, whose gloss — "a specified parameter is not supported or a specified resource is not valid for this operation" — is the natural home for an inadmissible pairing.
The second half: no cryptographic operation checks KeyUsage
InvalidKeyUsageException/400 is published on API_Encrypt, API_Decrypt, API_ReEncrypt, API_GenerateDataKey and API_GenerateDataKeyWithoutPlaintext, and its gloss has two bullets:
- The
KeyUsagevalue of the KMS key is incompatible with the API operation.- The encryption algorithm or signing algorithm specified for the operation is incompatible with the type of key material in the KMS key (
KeySpec).For encrypting, decrypting, re-encrypting, and generating data keys, the
KeyUsagemust beENCRYPT_DECRYPT.
#969 implements the second bullet and deliberately leaves the first. kmsResolveEncryptionAlgorithm (emulator/kms_encryption_algorithms.go) refuses an algorithm the key's KeySpec does not admit, which covers every key spec that supports no encryption algorithm at all — the ECC, HMAC and ML-DSA specs. It does not cover a SIGN_VERIFY RSA key: RSA_2048 admits RSAES_OAEP_SHA_1 and RSAES_OAEP_SHA_256 whatever the key's usage is, so an Encrypt against a signing key still succeeds where AWS answers InvalidKeyUsageException.
The check is one comparison against "ENCRYPT_DECRYPT" in a shared helper beside kmsKeyStateError, at the same five call sites. It is filed separately rather than folded into #969 because it is a different published bullet with a different provenance, and because the two together would make one PR that changed what five operations accept for two unrelated reasons.
Acceptance criteria
-
CreateKeyrefuses aKeySpecorKeyUsageoutside the published Valid Values, with the code chosen from whatAPI_CreateKeypublishes and the choice recorded if it is substrate's reading. - An inadmissible spec/usage pairing is decided — refused with
UnsupportedOperationExceptionor deliberately accepted — and recorded either way. - The five cryptographic operations refuse a key whose
KeyUsageis notENCRYPT_DECRYPT, withInvalidKeyUsageException/400, through one shared helper rather than five call-site tests. - The published Valid Values are re-verified against
API_CreateKeyat implementation time rather than taken from this issue. - Tests go over the wire (cfn: the aws:cloudformation:* stamp covers EC2 only, so the rest of a stack is unstamped #765) and assert the status alongside the code (fix(kms): NotFoundException is HTTP 400, and InvalidRequest is not a KMS code #923).
Activity
feat(kms): one KeyMetadata builder, and the sixteen members it stoppe…
scttfrdmn commentedon Sep 17, 2026
API_CreateKeyre-verified at implementation time, per this issue's fourth criterion. Three things the issue asked to be checked, and one it did not anticipate.The Valid Values, verbatim
KeySpec— 17, and the issue's list is complete and correctly ordered against the page:RSA_2048 | RSA_3072 | RSA_4096 | ECC_NIST_P256 | ECC_NIST_P384 | ECC_NIST_P521 | ECC_SECG_P256K1 | SYMMETRIC_DEFAULT | HMAC_224 | HMAC_256 | HMAC_384 | HMAC_512 | SM2 | ML_DSA_44 | ML_DSA_65 | ML_DSA_87 | ECC_NIST_EDWARDS25519KeyUsage— 4:SIGN_VERIFY | ENCRYPT_DECRYPT | GENERATE_VERIFY_MAC | KEY_AGREEMENT.The pairing rules are on
API_CreateKeyitself, not only in the developer guide, as seven bullets underKeyUsage: symmetric encryption → omit orENCRYPT_DECRYPT; HMAC →GENERATE_VERIFY_MAC; RSA →ENCRYPT_DECRYPTorSIGN_VERIFY; NIST-standard elliptic curve →SIGN_VERIFYorKEY_AGREEMENT;ECC_SECG_P256K1→SIGN_VERIFY; ML-DSA →SIGN_VERIFY; SM2 (China Regions only) →ENCRYPT_DECRYPT,SIGN_VERIFYorKEY_AGREEMENT.ECC_NIST_EDWARDS25519is annotated "signing and verification only" in theKeySpecbullet list, so it isSIGN_VERIFYalone — it is not one of the "NIST-standard elliptic curve" specs for the key-agreement bullet's purposes, which matches #974's finding that it publishes no key-agreement algorithm.The error code, which the issue left open and the page does not settle
API_CreateKeypublishes thirteen errors andValidationExceptionis not among them:CloudHsmClusterInvalidConfigurationException/400,CustomKeyStoreInvalidStateException/400,CustomKeyStoreNotFoundException/400,DependencyTimeoutException/500,InvalidArnException/400,KMSInternalException/500,LimitExceededException/400,MalformedPolicyDocumentException/400,TagException/400,UnsupportedOperationException/400,XksKeyAlreadyInUseException/400,XksKeyInvalidConfigurationException/400,XksKeyNotFoundException/400.So there are two distinct refusals here and they get two different codes:
KeySpec: "MADEUP"— is a constraint violation on the input, and the code isValidationError/400 fromCommonErrors.html("The input fails to satisfy the constraints specified by an AWS service"), following the precedent kms: ReEncrypt decodes two of nine request members and answers three of seven response members, and an unenforced SourceKeyId hides IncorrectKeyException #969 set for the same class. Substrate's reading, sinceAPI_CreateKeypublishes nothing narrower.KeySpec: "HMAC_256"withKeyUsage: "KEY_AGREEMENT"— isUnsupportedOperationException/400, as this issue proposed. Its gloss is "a specified parameter is not supported or a specified resource is not valid for this operation", and it is the only published 400 on the operation that fits. Also substrate's reading: AWS states the pairing rules and publishes no code against them.Keeping them separate matters, because they are distinguishable to a caller: one says that is not a key spec, the other says that is a key spec, and not with that usage.
One requirement the issue does not mention:
KeyUsageis not optional for most specsKeyUsage's own description, verbatim: "This parameter is optional when you are creating a symmetric encryption KMS key; otherwise, it is required." Substrate defaults it toENCRYPT_DECRYPTunconditionally, so today an HMAC or ML-DSA key can be created with noKeyUsageat all and comes back as an encryption key — a second silent substitution alongside the enum gap.The rule that falls out is narrow and worth stating precisely: the default fires only when
KeySpecisSYMMETRIC_DEFAULT, whether that value was sent or itself defaulted. An HMAC spec is symmetric but is not a symmetric encryption key, and its own bullet requiresGENERATE_VERIFY_MACexplicitly. A missing required parameter is a constraint violation on the input, so it takesValidationError/400 with the enum case rather thanUnsupportedOperationException.What this closes for, and what it does not
Also filed from the same verification pass, because none of the three is in scope here:
CreateKeydropsPolicyandGetKeyPolicyanswers an empty-statement document rather than AWS's default key policy.CreateKeydecodes neitherOrigin,CustomKeyStoreIdnorXksKeyId.CustomerMasterKeySpecis a request parameter too, with a 13-value enum narrower thanKeySpec's 17, and substrate decodes only the response half.#985 shares this issue's validation surface and must not end up with a different code for the same class of malformed input. It is either folded in here or lands immediately after reusing whatever this settles; the decision is recorded on #985.
Finally, the test rework this forces, which is larger than it looks:
kms_key_metadata_test.go(#974),kms_rotation_key_type_test.go(#972) andkms_encryption_algorithm_test.go(#969) all create keys through the gap this issue closes, and all three carry a note saying so.kms_key_metadata_test.go's_AnImpossiblePairReportsNoAlgorithmListAtAllis the sharpest case — it exists to pin what substrate answers for a pairing AWS would never accept, includingKeyUsage: "TRANSMOGRIFY", and every one of its sub-cases becomes unreachable throughCreateKey. That test does not get deleted; it gets re-pointed at the refusal, and #974's builder keeps its empty-list branch as the defence-in-depth it now is.feat(kms): validate KeySpec and KeyUsage, and pair them (#977) (#986)
feat(kms): read CustomerMasterKeySpec on CreateKey (#985) (#987)