-
Notifications
You must be signed in to change notification settings - Fork 90
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
Replace EOL Google Oauth library #409
Open
jtnord
wants to merge
14
commits into
jenkinsci:master
Choose a base branch
from
jtnord:pac4j
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
60fc090
Replace EOL Google Oauth library
jtnord 347dd4d
Implement a custom configuration so we can modify HttpRequests
jtnord 2941d99
the JWKSetURL set in the provider config was not set in manual mode.
jtnord 227d072
update help for sendScopesInTokenRequest to show this is not supported.
jtnord 5b51704
remove unused field
jtnord 7b753d6
Prevent NPE if GrantTypes is empty for refresh
jtnord 659ecfc
Merge remote-tracking branch 'origin/master' into pac4j
jtnord 0ebc81b
IDToken and refresh token may not be present when refreshing
jtnord fb4ce0c
workaround token refresh nonce issue
jtnord a594a27
update to pac4j 5.7.7 to pick up security fix
jtnord 7116a7b
Do not allow the "none" signing algorithm
jtnord f8230ef
update compatable since
jtnord 769f395
FormValidation should be an error as value is required
jtnord d5e1522
fix empty strings
jtnord File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/main/java/org/jenkinsci/plugins/oic/AnythingGoesTokenValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package org.jenkinsci.plugins.oic; | ||
|
||
import com.nimbusds.jose.JWSAlgorithm; | ||
import com.nimbusds.jwt.JWT; | ||
import com.nimbusds.jwt.JWTClaimsSet; | ||
import com.nimbusds.oauth2.sdk.ParseException; | ||
import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod; | ||
import com.nimbusds.oauth2.sdk.id.Issuer; | ||
import com.nimbusds.openid.connect.sdk.Nonce; | ||
import com.nimbusds.openid.connect.sdk.SubjectType; | ||
import com.nimbusds.openid.connect.sdk.claims.IDTokenClaimsSet; | ||
import com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.List; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import org.pac4j.core.exception.TechnicalException; | ||
import org.pac4j.oidc.config.OidcConfiguration; | ||
import org.pac4j.oidc.profile.creator.TokenValidator; | ||
|
||
public class AnythingGoesTokenValidator extends TokenValidator { | ||
|
||
public static final Logger LOGGER = Logger.getLogger(AnythingGoesTokenValidator.class.getName()); | ||
|
||
public AnythingGoesTokenValidator() { | ||
super(createFakeOidcConfiguration()); | ||
} | ||
|
||
@Override | ||
public IDTokenClaimsSet validate(final JWT idToken, final Nonce expectedNonce) { | ||
// validation is disabled, so everything is valid. | ||
try { | ||
return new IDTokenClaimsSet(idToken.getJWTClaimsSet()); | ||
} catch (ParseException | java.text.ParseException e) { | ||
LOGGER.log( | ||
Level.WARNING, | ||
"Token validation is disabled, but the token is corrupt and claims will not be represted.", | ||
e); | ||
try { | ||
return new IDTokenClaimsSet(new JWTClaimsSet.Builder().build()); | ||
} catch (ParseException e1) { | ||
throw new TechnicalException("could not create and empty IDTokenClaimsSet"); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Annoyingly the super class needs an OidcConfiguration with some values set, | ||
* which if we are not validating we may not actually have (e.g. jwks_url). | ||
* So we need a configuration with this set just so the validator can say "this is valid". | ||
*/ | ||
private static OidcConfiguration createFakeOidcConfiguration() { | ||
try { | ||
OidcConfiguration config = new OidcConfiguration(); | ||
config.setClientId("ignored"); | ||
config.setSecret("ignored"); | ||
OIDCProviderMetadata providerMetadata = new OIDCProviderMetadata( | ||
new Issuer("http://ignored"), List.of(SubjectType.PUBLIC), new URI("http://ignored.and.invalid./")); | ||
providerMetadata.setIDTokenJWSAlgs(List.of(JWSAlgorithm.HS256)); | ||
config.setProviderMetadata(providerMetadata); | ||
config.setPreferredJwsAlgorithm(JWSAlgorithm.HS256); | ||
config.setClientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC); | ||
return config; | ||
} catch (URISyntaxException e) { | ||
// should never happen the urls we are using are valid | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/org/jenkinsci/plugins/oic/CustomOidcConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.jenkinsci.plugins.oic; | ||
|
||
import com.nimbusds.oauth2.sdk.http.HTTPRequest; | ||
import hudson.ProxyConfiguration; | ||
import java.net.Proxy; | ||
import java.net.http.HttpRequest; | ||
import java.security.KeyManagementException; | ||
import java.security.NoSuchAlgorithmException; | ||
import javax.net.ssl.HostnameVerifier; | ||
import javax.net.ssl.SSLContext; | ||
import jenkins.model.Jenkins; | ||
import jenkins.security.FIPS140; | ||
import org.jenkinsci.plugins.oic.ssl.IgnoringHostNameVerifier; | ||
import org.jenkinsci.plugins.oic.ssl.TLSUtils; | ||
import org.pac4j.oidc.config.OidcConfiguration; | ||
|
||
/** | ||
* An OidcConfiguration that will customize {@link HttpRequest} with the Jenkins proxy, and iff TLS is disabled a lenient {@link HostnameVerifier} and {@link SSLContext}. | ||
*/ | ||
class CustomOidcConfiguration extends OidcConfiguration { | ||
|
||
private final boolean disableTLS; | ||
|
||
CustomOidcConfiguration(boolean disableTLS) { | ||
this.disableTLS = disableTLS; | ||
if (FIPS140.useCompliantAlgorithms() && disableTLS) { | ||
throw new IllegalStateException("Cannot disable TLS validation in FIPS-140 mode"); | ||
} | ||
} | ||
|
||
@Override | ||
public void configureHttpRequest(HTTPRequest request) { | ||
Proxy proxy = null; | ||
Jenkins jenkins = Jenkins.getInstanceOrNull(); | ||
if (jenkins != null) { // unit tests | ||
ProxyConfiguration pc = jenkins.getProxy(); | ||
if (pc != null) { | ||
proxy = pc.createProxy(request.getURL().getHost()); | ||
} | ||
} | ||
request.setProxy(proxy); | ||
if (disableTLS) { | ||
request.setHostnameVerifier(IgnoringHostNameVerifier.INSTANCE); | ||
try { | ||
request.setSSLSocketFactory(TLSUtils.createAnythingGoesSSLSocketFactory()); | ||
} catch (KeyManagementException | NoSuchAlgorithmException e) { | ||
throw new IllegalStateException("could not configure the SSLFactory, this should not be possible", e); | ||
} | ||
} | ||
super.configureHttpRequest(request); | ||
} | ||
} |
33 changes: 0 additions & 33 deletions
33
src/main/java/org/jenkinsci/plugins/oic/JenkinsAwareConnectionFactory.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my own learning.
IllegalState instead of IllegalArgument because this is only used during login, so it means configuration was already wrong (and should have been raised when creating the realm once jtnord#1 is merged) isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct