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

feat(jans-auth-server): extending crypto support sub pr4 #670

Merged
merged 15 commits into from
Jan 26, 2022

Conversation

smansoft
Copy link
Contributor

No description provided.

@smansoft smansoft added the comp-jans-auth-server Component affected by issue or PR label Jan 22, 2022
Copy link
Contributor

@yuriyz yuriyz left a comment

Choose a reason for hiding this comment

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

Please check inlined comments

@@ -90,13 +142,17 @@ public JSONArray toJSONArray() throws JSONException {
public String toString() {
try {
StringWriter stringWriter = new StringWriter();
try (JcaPEMWriter pemWriter = new JcaPEMWriter(stringWriter)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

try-resource statement looks better, is there any reason with replacing it with manual close()?

default: {
throw new SignatureException(String.format("Wrong type of the signature algorithm (SignatureAlgorithm): %s", signatureAlgorithm.toString()));
}
switch(signatureAlgorithm) {
Copy link
Contributor

Choose a reason for hiding this comment

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

formatting

* @author Sergey Manoylo
* @version January 20, 2021
*/
public class EDDSASigner extends AbstractJwsSigner {
Copy link
Contributor

Choose a reason for hiding this comment

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

EDDSASigner class is present but I don't see any usage of these class in entire PR. Maybe add test to see it in action.

Copy link
Contributor Author

@smansoft smansoft Jan 25, 2022

Choose a reason for hiding this comment

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

We have tests for EDDSASigner, of course (in
the branch jans-auth-server-extending-crypto-support-full).
for example:

https://github.com/JanssenProject/jans/blob/jans-auth-server-extending-crypto-support-full/jans-auth-server/server/src/test/java/io/jans/as/server/comp/SignatureTest.java

https://github.com/JanssenProject/jans/blob/jans-auth-server-extending-crypto-support-full/jans-auth-server/server/src/test/java/io/jans/as/server/comp/JwtCrossCheckTest.java
.

This branch:
jans-auth-server-extending-crypto-support-full
contains fixed working (PASSED) tests in the JwtCrossCheckTest (where checking signings oxAuth <-> Nimbus is provided).

In the branch: jans-auth-server-extending-crypto-support-full
class EDDSASigner is used in the
package io.jans.as.server.bcauthorize.ws.rs.BackchannelAuthorizeRestWebServiceImpl

            boolean validSignature = false;
            JwsSigner jwsSigner = null;

            switch(algorithm.getFamily()) {
                case RSA: {
                    RSAPublicKey publicKey = JwkClient.getRSAPublicKey(client.getJwksUri(), keyId);
                    jwsSigner = new RSASigner(algorithm, publicKey);
                    break;
                }
                case EC: {
                    ECDSAPublicKey publicKey = JwkClient.getECDSAPublicKey(client.getJwksUri(), keyId);
                    jwsSigner = new ECDSASigner(algorithm, publicKey);
                    break;
                }
                case ED: {
                    EDDSAPublicKey publicKey = JwkClient.getEDDSAPublicKey(client.getJwksUri(), keyId);
                    jwsSigner = new EDDSASigner(algorithm, publicKey);
                    break;
                }
                default: {
                    break;
                }
            }

            if(jwsSigner != null) {
                validSignature = jwsSigner.validate(jwt);
            }

together with (ECDSASigner, RSASigner).

I can move these changes in this PR, NP, but also I need to change the JwkClient class,
as this is a new function: JwkClient.getEDDSAPublicKey.

Also EDDSASigner is used by the JwtVerifier class (in the branch: jans-auth-server-extending-crypto-support-full).
There are unit tests for JwtVerifier too:

https://github.com/JanssenProject/jans/blob/jans-auth-server-extending-crypto-support-full/jans-auth-server/server/src/test/java/io/jans/as/server/comp/JwtSignerVerifyerTest.java

I hope, all this code will be moved to the main in next PRs.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, ok, lets get this PR first and in next PR test for it. Not ideal but we have to move forward somehow.

X509EncodedKeySpec publicKeySpec = eddsaPublicKey.getPublicKeySpec();
java.security.KeyFactory keyFactory = java.security.KeyFactory.getInstance(signatureAlgorithm.getName());
BCEdDSAPublicKey publicKey = (BCEdDSAPublicKey) keyFactory.generatePublic(publicKeySpec);
Signature virifier = Signature.getInstance(signatureAlgorithm.getName(), "BC");
Copy link
Contributor

Choose a reason for hiding this comment

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

DEF_BC instead of "BC" ? Lets use everywhere "BC" or otherwise DEF_BC. Mix does not look consistent.

BCRSAPublicKey publicKey = (BCRSAPublicKey) x509Certificate.getPublicKey();

rsaPublicKey = new RSAPublicKey(publicKey.getModulus(), publicKey.getPublicExponent());
if (x509Certificate != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets do early exit. We have big problems with nested ifs in bigger methods.

ìf (x509Certificate == null) {
    return null;
}

public ECDSAPublicKey getEcdsaPublicKey() {
ECDSAPublicKey ecdsaPublicKey = null;
if (x509Certificate != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

early exit

byte[] digest = null;
if (signatureAlgorithm != null) {
switch (signatureAlgorithm) {
case HS256:
Copy link
Contributor

Choose a reason for hiding this comment

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

formatting

if (signatureAlgorithm == SignatureAlgorithm.RS256 || signatureAlgorithm == SignatureAlgorithm.RS384 || signatureAlgorithm == SignatureAlgorithm.RS512) {
AlgorithmFamily algorithmFamily = signatureAlgorithm.getFamily();

if(algorithmFamily == AlgorithmFamily.RSA) {
Copy link
Contributor

Choose a reason for hiding this comment

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

formatting

@smansoft smansoft added the java Pull requests that update Java code label Jan 25, 2022
@moabu moabu changed the title jans-auth-server: Extending crypto support: sub pr4; feat(jans-auth-server): extending crypto support: sub pr4 Jan 25, 2022
@moabu moabu changed the title feat(jans-auth-server): extending crypto support: sub pr4 feat(jans-auth-server): extending crypto support sub pr4 Jan 25, 2022
@sonarcloud
Copy link

sonarcloud bot commented Jan 25, 2022

[jans-cli] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarcloud
Copy link

sonarcloud bot commented Jan 25, 2022

[notify] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarcloud
Copy link

sonarcloud bot commented Jan 25, 2022

[jans-pycloudlib] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarcloud
Copy link

sonarcloud bot commented Jan 25, 2022

[orm] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarcloud
Copy link

sonarcloud bot commented Jan 25, 2022

[jans-core] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarcloud
Copy link

sonarcloud bot commented Jan 25, 2022

[jans-config-api-parent] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarcloud
Copy link

sonarcloud bot commented Jan 25, 2022

[Fido2 API] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarcloud
Copy link

sonarcloud bot commented Jan 25, 2022

[jans-client-api] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarcloud
Copy link

sonarcloud bot commented Jan 25, 2022

[SCIM API] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarcloud
Copy link

sonarcloud bot commented Jan 26, 2022

[Jans authentication server parent] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-jans-auth-server Component affected by issue or PR java Pull requests that update Java code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants