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

AssertValidLicense throws exceptions against invalid public keys #22

Open
makcakaya opened this issue May 11, 2015 · 1 comment
Open

Comments

@makcakaya
Copy link

Following unit tests show AssertValidLicense method throwing exceptions when invalid public keys are given. Types of exceptions change depending on the given public key string.

I can add tests to the project to ensure the method does not throw when given unexpected parameters, if it fits the goals.

Exceptions are commented in the code:

        [Fact]
        public void ShouldNotThrow()
        {
            var passPhrase = "TopSecret";
            var generator = KeyGenerator.Create();
            var pair = generator.GenerateKeyPair();
            var privateKey = pair.ToEncryptedPrivateKeyString(passPhrase);
            var publicKey = pair.ToPublicKeyString();

            var license = License.New().CreateAndSignWithPrivateKey(privateKey, passPhrase);
            var errors = license.Validate().Signature("invalidKey").AssertValidLicense();
            Assert.True(!errors.Any());

            //ShouldNotThrow' failed: System.FormatException : Invalid length for a Base-64 char array or string.
            //    at System.Convert.FromBase64_Decode(Char* startInputPtr, Int32 inputLength, Byte* startDestPtr, Int32 destLength)
            //    at System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength)
            //    at System.Convert.FromBase64String(String s)
            //    at Portable.Licensing.License.VerifySignature(String publicKey)
            //    at Portable.Licensing.Validation.LicenseValidationExtensions.<>c__DisplayClassd.<Signature>b__c(License license)
            //    at Portable.Licensing.Validation.ValidationChainBuilder.<AssertValidLicense>d__1.MoveNext()
            //    at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
            //    LicenseClientTests.cs(96,0): at Biltera.Licensing.Client.Tests.LicenseClientTests.ShouldNotThrow()

            //0 passed, 1 failed, 0 skipped, took 1,11 seconds (xUnit.net 2.0.0 build 2929).
        }

        [Fact]
        public void ShouldNotThrow2()
        {
            var passPhrase = "TopSecret";
            var generator = KeyGenerator.Create();
            var pair = generator.GenerateKeyPair();
            var privateKey = pair.ToEncryptedPrivateKeyString(passPhrase);
            var publicKey = pair.ToPublicKeyString();

            var license = License.New().CreateAndSignWithPrivateKey(privateKey, passPhrase);
            var errors = license.Validate().Signature("invalidPublicKey").AssertValidLicense();
            Assert.True(!errors.Any());

            //            ShouldNotThrow2' failed: System.IO.EndOfStreamException : DEF length 123 object truncated by 113
            //    at Org.BouncyCastle.Asn1.DefiniteLengthInputStream.ToArray()
            //    at Org.BouncyCastle.Asn1.Asn1StreamParser.ReadTaggedObject(Boolean constructed, Int32 tag)
            //    at Org.BouncyCastle.Asn1.Asn1InputStream.BuildObject(Int32 tag, Int32 tagNo, Int32 length)
            //    at Org.BouncyCastle.Asn1.Asn1InputStream.ReadObject()
            //    at Org.BouncyCastle.Asn1.Asn1Object.FromByteArray(Byte[] data)
            //    at Org.BouncyCastle.Security.PublicKeyFactory.CreateKey(Byte[] keyInfoData)
            //    at Portable.Licensing.License.VerifySignature(String publicKey)
            //    at Portable.Licensing.Validation.LicenseValidationExtensions.<>c__DisplayClassd.<Signature>b__c(License license)
            //    at Portable.Licensing.Validation.ValidationChainBuilder.<AssertValidLicense>d__1.MoveNext()
            //    at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
            //    LicenseClientTests.cs(122,0): at Biltera.Licensing.Client.Tests.LicenseClientTests.ShouldNotThrow2()

            //0 passed, 1 failed, 0 skipped, took 1,16 seconds (xUnit.net 2.0.0 build 2929).
        }
@dnauck
Copy link
Owner

dnauck commented May 18, 2015

Related to #21

We should just return false on invalid input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants