token-validator: use version to distinguish TP2's VM from TP3

This commit is contained in:
nemunaire 2020-04-02 16:08:27 +02:00
parent 28d5aa8fca
commit e1642827d1

View File

@ -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)