Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lxd/instance/driver/qemu: replace sha1 by sha256 in blockNodeName() #12454

Merged
merged 1 commit into from
Oct 24, 2023
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
12 changes: 6 additions & 6 deletions lxd/instance/drivers/driver_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"bytes"
"compress/gzip"
"context"
"crypto/sha1"
"crypto/sha256"
"crypto/tls"
"crypto/x509"
"database/sql"
Expand Down Expand Up @@ -8308,14 +8308,14 @@ func (d *qemu) deviceDetachUSB(usbDev deviceConfig.USBDeviceItem) error {
// Block node names may only be up to 31 characters long, so use a hash if longer.
func (d *qemu) blockNodeName(name string) string {
if len(name) > 27 {
// If the name is too long, hash it as SHA-1 (20 bytes).
// Then encode the SHA-1 binary hash as Base64 Raw URL format (maximum 27 characters).
// Raw URL avoids the use of "+" character and the padding "=" character which QEMU doesn't allow,
// and keeps the length to 27 characters.
hash := sha1.New()
// If the name is too long, hash it as SHA-256 (32 bytes).
// Then encode the SHA-256 binary hash as Base64 Raw URL format and trim down to 27 chars.
// Raw URL avoids the use of "+" character and the padding "=" character which QEMU doesn't allow.
hash := sha256.New()
hash.Write([]byte(name))
binaryHash := hash.Sum(nil)
name = base64.RawURLEncoding.EncodeToString(binaryHash)
name = name[0:27]
}

// Apply the lxd_ prefix.
Expand Down
Loading