Skip to content

Commit

Permalink
Test vectors for proposed Branca attack
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbrady91 committed Aug 24, 2020
1 parent d3833ea commit b935fd8
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Security.Cryptography;
using FluentAssertions;
using Microsoft.IdentityModel.Tokens;
using ScottBrady.IdentityModel.Tokens;
Expand Down Expand Up @@ -95,5 +96,17 @@ public void ValidateToken_TestTokenWithWrongVersion()

exception.Message.Should().Be("Unsupported Branca version");
}

[Fact]
public void ValidateToken_CiphertextModification_ExpectSecurityTokenException()
{
var handler = new BrancaTokenHandler();

var token = handler.CreateToken("test", key);
var decoded = Base62.Decode(token);
decoded[decoded.Length - 17] ^= 1; // Last byte before the Poly1305 tag

Assert.Throws<CryptographicException>(() => handler.DecryptToken(Base62.Encode(decoded), key));
}
}
}

0 comments on commit b935fd8

Please sign in to comment.