Compare commits

...

8 Commits

Author SHA1 Message Date
Zack Scholl f6012939f3 v10.1.1 2024-11-28 03:02:27 -08:00
Zack Scholl bda3dcc670 Remove stun Fixes #849 2024-11-28 03:01:12 -08:00
Zack a96e7945e1
Merge pull request #847 from Ozoniuss/finish-qr-code
Add a qrcode flag
2024-11-24 03:41:38 -08:00
Ozoniuss 278e1b4099
Add a qrcode flag
- Introduces a new flag which allows displaying the receive command
  using a qr code.
- Adds a newline after the message indicating that the code was copied
  to the clipboard.
2024-11-24 13:33:38 +02:00
Zack c369c78b42
Merge pull request #843 from matthewfeickert/docs/add-conda-forge
docs: Add conda-forge install instructions for pixi and conda
2024-11-13 11:20:34 -08:00
Matthew Feickert a61a461436
docs: Add conda-forge install instructions for pixi and conda
* The conda-forge build supports Linux, macOS, and Windows.
   - c.f. https://github.com/conda-forge/croc-feedstock/
2024-11-13 12:17:51 -07:00
Zack d616b8fff7
Merge pull request #837 from gamagoat/mask-pass
Mask password in logs
2024-11-12 18:25:49 -08:00
gamagoat 3252f2abb2 Mask password in logs 2024-11-13 10:03:23 +09:00
8 changed files with 55 additions and 29 deletions

View File

@ -4,7 +4,7 @@
src="https://user-images.githubusercontent.com/6550035/46709024-9b23ad00-cbf6-11e8-9fb2-ca8b20b7dbec.jpg" src="https://user-images.githubusercontent.com/6550035/46709024-9b23ad00-cbf6-11e8-9fb2-ca8b20b7dbec.jpg"
width="408px" border="0" alt="croc"> width="408px" border="0" alt="croc">
<br> <br>
<a href="https://github.com/schollz/croc/releases/latest"><img src="https://img.shields.io/badge/version-v10.1.0-brightgreen.svg?style=flat-square" alt="Version"></a> <a href="https://github.com/schollz/croc/releases/latest"><img src="https://img.shields.io/badge/version-v10.1.1-brightgreen.svg?style=flat-square" alt="Version"></a>
<a href="https://github.com/schollz/croc/actions/workflows/ci.yml"><img <a href="https://github.com/schollz/croc/actions/workflows/ci.yml"><img
src="https://github.com/schollz/croc/actions/workflows/ci.yml/badge.svg" alt="Build src="https://github.com/schollz/croc/actions/workflows/ci.yml/badge.svg" alt="Build
Status"></a> Status"></a>
@ -104,7 +104,19 @@ On FreeBSD you can install with `pkg`:
pkg install croc pkg install croc
``` ```
Or, you can [install Go](https://golang.org/dl/) and build from source (requires Go 1.17+): On Linux, macOS, and Windows you can install from [conda-forge](https://github.com/conda-forge/croc-feedstock/) globally with [`pixi`](https://pixi.sh/):
```
pixi global install croc
```
or into a particular environment with [`conda`](https://docs.conda.io/projects/conda/):
```
conda install --channel conda-forge croc
```
Or, you can [install Go](https://golang.org/dl/) and build from source (requires Go 1.17+):
``` ```
go install github.com/schollz/croc/v10@latest go install github.com/schollz/croc/v10@latest

4
go.mod
View File

@ -17,13 +17,13 @@ require (
github.com/schollz/pake/v3 v3.0.5 github.com/schollz/pake/v3 v3.0.5
github.com/schollz/peerdiscovery v1.7.5 github.com/schollz/peerdiscovery v1.7.5
github.com/schollz/progressbar/v3 v3.17.1 github.com/schollz/progressbar/v3 v3.17.1
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/stretchr/testify v1.9.0 github.com/stretchr/testify v1.9.0
golang.org/x/crypto v0.29.0 golang.org/x/crypto v0.29.0
golang.org/x/net v0.31.0 golang.org/x/net v0.31.0
golang.org/x/sys v0.27.0 golang.org/x/sys v0.27.0
golang.org/x/term v0.26.0 golang.org/x/term v0.26.0
golang.org/x/time v0.8.0 golang.org/x/time v0.8.0
gortc.io/stun v1.23.0
) )
require ( require (
@ -37,5 +37,3 @@ require (
github.com/twmb/murmur3 v1.1.8 // indirect github.com/twmb/murmur3 v1.1.8 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
) )
replace gortc.io/stun => github.com/gortc/stun v1.23.0

4
go.sum
View File

@ -20,8 +20,6 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ= github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ=
github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI= github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gortc/stun v1.23.0 h1:/hkB8P0DeDfiVf3khHSMSTRpldFMqiuddn2XhaUPOkM=
github.com/gortc/stun v1.23.0/go.mod h1:XD5lpONVyjvV3BgOyJFNo0iv6R2oZB4L+weMqxts+zg=
github.com/kalafut/imohash v1.1.0 h1:Lldcmx0SXgMSoABB2WBD8mTgf0OlVnISn2Dyrfg2Ep8= github.com/kalafut/imohash v1.1.0 h1:Lldcmx0SXgMSoABB2WBD8mTgf0OlVnISn2Dyrfg2Ep8=
github.com/kalafut/imohash v1.1.0/go.mod h1:6cn9lU0Sj8M4eu9UaQm1kR/5y3k/ayB68yntRhGloL4= github.com/kalafut/imohash v1.1.0/go.mod h1:6cn9lU0Sj8M4eu9UaQm1kR/5y3k/ayB68yntRhGloL4=
github.com/magisterquis/connectproxy v0.0.0-20200725203833-3582e84f0c9b h1:xZ59n7Frzh8CwyfAapUZLSg+gXH5m63YEaFCMpDHhpI= github.com/magisterquis/connectproxy v0.0.0-20200725203833-3582e84f0c9b h1:xZ59n7Frzh8CwyfAapUZLSg+gXH5m63YEaFCMpDHhpI=
@ -52,6 +50,8 @@ github.com/schollz/peerdiscovery v1.7.5/go.mod h1:Crht2FOfD1/eL3U/AIM0vvwVZDPePl
github.com/schollz/progressbar/v3 v3.17.1 h1:bI1MTaoQO+v5kzklBjYNRQLoVpe0zbyRZNK6DFkVC5U= github.com/schollz/progressbar/v3 v3.17.1 h1:bI1MTaoQO+v5kzklBjYNRQLoVpe0zbyRZNK6DFkVC5U=
github.com/schollz/progressbar/v3 v3.17.1/go.mod h1:RzqpnsPQNjUyIgdglUjRLgD7sVnxN1wpmBMV+UiEbL4= github.com/schollz/progressbar/v3 v3.17.1/go.mod h1:RzqpnsPQNjUyIgdglUjRLgD7sVnxN1wpmBMV+UiEbL4=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

View File

@ -77,6 +77,7 @@ func Run() (err error) {
&cli.BoolFlag{Name: "git", Usage: "enable .gitignore respect / don't send ignored files"}, &cli.BoolFlag{Name: "git", Usage: "enable .gitignore respect / don't send ignored files"},
&cli.IntFlag{Name: "port", Value: 9009, Usage: "base port for the relay"}, &cli.IntFlag{Name: "port", Value: 9009, Usage: "base port for the relay"},
&cli.IntFlag{Name: "transfers", Value: 4, Usage: "number of ports to use for transfers"}, &cli.IntFlag{Name: "transfers", Value: 4, Usage: "number of ports to use for transfers"},
&cli.BoolFlag{Name: "qrcode", Aliases: []string{"qr"}, Usage: "show receive code as a qrcode"},
}, },
HelpName: "croc send", HelpName: "croc send",
Action: send, Action: send,
@ -302,6 +303,7 @@ func send(c *cli.Context) (err error) {
ThrottleUpload: c.String("throttleUpload"), ThrottleUpload: c.String("throttleUpload"),
ZipFolder: c.Bool("zip"), ZipFolder: c.Bool("zip"),
GitIgnore: c.Bool("git"), GitIgnore: c.Bool("git"),
ShowQrCode: c.Bool("qrcode"),
MulticastAddress: c.String("multicast"), MulticastAddress: c.String("multicast"),
} }
if crocOptions.RelayAddress != models.DEFAULT_RELAY { if crocOptions.RelayAddress != models.DEFAULT_RELAY {

View File

@ -27,6 +27,7 @@ import (
"github.com/schollz/pake/v3" "github.com/schollz/pake/v3"
"github.com/schollz/peerdiscovery" "github.com/schollz/peerdiscovery"
"github.com/schollz/progressbar/v3" "github.com/schollz/progressbar/v3"
"github.com/skip2/go-qrcode"
"golang.org/x/term" "golang.org/x/term"
"golang.org/x/time/rate" "golang.org/x/time/rate"
@ -85,6 +86,7 @@ type Options struct {
TestFlag bool TestFlag bool
GitIgnore bool GitIgnore bool
MulticastAddress string MulticastAddress string
ShowQrCode bool
} }
type SimpleMessage struct { type SimpleMessage struct {
@ -660,6 +662,9 @@ On the other computer run:
CROC_SECRET=%[1]q croc %[2]s CROC_SECRET=%[1]q croc %[2]s
`, c.Options.SharedSecret, flags.String()) `, c.Options.SharedSecret, flags.String())
copyToClipboard(c.Options.SharedSecret) copyToClipboard(c.Options.SharedSecret)
if c.Options.ShowQrCode {
showReceiveCommandQrCode(fmt.Sprintf("%[1]s", c.Options.SharedSecret))
}
if c.Options.Ask { if c.Options.Ask {
machid, _ := machineid.ID() machid, _ := machineid.ID()
fmt.Fprintf(os.Stderr, "\rYour machine ID is '%s'\n", machid) fmt.Fprintf(os.Stderr, "\rYour machine ID is '%s'\n", machid)
@ -832,6 +837,13 @@ On the other computer run:
return err return err
} }
func showReceiveCommandQrCode(command string) {
qrCode, err := qrcode.New(command, qrcode.Medium)
if err == nil {
fmt.Println(qrCode.ToSmallString(false))
}
}
// Receive will receive a file // Receive will receive a file
func (c *Client) Receive() (err error) { func (c *Client) Receive() (err error) {
fmt.Fprintf(os.Stderr, "connecting...") fmt.Fprintf(os.Stderr, "connecting...")
@ -2146,5 +2158,5 @@ func copyToClipboard(str string) {
log.Debugf("error copying to clipboard: %v", err) log.Debugf("error copying to clipboard: %v", err)
return return
} }
fmt.Fprintf(os.Stderr, "Code copied to clipboard") fmt.Fprintf(os.Stderr, "Code copied to clipboard\n")
} }

View File

@ -528,7 +528,7 @@ main() {
local autocomplete_install_rcode local autocomplete_install_rcode
croc_bin_name="croc" croc_bin_name="croc"
croc_version="10.1.0" croc_version="10.1.1"
croc_dl_ext="tar.gz" croc_dl_ext="tar.gz"
croc_base_url="https://github.com/schollz/croc/releases/download" croc_base_url="https://github.com/schollz/croc/releases/download"
prefix="${1}" prefix="${1}"

View File

@ -76,7 +76,17 @@ func Run(debugLevel, host, port, password string, banner ...string) (err error)
func (s *server) start() (err error) { func (s *server) start() (err error) {
log.SetLevel(s.debugLevel) log.SetLevel(s.debugLevel)
log.Debugf("starting with password '%s'", s.password)
// Mask our password in logs
maskedPassword := ""
if len(s.password) > 2 {
maskedPassword = fmt.Sprintf("%c***%c", s.password[0], s.password[len(s.password)-1])
} else {
maskedPassword = s.password
}
log.Debugf("starting with password '%s'", maskedPassword)
s.rooms.Lock() s.rooms.Lock()
s.rooms.rooms = make(map[string]roomInfo) s.rooms.rooms = make(map[string]roomInfo)
s.rooms.Unlock() s.rooms.Unlock()

View File

@ -14,6 +14,7 @@ import (
"math" "math"
"math/big" "math/big"
"net" "net"
"net/http"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -27,7 +28,6 @@ import (
"github.com/schollz/croc/v10/src/mnemonicode" "github.com/schollz/croc/v10/src/mnemonicode"
log "github.com/schollz/logger" log "github.com/schollz/logger"
"github.com/schollz/progressbar/v3" "github.com/schollz/progressbar/v3"
"gortc.io/stun"
) )
const NbPinNumbers = 4 const NbPinNumbers = 4
@ -246,29 +246,21 @@ func SHA256(s string) string {
// PublicIP returns public ip address // PublicIP returns public ip address
func PublicIP() (ip string, err error) { func PublicIP() (ip string, err error) {
// Create a "connection" to the STUN server // ask ipv4.icanhazip.com for the public ip
conn, err := stun.Dial("udp", "stun.l.google.com:19302") // by making http request
// if the request fails, return nothing
resp, err := http.Get("http://ipv4.icanhazip.com")
if err != nil { if err != nil {
return return
} }
defer resp.Body.Close()
// Build and send a binding request to the STUN server // read the body of the response
message := stun.MustBuild(stun.TransactionID, stun.BindingRequest) // and return the ip address
if err = conn.Do(message, func(res stun.Event) { buf := new(bytes.Buffer)
if res.Error != nil { buf.ReadFrom(resp.Body)
return ip = strings.TrimSpace(buf.String())
}
// Process the binding response
var xorAddr stun.XORMappedAddress
if err := xorAddr.GetFrom(res.Message); err != nil {
return
}
ip = xorAddr.IP.String()
}); err != nil {
return
}
return return
} }