Skip to content

Commit

Permalink
Throw error if signed message invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
mattosaurus committed Jul 11, 2022
1 parent f9f4721 commit ba48b2d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 46 deletions.
1 change: 0 additions & 1 deletion PgpCore.Tests/UnitTests/UnitTestsAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,6 @@ public async Task VerifyAsync_DoNotVerifySignedFileWithBadContent(KeyType keyTyp

// Assert
var ex = await Assert.ThrowsAsync<IOException>(action);
Assert.Equal("invalid armor", ex.Message);

// Teardown
testFactory.Teardown();
Expand Down
1 change: 0 additions & 1 deletion PgpCore.Tests/UnitTests/UnitTestsSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,6 @@ public void Verify_DoNotVerifySignedFileWithBadContent(KeyType keyType)

// Assert
var ex = Assert.Throws<IOException>(action);
Assert.Equal("invalid armor", ex.Message);

// Teardown
testFactory.Teardown();
Expand Down
65 changes: 21 additions & 44 deletions PgpCore/PGP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5480,7 +5480,6 @@ private Task<bool> VerifyAsync(Stream inputStream)
PgpLiteralData pgpLiteralData = (PgpLiteralData)factory.NextPgpObject();
Stream pgpLiteralStream = pgpLiteralData.GetInputStream();


// Verify against public key ID and that of any sub keys
var keyIdToVerify = pgpOnePassSignature.KeyId;
if (Utilities.FindPublicKey(keyIdToVerify, EncryptionKeys.VerificationKeys,
Expand All @@ -5494,25 +5493,18 @@ private Task<bool> VerifyAsync(Stream inputStream)
pgpOnePassSignature.Update((byte)ch);
}

try
PgpSignatureList pgpSignatureList = (PgpSignatureList)factory.NextPgpObject();

for (int i = 0; i < pgpSignatureList.Count; i++)
{
PgpSignatureList pgpSignatureList = (PgpSignatureList)factory.NextPgpObject();
PgpSignature pgpSignature = pgpSignatureList[i];

for (int i = 0; i < pgpSignatureList.Count; i++)
if (pgpOnePassSignature.Verify(pgpSignature))
{
PgpSignature pgpSignature = pgpSignatureList[i];

if (pgpOnePassSignature.Verify(pgpSignature))
{
verified = true;
break;
}
verified = true;
break;
}
}
catch
{
verified = false;
}
}
}
else if (pgpObject is PgpSignatureList signatureList)
Expand Down Expand Up @@ -5591,26 +5583,18 @@ private bool Verify(Stream inputStream)
pgpOnePassSignature.Update((byte)ch);
}

try
PgpSignatureList pgpSignatureList = (PgpSignatureList)factory.NextPgpObject();

for (int i = 0; i < pgpSignatureList.Count; i++)
{
PgpSignatureList pgpSignatureList = (PgpSignatureList)factory.NextPgpObject();
PgpSignature pgpSignature = pgpSignatureList[i];

for (int i = 0; i < pgpSignatureList.Count; i++)
if (pgpOnePassSignature.Verify(pgpSignature))
{
PgpSignature pgpSignature = pgpSignatureList[i];

if (pgpOnePassSignature.Verify(pgpSignature))
{
verified = true;
break;
}
verified = true;
break;
}
}
catch
{
verified = false;
break;
}
}
else
{
Expand Down Expand Up @@ -5650,25 +5634,18 @@ private bool Verify(Stream inputStream)
pgpOnePassSignature.Update((byte)ch);
}

try
PgpSignatureList pgpSignatureList = (PgpSignatureList)factory.NextPgpObject();

for (int i = 0; i < pgpSignatureList.Count; i++)
{
PgpSignatureList pgpSignatureList = (PgpSignatureList)factory.NextPgpObject();
PgpSignature pgpSignature = pgpSignatureList[i];

for (int i = 0; i < pgpSignatureList.Count; i++)
if (pgpOnePassSignature.Verify(pgpSignature))
{
PgpSignature pgpSignature = pgpSignatureList[i];

if (pgpOnePassSignature.Verify(pgpSignature))
{
verified = true;
break;
}
verified = true;
break;
}
}
catch
{
verified = false;
}
}
}
else if (pgpObject is PgpSignatureList signatureList)
Expand Down

0 comments on commit ba48b2d

Please sign in to comment.