Repository navigation
Description
KMSPlugin.encrypt answers a code API_Encrypt does not publish when Plaintext is not valid base64.
emulator/kms_plugin.go, in encrypt:
plaintext, err := base64.StdEncoding.DecodeString(input.Plaintext)
if err != nil {
return nil, &AWSError{Code: "InvalidCiphertextException", Message: "invalid base64 plaintext", HTTPStatus: http.StatusBadRequest}
}API_Encrypt publishes nine errors and InvalidCiphertextException is not among them. Verified against the page: DependencyTimeoutException/500, DisabledException/400, DryRunOperationException/400, InvalidGrantTokenException/400, InvalidKeyUsageException/400, KeyUnavailableException/500, KMSInternalException/500, KMSInvalidStateException/400, NotFoundException/400.
InvalidCiphertextException's own gloss says why it cannot be right here — it is scoped to two other operations and to a value Encrypt does not take:
From the
DecryptorReEncryptoperation, the request was rejected because the specified ciphertext, or additional authenticated data incorporated into the ciphertext, such as the encryption context, is corrupted, missing, or otherwise invalid.
Encrypt receives no ciphertext. A caller matching on the code learns that its ciphertext was bad when what it sent was a malformed plaintext, which is the opposite end of the operation.
What it should answer
ValidationError/400, from CommonErrors.html — "the input doesn't meet the required format or constraints". That is the same reading kmsUnknownEncryptionAlgorithm records for an enum value outside the published set and kmsInvalidBody records for an unparseable body: no operation page gives a code for a malformed member, so CommonErrors.html is where it has to land. A helper beside those two, following kms_errors.go's one-per-condition convention.
Two adjacent gaps worth deciding in the same pass
Neither is this issue's subject, but both are about the same member and a fix that ignores them leaves the member half-validated:
Plaintext's published length range, 1–4096, is unenforced.Required: Yeswith aLength Constraintsline, and substrate accepts an absent member (decoding to"") as well as an arbitrarily large one.- The smaller per-spec maxima are unenforced. AWS publishes a maximum plaintext size per key spec — 4096 for
SYMMETRIC_DEFAULT, and materially smaller figures for the RSA specs, which depend on the OAEP hash. AnEncryptof 4000 bytes underRSA_2048succeeds here and cannot succeed at AWS.
Both need their codes verified against the page before implementing, and the second needs the per-spec table transcribed from the developer guide rather than recalled.
Acceptance criteria
- A
Plaintextthat is not valid base64 answersValidationError/400 rather thanInvalidCiphertextException. - The refusal is built by a helper in
kms_errors.gowhose doc comment records thatAPI_Encryptpublishes nine errors and that this is not one of them, with theCommonErrors.htmlcitation for the replacement. - A test over the wire asserts the status alongside the code (fix(kms): NotFoundException is HTTP 400, and InvalidRequest is not a KMS code #923), and asserts that
Encryptanswers noInvalidCiphertextExceptionfor any input — the code belongs toDecryptandReEncryptalone. - The two adjacent gaps above are either fixed with their codes verified against the page, or recorded in
docs/services.mdas unenforced with the published figures named. -
docs/services.mdstates the corrected code.
Surfaced while implementing #979, which touched this handler and deliberately left the code alone rather than folding an unrelated correction into a context change.
Activity
scttfrdmn commentedon Sep 18, 2026
Premise corrections before the PR opens, verified at
2c0dbaf(the #988 branch, which shifts every line number inkms_plugin.gocited below; the issue's own numbers were taken before #984 and #988).1. The per-spec maximum table is published on
API_Encryptitself. The issue sends a reader to the developer guide for it. No trip is needed — the page's ownPlaintextparameter section carries the whole table:SYMMETRIC_DEFAULTRSA_2048RSAES_OAEP_SHA_1) / 190 bytes (RSAES_OAEP_SHA_256)RSA_3072RSA_4096SM2PKEThat matters beyond provenance: the maximum depends on the encryption algorithm as well as the spec for the three RSA sizes, so a check written per-spec alone would be wrong on four of the five rows. The member's own constraints are "Minimum length of 1. Maximum length of 4096".
2.
InvalidCiphertextExceptionis not amongAPI_Encrypt's published errors. The page publishes nine, all of them at 400 except the three 500s (DependencyTimeout,KeyUnavailable,KMSInternal):Disabled,DryRunOperation,InvalidGrantToken,InvalidKeyUsage,KMSInvalidState,NotFound. The code appears on the page only in prose about a laterDecryptfailing on a mismatched encryption context — which is the opposite direction from an undecodablePlaintexton this request.ValidationError/400 is the landing place, matchingkmsInvalidBodyandkmsUnknownEncryptionAlgorithm.3. The guard is in the wrong position, which the issue does not mention. At
kms_plugin.go:1369-1372the base64 decode runs afterresolveKeyTarget(:1342), the key load, the usage check, the state check and the algorithm-compatibility check. The 1–4096 range and base64 validity are key-independent, so they belong before:1342, following the rulekmsResolveEncryptionAlgorithm's own placement records at:1334-1335: a malformed member is not a statement about any key. Only the per-spec maximum needs the key and stays after:1351— and, per correction 1, after the algorithm is resolved too.4. Two other sites use the code correctly and must be left alone.
:1443(Decrypt) and:1761(ReEncrypt's source end) answerInvalidCiphertextExceptionfor an undecodable ciphertext, which is exactly what the code is published for on both of those pages.The PR is #3 of the KMS sequence, after #984 (merged) and #988 (open as #1045).
feat(kms): the default key policy, and the policy operations' refusals (