Skip to content

Commit 7455c84

Browse files
committed
Configured publishing to the central maven repository
1 parent 8004431 commit 7455c84

File tree

10 files changed

+152
-57
lines changed

10 files changed

+152
-57
lines changed

README.md

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ beyond `scala-logging`
55

66
Can be used as a library, or as a standalone program.
77

8+
89
## Standalone
910

1011
```
@@ -40,12 +41,13 @@ etag: "5e9efe7d-264"
4041
accept-ranges: bytes
4142
```
4243

44+
4345
## Library
4446

4547
To use it as a library in-process:
4648

4749
```scala
48-
import tlsproxy.TlsProxy
50+
import io.github.erikvanzijst.scalatlsproxy.TlsProxy
4951

5052
new TlsProxy(3128).run()
5153
```
@@ -56,13 +58,14 @@ calling thread. It does not return.
5658
To move it to the background, pass it to a `Thread` or `Executor`:
5759

5860
```scala
59-
import tlsproxy.TlsProxy
61+
import io.github.erikvanzijst.scalatlsproxy.TlsProxy
6062
import java.util.concurrent.Executors
6163

6264
val executor = Executors.newSingleThreadExecutor()
6365
executor.submit(new TlsProxy(3128))
6466
```
6567

68+
6669
## Caveat emptor
6770

6871
This is only implements the `CONNECT` method and can therefor only proxy HTTPS
@@ -75,10 +78,92 @@ connection getting closed:
7578
18:08:53.604 [main] ERROR tlsproxy.TlsProxyHandler - /0:0:0:0:0:0:0:1:51043 -> unconnected: error: connection closed: java.io.IOException: Malformed request
7679
```
7780

81+
7882
## Robustness (or lack thereof)
7983

8084
* This implementation is totally susceptible to all kinds of [slowloris attacks](https://en.wikipedia.org/wiki/Slowloris_(computer_security).
8185
* It does not support client authentication
8286
* Uses only 1 thread and cannot currently scale to multiple cores
8387
* Does not restrict non-standard upstream ports
8488
* Undoubtedly riddled with bugs
89+
90+
91+
## Publishing
92+
93+
Publishing is done to the Sonatype Central Repository and requires gpg-signed
94+
artifacts. For this, install gpg and (on Mac) `pin-entry-mac`:
95+
96+
```
97+
$ brew install gnupg pinentry-mac
98+
```
99+
100+
Add the pinentry program to `~/.gnupg/gpg-agent.conf`:
101+
102+
```
103+
pinentry-program /usr/local/bin/pinentry-mac
104+
```
105+
106+
Restart `gpg-agent`:
107+
108+
```
109+
$ gpgconf --kill gpg-agent
110+
```
111+
112+
Run `publishLocalSigned` to ensure signing from `sbt` works (this should pop
113+
up a dialog to enter the private key's passphrase):
114+
115+
```
116+
$ sbt publishLocalSigned
117+
[info] Loading global plugins from /Users/erik/.sbt/1.0/plugins
118+
[info] Loading settings for project tlsproxy-build from plugins.sbt ...
119+
[info] Loading project definition from /Users/erik/work/tlsproxy/project
120+
[info] Loading settings for project tlsproxy from build.sbt ...
121+
[info] Set current project to tlsproxy (in build file:/Users/erik/work/tlsproxy/)
122+
[info] Wrote /Users/erik/work/tlsproxy/target/scala-2.12/tlsproxy_2.12-0.1.pom
123+
[info] :: delivering :: erikvanzijst#tlsproxy_2.12;0.1 :: 0.1 :: release :: Tue Aug 17 22:44:46 CEST 2021
124+
[info] delivering ivy file to /Users/erik/work/tlsproxy/target/scala-2.12/ivy-0.1.xml
125+
[info] gpg: using "E96DDAAB16804D86EFA2A08A4539ACC7B26D1005" as default secret key for signing
126+
[info] gpg: using "E96DDAAB16804D86EFA2A08A4539ACC7B26D1005" as default secret key for signing
127+
[info] gpg: using "E96DDAAB16804D86EFA2A08A4539ACC7B26D1005" as default secret key for signing
128+
[info] gpg: using "E96DDAAB16804D86EFA2A08A4539ACC7B26D1005" as default secret key for signing
129+
[info] published tlsproxy_2.12 to /Users/erik/.ivy2/local/erikvanzijst/tlsproxy_2.12/0.1/jars/tlsproxy_2.12.jar
130+
[info] published tlsproxy_2.12 to /Users/erik/.ivy2/local/erikvanzijst/tlsproxy_2.12/0.1/docs/tlsproxy_2.12-javadoc.jar
131+
[info] published tlsproxy_2.12 to /Users/erik/.ivy2/local/erikvanzijst/tlsproxy_2.12/0.1/srcs/tlsproxy_2.12-sources.jar
132+
[info] published tlsproxy_2.12 to /Users/erik/.ivy2/local/erikvanzijst/tlsproxy_2.12/0.1/poms/tlsproxy_2.12.pom.asc
133+
[info] published tlsproxy_2.12 to /Users/erik/.ivy2/local/erikvanzijst/tlsproxy_2.12/0.1/poms/tlsproxy_2.12.pom
134+
[info] published tlsproxy_2.12 to /Users/erik/.ivy2/local/erikvanzijst/tlsproxy_2.12/0.1/jars/tlsproxy_2.12.jar.asc
135+
[info] published tlsproxy_2.12 to /Users/erik/.ivy2/local/erikvanzijst/tlsproxy_2.12/0.1/srcs/tlsproxy_2.12-sources.jar.asc
136+
[info] published tlsproxy_2.12 to /Users/erik/.ivy2/local/erikvanzijst/tlsproxy_2.12/0.1/docs/tlsproxy_2.12-javadoc.jar.asc
137+
[success] Total time: 1 s, completed Aug 17, 2021 10:44:47 PM
138+
```
139+
140+
Now publish to Sonatype:
141+
142+
```
143+
$ sbt publishSigned
144+
[info] Loading global plugins from /Users/erik/.sbt/1.0/plugins
145+
[info] Loading settings for project tlsproxy-build from plugins.sbt ...
146+
[info] Loading project definition from /Users/erik/work/tlsproxy/project
147+
[info] Loading settings for project tlsproxy from build.sbt ...
148+
[info] Set current project to scala-tlsproxy (in build file:/Users/erik/work/tlsproxy/)
149+
[info] Wrote /Users/erik/work/tlsproxy/target/scala-2.12/scala-tlsproxy_2.12-0.1-SNAPSHOT.pom
150+
[info] gpg: using "E96DDAAB16804D86EFA2A08A4539ACC7B26D1005" as default secret key for signing
151+
[info] gpg: using "E96DDAAB16804D86EFA2A08A4539ACC7B26D1005" as default secret key for signing
152+
[info] gpg: using "E96DDAAB16804D86EFA2A08A4539ACC7B26D1005" as default secret key for signing
153+
[info] gpg: using "E96DDAAB16804D86EFA2A08A4539ACC7B26D1005" as default secret key for signing
154+
[info] published scala-tlsproxy_2.12 to https://s01.oss.sonatype.org/content/repositories/snapshots/io/github/erikvanzijst/scala-tlsproxy_2.12/0.1-SNAPSHOT/scala-tlsproxy_2.12-0.1-SNAPSHOT.jar
155+
[info] published scala-tlsproxy_2.12 to https://s01.oss.sonatype.org/content/repositories/snapshots/io/github/erikvanzijst/scala-tlsproxy_2.12/0.1-SNAPSHOT/scala-tlsproxy_2.12-0.1-SNAPSHOT-sources.jar
156+
[info] published scala-tlsproxy_2.12 to https://s01.oss.sonatype.org/content/repositories/snapshots/io/github/erikvanzijst/scala-tlsproxy_2.12/0.1-SNAPSHOT/scala-tlsproxy_2.12-0.1-SNAPSHOT-javadoc.jar
157+
[info] published scala-tlsproxy_2.12 to https://s01.oss.sonatype.org/content/repositories/snapshots/io/github/erikvanzijst/scala-tlsproxy_2.12/0.1-SNAPSHOT/scala-tlsproxy_2.12-0.1-SNAPSHOT.jar.asc
158+
[info] published scala-tlsproxy_2.12 to https://s01.oss.sonatype.org/content/repositories/snapshots/io/github/erikvanzijst/scala-tlsproxy_2.12/0.1-SNAPSHOT/scala-tlsproxy_2.12-0.1-SNAPSHOT.pom.asc
159+
[info] published scala-tlsproxy_2.12 to https://s01.oss.sonatype.org/content/repositories/snapshots/io/github/erikvanzijst/scala-tlsproxy_2.12/0.1-SNAPSHOT/scala-tlsproxy_2.12-0.1-SNAPSHOT-sources.jar.asc
160+
[info] published scala-tlsproxy_2.12 to https://s01.oss.sonatype.org/content/repositories/snapshots/io/github/erikvanzijst/scala-tlsproxy_2.12/0.1-SNAPSHOT/scala-tlsproxy_2.12-0.1-SNAPSHOT-javadoc.jar.asc
161+
[info] published scala-tlsproxy_2.12 to https://s01.oss.sonatype.org/content/repositories/snapshots/io/github/erikvanzijst/scala-tlsproxy_2.12/0.1-SNAPSHOT/scala-tlsproxy_2.12-0.1-SNAPSHOT.pom
162+
[success] Total time: 9 s, completed Aug 17, 2021 11:29:22 PM
163+
```
164+
165+
Troubleshooting:
166+
167+
* https://github.com/sbt/sbt-pgp#sbt-pgp
168+
* https://gist.github.com/danieleggert/b029d44d4a54b328c0bac65d46ba4c65
169+
* https://www.scala-sbt.org/release/docs/Using-Sonatype.html

build.sbt

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,42 @@
1-
name := "tlsproxy"
1+
name := "scala-tlsproxy"
2+
organization := "io.github.erikvanzijst"
23

3-
version := "0.1"
4+
version := "0.1-SNAPSHOT"
45

56
scalaVersion := "2.12.14"
67

7-
libraryDependencies += "com.github.scopt" %% "scopt" % "4.0.1"
88
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.2.3"
99
libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.9.4"
10+
11+
credentials += Credentials(Path.userHome / ".sbt" / "sonatype_credentials")
12+
13+
ThisBuild / organization := "io.github.erikvanzijst"
14+
ThisBuild / organizationName := "erikvanzijst"
15+
ThisBuild / organizationHomepage := Some(url("https://github.com/erikvanzijst"))
16+
17+
ThisBuild / scmInfo := Some(
18+
ScmInfo(
19+
url("https://github.com/erikvanzijst/scala_tlsproxy"),
20+
"scm:[email protected]:erikvanzijst/scala_tlsproxy.git"
21+
)
22+
)
23+
ThisBuild / developers := List(
24+
Developer(
25+
id = "erikvanzijst",
26+
name = "Erik van Zijst",
27+
email = "[email protected]",
28+
url = url("https://github.com/erikvanzijst")
29+
)
30+
)
31+
32+
ThisBuild / description := "Very simple HTTPS proxy server lib written in Scala 2.12 with no external dependencies."
33+
ThisBuild / licenses := List("Apache 2" -> new URL("http://www.apache.org/licenses/LICENSE-2.0.txt"))
34+
ThisBuild / homepage := Some(url("https://github.com/erikvanzijst/scala_tlsproxy"))
35+
36+
ThisBuild / pomIncludeRepository := { _ => false }
37+
ThisBuild / publishTo := {
38+
val nexus = "https://s01.oss.sonatype.org/"
39+
if (isSnapshot.value) Some("snapshots" at nexus + "content/repositories/snapshots")
40+
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
41+
}
42+
ThisBuild / publishMavenStyle := true

project/plugins.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")

src/main/scala/tlsproxy/EchoHandler.scala renamed to src/main/scala/io/github/erikvanzijst/scalatlsproxy/EchoHandler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package tlsproxy
1+
package io.github.erikvanzijst.scalatlsproxy
22

33
import java.io.IOException
44
import java.nio.ByteBuffer
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.github.erikvanzijst.scalatlsproxy
2+
3+
import ch.qos.logback.classic.Level
4+
import com.typesafe.scalalogging.StrictLogging
5+
import org.slf4j.LoggerFactory
6+
7+
object Main extends StrictLogging {
8+
9+
// Suppress debug when running from the shell
10+
Seq("io.github.erikvanzijst.scalatlsproxy.TlsProxyHandler",
11+
"io.github.erikvanzijst.scalatlsproxy.ServerHandler",
12+
"io.github.erikvanzijst.scalatlsproxy.Pipe")
13+
.map(LoggerFactory.getLogger)
14+
.map(_.asInstanceOf[ch.qos.logback.classic.Logger])
15+
.foreach(_.setLevel(Level.INFO))
16+
17+
def main(args: Array[String]): Unit = new TlsProxy(3128).run()
18+
}

src/main/scala/tlsproxy/Pipe.scala renamed to src/main/scala/io/github/erikvanzijst/scalatlsproxy/Pipe.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package tlsproxy
1+
package io.github.erikvanzijst.scalatlsproxy
22

33
import java.nio.ByteBuffer
44
import java.nio.channels.{SelectionKey, SocketChannel}

src/main/scala/tlsproxy/ServerHandler.scala renamed to src/main/scala/io/github/erikvanzijst/scalatlsproxy/ServerHandler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package tlsproxy
1+
package io.github.erikvanzijst.scalatlsproxy
22

33
import java.net.InetSocketAddress
44
import java.nio.channels.{SelectionKey, Selector, ServerSocketChannel}

src/main/scala/tlsproxy/TlsProxy.scala renamed to src/main/scala/io/github/erikvanzijst/scalatlsproxy/TlsProxy.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
package tlsproxy
1+
package io.github.erikvanzijst.scalatlsproxy
22

33
import java.nio.channels.Selector
44

5-
import ch.qos.logback.classic.Level
65
import com.typesafe.scalalogging.StrictLogging
7-
import org.slf4j.LoggerFactory
86

97
trait KeyHandler {
108
def process(): Unit

src/main/scala/tlsproxy/TlsProxyHandler.scala renamed to src/main/scala/io/github/erikvanzijst/scalatlsproxy/TlsProxyHandler.scala

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package tlsproxy
1+
package io.github.erikvanzijst.scalatlsproxy
22

33
import java.io.IOException
44
import java.net.InetSocketAddress
@@ -7,23 +7,24 @@ import java.nio.channels.{SelectionKey, Selector, SocketChannel, UnresolvedAddre
77
import java.nio.charset.StandardCharsets
88

99
import com.typesafe.scalalogging.StrictLogging
10-
import tlsproxy.TlsProxyHandler.userAgent
1110

1211
import scala.collection.JavaConverters._
1312
import scala.util.Try
13+
import scala.util.matching.Regex
1414

1515
object ProxyPhase extends Enumeration {
1616
type ProxyPhase = Value
1717
val Destination, Headers, Response, Connecting, Established, Error = Value
1818
}
1919

2020
object TlsProxyHandler {
21-
private val destPattern = "CONNECT ([^:]+):([0-9]+) HTTP/1.1".r
22-
private val userAgent = "TlsProxy/1.0 (github.com/erikvanzijst/scala_tlsproxy)"
21+
val destPattern: Regex = "CONNECT ([^:]+):([0-9]+) HTTP/1.1".r
22+
val userAgent: String = "TlsProxy/1.0 (github.com/erikvanzijst/scala_tlsproxy)"
2323
}
2424

2525
class TlsProxyHandler(selector: Selector, clientChannel: SocketChannel) extends KeyHandler with StrictLogging {
2626
import ProxyPhase._
27+
import TlsProxyHandler._
2728

2829
clientChannel.configureBlocking(false)
2930
private val peer = clientChannel.getRemoteAddress
@@ -50,7 +51,6 @@ class TlsProxyHandler(selector: Selector, clientChannel: SocketChannel) extends
5051
throw new IOException(s"$peer handshake overflow")
5152
}
5253

53-
5454
private def readLine(): Option[String] = {
5555
readClient()
5656
clientBuffer.flip()
@@ -169,9 +169,8 @@ class TlsProxyHandler(selector: Selector, clientChannel: SocketChannel) extends
169169
clientChannel.write(serverBuffer)
170170
serverBuffer.compact()
171171

172-
if (serverBuffer.position() == 0) {
172+
if (serverBuffer.position() == 0)
173173
close()
174-
}
175174
}
176175

177176
} catch {

src/main/scala/tlsproxy/Main.scala

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)