Skip to content

Commit

Permalink
Revise the SSL support implementation details
Browse files Browse the repository at this point in the history
- Remove the complexity around the NoSSL parameter -- the harness can proxy SSL without a problem
- Change naming convention to Ssl from SSL.  e.g. HttpSSLKey is inconsistent with itself.
- Skip adding no-op SSL parameters to sample apps (minus booking)
  • Loading branch information
robfig committed Aug 4, 2013
1 parent 0b47ba2 commit 7f06f0d
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 46 deletions.
12 changes: 3 additions & 9 deletions harness/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type App struct {
BinaryPath string // Path to the app executable
Port int // Port to pass as a command line argument.
cmd AppCmd // The last cmd returned.
NoSsl bool // set to true to force-disable ssl
}

func NewApp(binPath string) *App {
Expand All @@ -26,7 +25,7 @@ func NewApp(binPath string) *App {

// Return a command to run the app server using the current configuration.
func (a *App) Cmd() AppCmd {
a.cmd = NewAppCmd(a.BinaryPath, a.Port, a.NoSsl)
a.cmd = NewAppCmd(a.BinaryPath, a.Port)
return a.cmd
}

Expand All @@ -41,16 +40,11 @@ type AppCmd struct {
*exec.Cmd
}

func NewAppCmd(binPath string, port int, nossl bool) AppCmd {
var ssl_param string
if nossl == true {
ssl_param = fmt.Sprint("-nossl=true")
}
func NewAppCmd(binPath string, port int) AppCmd {
cmd := exec.Command(binPath,
fmt.Sprintf("-port=%d", port),
fmt.Sprintf("-importPath=%s", revel.ImportPath),
fmt.Sprintf("-runMode=%s", revel.RunMode),
ssl_param)
fmt.Sprintf("-runMode=%s", revel.RunMode))
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
return AppCmd{cmd}
}
Expand Down
5 changes: 1 addition & 4 deletions harness/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ var (
port *int = flag.Int("port", 0, "By default, read from app.conf")
importPath *string = flag.String("importPath", "", "Go Import Path for the app.")
srcPath *string = flag.String("srcPath", "", "Path to the source root.")
noSsl *bool = flag.Bool("nossl", false, "Set to ignore SSL parameters.")
// So compiler won't complain if the generated code doesn't reference reflect package...
_ = reflect.Invalid
Expand Down Expand Up @@ -296,9 +295,7 @@ func main() {
revel.TestSuites = []interface{}{ {{range .TestSuites}}
(*{{index $.ImportPaths .ImportPath}}.{{.StructName}})(nil),{{end}}
}
if *noSsl == true {
revel.HttpSSL = false
}
revel.Run(*port)
}
`
Expand Down
26 changes: 15 additions & 11 deletions harness/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ func (hp *Harness) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("Upgrade") == "websocket" {
proxyWebsocket(w, r, hp.serverHost)
} else {
if revel.HttpSSL == true {
hp.proxy.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
}
hp.proxy.ServeHTTP(w, r)
}
}
Expand All @@ -90,6 +85,10 @@ func NewHarness() *Harness {

addr := revel.HttpAddr
port := revel.Config.IntDefault("harness.port", 0)
scheme := "http"
if revel.HttpSsl {
scheme = "https"
}

// If the server is running on the wildcard address, use "localhost"
if addr == "" {
Expand All @@ -100,13 +99,19 @@ func NewHarness() *Harness {
port = getFreePort()
}

serverUrl, _ := url.ParseRequestURI(fmt.Sprintf("http://%s:%d", addr, port))
serverUrl, _ := url.ParseRequestURI(fmt.Sprintf(scheme+"://%s:%d", addr, port))

harness := &Harness{
port: port,
serverHost: serverUrl.String()[len("http://"):],
serverHost: serverUrl.String()[len(scheme+"://"):],
proxy: httputil.NewSingleHostReverseProxy(serverUrl),
}

if revel.HttpSsl {
harness.proxy.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
}
return harness
}

Expand All @@ -122,7 +127,6 @@ func (h *Harness) Refresh() (err *revel.Error) {
return
}

h.app.NoSsl = true
h.app.Port = h.port
if err2 := h.app.Cmd().Start(); err2 != nil {
return &revel.Error{
Expand Down Expand Up @@ -153,9 +157,9 @@ func (h *Harness) Run() {
revel.INFO.Printf("Listening on %s", addr)

var err error
if revel.HttpSSL == true {
err = http.ListenAndServeTLS(addr, revel.HttpSSLCert,
revel.HttpSSLKey, h)
if revel.HttpSsl {
err = http.ListenAndServeTLS(addr, revel.HttpSslCert,
revel.HttpSslKey, h)
} else {
err = http.ListenAndServe(addr, h)
}
Expand Down
20 changes: 10 additions & 10 deletions revel.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ var (
// run on a random port and proxied.
HttpPort int // e.g. 9000
HttpAddr string // e.g. "", "127.0.0.1"
HttpSSL bool // e.g. true
HttpSSLCert string // e.g. "/path/to/cert.pem"
HttpSSLKey string // e.g. "/path/to/key.pem"
HttpSsl bool // e.g. true if using ssl
HttpSslCert string // e.g. "/path/to/cert.pem"
HttpSslKey string // e.g. "/path/to/key.pem"

// All cookies dropped by the framework begin with this prefix.
CookiePrefix string
Expand Down Expand Up @@ -136,18 +136,18 @@ func Init(mode, importPath, srcPath string) {
DevMode = Config.BoolDefault("mode.dev", false)
HttpPort = Config.IntDefault("http.port", 9000)
HttpAddr = Config.StringDefault("http.addr", "")
HttpSSL = Config.BoolDefault("http.ssl", false)
HttpSSLCert = Config.StringDefault("http.sslcert", "")
HttpSSLKey = Config.StringDefault("http.sslkey", "")

if HttpSSL == true {
if HttpSSLCert == "" {
HttpSsl = Config.BoolDefault("http.ssl", false)
HttpSslCert = Config.StringDefault("http.sslcert", "")
HttpSslKey = Config.StringDefault("http.sslkey", "")
if HttpSsl {
if HttpSslCert == "" {
log.Fatalln("No http.sslcert provided.")
}
if HttpSSLKey == "" {
if HttpSslKey == "" {
log.Fatalln("No http.sslkey provided.")
}
}

AppName = Config.StringDefault("app.name", "(not set)")
CookiePrefix = Config.StringDefault("cookie.prefix", "REVEL")
TemplateDelims = Config.StringDefault("template.delimiters", "")
Expand Down
1 change: 0 additions & 1 deletion revel/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,5 @@ func runApp(args []string) {
errorf("Failed to build app: %s", err)
}
app.Port = port
app.NoSsl = false
app.Cmd().Run()
}
3 changes: 0 additions & 3 deletions samples/chat/conf/app.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ app.name=chat
app.secret=pJLzyoiDe17L36mytqC912j81PfTiolHm1veQK6Grn1En3YFdB5lvEHVTwFEaWvj
http.addr=
http.port=9000
http.ssl=false
http.sslcert=
http.sslkey=

module.static=github.com/robfig/revel/modules/static

Expand Down
3 changes: 0 additions & 3 deletions samples/i18n/conf/app.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ app.name=i18n
app.secret=bPlNFGdSC2wd8f2QnFhk5A84JJjKWZdKH9H2FHFuvUs9Jz8UvBHv3Vc5awx39ivu
http.addr=
http.port=9000
http.ssl=false
http.sslcert=
http.sslkey=
cookie.prefix=REVEL

# The language cookie name used to store the current language.
Expand Down
4 changes: 2 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ func Run(port int) {
fmt.Printf("Listening on port %d...\n", port)
}()

if HttpSSL == true {
if HttpSsl {
ERROR.Fatalln("Failed to listen:",
Server.ListenAndServeTLS(HttpSSLCert, HttpSSLKey))
Server.ListenAndServeTLS(HttpSslCert, HttpSslKey))
} else {
ERROR.Fatalln("Failed to listen:", Server.ListenAndServe())
}
Expand Down
3 changes: 0 additions & 3 deletions testdata/i18n/config/test_app.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ app.name={{ .AppName }}
app.secret={{ .Secret }}
http.addr=
http.port=9000
http.ssl=false
http.sslcert=
http.sslkey=
cookie.prefix=REVEL

i18n.default_language=en
Expand Down

0 comments on commit 7f06f0d

Please sign in to comment.