Skip to content

Commit

Permalink
Drop OkHttp dependency
Browse files Browse the repository at this point in the history
Ref sbt/sbt#6912

Problem
-------
There's apparently a security issue with OkHttp 3.x,
which I am not really sure how applicable it is to our usage
of OkHttp but it is there.

Solution
--------
Since most of OkHttp-specic usage within LM is for Apache Ivy
downloading, I am going to drop this.
Since `sbt.librarymanagement.Http.http` is a public API,
I am substituting this with Apache HTTP backed implementation.
  • Loading branch information
eed3si9n committed Jun 13, 2022
1 parent 91bf264 commit 76452e5
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 466 deletions.
10 changes: 10 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ val mimaSettings = Def settings (
"1.3.0",
"1.4.0",
"1.5.0",
"1.6.0",
) map (
version =>
organization.value %% moduleName.value % version
Expand Down Expand Up @@ -353,6 +354,15 @@ lazy val lmIvy = (project in file("ivy"))
"sbt.internal.librarymanagement.CustomPomParser.versionRangeFlag"
),
exclude[MissingClassProblem]("sbt.internal.librarymanagement.FixedParser*"),
exclude[MissingClassProblem]("sbt.internal.librarymanagement.ivyint.GigahorseUrlHandler*"),
exclude[MissingClassProblem]("sbt.internal.librarymanagement.JavaNetAuthenticator"),
exclude[MissingClassProblem]("sbt.internal.librarymanagement.CustomHttp*"),
exclude[DirectMissingMethodProblem]("sbt.internal.librarymanagement.IvySbt.http"),
exclude[DirectMissingMethodProblem]("sbt.internal.librarymanagement.IvySbt.this"),
exclude[DirectMissingMethodProblem]("sbt.librarymanagement.ivy.IvyPublisher.apply"),
exclude[DirectMissingMethodProblem](
"sbt.librarymanagement.ivy.IvyDependencyResolution.apply"
),
),
)

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/sbt/librarymanagement/Http.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sbt.librarymanagement

import gigahorse._, support.okhttp.Gigahorse
import gigahorse._, support.apachehttp.Gigahorse
import scala.concurrent.duration.DurationInt

object Http {
Expand Down

This file was deleted.

21 changes: 0 additions & 21 deletions ivy/src/main/scala/sbt/internal/librarymanagement/CustomHttp.scala

This file was deleted.

10 changes: 2 additions & 8 deletions ivy/src/main/scala/sbt/internal/librarymanagement/Ivy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import java.io.File
import java.net.URI
import java.util.concurrent.Callable

import okhttp3.OkHttpClient
import org.apache.ivy.Ivy
import org.apache.ivy.core.IvyPatternHelper
import org.apache.ivy.core.cache.{ CacheMetadataOptions, DefaultRepositoryCacheManager }
Expand Down Expand Up @@ -50,17 +49,13 @@ import ivyint.{
CachedResolutionResolveEngine,
ParallelResolveEngine,
SbtDefaultDependencyDescriptor,
GigahorseUrlHandler
}
import sjsonnew.JsonFormat
import sjsonnew.support.murmurhash.Hasher

final class IvySbt(
val configuration: IvyConfiguration,
val http: OkHttpClient
) { self =>
def this(configuration: IvyConfiguration) = this(configuration, CustomHttp.defaultHttpClient)

/*
* ========== Configuration/Setup ============
* This part configures the Ivy instance by first creating the logger interface to ivy, then IvySettings, and then the Ivy instance.
Expand Down Expand Up @@ -90,7 +85,6 @@ final class IvySbt(
}

private lazy val basicUrlHandler: URLHandler = new BasicURLHandler
private lazy val gigahorseUrlHandler: URLHandler = new GigahorseUrlHandler(http)

private lazy val settings: IvySettings = {
val dispatcher: URLHandlerDispatcher = URLHandlerRegistry.getDefault match {
Expand All @@ -106,8 +100,8 @@ final class IvySbt(
disp
}

val urlHandler: URLHandler =
if (configuration.updateOptions.gigahorse) gigahorseUrlHandler else basicUrlHandler
// Ignore configuration.updateOptions.gigahorse due to sbt/sbt#6912
val urlHandler: URLHandler = basicUrlHandler

// Only set the urlHandler for the http/https protocols so we do not conflict with any other plugins
// that might register other protocol handlers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class IvyCache(val ivyHome: Option[File]) {
.withResolvers(Vector(local))
.withLock(lock)
.withLog(log)
(new IvySbt(conf, CustomHttp.defaultHttpClient), local)
(new IvySbt(conf), local)
}

/** Creates a default jar artifact based on the given ID.*/
Expand Down
Loading

0 comments on commit 76452e5

Please sign in to comment.