Skip to content
This repository has been archived by the owner on Jan 31, 2025. It is now read-only.

Verify signature_or_mac_3 #19

Merged

Conversation

chrysn
Copy link
Collaborator

@chrysn chrysn commented Apr 24, 2021

There are some minor fixes, but primarily this introduces a check for the signature / MAC on message 3. (This is based on #17 and #18, so please ignore these first commits; this may be easier to process if they are merged first).

@TimothyClaeys please check whether the basic operation fits in your concepts for py-edhoc.

This can be tested by checking out the edhoc branch of aiocoap and running the edhocserver.py script and edhocclient.py localhost, possibly with a --static-static option.

Timothy Claeys and others added 3 commits April 21, 2021 18:05
+ Fix the broken example scripts
+ Use real X.509 certificates in the examples (authentication keys are Ed25519) --> remove pickled dictionary with legacy credential store
+ remote_cred_cb takes a Callable that returns the remote credentials
+ the return value of remote_cred_cb should go through _parse_credentials to parse/verify the RPK/certificate and extract the remote public authentication key
+ Add a custom CBOR encoder to properly encode COSE header maps with COSE header attributes
+ remove dependency on asn1crypto (everything can be done with the X509 module of the cryptography package)
@chrysn
Copy link
Collaborator Author

chrysn commented Apr 24, 2021

Procedurally, it may also make sense to merge the fixes first (leaving out the last commit) and for me to merge that later with the checks on signature_or_mac2.

@chrysn
Copy link
Collaborator Author

chrysn commented Apr 25, 2021

Now extended to also verify mac_or_signature2; it'll probably need a round of refactoring to pass the tests again.

[edit: envisioned refactoring steps are

  • Group together all the small fixes in a series of commits that can be fast-tracked
  • Squash the two verifying functions together (along with the fixup)
  • Work through how to best get cred_id[ri] consistently encoded or decoded.

]

chrysn added 2 commits April 25, 2021 22:02
This will allow the verifier to rebuild a MAC in the next step.
The remote callback used to be evaluated lazily whenever one of the
properties is first accessed; now it is evaluated as soon as all its
input data are set (ie. when the ID_CRED_remote is set). That laziness
currently *would* saved some calculation, but these savings go away as
things are verified completely.

The way this is done may later need to be changed again to accommodate
asynchronous operation, either by making some parts async, or by
altering how the library is used.

Not evaluating the callback result also led to some usage patterns being
untested.  Resulting from these tests, *all* callback outputs are fed
through _parse_credentials; this was previously done in only one code
path.
@chrysn
Copy link
Collaborator Author

chrysn commented Apr 25, 2021

Changes (including a consistent view on id_cred_remote) are regrouped as planned now, with a single "verify" commit on top.

Tests start breaking at "cred / authkey: Evaluate callback eagerly, deduplicating code"; I'd need a bit of help understanding what fails here: if you check what's happening at tests/test_initiator.py line 26, in some cases cred_idr has not been set yet at all, so the initiator.remote_authkey would not have contained anything sensible before (None rather than what it now does in raising an AttributeError, which IMO is the better behavior for "not having been set"). How can that have yielded any sensible data before?

(Along with that, I think this is now ready for review).

chrysn added 5 commits April 26, 2021 12:37
The lambda wrapper represents a change already done earlier in
"remote_cred_cb takes a Callable that returns the remote credentials"
(just never hit the test cases).

The cred_id[ri] setting is not so much done to have that available (it's
not even stored currently), but to ensure that this step (that usually
happens when parsing an incoming message) takes its side effects (of
evaluating the credentials callback and storing remote cred and authkey)
before these are used in the test evaluations.
Arguments may be had about whether this should be expanded even earlier,
but at least now it's consistently accessible.
@chrysn
Copy link
Collaborator Author

chrysn commented Apr 26, 2021

Tests are now all fixed, most of them in a manner I'd consider compatible (in the sense that the fixes are really to the test system, either because parts of it were buggy and just didn't trigger, or because they represent a usage pattern that is unobtainable outside test settings).

What was not fixed that cleanly was testing of the mac_or_signature, as the auth keys for cred_type 0 (what is that? don't find it in the documented parts) are simply absent (None). In these cases, a warning is issued and the tests are aborted prematurely.

With this, the test suite passes, I think this is good to review and merge.

@TimothyClaeys
Copy link
Member

Thanks a lot for this update. I've went over it quickly (will do another more thorough pass later today) and it looks really good. The idea behind the cred_type parameter was to distinguish between the different credential types (either RPK, C.509 or X.509) when providing them to the Initiator/Responder, and based on that value change the behaviour of the tests. As you mentioned, it is not something from the standard but I added it to make my life simpler. I'm not sure if it is still necessary.

uhdr={headers.Algorithm: self.cipher_suite.sign_alg},
payload=mac_3,
external_aad=external_aad)
# FIXME peeking into internals (probably best resolved at pycose level)
Copy link
Member

@TimothyClaeys TimothyClaeys May 18, 2021

Choose a reason for hiding this comment

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

Yes I agree, using the pycose library here in edhoc has uncovered some design flaws in the API and its usage.

@TimothyClaeys
Copy link
Member

Merging in the changes. CI will fail because of the newer pycose package.

@TimothyClaeys TimothyClaeys merged commit c1306ad into openwsn-berkeley:master May 18, 2021
@chrysn chrysn deleted the actually-verify branch May 18, 2021 16:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants