diff --git a/token-validator/wg.go b/token-validator/wg.go index b48b646..544dd81 100644 --- a/token-validator/wg.go +++ b/token-validator/wg.go @@ -98,19 +98,23 @@ func getWgTunnelInfo(w http.ResponseWriter, r *http.Request, ps httprouter.Param } var pt PubTunnel + var version int if r.Method == "POST" { if err := json.NewDecoder(r.Body).Decode(&pt); err != nil { http.Error(w, fmt.Sprintf("{errmsg:%q}", err), http.StatusBadRequest) return } + version = 2 } else if pubkey := r.Header.Get("X-WG-PubKey"); pubkey != "" { pt.PubKey, _ = base64.StdEncoding.DecodeString(pubkey) + version = 3 } else { http.Error(w, fmt.Sprintf("{errmsg:\"No public key given\"}", err), http.StatusBadRequest) return } token.PubKey = pt.PubKey + token.Version = version _, err = token.Update() if err != nil { http.Error(w, fmt.Sprintf("{errmsg:%q}", err), http.StatusBadRequest)