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

EC2: Allow creation with x only (for compact applications) #57

Closed

Conversation

chrysn
Copy link
Contributor

@chrysn chrysn commented Apr 26, 2021

Something like this is essential for getting cipher suites 2-3 running in pyedhoc.

The FIXMEs in the code primarily represent questions I have about the style of pycose:

  • Can we have the curve classes as used in EC just as properties of the curve classes as used in cose? (I'm duplicating a bit from the generate_key switch, but I doubt it should be there in the first place).
  • The Union[Type['CoseCurve'] type input is a bit hard to use (as seen by the if crv in part), and it doesn't seem like it is resolved even on the path to the final object. Is there any harm in giving CoseCurve some copy-constructor like behavior that'd allow us to just pass that union type through crv = CoseCurve(crv) once and be done with it?

(This has been tested as a part of a py-cose branch, but not interop'd; only the fact that if I swap around any key endianness the later curve point import to openssl fails makes me relatively confident that the reconstruction does work out).

@TimothyClaeys
Copy link
Owner

Yes, this is something we definitely need to include in the pycose library. I'll prepare a PR (including this commit) that updates the test vectors so they pass and answers some of your FIXME comments in the code.

@chrysn
Copy link
Contributor Author

chrysn commented Apr 29, 2021

To elaborate on the second point: The EC2Key init is accepting the curve as Union[Type['CoseCurve'], str, int].

Consequently, when I later look up the curve, I have to do if crv in (P256, P256.identifier):.

There may be merit to accepting all these types, but I don't think there is merit to allowing self.store[EC2KpCurve] to be any of those -- that should really just be EC2KpCurve. In the crv.setter we already do a conversion, so maybe it's a bug anyway that the init function lets any crv thing pass directly into the dict.

The right thing to do IMO would be to pass crv through CoseCurve.from_id whenever we get our hands on it in EC2 and similar classes (eg. right in the first lines of the constructor), possibly eased by a case in from_id that says if isinstance(attribute, cls): return cls to not need that check everywhere else around. That makes from_id a very practical constructor. (I've originally described that wrongly as copy-constructor-like, but didn't find a good term for no-op-if-already-constructed constructors either).

But I can open a PR for something along these lines to actually change this once this is merged (so we don't open up conflicts).

@TimothyClaeys
Copy link
Owner

Hi @chrysn, your explanation makes a lot of sense. You are right, it is a bug and I definitely intended to store the crv attribute in the internal dictionary store as a EC2KpCurve. The current behavior is a bug.

@TimothyClaeys
Copy link
Owner

On second thoughts, I think this bug was already fixed in master but it was not released on PyPi. Thus py-edhoc is using an outdated pycose.

In the EC2Key constructor, I'm using the crv property of EC2Key to check the provided crv parameter and I do the conversion (in case of an integer or string) there.

self.crv = crv

self.store[EC2KpCurve] = CoseCurve.from_id(crv)

@sanghvibk
Copy link

On second thoughts, I think this bug was already fixed in master but it was not released on PyPi. Thus py-edhoc is using an outdated pycose.

@TimothyClaeys , It seems that code in Git is not in sync with PyPi for the same version number 0.9.dev5. May be version number needs to be incremented in Git and latest package needs to be pushed to PyPi. Thank you for developing such a nice library.

@TimothyClaeys
Copy link
Owner

Thanks @sanghvibk, I bumped the version and uploaded everything to PyPi.

@TimothyClaeys
Copy link
Owner

@chrysn I cherry-picked this commit and put it on top of the ongoing work on the develop branch. I will close this PR since it was included in the latest develop branch which I just merged into master. Code was also packaged and uploaded to PyPi.

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.

3 participants