Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ package resty

import (
"bytes"
"crypto/md5"
"crypto/rand"
"crypto/sha256"
"encoding/binary"
"encoding/hex"
"errors"
Expand Down Expand Up @@ -371,7 +371,7 @@ func newGUID() string {
// Timestamp, 4 bytes, big endian
binary.BigEndian.PutUint32(b[:], uint32(time.Now().Unix()))

// Machine, first 3 bytes of md5(hostname)
// Machine, first 3 bytes of sha256.Sum256([]byte(hostname))
b[4], b[5], b[6] = machineID[0], machineID[1], machineID[2]

// Pid, 2 bytes, specs don't specify endianness, but we use big endian.
Expand Down Expand Up @@ -403,13 +403,12 @@ var osHostname = os.Hostname
// readMachineID generates and returns a machine id.
// If this function fails to get the hostname it will cause a runtime error.
func readMachineID() []byte {
var sum [3]byte
id := sum[:]
const idSize = 3
id := make([]byte, idSize)

if hostname, err := osHostname(); err == nil {
hw := md5.New()
_, _ = hw.Write([]byte(hostname))
copy(id, hw.Sum(nil))
hash := sha256.Sum256([]byte(hostname))
copy(id, hash[:idSize])
return id
}

Expand Down