github.com/brimstone/sbuca@v0.0.0-20151202175429-8691d9eba5c5/server/ca.go (about)

     1  package server
     2  
     3  import (
     4  	"github.com/go-martini/martini"
     5  	"github.com/martini-contrib/render"
     6  	//"github.com/brimstone/sbuca/x509util"
     7  	"net/http"
     8  
     9  	"github.com/brimstone/sbuca/ca"
    10  )
    11  
    12  func getCA(req *http.Request, params martini.Params, r render.Render) {
    13  
    14  	format := req.URL.Query().Get("format")
    15  
    16  	newCA, err := ca.NewCA(config["root-dir"])
    17  	if err != nil {
    18  		panic(err)
    19  	}
    20  
    21  	pem, err := newCA.Certificate.ToPEM()
    22  	if err != nil {
    23  		panic(err)
    24  	}
    25  
    26  	if format == "file" {
    27  		r.Data(200, pem)
    28  	} else {
    29  		r.JSON(200, map[string]interface{}{
    30  			"ca": map[string]interface{}{
    31  				"crt": string(pem),
    32  			},
    33  		})
    34  	}
    35  }