-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
S.S.C.Cose: Add new MultiSign APIs and address API review feedback on existing ones #71390
Conversation
Tagging subscribers to this area: @dotnet/area-system-security, @vcsjones |
...s/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseHeaderLabel.cs
Outdated
Show resolved
Hide resolved
...ies/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseHeaderMap.cs
Outdated
Show resolved
Hide resolved
...s/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseHeaderValue.cs
Outdated
Show resolved
Hide resolved
...s/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseHeaderValue.cs
Outdated
Show resolved
Hide resolved
...aries/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseHelpers.cs
Outdated
Show resolved
Hide resolved
...aries/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseHelpers.cs
Outdated
Show resolved
Hide resolved
...tem.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseMultiSignMessage.cs
Outdated
Show resolved
Hide resolved
.../System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseSign1Message.cs
Outdated
Show resolved
Hide resolved
...stem.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/KnownCoseAlgorithms.cs
Show resolved
Hide resolved
...ies/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseSignature.cs
Outdated
Show resolved
Hide resolved
...ies/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseSignature.cs
Show resolved
Hide resolved
...s/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseHeaderLabel.cs
Outdated
Show resolved
Hide resolved
...ies/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseHeaderMap.cs
Outdated
Show resolved
Hide resolved
...ies/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseHeaderMap.cs
Show resolved
Hide resolved
...ies/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseHeaderMap.cs
Outdated
Show resolved
Hide resolved
...ies/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseHeaderMap.cs
Outdated
Show resolved
Hide resolved
...ies/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseHeaderMap.cs
Outdated
Show resolved
Hide resolved
...s/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseHeaderValue.cs
Show resolved
Hide resolved
...s/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseHeaderValue.cs
Outdated
Show resolved
Hide resolved
if (signaturesLength.GetValueOrDefault() < 1) | ||
{ | ||
throw new CryptographicException(SR.Format(SR.DecodeErrorWhileDecoding, SR.MultiSignMessageMustCarryAtLeastOneSignature)); | ||
} |
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 exception doesn't make sense when there is at least one signature but it used an indefinite length array.
Assuming I recall correctly and that COSE forbids indefinite length arrays then there should be a check for !signaturesLength.HasValue, and a special throw, before this.
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.
(Repeat for basically every place that calls ReadStartArray)
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.
One thing to consider is making a struct wrapper over top of a CborReader (e.g. CoseCborReader) and have it enforce all of these policy things. E.g.
internal struct CoseCborReader
{
private CborReader _reader;
internal CoseCborReader(...)
{
...;
}
internal int ReadStartArray()
{
int? len;
try
{
len = _reader.ReadStartArray();
}
catch (CborContentException e)
{
...
}
if (!len.HasValue)
{
throw new CryptographicException(SR.CoseForbidsIndefiniteArray);
}
return len.GetValueOrDefault();
}
}
In core crypto I've done a similar thing. The AsnValueReader
type is a variant of AsnReader
, but it always wraps AsnContentException in a CryptographicException (because that's the exception type that the methods threw before we wrote AsnReader)
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.
From https://datatracker.ietf.org/doc/html/rfc8152#section-14, it seems to me that indefinite length is only forbidden for Sig_Structure, the text on that section probably also means that we should use a CborWriter with Canonical conformance mode on CreateToBeSigned.
I can fix the exception messages stating that indefinite-length arrays are forbidden as part of this PR but I would prefer a separate PR to address/validate support of messages using indefinite length arrays, what do you think?
I can't find anything right now stating that indefinite length arrays are forbidden, so for example, can you receive a COSE_Sign message inside a indefinite-length array?
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 indefinite length arrays are already inconsistently supported and you'd have to touch currently untouched code to fix it up, then a separate PR makes more sense. If everything that would have to be changed is in this PR already, then we shouldn't merge code we know is wrong.
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.
The current state of the code is the former, an example is CoseMessage.DecodeSign1, it requires a CBOR array of length 4 to successfully decode.
...aries/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseMessage.cs
Outdated
Show resolved
Hide resolved
...aries/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseMessage.cs
Outdated
Show resolved
Hide resolved
...aries/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseMessage.cs
Outdated
Show resolved
Hide resolved
...tem.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseMultiSignMessage.cs
Show resolved
Hide resolved
...tem.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseMultiSignMessage.cs
Outdated
Show resolved
Hide resolved
...tem.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseMultiSignMessage.cs
Outdated
Show resolved
Hide resolved
...tem.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseMultiSignMessage.cs
Outdated
Show resolved
Hide resolved
.../System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseSign1Message.cs
Outdated
Show resolved
Hide resolved
...ies/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseSignature.cs
Outdated
Show resolved
Hide resolved
throw new ArgumentNullException(nameof(key)); | ||
|
||
if (key is RSA) | ||
throw new CryptographicException(SR.CoseSignerRSAKeyNeedsPadding); |
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.
throw new CryptographicException(SR.CoseSignerRSAKeyNeedsPadding); | |
throw new ArgumentException(SR.CoseSignerRSAKeyNeedsPadding, nameof(key)); |
src/libraries/System.Security.Cryptography.Cose/tests/CoseHeaderMapTests.cs
Show resolved
Hide resolved
src/libraries/System.Security.Cryptography.Cose/tests/CoseHeaderMapTests.cs
Outdated
Show resolved
Hide resolved
map.TryGetValue(label, out CoseHeaderValue value); | ||
return value.EncodedValue.ToArray(); |
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.
map.TryGetValue(label, out CoseHeaderValue value); | |
return value.EncodedValue.ToArray(); | |
bool found = map.TryGetValue(label, out CoseHeaderValue value); | |
Assert.True(found, "TryGetValue on a known value"); | |
return value.EncodedValue.ToArray(); |
It also addresses all bullets on Checkpoint MVP+2 #62600.
Fixes #62599.
Fixes #69896.
Fixes #70189 (5fb06cc).