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

Jans auth server jarm isuue no310 #773

Merged
merged 3 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.nimbusds.jwt.SignedJWT;
import io.jans.as.model.crypto.encryption.BlockEncryptionAlgorithm;
import io.jans.as.model.crypto.encryption.KeyEncryptionAlgorithm;
import io.jans.as.model.crypto.signature.SignatureAlgorithm;
import io.jans.as.model.exception.InvalidJweException;
import io.jans.as.model.exception.InvalidJwtException;
import io.jans.as.model.jwt.Jwt;
Expand All @@ -36,6 +37,14 @@ public class JweDecrypterImpl extends AbstractJweDecrypter {

private PrivateKey privateKey;
private byte[] sharedSymmetricKey;
private boolean fapi;

public boolean isFapi() {
return fapi;
}
public void setFapi(boolean fapi) {
this.fapi = fapi;
}

public JweDecrypterImpl(byte[] sharedSymmetricKey) {
if (sharedSymmetricKey != null) {
Expand Down Expand Up @@ -109,6 +118,7 @@ public Jwe decrypt(String encryptedJwe) throws InvalidJweException {
jwe.setClaims(jwt.getClaims());
} else {
final String base64encodedPayload = encryptedJwt.getPayload().toString();
validateNestedJwt(base64encodedPayload);
jwe.setClaims(new JwtClaims(base64encodedPayload));
}

Expand All @@ -117,4 +127,11 @@ public Jwe decrypt(String encryptedJwe) throws InvalidJweException {
throw new InvalidJweException(e);
}
}
}

private void validateNestedJwt(String base64encodedPayload) throws InvalidJwtException {
final Jwt jwt = Jwt.parseSilently(base64encodedPayload);
if (jwt != null && jwt.getHeader().getSignatureAlgorithm() == SignatureAlgorithm.NONE && isFapi()) {
throw new InvalidJwtException("The None algorithm in nested JWT is not allowed for FAPI");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public JwtAuthorizationRequest(AppConfiguration appConfiguration, AbstractCrypto
ClientService clientService = CdiUtil.bean(ClientService.class);
jweDecrypter = new JweDecrypterImpl(clientService.decryptSecret(client.getClientSecret()).getBytes(StandardCharsets.UTF_8));
}
jweDecrypter.setFapi(appConfiguration.getFapiCompatibility());
jweDecrypter.setKeyEncryptionAlgorithm(keyEncryptionAlgorithm);
jweDecrypter.setBlockEncryptionAlgorithm(blockEncryptionAlgorithm);

Expand Down