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

Fixed tests, build on Arch Linux #416

Merged
merged 4 commits into from
Jun 20, 2022

Conversation

hartmark
Copy link
Contributor

Will probably be needed for #407

Unless this fix is applied the tests fail with this error when running on arch linux:

Test method JWT.Tests.Algorithms.RSAlgorithmTests.Ctor_Should_Throw_Exception_When_PrivateKey_Is_Null threw exception: 
AutoFixture.ObjectCreationExceptionWithPath: AutoFixture was unable to create an instance from System.Security.Cryptography.RSACryptoServiceProvider because creation unexpectedly failed with exception. Please refer to the inner exception to investigate the root cause of the failure.

Request path:
	System.Security.Cryptography.RSACryptoServiceProvider

Inner exception messages:
	System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
	  System.Security.Cryptography.CryptographicException: Specified key is not a valid size for this algorithm.

 ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Security.Cryptography.CryptographicException: Specified key is not a valid size for this algorithm.
    at System.Security.Cryptography.AsymmetricAlgorithm.set_KeySize(Int32 value)
   at System.Security.Cryptography.RSAImplementation.RSAOpenSsl.set_KeySize(Int32 value)
   at System.Security.Cryptography.RSACryptoServiceProvider.set_KeySize(Int32 value)
--- End of inner exception stack trace ---
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.InvokeOneParameter(Object obj, BindingFlags invokeAttr, Binder binder, Object parameter, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
   at AutoFixture.Kernel.AutoPropertiesCommand`1.Execute(Object specimen, ISpecimenContext context)
   at AutoFixture.Kernel.Postprocessor`1.Create(Object request, ISpecimenContext context)
   at AutoFixture.AutoPropertiesTarget.Create(Object request, ISpecimenContext context)
   at AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context)
   at AutoFixture.Kernel.TerminatingWithPathSpecimenBuilder.Create(Object request, ISpecimenContext context)
--- End of inner exception stack trace ---
    at AutoFixture.Kernel.TerminatingWithPathSpecimenBuilder.Create(Object request, ISpecimenContext context)
   at AutoFixture.BehaviorRoot.Create(Object request, ISpecimenContext context)
   at AutoFixture.Kernel.RecursionGuard.Create(Object request, ISpecimenContext context)
   at AutoFixture.Fixture.Create(Object request, ISpecimenContext context)
   at AutoFixture.Kernel.SpecimenContext.Resolve(Object request)
   at AutoFixture.Kernel.SeedIgnoringRelay.Create(Object request, ISpecimenContext context)
   at AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context)
   at AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context)
   at AutoFixture.Kernel.Postprocessor`1.Create(Object request, ISpecimenContext context)
   at AutoFixture.AutoPropertiesTarget.Create(Object request, ISpecimenContext context)
   at AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context)
   at AutoFixture.Kernel.TerminatingWithPathSpecimenBuilder.Create(Object request, ISpecimenContext context)
   at AutoFixture.BehaviorRoot.Create(Object request, ISpecimenContext context)
   at AutoFixture.Kernel.RecursionGuard.Create(Object request, ISpecimenContext context)
   at AutoFixture.Fixture.Create(Object request, ISpecimenContext context)
   at AutoFixture.Kernel.SpecimenContext.Resolve(Object request)
   at AutoFixture.SpecimenFactory.Create[T](ISpecimenContext context)
   at AutoFixture.SpecimenFactory.Create[T](ISpecimenBuilder builder)
   at JWT.Tests.Algorithms.RSAlgorithmTests.get_RSACryptoServiceProvider() in /home/markus/code/jwt/tests/JWT.Tests.Common/Algorithms/RSAlgorithmTests.cs:line 21
   at JWT.Tests.Algorithms.RSAlgorithmTests.Ctor_Should_Throw_Exception_When_PrivateKey_Is_Null(Func`3 algFactory) in /home/markus/code/jwt/tests/JWT.Tests.Common/Algorithms/RSAlgorithmTests.cs:line 41

@abatishchev
Copy link
Member

Can you help me understand, if you know, the cause for the issue?

System.Security.Cryptography.CryptographicException: Specified key is not a valid size for this algorithm.

Why? I mean is there a size that is valid for this algorithm? Should it be smaller (idk if it can be) or larger (shall we try)?

@abatishchev
Copy link
Member

Looks like the provided secret is too short indeed. It must be 128 bit long, or 256 etx. I don't know why it works on other platforms though, maybe they're aren't that reactive/picky.

@hartmark
Copy link
Contributor Author

I haven't used AutoFixture so I have no idea how to set the key size

@abatishchev abatishchev changed the title Harre/linux build fix Fixed tests, build on Arch Linux Jun 18, 2022
@abatishchev
Copy link
Member

Right, the issue is in AutoFixture that instantiates RSACryptoServiceProvider with a key length or doesn't like.

If just new RSACryptoServiceProvider() works on .NET 6, doesn't it work elsewhere too?

@hartmark
Copy link
Contributor Author

I was conservative with the changes as it was already running on Linux for versions below .net6

I can try change it so all get same behaviour instead if it works

@hartmark hartmark force-pushed the harre/linux-build-fix branch from 830584b to f379952 Compare June 20, 2022 22:22
@hartmark
Copy link
Contributor Author

It seems that just newing up RSACryptoServiceProvider is working for all .net versions so I have updated the code.

abatishchev
abatishchev previously approved these changes Jun 20, 2022
@abatishchev
Copy link
Member

I approved. Please see if you can check it in after the gated build has succeeded.

@hartmark
Copy link
Contributor Author

Should be alright now :)

@abatishchev abatishchev merged commit 69b27fc into jwt-dotnet:main Jun 20, 2022
@abatishchev
Copy link
Member

Thank you, sir!

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

Successfully merging this pull request may close these issues.

2 participants