rewrite: Do not eagerly resolve Maven repositories, to prevent `SSLHandshakeException` stacktrace from `maven.java.net`

I have noticed several warnings lately when updating various projects related to repositories not being available or not up to date.

As far as I can see, it’s usually dependencies coming with exotic repositories declared and it seems that OpenRewrite resolves all of them (not sure if it’s new but I noticed it only lately).

It generates big warnings in the output such as:

(This is just an example, I had another issue with some dependency in the classpath registering central.maven.org as a repository…)

[WARNING] Failed to access maven repository https://maven.java.net/content/repositories/snapshots
[WARNING] javax.net.ssl.SSLHandshakeException: PKIX path validation failed: java.security.cert.CertPathValidatorException: validity check failed
[WARNING]     at sun.security.ssl.Alert.createSSLException (Alert.java:131)
[WARNING]     at sun.security.ssl.TransportContext.fatal (TransportContext.java:378)
[WARNING]     at sun.security.ssl.TransportContext.fatal (TransportContext.java:321)
[WARNING]     at sun.security.ssl.TransportContext.fatal (TransportContext.java:316)
[WARNING]     at sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts (CertificateMessage.java:654)
[WARNING]     at sun.security.ssl.CertificateMessage$T12CertificateConsumer.onCertificate (CertificateMessage.java:473)
[WARNING]     at sun.security.ssl.CertificateMessage$T12CertificateConsumer.consume (CertificateMessage.java:369)
[WARNING]     at sun.security.ssl.SSLHandshake.consume (SSLHandshake.java:396)
[WARNING]     at sun.security.ssl.HandshakeContext.dispatch (HandshakeContext.java:480)
[WARNING]     at sun.security.ssl.HandshakeContext.dispatch (HandshakeContext.java:458)
[WARNING]     at sun.security.ssl.TransportContext.dispatch (TransportContext.java:201)
[WARNING]     at sun.security.ssl.SSLTransport.decode (SSLTransport.java:172)
[WARNING]     at sun.security.ssl.SSLSocketImpl.decode (SSLSocketImpl.java:1510)
[WARNING]     at sun.security.ssl.SSLSocketImpl.readHandshakeRecord (SSLSocketImpl.java:1425)
[WARNING]     at sun.security.ssl.SSLSocketImpl.startHandshake (SSLSocketImpl.java:455)
[WARNING]     at sun.security.ssl.SSLSocketImpl.startHandshake (SSLSocketImpl.java:426)
[WARNING]     at sun.net.www.protocol.https.HttpsClient.afterConnect (HttpsClient.java:589)
[WARNING]     at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect (AbstractDelegateHttpsURLConnection.java:187)
[WARNING]     at sun.net.www.protocol.http.HttpURLConnection.getInputStream0 (HttpURLConnection.java:1665)
[WARNING]     at sun.net.www.protocol.http.HttpURLConnection.getInputStream (HttpURLConnection.java:1589)
[WARNING]     at java.net.HttpURLConnection.getResponseCode (HttpURLConnection.java:529)
[WARNING]     at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode (HttpsURLConnectionImpl.java:308)
[WARNING]     at org.openrewrite.ipc.http.HttpUrlConnectionSender.send (HttpUrlConnectionSender.java:97)
[WARNING]     at org.openrewrite.maven.internal.MavenPomDownloader.lambda$sendRequest$1 (MavenPomDownloader.java:142)
[WARNING]     at dev.failsafe.Functions.lambda$toCtxSupplier$11 (Functions.java:243)
[WARNING]     at dev.failsafe.Functions.lambda$get$0 (Functions.java:46)
[WARNING]     at dev.failsafe.internal.RetryPolicyExecutor.lambda$apply$0 (RetryPolicyExecutor.java:74)
[WARNING]     at dev.failsafe.SyncExecutionImpl.executeSync (SyncExecutionImpl.java:187)
[WARNING]     at dev.failsafe.FailsafeExecutor.call (FailsafeExecutor.java:376)
[WARNING]     at dev.failsafe.FailsafeExecutor.get (FailsafeExecutor.java:112)
[WARNING]     at org.openrewrite.maven.internal.MavenPomDownloader.sendRequest (MavenPomDownloader.java:141)
[WARNING]     at org.openrewrite.maven.internal.MavenPomDownloader.normalizeRepository (MavenPomDownloader.java:748)
[WARNING]     at org.openrewrite.maven.internal.MavenPomDownloader.distinctNormalizedRepositories (MavenPomDownloader.java:670)
[WARNING]     at org.openrewrite.maven.internal.MavenPomDownloader.download (MavenPomDownloader.java:507)
[WARNING]     at org.openrewrite.maven.tree.ResolvedPom$Resolver.resolveParentPom (ResolvedPom.java:492)
[WARNING]     at org.openrewrite.maven.tree.ResolvedPom$Resolver.resolveParentDependenciesRecursively (ResolvedPom.java:427)
[WARNING]     at org.openrewrite.maven.tree.ResolvedPom$Resolver.resolveParentsRecursively (ResolvedPom.java:375)
[WARNING]     at org.openrewrite.maven.tree.ResolvedPom.resolveDependencies (ResolvedPom.java:838)
[WARNING]     at org.openrewrite.maven.tree.ResolvedPom.resolveDependencies (ResolvedPom.java:754)
[WARNING]     at org.openrewrite.maven.tree.MavenResolutionResult.resolveDependencies (MavenResolutionResult.java:174)

Given there’s nothing we can do about it as they come from external dependencies, I wonder if this should be debug logging instead? At least for repositories coming from dependencies and not from the current project.

I have seen this lately in two different projects (and two different errors) so I suspect this might be more common than we think.

Thoughts?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 11
  • Comments: 62 (35 by maintainers)

Commits related to this issue

Most upvoted comments

👋 I have the same issue as well. Is there a known workaround? But is not blocking rewrite:run

Would like to draw attention to following things that were added to Maven not so long time ago:

Basically, in ideal case:

  • your root/parent POM defines all repositories you know you need
  • your build uses -itr => you are sure only repositories defined by YOU are in use (of course, if you miss some, your build will fail if you using empty local repo)
  • “tune” things with RRF

In Maven, that repo is not even touched, as can be seen:

[cstamas@urnebes openrewrite]$ mvn eu.maveniverse.maven.plugins:toolbox:0.1.31:gav-list-repositories -Dgav=io.quarkiverse.githubapp:quarkus-github-app-testing:2.6.0 -Dmaven.repo.local=local
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- toolbox:0.1.31:gav-list-repositories (default-cli) @ standalone-pom ---
[INFO]  * central (https://repo.maven.apache.org/maven2/, default, releases)
[INFO]    First introduced on root
[INFO]  * jboss-public-repository-group (https://repository.jboss.org/nexus/content/groups/public, default, releases)
[INFO]    First introduced on jakarta.enterprise:jakarta.enterprise.cdi-api:jar:4.1.0
[INFO]  * sonatype-snapshots (https://s01.oss.sonatype.org/content/repositories/snapshots, default, releases+snapshots)
[INFO]    First introduced on io.smallrye.reactive:mutiny:jar:2.6.0
[INFO]  * microprofile-snapshots (https://repo.eclipse.org/content/repositories/microprofile-snapshots, default, snapshots)
[INFO]    First introduced on io.smallrye.reactive:mutiny:jar:2.6.0
[INFO]  * sonatype-nexus-snapshots (https://oss.sonatype.org/content/repositories/snapshots, default, snapshots)
[INFO]    First introduced on io.netty:netty-codec:jar:4.1.108.Final
[INFO]  * vertx-snapshots-repository (https://s01.oss.sonatype.org/content/repositories/snapshots/, default, snapshots)
[INFO]    First introduced on io.vertx:vertx-core:jar:4.5.7
[INFO]  * repo.jenkins-ci.org (https://repo.jenkins-ci.org/public/, default, releases+snapshots)
[INFO]    First introduced on org.kohsuke:github-api:jar:1.321
[INFO]  * ow2-snapshot (https://repository.ow2.org/nexus/content/repositories/snapshots, default, snapshots)
[INFO]    First introduced on org.ow2.asm:asm-util:jar:9.7
[INFO]  * apache.snapshots (https://repository.apache.org/snapshots, default, snapshots)
[INFO]    First introduced on org.apache.maven.resolver:maven-resolver-impl:jar:1.9.18
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.106 s
[INFO] Finished at: 2024-07-11T13:42:15+02:00
[INFO] ------------------------------------------------------------------------
[cstamas@urnebes openrewrite]$

Reason is simple:

@timtebeek I think the problem is more complex than just having a warning.

See this comment: https://github.com/openrewrite/rewrite/issues/4101#issuecomment-2039520890

I think there is a problem in how the repositories are collected and their scopes. As these servers shouldn’t even be contacted (and are not in a standard Maven run).

FWIW, from the beginning in my case I had the warning but the recipes were applied.

👋 I have the same issue as well. Is there a known workaround? This is blocking rewrite:run to complete

Hi, @timtebeek , as this issue is closed can you please share the link to the issue where support of “-itr” will be added?

There’s no such issue yet. If you find you need that please open an issue and link it here. Be sure to include the context of why that needs to be added as well. 🙏

openssl s_client -connect yourserver.com:443 -showcerts

Copy the server’s certificate (including the -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- lines) and save it to a file, e.g., server.crt //

Import the certificate into the Java trust store: Use the keytool utility to import the certificate into the Java trust store. Replace /path/to/server.crt with the path to your certificate file and /path/to/cacerts with the path to your Java trust store (usually located in the lib/security directory of your JDK installation).

keytool -import -alias yourserver -keystore /path/to/cacerts -file /path/to/server.crt You will be prompted for the trust store password, which is usually changeit by default.

This worked for me for the PKIX issue.

Since most of the original problem has been resolved, perhaps we want to close this issue and open one about supporting “-itr”.

Hello, I am newbie with openwrite, just run a simple test from doc with petclinic, but I have always this error :

[INFO] — rewrite-maven-plugin:6.3.2:run (default-cli) @ spring-petclinic — [INFO] Using active recipe(s) [org.openrewrite.java.OrderImports] [INFO] Using active styles(s) [] [INFO] Validating active recipes… [INFO] Project [petclinic] Resolving Poms… [WARNING] Failed to access maven repository https://oss.sonatype.org/content/repositories/snapshots due to: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Hi! I notice you’ve also posted the same on this thread , and received an answer there saying it’s likely specific to your setup; let’s keep the discussion on this issue specific to what was reported.

The issue with maven.java.net has been fixed. Thanks to @brianf

Thanks for chiming in here with those details @michael-o ! Good to know it’s not just us, and caused by a certificate issue that we warn about, but continue in spite of to make the required changes.

Total crap, Oracle is too stupid to configure the certificate chain sent to the client. Just hit this as well:

$ grep -r maven.java.net /tmp/r2/
/tmp/r2/net/java/jvnet-parent/3/jvnet-parent-3.pom:                     <url>https://maven.java.net/content/repositories/snapshots</url>
/tmp/r2/net/java/jvnet-parent/3/jvnet-parent-3.pom:                     <url>https://maven.java.net/service/local/staging/deploy/maven2/</url>
/tmp/r2/net/java/jvnet-parent/3/jvnet-parent-3.pom:             <jvnetDistMgmtSnapshotsUrl>https://maven.java.net/content/repositories/snapshots/</jvnetDistMgmtSnapshotsUrl>

Similar: https://bugzilla.mozilla.org/show_bug.cgi?id=1763708

Here is the breakdown:

$ openssl s_client -connect maven.java.net:443
CONNECTED(00000003)
depth=0 C = US, ST = California, L = Redwood City, O = Oracle Corporation, CN = maven.java.net
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 C = US, ST = California, L = Redwood City, O = Oracle Corporation, CN = maven.java.net
verify error:num=21:unable to verify the first certificate
verify return:1
depth=0 C = US, ST = California, L = Redwood City, O = Oracle Corporation, CN = maven.java.net
verify return:1
---
Certificate chain
 0 s:C = US, ST = California, L = Redwood City, O = Oracle Corporation, CN = maven.java.net
   i:C = US, O = DigiCert Inc, CN = DigiCert TLS RSA SHA256 2020 CA1
 1 s:C = US, ST = California, L = Redwood City, O = Oracle Corporation, CN = maven.java.net
   i:C = US, O = DigiCert Inc, CN = DigiCert TLS RSA SHA256 2020 CA1
---

“DigiCert TLS RSA SHA256 2020 CA1” is an intermediate, but neither part of Mozilla NSS, nor OpenJDK cacerts. The missed to send the root certificate DN as well: https://tls-observatory.services.mozilla.com/static/certsplainer.html?id=188407168

Quoting from https://httpd.apache.org/docs/current/mod/mod_ssl.html#sslcertificatefile:

The files may also include intermediate CA certificates, sorted from leaf to root. This is supported with version 2.4.8 and later,
and obsoletes [SSLCertificateChainFile](https://httpd.apache.org/docs/current/mod/mod_ssl.html#sslcertificatechainfile).
When running with OpenSSL 1.0.2 or later, this allows to configure the intermediate CA chain on a per-certificate basis.

Ugly solution:

Yeah, FWIW, it’s not the only problematic artifact. Old legacy artifacts often point to a repository that doesn’t exist anymore.

In Quarkus, we are using jakarta.annotation but… we rely on the Maven artifacts here that require the javax. annotation and thus we had to use the old javax.annotation artifact to avoid conflicts.

But as you can see from the various reports you had, it happens quite a lot in the wild as not all the reports here are related to Quarkus.

Sorry, time is scarce on my side and I wasn’t able to provide feedback here earlier.

Here is a simple reproducer with a simple project, a simple recipe and using the OpenRewrite Maven plugin directly:

git clone https://github.com/quarkusio/quarkus-github-bot
cd quarkus-github-bot
cat <<EOT > rewrite.yml
type: specs.openrewrite.org/v1beta/recipe
name: io.quarkus.AddHibernateValidator
recipeList:
  - org.openrewrite.maven.AddDependency:
      groupId: io.quarkus
      artifactId: quarkus-hibernate-validator
      version: 3.12.0
EOT
./mvnw -U org.openrewrite.maven:rewrite-maven-plugin:run  -Drewrite.activeRecipes=io.quarkus.AddHibernateValidator

You will get this warning during the execution:

[WARNING] Failed to access maven repository https://maven.java.net/content/repositories/snapshots
javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

When building the project with Maven, even with an empty Maven repo, you don’t get this warning so, as I explained a bit earlier, there’s something incorrect in how the repositories are resolved.

I have been working on an update to the update task of the quarkus plugin. something like this applied to a quarkus app would show the stacktrace: mvn io.quarkus:quarkus-maven-plugin:999-SNAPSHOT:update -N -DrewriteDryRun=true and I was mistaken to think this is blocking. the process continues normally after printing the stack trace as a warning.

Thanks @timtebeek Found this issue also when running recipes on some jenkins plugins

Maven 3.9.7 added the --ignore-transitive-repositories switch. You might try that as a workaround.

Thanks for chiming in with that insight; good that recipe runs are at least not affected. That brings us back to the message Guillaume started with: that it’s probably best to not show the full stacktrace if this is not affecting recipe runs in practice.

With this PR we already have some work in progress that touches upon some of the same areas

I propose we wait for the above PR to be merged and then reevaluate if we still have to change the reported stacktrace here.

You are right. The execution-breaking error I referred to comes from dependencies using the LATEST version.

I have the same issue. It leads to a java.lang.IllegalStateException: Illegal state while comparing versions, or at least I assume that’s the cause

@delanym FWIW, that is not my personal experience. Anyway, there are more pleasant ways to convey this message.