-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'build-fix-2024-04-19' of github.com:aws/aws-cryptograph…
…ic-material-providers-library-dafny into build-fix-2024-04-19
- Loading branch information
Showing
47 changed files
with
695 additions
and
113 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
...ptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/src/ErrorMessages.dfy
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
include "../Model/AwsCryptographyMaterialProvidersTypes.dfy" | ||
include "KeyWrapping/EdkWrapping.dfy" | ||
|
||
module ErrorMessages { | ||
import Types = AwsCryptographyMaterialProvidersTypes | ||
import UTF8 | ||
import UUID | ||
import opened Wrappers | ||
import EdkWrapping | ||
|
||
const SALT_LENGTH := 16 | ||
const IV_LENGTH := 12 | ||
const VERSION_LENGTH := 16 | ||
|
||
function method IncorrectRawDataKeys(datakey: string, keyringName: string, keyProviderId: string) | ||
: string | ||
{ | ||
"EncryptedDataKey " | ||
+ datakey | ||
+ " did not match " + keyringName + ". " | ||
+ "Expected: keyProviderId: " | ||
+ keyProviderId + ".\n" | ||
} | ||
|
||
function method {:opaque} IncorrectDataKeys(encryptedDataKeys: Types.EncryptedDataKeyList, material : Types.AlgorithmSuiteInfo,errMsg: string := "") | ||
: Result<string, Types.Error> | ||
{ | ||
var expectedValue :- IncorrectDataKeysExpectedValues(encryptedDataKeys, material, errMsg); | ||
Success("Unable to decrypt data key: No Encrypted Data Keys found to match. \n Expected: \n" + expectedValue) | ||
} | ||
|
||
function method {:tailrecursion} {:opaque} IncorrectDataKeysExpectedValues(encryptedDataKeys: Types.EncryptedDataKeyList, material : Types.AlgorithmSuiteInfo, errMsg: string := "") | ||
: Result<string, Types.Error> | ||
decreases |encryptedDataKeys| | ||
{ | ||
if (|encryptedDataKeys| == 0) then | ||
Success(errMsg) | ||
else | ||
var encryptedDataKey := encryptedDataKeys[0]; | ||
var extractedKeyProviderId :- UTF8.Decode(encryptedDataKey.keyProviderId).MapFailure(e => Types.AwsCryptographicMaterialProvidersException( message := e )); | ||
var extractedKeyProviderInfo :- UTF8.Decode(encryptedDataKey.keyProviderInfo).MapFailure(e => Types.AwsCryptographicMaterialProvidersException( message := e )); | ||
if (extractedKeyProviderId != "aws-kms-hierarchy") then | ||
IncorrectDataKeysExpectedValues(encryptedDataKeys[1..], material, errMsg + | ||
"KeyProviderId: " + extractedKeyProviderId + | ||
", KeyProviderInfo: " + extractedKeyProviderInfo + "\n") | ||
else | ||
var providerWrappedMaterial :- EdkWrapping.GetProviderWrappedMaterial(encryptedDataKey.ciphertext, material); | ||
var EDK_CIPHERTEXT_BRANCH_KEY_VERSION_INDEX := SALT_LENGTH + IV_LENGTH; | ||
var EDK_CIPHERTEXT_VERSION_INDEX := EDK_CIPHERTEXT_BRANCH_KEY_VERSION_INDEX + VERSION_LENGTH; | ||
:- Need(EDK_CIPHERTEXT_BRANCH_KEY_VERSION_INDEX < EDK_CIPHERTEXT_VERSION_INDEX, Types.AwsCryptographicMaterialProvidersException(message := "Wrong branch key version index.")); | ||
:- Need(|providerWrappedMaterial| >= EDK_CIPHERTEXT_VERSION_INDEX, Types.AwsCryptographicMaterialProvidersException(message := "Incorrect ciphertext structure.")); | ||
var branchKeyVersionUuid := providerWrappedMaterial[EDK_CIPHERTEXT_BRANCH_KEY_VERSION_INDEX .. EDK_CIPHERTEXT_VERSION_INDEX]; | ||
var branchVersion :- UUID.FromByteArray(branchKeyVersionUuid).MapFailure(e => Types.AwsCryptographicMaterialProvidersException( message := e )); | ||
IncorrectDataKeysExpectedValues(encryptedDataKeys[1..], material, errMsg + | ||
"KeyProviderId: " + extractedKeyProviderId + | ||
", KeyProviderInfo: " + extractedKeyProviderInfo + | ||
", BranchKeyVersion: " + branchVersion + "\n") | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.