-
Notifications
You must be signed in to change notification settings - Fork 0
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
sketching a rationale for the negative tests #7
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
faab3c5
to
2c67163
Compare
Hey @shizhMSFT, could you please have a look? |
4c644a9
to
41a61df
Compare
|
||
### Negative conditions | ||
|
||
Assuming no out-of-band channel exists: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIU the spec does not enforce the alg
label to be present in the COSE_Sign1
nor COSE_Sign
, so these negative conditions are too strict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reference: https://datatracker.ietf.org/doc/html/rfc8152#section-3.1
alg: This parameter is used to indicate the algorithm used for the
security processing. This parameter MUST be authenticated where
the ability to do so exists. This support is provided by AEAD
algorithms or construction (COSE_Sign, COSE_Sign0, COSE_Mac, and
COSE_Mac0). This authentication can be done either by placing the
header in the protected header bucket or as part of the externally
supplied data. The value is taken from the "COSE Algorithms"
registry (see Section 16.4).
and also
Generic_Headers = (
? 1 => int / tstr, ; algorithm identifier
? 2 => [+label], ; criticality
? 3 => tstr / int, ; content type
? 4 => bstr, ; key identifier
? 5 => bstr, ; IV
? 6 => bstr, ; Partial IV
? 7 => COSE_Signature / [+COSE_Signature] ; Counter signature
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIU the spec does not enforce the
alg
label to be present in theCOSE_Sign1
norCOSE_Sign
, so these negative conditions are too strict.
The spec says "This header parameter MUST be authenticated where the ability to do so exists." - which is always the case for Sign1 - and gives us two ways to achieve that, namely:
- placing the header parameter in the protected-header-parameters bucket
- as part of the externally supplied data.
Now, since "external" is not present in the test vector (i.e., we assume no OOB channel), the only choice for the implementation is to pull it from protected header. And since is not there either, our "Sign1 producer" seems to have failed to adhere to the spec, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This level of detail goes out of my knowledge. I'll agree with whatever you and @shizhMSFT decide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thomas-fossati Can I interpret
This parameter MUST be authenticated where the ability to do so exists.
as that the alg
header must present either in the protected header or the external data?
In other words, if externally supplied data is nil
or empty
, alg
MUST exists in the protected header?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If externally supplied data exists, the caller of the go-cose
library should check alg
by itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thomas-fossati , @qmuntal @shizhMSFT : As far as I understand, three unique cases exists:
- alg-id present in protected header
- alg-id part of external data
- Implicit alg-id applied. (id not present)
My understanding based on https://www.rfc-editor.org/authors/rfc9052.html#appendix-A
@thomas-fossati : Are we planning a test involving item 3) as well ? If yes, I am ok if we add a github issue to do this, in future, so as to proceed with current changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thomas-fossati Can I interpret
This parameter MUST be authenticated where the ability to do so exists.
as that the
alg
header must present either in the protected header or the external data?In other words, if externally supplied data is
nil
orempty
,alg
MUST exists in the protected header?
Yes, I think so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If externally supplied data exists, the caller of the
go-cose
library should checkalg
by itself?
I guess the UX angle here is that the API should allow setting the verification Algorithm explicitly to allow for the case where the peers use external data to carry the alg.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thomas-fossati : Are we planning a test involving item 3) as well ?
No, that is completely application specific.
cose-musts-and-shoulds.md
Outdated
### Negative conditions | ||
|
||
* [:white_check_mark:](sign1-verify-negative-0007.json) CBOR encoding using indefinite lengths => rejected by receiver | ||
* [:white_check_mark:](sign1-verify-negative-0006.json) CBOR encoding not using shortest encoding possible => rejected by receiver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIU the spec recommends using shorted encoding possible, but it does not enforce it, so the receiver should not reject it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reference: https://datatracker.ietf.org/doc/html/rfc8152#section-14
The restriction applies to the encoding of the Sig_structure, the
Enc_structure, and the MAC_structure.
For signing, Sig_structure
is an intermediate structure for computing the digest and is not in COSE_Sign or COSE_Sign1 messages.
Sig_structure = [
context : "Signature" / "Signature1" / "CounterSignature",
body_protected : empty_or_serialized_map,
? sign_protected : empty_or_serialized_map,
external_aad : bstr,
payload : bstr
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I read https://www.rfc-editor.org/authors/rfc9052.html#section-9-2.2 correctly, using the shortest encoding is an actual MUST.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I've just re-read the spec. Thanks @shizhMSFT for pointing me in the right direction - I got confused by the scope being a bullet point itself. I agree with you and will drop negative tests 6 and 7.
Signed-off-by: Thomas Fossati <thomas.fossati@arm.com>
Signed-off-by: Thomas Fossati <thomas.fossati@arm.com>
Signed-off-by: Thomas Fossati <thomas.fossati@arm.com>
Signed-off-by: Thomas Fossati <thomas.fossati@arm.com>
a2cde38
to
f98f34d
Compare
Hi, I'm just peanut gallery for now, not much bandwidth to do much here... Maybe you already are planning critical headers tests. They are definitely needed. The negative tests that t_cose tests with are partly represented in this header here: https://github.com/laurencelundblade/t_cose/blob/master/test/t_cose_make_test_messages.h I modified the t_cose signing code to make bad COSE_Sign1 messages for a lot of the negative tests. Many of them are for critical headers. Also a few of them are for not-well-formed CBOR. Also worry a large and grand test suite for COSE might end up having to have a core common set of tests and a series of tests on top of that for different profiles because there are so many different ways to use COSE. The algorithm ID discussion above is an example. Glad to see this work happening! |
Thanks @laurencelundblade for the pointers. |
No description provided.