Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPS #9

Open
addam opened this issue Jun 26, 2017 · 4 comments
Open

HTTPS #9

addam opened this issue Jun 26, 2017 · 4 comments

Comments

@addam
Copy link

addam commented Jun 26, 2017

In order to have terrain on a HTTPS-enabled webpage, we need even the terrain requests to go through SSL. Is there an option or a simple modification for this?

@JJch331
Copy link

JJch331 commented Apr 9, 2018

I have the same problem. Did anyone find the answer ?

@addam
Copy link
Author

addam commented Apr 9, 2018

Speaking for myself, no. We ended up coding our own server since we wanted to store the tiles in a database anyway.

@DhinendraRajapakse
Copy link

hi i did a small fix myself feel free to use it

`// Implements a server for distributing Cesium terrain tilesets
package main

import (
"flag"
"fmt"
myhandlers "github.com/geo-data/cesium-terrain-server/handlers"
"github.com/geo-data/cesium-terrain-server/log"
"github.com/geo-data/cesium-terrain-server/stores/fs"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
l "log"
"net/http"
"os"
)

func main(){
port := flag.Uint("port", 8000, "the port on which the server listens")
tilesetRoot := flag.String("dir", ".", "the root directory under which tileset directories reside")
webRoot := flag.String("web-dir", "", "(optional) the root directory containing static files to be served")
memcached := flag.String("memcached", "", "(optional) memcached connection string for caching tiles e.g. localhost:11211")
baseTerrainUrl := flag.String("base-terrain-url", "/tilesets", "base url prefix under which all tilesets are served")
noRequestLog := flag.Bool("no-request-log", false, "do not log client requests for resources")
https := flag.Bool("https", false, "if https is enabled")
pemPath := flag.String("pemPath", "", "Path to pem files cert.pem and key.pem")
logging := NewLogOpt()
flag.Var(logging, "log-level", "level at which logging occurs. One of crit, err, notice, debug")
limit := NewLimitOpt()
limit.Set("1MB")
flag.Var(limit, "cache-limit", the memory size in bytes beyond which resources are not cached. Other memory units can be specified by suffixing the number with kB, MB, GB or TB)
flag.Parse()

// Set the logging
log.SetLog(l.New(os.Stderr, "", l.LstdFlags), logging.Priority)

// Get the tileset store
store := fs.New(*tilesetRoot)

r := mux.NewRouter()
r.HandleFunc(*baseTerrainUrl+"/{tileset}/layer.json", myhandlers.LayerHandler(store))
r.HandleFunc(*baseTerrainUrl+"/{tileset}/{z:[0-9]+}/{x:[0-9]+}/{y:[0-9]+}.terrain", myhandlers.TerrainHandler(store))
if len(*webRoot) > 0 {
	log.Debug(fmt.Sprintf("serving static resources from %s", *webRoot))
	r.PathPrefix("/").Handler(http.FileServer(http.Dir(*webRoot)))
}

handler := myhandlers.AddCorsHeader(r)
if len(*memcached) > 0 {
	log.Debug(fmt.Sprintf("memcached enabled for all resources: %s", *memcached))
	handler = myhandlers.NewCache(*memcached, handler, limit.Value, myhandlers.NewLimit)
}

if *noRequestLog == false {
	handler = handlers.CombinedLoggingHandler(os.Stdout, handler)
}

http.Handle("/", handler)

if *https {

	if len(*pemPath) == 0 {
		log.Notice(fmt.Sprintf("Https Server Cannot be run with out  -pemPath specified %s", *pemPath))
		os.Exit(1)
	}

	keyFilesExist := true
	_, err := os.Stat(*pemPath + "/key.pem")
	if err != nil {
		keyFilesExist = false
	} else if os.IsNotExist(err) {
		keyFilesExist = false
	}

	_, err = os.Stat(*pemPath + "/cert.pem")
	if err != nil {
		keyFilesExist = false
	} else if os.IsNotExist(err) {
		keyFilesExist = false
	}

	if !keyFilesExist {
		log.Notice(fmt.Sprintf("Https Server Cannot be run key.pem and cert.pem do not exist in dir %s" + *pemPath))
		os.Exit(1)
	}

	log.Notice(fmt.Sprintf("Https Server listening on port %d", *port))
	
	err_http := http.ListenAndServeTLS(fmt.Sprintf(":%d", *port), *pemPath+"/cert.pem", *pemPath+"/key.pem", nil)
	if err_http != nil {
		fmt.Println(err_http)
	}

	os.Exit(1)
} else {
	log.Notice(fmt.Sprintf("Http Server listening on port %d", *port))

	err_http := http.ListenAndServe(fmt.Sprintf(":%d", *port), nil)
	if err_http != nil {
		fmt.Println(err_http)
	}
	os.Exit(1)
}

}
`

@spingerfitz
Copy link

spingerfitz commented Jan 20, 2021

The fix from @DhinendraRajapakse worked for me.
Some extra notes: The fix is a tweaked version of <$GOPATH>/src/github.com/geo-data/cesium-terrain-server/cmd/cesium-terrain-server/main.go. The fix uses a key.pem and cert.pem file for the certification. These must be in place in directory which you provide at starting cesium-terrain-server.
Put this fix, key.pem, cert.pem in place, recompile the sourcecode and you are ready to go by something like:

# cesium-terrain-server -dir <tileset directory> -pemPath <SSL certificates directory> -https true
2021/01/20 08:17:56 NOTICE: Https Server listening on port 8000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants