-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds CBMC proof for aws_cryptosdk_priv_try_gen_key #661
Conversation
...fication/cbmc/proofs/aws_cryptosdk_priv_try_gen_key/aws_cryptosdk_priv_try_gen_key_harness.c
Outdated
Show resolved
Hide resolved
...fication/cbmc/proofs/aws_cryptosdk_priv_try_gen_key/aws_cryptosdk_priv_try_gen_key_harness.c
Outdated
Show resolved
Hide resolved
...fication/cbmc/proofs/aws_cryptosdk_priv_try_gen_key/aws_cryptosdk_priv_try_gen_key_harness.c
Outdated
Show resolved
Hide resolved
...fication/cbmc/proofs/aws_cryptosdk_priv_try_gen_key/aws_cryptosdk_priv_try_gen_key_harness.c
Outdated
Show resolved
Hide resolved
source/session_encrypt.c
Outdated
AWS_PRECONDITION(session != NULL); | ||
AWS_PRECONDITION(aws_cryptosdk_cmm_base_is_valid(session->cmm)); | ||
AWS_PRECONDITION(aws_cryptosdk_alg_properties_is_valid(session->alg_props)); | ||
AWS_PRECONDITION(aws_cryptosdk_hdr_is_valid(&session->header)); | ||
AWS_PRECONDITION(aws_cryptosdk_keyring_trace_is_valid(&session->keyring_trace)); | ||
AWS_PRECONDITION(aws_allocator_is_valid(session->alloc)); | ||
AWS_PRECONDITION(aws_cryptosdk_commitment_policy_is_valid(session->commitment_policy)); | ||
AWS_PRECONDITION(session->state == ST_GEN_KEY); | ||
AWS_PRECONDITION(session->mode == AWS_CRYPTOSDK_ENCRYPT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you open an issue so that I do not forget replacing this by the session validator that I am writing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made one here - #670
verification/cbmc/proofs/aws_cryptosdk_priv_try_gen_key/Makefile
Outdated
Show resolved
Hide resolved
verification/cbmc/proofs/aws_cryptosdk_priv_try_gen_key/Makefile
Outdated
Show resolved
Hide resolved
verification/cbmc/proofs/aws_cryptosdk_priv_try_gen_key/cbmc-batch.yaml
Outdated
Show resolved
Hide resolved
verification/cbmc/proofs/aws_cryptosdk_priv_try_gen_key/Makefile
Outdated
Show resolved
Hide resolved
...fication/cbmc/proofs/aws_cryptosdk_priv_try_gen_key/aws_cryptosdk_priv_try_gen_key_harness.c
Outdated
Show resolved
Hide resolved
...fication/cbmc/proofs/aws_cryptosdk_priv_try_gen_key/aws_cryptosdk_priv_try_gen_key_harness.c
Outdated
Show resolved
Hide resolved
76096d6
to
2340de6
Compare
93cf80d
to
00e277b
Compare
faff1c2
to
fd16bf3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is now ready to review! Here is a summary of the changes I have introduced since the last time you reviewed it:
- The session validator now allows
session->alg_props
to be null or valid. - Due to the previous change, the proofs for
sign_header
andderive_data_key
were broken (they assumedsession->alg_props
to be always valid). Therefore, I have added additional assumptions/preconditions to enforcesession->alg_props
to be valid. - All stubs that were defined in the harness have been moved to their own file on the stubs folder.
- I have included the stub for
aws_cryptosdk_hdr_write
that I wrote for thesign_header
proof in this PR. This reduced the time to complete this proof from ~2h to ~30mins. - Buffer validity is asserted for
okm
in the HKDF stub.
As noted in the harness, we do not use the session_setup
function because would be creating objects that are not used or need to be replaced later (costly in proofs like this one).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, with a few more improvements in documentation.
@@ -103,7 +103,7 @@ AWS_CRYPTOSDK_STATIC_INLINE bool aws_cryptosdk_session_is_valid(const struct aws | |||
bool cmm_valid = aws_cryptosdk_cmm_base_is_valid(session->cmm); | |||
bool hdr_valid = aws_cryptosdk_hdr_is_valid(&session->header); | |||
bool keyring_trace_valid = aws_cryptosdk_keyring_trace_is_valid(&session->keyring_trace); | |||
bool alg_props_valid = aws_cryptosdk_alg_properties_is_valid(session->alg_props); | |||
bool alg_props_valid = session->alg_props == NULL || aws_cryptosdk_alg_properties_is_valid(session->alg_props); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add parenthesis.
bool alg_props_valid = (session->alg_props == NULL || aws_cryptosdk_alg_properties_is_valid(session->alg_props));
And makes sure @alex-chew agree that a valid aws_cryptosdk_session
can have a NULL alg_props
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed session->alg_props
can be NULL.
if (aws_byte_buf_init(&session->header.message_id, session->alloc, message_id_len) != AWS_OP_SUCCESS) { | ||
goto out; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
* multiple functions (see Makefile). It also requires a quite specific | ||
* configuration for the session struct (cmm's vtable must include a | ||
* pointer to the function declared above, alg_props can be NULL or valid, | ||
* etc.) so we do not use the session_setup method to initialize it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/*
* ... to initialize it.
*/
* A generator function as described in the comment | ||
* in aws_cryptosdk_hash_elems_array_init_stub.c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should describe it again here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copied it.
/* Stub this until https://github.com/diffblue/cbmc/issues/5344 is fixed | ||
Original function is here: | ||
https://github.com/aws/aws-encryption-sdk-c/blob/master/source/edk.c#L44 */ | ||
void aws_cryptosdk_edk_list_clean_up(struct aws_array_list *encrypted_data_keys) { | ||
assert(aws_cryptosdk_edk_list_is_valid(encrypted_data_keys)); | ||
aws_array_list_clean_up(encrypted_data_keys); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a github issue to track this in this project, please, create one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like that issue has been solved, but we should determine the correctness/performance impact next. That alone would make an outstanding PR, so I have created the corresponding issue here: #690
a0d13b3
to
dfadf04
Compare
dfadf04
to
ec5b382
Compare
* Adds check in case byte_buf_init fails * Adds harness, Makefile and yaml for priv_try_gen_key * Adds preconditions to source code * Update to harness * yaml update to boiler plate default * Remove unneccessary remove functions * Added preconditions of lne of byte bufs * Use CBMC_OBJECT_BITS = 9 flag * Use session setup and validator functions * Move stubs in harness to stubs folder * Weaken preconditions. Allow null in session members * Remove CBMC_OBJECT_BITS flag * Add comments and assert for `okm` in hkdf stub * Add props assumptions in sign_header and derive_data_key proofs * Remove unused stub `aws_default_allocator` * Add missing source file in `sign_header` proof * Add minor improvements Co-authored-by: Adrian Palacios <[email protected]>
* Adds check in case byte_buf_init fails * Adds harness, Makefile and yaml for priv_try_gen_key * Adds preconditions to source code * Update to harness * yaml update to boiler plate default * Remove unneccessary remove functions * Added preconditions of lne of byte bufs * Use CBMC_OBJECT_BITS = 9 flag * Use session setup and validator functions * Move stubs in harness to stubs folder * Weaken preconditions. Allow null in session members * Remove CBMC_OBJECT_BITS flag * Add comments and assert for `okm` in hkdf stub * Add props assumptions in sign_header and derive_data_key proofs * Remove unused stub `aws_default_allocator` * Add missing source file in `sign_header` proof * Add minor improvements Co-authored-by: Adrian Palacios <[email protected]>
* Adds check in case byte_buf_init fails * Adds harness, Makefile and yaml for priv_try_gen_key * Adds preconditions to source code * Update to harness * yaml update to boiler plate default * Remove unneccessary remove functions * Added preconditions of lne of byte bufs * Use CBMC_OBJECT_BITS = 9 flag * Use session setup and validator functions * Move stubs in harness to stubs folder * Weaken preconditions. Allow null in session members * Remove CBMC_OBJECT_BITS flag * Add comments and assert for `okm` in hkdf stub * Add props assumptions in sign_header and derive_data_key proofs * Remove unused stub `aws_default_allocator` * Add missing source file in `sign_header` proof * Add minor improvements Co-authored-by: Adrian Palacios <[email protected]>
* Adds check in case byte_buf_init fails * Adds harness, Makefile and yaml for priv_try_gen_key * Adds preconditions to source code * Update to harness * yaml update to boiler plate default * Remove unneccessary remove functions * Added preconditions of lne of byte bufs * Use CBMC_OBJECT_BITS = 9 flag * Use session setup and validator functions * Move stubs in harness to stubs folder * Weaken preconditions. Allow null in session members * Remove CBMC_OBJECT_BITS flag * Add comments and assert for `okm` in hkdf stub * Add props assumptions in sign_header and derive_data_key proofs * Remove unused stub `aws_default_allocator` * Add missing source file in `sign_header` proof * Add minor improvements Co-authored-by: Adrian Palacios <[email protected]>
* Adds check in case byte_buf_init fails * Adds harness, Makefile and yaml for priv_try_gen_key * Adds preconditions to source code * Update to harness * yaml update to boiler plate default * Remove unneccessary remove functions * Added preconditions of lne of byte bufs * Use CBMC_OBJECT_BITS = 9 flag * Use session setup and validator functions * Move stubs in harness to stubs folder * Weaken preconditions. Allow null in session members * Remove CBMC_OBJECT_BITS flag * Add comments and assert for `okm` in hkdf stub * Add props assumptions in sign_header and derive_data_key proofs * Remove unused stub `aws_default_allocator` * Add missing source file in `sign_header` proof * Add minor improvements Co-authored-by: Adrian Palacios <[email protected]>
Adds Makefile, harness and yaml for proof of aws_cryptosdk_priv_try_gen_key.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Check any applicable: