AWS KMS: Import Matching Symmetric Material into a Replica
See more AWS KMS Examples
Uses the current AWS KMS API. Configure the region and keep credentials in private qa_data/aws/kms.json, with nonempty string fields access_key and secret_key. The examples do not obtain or refresh credentials. Keep diagnostics private; they may contain credentials or sensitive key data. Create the output directory before running file-writing examples.
Uses the AWS JSON 1.1 protocol with TrentService targets, service kms, HTTPS certificate verification, and Signature Version 4. When using temporary credentials, also provide a nonempty session_token; this Rest example includes it in the signed query on each request. Never log that URL. The endpoint shown is for the commercial AWS partition; use the appropriate endpoint for other partitions. Failures stop the sample; production retry policies should use bounded backoff with jitter and reconcile uncertain writes.
Where a key is required, set string key_id to its fixed key ARN in the configured region. Additional named fields and input files are described below. Keep output files private when they contain plaintext or policies. The code does not automatically retry mutations, refresh credentials, or create output directories. A successful request can precede propagation of a state change. Discard sensitive objects promptly; clearing one buffer does not erase copies held in strings, JSON, or runtime memory.
Use an existing EXTERNAL symmetric ENCRYPT_DECRYPT key and a protected, durably backed-up file qa_data/kms/import_aes256.bin containing exactly 32 raw bytes. This imports an existing file rather than generating unrecoverable material at runtime. Uses RSAES_OAEP_SHA_256 with RSA_4096. Run in the replica region with its ARN, the exact bytes already imported into the primary, and key_material_id from the primary. Sends EXISTING_KEY_MATERIAL. This does not trigger rotation. Nonexpiring material is an explicit policy choice; use KEY_MATERIAL_EXPIRES/ValidTo if expiration is required.
API actions used: kms:DescribeKey, kms:GetParametersForImport, kms:ImportKeyMaterial. IAM permissions and key policies must allow the actual resources; grant and multi-Region workflows can need permissions in more than one region/account.
DescribeKey | GetParametersForImport | ImportKeyMaterial
Chilkat Delphi DLL Downloads
var
success: Boolean;
stringCompare: HCkStringBuilder;
credentials: HCkJsonObject;
stringMatch1: Boolean;
stringMatch2: Boolean;
region: PWideChar;
endpoint: HCkStringBuilder;
aws: HCkAuthAws;
rest: HCkRest;
stringMatch3: Boolean;
connection: HCkSocket;
body: HCkJsonObject;
result: HCkJsonObject;
responseJson: PWideChar;
stringMatch4: Boolean;
keyId: PWideChar;
stringMatch5: Boolean;
stringMatch6: Boolean;
stringMatch7: Boolean;
stringMatch8: Boolean;
stringMatch9: Boolean;
stringMatch10: Boolean;
stringMatch11: Boolean;
stringMatch12: Boolean;
stringMatch13: Boolean;
stringMatch14: Boolean;
material: HCkBinData;
stringMatch15: Boolean;
stringMatch16: Boolean;
stringMatch17: Boolean;
materialId: PWideChar;
stringMatch18: Boolean;
stringMatch19: Boolean;
stringMatch20: Boolean;
stringMatch21: Boolean;
now: HCkDateTime;
expires: HCkDateTime;
importToken: PWideChar;
wrappingKey: HCkPublicKey;
rsa: HCkRsa;
stringMatch22: Boolean;
stringMatch23: Boolean;
begin
success := False;
stringCompare := CkStringBuilder_Create();
// Assumes Chilkat is unlocked. See Global Unlock Sample.
// Keep this credentials file outside public web content and source control.
credentials := CkJsonObject_Create();
CkJsonObject_putStrict(credentials,True);
success := CkJsonObject_LoadFile(credentials,'qa_data/aws/kms.json');
if (success <> True) then
begin
Memo1.Lines.Add('Could not load private KMS configuration.');
Exit;
end;
CkStringBuilder_SetString(stringCompare,CkJsonObject__stringOf(credentials,'access_key'));
stringMatch1 := CkStringBuilder_ContentsEqual(stringCompare,'',True);
if ((CkJsonObject_JsonTypeOf(credentials,'access_key') <> 1) or (stringMatch1 = True)) then
begin
Memo1.Lines.Add('Missing or invalid access_key.');
Exit;
end;
CkStringBuilder_SetString(stringCompare,CkJsonObject__stringOf(credentials,'secret_key'));
stringMatch2 := CkStringBuilder_ContentsEqual(stringCompare,'',True);
if ((CkJsonObject_JsonTypeOf(credentials,'secret_key') <> 1) or (stringMatch2 = True)) then
begin
Memo1.Lines.Add('Missing or invalid secret_key.');
Exit;
end;
region := 'us-west-2';
endpoint := CkStringBuilder_Create();
CkStringBuilder_Append(endpoint,'kms.');
CkStringBuilder_Append(endpoint,region);
CkStringBuilder_Append(endpoint,'.amazonaws.com');
aws := CkAuthAws_Create();
CkAuthAws_putAccessKey(aws,CkJsonObject__stringOf(credentials,'access_key'));
CkAuthAws_putSecretKey(aws,CkJsonObject__stringOf(credentials,'secret_key'));
CkAuthAws_putRegion(aws,region);
CkAuthAws_putServiceName(aws,'kms');
CkAuthAws_putSignatureVersion(aws,4);
rest := CkRest_Create();
CkRest_putConnectTimeoutMs(rest,20000);
CkRest_putIdleTimeoutMs(rest,60000);
CkRest_putVerboseLogging(rest,False);
success := CkRest_SetAuthAws(rest,aws);
if (success <> True) then
begin
Memo1.Lines.Add('Could not configure AWS signing.');
Exit;
end;
if (CkJsonObject_HasMember(credentials,'session_token') = True) then
begin
CkStringBuilder_SetString(stringCompare,CkJsonObject__stringOf(credentials,'session_token'));
stringMatch3 := CkStringBuilder_ContentsEqual(stringCompare,'',True);
if ((CkJsonObject_JsonTypeOf(credentials,'session_token') <> 1) or (stringMatch3 = True)) then
begin
Memo1.Lines.Add('Missing or invalid session_token.');
Exit;
end;
end;
connection := CkSocket_Create();
CkSocket_putRequireSslCertVerify(connection,True);
CkSocket_putMaxReadIdleMs(connection,60000);
CkSocket_putMaxSendIdleMs(connection,60000);
success := CkSocket_Connect(connection,CkStringBuilder__getAsString(endpoint),443,True,20000);
if (success <> True) then
begin
Memo1.Lines.Add('TLS connection failed; inspect diagnostics privately.');
Exit;
end;
success := CkRest_UseConnection(rest,connection,True);
if (success <> True) then
begin
Memo1.Lines.Add('Could not attach TLS connection.');
Exit;
end;
// Keep connection alive while Rest uses it.
body := CkJsonObject_Create();
result := CkJsonObject_Create();
CkJsonObject_putStrict(result,True);
CkStringBuilder_SetString(stringCompare,CkJsonObject__stringOf(credentials,'key_id'));
stringMatch4 := CkStringBuilder_ContentsEqual(stringCompare,'',True);
if ((CkJsonObject_JsonTypeOf(credentials,'key_id') <> 1) or (stringMatch4 = True)) then
begin
Memo1.Lines.Add('Missing or invalid key_id.');
Exit;
end;
keyId := CkJsonObject__stringOf(credentials,'key_id');
CkJsonObject_Clear(body);
success := CkJsonObject_UpdateString(body,'KeyId',keyId);
if (success <> True) then
begin
Memo1.Lines.Add('Could not set KeyId.');
Exit;
end;
success := CkRest_ClearAllQueryParams(rest);
if (success <> True) then
begin
Memo1.Lines.Add('Could not clear previous query parameters.');
Exit;
end;
// Keep the JSON operation body separate from authentication parameters.
// Include STS credentials in the signed query; never log the request URL.
if (CkJsonObject_HasMember(credentials,'session_token') = True) then
begin
success := CkRest_AddQueryParam(rest,'X-Amz-Security-Token',CkJsonObject__stringOf(credentials,'session_token'));
if (success <> True) then
begin
Memo1.Lines.Add('Could not set session token.');
Exit;
end;
end;
success := CkRest_AddHeader(rest,'X-Amz-Target','TrentService.DescribeKey');
if (success <> True) then
begin
Memo1.Lines.Add('Could not set operation.');
Exit;
end;
success := CkRest_AddHeader(rest,'Content-Type','application/x-amz-json-1.1');
if (success <> True) then
begin
Memo1.Lines.Add('Could not set content type.');
Exit;
end;
responseJson := CkRest__fullRequestString(rest,'POST','/',CkJsonObject__emit(body));
if (CkRest_getLastMethodSuccess(rest) <> True) then
begin
Memo1.Lines.Add('KMS request did not complete; inspect diagnostics privately. Reconcile any write before retrying.');
Exit;
end;
if (CkRest_getResponseStatusCode(rest) <> 200) then
begin
Memo1.Lines.Add('KMS HTTP status: ' + IntToStr(CkRest_getResponseStatusCode(rest)));
success := CkJsonObject_Load(result,responseJson);
if (success = True) then
begin
if (CkJsonObject_JsonTypeOf(result,'__type') = 1) then
begin
Memo1.Lines.Add('AWS error code: ' + CkJsonObject__stringOf(result,'__type'));
end;
end;
Memo1.Lines.Add('AWS request ID: ' + CkRest__responseHdrByName(rest,'x-amzn-RequestId'));
// Do not print full bodies, headers, credentials, key material, or tokens.
Exit;
end;
success := CkJsonObject_Load(result,responseJson);
if (success <> True) then
begin
Memo1.Lines.Add('Expected a well-formed JSON response.');
Exit;
end;
CkStringBuilder_SetString(stringCompare,CkJsonObject__stringOf(result,'KeyMetadata.Arn'));
stringMatch5 := CkStringBuilder_ContentsEqual(stringCompare,'',True);
if ((CkJsonObject_JsonTypeOf(result,'KeyMetadata.Arn') <> 1) or (stringMatch5 = True)) then
begin
Memo1.Lines.Add('Missing or invalid KeyMetadata.Arn.');
Exit;
end;
CkStringBuilder_SetString(stringCompare,CkJsonObject__stringOf(result,'KeyMetadata.KeyId'));
stringMatch6 := CkStringBuilder_ContentsEqual(stringCompare,'',True);
if ((CkJsonObject_JsonTypeOf(result,'KeyMetadata.KeyId') <> 1) or (stringMatch6 = True)) then
begin
Memo1.Lines.Add('Missing or invalid KeyMetadata.KeyId.');
Exit;
end;
CkStringBuilder_SetString(stringCompare,CkJsonObject__stringOf(result,'KeyMetadata.KeySpec'));
stringMatch7 := CkStringBuilder_ContentsEqual(stringCompare,'',True);
if ((CkJsonObject_JsonTypeOf(result,'KeyMetadata.KeySpec') <> 1) or (stringMatch7 = True)) then
begin
Memo1.Lines.Add('Missing or invalid KeyMetadata.KeySpec.');
Exit;
end;
CkStringBuilder_SetString(stringCompare,CkJsonObject__stringOf(result,'KeyMetadata.KeySpec'));
stringMatch8 := CkStringBuilder_ContentsEqual(stringCompare,'SYMMETRIC_DEFAULT',True);
if (stringMatch8 <> True) then
begin
Memo1.Lines.Add('Unexpected KeyMetadata.KeySpec.');
Exit;
end;
CkStringBuilder_SetString(stringCompare,CkJsonObject__stringOf(result,'KeyMetadata.KeyUsage'));
stringMatch9 := CkStringBuilder_ContentsEqual(stringCompare,'',True);
if ((CkJsonObject_JsonTypeOf(result,'KeyMetadata.KeyUsage') <> 1) or (stringMatch9 = True)) then
begin
Memo1.Lines.Add('Missing or invalid KeyMetadata.KeyUsage.');
Exit;
end;
CkStringBuilder_SetString(stringCompare,CkJsonObject__stringOf(result,'KeyMetadata.KeyUsage'));
stringMatch10 := CkStringBuilder_ContentsEqual(stringCompare,'ENCRYPT_DECRYPT',True);
if (stringMatch10 <> True) then
begin
Memo1.Lines.Add('Unexpected KeyMetadata.KeyUsage.');
Exit;
end;
CkStringBuilder_SetString(stringCompare,CkJsonObject__stringOf(result,'KeyMetadata.Origin'));
stringMatch11 := CkStringBuilder_ContentsEqual(stringCompare,'',True);
if ((CkJsonObject_JsonTypeOf(result,'KeyMetadata.Origin') <> 1) or (stringMatch11 = True)) then
begin
Memo1.Lines.Add('Missing or invalid KeyMetadata.Origin.');
Exit;
end;
CkStringBuilder_SetString(stringCompare,CkJsonObject__stringOf(result,'KeyMetadata.Origin'));
stringMatch12 := CkStringBuilder_ContentsEqual(stringCompare,'EXTERNAL',True);
if (stringMatch12 <> True) then
begin
Memo1.Lines.Add('Unexpected KeyMetadata.Origin.');
Exit;
end;
CkStringBuilder_SetString(stringCompare,CkJsonObject__stringOf(result,'KeyMetadata.KeyManager'));
stringMatch13 := CkStringBuilder_ContentsEqual(stringCompare,'',True);
if ((CkJsonObject_JsonTypeOf(result,'KeyMetadata.KeyManager') <> 1) or (stringMatch13 = True)) then
begin
Memo1.Lines.Add('Missing or invalid KeyMetadata.KeyManager.');
Exit;
end;
CkStringBuilder_SetString(stringCompare,CkJsonObject__stringOf(result,'KeyMetadata.KeyManager'));
stringMatch14 := CkStringBuilder_ContentsEqual(stringCompare,'CUSTOMER',True);
if (stringMatch14 <> True) then
begin
Memo1.Lines.Add('Unexpected KeyMetadata.KeyManager.');
Exit;
end;
keyId := CkJsonObject__stringOf(result,'KeyMetadata.Arn');
material := CkBinData_Create();
success := CkBinData_LoadFile(material,'qa_data/kms/import_aes256.bin');
if (success <> True) then
begin
Memo1.Lines.Add('Could not load qa_data/kms/import_aes256.bin.');
Exit;
end;
if (CkBinData_getNumBytes(material) <> 32) then
begin
Memo1.Lines.Add('Provide exactly 32 bytes of backed-up AES-256 key material.');
Exit;
end;
CkStringBuilder_SetString(stringCompare,CkJsonObject__stringOf(result,'KeyMetadata.MultiRegionConfiguration.MultiRegionKeyType'));
stringMatch15 := CkStringBuilder_ContentsEqual(stringCompare,'',True);
if ((CkJsonObject_JsonTypeOf(result,'KeyMetadata.MultiRegionConfiguration.MultiRegionKeyType') <> 1) or (stringMatch15 = True)) then
begin
Memo1.Lines.Add('Missing or invalid KeyMetadata.MultiRegionConfiguration.MultiRegionKeyType.');
Exit;
end;
CkStringBuilder_SetString(stringCompare,CkJsonObject__stringOf(result,'KeyMetadata.MultiRegionConfiguration.MultiRegionKeyType'));
stringMatch16 := CkStringBuilder_ContentsEqual(stringCompare,'REPLICA',True);
if (stringMatch16 <> True) then
begin
Memo1.Lines.Add('Unexpected KeyMetadata.MultiRegionConfiguration.MultiRegionKeyType.');
Exit;
end;
CkStringBuilder_SetString(stringCompare,CkJsonObject__stringOf(credentials,'key_material_id'));
stringMatch17 := CkStringBuilder_ContentsEqual(stringCompare,'',True);
if ((CkJsonObject_JsonTypeOf(credentials,'key_material_id') <> 1) or (stringMatch17 = True)) then
begin
Memo1.Lines.Add('Missing or invalid key_material_id.');
Exit;
end;
materialId := CkJsonObject__stringOf(credentials,'key_material_id');
CkJsonObject_Clear(body);
success := CkJsonObject_UpdateString(body,'KeyId',keyId);
if (success <> True) then
begin
Memo1.Lines.Add('Could not set KeyId.');
Exit;
end;
success := CkJsonObject_UpdateString(body,'WrappingAlgorithm','RSAES_OAEP_SHA_256');
if (success <> True) then
begin
Memo1.Lines.Add('Could not set WrappingAlgorithm.');
Exit;
end;
success := CkJsonObject_UpdateString(body,'WrappingKeySpec','RSA_4096');
if (success <> True) then
begin
Memo1.Lines.Add('Could not set WrappingKeySpec.');
Exit;
end;
success := CkRest_ClearAllQueryParams(rest);
if (success <> True) then
begin
Memo1.Lines.Add('Could not clear previous query parameters.');
Exit;
end;
// Keep the JSON operation body separate from authentication parameters.
// Include STS credentials in the signed query; never log the request URL.
if (CkJsonObject_HasMember(credentials,'session_token') = True) then
begin
success := CkRest_AddQueryParam(rest,'X-Amz-Security-Token',CkJsonObject__stringOf(credentials,'session_token'));
if (success <> True) then
begin
Memo1.Lines.Add('Could not set session token.');
Exit;
end;
end;
success := CkRest_AddHeader(rest,'X-Amz-Target','TrentService.GetParametersForImport');
if (success <> True) then
begin
Memo1.Lines.Add('Could not set operation.');
Exit;
end;
success := CkRest_AddHeader(rest,'Content-Type','application/x-amz-json-1.1');
if (success <> True) then
begin
Memo1.Lines.Add('Could not set content type.');
Exit;
end;
responseJson := CkRest__fullRequestString(rest,'POST','/',CkJsonObject__emit(body));
if (CkRest_getLastMethodSuccess(rest) <> True) then
begin
Memo1.Lines.Add('KMS request did not complete; inspect diagnostics privately. Reconcile any write before retrying.');
Exit;
end;
if (CkRest_getResponseStatusCode(rest) <> 200) then
begin
Memo1.Lines.Add('KMS HTTP status: ' + IntToStr(CkRest_getResponseStatusCode(rest)));
success := CkJsonObject_Load(result,responseJson);
if (success = True) then
begin
if (CkJsonObject_JsonTypeOf(result,'__type') = 1) then
begin
Memo1.Lines.Add('AWS error code: ' + CkJsonObject__stringOf(result,'__type'));
end;
end;
Memo1.Lines.Add('AWS request ID: ' + CkRest__responseHdrByName(rest,'x-amzn-RequestId'));
// Do not print full bodies, headers, credentials, key material, or tokens.
Exit;
end;
success := CkJsonObject_Load(result,responseJson);
if (success <> True) then
begin
Memo1.Lines.Add('Expected a well-formed JSON response.');
Exit;
end;
CkStringBuilder_SetString(stringCompare,CkJsonObject__stringOf(result,'KeyId'));
stringMatch18 := CkStringBuilder_ContentsEqual(stringCompare,'',True);
if ((CkJsonObject_JsonTypeOf(result,'KeyId') <> 1) or (stringMatch18 = True)) then
begin
Memo1.Lines.Add('Missing or invalid KeyId.');
Exit;
end;
CkStringBuilder_SetString(stringCompare,CkJsonObject__stringOf(result,'KeyId'));
stringMatch19 := CkStringBuilder_ContentsEqual(stringCompare,keyId,True);
if (stringMatch19 <> True) then
begin
Memo1.Lines.Add('Response belongs to another key; use a fixed key ARN in configuration.');
Exit;
end;
CkStringBuilder_SetString(stringCompare,CkJsonObject__stringOf(result,'ImportToken'));
stringMatch20 := CkStringBuilder_ContentsEqual(stringCompare,'',True);
if ((CkJsonObject_JsonTypeOf(result,'ImportToken') <> 1) or (stringMatch20 = True)) then
begin
Memo1.Lines.Add('Missing or invalid ImportToken.');
Exit;
end;
CkStringBuilder_SetString(stringCompare,CkJsonObject__stringOf(result,'PublicKey'));
stringMatch21 := CkStringBuilder_ContentsEqual(stringCompare,'',True);
if ((CkJsonObject_JsonTypeOf(result,'PublicKey') <> 1) or (stringMatch21 = True)) then
begin
Memo1.Lines.Add('Missing or invalid PublicKey.');
Exit;
end;
if (CkJsonObject_JsonTypeOf(result,'ParametersValidTo') <> 2) then
begin
Memo1.Lines.Add('Missing or invalid ParametersValidTo.');
Exit;
end;
now := CkDateTime_Create();
expires := CkDateTime_Create();
success := CkDateTime_SetFromCurrentSystemTime(now);
if (success <> True) then
begin
Memo1.Lines.Add('Could not read current time.');
Exit;
end;
success := CkJsonObject_DateOf(result,'ParametersValidTo',expires);
if (success <> True) then
begin
Memo1.Lines.Add('Invalid parameter expiration.');
Exit;
end;
if (CkDateTime_DiffSeconds(expires,now) <= 0) then
begin
Memo1.Lines.Add('Wrapping parameters expired.');
Exit;
end;
importToken := CkJsonObject__stringOf(result,'ImportToken');
wrappingKey := CkPublicKey_Create();
success := CkPublicKey_LoadBase64(wrappingKey,CkJsonObject__stringOf(result,'PublicKey'));
if (success <> True) then
begin
Memo1.Lines.Add('Invalid RSA wrapping key.');
Exit;
end;
if (CkPublicKey_getKeySize(wrappingKey) <> 4096) then
begin
Memo1.Lines.Add('Expected RSA-4096 wrapping key.');
Exit;
end;
rsa := CkRsa_Create();
CkRsa_putPkcsPadding(rsa,False);
CkRsa_putOaepHash(rsa,'sha256');
CkRsa_putOaepMgfHash(rsa,'sha256');
success := CkRsa_UsePublicKey(rsa,wrappingKey);
if (success <> True) then
begin
Memo1.Lines.Add('Could not select wrapping key.');
Exit;
end;
success := CkRsa_EncryptBd(rsa,material,False);
if (success <> True) then
begin
Memo1.Lines.Add('Could not wrap AES key material.');
Exit;
end;
CkJsonObject_Clear(body);
success := CkJsonObject_UpdateString(body,'KeyId',keyId);
if (success <> True) then
begin
Memo1.Lines.Add('Could not set KeyId.');
Exit;
end;
success := CkJsonObject_UpdateString(body,'ImportToken',importToken);
if (success <> True) then
begin
Memo1.Lines.Add('Could not set ImportToken.');
Exit;
end;
success := CkJsonObject_UpdateString(body,'EncryptedKeyMaterial',CkBinData__getEncoded(material,'base64'));
if (success <> True) then
begin
Memo1.Lines.Add('Could not set EncryptedKeyMaterial.');
Exit;
end;
success := CkJsonObject_UpdateString(body,'ExpirationModel','KEY_MATERIAL_DOES_NOT_EXPIRE');
if (success <> True) then
begin
Memo1.Lines.Add('Could not set ExpirationModel.');
Exit;
end;
success := CkJsonObject_UpdateString(body,'ImportType','EXISTING_KEY_MATERIAL');
if (success <> True) then
begin
Memo1.Lines.Add('Could not set ImportType.');
Exit;
end;
success := CkJsonObject_UpdateString(body,'KeyMaterialId',materialId);
if (success <> True) then
begin
Memo1.Lines.Add('Could not set KeyMaterialId.');
Exit;
end;
success := CkRest_ClearAllQueryParams(rest);
if (success <> True) then
begin
Memo1.Lines.Add('Could not clear previous query parameters.');
Exit;
end;
// Keep the JSON operation body separate from authentication parameters.
// Include STS credentials in the signed query; never log the request URL.
if (CkJsonObject_HasMember(credentials,'session_token') = True) then
begin
success := CkRest_AddQueryParam(rest,'X-Amz-Security-Token',CkJsonObject__stringOf(credentials,'session_token'));
if (success <> True) then
begin
Memo1.Lines.Add('Could not set session token.');
Exit;
end;
end;
success := CkRest_AddHeader(rest,'X-Amz-Target','TrentService.ImportKeyMaterial');
if (success <> True) then
begin
Memo1.Lines.Add('Could not set operation.');
Exit;
end;
success := CkRest_AddHeader(rest,'Content-Type','application/x-amz-json-1.1');
if (success <> True) then
begin
Memo1.Lines.Add('Could not set content type.');
Exit;
end;
responseJson := CkRest__fullRequestString(rest,'POST','/',CkJsonObject__emit(body));
if (CkRest_getLastMethodSuccess(rest) <> True) then
begin
Memo1.Lines.Add('KMS request did not complete; inspect diagnostics privately. Reconcile any write before retrying.');
Exit;
end;
if (CkRest_getResponseStatusCode(rest) <> 200) then
begin
Memo1.Lines.Add('KMS HTTP status: ' + IntToStr(CkRest_getResponseStatusCode(rest)));
success := CkJsonObject_Load(result,responseJson);
if (success = True) then
begin
if (CkJsonObject_JsonTypeOf(result,'__type') = 1) then
begin
Memo1.Lines.Add('AWS error code: ' + CkJsonObject__stringOf(result,'__type'));
end;
end;
Memo1.Lines.Add('AWS request ID: ' + CkRest__responseHdrByName(rest,'x-amzn-RequestId'));
// Do not print full bodies, headers, credentials, key material, or tokens.
Exit;
end;
// ImportKeyMaterial acceptance does not mean rotation has completed.
CkStringBuilder_SetString(stringCompare,responseJson);
stringMatch22 := CkStringBuilder_ContentsEqual(stringCompare,'',True);
if (stringMatch22 <> True) then
begin
success := CkJsonObject_Load(result,responseJson);
if (success <> True) then
begin
Memo1.Lines.Add('Import accepted, but the response could not be parsed; reconcile before retrying.');
Exit;
end;
CkStringBuilder_SetString(stringCompare,CkJsonObject__stringOf(result,'KeyMaterialId'));
stringMatch23 := CkStringBuilder_ContentsEqual(stringCompare,'',True);
if ((CkJsonObject_JsonTypeOf(result,'KeyMaterialId') <> 1) or (stringMatch23 = True)) then
begin
Memo1.Lines.Add('Missing or invalid KeyMaterialId.');
Exit;
end;
Memo1.Lines.Add('Imported material ID: ' + CkJsonObject__stringOf(result,'KeyMaterialId'));
end
else
begin
Memo1.Lines.Add('Import accepted; retrieve the material identifier/state with ListKeyRotations.');
end;
Memo1.Lines.Add('Symmetric material import accepted; inspect ListKeyRotations before rotation.');
CkStringBuilder_Dispose(stringCompare);
CkJsonObject_Dispose(credentials);
CkStringBuilder_Dispose(endpoint);
CkAuthAws_Dispose(aws);
CkRest_Dispose(rest);
CkSocket_Dispose(connection);
CkJsonObject_Dispose(body);
CkJsonObject_Dispose(result);
CkBinData_Dispose(material);
CkDateTime_Dispose(now);
CkDateTime_Dispose(expires);
CkPublicKey_Dispose(wrappingKey);
CkRsa_Dispose(rsa);