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:
parent
09bfd44c55
commit
7f567216dd
17
config.go
17
config.go
@ -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()
|
||||
}
|
||||
|
9
etag.go
9
etag.go
@ -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))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user