-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
66 lines (53 loc) · 1.96 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"flag"
"log"
"github.com/ChandraNarreddy/sillyproxy/utility"
)
func main() {
// sillyProxy -keypass xyz -keystore abc -minTLSVer 1 -bind :8443 -routes file
keyStoreFile = flag.String("keystore", "", "keystore file with the absolute path")
hostname := flag.String("hostname", "",
"Hostname under which the pem content needs to be written to."+
"Leave blank if you wish this certificate to be bound as default")
keyStorePass := flag.String("keypass", "", "Password to the keystore")
minTLSVer := flag.Uint("minTLSver", 1,
"global configuration for minimum TLS version - \n\t"+
"1 for 1.1, \n\t 2 for 1.2, \n\t3 for 1.3. \n\t Default is 1.1")
bindAddr := flag.String("bind", ":443", "address and port to bind")
pemCertFile := flag.String("pemCert", "",
"location of certificate file(PEM) to read")
pemKeyFile := flag.String("pemKey", "",
"location of privateKey file(PEM) to read")
routeMapFilePath := flag.String("routes", "", "path to routes map file")
// let us parse the flags
flag.Parse()
//Usage:: sillyProxy -options KeyStore for keystore related operations
// sillyProxy -options to run the proxy
if len(flag.Args()) > 0 {
switch flag.Args()[0] {
case "KeyStore", "keystore":
err := utility.GenerateKeyStore(keyStoreFile, hostname, pemCertFile, pemKeyFile,
keyStorePass)
if err != nil {
log.Printf(err.Error())
}
return
}
}
/***profiling code
f, err := os.Create(fmt.Sprintf("SP_CPU.prof_%#v", time.Now().Unix()))
if err != nil {
log.Fatal("could not create CPU profile: ", err)
}
if err := pprof.StartCPUProfile(f); err != nil {
log.Fatal("could not start CPU profile: ", err)
}
defer pprof.StopCPUProfile()
*****profiling****/
sillyProxy, sillyProxyErr := SillyProxy(keyStoreFile, keyStorePass, minTLSVer, bindAddr, routeMapFilePath)
if sillyProxyErr != nil {
log.Fatalf("SillyProxy failed with error: %#v", sillyProxyErr.Error())
}
log.Fatal(sillyProxy.ListenAndServeTLS("", "").Error())
}