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

Modify RS256Algorithm to use RSA from cert directly #127

Merged
merged 14 commits into from
Jul 24, 2017
Merged

Conversation

abatishchev
Copy link
Member

@abatishchev abatishchev commented Jul 14, 2017

Resolves #124, closes #118.

Drawback:

  • class RSA doesn't have method SignData in .NET 3.5, so I upgraded to .NET 4.6.2

@abatishchev abatishchev added this to the 3.0 milestone Jul 14, 2017
@abatishchev abatishchev self-assigned this Jul 14, 2017
@abatishchev
Copy link
Member Author

@nbarbettini can you please check whether I upgraded target framework properly? I'm asking because AppVeyor fails

@abatishchev abatishchev requested a review from nbarbettini July 14, 2017 19:29
@abatishchev
Copy link
Member Author

@StefH can you please help with test, and what's more important with proper unit testing?

@StefH
Copy link

StefH commented Jul 15, 2017

0]
I did also add some code-review comments...

Testing can be done like:

1] Generate certificate and private key

openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout private.key -out certificate_pub.crt

2]
Make a X509 certificate based on the two file above (https://github.com/StefH/JwtTest/blob/master/JwtTest/CertificateFromFileProvider.cs)

3]
Generate a token based on RS256 using your old (current) and new (this PR) RS256Algorithm.

4]
Copy paste this token in Encoded field on https://jwt.io/

5]
Copy paste your public certificate key (certificate_pub.crt) into that VERIFY SIGNATURE block (first block) only.

6]
When you get a blue box beneath saying signature verified then the JWT is valid.

@@ -3,10 +3,9 @@
<PropertyGroup>
<TargetFrameworks>net35;netstandard1.3</TargetFrameworks>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line needs to be net462;netstandard1.3

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks!

<FrameworkPathOverride>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client</FrameworkPathOverride>
<PropertyGroup Condition="'$(TargetFramework)' == 'net462'">
<TargetFramework>net462</TargetFramework>
<DefineConstants>NET46</DefineConstants>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any #if directives that look for either NET35 or NET46?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, only 1 places (this file) that looks for NET_STANDARD. Good point thought!

Adding netstandard1.3 back
@abatishchev
Copy link
Member Author

@ubercow sorry, it took some time to come back to the issue you're opened. Can you please take a look on this project? Should be same.

@abatishchev
Copy link
Member Author

@StefH right but I meant some input how to update existing/add new unit test(s). Can you please help here?

@abatishchev
Copy link
Member Author

abatishchev commented Jul 18, 2017

AppVeyor can't build anything:

Could not find Cake.exe at C:\projects\jwt\tools\Cake\Cake.exe

I question its stability :(

@nbarbettini
Copy link
Contributor

AppVeyor can't build anything

That doesn't seem like a typical error - can you try restarting the build?

@abatishchev
Copy link
Member Author

It fails with same error for a while now: https://ci.appveyor.com/project/abatishchev/jwt/history

#if NETSTANDARD1_3
var rsa = (RSACryptoServiceProvider)_cert.GetRSAPrivateKey();
return (RSA)cert.GetRSAPrivateKey();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why casting to RSA ? This is not needed ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, thanks!

<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
<DefineConstants>NET35</DefineConstants>
<FrameworkPathOverride>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client</FrameworkPathOverride>
<PropertyGroup Condition="'$(TargetFramework)' == 'net462'">
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is not used because you only define <TargetFrameworks>net35;netstandard1.3</TargetFrameworks>.

So just revert back this change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I want to upgrade to net462. What would be the right way to do that?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just add net462 like:
<TargetFrameworks>net35;net462;netstandard1.3</TargetFrameworks>.

But this is not needed because the net35 can be used by all frameworks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently it's this:

<TargetFrameworks>net462;netstandard1.3</TargetFrameworks>

Isn't this correct?

@StefH
Copy link

StefH commented Jul 19, 2017

@abatishchev
About unit-tests : you don't really need to test all rsa encryption code. Just use Moq to mock some calls.

@abatishchev
Copy link
Member Author

Usually we test end-to-end by having hard-coded JWT and asserting expected outcome

@StefH
Copy link

StefH commented Jul 19, 2017

If the build works fine, and all code is merged to master branch, I will take a quick look how to do unit test.

@abatishchev
Copy link
Member Author

@nbarbettini please take a look to the latest changes

@nbarbettini
Copy link
Contributor

I'm not super familiar with the RSACryptoServiceProvider stuff, but it looks reasonable.

Are you intending to raise the minimum framework version to .NET 4.6.2?

@abatishchev
Copy link
Member Author

Yeah, I'm not either :) Hope it works, and now works better.

Yes, to normalize the code between .NetFramework and .Net Core. Hope everybody will be fine with that too.

@abatishchev abatishchev merged commit c7a7145 into master Jul 24, 2017
@StefH
Copy link

StefH commented Jul 25, 2017

If possible, can you lower the dependency for 4.6.2?

Can you lower this to .net 4.0? In that way your librabry can also be used by .net 4 and .net 4.5 libraries/programs.

@abatishchev abatishchev deleted the fix-rs-256-1 branch July 25, 2017 17:26
@abatishchev
Copy link
Member Author

Let's continue in #130. Can you please describe your scenario/environment/requirements? The thing from my perspective is that 4.6.2 is the lowest supported as of today version, all lower are out of support. And transition from 4.0 to 4.5. would be long due, and from 4.5 to 4.6.2 usually is seamless. But again I'd love to understand your perspective.

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.

Bug : RS256Algorithm is incorrectly ?
3 participants