mirror of
https://github.com/floci-io/floci.git
synced 2026-11-30 08:55:17 -05:00
The model's KeySummary holds the identifier, the state, the attributes, the check value and the two flags, and not the whole key. The list answered with the whole key, so it carried the timestamps and the origin that a summary does not hold. The list answers with the summary now, and the whole key stays the answer of the operation that names one key. The control plane's answers are driven through a real SDK and through the AWS CLI, so the wire format of the operations the summary fix touches is the one the clients read. The certificate of a key pair, a tag that is added and removed, a key pair that keeps the usage its derived keys have, the RSA cryptogram the key exchange serves, the key the two parties agreed, and the timestamps the answers carry. The page said the member was read and checked. Nothing reads it: the shape check is what checks it, against the range the model states. The page said each key in the list is the whole key rather than the summary the model names, which the change that answers with the summary makes untrue. The page says what a listed key carries now. The round trip through the RSA cryptogram asserted the ARN of the key that came in and the usage it was given, which a wrong key of the same usage would also pass. It compares the check value with the exported key's, so the test shows that the same key came back. The key that came in was not added to the list the cleanup walks, so it was left in the service when the class finished. It is added now.
88 lines
3.3 KiB
Bash
88 lines
3.3 KiB
Bash
#!/usr/bin/env bats
|
|
# Payment Cryptography control plane tests
|
|
#
|
|
# The operations that are not the key exchange itself: the certificate of a key pair, the
|
|
# tags of a key, and the usage a derived key is for. The tests drive them with the AWS CLI,
|
|
# which is such a client.
|
|
|
|
setup() {
|
|
load 'test_helper/common-setup'
|
|
KEY_ARN=""
|
|
PAIR_ARN=""
|
|
}
|
|
|
|
teardown() {
|
|
for key in "$KEY_ARN" "$PAIR_ARN"; do
|
|
if [ -n "$key" ]; then
|
|
aws_cmd payment-cryptography delete-key --key-identifier "$key" \
|
|
--delete-key-in-days 7 >/dev/null 2>&1 || true
|
|
fi
|
|
done
|
|
}
|
|
|
|
# A key of the given algorithm, for the data the cipher protects.
|
|
create_key() {
|
|
aws_cmd payment-cryptography create-key \
|
|
--key-attributes "KeyAlgorithm=$1,KeyClass=SYMMETRIC_KEY,KeyUsage=TR31_D0_SYMMETRIC_DATA_ENCRYPTION_KEY,KeyModesOfUse={Encrypt=true,Decrypt=true}" \
|
|
--exportable \
|
|
--query 'Key.KeyArn' --output text
|
|
}
|
|
|
|
@test "Payment Cryptography control plane: the certificate of a key pair is served" {
|
|
PAIR_ARN=$(aws_cmd payment-cryptography create-key \
|
|
--key-attributes 'KeyAlgorithm=ECC_NIST_P256,KeyClass=ASYMMETRIC_KEY_PAIR,KeyUsage=TR31_S0_ASYMMETRIC_KEY_FOR_DIGITAL_SIGNATURE,KeyModesOfUse={Sign=true,Verify=true}' \
|
|
--exportable \
|
|
--query 'Key.KeyArn' --output text)
|
|
[ -n "$PAIR_ARN" ]
|
|
|
|
run aws_cmd payment-cryptography get-public-key-certificate \
|
|
--key-identifier "$PAIR_ARN"
|
|
assert_success
|
|
CERTIFICATE=$(json_get "$output" '.KeyCertificate')
|
|
CHAIN=$(json_get "$output" '.KeyCertificateChain')
|
|
[ -n "$CERTIFICATE" ]
|
|
[ -n "$CHAIN" ]
|
|
# The certificate is base64 of a PEM, so it decodes to one.
|
|
echo "$CERTIFICATE" | base64 --decode | grep -q "BEGIN CERTIFICATE"
|
|
}
|
|
|
|
@test "Payment Cryptography control plane: a tag is added to a key and removed again" {
|
|
KEY_ARN=$(create_key AES_256)
|
|
[ -n "$KEY_ARN" ]
|
|
|
|
run aws_cmd payment-cryptography tag-resource \
|
|
--resource-arn "$KEY_ARN" \
|
|
--tags "Key=owner,Value=team"
|
|
assert_success
|
|
|
|
run aws_cmd payment-cryptography list-tags-for-resource \
|
|
--resource-arn "$KEY_ARN"
|
|
assert_success
|
|
[ "$(json_get "$output" '.Tags[0].Value')" = "team" ]
|
|
|
|
run aws_cmd payment-cryptography untag-resource \
|
|
--resource-arn "$KEY_ARN" \
|
|
--tag-keys owner
|
|
assert_success
|
|
|
|
run aws_cmd payment-cryptography list-tags-for-resource \
|
|
--resource-arn "$KEY_ARN"
|
|
assert_success
|
|
[ "$(json_get "$output" '.Tags | length')" = "0" ]
|
|
}
|
|
|
|
@test "Payment Cryptography control plane: a key pair is created with the usage its derived keys have" {
|
|
# The usage a derived key is for is named when the key pair is made, as the export
|
|
# guide's key agreement flow does.
|
|
PAIR_ARN=$(aws_cmd payment-cryptography create-key \
|
|
--key-attributes 'KeyAlgorithm=ECC_NIST_P256,KeyClass=ASYMMETRIC_KEY_PAIR,KeyUsage=TR31_K3_ASYMMETRIC_KEY_FOR_KEY_AGREEMENT,KeyModesOfUse={DeriveKey=true}' \
|
|
--derive-key-usage TR31_K1_KEY_BLOCK_PROTECTION_KEY \
|
|
--exportable \
|
|
--query 'Key.KeyArn' --output text)
|
|
[ -n "$PAIR_ARN" ]
|
|
|
|
run aws_cmd payment-cryptography get-key --key-identifier "$PAIR_ARN"
|
|
assert_success
|
|
[ "$(json_get "$output" '.Key.DeriveKeyUsage')" = "TR31_K1_KEY_BLOCK_PROTECTION_KEY" ]
|
|
}
|