1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-01-08 10:45:04 +02:00

Get rid of ETag signature; Change ETag hash to SHA256; Add verison

This commit is contained in:
DarthSim 2018-09-06 19:02:21 +06:00
parent 09bfd44c55
commit 7f567216dd
3 changed files with 14 additions and 14 deletions

View File

@ -2,7 +2,6 @@ package main
import (
"bytes"
"crypto/rand"
"encoding/hex"
"flag"
"fmt"
@ -101,8 +100,7 @@ type config struct {
LocalFileSystemRoot string
ETagEnabled bool
ETagSignature []byte
ETagEnabled bool
BaseURL string
}
@ -124,8 +122,14 @@ var conf = config{
func init() {
keypath := flag.String("keypath", "", "path of the file with hex-encoded key")
saltpath := flag.String("saltpath", "", "path of the file with hex-encoded salt")
showVersion := flag.Bool("v", false, "show version")
flag.Parse()
if *showVersion {
fmt.Println(version)
os.Exit(0)
}
if port := os.Getenv("PORT"); len(port) > 0 {
conf.Bind = fmt.Sprintf(":%s", port)
}
@ -232,13 +236,6 @@ func init() {
}
}
if conf.ETagEnabled {
conf.ETagSignature = make([]byte, 16)
rand.Read(conf.ETagSignature)
log.Printf("ETag support is activated. The random value was generated to be used for ETag calculation: %s\n",
fmt.Sprintf("%x", conf.ETagSignature))
}
initVips()
initDownloading()
}

View File

@ -1,7 +1,7 @@
package main
import (
"crypto/sha1"
"crypto/sha256"
"encoding/binary"
"fmt"
)
@ -9,12 +9,13 @@ import (
var notModifiedErr = newError(304, "Not modified", "Not modified")
func calcETag(b []byte, po *processingOptions) string {
footprint := sha1.Sum(b)
footprint := sha256.Sum256(b)
hash := sha1.New()
hash := sha256.New()
hash.Write(footprint[:])
hash.Write([]byte(version))
binary.Write(hash, binary.LittleEndian, conf)
binary.Write(hash, binary.LittleEndian, *po)
hash.Write(conf.ETagSignature)
return fmt.Sprintf("%x", hash.Sum(nil))
}

View File

@ -12,6 +12,8 @@ import (
"golang.org/x/net/netutil"
)
const version = "1.1.7"
func main() {
// Force garbage collection
go func() {