]> Cypherpunks.ru repositories - ucspi.git/commitdiff
proxy
authorSergey Matveev <stargrave@stargrave.org>
Tue, 10 Aug 2021 12:02:08 +0000 (15:02 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 10 Aug 2021 12:02:08 +0000 (15:02 +0300)
README
cmd/proxy/main.go [new file with mode: 0644]

diff --git a/README b/README
index 8be9670fbe97cba7f7415aa7c6074e6c0956d4ae..c71493f50b07b6b7d9629cfeefce63608ce52ef0 100644 (file)
--- a/README
+++ b/README
@@ -29,5 +29,7 @@ that OpenSSL-dependant ones, or also much more complicated stunnel.
   disable authentication completely with -name "". -show option prints
   connection state after handshake and outputs certificates information.
 
+* cmd/proxy: proxy between UCSPI server and UCSPI client
+
 go.cypherpunks.ru/ucspi is free software: see the file COPYING for
 copying conditions.
diff --git a/cmd/proxy/main.go b/cmd/proxy/main.go
new file mode 100644 (file)
index 0000000..3fd4f77
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ucspi/cmd/tlsc -- UCSPI TLS client
+Copyright (C) 2021 Sergey Matveev <stargrave@stargrave.org>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, version 3 of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package main
+
+import (
+       "flag"
+       "fmt"
+       "io"
+       "log"
+       "os"
+)
+
+func main() {
+       flag.Usage = func() {
+               fmt.Fprintln(os.Stderr, "Usage: UCSPIserver [address] UCSPIclient [address] ucspi-proxy")
+       }
+       flag.Parse()
+       log.SetFlags(log.Lshortfile)
+
+       r := os.NewFile(6, "R")
+       w := os.NewFile(7, "W")
+       if r == nil {
+               log.Fatalln("no 6 file descriptor")
+       }
+       if w == nil {
+               log.Fatalln("no 7 file descriptor")
+       }
+       copiers := make(chan struct{})
+       var err error
+       go func() {
+               _, err = io.Copy(w, os.Stdin)
+               w.Close()
+               close(copiers)
+       }()
+       go func() {
+               io.Copy(os.Stdout, r)
+       }()
+       <-copiers
+       if err != nil {
+               log.Fatalln(err)
+       }
+}