Skip to content

Commit

Permalink
update cose handler
Browse files Browse the repository at this point in the history
  • Loading branch information
elantiguamsft committed Nov 8, 2023
1 parent 9a611cc commit 445ce9a
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions CoseHandler/CoseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -585,20 +585,41 @@ internal static ValidationResult ValidateInternal(
bool messageVerified = false;
try
{
if (!payloadBytes.IsNullOrEmpty())
{
// Detached payload received as byte array
messageVerified = msg.VerifyDetached(publicKey, new ReadOnlySpan<byte>(payloadBytes));
}
else if (payloadStream is not null)
{
// Detached payload received as a stream
messageVerified = Task.Run(() => msg.VerifyDetachedAsync(publicKey, payloadStream)).GetAwaiter().GetResult();
// If there is nothing in the content header, this should be treated as a detached signature
if (msg.Content is null) {
if (!payloadBytes.IsNullOrEmpty())

Check warning

Code scanning / CodeQL

Dereferenced variable may be null Warning

Variable
payloadBytes
may be null at this access because of
this
null argument.
Variable
payloadBytes
may be null at this access because of
this
null argument.
Variable
payloadBytes
may be null at this access because of
this
null argument.
{
// Detached payload received as byte array
messageVerified = msg.VerifyDetached(publicKey, new ReadOnlySpan<byte>(payloadBytes));
}
else if (payloadStream is not null)
{
// Detached payload received as a stream
messageVerified = Task.Run(() => msg.VerifyDetachedAsync(publicKey, payloadStream)).GetAwaiter().GetResult();
}
}
else
{
// Embedded payload
messageVerified = msg.VerifyEmbedded(publicKey);

// If the embedded content represents the hash of the file (i.e. IsDetachedSignature() is true),
// then we also need to make sure that the actual payload hash matches the content in the embedded message
if (messageVerified && msg.IsDetachedSignature())
{
if (!payloadBytes.IsNullOrEmpty())

Check warning

Code scanning / CodeQL

Dereferenced variable may be null Warning

Variable
payloadBytes
may be null at this access because of
this
null argument.
Variable
payloadBytes
may be null at this access because of
this
null argument.
Variable
payloadBytes
may be null at this access because of
this
null argument.
{
messageVerified = msg.SignatureMatches(payloadBytes);
}
else if (payloadStream is not null)
{
messageVerified = msg.SignatureMatches(payloadStream);
}
else
{
messageVerified = false;
}
}
}

if (!messageVerified)
Expand Down

0 comments on commit 445ce9a

Please sign in to comment.