From 9632b95e113a77159192d343ca8818f0c9284fb6 Mon Sep 17 00:00:00 2001 From: clerie Date: Sun, 24 Nov 2024 16:43:16 +0100 Subject: [PATCH] Init scan-to-gpg --- README.md | 8 +-- go.mod | 18 ++++-- go.sum | 23 +++++-- main.go | 183 +++++++++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 188 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index fed366a..d9f10eb 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,16 @@ -# ftp-http-forwarder +# scan-to-gpg ## Usage ``` -host string Host (default "localhost") - -pass string - Password for login (default "123456") -port int Port (default 2121) - -target string - target url -user string Username for login (default "admin") + -pass string + Password for login (default "123456") ``` diff --git a/go.mod b/go.mod index 8f49680..226546a 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,22 @@ -module github.com/luelista/ftp-http-forwarder +module clerie.de/scan-to-gpg go 1.20 -require goftp.io/server v0.4.1 +require ( + github.com/ProtonMail/gopenpgp/v3 v3.0.0 + goftp.io/server v0.4.1 +) require ( + github.com/ProtonMail/go-crypto v1.1.0 // indirect + github.com/cloudflare/circl v1.3.7 // indirect github.com/minio/minio-go/v6 v6.0.46 // indirect github.com/minio/sha256-simd v0.1.1 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect - golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 // indirect - golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect - golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e // indirect - golang.org/x/text v0.3.2 // indirect + github.com/pkg/errors v0.9.1 // indirect + golang.org/x/crypto v0.17.0 // indirect + golang.org/x/net v0.10.0 // indirect + golang.org/x/sys v0.16.0 // indirect + golang.org/x/text v0.14.0 // indirect gopkg.in/ini.v1 v1.42.0 // indirect ) diff --git a/go.sum b/go.sum index 2a1949f..78f0ed2 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,9 @@ +github.com/ProtonMail/go-crypto v1.1.0 h1:OnlSGxXflfrWJESDsGQOmACNQRM9IflG3q8XTrOqvbE= +github.com/ProtonMail/go-crypto v1.1.0/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= +github.com/ProtonMail/gopenpgp/v3 v3.0.0 h1:lqsrNKFv0U4tRYRdaMA8qzh3TACaDTg3iJiv7MFFmuM= +github.com/ProtonMail/gopenpgp/v3 v3.0.0/go.mod h1:XXZYIzOSEtEhKCyDcq/xepg3zuANcL5amIjwF4XZbNg= +github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= +github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -15,6 +21,8 @@ github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKU github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= @@ -25,28 +33,33 @@ github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:s github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= goftp.io/server v0.4.1 h1:x7KG4HIxSMdK/rpYhExMinRN/aO/T9icvaG/B5e/XfY= goftp.io/server v0.4.1/go.mod h1:hFZeR656ErRt3ojMKt7H10vQ5nuWV1e0YeUTeorlR6k= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= +golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 h1:Ao/3l156eZf2AW5wK8a7/smtodRU+gha3+BeqJ69lRk= golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e h1:D5TXcfTk7xF7hvieo4QErS3qqCB4teTffacDWr7CI+0= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= +golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= gopkg.in/ini.v1 v1.42.0 h1:7N3gPTt50s8GuLortA00n8AqRTk75qOP98+mTPpgzRk= gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/main.go b/main.go index 0b6446e..9a22d17 100644 --- a/main.go +++ b/main.go @@ -3,21 +3,17 @@ package main import ( "errors" "io" + "io/ioutil" "os" "time" - //"strings" - "net/url" - "net/http" - "flag" - "log" - "fmt" + "flag" + "log" "path/filepath" - "strings" "goftp.io/server" + "github.com/ProtonMail/gopenpgp/v3/crypto" ) type ForwarderDriver struct { - TargetURL string server.Perm } @@ -103,36 +99,169 @@ func (driver *ForwarderDriver) GetFile(path string, offset int64) (int64, io.Rea func (driver *ForwarderDriver) PutFile(destPath string, data io.Reader, appendData bool) (int64, error) { log.Printf("Forwarding %v (%v)", destPath, filepath.Base(destPath)) - destUrl := strings.Replace(strings.Replace( - driver.TargetURL, - "{escaped_path}", url.QueryEscape(destPath), -1), - "{escaped_name}", url.QueryEscape(filepath.Base(destPath)), -1) - log.Printf("Dest URL %v", destUrl) - client := &http.Client{} - req, err := http.NewRequest("PUT", destUrl, data) - resp, err := client.Do(req) - log.Printf("Status: %v, Transferred bytes: %v, errmes: %v", resp.Status, resp.Request.ContentLength, err) - if resp.StatusCode >= 300 { - return 0, fmt.Errorf("server returned error status %s", resp.Status) - } - return resp.Request.ContentLength, err + log.Printf("ReadAll…") + contents, err := ioutil.ReadAll(data) + if err != nil { + log.Printf("Error: %v", err) + return 0, err + } + + pubkey := `-----BEGIN PGP PUBLIC KEY BLOCK----- + +mQINBGYdTGwBEACj6qML9iydxEqXWNGakFTRaNNf+a7PBGSF6N4S21zJ3KOIENJH +NR5Rid6iKSa9j/z3eC2mqgxeSrQBlZ5jGp1yTaa83hdQFiB/XWEg7xR6XNRsoHSk +DohvzWB2RjAAd/QlQfLELjOXXSZQxBoPemt2nDpJTW6oC1BXZgaiezdxQhPDrakI +eGI/Ge1vMCyv3XBKdcSv9jIAeiEGK9/GLJ/rTUj5Pe3ie2GRdHifvwTdyXEc3pAo +TAmQo+xY5tchJFY7G4jhkel+tkhofb3+TSNZ1bqhJcidlk4DYwLhuY8D2Pdj7eye +652cJc69swWlb/id7lPuoMib1BgNAN4uH2qSNrEyFgi8YpuBQAR7kLDLO4roFNk1 +gyT/1knxmKiF6VGJy5vxFFTzs6qL2UEBeD05gJLbGNwseg9d/rEMXtsMd+07S7Rr +ZNIX9nxX2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G+iWCE0ns7LC+xp/qy5zYbykGVaHjgieL +8gfThcHL9BErPQsfLYNmQ2aWEpFTKCIaIty1Aop6M4p3kcqct/iLazEZvjw/MBD2 +RpcHAGhYQ0gDC/saSkgrdHNRKi7BfArWnW17sjZ9w7DWjs1lkIWvuOx4lZfEIqUn +xe+dYVbUx/UAEQEAAYkCMwQYAQgAJxYhBAyYL4e3r7oPUE+QomKedBlHyHkoBQJm +HU5CAxsgBAUJAeEzgAAA7Z8QAJEZwrAzZ0/7eyM/hsg1heXC3G9YVzCSO+3nH5We +6EqqxI9TnRa3ZQrHLbUAEmW/MgmV5QuHrDq1/cJzFe6+fCPXhYH8qrYnvGEgiat6 +B2Qh6aRJpZrN2EVxw4piUTqBuNXmQCE0jrmeNfTYLjFFjinjyUGCjUJilBA+UzC0 +fXyex0Se4ayfrhAG7vidSbAYAiUwQpRP4N+AVORpYb0IqnRvo0ScPEUMmelzKWFK +j4awEUvw5qC5s74WsUa2QdPecj6KmRQNKjupJdQVmEMYy5nXfM6yKBfbX8C8e2Vm +iif/zu1p6tQAI9s1nFwbmexzmmXOWq+t1KNj+/8ZthtE2Jhy8iGSCbpMjkF3Diq6 +AU0O/9ReszcRBHJWavGta8Vfhs9YG2XJjt0JZvGQNjs3kJ0apLLUpJfh1s0Ez5sh +y7vmqlcrC9y86RrfGTOL7OeO30a8CVfGEZi5ut2EqmWKk9s6RwCAqxNn89XU4rCD +weGu/A/SRFy/KKzKhiY4pZCwUzDpslmlNelEWDXwOJmIfO0IbPWIb8yoZZpvYMWR +3oWqqWmw/IR/6xS7sKoKo3A6PVQRzWeLmywRjjfPlkMg5lE60zn6jdL+dyEXBfip +eioP7bhmesMcSxs89lJr6bJ6+gWm4/JJUOJgUFWUbZsjTb8iPITi+UJa1DWmesN0 +cnkT +=NbZJ +-----END PGP PUBLIC KEY BLOCK-----` + + log.Printf("NewKeyFromArmored…") + publicKey, err := crypto.NewKeyFromArmored(pubkey) + if err != nil { + log.Printf("Error: %v", err) + return 0, err + } + log.Printf("crypto.PGP…") + pgp := crypto.PGP() + encHandle, err := pgp.Encryption().Recipient(publicKey).New() + if err != nil { + log.Printf("Error: %v", err) + return 0, err + } + log.Printf("Encrypt…") + pgpMessage, err := encHandle.Encrypt(contents) + if err != nil { + log.Printf("Error: %v", err) + return 0, err + } + log.Printf("ArmorBytes…") + armored, err := pgpMessage.ArmorBytes() + if err != nil { + log.Printf("Error: %v", err) + return 0, err + } + + log.Printf("WriteFile…") + os.WriteFile("file.txt", armored, 0666) + + log.Printf("Status: %v, Transferred bytes: %v, errmes: %v", 0, len(contents), err) + return int64(len(contents)), err } type ForwarderDriverFactory struct { - TargetURL string server.Perm } func (factory *ForwarderDriverFactory) NewDriver() (server.Driver, error) { - return &ForwarderDriver{factory.TargetURL, factory.Perm}, nil + return &ForwarderDriver{factory.Perm}, nil } func main() { var ( - target = flag.String("target", "", "target url") user = flag.String("user", "admin", "Username for login") pass = flag.String("pass", "123456", "Password for login") port = flag.Int("port", 2121, "Port") @@ -140,10 +269,8 @@ func main() { passiveports = flag.String("passiveports", "2130-2134", "Passive ports") ) flag.Parse() - if *target == "" { - log.Fatalf("Please set a target url with -target") - } - factory := &ForwarderDriverFactory{TargetURL: *target, Perm: server.NewSimplePerm("user","group")} + + factory := &ForwarderDriverFactory{Perm: server.NewSimplePerm("user","group")} opts := &server.ServerOpts{ Factory: factory,