Can specify certs now
This commit is contained in:
parent
d081639b88
commit
7a59ef6be3
2 changed files with 23 additions and 23 deletions
38
api/auth.go
38
api/auth.go
|
@ -6,15 +6,12 @@ import (
|
|||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
)
|
||||
|
||||
const (
|
||||
privKeyPath = "keys/app.rsa" // openssl genrsa -out app.rsa keysize
|
||||
pubKeyPath = "keys/app.rsa.pub" // openssl rsa -in app.rsa -pubout > app.rsa.pub
|
||||
tokenName = "AccessToken"
|
||||
tokenName = "AccessToken"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -26,31 +23,28 @@ var (
|
|||
errGenericError = errors.New("generic error")
|
||||
)
|
||||
|
||||
func init() {
|
||||
func SetupCerts(p string) error {
|
||||
var err error
|
||||
dir, _ := filepath.Abs(filepath.Dir(privKeyPath))
|
||||
fmt.Println(dir)
|
||||
|
||||
signKey, err = ioutil.ReadFile(privKeyPath)
|
||||
|
||||
if err != nil {
|
||||
// Before exploding, check up one level...
|
||||
signKey, err = ioutil.ReadFile("../../" + privKeyPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Error reading private key: ", err)
|
||||
return
|
||||
}
|
||||
log.Fatalf("Path error: ", err)
|
||||
}
|
||||
|
||||
// openssl genrsa -out app.rsa keysize
|
||||
privKeyPath := fmt.Sprintf("%vapp.rsa", p)
|
||||
signKey, err = ioutil.ReadFile(privKeyPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Error reading private key: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
// openssl rsa -in app.rsa -pubout > app.rsa.pub
|
||||
pubKeyPath := fmt.Sprintf("%vapp.rsa.pub", p)
|
||||
verifyKey, err = ioutil.ReadFile(pubKeyPath)
|
||||
if err != nil {
|
||||
// Before exploding, check up one level...
|
||||
verifyKey, err = ioutil.ReadFile("../../" + pubKeyPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Error reading public key: ", err)
|
||||
return
|
||||
}
|
||||
log.Fatalf("Error reading public key: ", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type authHandler func(http.ResponseWriter, *http.Request) error
|
||||
|
|
|
@ -24,8 +24,13 @@ func main() {
|
|||
Flags: []cli.Flag{
|
||||
cli.IntFlag{
|
||||
Name: "port",
|
||||
Value: 8901,
|
||||
Usage: "HTTP service port",
|
||||
Value: 8901,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "keys",
|
||||
Usage: "path to keys",
|
||||
Value: "keys/",
|
||||
},
|
||||
},
|
||||
Action: cmdServe,
|
||||
|
@ -56,6 +61,7 @@ func cmdServe(c *cli.Context) {
|
|||
httpAddr := fmt.Sprintf(":%v", c.Int("port"))
|
||||
|
||||
datastore.Connect()
|
||||
api.SetupCerts(c.String("keys"))
|
||||
|
||||
m := http.NewServeMux()
|
||||
m.Handle("/api/", http.StripPrefix("/api", api.Handler()))
|
||||
|
|
Reference in a new issue