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

Make symkey an optional kwarg. #324

Merged
merged 10 commits into from
Jun 5, 2017
Merged

Make symkey an optional kwarg. #324

merged 10 commits into from
Jun 5, 2017

Conversation

decentral1se
Copy link
Contributor

@decentral1se decentral1se commented Apr 5, 2017

  • Any changes relevant to users are recorded in the CHANGELOG.md.
  • The documentation has been updated, if necessary.

Follows from #322.

Copy link
Collaborator

@tpazderka tpazderka left a comment

Choose a reason for hiding this comment

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

I think that we shouldn't provide a default value to something that is security related. Rather define it as None and raise an ImproperlyConfigured error or similar if user is trying to use it without defining a proper value.

@VJalili
Copy link
Contributor

VJalili commented Apr 5, 2017

Agreed. I think the function signature is fine, but it's required to check for authentication method. Something link:
if authenticationMethod == symkeyauthn && symkey="" then raise ImproperlyConfigured

@lwm Could you please update your PR accordingly ?

Copy link
Contributor

@VJalili VJalili left a comment

Choose a reason for hiding this comment

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

Making symkey optional triggers following error for me:

File "/pyoidc/src/oic/utils/http_util.py", line 508, in get_cookie_value\n value, _ts, typ = txt.split("::")\n', ' ValueError: need more than 1 value to unpack\n'

@tpazderka
Copy link
Collaborator

That probably is a side-effect of what I have pointed out. Empty string is used in creation of the cookie.

@decentral1se
Copy link
Contributor Author

Ah yes, I'll need to work a bit more on this and make some tests. Thanks for review 👍

@decentral1se
Copy link
Contributor Author

decentral1se commented Apr 7, 2017

Breaking changes! 💣 I'll need to bump the version, I suppose. Getting close?

@@ -69,7 +69,7 @@ class ClaimsServer(Provider):
def __init__(self, name, sdb, cdb, userinfo, client_authn, urlmap=None,
ca_certs="", keyjar=None, hostname="", dist_claims_mode=None):
Provider.__init__(self, name, sdb, cdb, None, userinfo, None,
client_authn, "", urlmap, ca_certs, keyjar,
client_authn, rndstr(), urlmap, ca_certs, keyjar,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can probably cause issues...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you're right, will set to None instead.

ca_bundle=None, verify_ssl=True, default_acr="",
baseurl='', server_cls=Server, client_cert=None):

if symkey is not None and symkey == "":
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we can postpone this check till the point where the symkey is actually needed? Otherwise this check seems a little bit pointles since it passes for None which will break stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see what you mean, I'll try to find the point where it is used.

@tpazderka
Copy link
Collaborator

Sure, we can remmember to bump the version, but we should wait so we do not release that often.

@tpazderka
Copy link
Collaborator

Also you have a lot of unrelated cleanup changes. I would rather see them in a separate issue targeted at cleanup.

@decentral1se
Copy link
Contributor Author

Also you have a lot of unrelated cleanup changes. I would rather see them in a separate issue targeted at cleanup.

Yep, fair point, please see #329.

@decentral1se decentral1se changed the title Make symkey an optional kwarg. WIP: Make symkey an optional kwarg. Apr 13, 2017
@decentral1se
Copy link
Contributor Author

decentral1se commented Apr 13, 2017

  • Validate symkey is not the empty string in CookieDealer and SymkeyAuthn.
  • Write tests to cover these changes
  • Add some documentation (better start now than never) (no time again!)

I want to remove the level of indentation for this
function and find this to be the simplest way to do
that. I think it improve readability (I will add to
this functions implementation in future commits).
This new class is useful to show some user error when configuring the
Provider. I imagine, as we start to identify more which arguments/values
are security related, we will start to use this more.
In this commit, I track the usage of the `symkey` to the root in
`CookieDealer` and `SymKeyAuthn` and assert that it is never the empty
string.

Please see the following comment for background on this change:

    #324 (review)
I have to add a __init__.py so that pytest can figure
out where the conftest is.

Closes #361.
@decentral1se
Copy link
Contributor Author

OK gentlemen, please review this again! I've given it another go 👍

@decentral1se decentral1se self-assigned this Jun 4, 2017
@decentral1se decentral1se added this to the P2: SHOULD milestone Jun 4, 2017
@coveralls
Copy link

coveralls commented Jun 4, 2017

Coverage Status

Coverage increased (+0.05%) to 62.93% when pulling 3e7e291 on lwm:optional-symkey into b7a44a9 on OpenIDC:master.

@decentral1se decentral1se changed the title WIP: Make symkey an optional kwarg. Make symkey an optional kwarg. Jun 4, 2017
Copy link
Collaborator

@schlenk schlenk left a comment

Choose a reason for hiding this comment

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

Please fix at least the return case.

@@ -387,6 +388,10 @@ class SymKeyAuthn(UserAuthnMethod):

def __init__(self, srv, ttl, symkey):
UserAuthnMethod.__init__(self, srv, ttl)

if symkey is not None and symkey == "":
Copy link
Collaborator

Choose a reason for hiding this comment

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

The actual check is even stricter, due to the minimal aes keylength, that is enforced in oic.util.aes.build_cipher.

Maybe the aes code could provide a method to check for the minimal keylength, so we could raise ImproperlyConfigured for that too, instead of the current AssertionError/FailedAuthentication which is misleading?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The actual check is even stricter, due to the minimal aes keylength, that is enforced in oic.util.aes.build_cipher. ... Maybe the aes code could provide a method to check

I don't see the connection from the Provider.symkey to the oic.util.aes.build_cipher? Does one of the provider classes call this function? We put the check here due to the idea in this comment.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You are right (in a way).

The only usecase for using the Provider.symkey currently is to use it as a key for AES encryption. And AES encryption needs a minimum key length (as checked in build_cipher). So it makes no sense to have a symkey that is too short to use as an AES key. (e.g. just 2 Bytes or something like that).

Currently, you can set a symkey like 'ab' and all the setup/init works, but you blow up at runtime, when you get FailedAuthentication or other AssertionErrors from aes.encrypt(). So it would be user friendlier to prevent a too short to be useful symkey too, instead of just empty and None.

Copy link
Contributor Author

@decentral1se decentral1se Jun 5, 2017

Choose a reason for hiding this comment

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

Aha! I see, I see. Thanks for the explanation. I'll follow up with a key length check in #367.

if not getattr(srv, param, None):
setattr(srv, param, rndstr().encode("utf-8"))
if not srv:
return
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not raise an exception here? Every other method in the class will blow up with an Exception if self.srv is None, so the class is in a broken state without it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the original code did not either and I wasn't sure if this was acceptable. I'll patch that up. Please, @rohe, can you confirm this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd actually be happier with making this a separate ticket if you don't mind @schlenk. I have preserved the original behaviour (I think!) in this change but your recommendation (which I think is totally valid!) will bring something new. I've created #365 for that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok, fine with me.

@decentral1se decentral1se merged commit b0c8982 into CZ-NIC:master Jun 5, 2017
@decentral1se decentral1se deleted the optional-symkey branch June 5, 2017 15:00
@rohe
Copy link
Contributor

rohe commented Jun 7, 2017

Over the time I've been working on this library I've gone back and forth between throwing an exception or returning something to signal that an error occurred.
Lately I'm leaning more toward the 'throw an exception' camp so I would be OK with changing the code to raise an exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants