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

Improve cookie crypto for CookieDealer #373

Merged
merged 2 commits into from
Jun 8, 2017
Merged

Conversation

schlenk
Copy link
Collaborator

@schlenk schlenk commented Jun 7, 2017

Added per cookie IV's to the CookieDealers encryption handling.

This fixes #363.

Also restyled the encrypt and MAC construction for cookie security to
use a more modern AEAD approach.

In this case it is AES-SIV (RFC 5297), which has the nice property to
be a bit resistant to IV reuse.

@coveralls
Copy link

coveralls commented Jun 7, 2017

Coverage Status

Changes Unknown when pulling d0a2e58 on schlenk:cookie_crypto into ** on OpenIDC:master**.

@rohe
Copy link
Contributor

rohe commented Jun 8, 2017

LGTM apart from the import sorting :-/

@coveralls
Copy link

coveralls commented Jun 8, 2017

Coverage Status

Coverage increased (+0.2%) to 63.13% when pulling 3219f73 on schlenk:cookie_crypto into 7dd51a5 on OpenIDC:master.

@coveralls
Copy link

coveralls commented Jun 8, 2017

Coverage Status

Coverage increased (+0.2%) to 63.13% when pulling b4b63f6 on schlenk:cookie_crypto into 7dd51a5 on OpenIDC:master.

@coveralls
Copy link

coveralls commented Jun 8, 2017

Coverage Status

Coverage increased (+0.2%) to 63.13% when pulling fa38cab on schlenk:cookie_crypto into 7dd51a5 on OpenIDC:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 63.13% when pulling 58cdbce on schlenk:cookie_crypto into 7dd51a5 on OpenIDC:master.

1 similar comment
@coveralls
Copy link

coveralls commented Jun 8, 2017

Coverage Status

Coverage increased (+0.2%) to 63.13% when pulling 58cdbce on schlenk:cookie_crypto into 7dd51a5 on OpenIDC:master.

@schlenk
Copy link
Collaborator Author

schlenk commented Jun 8, 2017

Seems isort messed up the line endings..., need to fix that again.

Added per cookie IV's to the CookieDealers encryption handling.

This fixes CZ-NIC#363.

Also restyled the encrypt and MAC construction for cookie security to
use a more modern AEAD approach.

In this case it is AES-SIV (RFC  5297), which has the nice property to
be a bit resistant to IV reuse.
@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 63.13% when pulling b9279ae on schlenk:cookie_crypto into 7dd51a5 on OpenIDC:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 63.13% when pulling b9279ae on schlenk:cookie_crypto into 7dd51a5 on OpenIDC:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 63.13% when pulling b9279ae on schlenk:cookie_crypto into 7dd51a5 on OpenIDC:master.

@schlenk schlenk requested a review from decentral1se June 8, 2017 10:41
Copy link
Contributor

@decentral1se decentral1se left a comment

Choose a reason for hiding this comment

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

Thanks for getting to work on this! LGTM beside some minor comments (ignore if stuck for time).

"""
Authenticated Encryption with Associated Data Wrapper

This does encrypts and does an integrity check in one
Copy link
Contributor

Choose a reason for hiding this comment

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

%s/does encrypts and does an/does encryption and an/g


"""
def __init__(self, key, iv, mode=AES.MODE_SIV):
assert isinstance(key, binary_type)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we not raise an ImproperlyConfigured error here for consistency?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This assert is mostly there to help with PY2/PY3 issues so keys/ivs etc stay 'byte strings'.
The configuration mistakes possible should be handled higher up, down here it is a programming error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it 👍

bytes_load = load.encode("utf-8")
bytes_timestamp = timestamp.encode("utf-8")

# If we have an encryption key, we use an AEAD cipher instead of
Copy link
Contributor

Choose a reason for hiding this comment

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

I would be worried that the comments will not match the implementation if changes come. Can you make a more higher level description of the function in the docstring?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll try.



def test_AEAD_good():
key = os.urandom(32)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want to take advantage of our new and shiny conftest.py and add what you can (seed, iv, cleartext) as fixtures?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will have a look if it fits.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think its useful in the main conftest.py file, but i moved them to local fixtures in the test file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, fine for now. If we need them, they can move.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 63.124% when pulling 3453ed3 on schlenk:cookie_crypto into 7dd51a5 on OpenIDC:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 63.124% when pulling 3453ed3 on schlenk:cookie_crypto into 7dd51a5 on OpenIDC:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 63.124% when pulling 3453ed3 on schlenk:cookie_crypto into 7dd51a5 on OpenIDC:master.

@schlenk
Copy link
Collaborator Author

schlenk commented Jun 8, 2017

@lwm I fixed the docstrings a bit, so maybe its good to go now.

@decentral1se
Copy link
Contributor

@lwm I fixed the docstrings a bit, so maybe its good to go now.

👍

@schlenk schlenk merged commit eee497c into CZ-NIC:master Jun 8, 2017
@schlenk schlenk deleted the cookie_crypto branch June 8, 2017 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CookieDealer.create_cookie reuses the IV for AES encryption of cookies
4 participants