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

S.S.C.Cose: Add new MultiSign APIs and address API review feedback on existing ones #71390

Merged
merged 9 commits into from
Jul 7, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<IncludePlatformAttributes>true</IncludePlatformAttributes>
<UnsupportedOSPlatforms>browser</UnsupportedOSPlatforms>
</PropertyGroup>
</Project>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Argument_EncodeDestinationTooSmall" xml:space="preserve">
<value>The destination is too small to hold the encoded value.</value>
</data>
<data name="ContentWasDetached" xml:space="preserve">
<value>Content was not included in the message (detached message), provide a content to verify.</value>
</data>
<data name="ContentWasEmbedded" xml:space="preserve">
<value>Content was included in the message (embedded message) and yet another content was provided for verification.</value>
</data>
<data name="CoseHeaderMapArgumentCoseHeaderValueIncorrect" xml:space="preserve">
<value>Not a valid CBOR encoded value on CoseHeaderValue on header '{0}', see inner exception for details.</value>
</data>
<data name="CoseHeaderMapCborEncodedValueNotValid" xml:space="preserve">
<value>Not a valid CBOR encoded value, it must be a single value with no trailing data.</value>
</data>
Expand All @@ -126,21 +138,39 @@
<data name="CoseHeaderMapHeaderDoesNotAcceptSpecifiedValue" xml:space="preserve">
<value>Header '{0}' does not accept the specified value.</value>
</data>
<data name="CoseHeaderMapLabelDoeNotExist" xml:space="preserve">
<value>Label '{0}' does not exist is the map.</value>
<data name="CoseHeaderValueErrorWhileDecoding" xml:space="preserve">
<value>Error while decoding CBOR encoded value, see inner exception for details.</value>
</data>
<data name="DecodeSign1ArrayLengthMustBeFour" xml:space="preserve">
<value>Array length for COSE_Sign1 must be four.</value>
<data name="CoseSignerRSAKeyNeedsPadding" xml:space="preserve">
<value>RSA key needs a signature padding.</value>
</data>
<data name="DecodeSign1EncodedProtectedMapIncorrect" xml:space="preserve">
<value>Protected map was incorrect.</value>
<data name="CriticalHeaderMissing" xml:space="preserve">
<value>Critical Header '{0}' missing from protected map.</value>
</data>
<data name="CriticalHeadersLabelWasIncorrect" xml:space="preserve">
<value>Label in Critical Headers array was incorrect.</value>
</data>
<data name="DecodeSign1ErrorWhileDecoding" xml:space="preserve">
<data name="CriticalHeadersMustBeArrayOfAtLeastOne" xml:space="preserve">
<value>Critical Headers must be a definite-length CBOR array of at least one element.</value>
</data>
<data name="DecodeCoseSignatureMustBeArrayOfThree" xml:space="preserve">
<value>COSE Signature must be a definite-length array of 3 elements.</value>
</data>
<data name="DecodeErrorWhileDecoding" xml:space="preserve">
<value>Error while decoding COSE message. {0}</value>
</data>
<data name="DecodeSign1ErrorWhileDecodingSeeInnerEx" xml:space="preserve">
<data name="DecodeErrorWhileDecodingSeeInnerEx" xml:space="preserve">
<value>Error while decoding COSE message. See the inner exception for details.</value>
</data>
<data name="DecodeMultiSignIncorrectTag" xml:space="preserve">
<value>Incorrect tag. Expected Sign(98) or Untagged, Actual '{0}'.</value>
</data>
<data name="DecodeSign1ArrayLengthMustBeFour" xml:space="preserve">
<value>Array length for COSE_Sign1 must be four.</value>
</data>
<data name="DecodeSign1EncodedProtectedMapIncorrect" xml:space="preserve">
<value>Protected map was incorrect.</value>
</data>
<data name="DecodeSign1IncorrectTag" xml:space="preserve">
<value>Incorrect tag. Expected Sign1(18) or Untagged, Actual '{0}'.</value>
</data>
Expand All @@ -153,6 +183,9 @@
<data name="DecodeSign1PayloadWasIncorrect" xml:space="preserve">
<value>Payload was incorrect.</value>
</data>
<data name="MultiSignMessageMustCarryAtLeastOneSignature" xml:space="preserve">
<value>COSE Sign message must carry at least one signature.</value>
</data>
<data name="Sign1AlgDoesNotMatchWithTheOnesSupportedByTypeOfKey" xml:space="preserve">
<value>COSE algorithm '{0}' doesn't match with the supported algorithms of '{1}'.</value>
</data>
Expand All @@ -168,6 +201,9 @@
<data name="Sign1SignCoseAlgorithDoesNotMatchSpecifiedKeyAndHashAlgorithm" xml:space="preserve">
<value>COSE Algorithm '{0}' doesn't match with the specified Key '{1}' and Hash Algorithm '{2}'.</value>
</data>
<data name="Sign1SignCoseAlgorithDoesNotMatchSpecifiedKeyHashAlgorithmAndPadding" xml:space="preserve">
<value>COSE Algorithm '{0}' doesn't match with the specified Key '{1}', Hash Algorithm '{2}', and Signature Padding {3}.</value>
</data>
<data name="Sign1SignHeaderDuplicateLabels" xml:space="preserve">
<value>Protected and Unprotected buckets must not contain duplicate labels.</value>
</data>
Expand All @@ -186,16 +222,4 @@
<data name="Sign1VerifyAlgIsRequired" xml:space="preserve">
<value>Algorithm (alg) header is required and it must be a protected header.</value>
</data>
<data name="Sign1VerifyAlgorithmHeaderParameterWasMissing" xml:space="preserve">
<value>Algorithm (alg) header parameter was missing.</value>
</data>
<data name="Sign1VerifyContentWasDetached" xml:space="preserve">
<value>Content was not included in the message (detached message), provide a content to verify.</value>
</data>
<data name="Sign1VerifyContentWasEmbedded" xml:space="preserve">
<value>Content was included in the message (embedded message) and yet another content was provided for verification.</value>
</data>
<data name="Sign1VerifyCriticalAndCounterSignNotSupported" xml:space="preserve">
<value>Critical and Counter Signature headers are currently not supported.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@
<Compile Include="$(LibrariesProjectRoot)System.Formats.Cbor\src\System\Formats\Cbor\CborInitialByte.cs" Link="System\Formats\Cbor\CborInitialByte.cs" />
<Compile Include="System\Security\Cryptography\Cose\CoseHeaderLabel.cs" />
<Compile Include="System\Security\Cryptography\Cose\CoseHeaderMap.cs" />
<Compile Include="System\Security\Cryptography\Cose\CoseHeaderValue.cs" />
<Compile Include="System\Security\Cryptography\Cose\CoseHelpers.cs" />
<Compile Include="System\Security\Cryptography\Cose\CoseMessage.cs" />
<Compile Include="System\Security\Cryptography\Cose\CoseMultiSignMessage.cs" />
<Compile Include="System\Security\Cryptography\Cose\CoseSign1Message.cs" />
<Compile Include="System\Security\Cryptography\Cose\CoseSignature.cs" />
<Compile Include="System\Security\Cryptography\Cose\CoseSigner.cs" />
<Compile Include="System\Security\Cryptography\Cose\KeyType.cs" />
<Compile Include="System\Security\Cryptography\Cose\KnownCoseAlgorithms.cs" />
<Compile Include="System\Security\Cryptography\Cose\KnownHeaders.cs" />
<Compile Include="System\Security\Cryptography\Cose\SigStructureContext.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ namespace System.Security.Cryptography.Cose
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public readonly struct CoseHeaderLabel : IEquatable<CoseHeaderLabel>
{
internal string LabelName => LabelAsString ?? LabelAsInt32.ToString();
internal string LabelName => LabelAsString != null ? $"\"{LabelAsString}\"" : LabelAsInt32.ToString();
private string DebuggerDisplay => $"Label = {LabelName}, Type = {(LabelAsString != null ? typeof(string) : typeof(int))}";

// https://www.iana.org/assignments/cose/cose.xhtml#header-parameters
public static CoseHeaderLabel Algorithm => new CoseHeaderLabel(KnownHeaders.Alg);
public static CoseHeaderLabel Critical => new CoseHeaderLabel(KnownHeaders.Crit);
public static CoseHeaderLabel CriticalHeaders => new CoseHeaderLabel(KnownHeaders.Crit);
public static CoseHeaderLabel ContentType => new CoseHeaderLabel(KnownHeaders.ContentType);
public static CoseHeaderLabel KeyIdentifier => new CoseHeaderLabel(KnownHeaders.Kid);
public static CoseHeaderLabel IV => new CoseHeaderLabel(KnownHeaders.IV);
public static CoseHeaderLabel PartialIV => new CoseHeaderLabel(KnownHeaders.PartialIV);
public static CoseHeaderLabel CounterSignature => new CoseHeaderLabel(KnownHeaders.CounterSignature);

internal int LabelAsInt32 { get; }
internal string? LabelAsString { get; }
Expand Down
Loading