verify_mac
async
¶
verify_mac(
message: PlaintextType,
key_id: KeyIdType,
mac_algorithm: MacAlgorithmSpec,
mac: CiphertextType,
*,
config_overrides: Optional[AsyncKMSClientConfig] = None,
grant_tokens: Optional[GrantTokenList] = None,
dry_run: Optional[NullableBooleanType] = None,
) -> VerifyMacResponse
Verifies the hash-based message authentication code (HMAC) for a specified message, HMAC KMS key, and MAC algorithm. To verify the HMAC, VerifyMac computes an HMAC using the message, HMAC KMS key, and MAC algorithm that you specify, and compares the computed HMAC to the HMAC that you specify. If the HMACs are identical, the verification succeeds; otherwise, it fails. Verification indicates that the message hasn't changed since the HMAC was calculated, and the specified key was used to generate and verify the HMAC.
HMAC KMS keys and the HMAC algorithms that KMS uses conform to industry standards defined in RFC 2104.
This operation is part of KMS support for HMAC KMS keys. For details, see HMAC keys in KMS in the Key Management Service Developer Guide.
The KMS key that you use for this operation must be in a compatible key state. For details, see Key states of KMS keys in the Key Management Service Developer Guide.
Cross-account use: Yes. To perform this operation with a KMS key in a different Amazon Web Services account, specify the key ARN or alias ARN in the value of the KeyId parameter.
Required permissions: kms:VerifyMac (key policy)
Related operations: GenerateMac
Eventual consistency: The KMS API follows an eventual consistency model. For more information, see KMS eventual consistency.
Parameters:
-
message(PlaintextType) –The message that will be used in the verification. Enter the same message that was used to generate the HMAC.
GenerateMac and
VerifyMacdo not provide special handling for message digests. If you generated an HMAC for a hash digest of a message, you must verify the HMAC for the same hash digest. -
key_id(KeyIdType) –The KMS key that will be used in the verification.
Enter a key ID of the KMS key that was used to generate the HMAC. If you identify a different KMS key, the
VerifyMacoperation fails. -
mac_algorithm(MacAlgorithmSpec) –The MAC algorithm that will be used in the verification. Enter the same MAC algorithm that was used to compute the HMAC. This algorithm must be supported by the HMAC KMS key identified by the
KeyIdparameter. -
mac(CiphertextType) –The HMAC to verify. Enter the HMAC that was generated by the GenerateMac operation when you specified the same message, HMAC KMS key, and MAC algorithm as the values specified in this request.
-
grant_tokens(Optional[GrantTokenList], default:None) –A list of grant tokens.
Use a grant token when your permission to call this operation comes from a new grant that has not yet achieved eventual consistency. For more information, see Grant token and Using a grant token in the Key Management Service Developer Guide.
-
dry_run(Optional[NullableBooleanType], default:None) –Checks if your request will succeed.
DryRunis an optional parameter.To learn more about how to use this parameter, see Testing your permissions in the Key Management Service Developer Guide.
Raises:
-
DisabledException–The request was rejected because the specified KMS key is not enabled.
-
DryRunOperationException–The request was rejected because the DryRun parameter was specified.
-
InvalidGrantTokenException–The request was rejected because the specified grant token is not valid.
-
InvalidKeyUsageException–The request was rejected for one of the following reasons:
-
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. For signing and verifying messages, theKeyUsagemust beSIGN_VERIFY. For generating and verifying message authentication codes (MACs), theKeyUsagemust beGENERATE_VERIFY_MAC. For deriving key agreement secrets, theKeyUsagemust beKEY_AGREEMENT. To find theKeyUsageof a KMS key, use the DescribeKey operation.To find the encryption or signing algorithms supported for a particular KMS key, use the DescribeKey operation.
-
-
KeyUnavailableException–The request was rejected because the specified KMS key was not available. You can retry the request.
-
KMSInternalException–The request was rejected because an internal exception occurred. The request can be retried.
-
KMSInvalidMacException–The request was rejected because the HMAC verification failed. HMAC verification fails when the HMAC computed by using the specified message, HMAC KMS key, and MAC algorithm does not match the HMAC specified in the request.
-
KMSInvalidStateException–The request was rejected because the state of the specified resource is not valid for this request.
This exceptions means one of the following:
-
The key state of the KMS key is not compatible with the operation.
To find the key state, use the DescribeKey operation. For more information about which key states are compatible with each KMS operation, see Key states of KMS keys in the Key Management Service Developer Guide .
-
For cryptographic operations on KMS keys in custom key stores, this exception represents a general failure with many possible causes. To identify the cause, see the error message that accompanies the exception.
-
-
NotFoundException–The request was rejected because the specified entity or resource could not be found.
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
To verify an HMAC This example verifies an HMAC for a particular message, HMAC KMS keys, and MAC algorithm. A value of 'true' in the MacValid value in the response indicates that the HMAC is valid.
>>> await client.verify_mac(message='Hello World', key_id='1234abcd-12ab-34cd-56ef-1234567890ab', mac_algorithm='HMAC_SHA_384', mac='<HMAC_TAG>')
Source code in docs_src/capo_kms/_services/async_kms.py
4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 | |