Skip to content

Commit

Permalink
Merge branch 'release/0.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
nwtgck committed Dec 26, 2020
2 parents 281bca7 + 34152c9 commit ddc7123
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 31 deletions.
24 changes: 2 additions & 22 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,7 @@ jobs:
root: /go/dist
paths:
- .

github_release:
docker:
- image: cibuilds/github:0.10
steps:
- attach_workspace:
at: /go/dist
- run:
name: Publish Release on GitHub
command: |
VERSION=$CIRCLE_TAG
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} /go/dist

workflows:
version: 2
build:
Expand All @@ -72,12 +60,4 @@ workflows:
filters:
tags:
only: /.*/
- github_release:
requires:
- test
- build
filters:
tags:
only: /.+/
branches:
ignore: /.*/

15 changes: 11 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,23 @@ jobs:
with:
go-version: ^1.15
- run: go build -o piping-tunnel main/main.go
- run: ./piping-tunnel -s http://localhost:8080 server -p 2022 xxx yyy &
- run: ./piping-tunnel -s http://localhost:8080 client -p 3322 xxx yyy &
- run: ./piping-tunnel -s http://localhost:8080 server -p 2022 aaa bbb &
- run: ./piping-tunnel -s http://localhost:8080 client -p 3322 aaa bbb &
# (base: -o option: https://www.cyberithub.com/ssh-host-key-verification-failed-error-in-linux/)
- run: ssh -p 3322 -o 'StrictHostKeyChecking no' guest@localhost hostname

- name: Run server-host with yamux
run: ./piping-tunnel -s http://localhost:8080 server -p 2022 --yamux xxx yyy &
run: ./piping-tunnel -s http://localhost:8080 server -p 2022 --yamux aaa-yamux bbb-yamux &
- name: Run client-host with yamux
run: ./piping-tunnel -s http://localhost:8080 client -p 4422 --yamux xxx yyy &
run: ./piping-tunnel -s http://localhost:8080 client -p 4422 --yamux aaa-yamux bbb-yamux &
# Check whether ssh multiple times
# (base: -o option: https://www.cyberithub.com/ssh-host-key-verification-failed-error-in-linux/)
- run: ssh -p 4422 -o 'StrictHostKeyChecking no' guest@localhost hostname
- run: ssh -p 4422 -o 'StrictHostKeyChecking no' guest@localhost ls -l /

- name: Run socks with yamux
run: ./piping-tunnel -s http://localhost:8080 socks --yamux aaa-socks bbb-socks &
- name: Run client-host with yamux
run: ./piping-tunnel -s http://localhost:8080 client -p 1081 --yamux aaa-socks bbb-socks &
# NOTE: Depends on external resource: example.com
- run: curl -x socks5h://localhost:1081 https://example.com
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ release:
github:
disable: false
prerelease: auto
name_template: "{{.ProjectName}}-v{{.Version}}"
name_template: "v{{.Version}}"
brews:
- tap:
owner: nwtgck
Expand Down
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)

## [Unreleased]

## [0.4.2] - 2020-12-1
## [0.5.0] - 2020-12-26
### Added
* add "socks" subcommand for SOCKS5 proxy

## [0.4.2] - 2020-12-11
### Changed
* No change (for release)

Expand Down Expand Up @@ -55,7 +59,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
### Added
* Initial release

[Unreleased]: https://github.com/nwtgck/go-piping-tunnel/compare/v0.4.2...HEAD
[Unreleased]: https://github.com/nwtgck/go-piping-tunnel/compare/v0.5.0...HEAD
[0.5.0]: https://github.com/nwtgck/go-piping-tunnel/compare/v0.4.2...v0.5.0
[0.4.2]: https://github.com/nwtgck/go-piping-tunnel/compare/v0.4.1...v0.4.2
[0.4.1]: https://github.com/nwtgck/go-piping-tunnel/compare/v0.4.0...v0.4.1
[0.4.0]: https://github.com/nwtgck/go-piping-tunnel/compare/v0.3.1...v0.4.0
Expand Down
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@

Tunneling over HTTP with [Piping Server](https://github.com/nwtgck/piping-server)


## Install for Windows
[Download](https://github.com/nwtgck/go-piping-tunnel/releases/download/v0.4.2/piping-tunnel-0.4.2-windows-amd64.zip)

## Install for macOS
```bash
brew install nwtgck/piping-tunnel/piping-tunnel
```

## Install for Ubuntu
```bash
wget https://github.com/nwtgck/go-piping-tunnel/releases/download/v0.4.2/piping-tunnel-0.4.2-linux-amd64.deb
dpkg -i piping-tunnel-0.4.2-linux-amd64.deb
```

Get more executables in the [releases](https://github.com/nwtgck/go-piping-tunnel/releases).

## Help

You can use `$PIPING_SERVER` env to set default Piping Server.
Expand Down Expand Up @@ -77,6 +94,28 @@ Global Flags:
-s, --server string Piping Server URL (default "https://ppng.io")
```

The following help is for SOCKS5 proxy.

```
Run SOCKS5 server
Usage:
piping-tunnel socks [flags]
Flags:
-h, --help help for socks
--yamux Multiplex connection by hashicorp/yamux
Global Flags:
--dns-server string DNS server (e.g. 1.1.1.1:53)
-H, --header stringArray HTTP header
--http-read-buf-size int HTTP read-buffer size in bytes (default 16)
--http-write-buf-size int HTTP write-buffer size in bytes (default 16)
-k, --insecure Allow insecure server connections when using SSL
--progress Show progress (default true)
-s, --server string Piping Server URL (default "https://ppng.io")
```

## References
The idea of tunneling over Piping Server was proposed by [@Cryolite](https://github.com/Cryolite). Thanks!
- (Japanese) <https://qiita.com/Cryolite/items/ed8fa237dd8eab54ef2f>
Expand Down
1 change: 0 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var httpReadBufSize int

func init() {
cobra.OnInitialize()
RootCmd.AddCommand(serverCmd)
defaultServer, ok := os.LookupEnv(ServerUrlEnvName)
if !ok {
defaultServer = "https://ppng.io"
Expand Down
1 change: 1 addition & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var serverClientToServerBufSize uint
var serverYamux bool

func init() {
RootCmd.AddCommand(serverCmd)
serverCmd.Flags().IntVarP(&serverHostPort, "port", "p", 0, "TCP port of server host")
serverCmd.MarkFlagRequired("port")
serverCmd.Flags().UintVarP(&serverClientToServerBufSize, "c-to-s-buf-size", "", 16, "Buffer size of client-to-server in bytes")
Expand Down
109 changes: 109 additions & 0 deletions cmd/socks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package cmd

import (
"fmt"
"github.com/armon/go-socks5"
"github.com/hashicorp/yamux"
piping_tunnel_util "github.com/nwtgck/go-piping-tunnel/piping-tunnel-util"
"github.com/nwtgck/go-piping-tunnel/util"
"github.com/spf13/cobra"
"io"
"net/http"
"os"
"strings"
)

var socksYamux bool

func init() {
RootCmd.AddCommand(socksCmd)
socksCmd.Flags().BoolVarP(&socksYamux, "yamux", "", false, "Multiplex connection by hashicorp/yamux")
}

var socksCmd = &cobra.Command{
Use: "socks",
Short: "Run SOCKS5 server",
RunE: func(cmd *cobra.Command, args []string) error {
clientToServerPath, serverToClientPath, err := generatePaths(args)
if err != nil {
return err
}
headers, err := piping_tunnel_util.ParseKeyValueStrings(headerKeyValueStrs)
if err != nil {
return err
}
httpClient := util.CreateHttpClient(insecure, httpWriteBufSize, httpReadBufSize)
if dnsServer != "" {
// Set DNS resolver
httpClient.Transport.(*http.Transport).DialContext = util.CreateDialContext(dnsServer)
}
serverToClientUrl, err := util.UrlJoin(serverUrl, serverToClientPath)
if err != nil {
return err
}
clientToServerUrl, err := util.UrlJoin(serverUrl, clientToServerPath)
if err != nil {
return err
}
// Print hint
socksPrintHintForClientHost(clientToServerUrl, serverToClientUrl, clientToServerPath, serverToClientPath)

// If not use multiplexer with yamux
if !socksYamux {
return fmt.Errorf("--yamux must be specified")
}

fmt.Println("[INFO] Multiplexing with hashicorp/yamux")
socks5Conf := &socks5.Config{}
socks5Server, err := socks5.New(socks5Conf)
if err != nil {
panic(err)
}
return socksHandleWithYamux(socks5Server, httpClient, headers, clientToServerUrl, serverToClientUrl)
},
}

func socksPrintHintForClientHost(clientToServerUrl string, serverToClientUrl string, clientToServerPath string, serverToClientPath string) {
if !socksYamux {
fmt.Println("[INFO] Hint: Client host (socat + curl)")
fmt.Printf(
" socat TCP-LISTEN:31376 'EXEC:curl -NsS %s!!EXEC:curl -NsST - %s'\n",
strings.Replace(serverToClientUrl, ":", "\\:", -1),
strings.Replace(clientToServerUrl, ":", "\\:", -1),
)
}
flags := ""
if socksYamux {
flags += "--yamux "
}
fmt.Println("[INFO] Hint: Client host (piping-tunnel)")
fmt.Printf(
" piping-tunnel -s %s client -p 1080 %s%s %s\n",
serverUrl,
flags,
clientToServerPath,
serverToClientPath,
)
}

func socksHandleWithYamux(socks5Server *socks5.Server, httpClient *http.Client, headers []piping_tunnel_util.KeyValue, clientToServerUrl string, serverToClientUrl string) error {
duplex, err := piping_tunnel_util.NewPipingDuplex(httpClient, headers, serverToClientUrl, clientToServerUrl)
if err != nil {
return err
}
var readWriteCloser io.ReadWriteCloser = duplex
if showProgress {
readWriteCloser = util.NewIOProgressReadWriteCloser(duplex, os.Stderr, makeProgressMessage)
}
yamuxSession, err := yamux.Server(readWriteCloser, nil)
if err != nil {
return err
}
for {
yamuxStream, err := yamuxSession.Accept()
if err != nil {
return err
}
go socks5Server.ServeConn(yamuxStream)
}
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/nwtgck/go-piping-tunnel
go 1.14

require (
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce
github.com/spf13/cobra v1.1.1
)
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
Expand Down Expand Up @@ -206,6 +208,7 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package version

const Version = "0.4.2"
const Version = "0.5.0"

0 comments on commit ddc7123

Please sign in to comment.