netbirdio / netbird

Connect your devices into a secure WireGuard®-based overlay network with SSO, MFA and granular access controls.
https://netbird.io
BSD 3-Clause "New" or "Revised" License
10.2k stars 451 forks source link

client raising a "failed marshalling message string field contains invalid UTF-8" when trying to register the peer due to invalid SerialNumber #2260

Closed EdouardVanbelle closed 3 weeks ago

EdouardVanbelle commented 3 weeks ago

Hello I am getting an error: encryption/message.go:14: failed marshalling message string field contains invalid UTF-8 during a netbird up --key XXX --management-url YYY

NetBird version

0.28.4

More details on the reason

I have rebuilt netbird to have a better understanding of the isssue, here is the reason: my board do not have any serialnumber !

For better understanding:

$ git diff
diff --git a/encryption/message.go b/encryption/message.go
index a646fa67..8fe76f7a 100644
--- a/encryption/message.go
+++ b/encryption/message.go
@@ -9,6 +9,7 @@ import (
 // EncryptMessage encrypts a body of the given protobuf Message
 func EncryptMessage(remotePubKey wgtypes.Key, ourPrivateKey wgtypes.Key, message pb.Message) ([]byte, error) {
        byteResp, err := pb.Marshal(message)
+       log.Debugf("DEBUG marshalling message %v", message)
        if err != nil {
                log.Errorf("failed marshalling message %v", err)
                return nil, err

which raises me:

/home/ed/netbird/client/client up --log-level debug -F --log-file console --management-url https://MYSERVER:443 --setup-key MYKEY

2024-07-11T18:35:09+02:00 DEBG client/internal/login.go:93: connecting to the Management service https://MYSERVER:443
2024-07-11T18:35:09+02:00 DEBG client/internal/login.go:63: connected to the Management service https://MYSERVER:443
2024-07-11T18:35:10+02:00 ERRO encryption/message.go:12: DEBUG marshalling message meta:{hostname:"my-pretty-nuc"  goOS:"linux"  kernel:"Linux"  core:"12"  platform:"unknown"  OS:"Debian GNU/Linux"  wiretrusteeVersion:"development"  kernelVersion:"6.1.0-22-amd64"  OSVersion:"12"  networkAddresses:{netIP:"OBFUSCATED"  mac:"OBFUSCATED"}  networkAddresses:{netIP:"OBFUSCATED"  mac:"OBFUSCATED"}  networkAddresses:{netIP:"OBFUSCATED"  mac:"OBFUSCATED"}  sysSerialNumber:"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"  sysProductName:"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"  sysManufacturer:"OVH"  environment:{}}  peerKeys:{sshPubKey:"OBFUSCATED"}
2024-07-11T18:35:10+02:00 ERRO encryption/message.go:14: failed marshalling message string field contains invalid UTF-8
2024-07-11T18:35:10+02:00 ERRO management/client/grpc.go:331: failed to encrypt message: string field contains invalid UTF-8

My device has no serial number which generated a failure on marshalling phase

and I confirm it via a dmidecode:

# dmidecode -t system

# dmidecode 3.4
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.

Handle 0x0001, DMI type 1, 27 bytes
System Information
        Manufacturer: OVH
        Product Name: .................................
        Version: .................................
        Serial Number: .................................
        UUID: OBFUSCATED
        Wake-up Type: Power Switch
        SKU Number: .................................
        Family: .................................

do you have any suggestion to prevent this ? We could eventually use the UUID if serial number is not present ?

Kindest regards note: I love your project !

EdouardVanbelle commented 3 weeks ago

I bypassed this issue doing a fallback to the board

diff --git a/client/system/info_linux.go b/client/system/info_linux.go
index d85a6fae..564195a4 100644
--- a/client/system/info_linux.go
+++ b/client/system/info_linux.go
@@ -11,6 +11,7 @@ import (
        "runtime"
        "strings"
        "time"
+       "regexp"

        log "github.com/sirupsen/logrus"
        "github.com/zcalusic/sysinfo"
@@ -89,9 +90,17 @@ func _getInfo() string {
 func sysInfo() (serialNumber string, productName string, manufacturer string) {
        var si sysinfo.SysInfo
        si.GetSysInfo()
+       isascii, _ := regexp.Compile("^[[:ascii:]]+$")
        serial := si.Chassis.Serial
        if (serial == "Default string" || serial == "") && si.Product.Serial != "" {
                serial = si.Product.Serial
        }
-       return serial, si.Product.Name, si.Product.Vendor
+       if (!isascii.MatchString(serial)) && si.Board.Serial != "" {
+               serial = si.Board.Serial
+       }
+       name := si.Product.Name
+       if (!isascii.MatchString(name)) && si.Board.Name != "" {
+               name = si.Board.Name
+       }
+       return serial, name, si.Product.Vendor
 }

let me know if you want a merge request