Initial commit

This commit is contained in:
David Stotijn 2019-11-17 09:54:15 +01:00
commit 26ec9f72e5
3 changed files with 61 additions and 0 deletions

5
go.mod Normal file
View file

@ -0,0 +1,5 @@
module github.com/dstotijn/gurp
go 1.13
require github.com/google/martian v2.1.0+incompatible

2
go.sum Normal file
View file

@ -0,0 +1,2 @@
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=

54
main.go Normal file
View file

@ -0,0 +1,54 @@
package main
import (
"crypto/tls"
"crypto/x509"
"log"
"net"
"os"
"os/signal"
"time"
"github.com/google/martian"
"github.com/google/martian/mitm"
)
func main() {
p := martian.NewProxy()
defer p.Close()
tlsc, err := tls.LoadX509KeyPair("/Users/dstotijn/.ssh/gurp_cert.pem", "/Users/dstotijn/.ssh/gurp_key.pem")
if err != nil {
log.Fatal(err)
}
priv := tlsc.PrivateKey
x509c, err := x509.ParseCertificate(tlsc.Certificate[0])
if err != nil {
log.Fatal(err)
}
mc, err := mitm.NewConfig(x509c, priv)
if err != nil {
log.Fatal(err)
}
mc.SetValidity(time.Hour)
mc.SetOrganization("Gurp, Inc.")
p.SetMITM(mc)
l, err := net.Listen("tcp", ":8080")
if err != nil {
log.Fatal(err)
}
go func() {
if err := p.Serve(l); err != nil {
log.Println(err)
}
}()
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, os.Interrupt, os.Kill)
<-sigc
}