Add experimental support for SOCKS5 proxies.

socks
Martin Dosch 5 months ago
parent e5c2d417e0
commit 7677d2907a
No known key found for this signature in database
GPG Key ID: 52A57CFCE13D657D

@ -7,6 +7,7 @@ package main
import (
"fmt"
"net"
"os"
"strings"
"github.com/xmppo/go-xmpp" // BSD-3-Clause
@ -14,27 +15,31 @@ import (
)
func connect(options xmpp.Options, directTLS bool) (*xmpp.Client, error) {
proxy := os.Getenv("HTTP_PROXY")
// Look up SRV records if server is not specified manually.
if options.Host == "" {
server := options.User[strings.Index(options.User, "@")+1:]
// Look up xmpp-client SRV records.
srvMixed, err := xmppsrv.LookupClient(server)
if len(srvMixed) > 0 && err == nil {
for _, adr := range srvMixed {
if !directTLS && adr.Type != "xmpps-client" {
// Use StartTLS
options.NoTLS = true
options.StartTLS = true
} else if adr.Type == "xmpps-client" {
// Use direct TLS
options.NoTLS = false
options.StartTLS = false
}
options.Host = net.JoinHostPort(adr.Target, fmt.Sprint(adr.Port))
// Connect to server
client, err := options.NewClient()
if err == nil {
return client, nil
// Don't do SRV look ups if proxy is set.
if proxy == "" {
// Look up xmpp-client SRV records.
srvMixed, err := xmppsrv.LookupClient(server)
if len(srvMixed) > 0 && err == nil {
for _, adr := range srvMixed {
if !directTLS && adr.Type != "xmpps-client" {
// Use StartTLS
options.NoTLS = true
options.StartTLS = true
} else if adr.Type == "xmpps-client" {
// Use direct TLS
options.NoTLS = false
options.StartTLS = false
}
options.Host = net.JoinHostPort(adr.Target, fmt.Sprint(adr.Port))
// Connect to server
client, err := options.NewClient()
if err == nil {
return client, nil
}
}
}
}

@ -7,7 +7,7 @@ require (
github.com/beevik/etree v1.3.0
github.com/gabriel-vasile/mimetype v1.4.3
github.com/pborman/getopt/v2 v2.1.0
github.com/xmppo/go-xmpp v0.0.2-0.20240112111252-3f0cbac30767
github.com/xmppo/go-xmpp v0.0.2-0.20240113135810-685570cbd85c
salsa.debian.org/mdosch/xmppsrv v0.2.5
)

@ -25,8 +25,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/xmppo/go-xmpp v0.0.2-0.20240112111252-3f0cbac30767 h1:MUE5VQvCDO/EjxoYILDcp7bo6lFtwFb18klQm21TynI=
github.com/xmppo/go-xmpp v0.0.2-0.20240112111252-3f0cbac30767/go.mod h1:PcCOIcUOWDL2z/WvkQNUzT08pGK6cAF/edZVX8Ik8bI=
github.com/xmppo/go-xmpp v0.0.2-0.20240113135810-685570cbd85c h1:XIrdn4Tb5XbKbtectNcrRSsk60AKbg+6qHE9g05dxEs=
github.com/xmppo/go-xmpp v0.0.2-0.20240113135810-685570cbd85c/go.mod h1:upNxcOLQxelaw+L/qfOkA6joGmktdxMSGBbaFqkFA7Y=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=

@ -10,18 +10,22 @@ import (
"fmt"
"log"
"net/http"
"net/url"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
"github.com/beevik/etree" // BSD-2-clause
"github.com/gabriel-vasile/mimetype" // MIT License
"github.com/xmppo/go-xmpp" // BSD-3-Clause
)
func httpUpload(client *xmpp.Client, iqc chan xmpp.IQ, jserver string, filePath string) string {
func httpUpload(client *xmpp.Client, iqc chan xmpp.IQ, jserver string, filePath string,
timeout time.Duration,
) string {
var uploadComponent string
var maxFileSize int64
@ -190,7 +194,19 @@ func httpUpload(client *xmpp.Client, iqc chan xmpp.IQ, jserver string, filePath
log.Fatal("http-upload: upload slot does not provide https")
}
// Upload file
httpClient := &http.Client{}
httpTransport := &http.Transport{
IdleConnTimeout: timeout,
TLSHandshakeTimeout: timeout,
}
proxyEnv := os.Getenv("HTTP_PROXY")
if proxyEnv != "" {
proxyURL, err := url.Parse(proxyEnv)
if err != nil {
log.Fatal(err)
}
httpTransport.Proxy = http.ProxyURL(proxyURL)
}
httpClient := &http.Client{Transport: httpTransport}
req, err := http.NewRequest(http.MethodPut, iqHTTPUploadSlotXMLPutURL.Value,
buffer)
if err != nil {

@ -18,8 +18,8 @@ import (
"time"
"github.com/ProtonMail/gopenpgp/v2/crypto" // MIT License
"github.com/xmppo/go-xmpp" // BSD-3-Clause
"github.com/pborman/getopt/v2" // BSD-3-Clause
"github.com/xmppo/go-xmpp" // BSD-3-Clause
)
type configuration struct {
@ -384,7 +384,7 @@ func main() {
if *flagHTTPUpload != "" {
message = httpUpload(client, iqc, tlsConfig.ServerName,
*flagHTTPUpload)
*flagHTTPUpload, timeout)
}
if *flagOOBFile != "" {

Loading…
Cancel
Save