Skip to content
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

Merged
merged 17 commits into from
Jan 19, 2021

Conversation

tegansb
Copy link
Contributor

@tegansb tegansb commented Dec 9, 2020

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:

  • Were any files moved? Moving files changes their URL, which breaks all hyperlinks to the files.

@tegansb tegansb added the cbmc CBMC proof related work label Dec 9, 2020
source/keyring_trace.c Outdated Show resolved Hide resolved
Comment on lines 51 to 61
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);
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made one here - #670

@adpaco-aws adpaco-aws self-requested a review December 21, 2020 19:12
@adpaco-aws adpaco-aws force-pushed the cbmc_priv_try_gen_key branch from 76096d6 to 2340de6 Compare January 11, 2021 18:19
@adpaco-aws adpaco-aws marked this pull request as ready for review January 15, 2021 19:44
@adpaco-aws adpaco-aws force-pushed the cbmc_priv_try_gen_key branch 2 times, most recently from 93cf80d to 00e277b Compare January 18, 2021 10:18
@adpaco-aws adpaco-aws force-pushed the cbmc_priv_try_gen_key branch from faff1c2 to fd16bf3 Compare January 19, 2021 09:34
Copy link
Collaborator

@adpaco-aws adpaco-aws left a 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 and derive_data_key were broken (they assumed session->alg_props to be always valid). Therefore, I have added additional assumptions/preconditions to enforce session->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 the sign_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).

@adpaco-aws adpaco-aws dismissed their stale review January 19, 2021 11:32

Reviewer is now an author

@adpaco-aws adpaco-aws requested a review from alex-chew January 19, 2021 11:33
Copy link
Collaborator

@feliperodri feliperodri left a 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);
Copy link
Collaborator

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.

Copy link
Contributor

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.

Comment on lines +96 to +98
if (aws_byte_buf_init(&session->header.message_id, session->alloc, message_id_len) != AWS_OP_SUCCESS) {
goto out;
}
Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/*
 * ... to initialize it.
 */

Comment on lines 19 to 20
* A generator function as described in the comment
* in aws_cryptosdk_hash_elems_array_init_stub.c
Copy link
Collaborator

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied it.

Comment on lines +20 to +26
/* 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);
}
Copy link
Collaborator

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.

Copy link
Collaborator

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

verification/cbmc/stubs/transfer_list_stub.c Show resolved Hide resolved
@adpaco-aws adpaco-aws force-pushed the cbmc_priv_try_gen_key branch from a0d13b3 to dfadf04 Compare January 19, 2021 15:33
@adpaco-aws adpaco-aws force-pushed the cbmc_priv_try_gen_key branch from dfadf04 to ec5b382 Compare January 19, 2021 15:34
@adpaco-aws adpaco-aws merged commit c8c123a into aws:master Jan 19, 2021
robin-aws pushed a commit to robin-aws/aws-encryption-sdk-c that referenced this pull request Apr 26, 2021
* 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]>
robin-aws pushed a commit to robin-aws/aws-encryption-sdk-c that referenced this pull request Apr 29, 2021
* 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]>
robin-aws pushed a commit to robin-aws/aws-encryption-sdk-c that referenced this pull request May 4, 2021
* 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]>
robin-aws pushed a commit to robin-aws/aws-encryption-sdk-c that referenced this pull request May 4, 2021
* 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]>
robin-aws pushed a commit that referenced this pull request May 5, 2021
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cbmc CBMC proof related work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants