Repository navigation
fix(kms): a named key and an encryption algorithm are checked, not discarded (#969) - #980
Merged
Merged
Conversation
…scarded (#969) Decrypt's KeyId and ReEncrypt's SourceKeyId were decoded and then dropped, so naming a different key was indistinguishable from naming the right one: the operation used the key inside substrate's own stub ciphertext and answered 200. AWS glosses both members with one sentence and gives them one code, so one check serves both, comparing resolved key ARNs rather than strings so that all four accepted identifier forms still work. The four encryption-algorithm members on Encrypt, Decrypt and both ends of ReEncrypt were decoded by nobody and answered by nobody. They are derivable because AWS does not let a key choose its algorithm — "you cannot configure a KMS key to use a particular encryption algorithm" — and fixes the admissible set per key spec instead. A value outside the published four answers ValidationError on substrate's reading; one the key spec does not admit answers InvalidKeyUsageException, which is that code's own second gloss bullet.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #969.
The defect
Decrypttakes aKeyIdandReEncrypttakes aSourceKeyId, and neither names the key the operation will use — substrate finds that inside its own stub ciphertext. Both members are a constraint on which key the ciphertext may belong to, and both were decoded and then discarded, so naming a different key was indistinguishable from naming the right one: the operation used the ciphertext's key and answered200.Separately, four encryption-algorithm members — one each on
EncryptandDecrypt, two onReEncrypt— were decoded by nobody and answered by nobody.The named key
AWS glosses the two members with one sentence and gives them one code, which is why one check serves both:
Required: NoIncorrectKeyException/400NotFoundException/400The comparison is between key ARNs, not between strings. The member accepts all four forms a
KeyIdaccepts, so it is resolved to a key record first and the two records' ARNs are compared. Comparing the member against the bare key ID inside the ciphertext would have refused three of those four correct requests, and would have been wrong across accounts besides. A test sends all four forms plus the absent case.A member naming nothing answers
NotFoundException, notIncorrectKeyException. AWS publishes both codes for both operations and orders neither; the two ask the caller for different things, and go find the right key is useless advice when the identifier names no key.The wrong key is reported before the key state, following the direction #964 took — a defect in the request precedes a condition of a resource — so a caller is not sent after the state of a key it did not ask about. AWS publishes no ordering, so this is recorded rather than matched, and a test pins it with the two candidate answers visibly different.
The encryption algorithm
The absence was defensible while it lasted: substrate performs no cryptography, and echoing
SYMMETRIC_DEFAULTunconditionally would have reported a value derived from nothing. What makes it derivable is that AWS does not let a key choose its algorithm — the key spec reference states "you cannot configure a KMS key to use a particular encryption algorithm" and fixes the admissible set per key spec:SYMMETRIC_DEFAULTSYMMETRIC_DEFAULTRSA_2048,RSA_3072,RSA_4096RSAES_OAEP_SHA_1,RSAES_OAEP_SHA_256SM2SM2PKESubstrate still encrypts nothing. What it models is the refusal, in two codes on different evidence:
ValidationError/400, which is substrate's reading (no operation page gives a code for a malformed enum member, so it comes fromCommonErrors.html);InvalidKeyUsageException/400, which is published — it is that code's own second gloss bullet, "the encryption algorithm or signing algorithm specified for the operation is incompatible with the type of key material in the KMS key (KeySpec)".The two are checked at different points: the enum before the key is resolved, following #964's ordering for a number out of range, and the key-spec compatibility after the key-state check, so a caller holding a key pending deletion hears about the deletion.
AWS's separate rule that the member is "required only for asymmetric KMS keys" falls out with no branch of its own. The default is
SYMMETRIC_DEFAULTunconditionally and an RSA key does not admit it, so omitting the member on an RSA key is refused for the ordinary reason. A test asserts it, because the alternative implementation — a required-ness check keyed on the key spec — is a second thing to keep in step with the table.ReEncrypt's two ends are independent, each checked against its own key, source first, matching the order #961 established for the two key states. A test re-encrypts from a symmetric source to an RSA destination and then swaps each end for the other's value, because an implementation validating both members against one key would pass every other assertion here.InvalidKeyUsageException's first gloss bullet — aKeyUsageincompatible with the operation — is not modelled, and is tracked withCreateKey's acceptance of any string as aKeySpecin #977. Every non-symmetric key in these tests is created through that gap, which is noted in the test file so #977 re-verifies them.One correction on the record
The comment explaining why
GetKeyRotationStatusis deliberately unguarded said the page publishes neither key-state code. It publishesKMSInvalidStateException/400. The conclusion is unchanged and better sourced — the page's own prose documents both states as successful ("the key rotation status does not change when you disable a KMS key", "while a KMS key is pending deletion, its key rotation status isfalse") — so the comment now cites that rather than an absence that is not there. The equivalent sentence in #971's shipped changelog section is left as written, since a released section is not rewritten.Verification
Nine-command gate, all green. Coverage 84.4% emulator / 83.9% total, above the 84.3%/83.8% baseline.
Nine mutations, all caught: decrypt drops the
KeyIdcheck;reEncryptdrops theSourceKeyIdcheck; the named key compared as a string rather than resolved;IncorrectKeyExceptionmoved after the state check; an unpublished algorithm accepted; the key spec not consulted; both algorithms checked against the destination; the enum checked after the key lookup;Encrypthardcoding the reported algorithm.Compatibility
Three refusals are new where a
200used to be:Decrypt/ReEncryptwhoseKeyId/SourceKeyIdnames a key other than the ciphertext's →IncorrectKeyException/400;NotFoundException/400;ValidationError/400, and one the key spec does not admit →InvalidKeyUsageException/400 — which includes omitting the member on an asymmetric key, since the default is symmetric-only.Three response members are new:
EncryptandDecryptcarryEncryptionAlgorithm;ReEncryptcarriesSourceEncryptionAlgorithmandDestinationEncryptionAlgorithm.