|
|
|
@ -21,22 +21,22 @@ type HttpServer struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type CreateCSRRequest struct {
|
|
|
|
|
BaseMessage
|
|
|
|
|
*BaseMessage
|
|
|
|
|
Hostname string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type CreateCSRResponse struct {
|
|
|
|
|
BaseMessage
|
|
|
|
|
*BaseMessage
|
|
|
|
|
CSR string `json:"csr"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type UpdateOpenVPNConfigRequest struct {
|
|
|
|
|
BaseMessage
|
|
|
|
|
*BaseMessage
|
|
|
|
|
Config string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type DeliverCertificateRequest struct {
|
|
|
|
|
BaseMessage
|
|
|
|
|
*BaseMessage
|
|
|
|
|
Certificate string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -53,7 +53,9 @@ func (it *HttpServer) Start() {
|
|
|
|
|
|
|
|
|
|
http.HandleFunc("/create-csr", func(writer http.ResponseWriter, request *http.Request) {
|
|
|
|
|
log.Printf("%s /create-csr", strings.ToUpper(request.Method))
|
|
|
|
|
req := &CreateCSRRequest{}
|
|
|
|
|
req := &CreateCSRRequest{
|
|
|
|
|
BaseMessage: &BaseMessage{""},
|
|
|
|
|
}
|
|
|
|
|
err := it.verifyRequest(request, req)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
@ -69,13 +71,16 @@ func (it *HttpServer) Start() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
it.writeResponse(writer, CreateCSRResponse{
|
|
|
|
|
CSR: string(csr),
|
|
|
|
|
BaseMessage: &BaseMessage{""},
|
|
|
|
|
CSR: string(csr),
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
http.HandleFunc("/deliver-crt", func(writer http.ResponseWriter, request *http.Request) {
|
|
|
|
|
log.Printf("%s /deliver-crt", strings.ToUpper(request.Method))
|
|
|
|
|
req := &DeliverCertificateRequest{}
|
|
|
|
|
req := &DeliverCertificateRequest{
|
|
|
|
|
BaseMessage: &BaseMessage{""},
|
|
|
|
|
}
|
|
|
|
|
err := it.verifyRequest(request, req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Printf("Error on %s %s: %s", request.Method, request.URL.Path, err)
|
|
|
|
@ -94,7 +99,9 @@ func (it *HttpServer) Start() {
|
|
|
|
|
|
|
|
|
|
http.HandleFunc("/update-openvpn-config", func(writer http.ResponseWriter, request *http.Request) {
|
|
|
|
|
log.Printf("%s /update-openvpn-config", strings.ToUpper(request.Method))
|
|
|
|
|
req := &UpdateOpenVPNConfigRequest{}
|
|
|
|
|
req := &UpdateOpenVPNConfigRequest{
|
|
|
|
|
BaseMessage: &BaseMessage{""},
|
|
|
|
|
}
|
|
|
|
|
err := it.verifyRequest(request, req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Printf("Error on %s %s: %s", request.Method, request.URL.Path, err)
|
|
|
|
@ -114,11 +121,11 @@ func (it *HttpServer) Start() {
|
|
|
|
|
http.ListenAndServe(":7864", nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (it *HttpServer) writeResponse(writer http.ResponseWriter, v interface{}) error {
|
|
|
|
|
func (it *HttpServer) writeResponse(writer http.ResponseWriter, v Message) error {
|
|
|
|
|
return EncryptAndSign(v, it.manager.privateKey, it.manager.CAPublicKey(), it.manager.GetServerFingerprint(), writer)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (it *HttpServer) verifyRequest(r *http.Request, v interface{}) (error) {
|
|
|
|
|
func (it *HttpServer) verifyRequest(r *http.Request, v Message) (error) {
|
|
|
|
|
hexBody, err := ioutil.ReadAll(r.Body)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|