render context: add asset_download_token
This commit is contained in:
@ -75,6 +75,28 @@ func (s *DownloadSet) Decode(encoded string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (s DownloadSet) Signed(privKey ed25519.PrivateKey) string {
|
||||
buf := new(bytes.Buffer)
|
||||
{
|
||||
setBytes := []byte(s.Encode())
|
||||
|
||||
w := lz4.NewWriter(buf)
|
||||
w.Write(setBytes)
|
||||
w.Close()
|
||||
}
|
||||
|
||||
setBytes := buf.Bytes()
|
||||
sig := ed25519.Sign(privKey, setBytes)
|
||||
|
||||
buf = bytes.NewBuffer(make([]byte, 0, 1+len(sig)+len(setBytes)))
|
||||
buf.WriteByte(byte(len(sig)))
|
||||
buf.Write(sig)
|
||||
buf.Write(setBytes)
|
||||
|
||||
enc := base32.StdEncoding.WithPadding(base32.NoPadding)
|
||||
return enc.EncodeToString(buf.Bytes())
|
||||
}
|
||||
|
||||
type DownloadSetItem struct {
|
||||
Kind string
|
||||
Name string
|
||||
@ -143,32 +165,8 @@ func wsSignDownloadSet(req *restful.Request, resp *restful.Response) {
|
||||
Items: setReq.Items,
|
||||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
{
|
||||
setBytes := []byte(set.Encode())
|
||||
|
||||
w := lz4.NewWriter(buf)
|
||||
w.Write(setBytes)
|
||||
w.Close()
|
||||
}
|
||||
|
||||
setBytes := buf.Bytes()
|
||||
|
||||
privkey, pubkey := dlsSigningKeys()
|
||||
sig := ed25519.Sign(privkey, setBytes)
|
||||
|
||||
if !ed25519.Verify(pubkey, setBytes, sig) {
|
||||
wsError(resp, fmt.Errorf("signature self-check failed"))
|
||||
return
|
||||
}
|
||||
|
||||
buf = bytes.NewBuffer(make([]byte, 0, 1+len(sig)+len(setBytes)))
|
||||
buf.WriteByte(byte(len(sig)))
|
||||
buf.Write(sig)
|
||||
buf.Write(setBytes)
|
||||
|
||||
enc := base32.StdEncoding.WithPadding(base32.NoPadding)
|
||||
resp.WriteEntity(enc.EncodeToString(buf.Bytes()))
|
||||
privKey, _ := dlsSigningKeys()
|
||||
resp.WriteEntity(set.Signed(privKey))
|
||||
}
|
||||
|
||||
func getDlSet(req *restful.Request) (*DownloadSet, *httperr.Error) {
|
||||
@ -248,28 +246,13 @@ func wsDownloadSet(req *restful.Request, resp *restful.Response) {
|
||||
set, err := getDlSet(req)
|
||||
if err != nil {
|
||||
resp.WriteHeader(err.Status)
|
||||
resp.Write([]byte(`<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>` + err.Error() + `</title>
|
||||
<style src="/ui/style.css"/>
|
||||
<style src="/ui/app.css"/>
|
||||
</head>
|
||||
<body><h1>` + err.Error() + `</h1></body>
|
||||
</html>`))
|
||||
resp.Write([]byte(htmlHeader(err.Error())))
|
||||
resp.Write([]byte(htmlFooter))
|
||||
return
|
||||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
buf.WriteString(`<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Download set</title>
|
||||
<style src="/ui/style.css"/>
|
||||
<style src="/ui/app.css"/>
|
||||
</head>
|
||||
<body><h1>Download set</h1>
|
||||
`)
|
||||
buf.WriteString(htmlHeader("Download set"))
|
||||
|
||||
cfg, err2 := readConfig()
|
||||
if err2 != nil {
|
||||
@ -304,6 +287,6 @@ func wsDownloadSet(req *restful.Request, resp *restful.Response) {
|
||||
}
|
||||
}
|
||||
|
||||
buf.WriteString("</body></html>")
|
||||
buf.WriteString(htmlFooter)
|
||||
buf.WriteTo(resp)
|
||||
}
|
||||
|
Reference in New Issue
Block a user