Compare commits

...

2 Commits

Author SHA1 Message Date
Andrea Spacca
f33559aa6e remove deprecated rand.Seed 2023-08-11 19:08:16 +09:00
Stefan Benten
891ef14cfb server/server.go: use TLS config provided by acme/autocert (#567)
Suggestion based on go docs of acme autocert.
2023-06-20 20:07:19 +02:00
2 changed files with 16 additions and 15 deletions

View File

@@ -26,12 +26,9 @@ package server
import (
"context"
cryptoRand "crypto/rand"
"crypto/tls"
"encoding/binary"
"errors"
"log"
"math/rand"
"mime"
"net/http"
_ "net/http/pprof"
@@ -274,9 +271,8 @@ func UseLetsEncrypt(hosts []string) OptionFn {
},
}
srvr.tlsConfig = &tls.Config{
GetCertificate: m.GetCertificate,
}
srvr.tlsConfig = m.TLSConfig()
srvr.tlsConfig.GetCertificate = m.GetCertificate
}
}
@@ -403,14 +399,6 @@ func New(options ...OptionFn) (*Server, error) {
return s, nil
}
func init() {
var seedBytes [8]byte
if _, err := cryptoRand.Read(seedBytes[:]); err != nil {
panic("cannot obtain cryptographically secure seed")
}
rand.Seed(int64(binary.LittleEndian.Uint64(seedBytes[:])))
}
// Run starts Server
func (s *Server) Run() {
listening := false

View File

@@ -25,9 +25,22 @@ THE SOFTWARE.
package server
import (
cryptoRand "crypto/rand"
"encoding/binary"
"math/rand"
)
var seed *rand.Rand
func init() {
var seedBytes [8]byte
if _, err := cryptoRand.Read(seedBytes[:]); err != nil {
panic("cannot obtain cryptographically secure seed")
}
seed = rand.New(rand.NewSource(int64(binary.LittleEndian.Uint64(seedBytes[:]))))
}
const (
// SYMBOLS characters used for short-urls
SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
@@ -37,7 +50,7 @@ const (
func token(length int) string {
result := ""
for i := 0; i < length; i++ {
x := rand.Intn(len(SYMBOLS) - 1)
x := seed.Intn(len(SYMBOLS) - 1)
result = string(SYMBOLS[x]) + result
}