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

Lacking support for "smallrye.jwt.sign.key-location" smallrye jwt private key location support. #6781

Closed
patoessy opened this issue Jan 24, 2020 · 11 comments · Fixed by #6825
Assignees
Labels
kind/bug Something isn't working
Milestone

Comments

@patoessy
Copy link

JWT creation failing on Quarkus 1.2.0 using new smallrye jwt generation utility
Smallrye added a new configuration property to load private key for encryption. But in quarkus, its not been loaded.

Expected behavior
Load the private key specified by smallrye.jwt.sign.key-location config and be able to generate a jwt token

Actual behavior
An exception is thrown: io.smallrye.jwt.build.JwtSignatureException: Inner JWT can not be created, 'smallrye.jwt.sign.key-location' is not set but the 'alg' header is: RS256.

To Reproduce
Steps to reproduce the behavior:
Create a quarkus app with JWT RBAC claims, then try to generate a token using smallrye/smallrye-jwt#153

For example below code:
String jwt = Jwt.claims()
.claim("username", Collections.singletonMap("key", "value"))
.expiresAt(new Date().getTime() + 3600)
.groups("CUSTOMER")
.issuedAt(new Date().getTime())
.upn("[email protected]")
.audience("using-jwt-rbac")
.preferredUserName(username)
.subject("auth-noma-hapa")
.issuer("https://patopato/ghsdfgdhjsdg")
.jws()
.header("typ", "JWT")
.signatureKeyId("try-that-ui")
.signatureAlgorithm(SignatureAlgorithm.RS256)
.innerSign()
.encrypt();
System.out.println("This can work ... "+ jwt);

Environment (please complete the following information):

  • Output of uname -a or ver: Linux babanane 5.3.0-26-generic Merge our two divergent heads #28-Ubuntu SMP Wed Dec 18 05:37:46 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

  • Output of java -version:
    openjdk version "11.0.5" 2019-10-15
    OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.5+10)
    Eclipse OpenJ9 VM AdoptOpenJDK (build openj9-0.17.0, JRE 11 Linux amd64-64-Bit Compressed References 20191016_358 (JIT enabled, AOT enabled)
    OpenJ9 - 77c1cf708
    OMR - 20db4fbc
    JCL - 2a7af5674b based on jdk-11.0.5+10)

  • Quarkus version : 1.2.0.Final

@patoessy patoessy added the kind/bug Something isn't working label Jan 24, 2020
@patoessy patoessy changed the title Lack of "smallrye.jwt.sign.key-location" smallrye jwt private key location support. Lacking support for "smallrye.jwt.sign.key-location" smallrye jwt private key location support. Jan 24, 2020
@sberyozkin sberyozkin self-assigned this Jan 24, 2020
@sberyozkin
Copy link
Member

sberyozkin commented Jan 24, 2020

@patoessy thanks for giving it a try. Quick note, iat claim is set to the current time by default so unless you need to set something different you can omit it. Same for the typ header (JWT is default), and signatureAlgorithm (default is RS256).

Do you set this property in application.properties ? Hmm...In the smallrye-jwt tests I provide a test configuration source. Need to think...

@sberyozkin
Copy link
Member

For now, if you omit a signatureAlgorithm setter then it will work for innerSign() as you will end up with the none-signed inner JWT

@patoessy
Copy link
Author

patoessy commented Jan 25, 2020 via email

@patoessy
Copy link
Author

@patoessy thanks for giving it a try. Quick note, iat claim is set to the current time by default so unless you need to set something different you can omit it. Same for the typ header (JWT is default), and signatureAlgorithm (default is RS256).

Do you set this property in application.properties ? Hmm...In the smallrye-jwt tests I provide a test configuration source. Need to think...

Make it uniform by prefixing with quarkus- something like: [quarkus-smallrye.jwt.sign.key-location]=META-INF/resources/privateKey.pem
I'm novice but in near future I'd provide pull requests. Thanks

@sberyozkin
Copy link
Member

sberyozkin commented Jan 25, 2020

@patoessy thanks, but these are the properties which are meant to be recognized outside of Quarkus. Though having quarkus specific equivalents would make sense for all the smallrye-specific properties...

@sberyozkin
Copy link
Member

sberyozkin commented Jan 28, 2020

@patoessy I have opened #6825 which, once merged, will close this issue. It uses a no-argument sign method which innerSign() delegates to. I've also confirmed locally that if I try innerSign() and comment out smallrye.jwt.sign.key-location then the error you reported will be indeed reported.
May be there was a typo in the property name, can you check please ? You may also want to try it against the Quarkus master as some major class loading changes have gone in, and it may have fixed the issue you are seeing...Finally, if nothing works then please create a reproducer (and reopen this issue if it will be closed). thanks

@patoessy
Copy link
Author

Hello @sberyozkin , today it worked. I don't know how. But I recently discoved I was using 1.2.0.RC1 which hard the fuature already merged. Lemme test with encrypting the JWT token. Thanks. I have looked at #6825 and its really impressive.

@patoessy
Copy link
Author

Guide me on how to update the documentation maybe I can try and contribute on that too.

@sberyozkin
Copy link
Member

sberyozkin commented Jan 28, 2020

@patoessy Hi, thanks for already trying this API, and no problems, it is good to have it checked as part of the Quarkus build anyway.
Re the docs, right now it is in the design verification phase, I'm doing some more fixes in the smalrye-jwt library, we may also prepare a submission around it, so I'd like it to be as clean as possible before documenting it for Quarkus users. I can prepare some initial doc for 1.3.0 after another smalrye-jwt update and will CC you to review so that you could follow up with the improvements etc. Cheers

@patoessy
Copy link
Author

Cheer @sberyozkin. Thanks

@sberyozkin
Copy link
Member

@patoessy re the documentation in general, the current smallrye-jwt guide is here.

@gsmet gsmet added this to the 1.3.0.Alpha1 milestone Feb 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants